From 07438dc00fdbf983d19515a9fdc5a7b3ff4bcbf6 Mon Sep 17 00:00:00 2001 From: Caleb Whitehead Date: Wed, 30 Oct 2024 06:46:04 -0700 Subject: [PATCH 1/2] Add colored inventory tags (#78) --- .../InventoryPotionOverlay.java | 32 ++++++++++++++++--- .../InventoryPotionTagType.java | 7 ++++ .../MasteringMixologyConfig.java | 20 ++++++------ .../MasteringMixologyPlugin.java | 2 +- .../fking/masteringmixology/PotionType.java | 29 ++++++++++------- 5 files changed, 64 insertions(+), 26 deletions(-) create mode 100644 src/main/java/work/fking/masteringmixology/InventoryPotionTagType.java diff --git a/src/main/java/work/fking/masteringmixology/InventoryPotionOverlay.java b/src/main/java/work/fking/masteringmixology/InventoryPotionOverlay.java index a907f33..993a758 100644 --- a/src/main/java/work/fking/masteringmixology/InventoryPotionOverlay.java +++ b/src/main/java/work/fking/masteringmixology/InventoryPotionOverlay.java @@ -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; @@ -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()); + } } } diff --git a/src/main/java/work/fking/masteringmixology/InventoryPotionTagType.java b/src/main/java/work/fking/masteringmixology/InventoryPotionTagType.java new file mode 100644 index 0000000..d2a9b41 --- /dev/null +++ b/src/main/java/work/fking/masteringmixology/InventoryPotionTagType.java @@ -0,0 +1,7 @@ +package work.fking.masteringmixology; + +public enum InventoryPotionTagType { + NONE, + COLORED, + WHITE, +} diff --git a/src/main/java/work/fking/masteringmixology/MasteringMixologyConfig.java b/src/main/java/work/fking/masteringmixology/MasteringMixologyConfig.java index e45a8f1..ab5e3f7 100644 --- a/src/main/java/work/fking/masteringmixology/MasteringMixologyConfig.java +++ b/src/main/java/work/fking/masteringmixology/MasteringMixologyConfig.java @@ -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", @@ -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", diff --git a/src/main/java/work/fking/masteringmixology/MasteringMixologyPlugin.java b/src/main/java/work/fking/masteringmixology/MasteringMixologyPlugin.java index 4b8172f..44ba9dc 100644 --- a/src/main/java/work/fking/masteringmixology/MasteringMixologyPlugin.java +++ b/src/main/java/work/fking/masteringmixology/MasteringMixologyPlugin.java @@ -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) { diff --git a/src/main/java/work/fking/masteringmixology/PotionType.java b/src/main/java/work/fking/masteringmixology/PotionType.java index 9222815..bbb12ef 100644 --- a/src/main/java/work/fking/masteringmixology/PotionType.java +++ b/src/main/java/work/fking/masteringmixology/PotionType.java @@ -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(); @@ -30,19 +30,22 @@ public enum PotionType { var builder = new ImmutableMap.Builder(); 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; @@ -77,6 +80,10 @@ public int itemId() { return itemId; } + public int modifiedItemId() { + return modifiedItemId; + } + public String recipe() { return recipe; } From d8d59f98075dbb851a1fef8549d25bdf31847ace Mon Sep 17 00:00:00 2001 From: Frank Date: Wed, 30 Oct 2024 17:35:53 +0100 Subject: [PATCH 2/2] improve 'by station' potion order sorting (#80) --- .../masteringmixology/PotionComparators.java | 24 +++++++++++++++++++ .../masteringmixology/PotionOrderSorting.java | 2 +- 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 src/main/java/work/fking/masteringmixology/PotionComparators.java diff --git a/src/main/java/work/fking/masteringmixology/PotionComparators.java b/src/main/java/work/fking/masteringmixology/PotionComparators.java new file mode 100644 index 0000000..b14df1f --- /dev/null +++ b/src/main/java/work/fking/masteringmixology/PotionComparators.java @@ -0,0 +1,24 @@ +package work.fking.masteringmixology; + +import java.util.Comparator; + +public class PotionComparators { + + // Sort by modifier, in the order CRYSTALISED > HOMOGENOUS > CONCENTRATED + // And then by PotionType name alphabetically + public static Comparator byStation() { + return Comparator.comparingInt((PotionOrder order) -> { + switch (order.potionModifier()) { + case CRYSTALISED: + return 0; + case HOMOGENOUS: + return 1; + case CONCENTRATED: + return 2; + default: + return Integer.MAX_VALUE; + } + }) + .thenComparing(order -> order.potionType().name()); + } +} diff --git a/src/main/java/work/fking/masteringmixology/PotionOrderSorting.java b/src/main/java/work/fking/masteringmixology/PotionOrderSorting.java index e079b35..d0a6ad2 100644 --- a/src/main/java/work/fking/masteringmixology/PotionOrderSorting.java +++ b/src/main/java/work/fking/masteringmixology/PotionOrderSorting.java @@ -4,7 +4,7 @@ public enum PotionOrderSorting { VANILLA("Vanilla (random)", null), - BY_STATION("By station", Comparator.comparing(order -> order.potionModifier().ordinal())); + BY_STATION("By station", PotionComparators.byStation()); private final String name; private final Comparator comparator;