From 15a5a1910348696a518eccb3bc7ee01633d103b4 Mon Sep 17 00:00:00 2001 From: Tomas Slusny Date: Mon, 2 Apr 2018 04:59:47 +0200 Subject: [PATCH] Cache all ground items and then check their state Cache all ground items on item layer changed events and determine if they should be shown or not in the overlay. Also, update their price in the overlay to be not dependant on the initial state (having price already cached or not). Signed-off-by: Tomas Slusny --- .../grounditems/GroundItemsOverlay.java | 32 +++++++++++++++++-- .../grounditems/GroundItemsPlugin.java | 27 +++------------- 2 files changed, 34 insertions(+), 25 deletions(-) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/grounditems/GroundItemsOverlay.java b/runelite-client/src/main/java/net/runelite/client/plugins/grounditems/GroundItemsOverlay.java index 35d445262e..9490fff478 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/grounditems/GroundItemsOverlay.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/grounditems/GroundItemsOverlay.java @@ -39,11 +39,13 @@ import net.runelite.api.Player; import net.runelite.api.Point; import net.runelite.api.coords.LocalPoint; import net.runelite.api.coords.WorldPoint; +import net.runelite.client.game.ItemManager; import net.runelite.client.ui.overlay.Overlay; import net.runelite.client.ui.overlay.OverlayLayer; import net.runelite.client.ui.overlay.OverlayPosition; import net.runelite.client.ui.overlay.components.TextComponent; import net.runelite.client.util.StackFormatter; +import net.runelite.http.api.item.ItemPrice; public class GroundItemsOverlay extends Overlay { @@ -65,15 +67,17 @@ public class GroundItemsOverlay extends Overlay private final StringBuilder itemStringBuilder = new StringBuilder(); private final TextComponent textComponent = new TextComponent(); private final Map offsetMap = new HashMap<>(); + private final ItemManager itemManager; @Inject - public GroundItemsOverlay(Client client, GroundItemsPlugin plugin, GroundItemsConfig config) + public GroundItemsOverlay(Client client, GroundItemsPlugin plugin, GroundItemsConfig config, ItemManager itemManager) { setPosition(OverlayPosition.DYNAMIC); setLayer(OverlayLayer.ABOVE_SCENE); this.client = client; this.plugin = plugin; this.config = config; + this.itemManager = itemManager; } @Override @@ -102,7 +106,32 @@ public class GroundItemsOverlay extends Overlay } final boolean highlighted = plugin.isHighlighted(item.getName()); + final boolean hidden = plugin.isHidden(item.getName()); + if (!plugin.isHotKeyPressed()) + { + // Do not display hidden items + if (hidden) + { + continue; + } + + // Do not display non-highlighted items when only highlighted items should be shown + if (config.showHighlightedOnly() && !highlighted) + { + continue; + } + } + + // Update GE price for item + final ItemPrice itemPrice = itemManager.getItemPriceAsync(item.getItemId()); + + if (itemPrice != null && itemPrice.getPrice() > 0) + { + item.setGePrice(itemPrice.getPrice() * item.getQuantity()); + } + + // Do not display items that are under HA or GE price and are not highlighted if (!plugin.isHotKeyPressed() && !highlighted && ((item.getGePrice() > 0 && item.getGePrice() < config.getHideUnderGeValue()) || item.getHaPrice() < config.getHideUnderHAValue())) @@ -110,7 +139,6 @@ public class GroundItemsOverlay extends Overlay continue; } - final boolean hidden = plugin.isHidden(item.getName()); final Color color = getCostColor(item.getGePrice() > 0 ? item.getGePrice() : item.getHaPrice(), highlighted, hidden); itemStringBuilder.append(item.getName()); diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/grounditems/GroundItemsPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/grounditems/GroundItemsPlugin.java index f9e97919d3..5f344ab1b9 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/grounditems/GroundItemsPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/grounditems/GroundItemsPlugin.java @@ -279,21 +279,6 @@ public class GroundItemsPlugin extends Plugin final ItemComposition itemComposition = itemManager.getItemComposition(itemId); final int realItemId = itemComposition.getNote() != -1 ? itemComposition.getLinkedNoteId() : itemId; final int alchPrice = Math.round(itemComposition.getPrice() * HIGH_ALCHEMY_CONSTANT); - final String name = itemComposition.getName(); - - final boolean hidden = isHidden(name); - - if (!isHotKeyPressed() && hidden) - { - return null; - } - - final boolean highlighted = isHighlighted(name); - - if (config.showHighlightedOnly() && !isHotKeyPressed() && !highlighted) - { - return null; - } final GroundItem groundItem = GroundItem.builder() .id(itemId) @@ -304,16 +289,12 @@ public class GroundItemsPlugin extends Plugin .haPrice(alchPrice * item.getQuantity()) .build(); - // Set the correct item price + + // Update item price in case it is coins if (realItemId == COINS) { - groundItem.setHaPrice(item.getQuantity()); - groundItem.setGePrice(item.getQuantity()); - } - else - { - final ItemPrice itemPrice = itemManager.getItemPriceAsync(realItemId); - groundItem.setGePrice(itemPrice != null ? itemPrice.getPrice() * item.getQuantity() : 0); + groundItem.setHaPrice(groundItem.getQuantity()); + groundItem.setGePrice(groundItem.getQuantity()); } return groundItem;