From 91230f4ca84be3c9396840e2f81ea0b5bde43a01 Mon Sep 17 00:00:00 2001 From: Adam Date: Fri, 8 Nov 2024 09:44:58 -0500 Subject: [PATCH] bank tags: add hidden tags Hidden tags don't show in the edit-tags menu --- .../plugins/banktags/BankTagsPlugin.java | 26 +++++++++++++++---- .../client/plugins/banktags/TagManager.java | 18 +++++++++++++ .../plugins/banktags/tabs/TabInterface.java | 3 ++- .../plugins/banktags/BankTagsPluginTest.java | 5 ++++ 4 files changed, 46 insertions(+), 6 deletions(-) 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 771014d9849..b00a8cea68d 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 @@ -38,6 +38,7 @@ import java.util.function.Consumer; import java.util.stream.Collectors; import javax.inject.Inject; +import javax.inject.Named; import lombok.Getter; import lombok.extern.slf4j.Slf4j; import net.runelite.api.Client; @@ -82,11 +83,13 @@ public class BankTagsPlugin extends Plugin implements BankTagsService // banktags:icon_=id // banktags:tagtabs=tab,tab,tab,... // banktags:layout_=item,item,item,... + // banktags:hidden_=true public static final String CONFIG_GROUP = "banktags"; public static final String TAG_ICON_PREFIX = "icon_"; public static final String TAG_TABS_CONFIG = "tagtabs"; public static final String TAG_LAYOUT_PREFIX = "layout_"; static final String ITEM_KEY_PREFIX = "item_"; + static final String TAG_HIDDEN_PREFIX = "hidden_"; public static final String TAG_SEARCH = "tag:"; private static final String EDIT_TAGS_MENU_OPTION = "Edit-tags"; @@ -145,6 +148,10 @@ public class BankTagsPlugin extends Plugin implements BankTagsService @Inject private BankTagsConfig config; + @Inject + @Named("developerMode") + boolean developerMode; + @Getter private String activeTag; @@ -401,10 +408,15 @@ public void onMenuEntryAdded(MenuEntryAdded event) { Widget container = client.getWidget(ComponentID.BANK_ITEM_CONTAINER); Widget item = container.getChild(event.getActionParam0()); - int itemID = item.getItemId(); - String text = EDIT_TAGS_MENU_OPTION; - int tagCount = tagManager.getTags(itemID, false).size() + tagManager.getTags(itemID, true).size(); + int itemId = item.getItemId(); + Collection tags = tagManager.getTags(itemId, false); + tags.addAll(tagManager.getTags(itemId, true)); + int tagCount = (int) tags.stream() + .filter(tag -> !developerMode && !tagManager.isHidden(tag)) + .count(); + + String text = EDIT_TAGS_MENU_OPTION; if (tagCount > 0) { text += " (" + tagCount + ")"; @@ -429,9 +441,13 @@ private void editTags(MenuEntry entry) String name = itemComposition.getName(); // Get both tags and vartags and append * to end of vartags name - Collection tags = tagManager.getTags(itemId, false); + List tags = tagManager.getTags(itemId, false).stream() + .filter(tag -> !developerMode && !tagManager.isHidden(tag)) + .collect(Collectors.toList()); + tagManager.getTags(itemId, true).stream() - .map(i -> i + "*") + .filter(tag -> !developerMode && !tagManager.isHidden(tag)) + .map(tag -> tag + "*") .forEach(tags::add); String initialValue = Text.toCSV(tags); diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/banktags/TagManager.java b/runelite-client/src/main/java/net/runelite/client/plugins/banktags/TagManager.java index b3c0c9d5499..42ed4f37021 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/banktags/TagManager.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/banktags/TagManager.java @@ -39,6 +39,7 @@ import net.runelite.client.game.ItemVariationMapping; import static net.runelite.client.plugins.banktags.BankTagsPlugin.CONFIG_GROUP; import static net.runelite.client.plugins.banktags.BankTagsPlugin.ITEM_KEY_PREFIX; +import static net.runelite.client.plugins.banktags.BankTagsPlugin.TAG_HIDDEN_PREFIX; import net.runelite.client.util.Text; @Singleton @@ -167,6 +168,23 @@ public void renameTag(String oldTag, String newTag) }); } + public boolean isHidden(String tag) + { + return Boolean.TRUE.equals(configManager.getConfiguration(CONFIG_GROUP, TAG_HIDDEN_PREFIX + Text.standardize(tag), Boolean.class)); + } + + public void setHidden(String tag, boolean hidden) + { + if (hidden) + { + configManager.setConfiguration(CONFIG_GROUP, TAG_HIDDEN_PREFIX + Text.standardize(tag), true); + } + else + { + configManager.unsetConfiguration(CONFIG_GROUP, TAG_HIDDEN_PREFIX + Text.standardize(tag)); + } + } + private int getItemId(int itemId, boolean variation) { itemId = Math.abs(itemId); 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 c85495dce56..78bcc6270b7 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 @@ -797,11 +797,12 @@ private void onMenuEntryAdded(MenuEntryAdded event) } else { + boolean hidden = tagManager.isHidden(activeTag); client.createMenuEntry(-1) .setParam0(event.getActionParam0()) .setParam1(event.getActionParam1()) .setTarget(event.getTarget()) - .setOption((activeOptions & BankTagsService.OPTION_HIDE_REMOVE_TAG_NAME) == 0 ? REMOVE_TAG + " (" + activeTag + ")" : REMOVE_TAG) + .setOption(!hidden && (activeOptions & BankTagsService.OPTION_HIDE_REMOVE_TAG_NAME) == 0 ? REMOVE_TAG + " (" + activeTag + ")" : REMOVE_TAG) .setType(MenuAction.RUNELITE) .setIdentifier(event.getIdentifier()) .setItemId(event.getItemId()) diff --git a/runelite-client/src/test/java/net/runelite/client/plugins/banktags/BankTagsPluginTest.java b/runelite-client/src/test/java/net/runelite/client/plugins/banktags/BankTagsPluginTest.java index 2cef1ce3ffd..66efe448010 100644 --- a/runelite-client/src/test/java/net/runelite/client/plugins/banktags/BankTagsPluginTest.java +++ b/runelite-client/src/test/java/net/runelite/client/plugins/banktags/BankTagsPluginTest.java @@ -28,6 +28,7 @@ import com.google.inject.testing.fieldbinder.Bind; import com.google.inject.testing.fieldbinder.BoundFieldModule; import javax.inject.Inject; +import javax.inject.Named; import net.runelite.api.Client; import static net.runelite.api.ItemID.ABYSSAL_WHIP; import net.runelite.api.events.ScriptCallbackEvent; @@ -82,6 +83,10 @@ public class BankTagsPluginTest @Bind private ChatMessageManager chatMessageManager; + @Bind + @Named("developerMode") + boolean developerMode; + @Inject private TagManager tagManager;