Java Code Examples for net.runelite.api.events.MenuOpened#getFirstEntry()
The following examples show how to use
net.runelite.api.events.MenuOpened#getFirstEntry() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: InventoryTagsPlugin.java From plugins with GNU General Public License v3.0 | 4 votes |
@Subscribe private void onMenuOpened(final MenuOpened event) { final MenuEntry firstEntry = event.getFirstEntry(); if (firstEntry == null) { return; } final int widgetId = firstEntry.getParam1(); // Inventory item menu if (widgetId == WidgetInfo.INVENTORY.getId() && editorMode) { int itemId = firstEntry.getIdentifier(); if (itemId == -1) { return; } MenuEntry[] menuList = new MenuEntry[config.getAmount().toInt() + 1]; int num = 0; // preserve the 'Cancel' option as the client will reuse the first entry for Cancel and only resets option/action menuList[num++] = event.getMenuEntries()[0]; List<String> groups = GROUPS.subList(Math.max(GROUPS.size() - config.getAmount().toInt(), 0), GROUPS.size()); for (final String groupName : groups) { final String group = getTag(itemId); final MenuEntry newMenu = new MenuEntry(); final Color color = getGroupNameColor(groupName); newMenu.setOption(groupName.equals(group) ? MENU_REMOVE : MENU_SET); newMenu.setTarget(ColorUtil.prependColorTag(groupName, Objects.requireNonNullElse(color, Color.WHITE))); newMenu.setIdentifier(itemId); newMenu.setParam1(widgetId); newMenu.setOpcode(MenuOpcode.RUNELITE.getId()); menuList[num++] = newMenu; } // Need to set the event entries to prevent conflicts event.setMenuEntries(menuList); event.setModified(); } }
Example 2
Source File: InventoryTagsPlugin.java From runelite with BSD 2-Clause "Simplified" License | 4 votes |
@Subscribe public void onMenuOpened(final MenuOpened event) { final MenuEntry firstEntry = event.getFirstEntry(); if (firstEntry == null) { return; } final int widgetId = firstEntry.getParam1(); // Inventory item menu if (widgetId == WidgetInfo.INVENTORY.getId() && editorMode) { int itemId = firstEntry.getIdentifier(); if (itemId == -1) { return; } MenuEntry[] menuList = new MenuEntry[GROUPS.size() + 1]; int num = 0; // preserve the 'Cancel' option as the client will reuse the first entry for Cancel and only resets option/action menuList[num++] = event.getMenuEntries()[0]; for (final String groupName : GROUPS) { final String group = getTag(itemId); final MenuEntry newMenu = new MenuEntry(); final Color color = getGroupNameColor(groupName); newMenu.setOption(groupName.equals(group) ? MENU_REMOVE : MENU_SET); newMenu.setTarget(ColorUtil.prependColorTag(groupName, MoreObjects.firstNonNull(color, Color.WHITE))); newMenu.setIdentifier(itemId); newMenu.setParam1(widgetId); newMenu.setType(MenuAction.RUNELITE.getId()); menuList[num++] = newMenu; } client.setMenuEntries(menuList); } }
Example 3
Source File: MenuEntrySwapperPlugin.java From runelite with BSD 2-Clause "Simplified" License | 4 votes |
@Subscribe public void onMenuOpened(MenuOpened event) { if (!configuringShiftClick) { return; } MenuEntry firstEntry = event.getFirstEntry(); if (firstEntry == null) { return; } int widgetId = firstEntry.getParam1(); if (widgetId != WidgetInfo.INVENTORY.getId()) { return; } int itemId = firstEntry.getIdentifier(); if (itemId == -1) { return; } ItemComposition itemComposition = client.getItemDefinition(itemId); String itemName = itemComposition.getName(); String option = "Use"; int shiftClickActionIndex = itemComposition.getShiftClickActionIndex(); String[] inventoryActions = itemComposition.getInventoryActions(); if (shiftClickActionIndex >= 0 && shiftClickActionIndex < inventoryActions.length) { option = inventoryActions[shiftClickActionIndex]; } MenuEntry[] entries = event.getMenuEntries(); for (MenuEntry entry : entries) { if (itemName.equals(Text.removeTags(entry.getTarget()))) { entry.setType(MenuAction.RUNELITE.getId()); if (option.equals(entry.getOption())) { entry.setOption("* " + option); } } } final MenuEntry resetShiftClickEntry = new MenuEntry(); resetShiftClickEntry.setOption(RESET); resetShiftClickEntry.setTarget(MENU_TARGET); resetShiftClickEntry.setIdentifier(itemId); resetShiftClickEntry.setParam1(widgetId); resetShiftClickEntry.setType(MenuAction.RUNELITE.getId()); client.setMenuEntries(ArrayUtils.addAll(entries, resetShiftClickEntry)); }