project: Implement the new menu entry handling
This commit is contained in:
@@ -163,36 +163,6 @@ public abstract class MenuMixin implements RSClient
|
||||
}
|
||||
}
|
||||
|
||||
@Inject
|
||||
@Override
|
||||
public MenuEntry getLeftClickMenuEntry()
|
||||
{
|
||||
final int i = getMenuOptionCount() - 1;
|
||||
return new MenuEntry(
|
||||
getMenuOptions()[i],
|
||||
getMenuTargets()[i],
|
||||
getMenuIdentifiers()[i],
|
||||
getMenuOpcodes()[i],
|
||||
getMenuArguments1()[i],
|
||||
getMenuArguments2()[i],
|
||||
getMenuForceLeftClick()[i]
|
||||
);
|
||||
}
|
||||
|
||||
@Inject
|
||||
@Override
|
||||
public void setLeftClickMenuEntry(final MenuEntry entry)
|
||||
{
|
||||
final int i = getMenuOptionCount() - 1;
|
||||
getMenuOptions()[i] = entry.getOption();
|
||||
getMenuTargets()[i] = entry.getTarget();
|
||||
getMenuIdentifiers()[i] = entry.getIdentifier();
|
||||
getMenuOpcodes()[i] = entry.getOpcode();
|
||||
getMenuArguments1()[i] = entry.getParam0();
|
||||
getMenuArguments2()[i] = entry.getParam1();
|
||||
getMenuForceLeftClick()[i] = entry.isForceLeftClick();
|
||||
}
|
||||
|
||||
@Inject
|
||||
@FieldHook("tempMenuAction")
|
||||
public static void onTempMenuActionChanged(int idx)
|
||||
@@ -213,7 +183,7 @@ public abstract class MenuMixin implements RSClient
|
||||
}
|
||||
|
||||
tempMenuAction.setOption(entry.getOption());
|
||||
tempMenuAction.setOpcode(entry.getOpcode());
|
||||
tempMenuAction.setOpcode(entry.getType().getId());
|
||||
tempMenuAction.setIdentifier(entry.getIdentifier());
|
||||
tempMenuAction.setParam0(entry.getParam0());
|
||||
tempMenuAction.setParam1(entry.getParam1());
|
||||
|
||||
@@ -156,6 +156,7 @@ import net.runelite.rs.api.RSNodeDeque;
|
||||
import net.runelite.rs.api.RSNodeHashTable;
|
||||
import net.runelite.rs.api.RSPacketBuffer;
|
||||
import net.runelite.rs.api.RSPlayer;
|
||||
import net.runelite.rs.api.RSRuneLiteMenuEntry;
|
||||
import net.runelite.rs.api.RSScene;
|
||||
import net.runelite.rs.api.RSScriptEvent;
|
||||
import net.runelite.rs.api.RSSpritePixels;
|
||||
@@ -294,6 +295,12 @@ public abstract class RSClientMixin implements RSClient
|
||||
@Inject
|
||||
private static ArrayList<Widget> hiddenWidgets = new ArrayList<>();
|
||||
|
||||
@Inject
|
||||
private static final RSRuneLiteMenuEntry[] rl$menuEntries = new RSRuneLiteMenuEntry[500];
|
||||
|
||||
@Inject
|
||||
private static int tmpMenuOptionsCount;
|
||||
|
||||
@Inject
|
||||
@Override
|
||||
public void setPrintMenuActions(boolean yes)
|
||||
@@ -789,119 +796,210 @@ public abstract class RSClientMixin implements RSClient
|
||||
setChatCycle(getCycleCntr());
|
||||
}
|
||||
|
||||
@Inject
|
||||
public static RSRuneLiteMenuEntry newRuneliteMenuEntry(int idx)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Inject
|
||||
@Override
|
||||
public MenuEntry createMenuEntry(int idx)
|
||||
{
|
||||
// TODO: Implement this
|
||||
if (client.getMenuOptionCount() >= 500)
|
||||
{
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (idx < 0)
|
||||
{
|
||||
idx = client.getMenuOptionCount() + idx + 1;
|
||||
if (idx < 0)
|
||||
{
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
}
|
||||
|
||||
return new MenuEntry();
|
||||
RSRuneLiteMenuEntry menuEntry;
|
||||
if (idx < client.getMenuOptionCount())
|
||||
{
|
||||
RSRuneLiteMenuEntry tmpEntry = rl$menuEntries[client.getMenuOptionCount()];
|
||||
if (tmpEntry == null)
|
||||
{
|
||||
tmpEntry = rl$menuEntries[client.getMenuOptionCount()] = newRuneliteMenuEntry(client.getMenuOptionCount());
|
||||
}
|
||||
|
||||
for (int i = client.getMenuOptionCount(); i > idx; rl$menuEntries[i].setIdx(i--))
|
||||
{
|
||||
client.getMenuOptions()[i] = client.getMenuOptions()[i - 1];
|
||||
client.getMenuTargets()[i] = client.getMenuTargets()[i - 1];
|
||||
client.getMenuIdentifiers()[i] = client.getMenuIdentifiers()[i - 1];
|
||||
client.getMenuOpcodes()[i] = client.getMenuOpcodes()[i - 1];
|
||||
client.getMenuArguments1()[i] = client.getMenuArguments1()[i - 1];
|
||||
client.getMenuArguments2()[i] = client.getMenuArguments2()[i - 1];
|
||||
client.getMenuForceLeftClick()[i] = client.getMenuForceLeftClick()[i - 1];
|
||||
|
||||
rl$menuEntries[i] = rl$menuEntries[i - 1];
|
||||
}
|
||||
|
||||
client.setMenuOptionCount(client.getMenuOptionCount() + 1);
|
||||
tmpMenuOptionsCount = client.getMenuOptionCount();
|
||||
|
||||
menuEntry = tmpEntry;
|
||||
rl$menuEntries[idx] = tmpEntry;
|
||||
|
||||
tmpEntry.setIdx(idx);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (idx != client.getMenuOptionCount())
|
||||
{
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
|
||||
menuEntry = rl$menuEntries[client.getMenuOptionCount()];
|
||||
|
||||
if (menuEntry == null)
|
||||
{
|
||||
menuEntry = rl$menuEntries[client.getMenuOptionCount()] = newRuneliteMenuEntry(client.getMenuOptionCount());
|
||||
}
|
||||
|
||||
client.setMenuOptionCount(client.getMenuOptionCount() + 1);
|
||||
tmpMenuOptionsCount = client.getMenuOptionCount();
|
||||
}
|
||||
|
||||
menuEntry.setOption("");
|
||||
menuEntry.setTarget("");
|
||||
menuEntry.setIdentifier(0);
|
||||
menuEntry.setType(MenuAction.RUNELITE);
|
||||
menuEntry.setParam0(0);
|
||||
menuEntry.setParam1(0);
|
||||
menuEntry.setConsumer(null);
|
||||
|
||||
return menuEntry;
|
||||
}
|
||||
}
|
||||
|
||||
@Inject
|
||||
@Override
|
||||
public MenuEntry[] getMenuEntries()
|
||||
{
|
||||
int count = getMenuOptionCount();
|
||||
String[] menuOptions = getMenuOptions();
|
||||
String[] menuTargets = getMenuTargets();
|
||||
int[] menuIdentifiers = getMenuIdentifiers();
|
||||
int[] menuTypes = getMenuOpcodes();
|
||||
int[] params0 = getMenuArguments1();
|
||||
int[] params1 = getMenuArguments2();
|
||||
boolean[] leftClick = getMenuForceLeftClick();
|
||||
|
||||
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.setOpcode(menuTypes[i]);
|
||||
entry.setParam0(params0[i]);
|
||||
entry.setParam1(params1[i]);
|
||||
entry.setForceLeftClick(leftClick[i]);
|
||||
}
|
||||
return entries;
|
||||
return Arrays.copyOf(rl$menuEntries, client.getMenuOptionCount());
|
||||
}
|
||||
|
||||
@Inject
|
||||
@Override
|
||||
public void setMenuEntries(MenuEntry[] entries)
|
||||
public void setMenuEntries(MenuEntry[] menuEntries)
|
||||
{
|
||||
int count = 0;
|
||||
String[] menuOptions = getMenuOptions();
|
||||
String[] menuTargets = getMenuTargets();
|
||||
int[] menuIdentifiers = getMenuIdentifiers();
|
||||
int[] menuTypes = getMenuOpcodes();
|
||||
int[] params0 = getMenuArguments1();
|
||||
int[] params1 = getMenuArguments2();
|
||||
boolean[] leftClick = getMenuForceLeftClick();
|
||||
|
||||
for (MenuEntry entry : entries)
|
||||
for (int i = 0; i < menuEntries.length; ++i)
|
||||
{
|
||||
if (entry == null)
|
||||
RSRuneLiteMenuEntry menuEntry = (RSRuneLiteMenuEntry) menuEntries[i];
|
||||
if (menuEntry.getIdx() != i)
|
||||
{
|
||||
continue;
|
||||
sortMenuEntries(menuEntry.getIdx(), i);
|
||||
}
|
||||
|
||||
menuOptions[count] = entry.getOption();
|
||||
menuTargets[count] = entry.getTarget();
|
||||
menuIdentifiers[count] = entry.getIdentifier();
|
||||
menuTypes[count] = entry.getOpcode();
|
||||
params0[count] = entry.getParam0();
|
||||
params1[count] = entry.getParam1();
|
||||
leftClick[count] = entry.isForceLeftClick();
|
||||
++count;
|
||||
}
|
||||
|
||||
setMenuOptionCount(count);
|
||||
oldMenuEntryCount = count;
|
||||
client.setMenuOptionCount(menuEntries.length);
|
||||
tmpMenuOptionsCount = menuEntries.length;
|
||||
}
|
||||
|
||||
@Inject
|
||||
public static void sortMenuEntries(int left, int right)
|
||||
{
|
||||
String menuOption = client.getMenuOptions()[left];
|
||||
client.getMenuOptions()[left] = client.getMenuOptions()[right];
|
||||
client.getMenuOptions()[right] = menuOption;
|
||||
|
||||
String menuTarget = client.getMenuTargets()[left];
|
||||
client.getMenuTargets()[left] = client.getMenuTargets()[right];
|
||||
client.getMenuTargets()[right] = menuTarget;
|
||||
|
||||
int menuIdentifier = client.getMenuIdentifiers()[left];
|
||||
client.getMenuIdentifiers()[left] = client.getMenuIdentifiers()[right];
|
||||
client.getMenuIdentifiers()[right] = menuIdentifier;
|
||||
|
||||
int menuOpcode = client.getMenuOpcodes()[left];
|
||||
client.getMenuOpcodes()[left] = client.getMenuOpcodes()[right];
|
||||
client.getMenuOpcodes()[right] = menuOpcode;
|
||||
|
||||
int menuArguments1 = client.getMenuArguments1()[left];
|
||||
client.getMenuArguments1()[left] = client.getMenuArguments1()[right];
|
||||
client.getMenuArguments1()[right] = menuArguments1;
|
||||
|
||||
int menuArgument2 = client.getMenuArguments2()[left];
|
||||
client.getMenuArguments2()[left] = client.getMenuArguments2()[right];
|
||||
client.getMenuArguments2()[right] = menuArgument2;
|
||||
|
||||
boolean menuForceLeftClick = client.getMenuForceLeftClick()[left];
|
||||
client.getMenuForceLeftClick()[left] = client.getMenuForceLeftClick()[right];
|
||||
client.getMenuForceLeftClick()[right] = menuForceLeftClick;
|
||||
|
||||
RSRuneLiteMenuEntry tmpEntry = rl$menuEntries[left];
|
||||
rl$menuEntries[left] = rl$menuEntries[right];
|
||||
rl$menuEntries[right] = tmpEntry;
|
||||
|
||||
rl$menuEntries[left].setIdx(left);
|
||||
rl$menuEntries[right].setIdx(right);
|
||||
}
|
||||
|
||||
@Inject
|
||||
public static void swapMenuEntries(int var0)
|
||||
{
|
||||
RSRuneLiteMenuEntry var1 = rl$menuEntries[var0];
|
||||
RSRuneLiteMenuEntry var2 = rl$menuEntries[var0 + 1];
|
||||
|
||||
rl$menuEntries[var0] = var2;
|
||||
rl$menuEntries[var0 + 1] = var1;
|
||||
|
||||
var1.setIdx(var0 + 1);
|
||||
var2.setIdx(var0);
|
||||
}
|
||||
|
||||
@FieldHook("menuOptionsCount")
|
||||
@Inject
|
||||
public static void onMenuOptionsChanged(int idx)
|
||||
{
|
||||
int oldCount = oldMenuEntryCount;
|
||||
int newCount = client.getMenuOptionCount();
|
||||
int tmpOptionsCount = tmpMenuOptionsCount;
|
||||
int optionCount = client.getMenuOptionCount();
|
||||
|
||||
oldMenuEntryCount = newCount;
|
||||
tmpMenuOptionsCount = optionCount;
|
||||
|
||||
final String[] options = client.getMenuOptions();
|
||||
final String[] targets = client.getMenuTargets();
|
||||
final int[] identifiers = client.getMenuIdentifiers();
|
||||
final int[] opcodes = client.getMenuOpcodes();
|
||||
final int[] arguments1 = client.getMenuArguments1();
|
||||
final int[] arguments2 = client.getMenuArguments2();
|
||||
final boolean[] forceLeftClick = client.getMenuForceLeftClick();
|
||||
|
||||
if (newCount == oldCount + 1)
|
||||
if (optionCount < tmpOptionsCount)
|
||||
{
|
||||
MenuEntryAdded event = new MenuEntryAdded(
|
||||
options[oldCount],
|
||||
targets[oldCount],
|
||||
identifiers[oldCount],
|
||||
opcodes[oldCount],
|
||||
arguments1[oldCount],
|
||||
arguments2[oldCount],
|
||||
forceLeftClick[oldCount]
|
||||
);
|
||||
|
||||
client.getCallbacks().post(event);
|
||||
|
||||
if (event.isModified() && client.getMenuOptionCount() == newCount)
|
||||
for (int i = optionCount; i < tmpOptionsCount; ++i)
|
||||
{
|
||||
options[oldCount] = event.getOption();
|
||||
targets[oldCount] = event.getTarget();
|
||||
identifiers[oldCount] = event.getIdentifier();
|
||||
opcodes[oldCount] = event.getType();
|
||||
arguments1[oldCount] = event.getActionParam0();
|
||||
arguments2[oldCount] = event.getActionParam1();
|
||||
forceLeftClick[oldCount] = event.isForceLeftClick();
|
||||
rl$menuEntries[i].setConsumer(null);
|
||||
}
|
||||
}
|
||||
else if (optionCount == tmpOptionsCount + 1)
|
||||
{
|
||||
String menuOption = client.getMenuOptions()[tmpOptionsCount];
|
||||
String menuTarget = client.getMenuTargets()[tmpOptionsCount];
|
||||
int menuOpcode = client.getMenuOpcodes()[tmpOptionsCount];
|
||||
int menuIdentifier = client.getMenuIdentifiers()[tmpOptionsCount];
|
||||
int menuArgument1 = client.getMenuArguments1()[tmpOptionsCount];
|
||||
int menuArgument2 = client.getMenuArguments2()[tmpOptionsCount];
|
||||
if (rl$menuEntries[tmpOptionsCount] == null)
|
||||
{
|
||||
rl$menuEntries[tmpOptionsCount] = newRuneliteMenuEntry(tmpOptionsCount);
|
||||
}
|
||||
else
|
||||
{
|
||||
rl$menuEntries[tmpOptionsCount].setConsumer(null);
|
||||
}
|
||||
|
||||
MenuEntryAdded menuEntryAdded = new MenuEntryAdded(
|
||||
menuOption,
|
||||
menuTarget,
|
||||
menuOpcode,
|
||||
menuIdentifier,
|
||||
menuArgument1,
|
||||
menuArgument2
|
||||
);
|
||||
client.getCallbacks().post(menuEntryAdded);
|
||||
}
|
||||
}
|
||||
|
||||
@Inject
|
||||
@@ -1479,6 +1577,17 @@ public abstract class RSClientMixin implements RSClient
|
||||
@Replace("menuAction")
|
||||
static void copy$menuAction(int param0, int param1, int opcode, int id, String option, String target, int canvasX, int canvasY)
|
||||
{
|
||||
RSRuneLiteMenuEntry menuEntry = null;
|
||||
|
||||
for (int i = client.getMenuOptionCount() - 1; i >= 0; --i)
|
||||
{
|
||||
if (client.getMenuOptions()[i] == option && client.getMenuTargets()[i] == target && client.getMenuIdentifiers()[i] == id && client.getMenuOpcodes()[i] == opcode)
|
||||
{
|
||||
menuEntry = rl$menuEntries[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* The RuneScape client may deprioritize an action in the menu by incrementing the opcode with 2000,
|
||||
* undo it here so we can get the correct opcode
|
||||
@@ -1501,6 +1610,11 @@ public abstract class RSClientMixin implements RSClient
|
||||
|
||||
client.getCallbacks().post(menuOptionClicked);
|
||||
|
||||
if (menuEntry != null && menuEntry.getConsumer() != null)
|
||||
{
|
||||
menuEntry.getConsumer().accept(menuEntry);
|
||||
}
|
||||
|
||||
if (menuOptionClicked.isConsumed())
|
||||
{
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user