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