Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add colored inventory tags #78

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
package work.fking.masteringmixology;

import net.runelite.api.widgets.WidgetItem;
import net.runelite.api.ItemID;
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;
import java.awt.image.BufferedImage;
import java.util.HashMap;

public class InventoryPotionOverlay extends WidgetItemOverlay {
import static work.fking.masteringmixology.PotionComponent.AGA;
import static work.fking.masteringmixology.PotionComponent.LYE;
import static work.fking.masteringmixology.PotionComponent.MOX;

public class InventoryPotionOverlay extends WidgetItemOverlay {
private static final int MODIFIED_POTION_ID_DIFF = ItemID.MIXALOT_30030 - ItemID.MIXALOT;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't do this as it's generally not kosher to rely on the order of itemid. Probably should add a ctor parameter to potion type and they can be added to the same item map.

private final HashMap<PotionType, BufferedImage> imageCache = new HashMap<>();
private final MasteringMixologyPlugin plugin;
private final MasteringMixologyConfig config;

Expand All @@ -20,21 +29,68 @@ public class InventoryPotionOverlay extends WidgetItemOverlay {
showOnInventory();
}

public void clearCache() {
imageCache.clear();
}

@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);
var potion = PotionType.fromItemId(itemId <= ItemID.MIXALOT ? itemId : itemId - MODIFIED_POTION_ID_DIFF);
whiitehead marked this conversation as resolved.
Show resolved Hide resolved

if (potion == null) {
return;
}

if (!imageCache.containsKey(potion)) {
imageCache.put(potion, createRecipeImage(potion));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

caching these is unnecessary, just draw the text

}

var bounds = widgetItem.getCanvasBounds();
graphics2D.drawImage(imageCache.get(potion), bounds.x, bounds.y, null);
}

private BufferedImage createRecipeImage(PotionType potion) {
// Font measurements come from: graphics2D.getFontMetrics(FontManager.getRunescapeSmallFont())
whiitehead marked this conversation as resolved.
Show resolved Hide resolved
var image = new BufferedImage(25, 13, BufferedImage.TYPE_INT_ARGB);
whiitehead marked this conversation as resolved.
Show resolved Hide resolved
var graphics2D = image.createGraphics();
drawRecipe(graphics2D, potion, 1, 13, Color.BLACK); // Drop shadow
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally don't like the shadow, it should at least be configurable

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then should I make the shadow on resin configurable. What about the shadow on the overlay. Everything has shadow. I'm not making it configurable.

Copy link
Collaborator

@raiyni raiyni Oct 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are making a false equivalence about how things are rendered. The rendering engine for widgets isn't the same as the rendering engine for Runelite overlays.

If you really wanted to be in the spirit of runelite, you could do rendering like the Item Identification plugin. I believe that might have a shadow in TextComponent it handles and even parses colors.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally don't like the shadow

It's not a false equivalent. You are commenting on what the user sees. The user doesn't see implementation details. The spirit of RuneLite is to add a drop shadow. If you know of a better way of doing it I'm happy to change it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


if (config.inventoryPotionTagType() == InventoryPotionTagType.COLORED) {
whiitehead marked this conversation as resolved.
Show resolved Hide resolved
drawRecipe(graphics2D, potion, 0, 12, null);
return image;
}

drawRecipe(graphics2D, potion, 0, 12, Color.WHITE);
return image;
}

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) {
whiitehead marked this conversation as resolved.
Show resolved Hide resolved
graphics2D.setColor(color);
graphics2D.drawString(potion.abbreviation(), x, y);
return;
}

for (var component : potion.components()) {
if (component == MOX) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need to do all of this casing if you just use the measurement and use the component.character() and component.color()

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need to comment the same recommendation 5 times. This is a good idea and I will have a revision coming.

graphics2D.setColor(Color.decode("#" + MOX.color()));
graphics2D.drawString("M", x, y);
x += 8;
} else if (component == AGA) {
graphics2D.setColor(Color.decode("#" + AGA.color()));
graphics2D.drawString("A", x, y);
x += 7;
} else if (component == LYE) {
graphics2D.setColor(Color.decode("#" + LYE.color()));
graphics2D.drawString("L", x, y);
x += 5;
}
}
}
}
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() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reuse the current config defaulted to white

return InventoryPotionTagType.COLORED;
}

@ConfigItem(
keyName = "potionOrderSorting",
name = "Order sorting",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,10 @@ public void onConfigChanged(ConfigChanged event) {
clientThread.invokeLater(this::updatePotionOrders);
}

if (event.getKey().equals("inventoryPotionTags")) {
whiitehead marked this conversation as resolved.
Show resolved Hide resolved
potionOverlay.clearCache();
}

if (!config.highlightStations()) {
unHighlightAllStations();
}
Expand Down