menu swapper: add bank deposit/withdraw shift click

Co-authored-by: Adam <Adam@sigterm.info>
This commit is contained in:
Zach Waller
2020-01-27 15:27:52 -05:00
committed by Adam
parent ee2b2012e4
commit 8708788004
5 changed files with 198 additions and 32 deletions

View File

@@ -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;
}
}

View File

@@ -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;
}
}
}

View File

@@ -0,0 +1,52 @@
/*
* Copyright (c) 2020, Zach <https://github.com/zacharydwaller>
* 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;
}
}

View File

@@ -0,0 +1,52 @@
/*
* Copyright (c) 2020, Zach <https://github.com/zacharydwaller>
* 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;
}
}

View File

@@ -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<MenuEntry[]> 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());
}
}