Skip to content

Commit

Permalink
bank tags: split layouts from tag tabs
Browse files Browse the repository at this point in the history
This allows tags to have layouts, independent of tag tabs, and updates
the API to reflect this.
  • Loading branch information
Adam- committed Oct 25, 2024
1 parent fd82eaf commit d6aeca2
Show file tree
Hide file tree
Showing 10 changed files with 286 additions and 256 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,14 @@
*/
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.
* make it searchable in the bank UI and tab interface.
*
* @see TagManager#registerTag(String, BankTag)
* @see TagManager#unregisterTag(String)
* @see BankTagsService#openBankTag(BankTag)
* @see BankTagsService#openBankTag(String, int)
*/
public interface BankTag
{
Expand All @@ -45,13 +42,4 @@ public interface BankTag
* @return
*/
boolean contains(int itemId);

/**
* The tag layout
* @return the layout for the tag, or null for no layout
*/
default Layout layout()
{
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@
import net.runelite.client.plugins.banktags.tabs.TabInterface;
import static net.runelite.client.plugins.banktags.tabs.TabInterface.FILTERED_CHARS;
import net.runelite.client.plugins.banktags.tabs.TabSprites;
import net.runelite.client.plugins.banktags.tabs.TagTab;
import net.runelite.client.util.Text;

@PluginDescriptor(
Expand Down Expand Up @@ -141,7 +140,16 @@ public class BankTagsPlugin extends Plugin implements BankTagsService
private BankTagsConfig config;

@Getter
private BankTag activeTag;
private String activeTag;

@Getter
private BankTag activeBankTag;

@Getter
private Layout activeLayout;

@Getter
private int options;

@Override
public void configure(Binder binder)
Expand Down Expand Up @@ -323,7 +331,7 @@ public void onScriptCallbackEvent(ScriptCallbackEvent event)
final int itemId = intStack[intStackSize - 1];
String searchfilter = stringStack[stringStackSize - 1];

BankTag tag = activeTag;
BankTag tag = activeBankTag;
boolean tagSearch = true;
// Shared storage uses ~bankmain_filteritem too. Allow using tag searches in it but don't
// apply the tag search from the active tab.
Expand All @@ -345,7 +353,7 @@ public void onScriptCallbackEvent(ScriptCallbackEvent event)
tag = buildSearchFilterBankTag(searchfilter);
}

if (itemId == -1 && tag.layout() != null)
if (itemId == -1 && activeLayout != null)
{
// item -1 always passes on a laid out tab so items can be dragged to it
return;
Expand All @@ -364,12 +372,12 @@ else if (tagSearch)
}
break;
case "getSearchingTagTab":
intStack[intStackSize - 1] = activeTag != null ? 1 : 0;
intStack[intStackSize - 1] = activeBankTag != null ? 1 : 0;
break;
case "bankBuildTab":
// Use the per-tab view when we want to hide the separators to avoid having to reposition items &
// recomputing the scroll height.
if (activeTag != null && (tabInterface.isTagTabActive() || config.removeSeparators() || activeTag.layout() != null))
if (activeBankTag != null && (tabInterface.isTagTabActive() || config.removeSeparators() || activeLayout != null))
{
var stack = client.getIntStack();
var sz = client.getIntStackSize();
Expand Down Expand Up @@ -455,32 +463,28 @@ public void onConfigChanged(ConfigChanged configChanged)
}
}

public void open(TagTab tab)
public void openTag(String tag, Layout layout)
{
if (tab == null)
openTag(tag, layout, OPTION_ALLOW_MODIFICATIONS);
}

public void openTag(String tag, Layout layout, int options)
{
if (tag == null)
{
activeTag = null;
this.activeTag = null;
this.activeBankTag = null;
this.activeLayout = null;
this.options = 0;
return;
}

// custom tags are combined with the tab
final BankTag custom = tagManager.findTag(tab.getTag());
this.activeTag = tag;
this.activeBankTag = buildSearchFilterBankTag(tag);
this.activeLayout = layout;
this.options = options;

activeTag = new BankTag()
{
@Override
public boolean contains(int itemId)
{
return tagManager.findTag(itemId, tab.getTag())
|| (custom != null && custom.contains(itemId));
}

@Override
public Layout layout()
{
return tab.getLayout();
}
};
tabInterface.openTag(tag, layout, options, true);
}

private BankTag buildSearchFilterBankTag(String tag)
Expand All @@ -491,19 +495,26 @@ private BankTag buildSearchFilterBankTag(String tag)
|| (custom != null && custom.contains(itemId));
}

