From 3fc704431f45af4e6ebb0147a45e487c3ea788ad Mon Sep 17 00:00:00 2001 From: PKLite Date: Fri, 28 Jun 2019 11:33:59 -0400 Subject: [PATCH] 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) {