Skip to content

Commit

Permalink
bank tags: add layouts
Browse files Browse the repository at this point in the history
This incorporates bank tag layouts as seen by the popular bank tag
layouts plugin. Thanks to @geheur for their assistance with development
and testing, and for the original idea.

There are also several new APIs for plugins to manage tags, tabs, and
layouts.

Example API usage to open a custom layout:

  Layout l = new Layout();
  l.setItemAtPos(ItemID.ROBIN_HOOD_HAT, 4);
  BankTag bt = new BankTag()
  {
      @OverRide
      public boolean contains(int itemId)
      {
          return l.count(itemId) > 0;
      }

      @OverRide
      public Layout layout()
      {
          return l;
      }
  };
  bankTagsService.openBankTag(bt);
  • Loading branch information
Adam- committed Jun 28, 2024
1 parent 34275b1 commit c32f925
Show file tree
Hide file tree
Showing 16 changed files with 1,643 additions and 214 deletions.
3 changes: 3 additions & 0 deletions runelite-api/src/main/java/net/runelite/api/ScriptID.java
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,9 @@ public final class ScriptID
@ScriptArguments(integer = 17)
public static final int BANKMAIN_SEARCH_REFRESH = 283;

@ScriptArguments(integer = 6)
public static final int BANKMAIN_DRAGSCROLL = 284;

/**
* Called to update the PVP widget (wilderness level/protection)
*/
Expand Down
2 changes: 2 additions & 0 deletions runelite-api/src/main/java/net/runelite/api/VarClientInt.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ public final class VarClientInt
*/
public static final int INPUT_TYPE = 5;

public static final int BANK_SCROLL = 51;

/**
* The game sets this to the same value as {@link #CAMERA_ZOOM_RESIZABLE_VIEWPORT}
*/
Expand Down
3 changes: 3 additions & 0 deletions runelite-api/src/main/java/net/runelite/api/Varbits.java
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,9 @@ public final class Varbits

public static final int BANK_REARRANGE_MODE = 3959;
public static final int CURRENT_BANK_TAB = 4150;
public static final int BANK_QUANTITY_TYPE = 6590;
public static final int BANK_REQUESTEDQUANTITY = 3960;
public static final int BANK_LEAVEPLACEHOLDERS = 3755;

public static final int WORLDHOPPER_FAVORITE_1 = 4597;
public static final int WORLDHOPPER_FAVORITE_2 = 4598;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import net.runelite.api.events.MenuShouldLeftClick;
import net.runelite.api.events.ScriptCallbackEvent;
import net.runelite.api.events.ScriptPostFired;
import net.runelite.api.events.ScriptPreFired;
import net.runelite.api.events.WidgetLoaded;
import net.runelite.api.widgets.ComponentID;
import net.runelite.api.widgets.InterfaceID;
Expand Down Expand Up @@ -111,6 +112,7 @@ public class BankPlugin extends Plugin
private boolean forceRightClickFlag;
private Multiset<Integer> itemQuantities; // bank item quantities for bank value search
private String searchString;
private ContainerPrices prices;

private final KeyListener searchHotkeyListener = new KeyListener()
{
Expand Down Expand Up @@ -321,19 +323,26 @@ else if (event.getGroupId() == InterfaceID.CLANRANK_POPUP // also the Jagex acco
}
}

@Subscribe(priority = 1) // run prior to bank tags
public void onScriptPreFired(ScriptPreFired event)
{
if (event.getScriptId() == ScriptID.BANKMAIN_FINISHBUILDING)
{
// This is here so that it computes the tab price before bank tags layouts the tab with duplicates or placeholders.
prices = getWidgetContainerPrices(ComponentID.BANK_ITEM_CONTAINER, InventoryID.BANK);
}
}

@Subscribe
public void onScriptPostFired(ScriptPostFired event)
{
if (event.getScriptId() == ScriptID.BANKMAIN_BUILD)
if (event.getScriptId() == ScriptID.BANKMAIN_FINISHBUILDING)
{
ContainerPrices price = getWidgetContainerPrices(ComponentID.BANK_ITEM_CONTAINER, InventoryID.BANK);
if (price == null)
if (prices != null)
{
return;
Widget bankTitle = client.getWidget(ComponentID.BANK_TITLE_BAR);
bankTitle.setText(bankTitle.getText() + createValueText(prices.getGePrice(), prices.getHighAlchPrice()));
}

Widget bankTitle = client.getWidget(ComponentID.BANK_TITLE_BAR);
bankTitle.setText(bankTitle.getText() + createValueText(price.getGePrice(), price.getHighAlchPrice()));
}
else if (event.getScriptId() == ScriptID.BANKMAIN_SEARCH_REFRESH)
{
Expand Down Expand Up @@ -618,8 +627,8 @@ private ContainerPrices getWidgetContainerPrices(@Component int componentId, Inv
long geTotal = 0, haTotal = 0;
log.debug("Computing bank price of {} items", itemContainer.size());

// In the bank, the first components are the bank items, followed by tabs etc. There are always 816 components regardless
// of bank size, but we only need to check up to the bank size.
// In the bank, the first components are the bank items, followed by tabs etc. There are always enough
// components for the max bank regardless of the bank size, but we only need to check up to the bank size.
for (int i = 0; i < itemContainer.size(); ++i)
{
Widget child = children[i];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,33 @@
*/
package net.runelite.client.plugins.banktags;

import net.runelite.client.plugins.banktags.tabs.Layout;

/**
* A bank tag. Plugins may implement this interface to define custom bank tags.
* You may register a BankTag with {@link TagManager#registerTag(String, BankTag)} to
* make it searchable in the bank UI and tab interface. You may also set the active bank tag
* via {@link BankTagsService#openBankTag(BankTag)}, regardless of if the banktag is registered.
*
* @see TagManager#registerTag(String, BankTag)
* @see TagManager#unregisterTag(String)
* @see BankTagsService#openBankTag(BankTag)
*/
public interface BankTag
{
/**
* Test if an item is in the tag
* @param itemId
* @return
*/
boolean contains(int itemId);

/**
* The tag layout
* @return the layout for the tag, or null for no layout
*/
default Layout layout()
{
return null;
}
}
Loading

0 comments on commit c32f925

Please sign in to comment.