Skip to content

Commit

Permalink
add option to display resin amount on screen (#60)
Browse files Browse the repository at this point in the history
  • Loading branch information
raiyni authored Oct 9, 2024
1 parent b97699f commit b9f8413
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,16 @@ default boolean identifyPotions() {
return true;
}

@ConfigItem(
keyName = "displayResin",
name = "Display resin amount",
description = "Display total resin amounts",
position = 2
)
default boolean displayResin() {
return true;
}

@ConfigItem(
keyName = "stationHighlightColor",
name = "Station color",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.google.inject.Provides;
import net.runelite.api.Client;
import net.runelite.api.FontID;
import net.runelite.api.GameState;
import net.runelite.api.InventoryID;
import net.runelite.api.TileObject;
Expand All @@ -14,6 +15,8 @@
import net.runelite.api.events.WidgetClosed;
import net.runelite.api.events.WidgetLoaded;
import net.runelite.api.widgets.Widget;
import net.runelite.api.widgets.WidgetPositionMode;
import net.runelite.api.widgets.WidgetTextAlignment;
import net.runelite.api.widgets.WidgetType;
import net.runelite.client.Notifier;
import net.runelite.client.callback.ClientThread;
Expand All @@ -23,6 +26,7 @@
import net.runelite.client.plugins.Plugin;
import net.runelite.client.plugins.PluginDescriptor;
import net.runelite.client.ui.overlay.OverlayManager;
import net.runelite.client.util.ColorUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -47,6 +51,7 @@ public class MasteringMixologyPlugin extends Plugin {
private static final Logger LOGGER = LoggerFactory.getLogger(MasteringMixologyPlugin.class);

private static final int PROC_MASTERING_MIXOLOGY_BUILD_POTION_ORDER = 7063;
private static final int PROC_MASTERING_MIXOLOGY_BUILD_REAGENTS = 7064;

private static final int VARBIT_POTION_ORDER_1 = 11315;
private static final int VARBIT_POTION_MODIFIER_1 = 11316;
Expand Down Expand Up @@ -379,7 +384,7 @@ public void onGraphicsObjectCreated(GraphicsObjectCreated event) {

@Subscribe
public void onScriptPostFired(ScriptPostFired event) {
if (event.getScriptId() != PROC_MASTERING_MIXOLOGY_BUILD_POTION_ORDER) {
if (event.getScriptId() != PROC_MASTERING_MIXOLOGY_BUILD_REAGENTS) {
return;
}
var baseWidget = client.getWidget(COMPONENT_POTION_ORDERS);
Expand All @@ -397,6 +402,16 @@ public void onScriptPostFired(ScriptPostFired event) {
// The first text widget is always the interface title 'Potion Orders'
appendPotionRecipe(textComponents.get(order.idx()), order.idx(), order.fulfilled());
}

if (config.displayResin()) {
var parentWidth = baseWidget.getWidth();
var dx = parentWidth / 3;
int x = dx / 2;

addResinText(baseWidget.createChild(-1, WidgetType.TEXT), x, VARP_MOX_RESIN, MOX);
addResinText(baseWidget.createChild(-1, WidgetType.TEXT), x + dx, VARP_AGA_RESIN, AGA);
addResinText(baseWidget.createChild(-1, WidgetType.TEXT), x + dx * 2, VARP_LYE_RESIN, LYE);
}
}

private void initialize() {
Expand Down Expand Up @@ -517,6 +532,25 @@ private void appendPotionRecipe(Widget component, int orderIdx, boolean fulfille
component.setText(builder.toString());
}

private void addResinText(Widget widget, int x, int varp, PotionComponent component) {
var amount = client.getVarpValue(varp);
var color = ColorUtil.fromHex(component.color()).getRGB();

widget.setText(amount + "")
.setTextColor(color)
.setOriginalWidth(20)
.setOriginalHeight(15)
.setFontId(FontID.QUILL_8)
.setOriginalY(0)
.setOriginalX(x)
.setYPositionMode(WidgetPositionMode.ABSOLUTE_BOTTOM)
.setXTextAlignment(WidgetTextAlignment.CENTER)
.setYTextAlignment(WidgetTextAlignment.CENTER);

widget.revalidate();
LOGGER.debug("adding resin text {} at {} with color {}", amount, x, color);
}

private void tryFulfillOrder(PotionType potionType, PotionModifier modifier) {
for (var order : potionOrders) {
if (order.potionType() == potionType && order.potionModifier() == modifier && !order.fulfilled()) {
Expand Down

0 comments on commit b9f8413

Please sign in to comment.