Add ability to set/read tags on varations of items
Add ability to tag all variations of item in bank tags when holding shift. Closes #3767 Signed-off-by: Tomas Slusny <slusnucky@gmail.com>
This commit is contained in:
@@ -30,10 +30,14 @@ import com.google.common.base.Joiner;
|
||||
import com.google.common.base.Splitter;
|
||||
import com.google.common.eventbus.Subscribe;
|
||||
import com.google.inject.Provides;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.event.MouseWheelEvent;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Collection;
|
||||
import java.util.Objects;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
import javax.inject.Inject;
|
||||
import net.runelite.api.Client;
|
||||
import net.runelite.api.InventoryID;
|
||||
@@ -45,6 +49,7 @@ import net.runelite.api.MenuEntry;
|
||||
import net.runelite.api.VarClientStr;
|
||||
import net.runelite.api.events.ConfigChanged;
|
||||
import net.runelite.api.events.DraggingWidgetChanged;
|
||||
import net.runelite.api.events.FocusChanged;
|
||||
import net.runelite.api.events.GameTick;
|
||||
import net.runelite.api.events.MenuEntryAdded;
|
||||
import net.runelite.api.events.MenuOptionClicked;
|
||||
@@ -57,6 +62,8 @@ import net.runelite.client.callback.ClientThread;
|
||||
import net.runelite.client.config.ConfigManager;
|
||||
import net.runelite.client.game.ChatboxInputManager;
|
||||
import net.runelite.client.game.ItemManager;
|
||||
import net.runelite.client.input.KeyListener;
|
||||
import net.runelite.client.input.KeyManager;
|
||||
import net.runelite.client.input.MouseManager;
|
||||
import net.runelite.client.input.MouseWheelListener;
|
||||
import net.runelite.client.plugins.Plugin;
|
||||
@@ -72,7 +79,7 @@ import net.runelite.client.plugins.cluescrolls.ClueScrollPlugin;
|
||||
tags = {"searching", "tagging"}
|
||||
)
|
||||
@PluginDependency(ClueScrollPlugin.class)
|
||||
public class BankTagsPlugin extends Plugin implements MouseWheelListener
|
||||
public class BankTagsPlugin extends Plugin implements MouseWheelListener, KeyListener
|
||||
{
|
||||
public static final Splitter SPLITTER = Splitter.on(",").omitEmptyStrings().trimResults();
|
||||
public static final Joiner JOINER = Joiner.on(",").skipNulls();
|
||||
@@ -80,6 +87,7 @@ public class BankTagsPlugin extends Plugin implements MouseWheelListener
|
||||
public static final String TAG_SEARCH = "tag:";
|
||||
public static final String EDIT_TAGS_MENU_OPTION = "Edit-tags";
|
||||
public static final String ICON_SEARCH = "icon_";
|
||||
public static final String VAR_TAG_SUFFIX = "*";
|
||||
|
||||
private static final String SEARCH_BANK_INPUT_TEXT =
|
||||
"Show items whose names or tags contain the following text:<br>" +
|
||||
@@ -112,6 +120,11 @@ public class BankTagsPlugin extends Plugin implements MouseWheelListener
|
||||
@Inject
|
||||
private TabInterface tabInterface;
|
||||
|
||||
@Inject
|
||||
private KeyManager keyManager;
|
||||
|
||||
private boolean shiftPressed = false;
|
||||
|
||||
@Provides
|
||||
BankTagsConfig getConfig(ConfigManager configManager)
|
||||
{
|
||||
@@ -121,6 +134,7 @@ public class BankTagsPlugin extends Plugin implements MouseWheelListener
|
||||
@Override
|
||||
public void startUp()
|
||||
{
|
||||
keyManager.registerKeyListener(this);
|
||||
mouseManager.registerMouseWheelListener(this);
|
||||
clientThread.invokeLater(tabInterface::init);
|
||||
client.getSpriteOverrides().putAll(TabSprites.toMap(client));
|
||||
@@ -129,6 +143,7 @@ public class BankTagsPlugin extends Plugin implements MouseWheelListener
|
||||
@Override
|
||||
public void shutDown()
|
||||
{
|
||||
keyManager.unregisterKeyListener(this);
|
||||
mouseManager.unregisterMouseWheelListener(this);
|
||||
clientThread.invokeLater(tabInterface::destroy);
|
||||
|
||||
@@ -136,6 +151,8 @@ public class BankTagsPlugin extends Plugin implements MouseWheelListener
|
||||
{
|
||||
client.getSpriteOverrides().remove(value.getSpriteId());
|
||||
}
|
||||
|
||||
shiftPressed = false;
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
@@ -202,11 +219,13 @@ public class BankTagsPlugin extends Plugin implements MouseWheelListener
|
||||
Widget item = container.getChild(event.getActionParam0());
|
||||
int itemID = item.getItemId();
|
||||
String text = EDIT_TAGS_MENU_OPTION;
|
||||
int tagCount = tagManager.getTags(itemID).size();
|
||||
int tagCount = tagManager.getTags(itemID, false).size() + tagManager.getTags(itemID, true).size();
|
||||
|
||||
if (tagCount > 0)
|
||||
{
|
||||
text += " (" + tagCount + ")";
|
||||
}
|
||||
|
||||
MenuEntry editTags = new MenuEntry();
|
||||
editTags.setParam0(event.getActionParam0());
|
||||
editTags.setParam1(event.getActionParam1());
|
||||
@@ -249,24 +268,40 @@ public class BankTagsPlugin extends Plugin implements MouseWheelListener
|
||||
|
||||
int itemId = item.getId();
|
||||
ItemComposition itemComposition = itemManager.getItemComposition(itemId);
|
||||
String itemName = itemComposition.getName();
|
||||
String initialValue = tagManager.getTagString(itemId);
|
||||
String name = itemComposition.getName();
|
||||
|
||||
chatboxInputManager.openInputWindow(itemName + " tags:", initialValue, (newTags) ->
|
||||
// Get both tags and vartags and append * to end of vartags name
|
||||
Collection<String> tags = tagManager.getTags(itemId, false);
|
||||
tagManager.getTags(itemId, true).stream()
|
||||
.map(i -> i + "*")
|
||||
.forEach(tags::add);
|
||||
|
||||
// Create initial value string
|
||||
String initialValue = JOINER.join(tags);
|
||||
|
||||
chatboxInputManager.openInputWindow(name + " tags:<br>(append " + VAR_TAG_SUFFIX + " for variation tag)", initialValue, (newValue) ->
|
||||
{
|
||||
if (!Objects.equals(newTags, client.getVar(VarClientStr.INPUT_TEXT)))
|
||||
if (!Objects.equals(newValue, client.getVar(VarClientStr.INPUT_TEXT)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
tagManager.setTagString(itemId, newTags);
|
||||
// Split inputted tags to vartags (ending with *) and regular tags
|
||||
final Collection<String> newTags = new ArrayList<>(SPLITTER.splitToList(newValue.toLowerCase()));
|
||||
final Collection<String> newVarTags = new ArrayList<>(newTags).stream().filter(s -> s.endsWith(VAR_TAG_SUFFIX)).map(s ->
|
||||
{
|
||||
newTags.remove(s);
|
||||
return s.substring(0, s.length() - VAR_TAG_SUFFIX.length());
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
// And save them
|
||||
tagManager.setTagString(itemId, JOINER.join(newTags), false);
|
||||
tagManager.setTagString(itemId, JOINER.join(newVarTags), true);
|
||||
|
||||
// Check both previous and current tags in case the tag got removed in new tags or in case
|
||||
// the tag got added in new tags
|
||||
final List<String> initialTags = SPLITTER.splitToList(initialValue.toLowerCase());
|
||||
final List<String> tags = SPLITTER.splitToList(newTags.toLowerCase());
|
||||
tabInterface.updateTabIfActive(initialTags);
|
||||
tabInterface.updateTabIfActive(tags);
|
||||
tabInterface.updateTabIfActive(SPLITTER.splitToList(initialValue.toLowerCase().replaceAll(Pattern.quote(VAR_TAG_SUFFIX), "")));
|
||||
tabInterface.updateTabIfActive(SPLITTER.splitToList(newValue.toLowerCase().replaceAll(Pattern.quote(VAR_TAG_SUFFIX), "")));
|
||||
});
|
||||
}
|
||||
else
|
||||
@@ -300,7 +335,7 @@ public class BankTagsPlugin extends Plugin implements MouseWheelListener
|
||||
@Subscribe
|
||||
public void onDraggingWidgetChanged(DraggingWidgetChanged event)
|
||||
{
|
||||
tabInterface.handleDrag(event.isDraggingWidget());
|
||||
tabInterface.handleDrag(event.isDraggingWidget(), shiftPressed);
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
@@ -312,10 +347,42 @@ public class BankTagsPlugin extends Plugin implements MouseWheelListener
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onFocusChanged(FocusChanged event)
|
||||
{
|
||||
if (!event.isFocused())
|
||||
{
|
||||
shiftPressed = false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public MouseWheelEvent mouseWheelMoved(MouseWheelEvent event)
|
||||
{
|
||||
tabInterface.handleWheel(event);
|
||||
return event;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyTyped(KeyEvent e)
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyPressed(KeyEvent e)
|
||||
{
|
||||
if (e.getKeyCode() == KeyEvent.VK_SHIFT)
|
||||
{
|
||||
shiftPressed = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void keyReleased(KeyEvent e)
|
||||
{
|
||||
if (e.getKeyCode() == KeyEvent.VK_SHIFT)
|
||||
{
|
||||
shiftPressed = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@ import javax.inject.Singleton;
|
||||
import net.runelite.api.ItemID;
|
||||
import net.runelite.client.config.ConfigManager;
|
||||
import net.runelite.client.game.ItemManager;
|
||||
import net.runelite.client.game.ItemVariationMapping;
|
||||
import static net.runelite.client.plugins.banktags.BankTagsPlugin.CONFIG_GROUP;
|
||||
import static net.runelite.client.plugins.banktags.BankTagsPlugin.JOINER;
|
||||
import static net.runelite.client.plugins.banktags.BankTagsPlugin.SPLITTER;
|
||||
@@ -52,22 +53,25 @@ import net.runelite.client.util.Text;
|
||||
public class TagManager
|
||||
{
|
||||
private static final String ITEM_KEY_PREFIX = "item_";
|
||||
private final ItemManager itemManager;
|
||||
private final ConfigManager configManager;
|
||||
|
||||
private final ItemManager itemManager;
|
||||
private final ClueScrollService clueScrollService;
|
||||
|
||||
@Inject
|
||||
private TagManager(final ItemManager itemManager, final ConfigManager configManager, final ClueScrollService clueScrollService)
|
||||
private TagManager(
|
||||
final ItemManager itemManager,
|
||||
final ConfigManager configManager,
|
||||
final ClueScrollService clueScrollService)
|
||||
{
|
||||
this.itemManager = itemManager;
|
||||
this.configManager = configManager;
|
||||
this.clueScrollService = clueScrollService;
|
||||
}
|
||||
|
||||
String getTagString(int itemId)
|
||||
String getTagString(int itemId, boolean variation)
|
||||
{
|
||||
itemId = itemManager.canonicalize(itemId);
|
||||
itemId = getItemId(itemId, variation);
|
||||
|
||||
String config = configManager.getConfiguration(CONFIG_GROUP, ITEM_KEY_PREFIX + itemId);
|
||||
if (config == null)
|
||||
{
|
||||
@@ -77,14 +81,15 @@ public class TagManager
|
||||
return config;
|
||||
}
|
||||
|
||||
Collection<String> getTags(int itemId)
|
||||
Collection<String> getTags(int itemId, boolean variation)
|
||||
{
|
||||
return new LinkedHashSet<>(SPLITTER.splitToList(getTagString(itemId).toLowerCase()));
|
||||
return new LinkedHashSet<>(SPLITTER.splitToList(getTagString(itemId, variation).toLowerCase()));
|
||||
}
|
||||
|
||||
void setTagString(int itemId, String tags)
|
||||
void setTagString(int itemId, String tags, boolean variation)
|
||||
{
|
||||
itemId = itemManager.canonicalize(itemId);
|
||||
itemId = getItemId(itemId, variation);
|
||||
|
||||
if (Strings.isNullOrEmpty(tags))
|
||||
{
|
||||
configManager.unsetConfiguration(CONFIG_GROUP, ITEM_KEY_PREFIX + itemId);
|
||||
@@ -95,27 +100,27 @@ public class TagManager
|
||||
}
|
||||
}
|
||||
|
||||
public void addTags(int itemId, final Collection<String> t)
|
||||
public void addTags(int itemId, final Collection<String> t, boolean variation)
|
||||
{
|
||||
final Collection<String> tags = getTags(itemId);
|
||||
final Collection<String> tags = getTags(itemId, variation);
|
||||
if (tags.addAll(t))
|
||||
{
|
||||
setTags(itemId, tags);
|
||||
setTags(itemId, tags, variation);
|
||||
}
|
||||
}
|
||||
|
||||
public void addTag(int itemId, String tag)
|
||||
public void addTag(int itemId, String tag, boolean variation)
|
||||
{
|
||||
final Collection<String> tags = getTags(itemId);
|
||||
final Collection<String> tags = getTags(itemId, variation);
|
||||
if (tags.add(Text.standardize(tag)))
|
||||
{
|
||||
setTags(itemId, tags);
|
||||
setTags(itemId, tags, variation);
|
||||
}
|
||||
}
|
||||
|
||||
private void setTags(int itemId, Collection<String> tags)
|
||||
private void setTags(int itemId, Collection<String> tags, boolean variation)
|
||||
{
|
||||
setTagString(itemId, JOINER.join(tags));
|
||||
setTagString(itemId, JOINER.join(tags), variation);
|
||||
}
|
||||
|
||||
boolean findTag(int itemId, String search)
|
||||
@@ -125,7 +130,9 @@ public class TagManager
|
||||
return true;
|
||||
}
|
||||
|
||||
return getTags(itemId).stream().anyMatch(tag -> tag.contains(Text.standardize(search)));
|
||||
Collection<String> tags = getTags(itemId, false);
|
||||
tags.addAll(getTags(itemId, true));
|
||||
return tags.stream().anyMatch(tag -> tag.contains(Text.standardize(search)));
|
||||
}
|
||||
|
||||
public List<Integer> getItemsForTag(String tag)
|
||||
@@ -133,23 +140,46 @@ public class TagManager
|
||||
final String prefix = CONFIG_GROUP + "." + ITEM_KEY_PREFIX;
|
||||
return configManager.getConfigurationKeys(prefix).stream()
|
||||
.map(item -> Integer.parseInt(item.replace(prefix, "")))
|
||||
.filter(item -> getTags(item).contains(tag))
|
||||
.filter(item -> getTags(item, false).contains(tag) || getTags(item, true).contains(tag))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public void removeTag(String tag)
|
||||
{
|
||||
final String prefix = CONFIG_GROUP + "." + ITEM_KEY_PREFIX;
|
||||
configManager.getConfigurationKeys(prefix).forEach(item -> removeTag(Integer.parseInt(item.replace(prefix, "")), tag));
|
||||
configManager.getConfigurationKeys(prefix).forEach(item ->
|
||||
{
|
||||
int id = Integer.parseInt(item.replace(prefix, ""));
|
||||
removeTag(id, tag);
|
||||
});
|
||||
}
|
||||
|
||||
public void removeTag(int itemId, String tag)
|
||||
{
|
||||
final Collection<String> tags = getTags(itemId);
|
||||
Collection<String> tags = getTags(itemId, false);
|
||||
if (tags.remove(Text.standardize(tag)))
|
||||
{
|
||||
setTags(itemId, tags);
|
||||
setTags(itemId, tags, false);
|
||||
}
|
||||
|
||||
tags = getTags(itemId, true);
|
||||
if (tags.remove(Text.standardize(tag)))
|
||||
{
|
||||
setTags(itemId, tags, true);
|
||||
}
|
||||
}
|
||||
|
||||
private int getItemId(int itemId, boolean variation)
|
||||
{
|
||||
itemId = Math.abs(itemId);
|
||||
itemId = itemManager.canonicalize(itemId);
|
||||
|
||||
if (variation)
|
||||
{
|
||||
itemId = ItemVariationMapping.map(itemId) * -1;
|
||||
}
|
||||
|
||||
return itemId;
|
||||
}
|
||||
|
||||
private boolean testClue(int itemId)
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
package net.runelite.client.plugins.banktags.tabs;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.collect.Lists;
|
||||
import java.awt.Color;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.Toolkit;
|
||||
@@ -80,6 +81,7 @@ import static net.runelite.client.plugins.banktags.BankTagsPlugin.CONFIG_GROUP;
|
||||
import static net.runelite.client.plugins.banktags.BankTagsPlugin.ICON_SEARCH;
|
||||
import static net.runelite.client.plugins.banktags.BankTagsPlugin.SPLITTER;
|
||||
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.TagManager;
|
||||
import net.runelite.client.util.ColorUtil;
|
||||
import net.runelite.client.util.Text;
|
||||
@@ -453,7 +455,7 @@ public class TabInterface
|
||||
{
|
||||
for (Integer item : items)
|
||||
{
|
||||
tagManager.addTag(item, activeTab.getTag());
|
||||
tagManager.addTag(item, activeTab.getTag(), false);
|
||||
}
|
||||
|
||||
openTag(TAG_SEARCH + activeTab.getTag());
|
||||
@@ -472,7 +474,7 @@ public class TabInterface
|
||||
|
||||
for (Integer item : items)
|
||||
{
|
||||
tagManager.addTags(item, tags);
|
||||
tagManager.addTags(item, tags, false);
|
||||
}
|
||||
|
||||
updateTabIfActive(tags);
|
||||
@@ -590,7 +592,8 @@ public class TabInterface
|
||||
|
||||
while (dataIter.hasNext())
|
||||
{
|
||||
tagManager.addTag(Integer.valueOf(dataIter.next()), name);
|
||||
final int itemId = Integer.valueOf(dataIter.next());
|
||||
tagManager.addTag(itemId, name, itemId < 0);
|
||||
}
|
||||
|
||||
loadTab(name);
|
||||
@@ -620,7 +623,7 @@ public class TabInterface
|
||||
}
|
||||
}
|
||||
|
||||
public void handleDrag(boolean isDragging)
|
||||
public void handleDrag(boolean isDragging, boolean shiftDown)
|
||||
{
|
||||
if (isHidden())
|
||||
{
|
||||
@@ -643,8 +646,8 @@ public class TabInterface
|
||||
// Tag an item dragged on a tag tab
|
||||
if (draggedOn.getId() == parent.getId())
|
||||
{
|
||||
int itemId = draggedWidget.getItemId();
|
||||
tagManager.addTag(itemId, draggedOn.getName());
|
||||
tagManager.addTag(draggedWidget.getItemId(), draggedOn.getName(), shiftDown);
|
||||
updateTabIfActive(Lists.newArrayList(Text.standardize(draggedOn.getName())));
|
||||
}
|
||||
}
|
||||
else if (parent.getId() == draggedOn.getId() && parent.getId() == draggedWidget.getId())
|
||||
@@ -668,7 +671,7 @@ public class TabInterface
|
||||
|
||||
if (draggedWidget.getItemId() > 0 && entry.getOption().equals(VIEW_TAB) && draggedOn.getId() != draggedWidget.getId())
|
||||
{
|
||||
entry.setOption(TAG_SEARCH + Text.removeTags(entry.getTarget()));
|
||||
entry.setOption(TAG_SEARCH + Text.removeTags(entry.getTarget()) + (shiftDown ? VAR_TAG_SUFFIX : ""));
|
||||
entry.setTarget(draggedWidget.getName());
|
||||
client.setMenuEntries(entries);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user