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 <slusnucky@gmail.com>
This commit is contained in:
@@ -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<WorldPoint, Integer> 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());
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user