Skip to content

Commit

Permalink
Reimplement menu-related QOL.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ceikry committed Sep 25, 2022
1 parent 4377d49 commit 2f750e1
Show file tree
Hide file tree
Showing 9 changed files with 531 additions and 201 deletions.
7 changes: 7 additions & 0 deletions client/src/main/java/plugin/Plugin.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package plugin;

import plugin.api.MiniMenuEntry;
import rt4.Component;
import rt4.Npc;
import rt4.Player;
Expand Down Expand Up @@ -88,4 +89,10 @@ public void OnVarpUpdate(int id, int value) {}
* OnLogout is called when the client logs out. This should be used to clear player-relevant plugin state.
*/
public void OnLogout() {}

/**
* DrawMiniMenu is called when a MiniMenu entry has been created.
* @param entry the entry
*/
public void DrawMiniMenu(MiniMenuEntry entry) {}
}
6 changes: 6 additions & 0 deletions client/src/main/java/plugin/PluginRepository.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package plugin;

import plugin.api.MiniMenuEntry;
import plugin.api.MiniMenuType;
import rt4.*;

import java.io.File;
Expand Down Expand Up @@ -128,4 +130,8 @@ public static void OnXPUpdate(int skill, int xp) {
public static void OnLogout() {
loadedPlugins.values().forEach(Plugin::OnLogout);
}

public static void DrawMiniMenu(MiniMenuEntry entry) {
loadedPlugins.values().forEach((plugin) -> plugin.DrawMiniMenu(entry));
}
}
10 changes: 10 additions & 0 deletions client/src/main/java/plugin/api/API.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import java.awt.*;
import java.awt.event.*;
import java.util.ArrayList;

import static rt4.MathUtils.clamp;

Expand Down Expand Up @@ -195,4 +196,13 @@ public static int GetMouseY() {
public static boolean IsKeyPressed(int keycode) {
return Keyboard.pressedKeys[keycode];
}

public static MiniMenuEntry[] GetMiniMenuEntries() {
ArrayList<MiniMenuEntry> entries = new ArrayList<>();
for (int i = 0; i < MiniMenu.size; i++) {
if (MiniMenu.opBases[i] == null) continue;
entries.add(new MiniMenuEntry(i));
}
return entries.toArray(new MiniMenuEntry[]{});
}
}
51 changes: 51 additions & 0 deletions client/src/main/java/plugin/api/MiniMenuAction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package plugin.api;

import java.util.HashMap;

public enum MiniMenuAction {
WALK_HERE(60),
NPC_1(17),
NPC_2(16),
NPC_3(4),
NPC_4(19),
NPC_5(2),
NPC_EXAMINE(1007),
PLAYER_1(30),
PLAYER_BLOCK(34),
PLAYER_TRADE(29),
PLAYER_REQ_ASSIST(37),
PLAYER_FOLLOW(31),
PLAYER_5(57),
OBJ_1(47),
OBJ_EQUIP(5),
OBJ_4(35),
OBJ_OPERATE(23),
OBJ_5(58),
OBJ_EXAMINE(1002),
OBJSTACK_1(18),
OBJSTACK_2(20),
LOC_1(42),
LOC_2(50),
LOC_3(49),
LOC_4(46),
LOC_5(1001),
LOC_EXAMINE(1004)
;

public final short actionCode;
public static HashMap<Integer, MiniMenuAction> actionCodeMap = new HashMap<>();

MiniMenuAction(int actionCode) {
this.actionCode = (short) actionCode;
}

static {
for (MiniMenuAction a : values()) {
actionCodeMap.put((int) a.actionCode, a);
}
}

public static MiniMenuAction forActionCode(short actionCode) {
return actionCodeMap.get((int) actionCode);
}
}
81 changes: 81 additions & 0 deletions client/src/main/java/plugin/api/MiniMenuEntry.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package plugin.api;

import rt4.JagString;
import rt4.MiniMenu;

