From 8708788004d15cb87c0f334a7b4b9492de4c4792 Mon Sep 17 00:00:00 2001 From: Zach Waller Date: Mon, 27 Jan 2020 15:27:52 -0500 Subject: [PATCH] menu swapper: add bank deposit/withdraw shift click Co-authored-by: Adam --- .../MenuEntrySwapperConfig.java | 30 ++++++---- .../MenuEntrySwapperPlugin.java | 55 +++++++++++++------ .../menuentryswapper/ShiftDepositMode.java | 52 ++++++++++++++++++ .../menuentryswapper/ShiftWithdrawMode.java | 52 ++++++++++++++++++ .../MenuEntrySwapperPluginTest.java | 41 ++++++++++++-- 5 files changed, 198 insertions(+), 32 deletions(-) create mode 100644 runelite-client/src/main/java/net/runelite/client/plugins/menuentryswapper/ShiftDepositMode.java create mode 100644 runelite-client/src/main/java/net/runelite/client/plugins/menuentryswapper/ShiftWithdrawMode.java diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/menuentryswapper/MenuEntrySwapperConfig.java b/runelite-client/src/main/java/net/runelite/client/plugins/menuentryswapper/MenuEntrySwapperConfig.java index da98cfb9d4..15393366df 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/menuentryswapper/MenuEntrySwapperConfig.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/menuentryswapper/MenuEntrySwapperConfig.java @@ -382,16 +382,6 @@ public interface MenuEntrySwapperConfig extends Config return false; } - @ConfigItem( - keyName = "swapBankOp", - name = "Swap Bank Op", - description = "Swaps the extra menu option in banks (Wield, Eat, etc.) when holding shift" - ) - default boolean swapBankOp() - { - return false; - } - @ConfigItem( keyName = "swapNpcContact", name = "NPC Contact", @@ -401,4 +391,24 @@ public interface MenuEntrySwapperConfig extends Config { return false; } + + @ConfigItem( + keyName = "bankWithdrawShiftClick", + name = "Bank Withdraw Shift-Click", + description = "Swaps the behavior of shift-click when withdrawing from bank." + ) + default ShiftWithdrawMode bankWithdrawShiftClick() + { + return ShiftWithdrawMode.OFF; + } + + @ConfigItem( + keyName = "bankDepositShiftClick", + name = "Bank Deposit Shift-Click", + description = "Swaps the behavior of shift-click when depositing to bank." + ) + default ShiftDepositMode bankDepositShiftClick() + { + return ShiftDepositMode.OFF; + } } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/menuentryswapper/MenuEntrySwapperPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/menuentryswapper/MenuEntrySwapperPlugin.java index e5d3c227d9..3b3f225267 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/menuentryswapper/MenuEntrySwapperPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/menuentryswapper/MenuEntrySwapperPlugin.java @@ -307,30 +307,49 @@ public class MenuEntrySwapperPlugin extends Plugin // widget ticking and prior to our client tick event. This is because drag start // is what builds the context menu row which is what the eventual click will use + // Swap to shift-click deposit behavior // Deposit- op 2 is the current withdraw amount 1/5/10/x - if (shiftModifier && menuEntryAdded.getType() == MenuAction.CC_OP.getId() && menuEntryAdded.getIdentifier() == 2 - && config.swapBankOp() && menuEntryAdded.getOption().startsWith("Deposit-")) + if (shiftModifier && config.bankDepositShiftClick() != ShiftDepositMode.OFF + && menuEntryAdded.getType() == MenuAction.CC_OP.getId() && menuEntryAdded.getIdentifier() == 2 + && menuEntryAdded.getOption().startsWith("Deposit-")) { - MenuEntry[] menuEntries = client.getMenuEntries(); + ShiftDepositMode shiftDepositMode = config.bankDepositShiftClick(); + final int actionId = shiftDepositMode.getMenuAction().getId(); + final int opId = shiftDepositMode.getIdentifier(); + bankModeSwap(actionId, opId); + } - // Find the extra menu option; they don't have fixed names, so check - // based on the menu identifier - for (int i = menuEntries.length - 1; i >= 0; --i) + // Swap to shift-click withdraw behavior + // Deposit- op 1 is the current withdraw amount 1/5/10/x + if (shiftModifier && config.bankWithdrawShiftClick() != ShiftWithdrawMode.OFF + && menuEntryAdded.getType() == MenuAction.CC_OP.getId() && menuEntryAdded.getIdentifier() == 1 + && menuEntryAdded.getOption().startsWith("Withdraw-")) + { + ShiftWithdrawMode shiftWithdrawMode = config.bankWithdrawShiftClick(); + final int actionId = shiftWithdrawMode.getMenuAction().getId(); + final int opId = shiftWithdrawMode.getIdentifier(); + bankModeSwap(actionId, opId); + } + } + + private void bankModeSwap(int entryTypeId, int entryIdentifier) + { + MenuEntry[] menuEntries = client.getMenuEntries(); + + for (int i = menuEntries.length - 1; i >= 0; --i) + { + MenuEntry entry = menuEntries[i]; + + if (entry.getType() == entryTypeId && entry.getIdentifier() == entryIdentifier) { - MenuEntry entry = menuEntries[i]; + // Raise the priority of the op so it doesn't get sorted later + entry.setType(MenuAction.CC_OP.getId()); - // The extra options are always option 9 - if (entry.getType() == MenuAction.CC_OP_LOW_PRIORITY.getId() && entry.getIdentifier() == 9) - { - // we must also raise the priority of the op so it doesn't get sorted later - entry.setType(MenuAction.CC_OP.getId()); + menuEntries[i] = menuEntries[menuEntries.length - 1]; + menuEntries[menuEntries.length - 1] = entry; - menuEntries[i] = menuEntries[menuEntries.length - 1]; - menuEntries[menuEntries.length - 1] = entry; - - client.setMenuEntries(menuEntries); - break; - } + client.setMenuEntries(menuEntries); + break; } } } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/menuentryswapper/ShiftDepositMode.java b/runelite-client/src/main/java/net/runelite/client/plugins/menuentryswapper/ShiftDepositMode.java new file mode 100644 index 0000000000..da490eb6a6 --- /dev/null +++ b/runelite-client/src/main/java/net/runelite/client/plugins/menuentryswapper/ShiftDepositMode.java @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2020, Zach + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 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. + */ +package net.runelite.client.plugins.menuentryswapper; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import net.runelite.api.MenuAction; + +@Getter +@RequiredArgsConstructor +public enum ShiftDepositMode +{ + DEPOSIT_1("Deposit-1", MenuAction.CC_OP, 3), + DEPOSIT_5("Deposit-5", MenuAction.CC_OP, 4), + DEPOSIT_10("Deposit-10", MenuAction.CC_OP, 5), + DEPOSIT_X("Deposit-X", MenuAction.CC_OP_LOW_PRIORITY, 6), + DEPOSIT_ALL("Deposit-All", MenuAction.CC_OP_LOW_PRIORITY, 8), + EXTRA_OP("Eat/Wield/Etc.", MenuAction.CC_OP_LOW_PRIORITY, 9), + OFF("Off", MenuAction.UNKNOWN, 0); + + private final String name; + private final MenuAction menuAction; + private final int identifier; + + @Override + public String toString() + { + return name; + } +} diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/menuentryswapper/ShiftWithdrawMode.java b/runelite-client/src/main/java/net/runelite/client/plugins/menuentryswapper/ShiftWithdrawMode.java new file mode 100644 index 0000000000..30260d8fd6 --- /dev/null +++ b/runelite-client/src/main/java/net/runelite/client/plugins/menuentryswapper/ShiftWithdrawMode.java @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2020, Zach + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 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. + */ +package net.runelite.client.plugins.menuentryswapper; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import net.runelite.api.MenuAction; + +@Getter +@RequiredArgsConstructor +public enum ShiftWithdrawMode +{ + WITHDRAW_1("Withdraw-1", MenuAction.CC_OP, 2), + WITHDRAW_5("Withdraw-5", MenuAction.CC_OP, 3), + WITHDRAW_10("Withdraw-10", MenuAction.CC_OP, 4), + WITHDRAW_X("Withdraw-X", MenuAction.CC_OP, 5), + WITHDRAW_ALL("Withdraw-All", MenuAction.CC_OP_LOW_PRIORITY, 7), + WITHDRAW_ALL_BUT_1("Withdraw-All-But-1", MenuAction.CC_OP_LOW_PRIORITY, 8), + OFF("Off", MenuAction.UNKNOWN, 0); + + private final String name; + private final MenuAction menuAction; + private final int identifier; + + @Override + public String toString() + { + return name; + } +} diff --git a/runelite-client/src/test/java/net/runelite/client/plugins/menuentryswapper/MenuEntrySwapperPluginTest.java b/runelite-client/src/test/java/net/runelite/client/plugins/menuentryswapper/MenuEntrySwapperPluginTest.java index 8aedec91cd..da2e028af6 100644 --- a/runelite-client/src/test/java/net/runelite/client/plugins/menuentryswapper/MenuEntrySwapperPluginTest.java +++ b/runelite-client/src/test/java/net/runelite/client/plugins/menuentryswapper/MenuEntrySwapperPluginTest.java @@ -303,14 +303,14 @@ public class MenuEntrySwapperPluginTest } @Test - public void testBankExtraOp() + public void testShiftWithdraw() { - when(config.swapBankOp()).thenReturn(true); + when(config.bankDepositShiftClick()).thenReturn(ShiftDepositMode.EXTRA_OP); menuEntrySwapperPlugin.setShiftModifier(true); entries = new MenuEntry[]{ menu("Cancel", "", MenuAction.CANCEL), - menu("Weild", "Abyssal whip", MenuAction.CC_OP_LOW_PRIORITY, 9), + menu("Wield", "Abyssal whip", MenuAction.CC_OP_LOW_PRIORITY, 9), menu("Deposit-1", "Abyssal whip", MenuAction.CC_OP, 2), }; @@ -329,7 +329,40 @@ public class MenuEntrySwapperPluginTest assertArrayEquals(new MenuEntry[]{ menu("Cancel", "", MenuAction.CANCEL), menu("Deposit-1", "Abyssal whip", MenuAction.CC_OP, 2), - menu("Weild", "Abyssal whip", MenuAction.CC_OP, 9), + menu("Wield", "Abyssal whip", MenuAction.CC_OP, 9), + }, argumentCaptor.getValue()); + } + + @Test + public void testShiftDeposit() + { + when(config.bankDepositShiftClick()).thenReturn(ShiftDepositMode.DEPOSIT_ALL); + menuEntrySwapperPlugin.setShiftModifier(true); + + entries = new MenuEntry[]{ + menu("Cancel", "", MenuAction.CANCEL), + menu("Wield", "Rune arrow", MenuAction.CC_OP_LOW_PRIORITY, 9), + menu("Deposit-All", "Rune arrow", MenuAction.CC_OP_LOW_PRIORITY, 8), + menu("Deposit-1", "Rune arrow", MenuAction.CC_OP, 2), + }; + + menuEntrySwapperPlugin.onMenuEntryAdded(new MenuEntryAdded( + "Deposit-1", + "Rune arrow", + MenuAction.CC_OP.getId(), + 2, + -1, + -1 + )); + + ArgumentCaptor argumentCaptor = ArgumentCaptor.forClass(MenuEntry[].class); + verify(client).setMenuEntries(argumentCaptor.capture()); + + assertArrayEquals(new MenuEntry[]{ + menu("Cancel", "", MenuAction.CANCEL), + menu("Wield", "Rune arrow", MenuAction.CC_OP_LOW_PRIORITY, 9), + menu("Deposit-1", "Rune arrow", MenuAction.CC_OP, 2), + menu("Deposit-All", "Rune arrow", MenuAction.CC_OP, 8), }, argumentCaptor.getValue()); } } \ No newline at end of file