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:
Lucwousin
2019-11-13 17:13:24 +01:00
committed by GitHub
parent 33570fbe88
commit bfa3b22be6
10 changed files with 1232 additions and 1194 deletions
@@ -1905,4 +1905,10 @@ public interface Client extends GameShell
* the "You have been disconnected." message anymore. * the "You have been disconnected." message anymore.
*/ */
void setHideDisconnect(boolean dontShow); 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; package net.runelite.api.events;
import lombok.AccessLevel; import lombok.AccessLevel;
import lombok.EqualsAndHashCode;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
import net.runelite.api.MenuEntry; 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. * it seems that this event still triggers with the "Cancel" action.
*/ */
@Getter @Getter
@EqualsAndHashCode(callSuper = true)
public class MenuOptionClicked extends MenuEntry implements Event public class MenuOptionClicked extends MenuEntry implements Event
{ {
public MenuOptionClicked(String option, String target, int identifier, int opcode, int param0, int param1, boolean forceLeftClick) 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 static net.runelite.api.MenuOpcode.MENU_ACTION_DEPRIORITIZE_OFFSET;
import net.runelite.api.NPCDefinition; import net.runelite.api.NPCDefinition;
import net.runelite.api.events.BeforeRender; import net.runelite.api.events.BeforeRender;
import net.runelite.api.events.ClientTick;
import net.runelite.api.events.MenuEntryAdded; import net.runelite.api.events.MenuEntryAdded;
import net.runelite.api.events.MenuOpened; import net.runelite.api.events.MenuOpened;
import net.runelite.api.events.MenuOptionClicked; import net.runelite.api.events.MenuOptionClicked;
@@ -89,7 +90,6 @@ public class MenuManager
private final Map<AbstractComparableEntry, AbstractComparableEntry> swaps = new HashMap<>(); private final Map<AbstractComparableEntry, AbstractComparableEntry> swaps = new HashMap<>();
private MenuEntry leftClickEntry = null; private MenuEntry leftClickEntry = null;
private MenuEntry firstEntry = null;
private int playerAttackIdx = -1; private int playerAttackIdx = -1;
@@ -102,11 +102,15 @@ public class MenuManager
eventBus.subscribe(MenuOpened.class, this, this::onMenuOpened); eventBus.subscribe(MenuOpened.class, this, this::onMenuOpened);
eventBus.subscribe(MenuEntryAdded.class, this, this::onMenuEntryAdded); eventBus.subscribe(MenuEntryAdded.class, this, this::onMenuEntryAdded);
eventBus.subscribe(BeforeRender.class, this, this::onBeforeRender);
eventBus.subscribe(PlayerMenuOptionsChanged.class, this, this::onPlayerMenuOptionsChanged); eventBus.subscribe(PlayerMenuOptionsChanged.class, this, this::onPlayerMenuOptionsChanged);
eventBus.subscribe(NpcActionChanged.class, this, this::onNpcActionChanged); eventBus.subscribe(NpcActionChanged.class, this, this::onNpcActionChanged);
eventBus.subscribe(WidgetPressed.class, this, this::onWidgetPressed); eventBus.subscribe(WidgetPressed.class, this, this::onWidgetPressed);
eventBus.subscribe(MenuOptionClicked.class, this, this::onMenuOptionClicked); 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 // Need to reorder the list to normal, then rebuild with swaps
MenuEntry[] oldEntries = event.getMenuEntries(); MenuEntry[] oldEntries = event.getMenuEntries();
firstEntry = null; leftClickEntry = null;
List<MenuEntry> newEntries = Lists.newArrayList(oldEntries); List<MenuEntry> newEntries = Lists.newArrayList(oldEntries);
@@ -281,25 +285,20 @@ public class MenuManager
} }
} }
private void onBeforeRender(BeforeRender event) private void rebuildLeftClickMenu()
{
rebuildLeftClickMenu();
}
private MenuEntry rebuildLeftClickMenu()
{ {
leftClickEntry = null;
if (client.isMenuOpen()) if (client.isMenuOpen())
{ {
return null; return;
} }
int menuOptionCount = client.getMenuOptionCount(); int menuOptionCount = client.getMenuOptionCount();
if (menuOptionCount <= 2) if (menuOptionCount <= 2)
{ {
return null; return;
} }
firstEntry = null;
MenuEntry[] entries = new MenuEntry[menuOptionCount + priorityEntries.size()]; MenuEntry[] entries = new MenuEntry[menuOptionCount + priorityEntries.size()];
System.arraycopy(client.getMenuEntries(), 0, entries, 0, menuOptionCount); System.arraycopy(client.getMenuEntries(), 0, entries, 0, menuOptionCount);
@@ -308,21 +307,19 @@ public class MenuManager
indexPriorityEntries(entries, menuOptionCount); indexPriorityEntries(entries, menuOptionCount);
} }
if (firstEntry == null && !swaps.isEmpty()) if (leftClickEntry == null && !swaps.isEmpty())
{ {
indexSwapEntries(entries, menuOptionCount); indexSwapEntries(entries, menuOptionCount);
} }
if (firstEntry == null) if (leftClickEntry == null)
{ {
// stop being null smh // stop being null smh
firstEntry = entries[menuOptionCount - 1]; leftClickEntry = entries[menuOptionCount - 1];
} }
client.setMenuEntries(entries); client.setMenuEntries(entries);
return firstEntry;
} }
public void addPlayerMenuItem(String menuText) public void addPlayerMenuItem(String menuText)
@@ -426,16 +423,18 @@ public class MenuManager
private void onWidgetPressed(WidgetPressed event) private void onWidgetPressed(WidgetPressed event)
{ {
leftClickEntry = rebuildLeftClickMenu(); rebuildLeftClickMenu();
client.setTempMenuEntry(leftClickEntry);
} }
private void onMenuOptionClicked(MenuOptionClicked event) 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) if (leftClickEntry != null)
@@ -879,7 +878,7 @@ public class MenuManager
entries[menuOptionCount + i] = prios[i].entry; 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[i] = first;
entries[menuOptionCount - 1] = entry; entries[menuOptionCount - 1] = entry;
firstEntry = entry; leftClickEntry = entry;
return; return;
} }
} }
@@ -25,10 +25,14 @@
package net.runelite.mixins; package net.runelite.mixins;
import net.runelite.api.MenuEntry; 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.Inject;
import net.runelite.api.mixins.Mixin; import net.runelite.api.mixins.Mixin;
import net.runelite.api.mixins.Shadow;
import net.runelite.rs.api.RSClient; import net.runelite.rs.api.RSClient;
import net.runelite.rs.api.RSFont; import net.runelite.rs.api.RSFont;
import net.runelite.rs.api.RSMenuAction;
@Mixin(RSClient.class) @Mixin(RSClient.class)
public abstract class MenuMixin implements RSClient 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_TOP_2010 = 0x322E22;
private static final int MENU_HEADER_GRADIENT_BOTTOM_2010 = 0x090A04; private static final int MENU_HEADER_GRADIENT_BOTTOM_2010 = 0x090A04;
@Shadow("client")
private static RSClient client;
@Shadow("tempMenuAction")
private static RSMenuAction tempMenuAction;
@Inject @Inject
@Override @Override
public void draw2010Menu() public void draw2010Menu()
@@ -140,4 +150,28 @@ public abstract class MenuMixin implements RSClient
getMenuArguments2()[i] = entry.getParam1(); getMenuArguments2()[i] = entry.getParam1();
getMenuForceLeftClick()[i] = entry.isForceLeftClick(); 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.VarbitChanged;
import net.runelite.api.events.VolumeChanged; import net.runelite.api.events.VolumeChanged;
import net.runelite.api.events.WidgetLoaded; import net.runelite.api.events.WidgetLoaded;
import net.runelite.api.events.WidgetPressed;
import net.runelite.api.hooks.Callbacks; import net.runelite.api.hooks.Callbacks;
import net.runelite.api.hooks.DrawCallbacks; import net.runelite.api.hooks.DrawCallbacks;
import net.runelite.api.mixins.Copy; 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); 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") @FieldHook("Login_username")
@Inject @Inject
public static void onUsernameChanged(int idx) public static void onUsernameChanged(int idx)
@@ -25,7 +25,6 @@
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * 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. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
package net.runelite.rs.api; package net.runelite.rs.api;
import java.math.BigInteger; import java.math.BigInteger;
@@ -398,9 +397,6 @@ public interface RSClient extends RSGameShell, Client
@Import("menuAction") @Import("menuAction")
void sendMenuAction(int n2, int n3, int n4, int n5, String string, String string2, int n6, int n7); void sendMenuAction(int n2, int n3, int n4, int n5, String string, String string2, int n6, int n7);
@Import("tempMenuAction")
RSMenuAction getTempMenuAction();
@Import("SpriteBuffer_decode") @Import("SpriteBuffer_decode")
void decodeSprite(byte[] data); void decodeSprite(byte[] data);
@@ -24,6 +24,22 @@
*/ */
package net.runelite.rs.api; package net.runelite.rs.api;
import net.runelite.mapping.Import;
public interface RSMenuAction 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) { static void method325(int var0, int var1) {
MenuAction var2 = StudioGame.tempMenuAction; 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; StudioGame.tempMenuAction = null;
} }
@@ -17,8 +17,8 @@ public class MenuAction {
@ObfuscatedGetter( @ObfuscatedGetter(
intValue = -1613868885 intValue = -1613868885
) )
@Export("argument1") @Export("param0")
int argument1; int param0;
@ObfuscatedName("t") @ObfuscatedName("t")
@Export("action") @Export("action")
String action; String action;
@@ -26,8 +26,8 @@ public class MenuAction {
@ObfuscatedGetter( @ObfuscatedGetter(
intValue = -872703787 intValue = -872703787
) )
@Export("argument2") @Export("param1")
int argument2; int param1;
@ObfuscatedName("q") @ObfuscatedName("q")
@ObfuscatedGetter( @ObfuscatedGetter(
intValue = 553279575 intValue = 553279575
@@ -38,8 +38,8 @@ public class MenuAction {
@ObfuscatedGetter( @ObfuscatedGetter(
intValue = -1804422619 intValue = -1804422619
) )
@Export("argument0") @Export("identifier")
int argument0; int identifier;
MenuAction() { MenuAction() {
} }
+3 -3
View File
@@ -203,10 +203,10 @@ public class Script extends DualNode {
) )
static void method2384(int var0) { static void method2384(int var0) {
StudioGame.tempMenuAction = new MenuAction(); StudioGame.tempMenuAction = new MenuAction();
StudioGame.tempMenuAction.argument1 = Client.menuArguments1[var0]; StudioGame.tempMenuAction.param0 = Client.menuArguments1[var0];
StudioGame.tempMenuAction.argument2 = Client.menuArguments2[var0]; StudioGame.tempMenuAction.param1 = Client.menuArguments2[var0];
StudioGame.tempMenuAction.opcode = Client.menuOpcodes[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]; StudioGame.tempMenuAction.action = Client.menuActions[var0];
} }
} }