Skip to content

Commit

Permalink
inventory tags plugin: Use MenuManager
Browse files Browse the repository at this point in the history
This patch updates the inventory tags plugin to utilize the MenuManager
util to better add menu options to the inventory tab.

Fixes runelite#6132
  • Loading branch information
Nightfirecat committed Nov 2, 2018
1 parent 0d79490 commit 0a5e7d4
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,16 @@
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",
Expand All @@ -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
Expand All @@ -83,6 +98,9 @@ public class InventoryTagsPlugin extends Plugin
@Inject
private InventoryTagsConfig config;

@Inject
private MenuManager menuManager;

@Inject
private InventoryTagsOverlay overlay;

Expand Down Expand Up @@ -124,36 +142,35 @@ private void unsetTag(int itemId)
@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 onMenuOptionClicked(final MenuOptionClicked event)
public void onWidgetMenuOptionClicked(final WidgetMenuOptionClicked event)
{
if (event.getMenuAction() != MenuAction.RUNELITE)
if (event.getWidget() == WidgetInfo.FIXED_VIEWPORT_INVENTORY_TAB
|| event.getWidget() == WidgetInfo.RESIZABLE_VIEWPORT_INVENTORY_TAB
|| event.getWidget() == WidgetInfo.RESIZABLE_VIEWPORT_BOTTOM_LINE_INVENTORY_TAB)
{
return;
editorMode = event.getMenuOption().equals(CONFIGURE) && Text.removeTags(event.getMenuTarget()).equals(MENU_TARGET);
refreshInventoryMenuOptions();
}
}

if (MENU_TARGET.equals(event.getMenuTarget()))
@Subscribe
public void onMenuOptionClicked(final MenuOptionClicked event)
{
if (event.getMenuAction() != MenuAction.RUNELITE)
{
switch (event.getMenuOption())
{
case CONFIGURE:
editorMode = true;
break;
case SAVE:
editorMode = false;
break;
}

return;
}

Expand Down Expand Up @@ -185,31 +202,6 @@ public void onMenuOpened(final MenuOpened event)

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)
{
Expand Down Expand Up @@ -297,4 +289,31 @@ Color getGroupNameColor(final String name)

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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

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;
Expand All @@ -52,7 +51,6 @@
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;

Expand All @@ -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_";
Expand Down Expand Up @@ -197,7 +195,7 @@ public void onWidgetMenuOptionClicked(WidgetMenuOptionClicked event)
|| 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();
}
}
Expand Down

0 comments on commit 0a5e7d4

Please sign in to comment.