Skip to content

Commit

Permalink
Add colored inventory tags (hex-agon#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
whiitehead authored Oct 30, 2024
1 parent 76480f0 commit 07438dc
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
import net.runelite.client.ui.FontManager;
import net.runelite.client.ui.overlay.WidgetItemOverlay;

import javax.annotation.Nullable;
import javax.inject.Inject;
import java.awt.Color;
import java.awt.Graphics2D;

public class InventoryPotionOverlay extends WidgetItemOverlay {

private final MasteringMixologyPlugin plugin;
private final MasteringMixologyConfig config;

Expand All @@ -22,19 +22,43 @@ public class InventoryPotionOverlay extends WidgetItemOverlay {

@Override
public void renderItemOverlay(Graphics2D graphics2D, int itemId, WidgetItem widgetItem) {
if (!plugin.isInLab() || !config.identifyPotions()) {
if (!plugin.isInLab() || config.inventoryPotionTagType() == InventoryPotionTagType.NONE) {
return;
}

var potion = PotionType.fromItemId(itemId);

if (potion == null) {
return;
}

var bounds = widgetItem.getCanvasBounds();
var x = bounds.x;
var y = bounds.y + 13;

drawRecipe(graphics2D, potion, x + 1, y + 1, Color.BLACK); // Drop shadow

if (config.inventoryPotionTagType() == InventoryPotionTagType.COLORED) {
drawRecipe(graphics2D, potion, x, y, null);
return;
}

drawRecipe(graphics2D, potion, x, y, Color.WHITE);
}

private void drawRecipe(Graphics2D graphics2D, PotionType potion, int x, int y, @Nullable Color color) {
graphics2D.setFont(FontManager.getRunescapeSmallFont());

graphics2D.setColor(Color.WHITE);
graphics2D.drawString(potion.abbreviation(), bounds.x - 1, bounds.y + 15);
if (color != null) {
graphics2D.setColor(color);
graphics2D.drawString(potion.abbreviation(), x, y);
return;
}

for (var component : potion.components()) {
graphics2D.setColor(Color.decode("#" + component.color()));
graphics2D.drawString(String.valueOf(component.character()), x, y);
x += graphics2D.getFontMetrics().charWidth(component.character());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package work.fking.masteringmixology;

public enum InventoryPotionTagType {
NONE,
COLORED,
WHITE,
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ public interface MasteringMixologyConfig extends Config {
)
String HIGHLIGHTS = "Highlights";

@ConfigItem(
keyName = "inventoryPotionTags",
name = "Inventory Potion Tags",
description = "How potions should be tagged in the inventory",
position = 1
)
default InventoryPotionTagType inventoryPotionTagType() {
return InventoryPotionTagType.WHITE;
}

@ConfigItem(
keyName = "potionOrderSorting",
name = "Order sorting",
Expand Down Expand Up @@ -62,16 +72,6 @@ default boolean highlightQuickActionEvents() {
return true;
}

@ConfigItem(
keyName = "identifyPotions",
name = "Identify potions",
description = "Identify potions in your inventory",
position = 2
)
default boolean identifyPotions() {
return true;
}

@ConfigItem(
keyName = "displayResin",
name = "Display resin amount",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ public void onItemContainerChanged(ItemContainerChanged event) {
for (var item : inventory.getItems()) {
var potionType = PotionType.fromItemId(item.getId());

if (potionType == null) {
if (potionType == null || potionType.modifiedItemId() == item.getId()) {
continue;
}
for (var order : potionOrders) {
Expand Down
29 changes: 18 additions & 11 deletions src/main/java/work/fking/masteringmixology/PotionType.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@
import static work.fking.masteringmixology.PotionComponent.MOX;

public enum PotionType {
MAMMOTH_MIGHT_MIX(ItemID.MAMMOTHMIGHT_MIX, 1900, MOX, MOX, MOX),
MYSTIC_MANA_AMALGAM(ItemID.MYSTIC_MANA_AMALGAM, 2150, MOX, MOX, AGA),
MARLEYS_MOONLIGHT(ItemID.MARLEYS_MOONLIGHT, 2400, MOX, MOX, LYE),
ALCO_AUGMENTATOR(ItemID.ALCOAUGMENTATOR, 1900, AGA, AGA, AGA),
AZURE_AURA_MIX(ItemID.AZURE_AURA_MIX, 2650, AGA, AGA, MOX),
AQUALUX_AMALGAM(ItemID.AQUALUX_AMALGAM, 2900, AGA, LYE, AGA),
LIPLACK_LIQUOR(ItemID.LIPLACK_LIQUOR, 1900, LYE, LYE, LYE),
MEGALITE_LIQUID(ItemID.MEGALITE_LIQUID, 3150, MOX, LYE, LYE),
ANTI_LEECH_LOTION(ItemID.ANTILEECH_LOTION, 3400, AGA, LYE, LYE),
MIXALOT(ItemID.MIXALOT, 3650, MOX, AGA, LYE);
MAMMOTH_MIGHT_MIX(ItemID.MAMMOTHMIGHT_MIX, ItemID.MAMMOTHMIGHT_MIX_30021, 1900, MOX, MOX, MOX),
MYSTIC_MANA_AMALGAM(ItemID.MYSTIC_MANA_AMALGAM, ItemID.MYSTIC_MANA_AMALGAM_30022, 2150, MOX, MOX, AGA),
MARLEYS_MOONLIGHT(ItemID.MARLEYS_MOONLIGHT, ItemID.MARLEYS_MOONLIGHT_30023, 2400, MOX, MOX, LYE),
ALCO_AUGMENTATOR(ItemID.ALCOAUGMENTATOR, ItemID.ALCOAUGMENTATOR_30024, 1900, AGA, AGA, AGA),
AZURE_AURA_MIX(ItemID.AZURE_AURA_MIX, ItemID.AZURE_AURA_MIX_30026, 2650, AGA, AGA, MOX),
AQUALUX_AMALGAM(ItemID.AQUALUX_AMALGAM, ItemID.AQUALUX_AMALGAM_30025, 2900, AGA, LYE, AGA),
LIPLACK_LIQUOR(ItemID.LIPLACK_LIQUOR, ItemID.LIPLACK_LIQUOR_30027, 1900, LYE, LYE, LYE),
MEGALITE_LIQUID(ItemID.MEGALITE_LIQUID, ItemID.MEGALITE_LIQUID_30029, 3150, MOX, LYE, LYE),
ANTI_LEECH_LOTION(ItemID.ANTILEECH_LOTION, ItemID.ANTILEECH_LOTION_30028, 3400, AGA, LYE, LYE),
MIXALOT(ItemID.MIXALOT, ItemID.MIXALOT_30030, 3650, MOX, AGA, LYE);

public static final PotionType[] TYPES = PotionType.values();

Expand All @@ -30,19 +30,22 @@ public enum PotionType {
var builder = new ImmutableMap.Builder<Integer, PotionType>();
for (var p : PotionType.values()) {
builder.put(p.itemId(), p);
builder.put(p.modifiedItemId(), p);
}
ITEM_MAP = builder.build();
}

private final int itemId;
private final int modifiedItemId;
private final String recipe;
private final String abbreviation;
private final int experience;
private final PotionComponent[] components;


PotionType(int itemId, int experience, PotionComponent... components) {
PotionType(int itemId, int modifiedItemId, int experience, PotionComponent... components) {
this.itemId = itemId;
this.modifiedItemId = modifiedItemId;
this.recipe = colorizeRecipe(components);
this.experience = experience;
this.components = components;
Expand Down Expand Up @@ -77,6 +80,10 @@ public int itemId() {
return itemId;
}

public int modifiedItemId() {
return modifiedItemId;
}

public String recipe() {
return recipe;
}
Expand Down

0 comments on commit 07438dc

Please sign in to comment.