Skip to content

Commit

Permalink
wiki: fix view dps button to use absolute_center y position mode
Browse files Browse the repository at this point in the history
In the bank the Set/Stat bonus layer uses absoulte_center so that it
gets repositioned when the bank is resized. Do the same for the View dps
button so it also gets repositioned when the bank is resized.

The equipment screen uses absolute_top instead, so pull the position
mode from the set bonus parent.
  • Loading branch information
Adam- committed Sep 9, 2024
1 parent 265f801 commit 88829b4
Showing 1 changed file with 26 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import net.runelite.api.widgets.InterfaceID;
import net.runelite.api.widgets.JavaScriptCallback;
import net.runelite.api.widgets.Widget;
import net.runelite.api.widgets.WidgetPositionMode;
import net.runelite.api.widgets.WidgetType;
import net.runelite.api.widgets.WidgetUtil;
import net.runelite.client.callback.ClientThread;
Expand Down Expand Up @@ -217,14 +218,10 @@ void addButton(Screen screen, Runnable onClick)
// we must also use absolute for all the children below,
// which means it's necessary to offset the values by simulating corresponding pos/size modes.
int padding = 8;
int w = setBonus.getOriginalWidth();
int h = setBonus.getOriginalHeight();
int x = setBonus.getOriginalX() + (w / 2) + (padding / 2);
int y = setBonus.getOriginalY();
if (screen == Screen.BANK_EQUIPMENT) // uses ABSOLUTE_CENTER
{
y += parent.getHeight() / 2 - setBonus.getHeight() / 2;
}
final int w = setBonus.getOriginalWidth();
final int h = setBonus.getOriginalHeight();
final int x = setBonus.getOriginalX() + (w / 2) + (padding / 2);
final int y = setBonus.getOriginalY();

// now shift the Set Bonus and Stat Bonus buttons over a bit to make room
setBonus.setOriginalX(setBonus.getOriginalX() - (w / 2) - (padding / 2))
Expand All @@ -242,16 +239,31 @@ void addButton(Screen screen, Runnable onClick)
spriteWidgets[0] = parent.createChild(-1, WidgetType.GRAPHIC)
.setSpriteId(refComponents[0].getSpriteId())
.setPos(bgX, bgY)
.setSize(bgWidth, bgHeight);
.setSize(bgWidth, bgHeight)
.setYPositionMode(statBonus.getYPositionMode());
spriteWidgets[0].revalidate();

// borders and corners all use absolute positioning which is easy
// borders and corners all use absolute positioning
for (int i = 1; i < 9; i++)
{
spriteWidgets[i] = parent.createChild(-1, WidgetType.GRAPHIC)
Widget c = spriteWidgets[i] = parent.createChild(-1, WidgetType.GRAPHIC)
.setSpriteId(refComponents[i].getSpriteId())
.setPos(x + refComponents[i].getOriginalX(), y + refComponents[i].getOriginalY())
.setSize(refComponents[i].getOriginalWidth(), refComponents[i].getOriginalHeight());
if (statBonus.getYPositionMode() == WidgetPositionMode.ABSOLUTE_CENTER)
{
// Convert x/y from the reference component's, whose parent is the Set Bonus layer,
// to our components whose parent is the bank equipment parent.
// For y we have to reverse the ABSOLUTE_CENTER y calculation to convert
// the reference component original y into an offset from where the client will
// compute the ABSOLUTE_CENTER y to be.
c.setPos(x + refComponents[i].getOriginalX(), y - (setBonus.getHeight() - refComponents[i].getHeight() + 1) / 2 + refComponents[i].getOriginalY())
.setYPositionMode(statBonus.getYPositionMode());
}
else
{
c.setPos(x + refComponents[i].getOriginalX(), y + refComponents[i].getOriginalY());
}

spriteWidgets[i].revalidate();
}

Expand All @@ -265,7 +277,8 @@ void addButton(Screen screen, Runnable onClick)
.setXTextAlignment(refComponents[9].getXTextAlignment())
.setYTextAlignment(refComponents[9].getYTextAlignment())
.setPos(x, y)
.setSize(w, h);
.setSize(w, h)
.setYPositionMode(statBonus.getYPositionMode());
text.revalidate();

// we'll give the text layer the listeners since it covers the whole area
Expand Down

0 comments on commit 88829b4

Please sign in to comment.