menu swapper: add custom shift-click object swap
This commit is contained in:
@@ -102,6 +102,7 @@ public class MenuEntrySwapperPlugin extends Plugin
|
|||||||
private static final String SHIFTCLICK_CONFIG_GROUP = "shiftclick";
|
private static final String SHIFTCLICK_CONFIG_GROUP = "shiftclick";
|
||||||
private static final String ITEM_KEY_PREFIX = "item_";
|
private static final String ITEM_KEY_PREFIX = "item_";
|
||||||
private static final String OBJECT_KEY_PREFIX = "object_";
|
private static final String OBJECT_KEY_PREFIX = "object_";
|
||||||
|
private static final String OBJECT_SHIFT_KEY_PREFIX = "object_shift_";
|
||||||
private static final String NPC_KEY_PREFIX = "npc_";
|
private static final String NPC_KEY_PREFIX = "npc_";
|
||||||
private static final String NPC_SHIFT_KEY_PREFIX = "npc_shift_";
|
private static final String NPC_SHIFT_KEY_PREFIX = "npc_shift_";
|
||||||
private static final String WORN_ITEM_KEY_PREFIX = "wornitem_";
|
private static final String WORN_ITEM_KEY_PREFIX = "wornitem_";
|
||||||
@@ -688,10 +689,14 @@ public class MenuEntrySwapperPlugin extends Plugin
|
|||||||
final ObjectComposition composition = client.getObjectDefinition(entry.getIdentifier());
|
final ObjectComposition composition = client.getObjectDefinition(entry.getIdentifier());
|
||||||
final String[] actions = composition.getActions();
|
final String[] actions = composition.getActions();
|
||||||
|
|
||||||
final Integer swapConfig = getObjectSwapConfig(composition.getId());
|
final Integer swapConfig = getObjectSwapConfig(false, composition.getId());
|
||||||
final MenuAction currentAction = swapConfig != null ? OBJECT_MENU_TYPES.get(swapConfig) :
|
final MenuAction currentAction = swapConfig != null ? OBJECT_MENU_TYPES.get(swapConfig) :
|
||||||
defaultAction(composition);
|
defaultAction(composition);
|
||||||
|
|
||||||
|
final Integer shiftSwapConfig = getObjectSwapConfig(true, composition.getId());
|
||||||
|
final MenuAction currentShiftAction = shiftSwapConfig != null ? OBJECT_MENU_TYPES.get(shiftSwapConfig) :
|
||||||
|
defaultAction(composition);
|
||||||
|
|
||||||
for (int actionIdx = 0; actionIdx < OBJECT_MENU_TYPES.size(); ++actionIdx)
|
for (int actionIdx = 0; actionIdx < OBJECT_MENU_TYPES.size(); ++actionIdx)
|
||||||
{
|
{
|
||||||
if (Strings.isNullOrEmpty(actions[actionIdx]))
|
if (Strings.isNullOrEmpty(actions[actionIdx]))
|
||||||
@@ -699,22 +704,38 @@ public class MenuEntrySwapperPlugin extends Plugin
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
final int menuIdx = actionIdx;
|
|
||||||
final MenuAction menuAction = OBJECT_MENU_TYPES.get(actionIdx);
|
final MenuAction menuAction = OBJECT_MENU_TYPES.get(actionIdx);
|
||||||
if (currentAction == menuAction)
|
if (menuAction != currentAction)
|
||||||
{
|
{
|
||||||
continue;
|
client.createMenuEntry(idx)
|
||||||
|
.setOption("Swap left click " + actions[actionIdx])
|
||||||
|
.setTarget(entry.getTarget())
|
||||||
|
.setType(MenuAction.RUNELITE)
|
||||||
|
.onClick(objectConsumer(composition, actions, actionIdx, menuAction, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (menuAction != currentShiftAction && menuAction != currentAction)
|
||||||
|
{
|
||||||
|
client.createMenuEntry(idx)
|
||||||
|
.setOption("Swap shift click " + actions[actionIdx])
|
||||||
|
.setTarget(entry.getTarget())
|
||||||
|
.setType(MenuAction.RUNELITE)
|
||||||
|
.onClick(objectConsumer(composition, actions, actionIdx, menuAction, true));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (swapConfig != null || shiftSwapConfig != null)
|
||||||
|
{
|
||||||
|
// Reset
|
||||||
client.createMenuEntry(idx)
|
client.createMenuEntry(idx)
|
||||||
.setOption("Swap " + actions[actionIdx])
|
.setOption("Reset swap")
|
||||||
.setTarget(entry.getTarget())
|
.setTarget(entry.getTarget())
|
||||||
.setType(MenuAction.RUNELITE)
|
.setType(MenuAction.RUNELITE)
|
||||||
.onClick(e ->
|
.onClick(e ->
|
||||||
{
|
{
|
||||||
final String message = new ChatMessageBuilder()
|
final String message = new ChatMessageBuilder()
|
||||||
.append("The default left click option for '").append(Text.removeTags(composition.getName())).append("' ")
|
.append("The default left and shift click options for '").append(Text.removeTags(composition.getName())).append("' ")
|
||||||
.append("has been set to '").append(actions[menuIdx]).append("'.")
|
.append("have been reset.")
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
chatMessageManager.queue(QueuedMessage.builder()
|
chatMessageManager.queue(QueuedMessage.builder()
|
||||||
@@ -722,23 +743,36 @@ public class MenuEntrySwapperPlugin extends Plugin
|
|||||||
.runeLiteFormattedMessage(message)
|
.runeLiteFormattedMessage(message)
|
||||||
.build());
|
.build());
|
||||||
|
|
||||||
log.debug("Set object swap for {} to {}", composition.getId(), menuAction);
|
log.debug("Unset object swap for {}", composition.getId());
|
||||||
|
unsetObjectSwapConfig(true, composition.getId());
|
||||||
final MenuAction defaultAction = defaultAction(composition);
|
unsetObjectSwapConfig(false, composition.getId());
|
||||||
if (defaultAction != menuAction)
|
|
||||||
{
|
|
||||||
setObjectSwapConfig(composition.getId(), menuIdx);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
unsetObjectSwapConfig(composition.getId());
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Consumer<MenuEntry> objectConsumer(ObjectComposition composition, String[] actions, int menuIdx,
|
||||||
|
MenuAction menuAction, boolean shift)
|
||||||
|
{
|
||||||
|
return e ->
|
||||||
|
{
|
||||||
|
final String message = new ChatMessageBuilder()
|
||||||
|
.append("The default ").append(shift ? "shift" : "left").append(" click option for '").append(Text.removeTags(composition.getName())).append("' ")
|
||||||
|
.append("has been set to '").append(actions[menuIdx]).append("'.")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
chatMessageManager.queue(QueuedMessage.builder()
|
||||||
|
.type(ChatMessageType.CONSOLE)
|
||||||
|
.runeLiteFormattedMessage(message)
|
||||||
|
.build());
|
||||||
|
|
||||||
|
log.debug("Set object swap for {} to {}", composition.getId(), menuAction);
|
||||||
|
|
||||||
|
setObjectSwapConfig(shift, composition.getId(), menuIdx);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
private Consumer<MenuEntry> walkHereConsumer(boolean shift, NPCComposition composition)
|
private Consumer<MenuEntry> walkHereConsumer(boolean shift, NPCComposition composition)
|
||||||
{
|
{
|
||||||
return e ->
|
return e ->
|
||||||
@@ -1172,7 +1206,7 @@ public class MenuEntrySwapperPlugin extends Plugin
|
|||||||
objectId = objectComposition.getId();
|
objectId = objectComposition.getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
Integer customOption = getObjectSwapConfig(objectId);
|
Integer customOption = getObjectSwapConfig(shiftModifier(), objectId);
|
||||||
if (customOption != null)
|
if (customOption != null)
|
||||||
{
|
{
|
||||||
MenuAction swapAction = OBJECT_MENU_TYPES.get(customOption);
|
MenuAction swapAction = OBJECT_MENU_TYPES.get(customOption);
|
||||||
@@ -1492,9 +1526,9 @@ public class MenuEntrySwapperPlugin extends Plugin
|
|||||||
rebuildCustomizationMenus();
|
rebuildCustomizationMenus();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Integer getObjectSwapConfig(int objectId)
|
private Integer getObjectSwapConfig(boolean shift, int objectId)
|
||||||
{
|
{
|
||||||
String config = configManager.getConfiguration(MenuEntrySwapperConfig.GROUP, OBJECT_KEY_PREFIX + objectId);
|
String config = configManager.getConfiguration(MenuEntrySwapperConfig.GROUP, (shift ? OBJECT_SHIFT_KEY_PREFIX : OBJECT_KEY_PREFIX) + objectId);
|
||||||
if (config == null || config.isEmpty())
|
if (config == null || config.isEmpty())
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
@@ -1503,14 +1537,14 @@ public class MenuEntrySwapperPlugin extends Plugin
|
|||||||
return Integer.parseInt(config);
|
return Integer.parseInt(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setObjectSwapConfig(int objectId, int index)
|
private void setObjectSwapConfig(boolean shift, int objectId, int index)
|
||||||
{
|
{
|
||||||
configManager.setConfiguration(MenuEntrySwapperConfig.GROUP, OBJECT_KEY_PREFIX + objectId, index);
|
configManager.setConfiguration(MenuEntrySwapperConfig.GROUP, (shift ? OBJECT_SHIFT_KEY_PREFIX : OBJECT_KEY_PREFIX) + objectId, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void unsetObjectSwapConfig(int objectId)
|
private void unsetObjectSwapConfig(boolean shift, int objectId)
|
||||||
{
|
{
|
||||||
configManager.unsetConfiguration(MenuEntrySwapperConfig.GROUP, OBJECT_KEY_PREFIX + objectId);
|
configManager.unsetConfiguration(MenuEntrySwapperConfig.GROUP, (shift ? OBJECT_SHIFT_KEY_PREFIX : OBJECT_KEY_PREFIX) + objectId);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static MenuAction defaultAction(ObjectComposition objectComposition)
|
private static MenuAction defaultAction(ObjectComposition objectComposition)
|
||||||
|
|||||||
Reference in New Issue
Block a user