From 0d79490f6d4d4ba0dd7a2b67580e8e507b8e36e1 Mon Sep 17 00:00:00 2001 From: Jordan Atwood Date: Thu, 25 Oct 2018 11:30:01 -0700 Subject: [PATCH 1/2] inventory tags plugin: clean up plugin code This includes various code quality improvements such as stronger access control and removing redundant code. --- .../client/plugins/inventorytags/InventoryTagsPlugin.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/inventorytags/InventoryTagsPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/inventorytags/InventoryTagsPlugin.java index 9ffe2107a9..133cbf08f2 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/inventorytags/InventoryTagsPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/inventorytags/InventoryTagsPlugin.java @@ -92,7 +92,7 @@ public class InventoryTagsPlugin extends Plugin @Getter(AccessLevel.PACKAGE) private boolean hasTaggedItems; - private boolean editorMode = false; + private boolean editorMode; @Provides InventoryTagsConfig provideConfig(ConfigManager configManager) @@ -111,12 +111,12 @@ public class InventoryTagsPlugin extends Plugin return tag; } - void setTag(int itemId, String tag) + private void setTag(int itemId, String tag) { configManager.setConfiguration(InventoryTagsConfig.GROUP, ITEM_KEY_PREFIX + itemId, tag); } - void unsetTag(int itemId) + private void unsetTag(int itemId) { configManager.unsetConfiguration(InventoryTagsConfig.GROUP, ITEM_KEY_PREFIX + itemId); } @@ -228,7 +228,7 @@ public class InventoryTagsPlugin extends Plugin final String group = getTag(itemId); final MenuEntry newMenu = new MenuEntry(); final Color color = getGroupNameColor(groupName); - newMenu.setOption(group != null && groupName.equals(group) ? MENU_REMOVE : MENU_SET); + 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); From 0a5e7d4b4b94bf4cd742868705616d49b54d558a Mon Sep 17 00:00:00 2001 From: Jordan Atwood Date: Thu, 25 Oct 2018 11:31:13 -0700 Subject: [PATCH 2/2] inventory tags plugin: Use MenuManager This patch updates the inventory tags plugin to utilize the MenuManager util to better add menu options to the inventory tab. Fixes runelite/runelite#6132 --- .../inventorytags/InventoryTagsPlugin.java | 103 +++++++++++------- .../MenuEntrySwapperPlugin.java | 6 +- 2 files changed, 63 insertions(+), 46 deletions(-) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/inventorytags/InventoryTagsPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/inventorytags/InventoryTagsPlugin.java index 133cbf08f2..45e22dfb83 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/inventorytags/InventoryTagsPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/inventorytags/InventoryTagsPlugin.java @@ -42,14 +42,16 @@ import net.runelite.api.MenuEntry; import net.runelite.api.events.ItemContainerChanged; import net.runelite.api.events.MenuOpened; import net.runelite.api.events.MenuOptionClicked; +import net.runelite.api.events.WidgetMenuOptionClicked; import net.runelite.api.widgets.WidgetInfo; import net.runelite.client.config.ConfigManager; +import net.runelite.client.menus.MenuManager; +import net.runelite.client.menus.WidgetMenuOption; import net.runelite.client.plugins.Plugin; import net.runelite.client.plugins.PluginDescriptor; import net.runelite.client.ui.overlay.OverlayManager; import net.runelite.client.util.ColorUtil; import net.runelite.client.util.Text; -import org.apache.commons.lang3.ArrayUtils; @PluginDescriptor( name = "Inventory Tags", @@ -68,10 +70,23 @@ public class InventoryTagsPlugin extends Plugin private static final String CONFIGURE = "Configure"; private static final String SAVE = "Save"; - private static final String MENU_TARGET = ColorUtil.prependColorTag("Inventory Tags", new Color(255, 144, 64)); + private static final String MENU_TARGET = "Inventory Tags"; private static final String MENU_SET = "Mark"; private static final String MENU_REMOVE = "Remove"; + private static final WidgetMenuOption FIXED_INVENTORY_TAB_CONFIGURE = new WidgetMenuOption(CONFIGURE, + MENU_TARGET, WidgetInfo.FIXED_VIEWPORT_INVENTORY_TAB); + private static final WidgetMenuOption FIXED_INVENTORY_TAB_SAVE = new WidgetMenuOption(SAVE, + MENU_TARGET, WidgetInfo.FIXED_VIEWPORT_INVENTORY_TAB); + private static final WidgetMenuOption RESIZABLE_INVENTORY_TAB_CONFIGURE = new WidgetMenuOption(CONFIGURE, + MENU_TARGET, WidgetInfo.RESIZABLE_VIEWPORT_INVENTORY_TAB); + private static final WidgetMenuOption RESIZABLE_INVENTORY_TAB_SAVE = new WidgetMenuOption(SAVE, + MENU_TARGET, WidgetInfo.RESIZABLE_VIEWPORT_INVENTORY_TAB); + private static final WidgetMenuOption RESIZABLE_BOTTOM_LINE_INVENTORY_TAB_CONFIGURE = new WidgetMenuOption(CONFIGURE, + MENU_TARGET, WidgetInfo.RESIZABLE_VIEWPORT_BOTTOM_LINE_INVENTORY_TAB); + private static final WidgetMenuOption RESIZABLE_BOTTOM_LINE_INVENTORY_TAB_SAVE = new WidgetMenuOption(SAVE, + MENU_TARGET, WidgetInfo.RESIZABLE_VIEWPORT_BOTTOM_LINE_INVENTORY_TAB); + private static final List GROUPS = ImmutableList.of(SETNAME_GROUP_4, SETNAME_GROUP_3, SETNAME_GROUP_2, SETNAME_GROUP_1); @Inject @@ -83,6 +98,9 @@ public class InventoryTagsPlugin extends Plugin @Inject private InventoryTagsConfig config; + @Inject + private MenuManager menuManager; + @Inject private InventoryTagsOverlay overlay; @@ -124,16 +142,30 @@ public class InventoryTagsPlugin extends Plugin @Override protected void startUp() throws Exception { + refreshInventoryMenuOptions(); overlayManager.add(overlay); } @Override protected void shutDown() throws Exception { + removeInventoryMenuOptions(); overlayManager.remove(overlay); hasTaggedItems = editorMode = false; } + @Subscribe + public void onWidgetMenuOptionClicked(final WidgetMenuOptionClicked event) + { + if (event.getWidget() == WidgetInfo.FIXED_VIEWPORT_INVENTORY_TAB + || event.getWidget() == WidgetInfo.RESIZABLE_VIEWPORT_INVENTORY_TAB + || event.getWidget() == WidgetInfo.RESIZABLE_VIEWPORT_BOTTOM_LINE_INVENTORY_TAB) + { + editorMode = event.getMenuOption().equals(CONFIGURE) && Text.removeTags(event.getMenuTarget()).equals(MENU_TARGET); + refreshInventoryMenuOptions(); + } + } + @Subscribe public void onMenuOptionClicked(final MenuOptionClicked event) { @@ -142,21 +174,6 @@ public class InventoryTagsPlugin extends Plugin return; } - if (MENU_TARGET.equals(event.getMenuTarget())) - { - switch (event.getMenuOption()) - { - case CONFIGURE: - editorMode = true; - break; - case SAVE: - editorMode = false; - break; - } - - return; - } - final String selectedMenu = Text.removeTags(event.getMenuTarget()); if (event.getMenuOption().equals(MENU_SET)) @@ -185,31 +202,6 @@ public class InventoryTagsPlugin extends Plugin final int widgetId = firstEntry.getParam1(); - // Inventory button menu - if (widgetId == WidgetInfo.FIXED_VIEWPORT_INVENTORY_TAB.getId() || - widgetId == WidgetInfo.RESIZABLE_VIEWPORT_INVENTORY_TAB.getId() || - widgetId == WidgetInfo.RESIZABLE_VIEWPORT_BOTTOM_LINE_INVENTORY_TAB.getId()) - { - final int itemId = firstEntry.getIdentifier(); - - if (itemId == -1) - { - return; - } - - MenuEntry[] entries = event.getMenuEntries(); - - final MenuEntry configureOption = new MenuEntry(); - configureOption.setOption(editorMode ? SAVE : CONFIGURE); - configureOption.setTarget(MENU_TARGET); - configureOption.setIdentifier(itemId); - configureOption.setParam1(widgetId); - configureOption.setType(MenuAction.RUNELITE.getId()); - entries = ArrayUtils.addAll(entries, configureOption); - - client.setMenuEntries(entries); - } - // Inventory item menu if (widgetId == WidgetInfo.INVENTORY.getId() && editorMode) { @@ -297,4 +289,31 @@ public class InventoryTagsPlugin extends Plugin return null; } + + private void removeInventoryMenuOptions() + { + menuManager.removeManagedCustomMenu(FIXED_INVENTORY_TAB_CONFIGURE); + menuManager.removeManagedCustomMenu(FIXED_INVENTORY_TAB_SAVE); + menuManager.removeManagedCustomMenu(RESIZABLE_INVENTORY_TAB_CONFIGURE); + menuManager.removeManagedCustomMenu(RESIZABLE_INVENTORY_TAB_SAVE); + menuManager.removeManagedCustomMenu(RESIZABLE_BOTTOM_LINE_INVENTORY_TAB_CONFIGURE); + menuManager.removeManagedCustomMenu(RESIZABLE_BOTTOM_LINE_INVENTORY_TAB_SAVE); + } + + private void refreshInventoryMenuOptions() + { + removeInventoryMenuOptions(); + if (editorMode) + { + menuManager.addManagedCustomMenu(FIXED_INVENTORY_TAB_SAVE); + menuManager.addManagedCustomMenu(RESIZABLE_INVENTORY_TAB_SAVE); + menuManager.addManagedCustomMenu(RESIZABLE_BOTTOM_LINE_INVENTORY_TAB_SAVE); + } + else + { + menuManager.addManagedCustomMenu(FIXED_INVENTORY_TAB_CONFIGURE); + menuManager.addManagedCustomMenu(RESIZABLE_INVENTORY_TAB_CONFIGURE); + menuManager.addManagedCustomMenu(RESIZABLE_BOTTOM_LINE_INVENTORY_TAB_CONFIGURE); + } + } } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/menuentryswapper/MenuEntrySwapperPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/menuentryswapper/MenuEntrySwapperPlugin.java index ed01339020..8f88887eea 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/menuentryswapper/MenuEntrySwapperPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/menuentryswapper/MenuEntrySwapperPlugin.java @@ -27,7 +27,6 @@ package net.runelite.client.plugins.menuentryswapper; import com.google.common.eventbus.Subscribe; import com.google.inject.Provides; -import java.awt.Color; import javax.inject.Inject; import lombok.Getter; import lombok.Setter; @@ -52,7 +51,6 @@ import net.runelite.client.menus.MenuManager; import net.runelite.client.menus.WidgetMenuOption; import net.runelite.client.plugins.Plugin; import net.runelite.client.plugins.PluginDescriptor; -import net.runelite.client.util.ColorUtil; import net.runelite.client.util.Text; import org.apache.commons.lang3.ArrayUtils; @@ -67,7 +65,7 @@ public class MenuEntrySwapperPlugin extends Plugin private static final String CONFIGURE = "Configure"; private static final String SAVE = "Save"; private static final String RESET = "Reset"; - private static final String MENU_TARGET = ColorUtil.prependColorTag("Shift-click", new Color(255, 144, 64)); + private static final String MENU_TARGET = "Shift-click"; private static final String CONFIG_GROUP = "shiftclick"; private static final String ITEM_KEY_PREFIX = "item_"; @@ -197,7 +195,7 @@ public class MenuEntrySwapperPlugin extends Plugin || event.getWidget() == WidgetInfo.RESIZABLE_VIEWPORT_INVENTORY_TAB || event.getWidget() == WidgetInfo.RESIZABLE_VIEWPORT_BOTTOM_LINE_INVENTORY_TAB) { - configuringShiftClick = event.getMenuOption().equals(CONFIGURE); + configuringShiftClick = event.getMenuOption().equals(CONFIGURE) && Text.removeTags(event.getMenuTarget()).equals(MENU_TARGET); refreshShiftClickCustomizationMenus(); } }