Skip to content

Commit

Permalink
bank tags: add hidden tags
Browse files Browse the repository at this point in the history
Hidden tags don't show in the edit-tags menu
  • Loading branch information
Adam- committed Nov 8, 2024
1 parent 5a709ca commit 91230f4
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -82,11 +83,13 @@ public class BankTagsPlugin extends Plugin implements BankTagsService
// banktags:icon_<tag>=id
// banktags:tagtabs=tab,tab,tab,...
// banktags:layout_<tag>=item,item,item,...
// banktags:hidden_<tag>=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";
Expand Down Expand Up @@ -145,6 +148,10 @@ public class BankTagsPlugin extends Plugin implements BankTagsService
@Inject
private BankTagsConfig config;

@Inject
@Named("developerMode")
boolean developerMode;

@Getter
private String activeTag;

Expand Down Expand Up @@ -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<String> 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 + ")";
Expand All @@ -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<String> tags = tagManager.getTags(itemId, false);
List<String> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -82,6 +83,10 @@ public class BankTagsPluginTest
@Bind
private ChatMessageManager chatMessageManager;

@Bind
@Named("developerMode")
boolean developerMode;

@Inject
private TagManager tagManager;

Expand Down

0 comments on commit 91230f4

Please sign in to comment.