diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/banktags/BankTag.java b/runelite-client/src/main/java/net/runelite/client/plugins/banktags/BankTag.java index 064a51fd2c2..a0a56fedec5 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/banktags/BankTag.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/banktags/BankTag.java @@ -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 { @@ -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; - } } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/banktags/BankTagsPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/banktags/BankTagsPlugin.java index c70ba0cc22a..d75f620c45d 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/banktags/BankTagsPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/banktags/BankTagsPlugin.java @@ -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( @@ -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) @@ -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. @@ -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; @@ -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(); @@ -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) @@ -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(); } } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/banktags/BankTagsService.java b/runelite-client/src/main/java/net/runelite/client/plugins/banktags/BankTagsService.java index da41171e1ad..dfaedc1b26f 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/banktags/BankTagsService.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/banktags/BankTagsService.java @@ -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(); } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/banktags/tabs/AutoLayout.java b/runelite-client/src/main/java/net/runelite/client/plugins/banktags/tabs/AutoLayout.java index b511b767269..4dfe7af9ccb 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/banktags/tabs/AutoLayout.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/banktags/tabs/AutoLayout.java @@ -27,5 +27,5 @@ public interface AutoLayout { - Layout generateLayout(TagTab tab); + Layout generateLayout(Layout previous); } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/banktags/tabs/Layout.java b/runelite-client/src/main/java/net/runelite/client/plugins/banktags/tabs/Layout.java index f4cab6500e7..1ac4778e730 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/banktags/tabs/Layout.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/banktags/tabs/Layout.java @@ -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(); } @@ -83,7 +88,6 @@ else if (pos >= layout.length) } layout[pos] = itemId; - dirty = true; } public void addItem(int itemId) @@ -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) { @@ -116,7 +118,6 @@ public void removeItem(int itemId) if (layout[i] == itemId) { layout[i] = -1; - dirty = true; } } } @@ -129,7 +130,6 @@ public void removeItemAtPos(int pos) } layout[pos] = -1; - dirty = true; } void swap(int sidx, int tidx) @@ -137,7 +137,6 @@ 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) @@ -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) @@ -198,6 +196,5 @@ public void resize(int size) Arrays.fill(n, layout.length, size, -1); } layout = n; - dirty = true; } } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/banktags/tabs/LayoutManager.java b/runelite-client/src/main/java/net/runelite/client/plugins/banktags/tabs/LayoutManager.java index 808a60f1aea..b41ba9edcac 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/banktags/tabs/LayoutManager.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/banktags/tabs/LayoutManager.java @@ -25,7 +25,6 @@ */ package net.runelite.client.plugins.banktags.tabs; -import com.google.common.util.concurrent.Runnables; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; @@ -34,6 +33,7 @@ import java.util.Map; import java.util.Set; import javax.annotation.Nonnull; +import javax.annotation.Nullable; import javax.inject.Inject; import javax.inject.Singleton; import lombok.NonNull; @@ -65,6 +65,7 @@ import net.runelite.api.widgets.Widget; import net.runelite.client.chat.ChatMessageManager; import net.runelite.client.chat.QueuedMessage; +import net.runelite.client.config.ConfigManager; import net.runelite.client.eventbus.EventBus; import net.runelite.client.eventbus.Subscribe; import net.runelite.client.game.ItemManager; @@ -80,6 +81,9 @@ import static net.runelite.client.plugins.banktags.BankTagsPlugin.BANK_ITEM_WIDTH; import static net.runelite.client.plugins.banktags.BankTagsPlugin.BANK_ITEM_X_PADDING; import static net.runelite.client.plugins.banktags.BankTagsPlugin.BANK_ITEM_Y_PADDING; +import static net.runelite.client.plugins.banktags.BankTagsPlugin.CONFIG_GROUP; +import static net.runelite.client.plugins.banktags.BankTagsPlugin.TAG_LAYOUT_PREFIX; +import net.runelite.client.plugins.banktags.BankTagsService; import static net.runelite.client.plugins.banktags.tabs.TabInterface.DUPLICATE_ITEM; import static net.runelite.client.plugins.banktags.tabs.TabInterface.REMOVE_LAYOUT; import net.runelite.client.util.Text; @@ -93,29 +97,27 @@ public class LayoutManager private final BankTagsPlugin plugin; private final ChatboxPanelManager chatboxPanelManager; private final BankSearch bankSearch; - private final TabManager tabManager; - private final TabInterface tabInterface; private final ChatMessageManager chatMessageManager; private final PotionStorage potionStorage; private final EventBus eventBus; + private final ConfigManager configManager; private final List autoLayouts = new ArrayList<>(); @Inject LayoutManager(Client client, ItemManager itemManager, BankTagsPlugin plugin, ChatboxPanelManager chatboxPanelManager, - BankSearch bankSearch, TabManager tabManager, TabInterface tabInterface, ChatMessageManager chatMessageManager, - PotionStorage potionStorage, EventBus eventBus) + BankSearch bankSearch, ChatMessageManager chatMessageManager, + PotionStorage potionStorage, EventBus eventBus, ConfigManager configManager) { this.client = client; this.itemManager = itemManager; this.plugin = plugin; this.chatboxPanelManager = chatboxPanelManager; this.bankSearch = bankSearch; - this.tabManager = tabManager; - this.tabInterface = tabInterface; this.chatMessageManager = chatMessageManager; this.potionStorage = potionStorage; this.eventBus = eventBus; + this.configManager = configManager; registerAutoLayout(plugin, "Default", new DefaultLayout()); } @@ -132,6 +134,45 @@ public void unregister() eventBus.unregister(potionStorage); } + @Nullable + public Layout loadLayout(String tag) + { + String layoutStr = configManager.getConfiguration(CONFIG_GROUP, TAG_LAYOUT_PREFIX + Text.standardize(tag)); + if (layoutStr != null) + { + List layoutList = Text.fromCSV(layoutStr); + int[] layout = new int[layoutList.size()]; + for (int i = 0; i < layoutList.size(); ++i) + { + layout[i] = Integer.parseInt(layoutList.get(i)); + } + + return new Layout(tag, layout); + } + return null; + } + + public void saveLayout(Layout layout) + { + String tag = layout.getTag(); + int[] l = layout.getLayout(); + StringBuilder sb = new StringBuilder(l.length * 5); + for (int i = 0; i < l.length; ++i) + { + if (i > 0) + { + sb.append(','); + } + sb.append(l[i]); + } + configManager.setConfiguration(CONFIG_GROUP, TAG_LAYOUT_PREFIX + Text.standardize(tag), sb.toString()); + } + + public void removeLayout(String tag) + { + configManager.unsetConfiguration(CONFIG_GROUP, TAG_LAYOUT_PREFIX + Text.standardize(tag)); + } + private void layout(Layout l) { ItemContainer bank = client.getItemContainer(InventoryID.BANK); @@ -283,7 +324,7 @@ private void layout(Layout l) if (modified) { - tabManager.save(); + saveLayout(l); } } @@ -326,9 +367,9 @@ else if (qty == 0) c.setItemQuantity(Integer.MAX_VALUE); c.setItemQuantityMode(ItemQuantityMode.NEVER); - // TabInterface rewrites these to RUNELITE types and adds handlers - if (tabInterface.isActive()) + if ((plugin.getOptions() & BankTagsService.OPTION_ALLOW_MODIFICATIONS) != 0) { + // TabInterface rewrites these to RUNELITE types and adds handlers c.setAction(7 - 1, DUPLICATE_ITEM); c.setAction(8 - 1, REMOVE_LAYOUT); } @@ -443,7 +484,7 @@ private void dragCompleteHandler(Layout l, ScriptEvent ev) l.insert(sidx, tidx); } - tabManager.save(); + saveLayout(l); bankSearch.layoutBank(); } @@ -545,7 +586,7 @@ public void onScriptPreFired(ScriptPreFired event) { resetWidgets(); - BankTag activeTag = plugin.getActiveTag(); + BankTag activeTag = plugin.getActiveBankTag(); if (activeTag != null) { // Since the script vm isn't reentrant, we can't call into POTIONSTORE_DOSES/POTIONSTORE_WITHDRAW_DOSES @@ -554,7 +595,7 @@ public void onScriptPreFired(ScriptPreFired event) // them by the time the inv transmit listener runs. potionStorage.cachePotions = true; - Layout layout = activeTag.layout(); + Layout layout = plugin.getActiveLayout(); if (layout != null) { layout(layout); @@ -587,8 +628,7 @@ private void resetWidgets() } } - @Subscribe - private void onMenuEntryAdded(MenuEntryAdded event) + void onMenuEntryAdded(MenuEntryAdded event, TabInterface tabInterface) { if (event.getActionParam1() == ComponentID.BANK_CONTENT_CONTAINER && event.getOption().equals(TabInterface.DISABLE_LAYOUT)) { @@ -601,8 +641,8 @@ private void onMenuEntryAdded(MenuEntryAdded event) .setType(MenuAction.RUNELITE_HIGH_PRIORITY) .onClick(e -> { - TagTab tab = tabManager.find(Text.removeTags(e.getTarget())); - if (tab != tabInterface.getActiveTab()) + String tag = Text.removeTags(e.getTarget()); + if (!tag.equals(tabInterface.getActiveTag())) { chatMessageManager.queue(QueuedMessage.builder() .type(ChatMessageType.CONSOLE) @@ -611,20 +651,15 @@ private void onMenuEntryAdded(MenuEntryAdded event) return; } - Layout old = tab.getLayout(); - Layout new_ = autoLayout.autoLayout.generateLayout(tab); - tab.setLayout(new_); - bankSearch.layoutBank(); - tab.setLayout(old); - tabManager.save(); + Layout old = plugin.getActiveLayout(); + Layout new_ = autoLayout.autoLayout.generateLayout(old); + plugin.openTag(tag, new_); chatboxPanelManager.openTextMenuInput("Tab laid out using the '" + autoLayout.getName() + "' layout.") .option("1. Keep", () -> - { - tab.setLayout(new_); - tabManager.save(); - }) - .option("2. Undo", Runnables.doNothing()) + saveLayout(new_)) + .option("2. Undo", () -> + plugin.openTag(tag, old)) .onClose(bankSearch::layoutBank) .build(); }); @@ -632,13 +667,10 @@ private void onMenuEntryAdded(MenuEntryAdded event) } } - @Subscribe(priority = -1) - private void onMenuOptionClicked(MenuOptionClicked event) + void onMenuOptionClicked(MenuOptionClicked event) { // Update widget index of the menu so withdraws work in laid out tabs. - BankTag activeTag = plugin.getActiveTag(); - if (event.getParam1() == ComponentID.BANK_ITEM_CONTAINER - && activeTag != null && !tabInterface.isTagTabActive() && activeTag.layout() != null) + if (event.getParam1() == ComponentID.BANK_ITEM_CONTAINER && plugin.getActiveLayout() != null) { MenuEntry menu = event.getMenuEntry(); Widget w = menu.getWidget(); @@ -695,9 +727,9 @@ private void scrollLayout(Layout l) private class DefaultLayout implements AutoLayout { @Override - public Layout generateLayout(TagTab tab) + public Layout generateLayout(Layout previous) { - Layout l = new Layout(tab.getLayout()); + Layout l = new Layout(previous); List removed = new ArrayList<>(); // Equipment diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/banktags/tabs/PotionStorage.java b/runelite-client/src/main/java/net/runelite/client/plugins/banktags/tabs/PotionStorage.java index 532ec72eb76..fd02378369f 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/banktags/tabs/PotionStorage.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/banktags/tabs/PotionStorage.java @@ -95,7 +95,7 @@ public void onClientTick(ClientTick event) if (layout) { layout = false; - BankTag activeTag = plugin.getActiveTag(); + BankTag activeTag = plugin.getActiveBankTag(); if (activeTag != null) { bankSearch.layoutBank(); diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/banktags/tabs/TabInterface.java b/runelite-client/src/main/java/net/runelite/client/plugins/banktags/tabs/TabInterface.java index 9f3f77cf2f2..9aea08c3458 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/banktags/tabs/TabInterface.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/banktags/tabs/TabInterface.java @@ -88,6 +88,7 @@ import net.runelite.client.plugins.banktags.BankTagsPlugin; import static net.runelite.client.plugins.banktags.BankTagsPlugin.TAG_SEARCH; import static net.runelite.client.plugins.banktags.BankTagsPlugin.VAR_TAG_SUFFIX; +import net.runelite.client.plugins.banktags.BankTagsService; import net.runelite.client.plugins.banktags.TagManager; import net.runelite.client.ui.JagexColors; import net.runelite.client.util.ColorUtil; @@ -112,7 +113,7 @@ public class TabInterface private static final String REMOVE_TAG = "Remove-tag"; private static final String TAG_GEAR = "Tag-equipment"; private static final String TAG_INVENTORY = "Tag-inventory"; - private static final String TAB_MENU_KEY = "tagtabs"; + private static final String TAGTABS = "tagtabs"; private static final String OPEN_TAB_MENU = "View tag tabs"; static final String ENABLE_LAYOUT = "Enable layout"; static final String DISABLE_LAYOUT = "Disable layout"; @@ -150,6 +151,7 @@ public class TabInterface private final ItemManager itemManager; private final TagManager tagManager; private final TabManager tabManager; + private final LayoutManager layoutManager; private final ChatboxPanelManager chatboxPanelManager; private final BankTagsConfig config; private final BankSearch bankSearch; @@ -158,7 +160,11 @@ public class TabInterface private boolean enabled; @Getter - private TagTab activeTab; + private String activeTag; + private Layout activeLayout; + private int activeOptions; +// @Getter +// private BankTag activeBankTag; @Getter private boolean tagTabActive; private int tagTabFirstChildIdx = -1; @@ -180,6 +186,7 @@ private TabInterface( final ItemManager itemManager, final TagManager tagManager, final TabManager tabManager, + final LayoutManager layoutManager, final ChatboxPanelManager chatboxPanelManager, final BankTagsConfig config, final BankSearch bankSearch, @@ -193,6 +200,7 @@ private TabInterface( this.itemManager = itemManager; this.tagManager = tagManager; this.tabManager = tabManager; + this.layoutManager = layoutManager; this.chatboxPanelManager = chatboxPanelManager; this.config = config; this.bankSearch = bankSearch; @@ -200,11 +208,6 @@ private TabInterface( this.chatMessageManager = chatMessageManager; } - public boolean isActive() - { - return activeTab != null; - } - @Subscribe public void onScriptPreFired(ScriptPreFired event) { @@ -246,7 +249,7 @@ else if (event.getScriptId() == ScriptID.BANKMAIN_SIZE_CHECK && enabled) } else if (event.getScriptId() == ScriptID.BANKMAIN_SEARCH_TOGGLE) { - if (activeTab != null || tagTabActive) + if (activeTag != null || tagTabActive) { // close the active tab when search is pressed closeTag(false); @@ -270,10 +273,10 @@ else if (event.getScriptId() == ScriptID.BANKMAIN_FINISHBUILDING && enabled) Widget bankTitle = client.getWidget(ComponentID.BANK_TITLE_BAR); bankTitle.setText("Tag tab tab"); } - else if (activeTab != null) + else if (activeTag != null) { Widget bankTitle = client.getWidget(ComponentID.BANK_TITLE_BAR); - bankTitle.setText("Tag tab " + activeTab.getTag() + ""); + bankTitle.setText("Tag tab " + activeTag + ""); } // Recompute scroll size. Only required for tag tab tab since it doesn't show real items. @@ -295,8 +298,10 @@ public void onWidgetClosed(WidgetClosed event) { enabled = false; upButton = downButton = newTab = scrollComponent = parent = null; - activeTab = null; - plugin.open(null); + activeTag = null; + activeLayout = null; + activeOptions = 0; + plugin.openTag(null, null); tagTabActive = false; tagTabFirstChildIdx = -1; } @@ -346,9 +351,8 @@ private void init() // the server will resync the last opened vanilla tab when the bank is opened client.setVarbit(Varbits.CURRENT_BANK_TAB, 0); var tab = config.tab(); - activeTab = tabManager.find(tab); - tagTabActive = TAB_MENU_KEY.equals(tab); - plugin.open(activeTab); + var layout = layoutManager.loadLayout(tab); + plugin.openTag(tab, layout); } // Move equipment button to the titlebar @@ -391,8 +395,10 @@ private void init() public void deinit() { enabled = false; - activeTab = null; - plugin.open(null); + activeTag = null; + activeLayout = null; + activeOptions = 0; + plugin.openTag(null, null); upButton = downButton = newTab = scrollComponent = null; @@ -422,11 +428,11 @@ private void handleDeposit(MenuOptionClicked event, boolean inventory) if (!Strings.isNullOrEmpty(event.getMenuTarget())) { - if (activeTab != null && Text.removeTags(event.getMenuTarget()).equals(activeTab.getTag())) + if (activeTag != null && Text.removeTags(event.getMenuTarget()).equals(activeTag)) { for (Integer item : items) { - tagManager.addTag(item, activeTab.getTag(), false); + tagManager.addTag(item, activeTag, false); } reloadActiveTab(); @@ -498,7 +504,7 @@ private void handleNewTab(ScriptEvent event) rebuildTabs(); rebuildTagTabTab(); - if (activeTab != null && tab.getTag().equals(activeTab.getTag())) + if (tab.getTag().equals(activeTag)) { bankSearch.reset(true); } @@ -513,7 +519,7 @@ private void handleNewTab(ScriptEvent event) break; case NEWTAB_OP_OPEN_TAB_MENU: client.setVarbit(Varbits.CURRENT_BANK_TAB, 0); - openNamedTag(TAB_MENU_KEY, true); + openTag(TAGTABS, null, 0, true); break; } } @@ -559,7 +565,7 @@ private TagTab importTag(Iterator dataIter) if (dataIter.hasNext()) { - Layout l = new Layout(); + Layout l = new Layout(name); while (dataIter.hasNext()) { final int idx = Integer.parseInt(dataIter.next()); @@ -568,7 +574,7 @@ private TagTab importTag(Iterator dataIter) tagManager.addTag(itemId, name, false); } - tab.setLayout(l); + layoutManager.saveLayout(l); } return tab; @@ -596,8 +602,7 @@ private TagTab importBtlTag(Iterator dataIter) name = sb.toString(); TagTab tab = tabManager.load(name); - Layout l = new Layout(); - tab.setLayout(l); + Layout l = new Layout(name); while (dataIter.hasNext()) { @@ -622,6 +627,8 @@ private TagTab importBtlTag(Iterator dataIter) tagManager.addTag(itemId, name, itemId < 0); } + layoutManager.saveLayout(l); + return tab; } @@ -642,15 +649,16 @@ private void opTagTab(ScriptEvent event) Widget clicked = event.getSource(); - TagTab tab = tabManager.find(Text.removeTags(clicked.getName())); + String tag = Text.removeTags(clicked.getName()); - if (tab.equals(activeTab)) + if (tag.equals(activeTag)) { closeTag(true); } else { - openTag(tab, true); + Layout layout = layoutManager.loadLayout(tag); + plugin.openTag(tag, layout); } client.playSoundEffect(SoundEffectID.UI_BOOP); @@ -677,23 +685,26 @@ private void opTagTab(ScriptEvent event) } case TAB_OP_LAYOUT: { - TagTab tab = tabManager.find(Text.removeTags(event.getSource().getName())); - if (tab == null) - { - return; - } + String tag = Text.removeTags(event.getSource().getName()); + Layout layout = layoutManager.loadLayout(tag); - if (!tab.hasLayout()) + if (layout == null) { - tab.setLayout(new Layout()); - sendChatMessage("Tag tab '" + tab.getTag() + "' is now in layout mode. You may reorder the items without changing their order in the bank."); + layout = new Layout(tag); + layoutManager.saveLayout(layout); + sendChatMessage("Tag tab '" + tag + "' is now in layout mode. You may reorder the items without changing their order in the bank."); } else { - tab.setLayout(null); - sendChatMessage("Tag tab '" + tab.getTag() + "' is no longer in layout mode"); + layoutManager.removeLayout(tag); + layout = null; + sendChatMessage("Tag tab '" + tag + "' is no longer in layout mode"); + } + + if (tag.equals(activeTag)) + { + plugin.openTag(tag, layout); } - tabManager.save(); bankSearch.layoutBank(); break; @@ -714,7 +725,9 @@ private void opTagTab(ScriptEvent event) break; case TAB_OP_EXPORT_TAB: final List data = new ArrayList<>(); - final TagTab tagTab = tabManager.find(Text.removeTags(event.getOpbase())); + final String tag = Text.removeTags(event.getOpbase()); + final TagTab tagTab = tabManager.find(tag); + final Layout layout = layoutManager.loadLayout(tag); data.add("banktags"); data.add("1"); data.add(tagTab.getTag()); @@ -722,22 +735,22 @@ private void opTagTab(ScriptEvent event) for (Integer item : tagManager.getItemsForTag(tagTab.getTag())) { - if (!tagTab.hasLayout() || tagTab.getLayout().count(item) == 0) + if (layout == null || layout.count(item) == 0) { data.add(String.valueOf(item)); } } - if (tagTab.hasLayout()) + if (layout != null) { data.add("layout"); - int[] layout = tagTab.getLayout().getLayout(); - for (int idx = 0; idx < layout.length; ++idx) + int[] l = layout.getLayout(); + for (int idx = 0; idx < l.length; ++idx) { - if (layout[idx] != -1) + if (l[idx] != -1) { data.add(String.valueOf(idx)); - data.add(String.valueOf(layout[idx])); + data.add(String.valueOf(l[idx])); } } } @@ -756,11 +769,11 @@ private void opTagTab(ScriptEvent event) @Subscribe private void onMenuEntryAdded(MenuEntryAdded event) { - if (activeTab != null + if ((activeOptions & BankTagsService.OPTION_ALLOW_MODIFICATIONS) != 0 && event.getActionParam1() == ComponentID.BANK_ITEM_CONTAINER && event.getOption().equals("Examine")) { - if (activeTab.hasLayout()) + if (activeLayout != null) { client.createMenuEntry(-1) .setParam0(event.getActionParam0()) @@ -773,7 +786,7 @@ private void onMenuEntryAdded(MenuEntryAdded event) .onClick(this::opDuplicateItem); } - if (activeTab.hasLayout() && activeTab.getLayout().count(itemManager.canonicalize(event.getItemId())) > 1) + if (activeLayout != null && activeLayout.count(itemManager.canonicalize(event.getItemId())) > 1) { client.createMenuEntry(-1) .setParam0(event.getActionParam0()) @@ -790,25 +803,25 @@ private void onMenuEntryAdded(MenuEntryAdded event) .setParam0(event.getActionParam0()) .setParam1(event.getActionParam1()) .setTarget(event.getTarget()) - .setOption(REMOVE_TAG + " (" + activeTab.getTag() + ")") + .setOption((activeOptions & BankTagsService.OPTION_HIDE_REMOVE_TAG_NAME) == 0 ? REMOVE_TAG + " (" + activeTag + ")" : REMOVE_TAG) .setType(MenuAction.RUNELITE) .setIdentifier(event.getIdentifier()) .setItemId(event.getItemId()) .onClick(e -> { final int itemId = e.getItemId(); - if (activeTab.hasLayout()) + if (activeLayout != null) { - activeTab.getLayout().removeItem(itemId); - tabManager.save(); + activeLayout.removeItem(itemId); + layoutManager.saveLayout(activeLayout); } - tagManager.removeTag(itemId, activeTab.getTag()); + tagManager.removeTag(itemId, activeTag); bankSearch.layoutBank(); // re-layout to filter the removed item out }); } } // Duplicate/Remove on layout placeholders - else if (activeTab != null + else if (activeTag != null && event.getActionParam1() == ComponentID.BANK_ITEM_CONTAINER && event.getOption().equals(DUPLICATE_ITEM)) { @@ -816,7 +829,7 @@ else if (activeTab != null event.getMenuEntry().setType(MenuAction.RUNELITE_LOW_PRIORITY); event.getMenuEntry().onClick(this::opDuplicateItem); } - if (activeTab != null + if (activeTag != null && event.getActionParam1() == ComponentID.BANK_ITEM_CONTAINER && event.getOption().equals(REMOVE_LAYOUT)) { @@ -828,9 +841,9 @@ else if (event.getActionParam1() == ComponentID.BANK_DEPOSIT_INVENTORY { createMenuEntry(event, TAG_INVENTORY, event.getTarget()); - if (activeTab != null) + if (activeTag != null && (activeOptions & BankTagsService.OPTION_ALLOW_MODIFICATIONS) != 0) { - createMenuEntry(event, TAG_INVENTORY, ColorUtil.wrapWithColorTag(activeTab.getTag(), HILIGHT_COLOR)); + createMenuEntry(event, TAG_INVENTORY, ColorUtil.wrapWithColorTag(activeTag, HILIGHT_COLOR)); } } else if (event.getActionParam1() == ComponentID.BANK_DEPOSIT_EQUIPMENT @@ -838,30 +851,32 @@ else if (event.getActionParam1() == ComponentID.BANK_DEPOSIT_EQUIPMENT { createMenuEntry(event, TAG_GEAR, event.getTarget()); - if (activeTab != null) + if (activeTag != null && (activeOptions & BankTagsService.OPTION_ALLOW_MODIFICATIONS) != 0) { - createMenuEntry(event, TAG_GEAR, ColorUtil.wrapWithColorTag(activeTab.getTag(), HILIGHT_COLOR)); + createMenuEntry(event, TAG_GEAR, ColorUtil.wrapWithColorTag(activeTag, HILIGHT_COLOR)); } } + + layoutManager.onMenuEntryAdded(event, this); } private void opDuplicateItem(MenuEntry e) { int id = itemManager.canonicalize(e.getItemId()); log.debug("Duplicate item {} at {}", itemManager.getItemComposition(id).getName(), e.getParam0()); - activeTab.getLayout().addItemAfter(id, e.getParam0()); - tabManager.save(); + activeLayout.addItemAfter(id, e.getParam0()); + layoutManager.saveLayout(activeLayout); bankSearch.layoutBank(); } private void opRemoveLayout(MenuEntry e) { - activeTab.getLayout().removeItemAtPos(e.getParam0()); - tabManager.save(); + activeLayout.removeItemAtPos(e.getParam0()); + layoutManager.saveLayout(activeLayout); bankSearch.layoutBank(); } - @Subscribe + @Subscribe(priority = -1) public void onMenuOptionClicked(MenuOptionClicked event) { // Close the chatbox input when clicking on things in the bank, to mimic how actions like withdrawing @@ -888,6 +903,8 @@ else if (event.getMenuAction() == MenuAction.RUNELITE { handleDeposit(event, event.getParam1() == ComponentID.BANK_DEPOSIT_INVENTORY); } + + layoutManager.onMenuOptionClicked(event); } @Subscribe @@ -903,8 +920,9 @@ public void onDraggingWidgetChanged(DraggingWidgetChanged event) // Returning early or nulling the drag release listener has no effect. Hence, we need to // null the draggedOnWidget instead. - if (draggedWidget.getId() == ComponentID.BANK_ITEM_CONTAINER && activeTab != null && !activeTab.hasLayout() - && config.preventTagTabDrags()) + if (draggedWidget.getId() == ComponentID.BANK_ITEM_CONTAINER && activeTag != null + && (activeLayout == null && config.preventTagTabDrags() + || (activeOptions & BankTagsService.OPTION_ALLOW_MODIFICATIONS) == 0)) { client.setDraggedOnWidget(null); } @@ -994,9 +1012,9 @@ private void addTabActions(TagTab tab, Widget w) { w.setAction(TAB_OP_OPEN_TAG, VIEW_TAB); w.setAction(TAB_OP_CHANGE_ICON, CHANGE_ICON); - if (!TAB_MENU_KEY.equals(tab.getTag())) + if (!TAGTABS.equals(tab.getTag())) { - w.setAction(TAB_OP_LAYOUT, tab.hasLayout() ? DISABLE_LAYOUT : ENABLE_LAYOUT); + w.setAction(TAB_OP_LAYOUT, activeLayout != null ? DISABLE_LAYOUT : ENABLE_LAYOUT); } w.setAction(TAB_OP_EXPORT_TAB, EXPORT_TAB); w.setAction(TAB_OP_RENAME_TAB, RENAME_TAB); @@ -1025,7 +1043,7 @@ private void loadTab(String tag) private void deleteTab(String tag) { - if (activeTab != null && activeTab.getTag().equals(tag)) + if (tag.equals(activeTag)) { closeTag(true); } @@ -1033,6 +1051,8 @@ private void deleteTab(String tag) tabManager.remove(tag); tabManager.save(); + layoutManager.removeLayout(tag); + repositionButtons(); rebuildTabs(); rebuildTagTabTab(); @@ -1050,12 +1070,27 @@ private void renameTab(String oldTag) if (tabManager.find(newTag) == null) { TagTab tagTab = tabManager.find(oldTag); + Layout layout = layoutManager.loadLayout(oldTag); + + tabManager.remove(oldTag); // remove the icon + layoutManager.removeLayout(oldTag); // remove the layout - tabManager.remove(oldTag); // remove the icon/layout of the old tag tagTab.setTag(newTag); + tabManager.add(tagTab); tabManager.save(); + if (activeTag.equals(oldTag)) + { + activeTag = newTag; + } + + if (layout != null) + { + Layout newLayout = new Layout(newTag, layout.getLayout()); + layoutManager.saveLayout(newLayout); + } + tagManager.renameTag(oldTag, newTag); // rename tag on items rebuildTabs(); @@ -1070,12 +1105,11 @@ private void renameTab(String oldTag) clientThread.invoke(() -> { tagManager.renameTag(oldTag, newTag); - final String activeTag = activeTab != null ? activeTab.getTag() : ""; deleteTab(oldTag); - if (activeTag.equals(oldTag)) + if (oldTag.equals(activeTag)) { - openNamedTag(newTag, true); + plugin.openBankTag(newTag); } else { @@ -1124,25 +1158,13 @@ private void scrollTab(int d) layoutTabs(); } - private void openNamedTag(String name, boolean relayout) + public void openTag(String tag, Layout layout, int options, boolean relayout) { - activeTab = tabManager.find(name); - tagTabActive = TAB_MENU_KEY.equals(name); - plugin.open(activeTab); - config.tab(name); - - if (relayout) - { - bankSearch.reset(true); - } - } - - private void openTag(TagTab tab, boolean relayout) - { - activeTab = tab; - tagTabActive = tab != null && TAB_MENU_KEY.equals(tab.getTag()); - plugin.open(activeTab); - config.tab(tab != null ? tab.getTag() : ""); + activeTag = tag; + activeLayout = layout; + activeOptions = options; + tagTabActive = TAGTABS.equals(tag); + config.tab(tag); if (relayout) { @@ -1152,9 +1174,11 @@ private void openTag(TagTab tab, boolean relayout) public void closeTag(boolean relayout) { - activeTab = null; + activeTag = null; + activeLayout = null; + activeOptions = 0; tagTabActive = false; - plugin.open(null); + plugin.openTag(null, null); config.tab(""); if (relayout) @@ -1165,9 +1189,9 @@ public void closeTag(boolean relayout) public void reloadActiveTab() { - if (activeTab != null) + if (activeTag != null) { - bankSearch.reset(true); + plugin.openBankTag(activeTag); } } @@ -1235,7 +1259,7 @@ private void rebuildTabs() for (TagTab tab : tabs) { Widget background = createGraphic(parent, ColorUtil.wrapWithColorTag(tab.getTag(), HILIGHT_COLOR), - (activeTab == tab ? TabSprites.TAB_BACKGROUND_ACTIVE : TabSprites.TAB_BACKGROUND).getSpriteId(), + (tab.getTag().equals(activeTag) ? TabSprites.TAB_BACKGROUND_ACTIVE : TabSprites.TAB_BACKGROUND).getSpriteId(), -1, TAB_WIDTH, TAB_HEIGHT, MARGIN, -1); addTabActions(tab, background); diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/banktags/tabs/TabManager.java b/runelite-client/src/main/java/net/runelite/client/plugins/banktags/tabs/TabManager.java index 59359aa4e79..63272535fdc 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/banktags/tabs/TabManager.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/banktags/tabs/TabManager.java @@ -38,7 +38,6 @@ import net.runelite.client.config.ConfigManager; import static net.runelite.client.plugins.banktags.BankTagsPlugin.CONFIG_GROUP; import static net.runelite.client.plugins.banktags.BankTagsPlugin.TAG_ICON_PREFIX; -import static net.runelite.client.plugins.banktags.BankTagsPlugin.TAG_LAYOUT_PREFIX; import static net.runelite.client.plugins.banktags.BankTagsPlugin.TAG_TABS_CONFIG; import net.runelite.client.util.Text; import org.apache.commons.lang3.math.NumberUtils; @@ -61,10 +60,6 @@ public void add(TagTab tagTab) if (!contains(tagTab.getTag())) { tabs.add(tagTab); - if (tagTab.hasLayout()) - { - tagTab.getLayout().dirty = true; - } } } @@ -94,19 +89,6 @@ TagTab load(String tag) String item = configManager.getConfiguration(CONFIG_GROUP, TAG_ICON_PREFIX + tag); int itemid = NumberUtils.toInt(item, ItemID.SPADE); tagTab = new TagTab(itemid, tag); - - String layoutStr = configManager.getConfiguration(CONFIG_GROUP, TAG_LAYOUT_PREFIX + tag); - if (layoutStr != null) - { - List layoutList = Text.fromCSV(layoutStr); - int[] layout = new int[layoutList.size()]; - for (int i = 0; i < layoutList.size(); ++i) - { - layout[i] = Integer.parseInt(layoutList.get(i)); - } - - tagTab.setLayout(new Layout(layout)); - } } return tagTab; @@ -115,19 +97,6 @@ TagTab load(String tag) private void save(TagTab tab) { setIcon(tab.getTag(), tab.getIconItemId()); - - if (tab.hasLayout()) - { - Layout layout = tab.getLayout(); - if (layout.dirty) - { - setLayout(tab.getTag(), layout.getLayout()); - } - } - else - { - removeLayout(tab.getTag()); - } } void swap(String tagToMove, String tagDestination) @@ -160,7 +129,6 @@ public void remove(String tag) { tabs.remove(tagTab); removeIcon(tag); - removeLayout(tag); } } @@ -185,25 +153,6 @@ private void setIcon(final String tag, int itemId) configManager.setConfiguration(CONFIG_GROUP, TAG_ICON_PREFIX + Text.standardize(tag), itemId); } - private void removeLayout(String tag) - { - configManager.unsetConfiguration(CONFIG_GROUP, TAG_LAYOUT_PREFIX + Text.standardize(tag)); - } - - private void setLayout(String tag, int[] layout) - { - StringBuilder sb = new StringBuilder(layout.length * 5); - for (int i = 0; i < layout.length; ++i) - { - if (i > 0) - { - sb.append(','); - } - sb.append(layout[i]); - } - configManager.setConfiguration(CONFIG_GROUP, TAG_LAYOUT_PREFIX + Text.standardize(tag), sb.toString()); - } - int size() { return tabs.size(); diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/banktags/tabs/TagTab.java b/runelite-client/src/main/java/net/runelite/client/plugins/banktags/tabs/TagTab.java index f85af47bae6..7755924a340 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/banktags/tabs/TagTab.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/banktags/tabs/TagTab.java @@ -30,7 +30,7 @@ import lombok.NoArgsConstructor; /** - * A bank tag tab. + * A bank tag tab. This represents one of the tabs on the left hand side of the bank. * * @see TabManager#add(TagTab) * @see TabManager#remove(String) @@ -42,16 +42,10 @@ public class TagTab { private String tag; private int iconItemId; - private Layout layout; TagTab(int iconItemId, String tag) { this.iconItemId = iconItemId; this.tag = tag; } - - public boolean hasLayout() - { - return layout != null; - } }