menu swapper: add bank extra op swap
This commit is contained in:
@@ -381,4 +381,14 @@ public interface MenuEntrySwapperConfig extends Config
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@ConfigItem(
|
||||
keyName = "swapBankOp",
|
||||
name = "Swap Bank Op",
|
||||
description = "Swaps the extra menu option in banks (Weild, Eat, etc.) when holding shift"
|
||||
)
|
||||
default boolean swapBankOp()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,6 +42,7 @@ import net.runelite.api.MenuEntry;
|
||||
import net.runelite.api.NPC;
|
||||
import net.runelite.api.events.ClientTick;
|
||||
import net.runelite.api.events.FocusChanged;
|
||||
import net.runelite.api.events.MenuEntryAdded;
|
||||
import net.runelite.api.events.MenuOpened;
|
||||
import net.runelite.api.events.MenuOptionClicked;
|
||||
import net.runelite.api.events.PostItemComposition;
|
||||
@@ -299,6 +300,41 @@ public class MenuEntrySwapperPlugin extends Plugin
|
||||
client.setMenuEntries(ArrayUtils.addAll(entries, resetShiftClickEntry));
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onMenuEntryAdded(MenuEntryAdded menuEntryAdded)
|
||||
{
|
||||
// This swap needs to happen prior to drag start on click, which happens during
|
||||
// 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
|
||||
|
||||
// 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-"))
|
||||
{
|
||||
MenuEntry[] menuEntries = client.getMenuEntries();
|
||||
|
||||
// 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)
|
||||
{
|
||||
MenuEntry entry = menuEntries[i];
|
||||
|
||||
// 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;
|
||||
|
||||
client.setMenuEntries(menuEntries);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onMenuOptionClicked(MenuOptionClicked event)
|
||||
{
|
||||
|
||||
@@ -33,6 +33,7 @@ import net.runelite.api.GameState;
|
||||
import net.runelite.api.MenuAction;
|
||||
import net.runelite.api.MenuEntry;
|
||||
import net.runelite.api.events.ClientTick;
|
||||
import net.runelite.api.events.MenuEntryAdded;
|
||||
import net.runelite.client.config.ConfigManager;
|
||||
import net.runelite.client.game.ItemManager;
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
@@ -98,11 +99,17 @@ public class MenuEntrySwapperPluginTest
|
||||
}
|
||||
|
||||
private static MenuEntry menu(String option, String target, MenuAction menuAction)
|
||||
{
|
||||
return menu(option, target, menuAction, 0);
|
||||
}
|
||||
|
||||
private static MenuEntry menu(String option, String target, MenuAction menuAction, int identifier)
|
||||
{
|
||||
MenuEntry menuEntry = new MenuEntry();
|
||||
menuEntry.setOption(option);
|
||||
menuEntry.setTarget(target);
|
||||
menuEntry.setType(menuAction.getId());
|
||||
menuEntry.setIdentifier(identifier);
|
||||
return menuEntry;
|
||||
}
|
||||
|
||||
@@ -294,4 +301,35 @@ public class MenuEntrySwapperPluginTest
|
||||
menu("Quick-Enter", "Formidable Passage", MenuAction.GAME_OBJECT_SECOND_OPTION),
|
||||
}, argumentCaptor.getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBankExtraOp()
|
||||
{
|
||||
when(config.swapBankOp()).thenReturn(true);
|
||||
menuEntrySwapperPlugin.setShiftModifier(true);
|
||||
|
||||
entries = new MenuEntry[]{
|
||||
menu("Cancel", "", MenuAction.CANCEL),
|
||||
menu("Weild", "Abyssal whip", MenuAction.CC_OP_LOW_PRIORITY, 9),
|
||||
menu("Deposit-1", "Abyssal whip", MenuAction.CC_OP, 2),
|
||||
};
|
||||
|
||||
menuEntrySwapperPlugin.onMenuEntryAdded(new MenuEntryAdded(
|
||||
"Deposit-1",
|
||||
"Abyssal whip",
|
||||
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("Deposit-1", "Abyssal whip", MenuAction.CC_OP, 2),
|
||||
menu("Weild", "Abyssal whip", MenuAction.CC_OP, 9),
|
||||
}, argumentCaptor.getValue());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user