From b951ce3ef7ec7dc3564b5fd51b50a4284895a1c4 Mon Sep 17 00:00:00 2001 From: PKLite Date: Fri, 21 Jun 2019 05:28:37 -0400 Subject: [PATCH] WIP: part 2 of loot tracker updates started. Adds reset button to clear all local data. Signed-off-by: PKLite --- .../plugins/loottracker/LootTrackerPanel.java | 52 +++++++++++++++++- .../loottracker/LootTrackerPlugin.java | 13 +++++ .../client/plugins/loottracker/reset.png | Bin 0 -> 275 bytes 3 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 runelite-client/src/main/resources/net/runelite/client/plugins/loottracker/reset.png diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/loottracker/LootTrackerPanel.java b/runelite-client/src/main/java/net/runelite/client/plugins/loottracker/LootTrackerPanel.java index ac2d502ce5..f1f054eadf 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/loottracker/LootTrackerPanel.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/loottracker/LootTrackerPanel.java @@ -75,6 +75,10 @@ class LootTrackerPanel extends PluginPanel private static final ImageIcon VISIBLE_ICON_HOVER; private static final ImageIcon INVISIBLE_ICON; private static final ImageIcon INVISIBLE_ICON_HOVER; + private static final ImageIcon RESET_ICON; + private static final ImageIcon RESET_ICON_FADED; + private static final ImageIcon RESET_ICON_HOVER; + private static final String HTML_LABEL_TEMPLATE = "%s%s"; @@ -98,6 +102,7 @@ class LootTrackerPanel extends PluginPanel private final JLabel viewHiddenBtn = new JLabel(); private final JLabel singleLootBtn = new JLabel(); private final JLabel groupedLootBtn = new JLabel(); + private final JLabel resetIcon = new JLabel(); // Log collection private final List records = new ArrayList<>(); @@ -118,11 +123,17 @@ class LootTrackerPanel extends PluginPanel final BufferedImage backArrowImg = ImageUtil.getResourceStreamFromClass(LootTrackerPlugin.class, "back_icon.png"); final BufferedImage visibleImg = ImageUtil.getResourceStreamFromClass(LootTrackerPlugin.class, "visible_icon.png"); final BufferedImage invisibleImg = ImageUtil.getResourceStreamFromClass(LootTrackerPlugin.class, "invisible_icon.png"); + final BufferedImage resetImg = ImageUtil.getResourceStreamFromClass(LootTrackerPlugin.class, "reset.png"); SINGLE_LOOT_VIEW = new ImageIcon(singleLootImg); SINGLE_LOOT_VIEW_FADED = new ImageIcon(ImageUtil.alphaOffset(singleLootImg, -180)); SINGLE_LOOT_VIEW_HOVER = new ImageIcon(ImageUtil.alphaOffset(singleLootImg, -220)); + RESET_ICON = new ImageIcon(resetImg); + RESET_ICON_FADED = new ImageIcon(ImageUtil.alphaOffset(resetImg, -180)); + RESET_ICON_HOVER = new ImageIcon(ImageUtil.alphaOffset(resetImg, -220)); + + GROUPED_LOOT_VIEW = new ImageIcon(groupedLootImg); GROUPED_LOOT_VIEW_FADED = new ImageIcon(ImageUtil.alphaOffset(groupedLootImg, -180)); GROUPED_LOOT_VIEW_HOVER = new ImageIcon(ImageUtil.alphaOffset(groupedLootImg, -220)); @@ -164,7 +175,7 @@ class LootTrackerPanel extends PluginPanel actionsContainer.setBorder(new EmptyBorder(5, 5, 5, 10)); actionsContainer.setVisible(false); - final JPanel viewControls = new JPanel(new GridLayout(1, 3, 10, 0)); + final JPanel viewControls = new JPanel(new GridLayout(1, 4, 10, 0)); viewControls.setBackground(ColorScheme.DARKER_GRAY_COLOR); singleLootBtn.setIcon(SINGLE_LOOT_VIEW); @@ -236,6 +247,30 @@ class LootTrackerPanel extends PluginPanel } }); + resetIcon.setIcon(RESET_ICON); + resetIcon.setToolTipText("Resets all locally saved data (cannot be undone)"); + resetIcon.addMouseListener(new MouseAdapter() + { + @Override + public void mousePressed(MouseEvent e) + { + resetRecords(); + } + + @Override + public void mouseEntered(MouseEvent e) + { + resetIcon.setIcon(RESET_ICON_HOVER); + } + + @Override + public void mouseExited(MouseEvent e) + { + resetIcon.setIcon(records.isEmpty() ? RESET_ICON_FADED : RESET_ICON); + } + }); + + viewControls.add(resetIcon); viewControls.add(groupedLootBtn); viewControls.add(singleLootBtn); viewControls.add(viewHiddenBtn); @@ -399,6 +434,21 @@ class LootTrackerPanel extends PluginPanel viewHiddenBtn.setIcon(hideIgnoredItems ? VISIBLE_ICON : INVISIBLE_ICON); } + /** + * Clears all loaded records. This will also attempt to delete the local storage file + */ + private void resetRecords() + { + records.clear(); + boxes.clear(); + logsContainer.removeAll(); + logsContainer.repaint(); + if (config.localPersistence()) + { + plugin.deleteLocalRecords(); + } + } + /** * After an item changed it's ignored state, iterate all the records and make * sure all items of the same name also get updated diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/loottracker/LootTrackerPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/loottracker/LootTrackerPlugin.java index 25b2df509a..f53a71739e 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/loottracker/LootTrackerPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/loottracker/LootTrackerPlugin.java @@ -657,6 +657,19 @@ public class LootTrackerPlugin extends Plugin } } + public void deleteLocalRecords() + { + try + { + Files.deleteIfExists(LOOT_RECORDS_FILE.toPath()); + } + catch (IOException e) + { + log.debug("Error deleting local loot records file."); + log.debug(Arrays.toString(e.getStackTrace())); + } + } + /** * Takes a snapshot of the local player's inventory and equipment right before respawn. */ diff --git a/runelite-client/src/main/resources/net/runelite/client/plugins/loottracker/reset.png b/runelite-client/src/main/resources/net/runelite/client/plugins/loottracker/reset.png new file mode 100644 index 0000000000000000000000000000000000000000..0b85a3dbde3584d5407c7bbb9f40bc3f20e1ce3a GIT binary patch literal 275 zcmV+u0qp*XP)sa)Xqoe;nfNzQI*#W z-4V<+5GEA*cZROU`@UOx9JY-f1l(Riz`+BLm5d9CQ7OeH?*`kp8T$3t{yk{FlX2Ll zeHfqt+Zr5xg