loottracker: Remove import loot panel
This commit is contained in:
@@ -52,7 +52,6 @@ import javax.swing.JPanel;
|
|||||||
import javax.swing.JPopupMenu;
|
import javax.swing.JPopupMenu;
|
||||||
import javax.swing.JRadioButton;
|
import javax.swing.JRadioButton;
|
||||||
import javax.swing.JToggleButton;
|
import javax.swing.JToggleButton;
|
||||||
import javax.swing.SwingUtilities;
|
|
||||||
import javax.swing.border.EmptyBorder;
|
import javax.swing.border.EmptyBorder;
|
||||||
import javax.swing.plaf.basic.BasicButtonUI;
|
import javax.swing.plaf.basic.BasicButtonUI;
|
||||||
import javax.swing.plaf.basic.BasicToggleButtonUI;
|
import javax.swing.plaf.basic.BasicToggleButtonUI;
|
||||||
@@ -85,7 +84,6 @@ class LootTrackerPanel extends PluginPanel
|
|||||||
private static final ImageIcon INVISIBLE_ICON_HOVER;
|
private static final ImageIcon INVISIBLE_ICON_HOVER;
|
||||||
private static final ImageIcon COLLAPSE_ICON;
|
private static final ImageIcon COLLAPSE_ICON;
|
||||||
private static final ImageIcon EXPAND_ICON;
|
private static final ImageIcon EXPAND_ICON;
|
||||||
private static final ImageIcon IMPORT_ICON;
|
|
||||||
|
|
||||||
private static final String HTML_LABEL_TEMPLATE =
|
private static final String HTML_LABEL_TEMPLATE =
|
||||||
"<html><body style='color:%s'>%s<span style='color:white'>%s</span></body></html>";
|
"<html><body style='color:%s'>%s<span style='color:white'>%s</span></body></html>";
|
||||||
@@ -117,8 +115,6 @@ class LootTrackerPanel extends PluginPanel
|
|||||||
private final JRadioButton groupedLootBtn = new JRadioButton();
|
private final JRadioButton groupedLootBtn = new JRadioButton();
|
||||||
private final JButton collapseBtn = new JButton();
|
private final JButton collapseBtn = new JButton();
|
||||||
|
|
||||||
private final JPanel importNoticePanel;
|
|
||||||
|
|
||||||
// Aggregate of all kills
|
// Aggregate of all kills
|
||||||
private final List<LootTrackerRecord> aggregateRecords = new ArrayList<>();
|
private final List<LootTrackerRecord> aggregateRecords = new ArrayList<>();
|
||||||
// Individual records for the individual kills this session
|
// Individual records for the individual kills this session
|
||||||
@@ -163,8 +159,6 @@ class LootTrackerPanel extends PluginPanel
|
|||||||
|
|
||||||
COLLAPSE_ICON = new ImageIcon(collapseImg);
|
COLLAPSE_ICON = new ImageIcon(collapseImg);
|
||||||
EXPAND_ICON = new ImageIcon(expandedImg);
|
EXPAND_ICON = new ImageIcon(expandedImg);
|
||||||
|
|
||||||
IMPORT_ICON = new ImageIcon(ImageUtil.loadImageResource(LootTrackerPlugin.class, "import_icon.png"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
LootTrackerPanel(final LootTrackerPlugin plugin, final ItemManager itemManager, final LootTrackerConfig config)
|
LootTrackerPanel(final LootTrackerPlugin plugin, final ItemManager itemManager, final LootTrackerConfig config)
|
||||||
@@ -185,12 +179,10 @@ class LootTrackerPanel extends PluginPanel
|
|||||||
|
|
||||||
actionsPanel = buildActionsPanel();
|
actionsPanel = buildActionsPanel();
|
||||||
overallPanel = buildOverallPanel();
|
overallPanel = buildOverallPanel();
|
||||||
importNoticePanel = createImportNoticePanel();
|
|
||||||
|
|
||||||
// Create loot boxes wrapper
|
// Create loot boxes wrapper
|
||||||
logsContainer.setLayout(new BoxLayout(logsContainer, BoxLayout.Y_AXIS));
|
logsContainer.setLayout(new BoxLayout(logsContainer, BoxLayout.Y_AXIS));
|
||||||
layoutPanel.add(actionsPanel);
|
layoutPanel.add(actionsPanel);
|
||||||
layoutPanel.add(importNoticePanel);
|
|
||||||
layoutPanel.add(overallPanel);
|
layoutPanel.add(overallPanel);
|
||||||
layoutPanel.add(logsContainer);
|
layoutPanel.add(logsContainer);
|
||||||
|
|
||||||
@@ -354,30 +346,6 @@ class LootTrackerPanel extends PluginPanel
|
|||||||
return overallPanel;
|
return overallPanel;
|
||||||
}
|
}
|
||||||
|
|
||||||
private JPanel createImportNoticePanel()
|
|
||||||
{
|
|
||||||
JPanel panel = new JPanel();
|
|
||||||
panel.setBackground(ColorScheme.DARKER_GRAY_COLOR);
|
|
||||||
panel.setBorder(BorderFactory.createCompoundBorder(
|
|
||||||
BorderFactory.createMatteBorder(5, 0, 0, 0, ColorScheme.DARK_GRAY_COLOR),
|
|
||||||
BorderFactory.createEmptyBorder(8, 10, 8, 10)
|
|
||||||
));
|
|
||||||
panel.setLayout(new BorderLayout());
|
|
||||||
|
|
||||||
final JLabel importLabel = new JLabel("<html>Missing saved loot? Click the<br>import button to import it.</html>");
|
|
||||||
importLabel.setForeground(Color.YELLOW);
|
|
||||||
panel.add(importLabel, BorderLayout.WEST);
|
|
||||||
|
|
||||||
JButton importButton = new JButton();
|
|
||||||
SwingUtil.removeButtonDecorations(importButton);
|
|
||||||
importButton.setIcon(IMPORT_ICON);
|
|
||||||
importButton.setToolTipText("Import old loot tracker data to current profile");
|
|
||||||
importButton.addActionListener(l -> plugin.importLoot());
|
|
||||||
panel.add(importButton, BorderLayout.EAST);
|
|
||||||
|
|
||||||
return panel;
|
|
||||||
}
|
|
||||||
|
|
||||||
void updateCollapseText()
|
void updateCollapseText()
|
||||||
{
|
{
|
||||||
collapseBtn.setSelected(isAllCollapsed());
|
collapseBtn.setSelected(isAllCollapsed());
|
||||||
@@ -736,9 +704,4 @@ class LootTrackerPanel extends PluginPanel
|
|||||||
final String valueStr = QuantityFormatter.quantityToStackSize(value);
|
final String valueStr = QuantityFormatter.quantityToStackSize(value);
|
||||||
return String.format(HTML_LABEL_TEMPLATE, ColorUtil.toHexColor(ColorScheme.LIGHT_GRAY_COLOR), key, valueStr);
|
return String.format(HTML_LABEL_TEMPLATE, ColorUtil.toHexColor(ColorScheme.LIGHT_GRAY_COLOR), key, valueStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void toggleImportNotice(boolean on)
|
|
||||||
{
|
|
||||||
SwingUtilities.invokeLater(() -> importNoticePanel.setVisible(on));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,7 +38,6 @@ import com.google.gson.Gson;
|
|||||||
import com.google.gson.JsonSyntaxException;
|
import com.google.gson.JsonSyntaxException;
|
||||||
import com.google.inject.Provides;
|
import com.google.inject.Provides;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.io.IOException;
|
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.time.temporal.ChronoUnit;
|
import java.time.temporal.ChronoUnit;
|
||||||
@@ -60,7 +59,6 @@ import java.util.regex.Pattern;
|
|||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.swing.JOptionPane;
|
|
||||||
import javax.swing.SwingUtilities;
|
import javax.swing.SwingUtilities;
|
||||||
import lombok.AccessLevel;
|
import lombok.AccessLevel;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
@@ -469,8 +467,6 @@ public class LootTrackerPlugin extends Plugin
|
|||||||
panel.addRecords(records);
|
panel.addRecords(records);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
panel.toggleImportNotice(!hasImported());
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1340,115 +1336,5 @@ public class LootTrackerPlugin extends Plugin
|
|||||||
{
|
{
|
||||||
configManager.unsetConfiguration(LootTrackerConfig.GROUP, profile, key);
|
configManager.unsetConfiguration(LootTrackerConfig.GROUP, profile, key);
|
||||||
}
|
}
|
||||||
|
|
||||||
clearImported();
|
|
||||||
panel.toggleImportNotice(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
void importLoot()
|
|
||||||
{
|
|
||||||
if (configManager.getRSProfileKey() == null)
|
|
||||||
{
|
|
||||||
JOptionPane.showMessageDialog(panel, "You do not have an active profile to import loot into; log in to the game first.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (lootTrackerClient.getUuid() == null)
|
|
||||||
{
|
|
||||||
JOptionPane.showMessageDialog(panel, "You are not logged into RuneLite, so loot can not be imported from your account. Log in first.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (lastLootImport.isAfter(Instant.now().minus(1, ChronoUnit.MINUTES)))
|
|
||||||
{
|
|
||||||
JOptionPane.showMessageDialog(panel, "You imported too recently. Wait a minute and try again.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
lastLootImport = Instant.now();
|
|
||||||
|
|
||||||
executor.execute(() ->
|
|
||||||
{
|
|
||||||
if (hasImported())
|
|
||||||
{
|
|
||||||
SwingUtilities.invokeLater(() -> JOptionPane.showMessageDialog(panel, "You already have imported loot."));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Collection<LootAggregate> lootRecords;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
lootRecords = lootTrackerClient.get();
|
|
||||||
}
|
|
||||||
catch (IOException e)
|
|
||||||
{
|
|
||||||
log.debug("Unable to look up loot", e);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
log.debug("Loaded {} data entries", lootRecords.size());
|
|
||||||
|
|
||||||
for (LootAggregate record : lootRecords)
|
|
||||||
{
|
|
||||||
ConfigLoot lootConfig = getLootConfig(record.getType(), record.getEventId());
|
|
||||||
if (lootConfig == null)
|
|
||||||
{
|
|
||||||
lootConfig = new ConfigLoot(record.getType(), record.getEventId());
|
|
||||||
}
|
|
||||||
lootConfig.first = record.getFirst_time();
|
|
||||||
lootConfig.last = record.getLast_time();
|
|
||||||
lootConfig.kills += record.getAmount();
|
|
||||||
for (GameItem gameItem : record.getDrops())
|
|
||||||
{
|
|
||||||
lootConfig.add(gameItem.getId(), gameItem.getQty());
|
|
||||||
}
|
|
||||||
setLootConfig(record.getType(), record.getEventId(), lootConfig);
|
|
||||||
}
|
|
||||||
|
|
||||||
clientThread.invokeLater(() ->
|
|
||||||
{
|
|
||||||
Collection<LootTrackerRecord> records = convertToLootTrackerRecord(lootRecords);
|
|
||||||
SwingUtilities.invokeLater(() -> panel.addRecords(records));
|
|
||||||
});
|
|
||||||
|
|
||||||
SwingUtilities.invokeLater(() -> JOptionPane.showMessageDialog(panel, "Imported " + lootRecords.size() + " loot entries."));
|
|
||||||
|
|
||||||
setHasImported();
|
|
||||||
panel.toggleImportNotice(false);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
void setHasImported()
|
|
||||||
{
|
|
||||||
String profile = profileKey;
|
|
||||||
if (Strings.isNullOrEmpty(profile))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
configManager.setConfiguration(LootTrackerConfig.GROUP, profile, "imported", 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean hasImported()
|
|
||||||
{
|
|
||||||
String profile = profileKey;
|
|
||||||
if (Strings.isNullOrEmpty(profile))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
Integer i = configManager.getConfiguration(LootTrackerConfig.GROUP, profile, "imported", Integer.class);
|
|
||||||
return i != null && i == 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
void clearImported()
|
|
||||||
{
|
|
||||||
String profile = profileKey;
|
|
||||||
if (Strings.isNullOrEmpty(profile))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
configManager.unsetConfiguration(LootTrackerConfig.GROUP, profile, "imported");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user