Skip to content

Commit

Permalink
Merge pull request #208 from charles-m-knox/shift-click-modifiers
Browse files Browse the repository at this point in the history
Add shift+click to drop
  • Loading branch information
Promises authored Sep 7, 2024
2 parents 1019ad9 + adf5386 commit df3181b
Show file tree
Hide file tree
Showing 6 changed files with 141 additions and 25 deletions.
1 change: 1 addition & 0 deletions config/client-435.conf.example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ game:
roofsEnabled: true
freeTeleports: false
debugContextMenu: true
shiftClickModifier: true
serverDisplayName: Build 435
11 changes: 10 additions & 1 deletion src/main/java/org/runejs/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public static void read() {
USERNAME = (String) login.get("username");
PASSWORD = (String) login.get("password");
ROOFS_ENABLED = (boolean) game.get("roofsEnabled");
SHIFT_CLICK_MODIFIER = (boolean) game.get("shiftClickModifier");
SOUND_MUTED = (boolean) game.get("soundMuted");
FREE_TELEPORTS = (boolean) game.get("freeTeleports");
DEBUG_CONTEXT = (boolean) game.get("debugContextMenu");
Expand All @@ -51,7 +52,7 @@ public static void read() {
if (PASSWORD == null) {
PASSWORD = "";
}

if (SERVER_DISPLAY_NAME == null) {
SERVER_DISPLAY_NAME = "Build 435";
}
Expand All @@ -78,6 +79,7 @@ public static void read() {

Map<String, Object> game = new HashMap<String, Object>();
game.put("roofsEnabled", ROOFS_ENABLED);
game.put("shiftClickModifier", SHIFT_CLICK_MODIFIER);
game.put("freeTeleports", FREE_TELEPORTS);
game.put("debugContextMenu", DEBUG_CONTEXT);
game.put("soundMuted", SOUND_MUTED);
Expand Down Expand Up @@ -172,6 +174,13 @@ public static void read() {
*/
public static boolean ROOFS_ENABLED = true;

/**
* If true, the shift key will cause the second-highest menu item to be
* shown instead of the first, and if there is a "Drop" value present, it
* will be prioritized.
*/
public static boolean SHIFT_CLICK_MODIFIER = true;

/**
* Always light up teleports
*/
Expand Down
20 changes: 19 additions & 1 deletion src/main/java/org/runejs/client/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,14 @@ public class Game {
public static int playerRights = 0;
public static Timer gameTimer;
public static int idleLogout = 0;

/**
* If the shift key has been pressed, this reflects the state, but only
* `Game.isShiftModifierActive()` should be used for confirming that the key
* is pressed as well as checking that player's client's configuration
* allows shift modifiers to be leveraged.
*/
public static boolean shiftPressed = false;
/**
* Backup port if the first one fails?
*/
Expand Down Expand Up @@ -990,7 +998,7 @@ public static void drawGameScreen() {
ChatBox.redrawChatbox = true;
}
}

if(flashingTabId != -1) {
GameInterface.drawTabIcons = true;
}
Expand Down Expand Up @@ -2058,4 +2066,14 @@ public void startup() {
MovedStatics.showFps = true;
chatboxInterface = new GameInterface();
}

/**
* Checks if the shift modifiers are enabled and active.
*
* @return true if the player is currently pressing the shift key and if
* player has configured their client to accept shift modifiers.
*/
public static boolean isShiftModifierActive() {
return Game.shiftPressed == true && Configuration.SHIFT_CLICK_MODIFIER;
}
}
114 changes: 95 additions & 19 deletions src/main/java/org/runejs/client/MovedStatics.java
Original file line number Diff line number Diff line change
Expand Up @@ -660,17 +660,30 @@ else if (lightness > 126)
return (0xff80 & hsl) + lightness;
}

public static void method1013() {
/**
* The menu items for interacting with NPC's/objects/tiles are compiled
* here.
*/
public static void buildRightClickMenu() {
int lasthash = -1;
if (GameInterface.itemCurrentlySelected == 0 && Game.widgetSelected == 0) {
String tileCoords = "";

int actionTeleportId = ActionRowType.TELEPORT_HERE.getId();
int actionWalkId = ActionRowType.WALK_HERE.getId();

if (Game.isShiftModifierActive()) {
actionWalkId += ActionRowType.LOW_PRIORITY_MODIFIER;
}

if (Configuration.DEBUG_CONTEXT) {
tileCoords = MessageFormat.format("<col=8F8FFF>({0}, {1})</col>", Integer.toString(Game.currentScene.hoveredTileX + baseX), Integer.toString(Game.currentScene.hoveredTileY + baseY));
if (Game.playerRights >= 2) {
addActionRow(English.teleportHere, 0, (Game.currentScene.hoveredTileX + baseX), (Game.currentScene.hoveredTileY + baseY), ActionRowType.TELEPORT_HERE.getId(), tileCoords);
addActionRow(English.teleportHere, 0, (Game.currentScene.hoveredTileX + baseX), (Game.currentScene.hoveredTileY + baseY), actionTeleportId, tileCoords);
}
}
addActionRow(English.walkHere, 0, MouseHandler.mouseX, MouseHandler.mouseY, ActionRowType.WALK_HERE.getId(), tileCoords);

addActionRow(English.walkHere, 0, MouseHandler.mouseX, MouseHandler.mouseY, actionWalkId, tileCoords);
}

for (int idx = 0; Model.resourceCount > idx; idx++) {
Expand Down Expand Up @@ -2127,17 +2140,32 @@ public static String getCombatLevelColour(int arg0, int arg1) {

public static void drawMenuTooltip(int arg0) {
if (menuActionRow >= 2 || GameInterface.itemCurrentlySelected != 0 || Game.widgetSelected != 0) {
String class1;
String tooltipText;
if (GameInterface.itemCurrentlySelected == 1 && menuActionRow < 2)
class1 = English.use + Native.whitespace + Native.selectedItemName + Native.targetThingArrow;
else if (Game.widgetSelected != 1 || menuActionRow >= 2)
class1 = menuActionTexts[-1 + menuActionRow];
tooltipText = English.use + Native.whitespace + Native.selectedItemName + Native.targetThingArrow;
else if (Game.widgetSelected != 1 || menuActionRow >= 2) {
// if shift is pressed, use the next item in the list instead of
// the first, or "Drop" if it's available
if (Game.isShiftModifierActive() && menuActionRow >= 2) {
int i = -1 + menuActionRow - 1; // second item in the list
// first, attempt to find Drop in the list
for (int j = 0; j < menuActionRow; j++) {
if (menuActionTypes[j] == ActionRowType.DROP_ITEM.getId()) {
i = j;
break;
}
}
tooltipText = menuActionTexts[i];
} else {
tooltipText = menuActionTexts[-1 + menuActionRow];
}
}
else
class1 = Native.selectedSpellVerb + Native.whitespace + Native.selectedSpellName + Native.targetThingArrow;
tooltipText = Native.selectedSpellVerb + Native.whitespace + Native.selectedSpellName + Native.targetThingArrow;
if (menuActionRow > 2)
class1 = class1 + Native.whiteSlash + (menuActionRow + -2) + English.suffixMoreOptions;
tooltipText = tooltipText + Native.whiteSlash + (menuActionRow + -2) + English.suffixMoreOptions;
if (arg0 == 4)
TypeFace.fontBold.drawShadowedSeededAlphaString(class1, 4, 15, 16777215, true, pulseCycle / 1000);
TypeFace.fontBold.drawShadowedSeededAlphaString(tooltipText, 4, 15, 16777215, true, pulseCycle / 1000);
}
}

Expand Down Expand Up @@ -2239,7 +2267,7 @@ public static void processRightClick() {
// Right game screen
if(ScreenController.isCoordinatesIn3dScreen(MouseHandler.mouseX , MouseHandler.mouseY )) {
if(GameInterface.gameScreenInterfaceId == -1) {
method1013();
buildRightClickMenu();
} else {
int yOffset = (ScreenController.drawHeight /2) - (334/2) - (184/2);
int xOffset = (ScreenController.drawWidth /2) - (512/2) - (234/3);
Expand Down Expand Up @@ -3010,8 +3038,8 @@ public static void processMenuClick() {
int meta = MouseHandler.clickType;
if(Game.widgetSelected == 1 && MouseHandler.clickX >= 516 && MouseHandler.clickY >= 160 && MouseHandler.clickX <= 765 && MouseHandler.clickY <= 205)
meta = 0;
if(menuOpen) {
if(meta != 1) {
if(menuOpen || Game.isShiftModifierActive()) {
if(meta != 1 && !Game.isShiftModifierActive()) {
int x = MouseHandler.mouseX;
int y = MouseHandler.mouseY;
if(menuScreenArea == 0) {
Expand Down Expand Up @@ -3052,23 +3080,66 @@ public static void processMenuClick() {
x -= 17;
y -= 357;
}

int id = -1;
// attempt to find "Drop" in the list of available actions
// if shift is pressed
int dropActionId = ActionRowType.DROP_ITEM.getId();
int indexOfDropIdInMenu = -1;

// if the shift modifier is pressed, and there are two or more
// options in the menu, use the second menu item instead of the
// first. Don't worry - we'll try to find Drop next.
if (Game.isShiftModifierActive() && menuActionRow >= 2) {
id = menuActionRow - 2;
}

for(int row = 0; row < menuActionRow; row++) {
int k3 = 31 + menuY + 15 * (menuActionRow + -1 - row);
if(x > menuX && x < dx + menuX && y > -13 + k3 && y < 3 + k3)
// if the user is pressing shift, and there is a Drop option
// present, use it.
if (Game.isShiftModifierActive() && menuActionTypes[row] == dropActionId) {
indexOfDropIdInMenu = row;
id = row;
} else {
// if not, assume the user has the menu open, and
// calculate which menu item where they're clicking on.
int k3 = 31 + menuY + 15 * (menuActionRow + -1 - row);
if(x > menuX && x < dx + menuX && y > -13 + k3 && y < 3 + k3)
id = row;
}
}

// at this point, either the "drop" or second menu item has been
// selected as the action item to use if the user is pressing
// the shift key. If the user isn't pressing the shift key,
// then the menu is presumed to be open instead, and the menu
// option that they're hovering over gets executed.
if(id != -1) {
if (Game.isShiftModifierActive()) {
if (indexOfDropIdInMenu != -1) {
GameInterface.processMenuActions(indexOfDropIdInMenu);
} else {
GameInterface.processMenuActions(menuActionRow - 2);
}
} else {
GameInterface.processMenuActions(id);
}
}
if(id != -1)
GameInterface.processMenuActions(id);

if(menuScreenArea == 1)
GameInterface.redrawTabArea = true;

menuOpen = false;

if(menuScreenArea == 2)
ChatBox.redrawChatbox = true;
}
} else {
if(meta == 1 && menuActionRow > 0) {
int action = menuActionTypes[menuActionRow - 1];
if (Game.isShiftModifierActive() && menuActionRow >= 2) {
action = menuActionTypes[menuActionRow - 2];
}
if(
action == ActionRowType.INTERACT_WITH_ITEM_ON_V1_WIDGET_OPTION_1.getId()
|| action == ActionRowType.INTERACT_WITH_ITEM_ON_V1_WIDGET_OPTION_2.getId()
Expand Down Expand Up @@ -3104,8 +3175,13 @@ public static void processMenuClick() {
}
if(meta == 1 && (Game.oneMouseButton == 1 || menuHasAddFriend(-1 + menuActionRow)) && menuActionRow > 2)
meta = 2;
if(meta == 1 && menuActionRow > 0)
GameInterface.processMenuActions(menuActionRow - 1);
if(meta == 1 && menuActionRow > 0) {
if (Game.isShiftModifierActive() && menuActionRow >= 2) {
GameInterface.processMenuActions(menuActionRow - 2);
} else {
GameInterface.processMenuActions(menuActionRow - 1);
}
}
if(meta == 2 && menuActionRow > 0)
determineMenuSize();
}
Expand Down
12 changes: 8 additions & 4 deletions src/main/java/org/runejs/client/frame/ScreenController.java
Original file line number Diff line number Diff line change
Expand Up @@ -386,9 +386,13 @@ public static void handleMinimapMouse() {
int destX = Player.localPlayer.worldX + i_14_ >> 7;
int destY = -i_15_ + Player.localPlayer.worldY >> 7;

// if the player is a mod or admin, and the shift key is pressed,
// this will send a console command to the server to teleport the
// player. This predates the shift key modifiers
// added on 2024-09-04.
if (MovedStatics.obfuscatedKeyStatus[81] && Game.playerRights > 1) {
OutgoingPackets.buffer.putPacket(246);
OutgoingPackets.buffer.putString(MessageFormat.format(" move {0} {1}", Integer.toString(destX + MovedStatics.baseX), Integer.toString(destY + MovedStatics.baseY)));
OutgoingPackets.buffer.putString(MessageFormat.format("{0} {1} {2}", "move", Integer.toString(destX + MovedStatics.baseX), Integer.toString(destY + MovedStatics.baseY)));
} else {
Pathfinding.MinimapWalkAnalytics analytics = new Pathfinding.MinimapWalkAnalytics(
minimapClickX,
Expand All @@ -405,9 +409,9 @@ public static void handleMinimapMouse() {
);

Pathfinding.doMinimapWalkTo(
Player.localPlayer.pathY[0],
Player.localPlayer.pathX[0],
destX,
Player.localPlayer.pathY[0],
Player.localPlayer.pathX[0],
destX,
destY,
analytics
);
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/org/runejs/client/input/KeyFocusListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ public synchronized void keyPressed(KeyEvent keyEvent) {
} else {
keyChar = getKeyChar(keyEvent);
}
if (eventKeyCode == KeyEvent.VK_SHIFT) {
Game.shiftPressed = true;
}
if (eventKeyCode == 192 || eventKeyCode == 129) {
Console.console.consoleOpen = !Console.console.consoleOpen;
}
Expand Down Expand Up @@ -159,11 +162,16 @@ public synchronized void keyReleased(KeyEvent arg0) {
framesSinceKeyboardInput = 0;
int i = arg0.getKeyCode();

if (i == KeyEvent.VK_SHIFT) {
Game.shiftPressed = false;
}

if (i < 0 || OBFUSCATED_KEY_CODES.length <= i) {
i = -1;
} else {
i = ~0x80 & OBFUSCATED_KEY_CODES[i];
}

if (anInt2543 >= 0 && i >= 0) {
MovedStatics.keyCodes[anInt2543] = i ^ 0xffffffff;
anInt2543 = 0x7f & 1 + anInt2543;
Expand Down

0 comments on commit df3181b

Please sign in to comment.