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);
|
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
|
* Loads item sprite from game, makes transparent, and generates image
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -29,16 +29,16 @@ import java.util.Arrays;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import net.runelite.api.Client;
|
import net.runelite.api.Client;
|
||||||
import net.runelite.api.IntegerNode;
|
|
||||||
import net.runelite.api.InventoryID;
|
import net.runelite.api.InventoryID;
|
||||||
import net.runelite.api.Item;
|
import net.runelite.api.Item;
|
||||||
import net.runelite.api.ItemComposition;
|
import net.runelite.api.ItemComposition;
|
||||||
import net.runelite.api.ItemContainer;
|
import net.runelite.api.ItemContainer;
|
||||||
import net.runelite.api.MenuAction;
|
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.MenuOptionClicked;
|
||||||
import net.runelite.api.events.ScriptCallbackEvent;
|
import net.runelite.api.events.ScriptCallbackEvent;
|
||||||
import net.runelite.api.widgets.Widget;
|
import net.runelite.api.widgets.Widget;
|
||||||
import net.runelite.api.widgets.WidgetConfig;
|
|
||||||
import net.runelite.api.widgets.WidgetInfo;
|
import net.runelite.api.widgets.WidgetInfo;
|
||||||
import net.runelite.client.config.ConfigManager;
|
import net.runelite.client.config.ConfigManager;
|
||||||
import net.runelite.client.game.ChatboxInputManager;
|
import net.runelite.client.game.ChatboxInputManager;
|
||||||
@@ -59,7 +59,7 @@ public class BankTagsPlugin extends Plugin
|
|||||||
|
|
||||||
private static final String SEARCH_BANK_INPUT_TEXT =
|
private static final String SEARCH_BANK_INPUT_TEXT =
|
||||||
"Show items whose names or tags contain the following text:<br>" +
|
"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 =
|
private static final String SEARCH_BANK_INPUT_TEXT_FOUND =
|
||||||
"Show items whose names or tags contain the following text: (%d found)<br>" +
|
"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 String EDIT_TAGS_MENU_OPTION = "Edit-tags";
|
||||||
|
|
||||||
private static final int EDIT_TAGS_MENU_INDEX = 8;
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private Client client;
|
private Client client;
|
||||||
|
|
||||||
@@ -140,39 +138,11 @@ public class BankTagsPlugin extends Plugin
|
|||||||
stringStack[stringStackSize - 1] = String.format(SEARCH_BANK_INPUT_TEXT_FOUND, matches);
|
stringStack[stringStackSize - 1] = String.format(SEARCH_BANK_INPUT_TEXT_FOUND, matches);
|
||||||
break;
|
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":
|
case "bankSearchFilter":
|
||||||
int itemId = intStack[intStackSize - 1];
|
int itemId = itemManager.canonicalize(intStack[intStackSize - 1]);
|
||||||
String itemName = stringStack[stringStackSize - 2];
|
String itemName = stringStack[stringStackSize - 2];
|
||||||
String searchInput = stringStack[stringStackSize - 1];
|
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);
|
String tagsConfig = configManager.getConfiguration(CONFIG_GROUP, ITEM_KEY_PREFIX + itemId);
|
||||||
if (tagsConfig == null || tagsConfig.length() == 0)
|
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
|
@Subscribe
|
||||||
public void onMenuOptionClicked(MenuOptionClicked event)
|
public void onMenuOptionClicked(MenuOptionClicked event)
|
||||||
{
|
{
|
||||||
if (event.getWidgetId() == WidgetInfo.BANK_ITEM_CONTAINER.getId()
|
if (event.getWidgetId() == WidgetInfo.BANK_ITEM_CONTAINER.getId()
|
||||||
&& event.getMenuAction() == MenuAction.EXAMINE_ITEM_BANK_EQ
|
&& event.getMenuAction() == MenuAction.RUNELITE
|
||||||
&& event.getId() == EDIT_TAGS_MENU_INDEX
|
|
||||||
&& event.getMenuOption().startsWith(EDIT_TAGS_MENU_OPTION))
|
&& event.getMenuOption().startsWith(EDIT_TAGS_MENU_OPTION))
|
||||||
{
|
{
|
||||||
event.consume();
|
event.consume();
|
||||||
@@ -231,18 +247,10 @@ public class BankTagsPlugin extends Plugin
|
|||||||
{
|
{
|
||||||
return;
|
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 itemName = itemComposition.getName();
|
||||||
|
|
||||||
String initialValue = getTags(itemId);
|
String initialValue = getTags(itemId);
|
||||||
@@ -254,29 +262,6 @@ public class BankTagsPlugin extends Plugin
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setTags(itemId, newTags);
|
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 + ")";
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
99623BD5CD95F5C19641A0BD0764B85E0322A58AADD8412C94B81B5C33FE1C07
|
|
||||||
@@ -1,192 +0,0 @@
|
|||||||
.id 278
|
|
||||||
.int_stack_count 7
|
|
||||||
.string_stack_count 0
|
|
||||||
.int_var_count 7
|
|
||||||
.string_var_count 0
|
|
||||||
iload 0
|
|
||||||
load_int -1
|
|
||||||
if_icmpne LABEL4
|
|
||||||
jump LABEL147
|
|
||||||
LABEL4:
|
|
||||||
widget_put_actions_null
|
|
||||||
iload 0
|
|
||||||
load_int 20594
|
|
||||||
if_icmpeq LABEL9
|
|
||||||
jump LABEL33
|
|
||||||
LABEL9:
|
|
||||||
iload 0
|
|
||||||
load_int -1
|
|
||||||
1200
|
|
||||||
load_int 7
|
|
||||||
load_string "Clear-All"
|
|
||||||
widget_put_action
|
|
||||||
load_int 8
|
|
||||||
load_string "Clear"
|
|
||||||
widget_put_action
|
|
||||||
load_int 0
|
|
||||||
widget_put_opacity
|
|
||||||
load_int 285
|
|
||||||
load_int -2147483645
|
|
||||||
load_int -2147483643
|
|
||||||
load_int -2147483642
|
|
||||||
load_int -2147483641
|
|
||||||
load_int 0
|
|
||||||
iload 3
|
|
||||||
iload 4
|
|
||||||
iload 5
|
|
||||||
iload 6
|
|
||||||
load_string "IiIiiIIII"
|
|
||||||
widget_put_drag_release_listener
|
|
||||||
jump LABEL128
|
|
||||||
LABEL33:
|
|
||||||
iload 0
|
|
||||||
4209
|
|
||||||
iload 0
|
|
||||||
if_icmpne LABEL38
|
|
||||||
jump LABEL59
|
|
||||||
LABEL38:
|
|
||||||
iload 0
|
|
||||||
load_int 0
|
|
||||||
1200
|
|
||||||
load_int 8
|
|
||||||
load_string "Release"
|
|
||||||
widget_put_action
|
|
||||||
load_int 120
|
|
||||||
widget_put_opacity
|
|
||||||
load_int 285
|
|
||||||
load_int -2147483645
|
|
||||||
load_int -2147483643
|
|
||||||
load_int -2147483642
|
|
||||||
load_int -2147483641
|
|
||||||
load_int 120
|
|
||||||
iload 3
|
|
||||||
iload 4
|
|
||||||
iload 5
|
|
||||||
iload 6
|
|
||||||
load_string "IiIiiIIII"
|
|
||||||
widget_put_drag_release_listener
|
|
||||||
jump LABEL128
|
|
||||||
LABEL59:
|
|
||||||
iload 0
|
|
||||||
iload 1
|
|
||||||
1200
|
|
||||||
invoke 1972
|
|
||||||
load_int 1
|
|
||||||
if_icmpeq LABEL66
|
|
||||||
jump LABEL72
|
|
||||||
LABEL66:
|
|
||||||
load_int 1
|
|
||||||
load_string "Withdraw-"
|
|
||||||
invoke 2227
|
|
||||||
concat_string
|
|
||||||
widget_put_action
|
|
||||||
jump LABEL75
|
|
||||||
LABEL72:
|
|
||||||
load_int 1 ; if the bank tags plugin is not active this will not get changed and thus
|
|
||||||
; overridden by the Withdraw-1 option
|
|
||||||
load_string "Edit-tags" ; push menu action name
|
|
||||||
iload 0 ; push item id
|
|
||||||
widget_get_index ; push the item index for setting the widget flag
|
|
||||||
load_string "setBankItemMenu" ; push event name
|
|
||||||
runelite_callback ; invoke callback
|
|
||||||
pop_int ; pop widget index
|
|
||||||
pop_int ; pop item id
|
|
||||||
widget_put_action ; add edit tags menu action
|
|
||||||
load_int 1
|
|
||||||
load_string "Withdraw-1"
|
|
||||||
widget_put_action
|
|
||||||
LABEL75:
|
|
||||||
load_int 2
|
|
||||||
load_string "Withdraw-5"
|
|
||||||
widget_put_action
|
|
||||||
load_int 3
|
|
||||||
load_string "Withdraw-10"
|
|
||||||
widget_put_action
|
|
||||||
get_varbit 3960
|
|
||||||
load_int 0
|
|
||||||
if_icmpgt LABEL85
|
|
||||||
jump LABEL91
|
|
||||||
LABEL85:
|
|
||||||
load_int 4
|
|
||||||
load_string "Withdraw-"
|
|
||||||
get_varbit 3960
|
|
||||||
int_to_string
|
|
||||||
string_append 2
|
|
||||||
widget_put_action
|
|
||||||
LABEL91:
|
|
||||||
load_int 5
|
|
||||||
load_string "Withdraw-X"
|
|
||||||
widget_put_action
|
|
||||||
load_int 6
|
|
||||||
load_string "Withdraw-All"
|
|
||||||
widget_put_action
|
|
||||||
load_int 7
|
|
||||||
load_string "Withdraw-All-but-1"
|
|
||||||
widget_put_action
|
|
||||||
get_varbit 6347
|
|
||||||
load_int 0
|
|
||||||
if_icmpgt LABEL104
|
|
||||||
jump LABEL107
|
|
||||||
LABEL104:
|
|
||||||
load_int 8
|
|
||||||
load_string "Withdraw-1"
|
|
||||||
widget_put_action
|
|
||||||
LABEL107:
|
|
||||||
get_varbit 3755
|
|
||||||
load_int 0
|
|
||||||
if_icmpeq LABEL111
|
|
||||||
jump LABEL114
|
|
||||||
LABEL111:
|
|
||||||
load_int 9
|
|
||||||
load_string "Placeholder"
|
|
||||||
widget_put_action
|
|
||||||
LABEL114:
|
|
||||||
load_int 0
|
|
||||||
widget_put_opacity
|
|
||||||
load_int 285
|
|
||||||
load_int -2147483645
|
|
||||||
load_int -2147483643
|
|
||||||
load_int -2147483642
|
|
||||||
load_int -2147483641
|
|
||||||
load_int 0
|
|
||||||
iload 3
|
|
||||||
iload 4
|
|
||||||
iload 5
|
|
||||||
iload 6
|
|
||||||
load_string "IiIiiIIII"
|
|
||||||
widget_put_drag_release_listener
|
|
||||||
LABEL128:
|
|
||||||
load_int 10
|
|
||||||
load_string "Examine"
|
|
||||||
widget_put_action
|
|
||||||
load_string "<col=ff9040>"
|
|
||||||
iload 0
|
|
||||||
get_item_name
|
|
||||||
load_string "</col>"
|
|
||||||
string_append 3
|
|
||||||
widget_put_name
|
|
||||||
load_int 284
|
|
||||||
load_int -2147483645
|
|
||||||
load_int -2147483643
|
|
||||||
load_int -2147483647
|
|
||||||
load_int -2147483646
|
|
||||||
iload 3
|
|
||||||
load_int 0
|
|
||||||
load_string "IiiiIi"
|
|
||||||
widget_put_drag_start_listener
|
|
||||||
jump LABEL159
|
|
||||||
LABEL147:
|
|
||||||
load_int 255
|
|
||||||
widget_put_opacity
|
|
||||||
load_int 6512
|
|
||||||
load_int 1
|
|
||||||
1200
|
|
||||||
widget_put_actions_null
|
|
||||||
load_int -1
|
|
||||||
load_string ""
|
|
||||||
widget_put_drag_start_listener
|
|
||||||
load_int -1
|
|
||||||
load_string ""
|
|
||||||
widget_put_drag_release_listener
|
|
||||||
LABEL159:
|
|
||||||
return
|
|
||||||
Reference in New Issue
Block a user