public void openBankTag(String name)
{
openBankTag(name, OPTION_ALLOW_MODIFICATIONS);
}

@Override
public void openTagTab(TagTab tagTab)
public void openBankTag(String name, int options)
{
tabInterface.closeTag(false);
open(tagTab);
bankSearch.layoutBank();
Layout layout = layoutManager.loadLayout(name);
openTag(name, layout, options);
}

@Override
public void openBankTag(BankTag bankTag)
public void closeBankTag()
{
tabInterface.closeTag(false);
activeTag = bankTag;
this.activeTag = null;
this.activeBankTag = null;
this.activeLayout = null;
this.options = 0;
bankSearch.layoutBank();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,54 @@
*/
package net.runelite.client.plugins.banktags;

import net.runelite.client.plugins.banktags.tabs.TagTab;
import javax.annotation.Nullable;
import net.runelite.client.plugins.banktags.tabs.Layout;

/**
* API for the bank tags plugin
*
* @see TagManager
* @see net.runelite.client.plugins.banktags.tabs.TabManager
* @see net.runelite.client.plugins.banktags.tabs.LayoutManager
*/
public interface BankTagsService
{
/**
* Open the given tag tab.
* @param tagTab
* Bank tag is allowed to be modified
*/
int OPTION_ALLOW_MODIFICATIONS = 1;
/**
* Option to hide the tag name from the "Remove-tag" menu option.
*/
int OPTION_HIDE_REMOVE_TAG_NAME = 2;

/**
* Open the given bank tag. The tag may have an associated {@link net.runelite.client.plugins.banktags.tabs.TagTab},
* but this isn't required. If the tag has an associated {@link net.runelite.client.plugins.banktags.tabs.Layout},
* the layout will be applied.
*
* @param tag the tag name
* @param options
* @see #OPTION_ALLOW_MODIFICATIONS
* @see #OPTION_HIDE_REMOVE_TAG_NAME
*/
void openBankTag(String tag, int options);

/**
* Close the currently open {@link BankTag}.
*/
void openTagTab(TagTab tagTab);
void closeBankTag();

@Nullable
String getActiveTag();

/**
* Open the given bank tag.
* @param bankTag
* Get the currently open {@link BankTag}
* @return
*/
void openBankTag(BankTag bankTag);
@Nullable
BankTag getActiveBankTag();

@Nullable
Layout getActiveLayout();
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@

public interface AutoLayout
{
Layout generateLayout(TagTab tab);
Layout generateLayout(Layout previous);
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,30 @@
package net.runelite.client.plugins.banktags.tabs;

import java.util.Arrays;
import lombok.Getter;
import lombok.NonNull;

public class Layout
{
@Getter
private final String tag;
private int[] layout;
boolean dirty = true;

public Layout()
public Layout(String tag)
{
this.tag = tag;
this.layout = new int[0];
}

public Layout(@NonNull int[] layout)
public Layout(String tag, @NonNull int[] layout)
{
this.tag = tag;
this.layout = layout;
}

public Layout(Layout other)
{
tag = other.tag;
layout = other.layout.clone();
}

Expand Down Expand Up @@ -83,7 +88,6 @@ else if (pos >= layout.length)
}

layout[pos] = itemId;
dirty = true;
}

public void addItem(int itemId)
Expand All @@ -93,8 +97,6 @@ public void addItem(int itemId)

public void addItemAfter(int itemId, int pos)
{
dirty = true;

int i;
for (i = pos; i < layout.length; ++i)
{
Expand All @@ -116,7 +118,6 @@ public void removeItem(int itemId)
if (layout[i] == itemId)
{
layout[i] = -1;
dirty = true;
}
}
}
Expand All @@ -129,15 +130,13 @@ public void removeItemAtPos(int pos)
}

layout[pos] = -1;
dirty = true;
}

void swap(int sidx, int tidx)
{
int sid = layout[sidx];
layout[sidx] = layout[tidx];
layout[tidx] = sid;
dirty = true;
}

void insert(int sidx, int tidx)
Expand Down Expand Up @@ -169,7 +168,6 @@ else if (sidx > tidx)
System.arraycopy(layout, tidx, layout, tidx + 1, i - tidx);
layout[tidx] = sid;
}
dirty = true;
}

public int count(int itemId)
Expand Down Expand Up @@ -198,6 +196,5 @@ public void resize(int size)
Arrays.fill(n, layout.length, size, -1);
}
layout = n;
dirty = true;
}
}
Loading

0 comments on commit d6aeca2

Please sign in to comment.