From b951ce3ef7ec7dc3564b5fd51b50a4284895a1c4 Mon Sep 17 00:00:00 2001 From: PKLite Date: Fri, 21 Jun 2019 05:28:37 -0400 Subject: [PATCH 1/7] 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 Date: Wed, 26 Jun 2019 03:39:05 -0400 Subject: [PATCH 2/7] adds support for date and adds date display to loot tracker panel Signed-off-by: PKLite --- .../plugins/loottracker/LootRecordSortType.java | 2 +- .../client/plugins/loottracker/LootTrackerBox.java | 12 ++++++++++++ .../client/plugins/loottracker/LootTrackerPanel.java | 5 +++-- .../plugins/loottracker/LootTrackerPlugin.java | 2 +- .../plugins/loottracker/LootTrackerRecord.java | 3 ++- 5 files changed, 19 insertions(+), 5 deletions(-) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/loottracker/LootRecordSortType.java b/runelite-client/src/main/java/net/runelite/client/plugins/loottracker/LootRecordSortType.java index 6dc01e960c..9d72d9e8c0 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/loottracker/LootRecordSortType.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/loottracker/LootRecordSortType.java @@ -17,7 +17,7 @@ public enum LootRecordSortType implements Comparator @Override public int compare(LootTrackerRecord o1, LootTrackerRecord o2) { - return Long.compare(o1.getTimestamp(), o2.getTimestamp()); + return Long.compare(o1.getTimestamp().toEpochMilli(), o2.getTimestamp().toEpochMilli()); } }, TOTAL_VALUE diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/loottracker/LootTrackerBox.java b/runelite-client/src/main/java/net/runelite/client/plugins/loottracker/LootTrackerBox.java index b111fde570..a7454387e9 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/loottracker/LootTrackerBox.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/loottracker/LootTrackerBox.java @@ -32,6 +32,7 @@ import java.awt.GridLayout; import java.awt.image.BufferedImage; import java.util.ArrayList; import java.util.Arrays; +import java.util.Date; import java.util.List; import java.util.function.BiConsumer; import javax.annotation.Nullable; @@ -59,6 +60,7 @@ class LootTrackerBox extends JPanel private final JPanel itemContainer = new JPanel(); private final JLabel priceLabel = new JLabel(); private final JLabel subTitleLabel = new JLabel(); + private final JLabel dateLabel = new JLabel(); private final ItemManager itemManager; @Getter(AccessLevel.PACKAGE) private final String id; @@ -69,14 +71,17 @@ class LootTrackerBox extends JPanel private long totalPrice; private boolean hideIgnoredItems; private BiConsumer onItemToggle; + private final long timeStamp; LootTrackerBox( + final long timeStamp, final ItemManager itemManager, final String id, @Nullable final String subtitle, final boolean hideIgnoredItems, final BiConsumer onItemToggle) { + this.timeStamp = timeStamp; this.id = id; this.itemManager = itemManager; this.onItemToggle = onItemToggle; @@ -99,6 +104,12 @@ class LootTrackerBox extends JPanel subTitleLabel.setForeground(ColorScheme.LIGHT_GRAY_COLOR); logTitle.add(subTitleLabel, BorderLayout.CENTER); + dateLabel.setFont(FontManager.getRunescapeSmallFont().deriveFont(FontManager.getRunescapeSmallFont().getSize() - 2)); + dateLabel.setForeground(Color.LIGHT_GRAY); + dateLabel.setText(new Date(timeStamp).toLocaleString()); + logTitle.add(dateLabel, BorderLayout.SOUTH); + + if (!Strings.isNullOrEmpty(subtitle)) { subTitleLabel.setText(subtitle); @@ -110,6 +121,7 @@ class LootTrackerBox extends JPanel add(logTitle, BorderLayout.NORTH); add(itemContainer, BorderLayout.CENTER); + } /** 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 f1f054eadf..dc0d7c34d7 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 @@ -32,6 +32,7 @@ import java.awt.GridLayout; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.awt.image.BufferedImage; +import java.time.Instant; import java.util.ArrayList; import java.util.Collection; import java.util.List; @@ -390,7 +391,7 @@ class LootTrackerPanel extends PluginPanel void add(final String eventName, final String localUsername, final int actorLevel, LootTrackerItem[] items) { final String subTitle = actorLevel > -1 ? "(lvl-" + actorLevel + ")" : ""; - final LootTrackerRecord record = new LootTrackerRecord( eventName, localUsername, subTitle, items, System.currentTimeMillis()); + final LootTrackerRecord record = new LootTrackerRecord( eventName, localUsername, subTitle, items, Instant.now()); records.add(record); LootTrackerBox box = buildBox(record); if (box != null) @@ -545,7 +546,7 @@ class LootTrackerPanel extends PluginPanel overallPanel.setVisible(true); // Create box - final LootTrackerBox box = new LootTrackerBox(itemManager, record.getTitle(), record.getSubTitle(), + final LootTrackerBox box = new LootTrackerBox(record.getTimestamp().toEpochMilli(), itemManager, record.getTitle(), record.getSubTitle(), hideIgnoredItems, plugin::toggleItem); box.combine(record); 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 94847fe8eb..a71d4ff31e 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 @@ -823,7 +823,7 @@ public class LootTrackerPlugin extends Plugin ).toArray(LootTrackerItem[]::new); trackerRecords.add(new LootTrackerRecord(record.getEventId(), record.getUsername(), - "", drops, -1)); + "", drops, record.getTime())); } return trackerRecords; diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/loottracker/LootTrackerRecord.java b/runelite-client/src/main/java/net/runelite/client/plugins/loottracker/LootTrackerRecord.java index a92ff0009f..cadec0680f 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/loottracker/LootTrackerRecord.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/loottracker/LootTrackerRecord.java @@ -25,6 +25,7 @@ package net.runelite.client.plugins.loottracker; import com.google.gson.annotations.SerializedName; +import java.time.Instant; import lombok.Value; @Value @@ -35,7 +36,7 @@ class LootTrackerRecord private final String subTitle; @SerializedName("item_records") private final LootTrackerItem[] items; - private final long timestamp; + private final Instant timestamp; /** * Checks if this record matches specified id From 94c1bc57a19eed727daa84938975acebaea0ca3a Mon Sep 17 00:00:00 2001 From: PKLite Date: Fri, 28 Jun 2019 02:38:53 -0400 Subject: [PATCH 3/7] add local loot saving for chests, clue scrolls, etc Signed-off-by: PKLite --- .../plugins/loottracker/LootTrackerPlugin.java | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) 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 42d6bf71dc..7a98b15cb8 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 @@ -518,14 +518,19 @@ public class LootTrackerPlugin extends Plugin } final LootTrackerItem[] entries = buildEntries(stack(items)); + SwingUtilities.invokeLater(() -> panel.add(eventType, client.getLocalPlayer().getName(), -1, entries)); + LootRecord lootRecord = new LootRecord(eventType, client.getLocalPlayer().getName(), LootRecordType.EVENT, + toGameItems(items), Instant.now()); if (lootTrackerClient != null && config.saveLoot()) { - LootRecord lootRecord = new LootRecord(eventType, client.getLocalPlayer().getName(), LootRecordType.EVENT, - toGameItems(items), Instant.now()); lootTrackerClient.submit(lootRecord); } + if (config.localPersistence()) + { + saveLocalLootRecord(lootRecord); + } } @Subscribe @@ -744,13 +749,18 @@ public class LootTrackerPlugin extends Plugin final LootTrackerItem[] entries = buildEntries(stack(items)); SwingUtilities.invokeLater(() -> panel.add(chestType, client.getLocalPlayer().getName(), -1, entries)); + LootRecord lootRecord = new LootRecord(chestType, client.getLocalPlayer().getName(), + LootRecordType.EVENT, toGameItems(items), Instant.now()); if (lootTrackerClient != null && config.saveLoot()) { - LootRecord lootRecord = new LootRecord(chestType, client.getLocalPlayer().getName(), - LootRecordType.EVENT, toGameItems(items), Instant.now()); lootTrackerClient.submit(lootRecord); } + if (config.localPersistence()) + { + saveLocalLootRecord(lootRecord); + } + inventorySnapshot = null; } } From 3272fc1ee350e6d9622c8bf17a9b64e90271dc04 Mon Sep 17 00:00:00 2001 From: PKLite Date: Fri, 28 Jun 2019 04:36:09 -0400 Subject: [PATCH 4/7] Adds the date filter, need to make changing it update the total Signed-off-by: PKLite --- .../loottracker/LootRecordDateFilter.java | 42 +++++++++++++++++++ .../plugins/loottracker/LootTrackerPanel.java | 35 +++++++++++++++- 2 files changed, 75 insertions(+), 2 deletions(-) create mode 100644 runelite-client/src/main/java/net/runelite/client/plugins/loottracker/LootRecordDateFilter.java diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/loottracker/LootRecordDateFilter.java b/runelite-client/src/main/java/net/runelite/client/plugins/loottracker/LootRecordDateFilter.java new file mode 100644 index 0000000000..abdfbb69e0 --- /dev/null +++ b/runelite-client/src/main/java/net/runelite/client/plugins/loottracker/LootRecordDateFilter.java @@ -0,0 +1,42 @@ +/* + * ****************************************************************************** + * * Copyright (c) 2019 RuneLitePlus + * * Redistributions and modifications of this software are permitted as long as this notice remains in its original unmodified state at the top of this file. + * * If there are any questions comments, or feedback about this software, please direct all inquiries directly to the file authors: + * * ST0NEWALL#9112 + * * RuneLitePlus Discord: https://discord.gg/Q7wFtCe + * * RuneLitePlus website: https://runelitepl.us + * ***************************************************************************** + */ + +package net.runelite.client.plugins.loottracker; + + +import java.time.Duration; +import lombok.Getter; + +public enum LootRecordDateFilter +{ + HOUR("Hour", Duration.ofHours(1)), + DAY("Day", Duration.ofDays(1)), + WEEK("Week", Duration.ofDays(7)), + MONTH("Month", Duration.ofDays(30)), + YEAR("Year", Duration.ofDays(365)), + ALL("All", Duration.ZERO); + + private final String name; + @Getter + private final Duration duration; + + private LootRecordDateFilter(String name, Duration duration) + { + this.name = name; + this.duration = duration; + } + + @Override + public String toString() + { + return this.name; + } +} 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 dc0d7c34d7..178176c854 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 @@ -34,12 +34,15 @@ import java.awt.event.MouseEvent; import java.awt.image.BufferedImage; import java.time.Instant; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collection; import java.util.List; import java.util.Objects; +import java.util.Vector; import javax.swing.BorderFactory; import javax.swing.BoxLayout; import javax.swing.ImageIcon; +import javax.swing.JComboBox; import javax.swing.JLabel; import javax.swing.JMenuItem; import javax.swing.JPanel; @@ -104,6 +107,7 @@ class LootTrackerPanel extends PluginPanel private final JLabel singleLootBtn = new JLabel(); private final JLabel groupedLootBtn = new JLabel(); private final JLabel resetIcon = new JLabel(); + private JComboBox dateFilterComboBox = new JComboBox<>(new Vector(Arrays.asList(LootRecordDateFilter.values()))); // Log collection private final List records = new ArrayList<>(); @@ -114,6 +118,7 @@ class LootTrackerPanel extends PluginPanel private final LootTrackerConfig config; private boolean groupLoot; + private LootRecordDateFilter dateFilter = LootRecordDateFilter.ALL; private boolean hideIgnoredItems; private String currentView; @@ -176,7 +181,7 @@ class LootTrackerPanel extends PluginPanel actionsContainer.setBorder(new EmptyBorder(5, 5, 5, 10)); actionsContainer.setVisible(false); - final JPanel viewControls = new JPanel(new GridLayout(1, 4, 10, 0)); + final JPanel viewControls = new JPanel(new GridLayout(1, 5, 5, 0)); viewControls.setBackground(ColorScheme.DARKER_GRAY_COLOR); singleLootBtn.setIcon(SINGLE_LOOT_VIEW); @@ -271,6 +276,19 @@ class LootTrackerPanel extends PluginPanel } }); + dateFilterComboBox.setSelectedItem(LootRecordDateFilter.ALL); + dateFilterComboBox.setToolTipText("Filter the displayed loot records by date"); + dateFilterComboBox.setMaximumSize(new Dimension(15, 0)); + dateFilterComboBox.setMaximumRowCount(3); + dateFilterComboBox.addItemListener(e -> + { + final LootRecordDateFilter dateFilterSelected = (LootRecordDateFilter) e.getItem(); + dateFilter = dateFilterSelected; + rebuild(); + } + ); + + //viewControls.add(dateFilterComboBox); viewControls.add(resetIcon); viewControls.add(groupedLootBtn); viewControls.add(singleLootBtn); @@ -312,6 +330,7 @@ class LootTrackerPanel extends PluginPanel leftTitleContainer.add(backBtn, BorderLayout.WEST); leftTitleContainer.add(detailsTitle, BorderLayout.CENTER); + actionsContainer.add(dateFilterComboBox); actionsContainer.add(leftTitleContainer, BorderLayout.WEST); actionsContainer.add(viewControls, BorderLayout.EAST); @@ -494,7 +513,15 @@ class LootTrackerPanel extends PluginPanel continue; } } - buildBox(records.get(i)); + if (this.dateFilter.equals(LootRecordDateFilter.ALL)) + { + buildBox(records.get(i)); + continue; + } + if (Instant.now().toEpochMilli() - records.get(i).getTimestamp().toEpochMilli() <= this.dateFilter.getDuration().toMillis()) + { + buildBox(records.get(i)); + } } boxes.forEach(LootTrackerBox::rebuild); @@ -527,6 +554,10 @@ class LootTrackerPanel extends PluginPanel } } + if (!this.dateFilter.equals(LootRecordDateFilter.ALL)) + { + + } // Group all similar loot together if (groupLoot) { From 3fc704431f45af4e6ebb0147a45e487c3ea788ad Mon Sep 17 00:00:00 2001 From: PKLite Date: Fri, 28 Jun 2019 11:33:59 -0400 Subject: [PATCH 5/7] Hiding certain NPCs Signed-off-by: PKLite --- .../plugins/loottracker/LootTrackerBox.java | 6 ++- .../loottracker/LootTrackerConfig.java | 39 +++++++++++++++ .../plugins/loottracker/LootTrackerPanel.java | 50 +++++++++++++++++-- .../loottracker/LootTrackerPlugin.java | 34 +++++++++++++ 4 files changed, 124 insertions(+), 5 deletions(-) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/loottracker/LootTrackerBox.java b/runelite-client/src/main/java/net/runelite/client/plugins/loottracker/LootTrackerBox.java index a7454387e9..0e10bcd1d1 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/loottracker/LootTrackerBox.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/loottracker/LootTrackerBox.java @@ -79,6 +79,7 @@ class LootTrackerBox extends JPanel final String id, @Nullable final String subtitle, final boolean hideIgnoredItems, + @Nullable final Boolean showDate, final BiConsumer onItemToggle) { this.timeStamp = timeStamp; @@ -107,7 +108,10 @@ class LootTrackerBox extends JPanel dateLabel.setFont(FontManager.getRunescapeSmallFont().deriveFont(FontManager.getRunescapeSmallFont().getSize() - 2)); dateLabel.setForeground(Color.LIGHT_GRAY); dateLabel.setText(new Date(timeStamp).toLocaleString()); - logTitle.add(dateLabel, BorderLayout.SOUTH); + if (showDate) + { + logTitle.add(dateLabel, BorderLayout.SOUTH); + } if (!Strings.isNullOrEmpty(subtitle)) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/loottracker/LootTrackerConfig.java b/runelite-client/src/main/java/net/runelite/client/plugins/loottracker/LootTrackerConfig.java index 03179c69b9..c8761c7169 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/loottracker/LootTrackerConfig.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/loottracker/LootTrackerConfig.java @@ -51,6 +51,25 @@ public interface LootTrackerConfig extends Config ) void setIgnoredItems(String key); + @ConfigItem( + keyName = "ignoredNPCs", + name = "Ignored NPCs", + description = "Configures which NPCs should be ignored ", + position = 1, + group = "Filters" + ) + default String getIgnoredNPCs() + { + return ""; + } + + @ConfigItem( + keyName = "ignoredNPCs", + name = "", + description = "" + ) + void setIgnoredNPCs(String key); + @ConfigItem( keyName = "saveLoot", name = "Submit loot tracker data", @@ -169,4 +188,24 @@ public interface LootTrackerConfig extends Config return true; } + @ConfigItem( + keyName = "showDeaths", + name = "Show PvP Deaths", + description = "Shows your deaths to help you calculate PvP profit" + ) + default boolean showDeaths() + { + return true; + } + + @ConfigItem( + keyName = "displayDate", + name = "Display Date", + description = "Displays the date the loot was received" + ) + default boolean displayDate() + { + return true; + } + } 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 178176c854..3bfd94f568 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 @@ -506,6 +506,15 @@ class LootTrackerPanel extends PluginPanel for (int i = start; i < records.size(); i++) { + // Check to see if we should even show this record + if (this.hideIgnoredItems) + { + if (this.plugin.isIgnoredNPC(records.get(i).getTitle())) + { + continue; + } + } + if (this.plugin.client.getGameState().equals(GameState.LOGGED_IN)) { if (!(this.plugin.client.getLocalPlayer().getName().equals(records.get(i).getLocalUsername()))) @@ -554,10 +563,16 @@ class LootTrackerPanel extends PluginPanel } } - if (!this.dateFilter.equals(LootRecordDateFilter.ALL)) + // Check to see if we should even show this record + if (this.hideIgnoredItems) { - + if (this.plugin.isIgnoredNPC(record.getTitle())) + { + return null; + } } + + // Group all similar loot together if (groupLoot) { @@ -578,7 +593,7 @@ class LootTrackerPanel extends PluginPanel // Create box final LootTrackerBox box = new LootTrackerBox(record.getTimestamp().toEpochMilli(), itemManager, record.getTitle(), record.getSubTitle(), - hideIgnoredItems, plugin::toggleItem); + hideIgnoredItems, config.displayDate(), plugin::toggleItem); box.combine(record); // Create popup menu @@ -586,6 +601,26 @@ class LootTrackerPanel extends PluginPanel popupMenu.setBorder(new EmptyBorder(5, 5, 5, 5)); box.setComponentPopupMenu(popupMenu); + // Create Hide Menu item + + final JMenuItem hide; + if (this.hideIgnoredItems) + { + hide = new JMenuItem("Hide " + box.getId()); + } + else + { + hide = new JMenuItem("Unhide " + box.getId()); + } + + hide.addActionListener(e -> + { + this.plugin.toggleNPC(box.getId(), this.hideIgnoredItems); + rebuild(); + }); + + popupMenu.add(hide); + // Create reset menu final JMenuItem reset = new JMenuItem("Reset"); reset.addActionListener(e -> @@ -645,7 +680,14 @@ class LootTrackerPanel extends PluginPanel { if (!record.getLocalUsername().equals(plugin.client.getLocalPlayer().getName())) { - + continue; + } + } + if (!dateFilter.equals(LootRecordDateFilter.ALL)) + { + if (Instant.now().toEpochMilli() - record.getTimestamp().toEpochMilli() + > this.dateFilter.getDuration().toMillis()) + { continue; } } 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 7a98b15cb8..d503b41968 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 @@ -167,6 +167,7 @@ public class LootTrackerPlugin extends Plugin private NavigationButton navButton; private String eventType; private List ignoredItems = new ArrayList<>(); + private List ignoredNPCs = new ArrayList<>(); private Multiset inventorySnapshot; @Getter(AccessLevel.PACKAGE) private LootTrackerClient lootTrackerClient; @@ -268,6 +269,7 @@ public class LootTrackerPlugin extends Plugin protected void startUp() throws Exception { ignoredItems = Text.fromCSV(config.getIgnoredItems()); + ignoredNPCs = Text.fromCSV(config.getIgnoredNPCs()); panel = new LootTrackerPanel(this, itemManager, config); spriteManager.getSpriteAsync(SpriteID.TAB_INVENTORY, 0, panel::loadHeaderIcon); @@ -787,6 +789,38 @@ public class LootTrackerPlugin extends Plugin return ignoredItems.contains(name); } + /** + * Toggles the hidden status for a particular record + * @param name - The String name of the record to toggle the hidden status of + * @param ignore - true to ignore, false to remove + */ + public void toggleNPC(String name, boolean ignore) + { + final Set ignoredNPCSet = new HashSet<>(ignoredNPCs); + + if (ignore) + { + ignoredNPCSet.add(name); + } + else + { + ignoredNPCSet.remove(name); + } + + config.setIgnoredNPCs(Text.toCSV(ignoredNPCSet)); + panel.rebuild(); + } + + /** + * Checks to see if a record name is in the list of ignored NPCs + * @param name - The String of the name to check + * @return - true if it is being ignored, false otherwise + */ + public boolean isIgnoredNPC(String name) + { + return ignoredNPCs.contains(name); + } + @VisibleForTesting private LootTrackerItem buildLootTrackerItem(int itemId, int quantity) { From 4390617d0e178d42ce0746da5e8120ae93e243ef Mon Sep 17 00:00:00 2001 From: PKLite Date: Wed, 3 Jul 2019 04:20:22 -0400 Subject: [PATCH 6/7] test Signed-off-by: PKLite --- .../runelite/client/plugins/loottracker/LootTrackerPanel.java | 1 + .../runelite/client/plugins/loottracker/LootTrackerPlugin.java | 3 +++ 2 files changed, 4 insertions(+) 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 3bfd94f568..b6b7684eeb 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 @@ -477,6 +477,7 @@ class LootTrackerPanel extends PluginPanel { for (LootTrackerRecord r : records) { + if (plugin.isIgnoredNPC(r.getTitle())) for (LootTrackerItem item : r.getItems()) { if (plugin.isIgnored(item.getName()) != item.isIgnored()) 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 0ac8e4b979..b3a5fe8ce3 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 @@ -804,10 +804,12 @@ public class LootTrackerPlugin extends Plugin if (ignore) { ignoredNPCSet.add(name); + ignoredNPCs.add(name); } else { ignoredNPCSet.remove(name); + ignoredNPCs.remove(name); } config.setIgnoredNPCs(Text.toCSV(ignoredNPCSet)); @@ -821,6 +823,7 @@ public class LootTrackerPlugin extends Plugin */ public boolean isIgnoredNPC(String name) { + log.info(ignoredNPCs.toString()); return ignoredNPCs.contains(name); } From d8fbd902ccbb12c72a20b4c9ed1cb2273670e39e Mon Sep 17 00:00:00 2001 From: PKLite Date: Wed, 3 Jul 2019 14:02:41 -0400 Subject: [PATCH 7/7] Bug Fixes Signed-off-by: PKLite --- .../loottracker/LootTrackerPlugin.java | 30 +++++++------------ 1 file changed, 11 insertions(+), 19 deletions(-) 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 b3a5fe8ce3..bd27d3f981 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 @@ -259,6 +259,11 @@ public class LootTrackerPlugin extends Plugin ignoredItems = Text.fromCSV(config.getIgnoredItems()); SwingUtilities.invokeLater(panel::updateIgnoredRecords); } + if (event.getKey().equals("ignoredNPCs")) + { + ignoredNPCs = Text.fromCSV(config.getIgnoredNPCs()); + SwingUtilities.invokeLater(panel::updateIgnoredRecords); + } if (event.getKey().equals("sortType")) { panel.setLootRecordSortType(config.sortType()); @@ -304,20 +309,9 @@ public class LootTrackerPlugin extends Plugin executor.submit(() -> { - - if (config.syncPanel() && lootTrackerClient != null) + if (config.syncPanel()) { lootTrackerClient = new LootTrackerClient(accountSession.getUuid()); - try - { - lootRecords = lootTrackerClient.get(); - } - catch (IOException e) - { - log.debug("Unable to look up loot", e); - return; - } - log.debug("Loaded {} remote data entries", lootRecords.size()); } if (config.localPersistence()) @@ -392,7 +386,7 @@ public class LootTrackerPlugin extends Plugin LootRecord lootRecord = new LootRecord(name, localUsername, LootRecordType.NPC, toGameItems(items), Instant.now()); - if (lootTrackerClient != null && config.saveLoot()) + if (config.saveLoot() && lootTrackerClient != null) { lootTrackerClient.submit(lootRecord); } @@ -416,7 +410,8 @@ public class LootTrackerPlugin extends Plugin { if (config.sendLootValueMessages()) { - if (WorldType.isDeadmanWorld(client.getWorldType()) || WorldType.isHighRiskWorld(client.getWorldType()) || WorldType.isPvpWorld(client.getWorldType()) || client.getVar(Varbits.IN_WILDERNESS) == 1) + if (WorldType.isDeadmanWorld(client.getWorldType()) || WorldType.isHighRiskWorld(client.getWorldType()) || + WorldType.isPvpWorld(client.getWorldType()) || client.getVar(Varbits.IN_WILDERNESS) == 1) { final String totalValue = StackFormatter.quantityToRSStackSize(playerLootReceived.getItems().stream() .mapToInt(itemStack -> itemManager.getItemPrice(itemStack.getId()) * itemStack.getQuantity()).sum()); @@ -439,7 +434,7 @@ public class LootTrackerPlugin extends Plugin { lootTrackerClient.submit(lootRecord); } - if (config.localPersistence() && lootTrackerClient == null) + if (config.localPersistence()) { saveLocalLootRecord(lootRecord); } @@ -695,6 +690,7 @@ public class LootTrackerPlugin extends Plugin { try { + lootRecords.clear(); Files.deleteIfExists(LOOT_RECORDS_FILE.toPath()); } catch (IOException e) @@ -800,16 +796,13 @@ public class LootTrackerPlugin extends Plugin public void toggleNPC(String name, boolean ignore) { final Set ignoredNPCSet = new HashSet<>(ignoredNPCs); - if (ignore) { ignoredNPCSet.add(name); - ignoredNPCs.add(name); } else { ignoredNPCSet.remove(name); - ignoredNPCs.remove(name); } config.setIgnoredNPCs(Text.toCSV(ignoredNPCSet)); @@ -823,7 +816,6 @@ public class LootTrackerPlugin extends Plugin */ public boolean isIgnoredNPC(String name) { - log.info(ignoredNPCs.toString()); return ignoredNPCs.contains(name); }