client: Improve menumanager (#2026)
* make menumanager work with everything it didn't work with before * rebuild left click before render instead of on client tick * Remove useless checks which were breaking when dragging in bank * Change rsclient line breaks (only 5th fucking time this pr dw) * Rename arg1 & arg2 getters/fields to be more consistent
This commit is contained in:
@@ -1905,4 +1905,10 @@ public interface Client extends GameShell
|
||||
* the "You have been disconnected." message anymore.
|
||||
*/
|
||||
void setHideDisconnect(boolean dontShow);
|
||||
|
||||
/**
|
||||
* Sets the fields in the temporary menu entry that's saved in the client
|
||||
* when a inventory item is clicked and dragged.
|
||||
*/
|
||||
void setTempMenuEntry(MenuEntry entry);
|
||||
}
|
||||
@@ -25,7 +25,6 @@
|
||||
package net.runelite.api.events;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import net.runelite.api.MenuEntry;
|
||||
@@ -42,7 +41,6 @@ import net.runelite.api.MenuEntry;
|
||||
* it seems that this event still triggers with the "Cancel" action.
|
||||
*/
|
||||
@Getter
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class MenuOptionClicked extends MenuEntry implements Event
|
||||
{
|
||||
public MenuOptionClicked(String option, String target, int identifier, int opcode, int param0, int param1, boolean forceLeftClick)
|
||||
|
||||
@@ -52,6 +52,7 @@ import net.runelite.api.MenuOpcode;
|
||||
import static net.runelite.api.MenuOpcode.MENU_ACTION_DEPRIORITIZE_OFFSET;
|
||||
import net.runelite.api.NPCDefinition;
|
||||
import net.runelite.api.events.BeforeRender;
|
||||
import net.runelite.api.events.ClientTick;
|
||||
import net.runelite.api.events.MenuEntryAdded;
|
||||
import net.runelite.api.events.MenuOpened;
|
||||
import net.runelite.api.events.MenuOptionClicked;
|
||||
@@ -89,7 +90,6 @@ public class MenuManager
|
||||
private final Map<AbstractComparableEntry, AbstractComparableEntry> swaps = new HashMap<>();
|
||||
|
||||
private MenuEntry leftClickEntry = null;
|
||||
private MenuEntry firstEntry = null;
|
||||
|
||||
private int playerAttackIdx = -1;
|
||||
|
||||
@@ -102,11 +102,15 @@ public class MenuManager
|
||||
|
||||
eventBus.subscribe(MenuOpened.class, this, this::onMenuOpened);
|
||||
eventBus.subscribe(MenuEntryAdded.class, this, this::onMenuEntryAdded);
|
||||
eventBus.subscribe(BeforeRender.class, this, this::onBeforeRender);
|
||||
eventBus.subscribe(PlayerMenuOptionsChanged.class, this, this::onPlayerMenuOptionsChanged);
|
||||
eventBus.subscribe(NpcActionChanged.class, this, this::onNpcActionChanged);
|
||||
eventBus.subscribe(WidgetPressed.class, this, this::onWidgetPressed);
|
||||
eventBus.subscribe(MenuOptionClicked.class, this, this::onMenuOptionClicked);
|
||||
|
||||
// Make sure last tick's entry gets cleared
|
||||
eventBus.subscribe(ClientTick.class, this, tick -> leftClickEntry = null);
|
||||
// Rebuild left click menu for top left entry
|
||||
eventBus.subscribe(BeforeRender.class, this, br -> rebuildLeftClickMenu());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -153,7 +157,7 @@ public class MenuManager
|
||||
// Need to reorder the list to normal, then rebuild with swaps
|
||||
MenuEntry[] oldEntries = event.getMenuEntries();
|
||||
|
||||
firstEntry = null;
|
||||
leftClickEntry = null;
|
||||
|
||||
List<MenuEntry> newEntries = Lists.newArrayList(oldEntries);
|
||||
|
||||
@@ -281,25 +285,20 @@ public class MenuManager
|
||||
}
|
||||
}
|
||||
|
||||
private void onBeforeRender(BeforeRender event)
|
||||
{
|
||||
rebuildLeftClickMenu();
|
||||
}
|
||||
|
||||
private MenuEntry rebuildLeftClickMenu()
|
||||
private void rebuildLeftClickMenu()
|
||||
{
|
||||
leftClickEntry = null;
|
||||
if (client.isMenuOpen())
|
||||
{
|
||||
return null;
|
||||
return;
|
||||
}
|
||||
|
||||
int menuOptionCount = client.getMenuOptionCount();
|
||||
if (menuOptionCount <= 2)
|
||||
{
|
||||
return null;
|
||||
return;
|
||||
}
|
||||
|
||||
firstEntry = null;
|
||||
MenuEntry[] entries = new MenuEntry[menuOptionCount + priorityEntries.size()];
|
||||
System.arraycopy(client.getMenuEntries(), 0, entries, 0, menuOptionCount);
|
||||
|
||||
@@ -308,21 +307,19 @@ public class MenuManager
|
||||
indexPriorityEntries(entries, menuOptionCount);
|
||||
}
|
||||
|
||||
if (firstEntry == null && !swaps.isEmpty())
|
||||
if (leftClickEntry == null && !swaps.isEmpty())
|
||||
{
|
||||
indexSwapEntries(entries, menuOptionCount);
|
||||
}
|
||||
|
||||
|
||||
if (firstEntry == null)
|
||||
if (leftClickEntry == null)
|
||||
{
|
||||
// stop being null smh
|
||||
firstEntry = entries[menuOptionCount - 1];
|
||||
leftClickEntry = entries[menuOptionCount - 1];
|
||||
}
|
||||
|
||||
client.setMenuEntries(entries);
|
||||
|
||||
return firstEntry;
|
||||
}
|
||||
|
||||
public void addPlayerMenuItem(String menuText)
|
||||
@@ -426,16 +423,18 @@ public class MenuManager
|
||||
|
||||
private void onWidgetPressed(WidgetPressed event)
|
||||
{
|
||||
leftClickEntry = rebuildLeftClickMenu();
|
||||
rebuildLeftClickMenu();
|
||||
client.setTempMenuEntry(leftClickEntry);
|
||||
}
|
||||
|
||||
private void onMenuOptionClicked(MenuOptionClicked event)
|
||||
{
|
||||
if (!client.isMenuOpen() && event.isAuthentic())
|
||||
// option and target will be the same if this one came from "tempMenuAction"
|
||||
if (!client.isMenuOpen() && !event.getOption().equals(event.getTarget()) && event.isAuthentic())
|
||||
{
|
||||
if (event.getMouseButton() != 0)
|
||||
if (!event.equals(leftClickEntry))
|
||||
{
|
||||
leftClickEntry = rebuildLeftClickMenu();
|
||||
rebuildLeftClickMenu();
|
||||
}
|
||||
|
||||
if (leftClickEntry != null)
|
||||
@@ -879,7 +878,7 @@ public class MenuManager
|
||||
entries[menuOptionCount + i] = prios[i].entry;
|
||||
}
|
||||
|
||||
firstEntry = entries[menuOptionCount + i - 1];
|
||||
leftClickEntry = entries[menuOptionCount + i - 1];
|
||||
|
||||
}
|
||||
|
||||
@@ -922,7 +921,7 @@ public class MenuManager
|
||||
|
||||
entries[i] = first;
|
||||
entries[menuOptionCount - 1] = entry;
|
||||
firstEntry = entry;
|
||||
leftClickEntry = entry;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,10 +25,14 @@
|
||||
package net.runelite.mixins;
|
||||
|
||||
import net.runelite.api.MenuEntry;
|
||||
import net.runelite.api.events.WidgetPressed;
|
||||
import net.runelite.api.mixins.FieldHook;
|
||||
import net.runelite.api.mixins.Inject;
|
||||
import net.runelite.api.mixins.Mixin;
|
||||
import net.runelite.api.mixins.Shadow;
|
||||
import net.runelite.rs.api.RSClient;
|
||||
import net.runelite.rs.api.RSFont;
|
||||
import net.runelite.rs.api.RSMenuAction;
|
||||
|
||||
@Mixin(RSClient.class)
|
||||
public abstract class MenuMixin implements RSClient
|
||||
@@ -41,6 +45,12 @@ public abstract class MenuMixin implements RSClient
|
||||
private static final int MENU_HEADER_GRADIENT_TOP_2010 = 0x322E22;
|
||||
private static final int MENU_HEADER_GRADIENT_BOTTOM_2010 = 0x090A04;
|
||||
|
||||
@Shadow("client")
|
||||
private static RSClient client;
|
||||
|
||||
@Shadow("tempMenuAction")
|
||||
private static RSMenuAction tempMenuAction;
|
||||
|
||||
@Inject
|
||||
@Override
|
||||
public void draw2010Menu()
|
||||
@@ -140,4 +150,28 @@ public abstract class MenuMixin implements RSClient
|
||||
getMenuArguments2()[i] = entry.getParam1();
|
||||
getMenuForceLeftClick()[i] = entry.isForceLeftClick();
|
||||
}
|
||||
|
||||
@Inject
|
||||
@FieldHook("tempMenuAction")
|
||||
public static void onTempMenuActionChanged(int idx)
|
||||
{
|
||||
if (tempMenuAction != null)
|
||||
{
|
||||
client.getCallbacks().post(WidgetPressed.class, WidgetPressed.INSTANCE);
|
||||
}
|
||||
}
|
||||
|
||||
@Inject
|
||||
@Override
|
||||
public void setTempMenuEntry(MenuEntry entry)
|
||||
{
|
||||
if (entry == null || tempMenuAction == null)
|
||||
return;
|
||||
|
||||
tempMenuAction.setOption(entry.getOption());
|
||||
tempMenuAction.setOpcode(entry.getOpcode());
|
||||
tempMenuAction.setIdentifier(entry.getIdentifier());
|
||||
tempMenuAction.setParam0(entry.getParam0());
|
||||
tempMenuAction.setParam1(entry.getParam1());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,7 +100,6 @@ import net.runelite.api.events.UsernameChanged;
|
||||
import net.runelite.api.events.VarbitChanged;
|
||||
import net.runelite.api.events.VolumeChanged;
|
||||
import net.runelite.api.events.WidgetLoaded;
|
||||
import net.runelite.api.events.WidgetPressed;
|
||||
import net.runelite.api.hooks.Callbacks;
|
||||
import net.runelite.api.hooks.DrawCallbacks;
|
||||
import net.runelite.api.mixins.Copy;
|
||||
@@ -1403,16 +1402,6 @@ public abstract class RSClientMixin implements RSClient
|
||||
client.sendMenuAction(actionParam, widgetId, menuAction, id, menuOption, "!AUTHENTIC" + menuTarget, var6, var7);
|
||||
}
|
||||
|
||||
@Inject
|
||||
@FieldHook("tempMenuAction")
|
||||
public static void onTempMenuActionChanged(int idx)
|
||||
{
|
||||
if (client.getTempMenuAction() != null)
|
||||
{
|
||||
client.getCallbacks().post(WidgetPressed.class, WidgetPressed.INSTANCE);
|
||||
}
|
||||
}
|
||||
|
||||
@FieldHook("Login_username")
|
||||
@Inject
|
||||
public static void onUsernameChanged(int idx)
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -24,6 +24,22 @@
|
||||
*/
|
||||
package net.runelite.rs.api;
|
||||
|
||||
import net.runelite.mapping.Import;
|
||||
|
||||
public interface RSMenuAction
|
||||
{
|
||||
@Import("action")
|
||||
void setOption(String yes);
|
||||
|
||||
@Import("opcode")
|
||||
void setOpcode(int yes);
|
||||
|
||||
@Import("identifier")
|
||||
void setIdentifier(int yes);
|
||||
|
||||
@Import("param0")
|
||||
void setParam0(int yes);
|
||||
|
||||
@Import("param1")
|
||||
void setParam1(int yes);
|
||||
}
|
||||
|
||||
@@ -361,7 +361,7 @@ public abstract class AbstractWorldMapData {
|
||||
)
|
||||
static void method325(int var0, int var1) {
|
||||
MenuAction var2 = StudioGame.tempMenuAction;
|
||||
GrandExchangeOfferOwnWorldComparator.menuAction(var2.argument1, var2.argument2, var2.opcode, var2.argument0, var2.action, var2.action, var0, var1);
|
||||
GrandExchangeOfferOwnWorldComparator.menuAction(var2.param0, var2.param1, var2.opcode, var2.identifier, var2.action, var2.action, var0, var1);
|
||||
StudioGame.tempMenuAction = null;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,8 +17,8 @@ public class MenuAction {
|
||||
@ObfuscatedGetter(
|
||||
intValue = -1613868885
|
||||
)
|
||||
@Export("argument1")
|
||||
int argument1;
|
||||
@Export("param0")
|
||||
int param0;
|
||||
@ObfuscatedName("t")
|
||||
@Export("action")
|
||||
String action;
|
||||
@@ -26,8 +26,8 @@ public class MenuAction {
|
||||
@ObfuscatedGetter(
|
||||
intValue = -872703787
|
||||
)
|
||||
@Export("argument2")
|
||||
int argument2;
|
||||
@Export("param1")
|
||||
int param1;
|
||||
@ObfuscatedName("q")
|
||||
@ObfuscatedGetter(
|
||||
intValue = 553279575
|
||||
@@ -38,8 +38,8 @@ public class MenuAction {
|
||||
@ObfuscatedGetter(
|
||||
intValue = -1804422619
|
||||
)
|
||||
@Export("argument0")
|
||||
int argument0;
|
||||
@Export("identifier")
|
||||
int identifier;
|
||||
|
||||
MenuAction() {
|
||||
}
|
||||
|
||||
@@ -203,10 +203,10 @@ public class Script extends DualNode {
|
||||
)
|
||||
static void method2384(int var0) {
|
||||
StudioGame.tempMenuAction = new MenuAction();
|
||||
StudioGame.tempMenuAction.argument1 = Client.menuArguments1[var0];
|
||||
StudioGame.tempMenuAction.argument2 = Client.menuArguments2[var0];
|
||||
StudioGame.tempMenuAction.param0 = Client.menuArguments1[var0];
|
||||
StudioGame.tempMenuAction.param1 = Client.menuArguments2[var0];
|
||||
StudioGame.tempMenuAction.opcode = Client.menuOpcodes[var0];
|
||||
StudioGame.tempMenuAction.argument0 = Client.menuIdentifiers[var0];
|
||||
StudioGame.tempMenuAction.identifier = Client.menuIdentifiers[var0];
|
||||
StudioGame.tempMenuAction.action = Client.menuActions[var0];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user