menu swapper: move bank swaps to client tick
The underlying issue preventing this from working during client tick has been addressed
This commit is contained in:
@@ -56,7 +56,6 @@ import net.runelite.api.NPC;
|
||||
import net.runelite.api.NPCComposition;
|
||||
import net.runelite.api.ObjectComposition;
|
||||
import net.runelite.api.events.ClientTick;
|
||||
import net.runelite.api.events.MenuEntryAdded;
|
||||
import net.runelite.api.events.MenuOpened;
|
||||
import net.runelite.api.events.PostItemComposition;
|
||||
import net.runelite.api.widgets.WidgetID;
|
||||
@@ -793,15 +792,14 @@ public class MenuEntrySwapperPlugin extends Plugin
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onMenuEntryAdded(MenuEntryAdded menuEntryAdded)
|
||||
private boolean swapBank(MenuEntry menuEntry, MenuAction type)
|
||||
{
|
||||
// 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
|
||||
|
||||
final int widgetGroupId = WidgetInfo.TO_GROUP(menuEntryAdded.getActionParam1());
|
||||
if (type != MenuAction.CC_OP && type != MenuAction.CC_OP_LOW_PRIORITY)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
final int widgetGroupId = WidgetInfo.TO_GROUP(menuEntry.getParam1());
|
||||
final boolean isDepositBoxPlayerInventory = widgetGroupId == WidgetID.DEPOSIT_BOX_GROUP_ID;
|
||||
final boolean isChambersOfXericStorageUnitPlayerInventory = widgetGroupId == WidgetID.CHAMBERS_OF_XERIC_STORAGE_UNIT_INVENTORY_GROUP_ID;
|
||||
final boolean isGroupStoragePlayerInventory = widgetGroupId == WidgetID.GROUP_STORAGE_INVENTORY_GROUP_ID;
|
||||
@@ -809,9 +807,9 @@ public class MenuEntrySwapperPlugin extends Plugin
|
||||
// Deposit- op 1 is the current withdraw amount 1/5/10/x for deposit box interface and chambers of xeric storage unit.
|
||||
// Deposit- op 2 is the current withdraw amount 1/5/10/x for bank interface
|
||||
if (shiftModifier() && config.bankDepositShiftClick() != ShiftDepositMode.OFF
|
||||
&& menuEntryAdded.getType() == MenuAction.CC_OP.getId()
|
||||
&& menuEntryAdded.getIdentifier() == (isDepositBoxPlayerInventory || isGroupStoragePlayerInventory || isChambersOfXericStorageUnitPlayerInventory ? 1 : 2)
|
||||
&& (menuEntryAdded.getOption().startsWith("Deposit-") || menuEntryAdded.getOption().startsWith("Store") || menuEntryAdded.getOption().startsWith("Donate")))
|
||||
&& type == MenuAction.CC_OP
|
||||
&& menuEntry.getIdentifier() == (isDepositBoxPlayerInventory || isGroupStoragePlayerInventory || isChambersOfXericStorageUnitPlayerInventory ? 1 : 2)
|
||||
&& (menuEntry.getOption().startsWith("Deposit-") || menuEntry.getOption().startsWith("Store") || menuEntry.getOption().startsWith("Donate")))
|
||||
{
|
||||
ShiftDepositMode shiftDepositMode = config.bankDepositShiftClick();
|
||||
final int opId = isDepositBoxPlayerInventory ? shiftDepositMode.getIdentifierDepositBox()
|
||||
@@ -820,13 +818,14 @@ public class MenuEntrySwapperPlugin extends Plugin
|
||||
: shiftDepositMode.getIdentifier();
|
||||
final MenuAction action = opId >= 6 ? MenuAction.CC_OP_LOW_PRIORITY : MenuAction.CC_OP;
|
||||
bankModeSwap(action, opId);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 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"))
|
||||
&& type == MenuAction.CC_OP && menuEntry.getIdentifier() == 1
|
||||
&& menuEntry.getOption().startsWith("Withdraw"))
|
||||
{
|
||||
ShiftWithdrawMode shiftWithdrawMode = config.bankWithdrawShiftClick();
|
||||
final MenuAction action;
|
||||
@@ -842,7 +841,10 @@ public class MenuEntrySwapperPlugin extends Plugin
|
||||
opId = shiftWithdrawMode.getIdentifier();
|
||||
}
|
||||
bankModeSwap(action, opId);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private void bankModeSwap(MenuAction entryType, int entryIdentifier)
|
||||
@@ -976,6 +978,11 @@ public class MenuEntrySwapperPlugin extends Plugin
|
||||
}
|
||||
}
|
||||
|
||||
if (swapBank(menuEntry, menuAction))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Built-in swaps
|
||||
Collection<Swap> swaps = this.swaps.get(option);
|
||||
for (Swap swap : swaps)
|
||||
|
||||
@@ -38,7 +38,6 @@ import net.runelite.api.NPC;
|
||||
import net.runelite.api.NPCComposition;
|
||||
import net.runelite.api.ObjectComposition;
|
||||
import net.runelite.api.events.ClientTick;
|
||||
import net.runelite.api.events.MenuEntryAdded;
|
||||
import net.runelite.client.chat.ChatMessageManager;
|
||||
import net.runelite.client.config.ConfigManager;
|
||||
import net.runelite.client.game.ItemManager;
|
||||
@@ -332,14 +331,7 @@ public class MenuEntrySwapperPluginTest
|
||||
menu("Deposit-1", "Abyssal whip", MenuAction.CC_OP, 2),
|
||||
};
|
||||
|
||||
menuEntrySwapperPlugin.onMenuEntryAdded(new MenuEntryAdded(
|
||||
"Deposit-1",
|
||||
"Abyssal whip",
|
||||
MenuAction.CC_OP.getId(),
|
||||
2,
|
||||
-1,
|
||||
-1
|
||||
));
|
||||
menuEntrySwapperPlugin.onClientTick(new ClientTick());
|
||||
|
||||
ArgumentCaptor<MenuEntry[]> argumentCaptor = ArgumentCaptor.forClass(MenuEntry[].class);
|
||||
verify(client).setMenuEntries(argumentCaptor.capture());
|
||||
@@ -364,14 +356,7 @@ public class MenuEntrySwapperPluginTest
|
||||
menu("Deposit-1", "Rune arrow", MenuAction.CC_OP, 2),
|
||||
};
|
||||
|
||||
menuEntrySwapperPlugin.onMenuEntryAdded(new MenuEntryAdded(
|
||||
"Deposit-1",
|
||||
"Rune arrow",
|
||||
MenuAction.CC_OP.getId(),
|
||||
2,
|
||||
-1,
|
||||
-1
|
||||
));
|
||||
menuEntrySwapperPlugin.onClientTick(new ClientTick());
|
||||
|
||||
ArgumentCaptor<MenuEntry[]> argumentCaptor = ArgumentCaptor.forClass(MenuEntry[].class);
|
||||
verify(client).setMenuEntries(argumentCaptor.capture());
|
||||
|
||||
Reference in New Issue
Block a user