Merge pull request #6183 from Nightfirecat/configure-inventory-tags-menumanager

Update Inventory tags plugin to use MenuManager
This commit is contained in:
Tomas Slusny
2018-11-03 10:53:06 +01:00
committed by GitHub
2 changed files with 67 additions and 50 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;
@@ -92,7 +110,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 +129,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);
}
@@ -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)
{
@@ -228,7 +220,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);
@@ -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();
}
}