Merge pull request #6183 from Nightfirecat/configure-inventory-tags-menumanager
Update Inventory tags plugin to use MenuManager
This commit is contained in:
@@ -42,14 +42,16 @@ import net.runelite.api.MenuEntry;
|
|||||||
import net.runelite.api.events.ItemContainerChanged;
|
import net.runelite.api.events.ItemContainerChanged;
|
||||||
import net.runelite.api.events.MenuOpened;
|
import net.runelite.api.events.MenuOpened;
|
||||||
import net.runelite.api.events.MenuOptionClicked;
|
import net.runelite.api.events.MenuOptionClicked;
|
||||||
|
import net.runelite.api.events.WidgetMenuOptionClicked;
|
||||||
import net.runelite.api.widgets.WidgetInfo;
|
import net.runelite.api.widgets.WidgetInfo;
|
||||||
import net.runelite.client.config.ConfigManager;
|
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.Plugin;
|
||||||
import net.runelite.client.plugins.PluginDescriptor;
|
import net.runelite.client.plugins.PluginDescriptor;
|
||||||
import net.runelite.client.ui.overlay.OverlayManager;
|
import net.runelite.client.ui.overlay.OverlayManager;
|
||||||
import net.runelite.client.util.ColorUtil;
|
import net.runelite.client.util.ColorUtil;
|
||||||
import net.runelite.client.util.Text;
|
import net.runelite.client.util.Text;
|
||||||
import org.apache.commons.lang3.ArrayUtils;
|
|
||||||
|
|
||||||
@PluginDescriptor(
|
@PluginDescriptor(
|
||||||
name = "Inventory Tags",
|
name = "Inventory Tags",
|
||||||
@@ -68,10 +70,23 @@ public class InventoryTagsPlugin extends Plugin
|
|||||||
|
|
||||||
private static final String CONFIGURE = "Configure";
|
private static final String CONFIGURE = "Configure";
|
||||||
private static final String SAVE = "Save";
|
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_SET = "Mark";
|
||||||
private static final String MENU_REMOVE = "Remove";
|
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);
|
private static final List<String> GROUPS = ImmutableList.of(SETNAME_GROUP_4, SETNAME_GROUP_3, SETNAME_GROUP_2, SETNAME_GROUP_1);
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
@@ -83,6 +98,9 @@ public class InventoryTagsPlugin extends Plugin
|
|||||||
@Inject
|
@Inject
|
||||||
private InventoryTagsConfig config;
|
private InventoryTagsConfig config;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private MenuManager menuManager;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
private InventoryTagsOverlay overlay;
|
private InventoryTagsOverlay overlay;
|
||||||
|
|
||||||
@@ -92,7 +110,7 @@ public class InventoryTagsPlugin extends Plugin
|
|||||||
@Getter(AccessLevel.PACKAGE)
|
@Getter(AccessLevel.PACKAGE)
|
||||||
private boolean hasTaggedItems;
|
private boolean hasTaggedItems;
|
||||||
|
|
||||||
private boolean editorMode = false;
|
private boolean editorMode;
|
||||||
|
|
||||||
@Provides
|
@Provides
|
||||||
InventoryTagsConfig provideConfig(ConfigManager configManager)
|
InventoryTagsConfig provideConfig(ConfigManager configManager)
|
||||||
@@ -111,12 +129,12 @@ public class InventoryTagsPlugin extends Plugin
|
|||||||
return tag;
|
return tag;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setTag(int itemId, String tag)
|
private void setTag(int itemId, String tag)
|
||||||
{
|
{
|
||||||
configManager.setConfiguration(InventoryTagsConfig.GROUP, ITEM_KEY_PREFIX + itemId, 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);
|
configManager.unsetConfiguration(InventoryTagsConfig.GROUP, ITEM_KEY_PREFIX + itemId);
|
||||||
}
|
}
|
||||||
@@ -124,16 +142,30 @@ public class InventoryTagsPlugin extends Plugin
|
|||||||
@Override
|
@Override
|
||||||
protected void startUp() throws Exception
|
protected void startUp() throws Exception
|
||||||
{
|
{
|
||||||
|
refreshInventoryMenuOptions();
|
||||||
overlayManager.add(overlay);
|
overlayManager.add(overlay);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void shutDown() throws Exception
|
protected void shutDown() throws Exception
|
||||||
{
|
{
|
||||||
|
removeInventoryMenuOptions();
|
||||||
overlayManager.remove(overlay);
|
overlayManager.remove(overlay);
|
||||||
hasTaggedItems = editorMode = false;
|
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
|
@Subscribe
|
||||||
public void onMenuOptionClicked(final MenuOptionClicked event)
|
public void onMenuOptionClicked(final MenuOptionClicked event)
|
||||||
{
|
{
|
||||||
@@ -142,21 +174,6 @@ public class InventoryTagsPlugin extends Plugin
|
|||||||
return;
|
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());
|
final String selectedMenu = Text.removeTags(event.getMenuTarget());
|
||||||
|
|
||||||
if (event.getMenuOption().equals(MENU_SET))
|
if (event.getMenuOption().equals(MENU_SET))
|
||||||
@@ -185,31 +202,6 @@ public class InventoryTagsPlugin extends Plugin
|
|||||||
|
|
||||||
final int widgetId = firstEntry.getParam1();
|
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
|
// Inventory item menu
|
||||||
if (widgetId == WidgetInfo.INVENTORY.getId() && editorMode)
|
if (widgetId == WidgetInfo.INVENTORY.getId() && editorMode)
|
||||||
{
|
{
|
||||||
@@ -228,7 +220,7 @@ public class InventoryTagsPlugin extends Plugin
|
|||||||
final String group = getTag(itemId);
|
final String group = getTag(itemId);
|
||||||
final MenuEntry newMenu = new MenuEntry();
|
final MenuEntry newMenu = new MenuEntry();
|
||||||
final Color color = getGroupNameColor(groupName);
|
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.setTarget(ColorUtil.prependColorTag(groupName, MoreObjects.firstNonNull(color, Color.WHITE)));
|
||||||
newMenu.setIdentifier(itemId);
|
newMenu.setIdentifier(itemId);
|
||||||
newMenu.setParam1(widgetId);
|
newMenu.setParam1(widgetId);
|
||||||
@@ -297,4 +289,31 @@ public class InventoryTagsPlugin extends Plugin
|
|||||||
|
|
||||||
return null;
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,7 +27,6 @@ package net.runelite.client.plugins.menuentryswapper;
|
|||||||
|
|
||||||
import com.google.common.eventbus.Subscribe;
|
import com.google.common.eventbus.Subscribe;
|
||||||
import com.google.inject.Provides;
|
import com.google.inject.Provides;
|
||||||
import java.awt.Color;
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
@@ -52,7 +51,6 @@ import net.runelite.client.menus.MenuManager;
|
|||||||
import net.runelite.client.menus.WidgetMenuOption;
|
import net.runelite.client.menus.WidgetMenuOption;
|
||||||
import net.runelite.client.plugins.Plugin;
|
import net.runelite.client.plugins.Plugin;
|
||||||
import net.runelite.client.plugins.PluginDescriptor;
|
import net.runelite.client.plugins.PluginDescriptor;
|
||||||
import net.runelite.client.util.ColorUtil;
|
|
||||||
import net.runelite.client.util.Text;
|
import net.runelite.client.util.Text;
|
||||||
import org.apache.commons.lang3.ArrayUtils;
|
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 CONFIGURE = "Configure";
|
||||||
private static final String SAVE = "Save";
|
private static final String SAVE = "Save";
|
||||||
private static final String RESET = "Reset";
|
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 CONFIG_GROUP = "shiftclick";
|
||||||
private static final String ITEM_KEY_PREFIX = "item_";
|
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_INVENTORY_TAB
|
||||||
|| event.getWidget() == WidgetInfo.RESIZABLE_VIEWPORT_BOTTOM_LINE_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();
|
refreshShiftClickCustomizationMenus();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user