xp drop plugin: fix alignment of xpdrops when hiding skill icons

This commit is contained in:
Adam
2018-07-16 20:51:08 -04:00
parent a16ff307b8
commit 6bf32768f1

View File

@@ -47,7 +47,7 @@ import net.runelite.client.plugins.PluginDescriptor;
)
public class XpDropPlugin extends Plugin
{
private static final int EXPERIENCE_DROP_SPRITE_WIDTH = 16;
private static final int XPDROP_PADDING = 2; // space between xp drop icons
@Inject
private Client client;
@@ -87,9 +87,37 @@ public class XpDropPlugin extends Plugin
}
else if (!widget.getText().isEmpty())
{
// Align text left accordingly to take up hidden skill icon space
// Align text accordingly to take up hidden skill icon space
int width = 0;
for (Widget w : widget.getParent().getDynamicChildren())
{
if (w.getSpriteId() != -1)
{
if (width > 0)
{
// Add in space between sprites
width += XPDROP_PADDING;
}
width += w.getWidth(); // width of sprite
}
}
final int xpDropPosition = client.getVar(Varbits.EXPERIENCE_TRACKER_POSITION);
widget.setRelativeX(EXPERIENCE_DROP_SPRITE_WIDTH * xpDropPosition * -1 / 2);
switch (xpDropPosition)
{
case 2: // left
int cur = widget.getRelativeX();
cur -= width;
widget.setRelativeX(cur);
break;
case 0: // right
break;
case 1: // center
cur = widget.getRelativeX();
cur -= width / 2;
widget.setRelativeX(cur);
break;
}
}
}