/**
* Convenience wrapper for mini menu entries
* @author ceikry
*/
public class MiniMenuEntry {
int index;
public MiniMenuEntry(int index) {
this.index = index;
}

public String getSubject() {
return MiniMenu.opBases[index].toString();
}

public void setSubject(String name) {
MiniMenu.opBases[index] = JagString.of(name);
}

public long getSubjectIndex() {
return MiniMenu.keys[index];
}

public MiniMenuType getType() {
if (getSubject().length() < 11) return MiniMenuType.TILE;

String color = getSubject().substring(5,11);
if (color.equals("00ffff")) return MiniMenuType.LOCATION;
if (color.equals("ffff00")) return MiniMenuType.NPC;
if (color.equals("ffffff")) return MiniMenuType.PLAYER;
if (color.equals("ff9040")) return MiniMenuType.OBJ;
else return MiniMenuType.TILE;
}

public String getVerb() {
return MiniMenu.ops[index].toString();
}

public void setVerb(String verb) {
MiniMenu.ops[index] = JagString.of(verb);
}

public int getIntArg1() {
return MiniMenu.intArgs1[index];
}

public int getIntArg2() {
return MiniMenu.intArgs2[index];
}

public int getCursor() {
return MiniMenu.cursors[index];
}

public MiniMenuAction getAction() {
int actionCode = MiniMenu.actions[index];
if (isStrictlySecondary()) actionCode -= 2000;
return MiniMenuAction.forActionCode((short) actionCode);
}

public short getActionCode() {
return MiniMenu.actions[index];
}

public void setAction(MiniMenuAction action) {
MiniMenu.actions[index] = action.actionCode;
}

public void toggleStrictlySecondary() {
if (isStrictlySecondary()) MiniMenu.actions[index] -= 2000;
else MiniMenu.actions[index] += 2000;
}

public boolean isStrictlySecondary() {
return MiniMenu.actions[index] >= 2000;
}
}
10 changes: 10 additions & 0 deletions client/src/main/java/plugin/api/MiniMenuType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package plugin.api;

