diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/grounditems/GroundItemsConfig.java b/runelite-client/src/main/java/net/runelite/client/plugins/grounditems/GroundItemsConfig.java index 07d7461ff9..e7cfa87ae8 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/grounditems/GroundItemsConfig.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/grounditems/GroundItemsConfig.java @@ -71,11 +71,44 @@ public interface GroundItemsConfig extends Config return false; } + @ConfigItem( + keyName = "showMenuItemQuantities", + name = "Show Menu Item Quantities", + description = "Configures whether or not to show the item quantities in the menu", + position = 4 + ) + default boolean showMenuItemQuantities() + { + return true; + } + + @ConfigItem( + keyName = "highlightMenuOption", + name = "Highlight Menu Option", + description = "Configures whether or not to highlight the menu option", + position = 5 + ) + default boolean highlightMenuOption() + { + return true; + } + + @ConfigItem( + keyName = "highlightMenuItemName", + name = "Highlight Menu Item Name", + description = "Configures whether or not to highlight the menu item name", + position = 6 + ) + default boolean highlightMenuItemName() + { + return false; + } + @ConfigItem( keyName = "hideUnderGeValue", name = "Hide < GE Value", description = "Configures hidden ground items under GE value", - position = 4 + position = 7 ) default int getHideUnderGeValue() { @@ -86,7 +119,7 @@ public interface GroundItemsConfig extends Config keyName = "hideUnderHaValue", name = "Hide < HA Value", description = "Configures hidden ground items under High Alch value", - position = 5 + position = 8 ) default int getHideUnderHAValue() { @@ -97,7 +130,7 @@ public interface GroundItemsConfig extends Config keyName = "highlightedItems", name = "Highlighted Items", description = "Configures specifically highlighted ground items. Format: (item), (item)", - position = 6 + position = 9 ) default String getHighlightItems() { @@ -108,7 +141,7 @@ public interface GroundItemsConfig extends Config keyName = "hiddenItems", name = "Hidden Items", description = "Configures hidden ground items. Format: (item), (item)", - position = 7 + position = 10 ) default String getHiddenItems() { @@ -119,7 +152,7 @@ public interface GroundItemsConfig extends Config keyName = "defaultColor", name = "Default items color", description = "Configures the color for default, non-highlighted items", - position = 8 + position = 11 ) default Color defaultColor() { @@ -130,7 +163,7 @@ public interface GroundItemsConfig extends Config keyName = "highlightedColor", name = "Highlighted items color", description = "Configures the color for highlighted items", - position = 9 + position = 12 ) default Color highlightedColor() { @@ -141,7 +174,7 @@ public interface GroundItemsConfig extends Config keyName = "lowValueColor", name = "Low value items color", description = "Configures the color for low value items", - position = 10 + position = 13 ) default Color lowValueColor() { @@ -152,7 +185,7 @@ public interface GroundItemsConfig extends Config keyName = "mediumValueColor", name = "Medium value items color", description = "Configures the color for medium value items", - position = 11 + position = 14 ) default Color mediumValueColor() { @@ -163,7 +196,7 @@ public interface GroundItemsConfig extends Config keyName = "highValueColor", name = "High value items color", description = "Configures the color for high value items", - position = 12 + position = 15 ) default Color highValueColor() { @@ -174,7 +207,7 @@ public interface GroundItemsConfig extends Config keyName = "insaneValueColor", name = "Insane value items color", description = "Configures the color for insane value items", - position = 13 + position = 16 ) default Color insaneValueColor() { 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 34adea197d..9a609bd5e5 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 @@ -70,7 +70,7 @@ public class GroundItemsOverlay extends Overlay // The 15 pixel gap between each drawn ground item. private static final int STRING_GAP = 15; // Threshold for highlighting items as blue. - private static final int LOW_VALUE = 20_000; + static final int LOW_VALUE = 20_000; // Threshold for highlighting items as green. private static final int MEDIUM_VALUE = 100_000; // Threshold for highlighting items as amber. @@ -80,7 +80,7 @@ public class GroundItemsOverlay extends Overlay // Used when getting High Alchemy value - multiplied by general store price. private static final float HIGH_ALCHEMY_CONSTANT = 0.6f; // Regex for splitting the hidden items in the config. - private static final String DELIMITER_REGEX = "\\s*,\\s*"; + static final String DELIMITER_REGEX = "\\s*,\\s*"; // ItemID for coins private static final int COINS = ItemID.COINS_995; @@ -242,23 +242,8 @@ public class GroundItemsOverlay extends Overlay if (itemPrice != null && config.showGEPrice()) { int cost = itemPrice.getPrice() * quantity; - // set the color according to rarity, if possible - if (cost >= INSANE_VALUE) // 10,000,000 gp - { - textColor = config.insaneValueColor(); - } - else if (cost >= HIGH_VALUE) // 1,000,000 gp - { - textColor = config.highValueColor(); - } - else if (cost >= MEDIUM_VALUE) // 100,000 gp - { - textColor = config.mediumValueColor(); - } - else if (cost >= LOW_VALUE) // 20,000 gp - { - textColor = config.lowValueColor(); - } + + textColor = getCostColor(cost); itemStringBuilder.append(" (EX: ") .append(StackFormatter.quantityToStackSize(cost)) @@ -294,4 +279,30 @@ public class GroundItemsOverlay extends Overlay return null; } + + Color getCostColor(int cost) + { + // set the color according to rarity, if possible + if (cost >= INSANE_VALUE) // 10,000,000 gp + { + return config.insaneValueColor(); + } + else if (cost >= HIGH_VALUE) // 1,000,000 gp + { + return config.highValueColor(); + } + else if (cost >= MEDIUM_VALUE) // 100,000 gp + { + return config.mediumValueColor(); + } + else if (cost >= LOW_VALUE) // 20,000 gp + { + return config.lowValueColor(); + } + else + { + return config.defaultColor(); + } + } + } 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 bf1c8b1c90..d2d272ed37 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 @@ -24,21 +24,45 @@ */ package net.runelite.client.plugins.grounditems; +import com.google.common.eventbus.Subscribe; import com.google.inject.Provides; +import java.awt.Color; +import java.util.Arrays; +import java.util.List; import javax.inject.Inject; +import net.runelite.api.Client; +import net.runelite.api.Item; +import net.runelite.api.ItemComposition; +import net.runelite.api.ItemLayer; +import net.runelite.api.MenuEntry; +import net.runelite.api.Node; +import net.runelite.api.Region; +import net.runelite.api.Tile; +import net.runelite.api.events.MenuEntryAdded; import net.runelite.client.config.ConfigManager; +import net.runelite.client.game.ItemManager; import net.runelite.client.plugins.Plugin; import net.runelite.client.plugins.PluginDescriptor; import net.runelite.client.ui.overlay.Overlay; +import net.runelite.http.api.item.ItemPrice; @PluginDescriptor( name = "Ground Items" ) public class GroundItemsPlugin extends Plugin { + @Inject + private Client client; + @Inject private ConfigManager configManager; + @Inject + private ItemManager itemManager; + + @Inject + private GroundItemsConfig config; + @Inject private GroundItemsOverlay overlay; @@ -54,4 +78,95 @@ public class GroundItemsPlugin extends Plugin return overlay; } + private ItemPrice getItemPrice(ItemComposition itemComposition) + { + if (itemComposition.getNote() != -1) + { + return itemManager.getItemPriceAsync(itemComposition.getLinkedNoteId()); + } + else + { + return itemManager.getItemPriceAsync(itemComposition.getId()); + } + } + + @Subscribe + public void onMenuEntryAdded(MenuEntryAdded event) + { + if ((config.highlightMenuOption() || config.highlightMenuItemName()) && event.getOption().equals("Take")) + { + String hiddenItemsStr = config.getHiddenItems().toLowerCase(); + List hiddenItems = Arrays.asList(hiddenItemsStr.split(GroundItemsOverlay.DELIMITER_REGEX)); + + String highlightItemsStr = config.getHighlightItems().toLowerCase(); + List highlightedItems = Arrays.asList(highlightItemsStr.split(GroundItemsOverlay.DELIMITER_REGEX)); + + int itemId = event.getIdentifier(); + ItemComposition itemComposition = client.getItemDefinition(itemId); + String name = itemComposition.getName().toLowerCase(); + + if (hiddenItems.contains(name)) + { + return; + } + + Region region = client.getRegion(); + Tile tile = region.getTiles()[client.getPlane()][event.getActionParam0()][event.getActionParam1()]; + ItemLayer itemLayer = tile.getItemLayer(); + + MenuEntry[] menuEntries = client.getMenuEntries(); + MenuEntry lastEntry = menuEntries[menuEntries.length - 1]; + + int quantity = 1; + Node current = itemLayer.getBottom(); + while (current instanceof Item) + { + Item item = (Item) current; + if (item.getId() == itemId) + { + quantity = item.getQuantity(); + } + current = current.getNext(); + } + + ItemPrice itemPrice = getItemPrice(itemComposition); + int price = itemPrice == null ? itemComposition.getPrice() : itemPrice.getPrice(); + int cost = quantity * price; + + Color color = null; + + if (cost >= GroundItemsOverlay.LOW_VALUE) + { + color = overlay.getCostColor(cost); + } + + if (highlightedItems.contains(name)) + { + color = config.highlightedColor(); + } + + if (color != null) + { + String hexColor = Integer.toHexString(color.getRGB() & 0xFFFFFF); + String colTag = ""; + if (config.highlightMenuOption()) + { + lastEntry.setOption(colTag + "Take"); + } + if (config.highlightMenuItemName()) + { + String target = lastEntry.getTarget().substring(lastEntry.getTarget().indexOf(">") + 1); + lastEntry.setTarget(colTag + target); + } + } + + if (config.showMenuItemQuantities() && itemComposition.isStackable() && quantity > 1) + { + lastEntry.setTarget(lastEntry.getTarget() + " (" + quantity + ")"); + } + + client.setMenuEntries(menuEntries); + } + } + }