Skip to content

Commit

Permalink
inventory tags: add fill tag option
Browse files Browse the repository at this point in the history
This changes the display mode selector to be several separate options so
that users can select multiple, such as outline and fill.

Co-authored-by: Jordan <[email protected]>
Co-authored-by: 1jz <[email protected]>
  • Loading branch information
3 people committed Jan 24, 2021
1 parent 46434c3 commit f6953f3
Show file tree
Hide file tree
Showing 3 changed files with 112 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,74 @@
import net.runelite.client.config.Config;
import net.runelite.client.config.ConfigGroup;
import net.runelite.client.config.ConfigItem;
import net.runelite.client.config.ConfigSection;
import net.runelite.client.config.Range;

@ConfigGroup("inventorytags")
@ConfigGroup(InventoryTagsConfig.GROUP)
public interface InventoryTagsConfig extends Config
{
enum DisplayMode
String GROUP = "inventorytags";

@ConfigSection(
name = "Tag display mode",
description = "How tags are displayed in the inventory",
position = 0
)
String tagStyleSection = "tagStyleSection";

@ConfigItem(
position = 0,
keyName = "showTagOutline",
name = "Outline",
description = "Configures whether or not item tags show be outlined",
section = tagStyleSection
)
default boolean showTagOutline()
{
OUTLINE,
UNDERLINE
return true;
}

String GROUP = "inventorytags";
@ConfigItem(
position = 1,
keyName = "tagUnderline",
name = "Underline",
description = "Configures whether or not item tags should be underlined",
section = tagStyleSection
)
default boolean showTagUnderline()
{
return false;
}

@ConfigItem(
position = 0,
position = 2,
keyName = "tagFill",
name = "Fill",
description = "Configures whether or not item tags should be filled",
section = tagStyleSection
)
default boolean showTagFill()
{
return false;
}

@Range(
max = 255
)
@ConfigItem(
position = 3,
keyName = "fillOpacity",
name = "Fill opacity",
description = "Configures the opacity of the tag \"Fill\"",
section = tagStyleSection
)
default int fillOpacity()
{
return 50;
}

@ConfigItem(
position = 1,
keyName = "groupColor1",
name = "Group 1 Color",
description = "Color of the Tag"
Expand All @@ -52,7 +106,7 @@ default Color getGroup1Color()
}

@ConfigItem(
position = 1,
position = 2,
keyName = "groupColor2",
name = "Group 2 Color",
description = "Color of the Tag"
Expand All @@ -63,7 +117,7 @@ default Color getGroup2Color()
}

@ConfigItem(
position = 2,
position = 3,
keyName = "groupColor3",
name = "Group 3 Color",
description = "Color of the Tag"
Expand All @@ -74,7 +128,7 @@ default Color getGroup3Color()
}

@ConfigItem(
position = 3,
position = 4,
keyName = "groupColor4",
name = "Group 4 Color",
description = "Color of the Tag"
Expand All @@ -85,7 +139,7 @@ default Color getGroup4Color()
}

@ConfigItem(
position = 4,
position = 5,
keyName = "groupColor5",
name = "Group 5 Color",
description = "Color of the Tag"
Expand All @@ -96,7 +150,7 @@ default Color getGroup5Color()
}

@ConfigItem(
position = 5,
position = 6,
keyName = "groupColor6",
name = "Group 6 Color",
description = "Color of the Tag"
Expand All @@ -105,15 +159,4 @@ default Color getGroup6Color()
{
return new Color(0, 255, 255);
}

@ConfigItem(
position = 6,
keyName = "displayMode",
name = "Display mode",
description = "How tags are displayed in the inventory"
)
default DisplayMode getDisplayMode()
{
return DisplayMode.OUTLINE;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,26 @@
*/
package net.runelite.client.plugins.inventorytags;

import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Rectangle;
import java.awt.image.BufferedImage;
import javax.inject.Inject;
import net.runelite.api.widgets.WidgetItem;
import net.runelite.client.game.ItemManager;
import net.runelite.client.plugins.inventorytags.InventoryTagsConfig.DisplayMode;
import net.runelite.client.ui.overlay.WidgetItemOverlay;
import net.runelite.client.util.ColorUtil;
import net.runelite.client.util.ImageUtil;

public class InventoryTagsOverlay extends WidgetItemOverlay
{
private final ItemManager itemManager;
private final InventoryTagsPlugin plugin;
private final InventoryTagsConfig config;
private final Cache<Long, Image> fillCache;

@Inject
private InventoryTagsOverlay(ItemManager itemManager, InventoryTagsPlugin plugin, InventoryTagsConfig config)
Expand All @@ -48,6 +53,10 @@ private InventoryTagsOverlay(ItemManager itemManager, InventoryTagsPlugin plugin
this.config = config;
showOnEquipment();
showOnInventory();
fillCache = CacheBuilder.newBuilder()
.concurrencyLevel(1)
.maximumSize(32)
.build();
}

@Override
Expand All @@ -57,16 +66,22 @@ public void renderItemOverlay(Graphics2D graphics, int itemId, WidgetItem widget
if (group != null)
{
final Color color = plugin.getGroupNameColor(group);
final DisplayMode displayMode = config.getDisplayMode();
if (color != null)
{
Rectangle bounds = widgetItem.getCanvasBounds();
if (displayMode == DisplayMode.OUTLINE)
if (config.showTagOutline())
{
final BufferedImage outline = itemManager.getItemOutline(itemId, widgetItem.getQuantity(), color);
graphics.drawImage(outline, (int) bounds.getX(), (int) bounds.getY(), null);
}
else

if (config.showTagFill())
{
final Image image = getFillImage(color, widgetItem.getId(), widgetItem.getQuantity());
graphics.drawImage(image, (int) bounds.getX(), (int) bounds.getY(), null);
}

if (config.showTagUnderline())
{
int heightOffSet = (int) bounds.getY() + (int) bounds.getHeight() + 2;
graphics.setColor(color);
Expand All @@ -75,4 +90,22 @@ public void renderItemOverlay(Graphics2D graphics, int itemId, WidgetItem widget
}
}
}

private Image getFillImage(Color color, int itemId, int qty)
{
long key = (((long) itemId) << 32) | qty;
Image image = fillCache.getIfPresent(key);
if (image == null)
{
final Color fillColor = ColorUtil.colorWithAlpha(color, config.fillOpacity());
image = ImageUtil.fillImage(itemManager.getImage(itemId, qty, false), fillColor);
fillCache.put(key, image);
}
return image;
}

void invalidateCache()
{
fillCache.invalidateAll();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import net.runelite.api.widgets.WidgetInfo;
import net.runelite.client.config.ConfigManager;
import net.runelite.client.eventbus.Subscribe;
import net.runelite.client.events.ConfigChanged;
import net.runelite.client.menus.MenuManager;
import net.runelite.client.menus.WidgetMenuOption;
import net.runelite.client.plugins.Plugin;
Expand Down Expand Up @@ -147,6 +148,15 @@ protected void shutDown() throws Exception
editorMode = false;
}

@Subscribe
public void onConfigChanged(ConfigChanged configChanged)
{
if (configChanged.getGroup().equals(InventoryTagsConfig.GROUP))
{
overlay.invalidateCache();
}
}

@Subscribe
public void onWidgetMenuOptionClicked(final WidgetMenuOptionClicked event)
{
Expand Down

0 comments on commit f6953f3

Please sign in to comment.