banktags: improve bank scrollbar updates
With tag tab tab or "Remove tab separators", the scrollbar height needs to be adjusted to account for either many tag tabs (which requires scrolling to see) or the hiding of the tab separators. This is because we artifically filter the bank results without keeping the bank in searching mode, causing the vanilla code which usually computes the scroll height to be incorrect. The existing code does this by manually invoking [proc,update_scrollbar] later with the recomputed scroll height. Now that invokeLater runs next tick and not next frame, this leaves several frames with the scrollbar the incorrect size. The desired scroll height is passed to [proc,bankmain_finishbuilding] in argument int12, so instead we recompute the scroll height and overwrite the script argument prior to execution.
This commit is contained in:
@@ -477,6 +477,32 @@ public class BankTagsPlugin extends Plugin implements MouseWheelListener
|
||||
Widget bankTitle = client.getWidget(WidgetInfo.BANK_TITLE_BAR);
|
||||
bankTitle.setText("Tag tab <col=ff0000>" + activeTab.getTag() + "</col>");
|
||||
}
|
||||
|
||||
// Recompute scroll size. Only required for tag tab tab and with remove separators, to remove the
|
||||
// space that the separators took.
|
||||
if (tabInterface.isTagTabActive() || (tabInterface.isActive() && config.removeSeparators()))
|
||||
{
|
||||
Widget itemContainer = client.getWidget(WidgetInfo.BANK_ITEM_CONTAINER);
|
||||
Widget[] children = itemContainer.getChildren();
|
||||
int items = 0;
|
||||
for (Widget child : children)
|
||||
{
|
||||
if (child != null && child.getItemId() != -1 && !child.isHidden())
|
||||
{
|
||||
++items;
|
||||
}
|
||||
}
|
||||
|
||||
// New scroll height for if_setscrollsize
|
||||
final int adjustedScrollHeight = (Math.max(0, items - 1) / ITEMS_PER_ROW) * ITEM_VERTICAL_SPACING +
|
||||
ITEM_VERTICAL_SPACING + ITEM_CONTAINER_BOTTOM_PADDING;
|
||||
|
||||
// This is prior to bankmain_finishbuilding running, so the arguments are still on the stack. Overwrite
|
||||
// argument int12 (7 from the end) which is the height passed to if_setscrollsize
|
||||
final int[] intStack = client.getIntStack();
|
||||
final int intStackSize = client.getIntStackSize();
|
||||
intStack[intStackSize - 7] = adjustedScrollHeight;
|
||||
}
|
||||
}
|
||||
else if (scriptId == ScriptID.BANKMAIN_SEARCH_TOGGLE)
|
||||
{
|
||||
@@ -510,15 +536,6 @@ public class BankTagsPlugin extends Plugin implements MouseWheelListener
|
||||
return;
|
||||
}
|
||||
|
||||
if (tabInterface.isTagTabActive())
|
||||
{
|
||||
int numTabs = (int) Arrays.stream(itemContainer.getDynamicChildren())
|
||||
.filter(child -> child.getItemId() != -1 && !child.isHidden())
|
||||
.count();
|
||||
updateBankContainerScrollHeight(numTabs);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!tabInterface.isActive() || !config.removeSeparators())
|
||||
{
|
||||
return;
|
||||
@@ -540,14 +557,9 @@ public class BankTagsPlugin extends Plugin implements MouseWheelListener
|
||||
int adjYOffset = (items / ITEMS_PER_ROW) * ITEM_VERTICAL_SPACING;
|
||||
int adjXOffset = (items % ITEMS_PER_ROW) * ITEM_HORIZONTAL_SPACING + ITEM_ROW_START;
|
||||
|
||||
if (child.getOriginalY() != adjYOffset)
|
||||
if (child.getOriginalY() != adjYOffset || child.getOriginalX() != adjXOffset)
|
||||
{
|
||||
child.setOriginalY(adjYOffset);
|
||||
child.revalidate();
|
||||
}
|
||||
|
||||
if (child.getOriginalX() != adjXOffset)
|
||||
{
|
||||
child.setOriginalX(adjXOffset);
|
||||
child.revalidate();
|
||||
}
|
||||
@@ -562,23 +574,6 @@ public class BankTagsPlugin extends Plugin implements MouseWheelListener
|
||||
child.setHidden(true);
|
||||
}
|
||||
}
|
||||
|
||||
updateBankContainerScrollHeight(items);
|
||||
}
|
||||
|
||||
private void updateBankContainerScrollHeight(int items)
|
||||
{
|
||||
Widget bankItemContainer = client.getWidget(WidgetInfo.BANK_ITEM_CONTAINER);
|
||||
int itemContainerHeight = bankItemContainer.getHeight();
|
||||
final int adjustedScrollHeight = (Math.max(0, items - 1) / ITEMS_PER_ROW) * ITEM_VERTICAL_SPACING + ITEM_VERTICAL_SPACING + ITEM_CONTAINER_BOTTOM_PADDING;
|
||||
bankItemContainer.setScrollHeight(Math.max(adjustedScrollHeight, itemContainerHeight));
|
||||
|
||||
final int itemContainerScroll = bankItemContainer.getScrollY();
|
||||
clientThread.invokeLater(() ->
|
||||
client.runScript(ScriptID.UPDATE_SCROLLBAR,
|
||||
WidgetInfo.BANK_SCROLLBAR.getId(),
|
||||
WidgetInfo.BANK_ITEM_CONTAINER.getId(),
|
||||
itemContainerScroll));
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
.id 279
|
||||
.id 279 ; [proc,bankmain_filteritem]
|
||||
.int_stack_count 1
|
||||
.string_stack_count 0
|
||||
.int_var_count 2 ; +1 for storage of search filter result
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
.id 277
|
||||
.id 277 ; [proc,bankmain_build]
|
||||
.int_stack_count 17
|
||||
.string_stack_count 0
|
||||
.int_var_count 36
|
||||
@@ -842,7 +842,7 @@ LABEL729:
|
||||
iload 14
|
||||
iload 15
|
||||
iload 16
|
||||
invoke 505
|
||||
invoke 505 ; [proc,bankmain_finishbuilding]
|
||||
return
|
||||
LABEL750:
|
||||
invoke 514
|
||||
|
||||
Reference in New Issue
Block a user