Merge pull request #2117 from Lucwousin/wiki-and-menuman-opt
client: Re-optimize wikiplugin, call contains on hashmultimap in menumanager
This commit is contained in:
@@ -266,6 +266,8 @@ public class MenuManager
|
||||
}
|
||||
|
||||
int widgetId = event.getParam1();
|
||||
if (managedMenuOptions.containsKey(widgetId))
|
||||
{
|
||||
Collection<WidgetMenuOption> options = managedMenuOptions.get(widgetId);
|
||||
|
||||
for (WidgetMenuOption currentMenu : options)
|
||||
@@ -284,6 +286,7 @@ public class MenuManager
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void rebuildLeftClickMenu()
|
||||
{
|
||||
|
||||
@@ -25,11 +25,8 @@
|
||||
package net.runelite.client.plugins.wiki;
|
||||
|
||||
import com.google.common.primitives.Ints;
|
||||
import java.util.Arrays;
|
||||
import java.util.stream.Stream;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Provider;
|
||||
import javax.inject.Singleton;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.runelite.api.Client;
|
||||
import net.runelite.api.MenuEntry;
|
||||
@@ -53,18 +50,18 @@ import net.runelite.client.callback.ClientThread;
|
||||
import net.runelite.client.eventbus.Subscribe;
|
||||
import net.runelite.client.game.ItemManager;
|
||||
import net.runelite.client.game.SpriteManager;
|
||||
import net.runelite.client.game.chatbox.ChatboxPanelManager;
|
||||
import net.runelite.client.plugins.Plugin;
|
||||
import net.runelite.client.plugins.PluginDescriptor;
|
||||
import net.runelite.client.util.LinkBrowser;
|
||||
import okhttp3.HttpUrl;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@Slf4j
|
||||
@PluginDescriptor(
|
||||
name = "Wiki",
|
||||
description = "Adds a Wiki button that takes you to the OSRS Wiki"
|
||||
)
|
||||
@Singleton
|
||||
public class WikiPlugin extends Plugin
|
||||
{
|
||||
private static final int[] QUESTLIST_WIDGET_IDS = new int[]
|
||||
@@ -92,9 +89,6 @@ public class WikiPlugin extends Plugin
|
||||
@Inject
|
||||
private Client client;
|
||||
|
||||
@Inject
|
||||
private ChatboxPanelManager chatboxPanelManager;
|
||||
|
||||
@Inject
|
||||
private ItemManager itemManager;
|
||||
|
||||
@@ -108,7 +102,6 @@ public class WikiPlugin extends Plugin
|
||||
@Override
|
||||
public void startUp()
|
||||
{
|
||||
|
||||
spriteManager.addSpriteOverrides(WikiSprite.values());
|
||||
clientThread.invokeLater(this::addWidgets);
|
||||
}
|
||||
@@ -199,9 +192,16 @@ public class WikiPlugin extends Plugin
|
||||
@Subscribe
|
||||
private void onMenuOptionClicked(MenuOptionClicked ev)
|
||||
{
|
||||
optarget:
|
||||
if (wikiSelected)
|
||||
if (ev.getMenuOpcode() == MenuOpcode.RUNELITE)
|
||||
{
|
||||
checkQuestClicked(ev);
|
||||
}
|
||||
|
||||
if (!wikiSelected)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
onDeselect();
|
||||
client.setSpellSelected(false);
|
||||
ev.consume();
|
||||
@@ -214,8 +214,6 @@ public class WikiPlugin extends Plugin
|
||||
switch (ev.getMenuOpcode())
|
||||
{
|
||||
case RUNELITE:
|
||||
// This is a quest widget op
|
||||
break optarget;
|
||||
case CANCEL:
|
||||
return;
|
||||
case ITEM_USE_ON_WIDGET:
|
||||
@@ -251,6 +249,7 @@ public class WikiPlugin extends Plugin
|
||||
break;
|
||||
}
|
||||
case SPELL_CAST_ON_WIDGET:
|
||||
{
|
||||
Widget w = getWidget(ev.getParam1(), ev.getParam0());
|
||||
|
||||
if (w.getType() == WidgetType.GRAPHIC && w.getItemId() != -1)
|
||||
@@ -261,6 +260,7 @@ public class WikiPlugin extends Plugin
|
||||
location = null;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// fallthrough
|
||||
default:
|
||||
log.info("Unknown menu option: {} {} {}", ev, ev.getMenuOpcode(), ev.getMenuOpcode() == MenuOpcode.CANCEL);
|
||||
@@ -285,10 +285,9 @@ public class WikiPlugin extends Plugin
|
||||
HttpUrl url = urlBuilder.build();
|
||||
|
||||
LinkBrowser.browse(url.toString());
|
||||
return;
|
||||
}
|
||||
|
||||
if (ev.getMenuOpcode() == MenuOpcode.RUNELITE)
|
||||
private void checkQuestClicked(MenuOptionClicked ev)
|
||||
{
|
||||
boolean quickguide = false;
|
||||
switch (ev.getOption())
|
||||
@@ -317,7 +316,6 @@ public class WikiPlugin extends Plugin
|
||||
.build().toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void openSearchInput()
|
||||
{
|
||||
@@ -325,22 +323,11 @@ public class WikiPlugin extends Plugin
|
||||
.build();
|
||||
}
|
||||
|
||||
private Widget getWidget(int wid, int index)
|
||||
{
|
||||
Widget w = client.getWidget(WidgetInfo.TO_GROUP(wid), WidgetInfo.TO_CHILD(wid));
|
||||
if (index != -1)
|
||||
{
|
||||
w = w.getChild(index);
|
||||
}
|
||||
return w;
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
private void onMenuEntryAdded(MenuEntryAdded event)
|
||||
{
|
||||
int widgetIndex = event.getParam0();
|
||||
int widgetID = event.getParam1();
|
||||
MenuEntry[] menuEntries = client.getMenuEntries();
|
||||
|
||||
if (wikiSelected && event.getOpcode() == MenuOpcode.SPELL_CAST_ON_WIDGET.getId())
|
||||
{
|
||||
@@ -350,13 +337,16 @@ public class WikiPlugin extends Plugin
|
||||
// we don't support this widget
|
||||
// remove the last SPELL_CAST_ON_WIDGET; we can't blindly remove the top action because some other
|
||||
// plugin might have added something on this same event, and we probably shouldn't remove that instead
|
||||
MenuEntry[] oldEntries = menuEntries;
|
||||
menuEntries = Arrays.copyOf(menuEntries, menuEntries.length - 1);
|
||||
for (int ourEntry = oldEntries.length - 1; ourEntry >= 2 && oldEntries[oldEntries.length - 1].getOpcode() != MenuOpcode.SPELL_CAST_ON_WIDGET.getId(); ourEntry--)
|
||||
MenuEntry[] menuEntries = client.getMenuEntries();
|
||||
for (int i = menuEntries.length - 1; i >= 0; i--)
|
||||
{
|
||||
menuEntries[ourEntry - 1] = oldEntries[ourEntry];
|
||||
}
|
||||
if (menuEntries[i].getOpcode() == MenuOpcode.SPELL_CAST_ON_WIDGET.getId())
|
||||
{
|
||||
menuEntries[i] = null;
|
||||
client.setMenuEntries(menuEntries);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -396,9 +386,7 @@ public class WikiPlugin extends Plugin
|
||||
return;
|
||||
}
|
||||
|
||||
String action = Stream.of(w.getActions())
|
||||
.filter(s -> s != null && !s.isEmpty())
|
||||
.findFirst().orElse(null);
|
||||
String action = firstAction(w);
|
||||
if (action == null)
|
||||
{
|
||||
return;
|
||||
@@ -424,9 +412,7 @@ public class WikiPlugin extends Plugin
|
||||
return;
|
||||
}
|
||||
|
||||
String action = Stream.of(w.getActions())
|
||||
.filter(s -> s != null && !s.isEmpty())
|
||||
.findFirst().orElse(null);
|
||||
String action = firstAction(w);
|
||||
if (action == null)
|
||||
{
|
||||
return;
|
||||
@@ -443,4 +429,28 @@ public class WikiPlugin extends Plugin
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private Widget getWidget(int wid, int index)
|
||||
{
|
||||
Widget w = client.getWidget(WidgetInfo.TO_GROUP(wid), WidgetInfo.TO_CHILD(wid));
|
||||
if (index != -1)
|
||||
{
|
||||
w = w.getChild(index);
|
||||
}
|
||||
return w;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static String firstAction(Widget widget)
|
||||
{
|
||||
for (String action : widget.getActions())
|
||||
{
|
||||
if (StringUtils.isNotEmpty(action))
|
||||
{
|
||||
return action;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user