From ab297e969cae932be8a654e915771991a508ffbc Mon Sep 17 00:00:00 2001 From: Adam Date: Thu, 16 Nov 2017 20:06:28 -0500 Subject: [PATCH] runelite-api: add MenuEntry abstraction for menu arrays --- .../main/java/net/runelite/api/Client.java | 7 +- .../main/java/net/runelite/api/MenuEntry.java | 102 ++++++++++++++++++ .../mousehighlight/MouseHighlightOverlay.java | 13 +-- .../net/runelite/mixins/RSClientMixin.java | 58 +++++++++- .../java/net/runelite/rs/api/RSClient.java | 30 ++++-- 5 files changed, 187 insertions(+), 23 deletions(-) create mode 100644 runelite-api/src/main/java/net/runelite/api/MenuEntry.java diff --git a/runelite-api/src/main/java/net/runelite/api/Client.java b/runelite-api/src/main/java/net/runelite/api/Client.java index e831b557c2..052a82ff0c 100644 --- a/runelite-api/src/main/java/net/runelite/api/Client.java +++ b/runelite-api/src/main/java/net/runelite/api/Client.java @@ -27,7 +27,6 @@ package net.runelite.api; import java.awt.Canvas; import java.util.List; import java.util.Map; - import net.runelite.api.widgets.Widget; import net.runelite.api.widgets.WidgetInfo; @@ -107,11 +106,9 @@ public interface Client int[] getPlayerMenuTypes(); - String[] getMenuOptions(); + MenuEntry[] getMenuEntries(); - String[] getMenuTargets(); - - int getMenuOptionCount(); + void setMenuEntries(MenuEntry[] entries); boolean isMenuOpen(); diff --git a/runelite-api/src/main/java/net/runelite/api/MenuEntry.java b/runelite-api/src/main/java/net/runelite/api/MenuEntry.java new file mode 100644 index 0000000000..dccdfcf3dd --- /dev/null +++ b/runelite-api/src/main/java/net/runelite/api/MenuEntry.java @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2016-2017, Adam + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.api; + +public class MenuEntry +{ + private String option; + private String target; + private int identifier; + private MenuAction type; + private int param0; + private int param1; + + @Override + public String toString() + { + return "MenuEntry{" + "option=" + option + ", target=" + target + ", identifier=" + identifier + ", type=" + type + ", param0=" + param0 + ", param1=" + param1 + '}'; + } + + public String getOption() + { + return option; + } + + public void setOption(String option) + { + this.option = option; + } + + public String getTarget() + { + return target; + } + + public void setTarget(String target) + { + this.target = target; + } + + public int getIdentifier() + { + return identifier; + } + + public void setIdentifier(int identifier) + { + this.identifier = identifier; + } + + public MenuAction getType() + { + return type; + } + + public void setType(MenuAction type) + { + this.type = type; + } + + public int getParam0() + { + return param0; + } + + public void setParam0(int param0) + { + this.param0 = param0; + } + + public int getParam1() + { + return param1; + } + + public void setParam1(int param1) + { + this.param1 = param1; + } + +} diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/mousehighlight/MouseHighlightOverlay.java b/runelite-client/src/main/java/net/runelite/client/plugins/mousehighlight/MouseHighlightOverlay.java index ad66991cb2..598113fa1c 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/mousehighlight/MouseHighlightOverlay.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/mousehighlight/MouseHighlightOverlay.java @@ -30,6 +30,7 @@ import javax.annotation.Nullable; import javax.inject.Inject; import net.runelite.api.Client; import net.runelite.api.GameState; +import net.runelite.api.MenuEntry; import net.runelite.client.ui.overlay.Overlay; import net.runelite.client.ui.overlay.OverlayPosition; import net.runelite.client.ui.overlay.OverlayRenderer; @@ -67,17 +68,17 @@ class MouseHighlightOverlay extends Overlay return null; } - String[] targets = client.getMenuTargets(); - String[] options = client.getMenuOptions(); - int count = client.getMenuOptionCount() - 1; + MenuEntry[] menuEntries = client.getMenuEntries(); + int last = menuEntries.length - 1; - if (count < 0 || count >= targets.length || count >= options.length) + if (last < 0) { return null; } - String target = targets[count]; - String option = options[count]; + MenuEntry menuEntry = menuEntries[last]; + String target = menuEntry.getTarget(); + String option = menuEntry.getOption(); if (target.isEmpty()) { diff --git a/runelite-mixins/src/main/java/net/runelite/mixins/RSClientMixin.java b/runelite-mixins/src/main/java/net/runelite/mixins/RSClientMixin.java index 5923815905..e62763c8cc 100644 --- a/runelite-mixins/src/main/java/net/runelite/mixins/RSClientMixin.java +++ b/runelite-mixins/src/main/java/net/runelite/mixins/RSClientMixin.java @@ -27,6 +27,8 @@ package net.runelite.mixins; import java.util.ArrayList; import java.util.List; import net.runelite.api.GameState; +import net.runelite.api.MenuAction; +import net.runelite.api.MenuEntry; import net.runelite.api.NPC; import net.runelite.api.Player; import net.runelite.api.Point; @@ -51,12 +53,12 @@ public abstract class RSClientMixin implements RSClient int[] playerIndexes = getPlayerIndices(); Player[] cachedPlayers = getCachedPlayers(); List players = new ArrayList(validPlayerIndexes); - + for (int i = 0; i < validPlayerIndexes; ++i) { players.add(cachedPlayers[playerIndexes[i]]); } - + return players; } @@ -260,4 +262,56 @@ public abstract class RSClientMixin implements RSClient } return getWidget(WidgetInfo.FIXED_VIEWPORT); } + + @Inject + @Override + public MenuEntry[] getMenuEntries() + { + int count = getMenuOptionCount(); + String[] menuOptions = getMenuOptions(); + String[] menuTargets = getMenuTargets(); + int[] menuIdentifiers = getMenuIdentifiers(); + int[] menuTypes = getMenuTypes(); + int[] params0 = getMenuActionParams0(); + int[] params1 = getMenuActionParams1(); + + MenuEntry[] entries = new MenuEntry[count]; + for (int i = 0; i < count; ++i) + { + MenuEntry entry = entries[i] = new MenuEntry(); + entry.setOption(menuOptions[i]); + entry.setTarget(menuTargets[i]); + entry.setIdentifier(menuIdentifiers[i]); + entry.setType(MenuAction.of(menuTypes[i])); + entry.setParam0(params0[i]); + entry.setParam1(params1[i]); + } + return entries; + } + + @Inject + @Override + public void setMenuEntries(MenuEntry[] entries) + { + int count = 0; + String[] menuOptions = getMenuOptions(); + String[] menuTargets = getMenuTargets(); + int[] menuIdentifiers = getMenuIdentifiers(); + int[] menuTypes = getMenuTypes(); + int[] params0 = getMenuActionParams0(); + int[] params1 = getMenuActionParams1(); + + for (MenuEntry entry : entries) + { + menuOptions[count] = entry.getOption(); + menuTargets[count] = entry.getTarget(); + menuIdentifiers[count] = entry.getIdentifier(); + menuTypes[count] = entry.getType().getId(); + params0[count] = entry.getParam0(); + params1[count] = entry.getParam1(); + ++count; + } + + setMenuOptionCount(count); + } } diff --git a/runescape-api/src/main/java/net/runelite/rs/api/RSClient.java b/runescape-api/src/main/java/net/runelite/rs/api/RSClient.java index 82bf381673..6605856945 100644 --- a/runescape-api/src/main/java/net/runelite/rs/api/RSClient.java +++ b/runescape-api/src/main/java/net/runelite/rs/api/RSClient.java @@ -162,14 +162,6 @@ public interface RSClient extends RSGameEngine, Client @Override int[] getPlayerMenuTypes(); - @Import("menuTargets") - @Override - String[] getMenuTargets(); - - @Import("menuOptions") - @Override - String[] getMenuOptions(); - @Import("mouseX") int getMouseX(); @@ -179,12 +171,30 @@ public interface RSClient extends RSGameEngine, Client @Import("menuOptionCount") int getMenuOptionCount(); - @Import("menuTypes") - int[] getMenuTypes(); + @Import( + value = "menuOptionCount", + setter = true + ) + void setMenuOptionCount(int menuOptionCount); + + @Import("menuOptions") + String[] getMenuOptions(); + + @Import("menuTargets") + String[] getMenuTargets(); @Import("menuIdentifiers") int[] getMenuIdentifiers(); + @Import("menuTypes") + int[] getMenuTypes(); + + @Import("menuActionParams0") + int[] getMenuActionParams0(); + + @Import("menuActionParams1") + int[] getMenuActionParams1(); + @Import("friends") RSFriend[] getFriends();