Skip to content

Commit

Permalink
rewrite banktags again!
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam- committed Oct 14, 2024
1 parent 242cfa8 commit ff6a895
Show file tree
Hide file tree
Showing 9 changed files with 267 additions and 213 deletions.
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 @@ -455,30 +454,30 @@ public void onConfigChanged(ConfigChanged configChanged)
}
}

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

// custom tags are combined with the tab
final BankTag custom = tagManager.findTag(tab.getTag());
final BankTag custom = tagManager.findTag(tag);

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

@Override
public Layout layout()
{
return tab.getLayout();
return layout;
}
};
}
Expand All @@ -492,18 +491,17 @@ private BankTag buildSearchFilterBankTag(String tag)
}

@Override
public void openTagTab(TagTab tagTab)
public void openBankTag(BankTag bankTag)
{
tabInterface.closeTag(false);
open(tagTab);
activeTag = bankTag;
bankSearch.layoutBank();
}

@Override
public void openBankTag(BankTag bankTag)
public void openBankTag(String name)
{
tabInterface.closeTag(false);
activeTag = bankTag;
bankSearch.layoutBank();
Layout layout = layoutManager.loadLayout(name);
tabInterface.openTag(name, layout, true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,29 @@
*/
package net.runelite.client.plugins.banktags;

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

/**
* 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
* 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
*/
void openTagTab(TagTab tagTab);
void openBankTag(String tag);

/**
* Open the given bank tag.
* Open the given {@link BankTag}. The bank tag is ephemeral and is implemented by the caller. The tags may not
* be modified by the end user, and changes to the tag are not persisted. No part of the bank tag is saved by the
* Bank tag plugin. IF the {@link BankTag} has an associated {@link net.runelite.client.plugins.banktags.tabs.Layout},
* the layout will be applied.
* @param bankTag
*/
void openBankTag(BankTag bankTag);
Expand Down
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 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 ff6a895

Please sign in to comment.