Skip to content

Commit

Permalink
Add or remove resin text when config changes
Browse files Browse the repository at this point in the history
If you toggled resin display, it wouldn't update till you completed an order
  • Loading branch information
BlueSoapTurtle committed Oct 30, 2024
1 parent c3a14c2 commit 8ab85b5
Showing 1 changed file with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import javax.inject.Inject;
import java.awt.Color;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
Expand Down Expand Up @@ -194,6 +195,17 @@ public void onConfigChanged(ConfigChanged event) {
}
}

if (event.getKey().equals("displayResin")) {
var baseWidget = client.getWidget(COMPONENT_POTION_ORDERS);
if (baseWidget != null) {
if (!config.displayResin()) {
clientThread.invokeLater(() -> removeResinText(baseWidget));
} else {
clientThread.invokeLater(() -> appendResins(baseWidget));
}
}
}

if (!config.highlightDigWeed()) {
unHighlightObject(AlchemyObject.DIGWEED_NORTH_EAST);
unHighlightObject(AlchemyObject.DIGWEED_SOUTH_EAST);
Expand Down Expand Up @@ -435,6 +447,26 @@ private void updatePotionOrdersComponent(Widget baseWidget) {
}
}

private void removeResinText(Widget widget) {
Widget[] children = widget.getChildren();
if (children == null || children.length < 3) {
return;
}

// Get the balance of all resins
String moxResinAmount = String.valueOf(client.getVarpValue(VARP_MOX_RESIN));
String agaResinAmount = String.valueOf(client.getVarpValue(VARP_AGA_RESIN));
String lyeResinAmount = String.valueOf(client.getVarpValue(VARP_LYE_RESIN));

// Check if the last three children have texts matching the resin amounts and remove them
if (children[children.length - 1].getText().equals(lyeResinAmount) &&
children[children.length - 2].getText().equals(agaResinAmount) &&
children[children.length - 3].getText().equals(moxResinAmount)) {
widget.setChildren(Arrays.copyOf(children, children.length - 3));
widget.revalidate();
}
}

private void appendResins(Widget baseWidget) {
if (!config.displayResin()) {
return;
Expand Down

0 comments on commit 8ab85b5

Please sign in to comment.