Merge pull request #5520 from Abextm/bank-tags-10-menu
banktags: Don't use cs2 to add menu options
This commit is contained in:
@@ -229,6 +229,26 @@ public class ItemManager
|
||||
return itemCompositions.getUnchecked(itemId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an item's un-noted, un-placeholdered ID
|
||||
*/
|
||||
public int canonicalize(int itemID)
|
||||
{
|
||||
ItemComposition itemComposition = getItemComposition(itemID);
|
||||
|
||||
if (itemComposition.getNote() != -1)
|
||||
{
|
||||
return itemComposition.getLinkedNoteId();
|
||||
}
|
||||
|
||||
if (itemComposition.getPlaceholderTemplateId() != -1)
|
||||
{
|
||||
return itemComposition.getPlaceholderId();
|
||||
}
|
||||
|
||||
return itemID;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads item sprite from game, makes transparent, and generates image
|
||||
*
|
||||
|
||||
@@ -29,16 +29,16 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import javax.inject.Inject;
|
||||
import net.runelite.api.Client;
|
||||
import net.runelite.api.IntegerNode;
|
||||
import net.runelite.api.InventoryID;
|
||||
import net.runelite.api.Item;
|
||||
import net.runelite.api.ItemComposition;
|
||||
import net.runelite.api.ItemContainer;
|
||||
import net.runelite.api.MenuAction;
|
||||
import net.runelite.api.MenuEntry;
|
||||
import net.runelite.api.events.MenuEntryAdded;
|
||||
import net.runelite.api.events.MenuOptionClicked;
|
||||
import net.runelite.api.events.ScriptCallbackEvent;
|
||||
import net.runelite.api.widgets.Widget;
|
||||
import net.runelite.api.widgets.WidgetConfig;
|
||||
import net.runelite.api.widgets.WidgetInfo;
|
||||
import net.runelite.client.config.ConfigManager;
|
||||
import net.runelite.client.game.ChatboxInputManager;
|
||||
@@ -59,7 +59,7 @@ public class BankTagsPlugin extends Plugin
|
||||
|
||||
private static final String SEARCH_BANK_INPUT_TEXT =
|
||||
"Show items whose names or tags contain the following text:<br>" +
|
||||
"(To show only tagged items, start your search with 'tag:')";
|
||||
"(To show only tagged items, start your search with 'tag:')";
|
||||
|
||||
private static final String SEARCH_BANK_INPUT_TEXT_FOUND =
|
||||
"Show items whose names or tags contain the following text: (%d found)<br>" +
|
||||
@@ -69,8 +69,6 @@ public class BankTagsPlugin extends Plugin
|
||||
|
||||
private static final String EDIT_TAGS_MENU_OPTION = "Edit-tags";
|
||||
|
||||
private static final int EDIT_TAGS_MENU_INDEX = 8;
|
||||
|
||||
@Inject
|
||||
private Client client;
|
||||
|
||||
@@ -140,39 +138,11 @@ public class BankTagsPlugin extends Plugin
|
||||
stringStack[stringStackSize - 1] = String.format(SEARCH_BANK_INPUT_TEXT_FOUND, matches);
|
||||
break;
|
||||
}
|
||||
case "setBankItemMenu":
|
||||
{
|
||||
// set menu action index so the edit tags option will not be overridden
|
||||
intStack[intStackSize - 3] = EDIT_TAGS_MENU_INDEX;
|
||||
|
||||
int itemId = intStack[intStackSize - 2];
|
||||
int tagCount = getTagCount(itemId);
|
||||
if (tagCount > 0)
|
||||
{
|
||||
stringStack[stringStackSize - 1] += " (" + tagCount + ")";
|
||||
}
|
||||
|
||||
int index = intStack[intStackSize - 1];
|
||||
long key = (long) index + ((long) WidgetInfo.BANK_ITEM_CONTAINER.getId() << 32);
|
||||
IntegerNode flagNode = (IntegerNode) client.getWidgetFlags().get(key);
|
||||
if (flagNode != null && flagNode.getValue() != 0)
|
||||
{
|
||||
flagNode.setValue(flagNode.getValue() | WidgetConfig.SHOW_MENU_OPTION_NINE);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "bankSearchFilter":
|
||||
int itemId = intStack[intStackSize - 1];
|
||||
int itemId = itemManager.canonicalize(intStack[intStackSize - 1]);
|
||||
String itemName = stringStack[stringStackSize - 2];
|
||||
String searchInput = stringStack[stringStackSize - 1];
|
||||
|
||||
ItemComposition itemComposition = itemManager.getItemComposition(itemId);
|
||||
if (itemComposition.getPlaceholderTemplateId() != -1)
|
||||
{
|
||||
// if the item is a placeholder then get the item id for the normal item
|
||||
itemId = itemComposition.getPlaceholderId();
|
||||
}
|
||||
|
||||
String tagsConfig = configManager.getConfiguration(CONFIG_GROUP, ITEM_KEY_PREFIX + itemId);
|
||||
if (tagsConfig == null || tagsConfig.length() == 0)
|
||||
{
|
||||
@@ -206,12 +176,58 @@ public class BankTagsPlugin extends Plugin
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onMenuEntryAdded(MenuEntryAdded event)
|
||||
{
|
||||
int widgetId = event.getActionParam1();
|
||||
if (widgetId != WidgetInfo.BANK_ITEM_CONTAINER.getId())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int index = event.getActionParam0();
|
||||
if (index < 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Examine is the only guaranteed menuop to be added
|
||||
if (!"Examine".equals(event.getOption()))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Widget container = client.getWidget(WidgetInfo.BANK_ITEM_CONTAINER);
|
||||
Widget item = container.getChild(index);
|
||||
int itemID = itemManager.canonicalize(item.getItemId());
|
||||
|
||||
String text = EDIT_TAGS_MENU_OPTION;
|
||||
|
||||
int tagCount = getTagCount(itemID);
|
||||
if (tagCount > 0)
|
||||
{
|
||||
text += " (" + tagCount + ")";
|
||||
}
|
||||
|
||||
MenuEntry editTags = new MenuEntry();
|
||||
editTags.setParam0(event.getActionParam0());
|
||||
editTags.setParam1(event.getActionParam1());
|
||||
editTags.setTarget(event.getTarget());
|
||||
editTags.setOption(text);
|
||||
editTags.setType(MenuAction.RUNELITE.getId());
|
||||
editTags.setIdentifier(event.getIdentifier());
|
||||
|
||||
MenuEntry[] entries = client.getMenuEntries();
|
||||
entries = Arrays.copyOf(entries, entries.length + 1);
|
||||
entries[entries.length - 1] = editTags;
|
||||
client.setMenuEntries(entries);
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onMenuOptionClicked(MenuOptionClicked event)
|
||||
{
|
||||
if (event.getWidgetId() == WidgetInfo.BANK_ITEM_CONTAINER.getId()
|
||||
&& event.getMenuAction() == MenuAction.EXAMINE_ITEM_BANK_EQ
|
||||
&& event.getId() == EDIT_TAGS_MENU_INDEX
|
||||
&& event.getMenuAction() == MenuAction.RUNELITE
|
||||
&& event.getMenuOption().startsWith(EDIT_TAGS_MENU_OPTION))
|
||||
{
|
||||
event.consume();
|
||||
@@ -231,18 +247,10 @@ public class BankTagsPlugin extends Plugin
|
||||
{
|
||||
return;
|
||||
}
|
||||
ItemComposition itemComposition = itemManager.getItemComposition(item.getId());
|
||||
int itemId;
|
||||
if (itemComposition.getPlaceholderTemplateId() != -1)
|
||||
{
|
||||
// if the item is a placeholder then get the item id for the normal item
|
||||
itemId = itemComposition.getPlaceholderId();
|
||||
}
|
||||
else
|
||||
{
|
||||
itemId = item.getId();
|
||||
}
|
||||
|
||||
int itemId = itemManager.canonicalize(item.getId());
|
||||
|
||||
ItemComposition itemComposition = itemManager.getItemComposition(itemId);
|
||||
String itemName = itemComposition.getName();
|
||||
|
||||
String initialValue = getTags(itemId);
|
||||
@@ -254,29 +262,6 @@ public class BankTagsPlugin extends Plugin
|
||||
return;
|
||||
}
|
||||
setTags(itemId, newTags);
|
||||
Widget bankContainerWidget = client.getWidget(WidgetInfo.BANK_ITEM_CONTAINER);
|
||||
if (bankContainerWidget == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Widget[] bankItemWidgets = bankContainerWidget.getDynamicChildren();
|
||||
if (bankItemWidgets == null || inventoryIndex >= bankItemWidgets.length)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Widget bankItemWidget = bankItemWidgets[inventoryIndex];
|
||||
String[] actions = bankItemWidget.getActions();
|
||||
if (actions == null || EDIT_TAGS_MENU_INDEX - 1 >= actions.length
|
||||
|| itemId != bankItemWidget.getItemId())
|
||||
{
|
||||
return;
|
||||
}
|
||||
int tagCount = getTagCount(itemId);
|
||||
actions[EDIT_TAGS_MENU_INDEX - 1] = EDIT_TAGS_MENU_OPTION;
|
||||
if (tagCount > 0)
|
||||
{
|
||||
actions[EDIT_TAGS_MENU_INDEX - 1] += " (" + tagCount + ")";
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user