public enum MiniMenuType {
NPC,
PLAYER,
LOCATION,
TILE,
OBJ,
OBJSTACK
}
138 changes: 2 additions & 136 deletions client/src/main/java/rt4/LoginManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -1448,9 +1448,9 @@ public static void method1841() {
MiniMenu.sort();
if (Cs1ScriptRunner.aBoolean108) {
if (InterfaceList.aBoolean298) {
method2297();
MiniMenu.drawB();
} else {
method2744();
MiniMenu.drawA();
}
} else if (aClass13_13 != null) {
MiniMenu.method1207(aClass13_13, Cs1ScriptRunner.anInt3484, Cs1ScriptRunner.anInt3260);
Expand Down Expand Up @@ -1494,140 +1494,6 @@ public static int method4044() {
return Cheat.shiftClick && Keyboard.pressedKeys[Keyboard.KEY_SHIFT] && MiniMenu.size > 2 ? MiniMenu.cursors[MiniMenu.size - 2] : MiniMenu.cursors[MiniMenu.size - 1];
}

@OriginalMember(owner = "client!ij", name = "a", descriptor = "(B)V")
public static void method2297() {
@Pc(3) int local3 = InterfaceList.anInt4271;
@Pc(9) int local9 = InterfaceList.anInt5138;
@Pc(11) int local11 = InterfaceList.anInt436;
@Pc(13) int local13 = InterfaceList.anInt761;
if (aClass3_Sub2_Sub1_1 == null || aClass3_Sub2_Sub1_9 == null) {
if (client.js5Archive8.isFileReady(anInt1736) && client.js5Archive8.isFileReady(anInt4073)) {
aClass3_Sub2_Sub1_1 = SoftwareSprite.loadSoftwareAlphaSprite(client.js5Archive8, anInt1736);
aClass3_Sub2_Sub1_9 = SoftwareSprite.loadSoftwareAlphaSprite(client.js5Archive8, anInt4073);
if (GlRenderer.enabled) {
if (aClass3_Sub2_Sub1_1 instanceof SoftwareAlphaSprite) {
aClass3_Sub2_Sub1_1 = new GlAlphaSprite((SoftwareSprite) aClass3_Sub2_Sub1_1);
} else {
aClass3_Sub2_Sub1_1 = new GlSprite((SoftwareSprite) aClass3_Sub2_Sub1_1);
}
if (aClass3_Sub2_Sub1_9 instanceof SoftwareAlphaSprite) {
aClass3_Sub2_Sub1_9 = new GlAlphaSprite((SoftwareSprite) aClass3_Sub2_Sub1_9);
} else {
aClass3_Sub2_Sub1_9 = new GlSprite((SoftwareSprite) aClass3_Sub2_Sub1_9);
}
}
} else if (GlRenderer.enabled) {
GlRaster.fillRectAlpha(local3, local9, local13, 20, anInt1275, 256 - anInt2910);
} else {
SoftwareRaster.fillRectAlpha(local3, local9, local13, 20, anInt1275, 256 - anInt2910);
}
}
@Pc(112) int local112;
@Pc(114) int local114;
if (aClass3_Sub2_Sub1_1 != null && aClass3_Sub2_Sub1_9 != null) {
local112 = local13 / aClass3_Sub2_Sub1_1.width;
for (local114 = 0; local114 < local112; local114++) {
aClass3_Sub2_Sub1_1.render(local114 * aClass3_Sub2_Sub1_1.width + local3, local9);
}
aClass3_Sub2_Sub1_9.render(local3, local9);
aClass3_Sub2_Sub1_9.renderHorizontalFlip(local3 + local13 - aClass3_Sub2_Sub1_9.width, local9);
}
Fonts.b12Full.renderLeft(LocalizedText.CHOOSE_OPTION, local3 + 3, local9 + 14, anInt4581, -1);
if (GlRenderer.enabled) {
GlRaster.fillRectAlpha(local3, local9 + 20, local13, local11 - 20, anInt1275, 256 - anInt2910);
} else {
SoftwareRaster.fillRectAlpha(local3, local9 + 20, local13, local11 - 20, anInt1275, 256 - anInt2910);
}
local114 = Mouse.lastMouseY;
local112 = Mouse.lastMouseX;
@Pc(203) int local203;
@Pc(219) int local219;
for (local203 = 0; local203 < MiniMenu.size; local203++) {
local219 = (MiniMenu.size - local203 - 1) * 15 + local9 + 35;
if (local3 < local112 && local112 < local3 + local13 && local114 > local219 - 13 && local114 < local219 + 3) {
if (GlRenderer.enabled) {
GlRaster.fillRectAlpha(local3, local219 - 13, local13, 16, anInt5457, 256 - anInt5208);
} else {
SoftwareRaster.fillRectAlpha(local3, local219 - 13, local13, 16, anInt5457, 256 - anInt5208);
}
}
}
if ((aClass3_Sub2_Sub1_8 == null || aClass3_Sub2_Sub1_6 == null || aClass3_Sub2_Sub1_10 == null) && client.js5Archive8.isFileReady(anInt2261) && client.js5Archive8.isFileReady(anInt3324) && client.js5Archive8.isFileReady(anInt5556)) {
aClass3_Sub2_Sub1_8 = SoftwareSprite.loadSoftwareAlphaSprite(client.js5Archive8, anInt2261);
aClass3_Sub2_Sub1_6 = SoftwareSprite.loadSoftwareAlphaSprite(client.js5Archive8, anInt3324);
aClass3_Sub2_Sub1_10 = SoftwareSprite.loadSoftwareAlphaSprite(client.js5Archive8, anInt5556);
if (GlRenderer.enabled) {
if (aClass3_Sub2_Sub1_8 instanceof SoftwareAlphaSprite) {
aClass3_Sub2_Sub1_8 = new GlAlphaSprite((SoftwareSprite) aClass3_Sub2_Sub1_8);
} else {
aClass3_Sub2_Sub1_8 = new GlSprite((SoftwareSprite) aClass3_Sub2_Sub1_8);
}
if (aClass3_Sub2_Sub1_6 instanceof SoftwareAlphaSprite) {
aClass3_Sub2_Sub1_6 = new GlAlphaSprite((SoftwareSprite) aClass3_Sub2_Sub1_6);
} else {
aClass3_Sub2_Sub1_6 = new GlSprite((SoftwareSprite) aClass3_Sub2_Sub1_6);
}
if (aClass3_Sub2_Sub1_10 instanceof SoftwareAlphaSprite) {
aClass3_Sub2_Sub1_10 = new GlAlphaSprite((SoftwareSprite) aClass3_Sub2_Sub1_10);
} else {
aClass3_Sub2_Sub1_10 = new GlSprite((SoftwareSprite) aClass3_Sub2_Sub1_10);
}
}
}
@Pc(418) int local418;
if (aClass3_Sub2_Sub1_8 != null && aClass3_Sub2_Sub1_6 != null && aClass3_Sub2_Sub1_10 != null) {
local203 = local13 / aClass3_Sub2_Sub1_8.width;
for (local219 = 0; local219 < local203; local219++) {
aClass3_Sub2_Sub1_8.render(local3 + aClass3_Sub2_Sub1_8.width * local219, local11 + local9 + -aClass3_Sub2_Sub1_8.height);
}
local219 = (local11 - 20) / aClass3_Sub2_Sub1_6.height;
for (local418 = 0; local418 < local219; local418++) {
aClass3_Sub2_Sub1_6.render(local3, local9 + local418 * aClass3_Sub2_Sub1_6.height + 20);
aClass3_Sub2_Sub1_6.renderHorizontalFlip(local3 + local13 - aClass3_Sub2_Sub1_6.width, local9 + 20 + local418 * aClass3_Sub2_Sub1_6.height);
}
aClass3_Sub2_Sub1_10.render(local3, local11 + local9 - aClass3_Sub2_Sub1_10.height);
aClass3_Sub2_Sub1_10.renderHorizontalFlip(local3 + local13 - aClass3_Sub2_Sub1_10.width, local9 - -local11 + -aClass3_Sub2_Sub1_10.height);
}
for (local203 = 0; local203 < MiniMenu.size; local203++) {
local219 = (MiniMenu.size - local203 - 1) * 15 + local9 + 35;
local418 = anInt4581;
if (local3 < local112 && local13 + local3 > local112 && local219 - 13 < local114 && local114 < local219 + 3) {
local418 = anInt5752;
}
Fonts.b12Full.renderLeft(MiniMenu.getOp(local203), local3 + 3, local219, local418, 0);
}
InterfaceList.forceRedrawScreen(InterfaceList.anInt4271, InterfaceList.anInt5138, InterfaceList.anInt436, InterfaceList.anInt761);
}

@OriginalMember(owner = "client!lf", name = "b", descriptor = "(I)V")
public static void method2744() {
@Pc(3) int local3 = InterfaceList.anInt5138;
@Pc(9) int local9 = InterfaceList.anInt761;
@Pc(11) int local11 = InterfaceList.anInt4271;
@Pc(15) int local15 = InterfaceList.anInt436;
if (GlRenderer.enabled) {
GlRaster.fillRect(local11, local3, local9, local15, 6116423);
GlRaster.fillRect(local11 + 1, local3 + 1, local9 - 2, 16, 0);
GlRaster.drawRect(local11 + 1, local3 + 18, local9 - 2, local15 + -19, 0);
} else {
SoftwareRaster.fillRect(local11, local3, local9, local15, 6116423);
SoftwareRaster.fillRect(local11 + 1, local3 + 1, local9 - 2, 16, 0);
SoftwareRaster.drawRect(local11 + 1, local3 + 18, local9 - 2, local15 + -19, 0);
}
Fonts.b12Full.renderLeft(LocalizedText.CHOOSE_OPTION, local11 + 3, local3 + 14, 6116423, -1);
@Pc(96) int local96 = Mouse.lastMouseY;
@Pc(98) int local98 = Mouse.lastMouseX;
for (@Pc(107) int local107 = 0; local107 < MiniMenu.size; local107++) {
@Pc(127) int local127 = (MiniMenu.size - local107 - 1) * 15 + local3 + 31;
@Pc(129) int local129 = 16777215;
if (local11 < local98 && local98 < local11 + local9 && local127 - 13 < local96 && local96 < local127 + 3) {
local129 = 16776960;
}
Fonts.b12Full.renderLeft(MiniMenu.getOp(local107), local11 + 3, local127, local129, 0);
}
InterfaceList.forceRedrawScreen(InterfaceList.anInt4271, InterfaceList.anInt5138, InterfaceList.anInt436, InterfaceList.anInt761);
}

@OriginalMember(owner = "client!gn", name = "a", descriptor = "(ZI)V")
public static void method1805(@OriginalArg(0) boolean arg0) {
@Pc(7) byte local7;
Expand Down
Loading

0 comments on commit 2f750e1

Please sign in to comment.