runelite-api: add MenuEntry abstraction for menu arrays

This commit is contained in:
Adam
2017-11-16 20:06:28 -05:00
parent 5cf73f424d
commit ab297e969c
5 changed files with 187 additions and 23 deletions

View File

@@ -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();

View File

@@ -0,0 +1,102 @@
/*
* Copyright (c) 2016-2017, Adam <Adam@sigterm.info>
* 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;
}
}

View File

@@ -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())
{

View File

@@ -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<Player> players = new ArrayList<Player>(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);
}
}

View File

@@ -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();