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
This commit is contained in:
Jordan Atwood
2018-10-25 11:31:13 -07:00
parent 0d79490f6d
commit 0a5e7d4b4b
2 changed files with 63 additions and 46 deletions

View File

@@ -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<String> 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);
}
}
}

View File

@@ -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();
}
}