Added per item highlighting/hiding to GroundItems (#96)

This commit is contained in:
Abel Briggs
2017-06-28 08:49:48 -05:00
committed by Adam
parent 0f1bd9440d
commit d8baaf99d0
2 changed files with 49 additions and 7 deletions

View File

@@ -58,10 +58,30 @@ public interface GroundItemsConfig
@ConfigItem( @ConfigItem(
keyName = "showHAValue", keyName = "showHAValue",
name = "Show High Alchemy Values", name = "Show High Alchemy Values",
description = "Configure whether or not to draw High Alchemy values alongside ground items" description = "Configures whether or not to draw High Alchemy values alongside ground items"
) )
default boolean showHAValue() default boolean showHAValue()
{ {
return false; return false;
} }
@ConfigItem(
keyName = "hiddenItems",
name = "Hidden Items",
description = "Configures hidden ground items. Format: (item), (item)"
)
default String getHiddenItems()
{
return "";
}
@ConfigItem(
keyName = "highlightedItems",
name = "Highlighted Items",
description = "Configures specifically highlighted ground items. Format: (item), (item)"
)
default String getHighlightItems()
{
return "";
}
} }

View File

@@ -33,6 +33,7 @@ import java.util.Collections;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Arrays;
import net.runelite.api.Client; import net.runelite.api.Client;
import net.runelite.api.GameState; import net.runelite.api.GameState;
import net.runelite.api.Item; import net.runelite.api.Item;
@@ -73,8 +74,12 @@ public class GroundItemsOverlay extends Overlay
// Threshold for highlighting items as pink. // Threshold for highlighting items as pink.
private static final int INSANE_VALUE = 10_000_000; private static final int INSANE_VALUE = 10_000_000;
private static final Color FADED_PINK = new Color(255, 102, 178); private static final Color FADED_PINK = new Color(255, 102, 178);
// Color to use if an item is highlighted in the config.
private static final Color PURPLE = new Color(170, 0, 255);
// Used when getting High Alchemy value - multiplied by general store price. // Used when getting High Alchemy value - multiplied by general store price.
private static final float HIGH_ALCHEMY_CONSTANT = 0.6f; 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*";
private final Client client = RuneLite.getClient(); private final Client client = RuneLite.getClient();
private final GroundItemsConfig config; private final GroundItemsConfig config;
@@ -108,6 +113,13 @@ public class GroundItemsOverlay extends Overlay
// return null; // return null;
//} //}
// gets the hidden/highlighted items from the text box in the config
String configItems = config.getHiddenItems();
List<String> hiddenItems = Arrays.asList(configItems.split(DELIMITER_REGEX));
// note: both of these lists are immutable
configItems = config.getHighlightItems();
List<String> highlightedItems = Arrays.asList(configItems.split(DELIMITER_REGEX));
Region region = client.getRegion(); Region region = client.getRegion();
Tile[][][] tiles = region.getTiles(); Tile[][][] tiles = region.getTiles();
FontMetrics fm = graphics.getFontMetrics(); FontMetrics fm = graphics.getFontMetrics();
@@ -149,15 +161,20 @@ public class GroundItemsOverlay extends Overlay
Item item = (Item) current; Item item = (Item) current;
int itemId = item.getId(); int itemId = item.getId();
int itemQuantity = item.getQuantity(); int itemQuantity = item.getQuantity();
// Item does not support getting the name, so we need to get the ItemComposition instead
ItemComposition itemDefinition = client.getItemDefinition(itemId);
Integer currentQuantity = items.get(itemId); Integer currentQuantity = items.get(itemId);
if (currentQuantity == null) if (!hiddenItems.contains(itemDefinition.getName()))
{ {
items.put(itemId, itemQuantity); if (currentQuantity == null)
} {
else items.put(itemId, itemQuantity);
{ }
items.put(itemId, currentQuantity + itemQuantity); else
{
items.put(itemId, currentQuantity + itemQuantity);
}
} }
current = current.getNext(); current = current.getNext();
@@ -232,6 +249,11 @@ public class GroundItemsOverlay extends Overlay
.append(" gp)"); .append(" gp)");
} }
if (highlightedItems.contains(item.getName()))
{
textColor = PURPLE;
}
String itemString = itemStringBuilder.toString(); String itemString = itemStringBuilder.toString();
itemStringBuilder.setLength(0); itemStringBuilder.setLength(0);