Improve menu action prioritizing (reworks easyscape construction)

This commit is contained in:
Lucas
2019-05-22 19:04:28 +02:00
parent 58086b605d
commit 6af0da37ea
4 changed files with 259 additions and 41 deletions

View File

@@ -1,3 +1,27 @@
/*
* Copyright (c) 2019, Lucas <https://github.com/Lucwousin>
* 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.menus;
import joptsimple.internal.Strings;

View File

@@ -1,5 +1,6 @@
/*
* Copyright (c) 2017, Robin <robin.weymans@gmail.com>
* Copyright (c) 2019, Lucas <https://github.com/Lucwousin>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -39,11 +40,13 @@ import java.util.Set;
import java.util.regex.Pattern;
import javax.inject.Inject;
import javax.inject.Singleton;
import joptsimple.internal.Strings;
import lombok.extern.slf4j.Slf4j;
import net.runelite.api.Client;
import net.runelite.api.MenuAction;
import net.runelite.api.MenuEntry;
import net.runelite.api.NPCComposition;
import net.runelite.api.ObjectComposition;
import net.runelite.api.events.MenuEntryAdded;
import net.runelite.api.events.MenuOptionClicked;
import net.runelite.api.events.NpcActionChanged;
@@ -92,6 +95,8 @@ public class MenuManager
private final Set<MenuEntry> currentPriorityEntries = new HashSet<>();
private final Map<AbstractMenuEntry, AbstractMenuEntry> swaps = new HashMap<>();
private final Set<MenuEntry> originalTypes = new HashSet<>();
private final Set<Integer> leftClickObjects = new HashSet<>();
@Inject
private MenuManager(Client client, EventBus eventBus)
@@ -148,6 +153,8 @@ public class MenuManager
{
// Menu entries reset, so priority entries should reset as well
currentPriorityEntries.clear();
originalTypes.clear();
}
for (WidgetMenuOption currentMenu : options)
@@ -166,7 +173,7 @@ public class MenuManager
}
}
MenuEntry newestEntry = menuEntries[menuEntries.length - 1];
final MenuEntry newestEntry = menuEntries[menuEntries.length - 1];
boolean isPrio = false;
for (AbstractMenuEntry p : priorityEntries)
@@ -192,7 +199,7 @@ public class MenuManager
{
copy.retainAll(currentPriorityEntries);
copy.add(CANCEL());
copy.add(0, CANCEL());
}
// Find the current entry in the swaps map
@@ -223,14 +230,18 @@ public class MenuManager
if (foundSwap != null)
{
// This is to make things like games necklace and essence pouches show up right
if (foundSwap.getType() == MenuAction.EXAMINE_ITEM_BANK_EQ.getId())
// This is the menu entry added last's type
final int otherType = foundSwap.getType();
// MenuActions with an id of over 1000 get shifted to the back of the menu entry array
// They have different id's in the packet buffer though, so we got to modify them back on click
// I couldn't get this to work with objects, so we're using modified objectcomposition for that
final boolean shouldModifyType = otherType == MenuAction.EXAMINE_ITEM_BANK_EQ.getId();
if (shouldModifyType)
{
int newType = foundSwap.getType();
foundSwap.setType(newestEntry.getType());
newestEntry.setType(newType);
foundSwap.setType(MenuAction.WIDGET_DEFAULT.getId());
originalTypes.add(foundSwap);
}
// Swap
@@ -271,6 +282,86 @@ public class MenuManager
}
}
public boolean toggleLeftClick(String menuText, int objectID, boolean reset)
{
Preconditions.checkNotNull(menuText);
if (client == null)
{
return false;
}
ObjectComposition oc = client.getObjectDefinition(objectID);
if (oc == null)
{
return false;
}
ObjectComposition impostor = oc.getImpostorIds() != null ? oc.getImpostor() : null;
if (impostor != null)
{
if (toggleLeftClick(menuText, impostor.getId(), reset))
{
// Sorry about this
leftClickObjects.remove(impostor.getId());
if (reset)
{
leftClickObjects.remove(objectID);
}
else
{
leftClickObjects.add(objectID);
}
return true;
}
}
String[] options = oc.getActions();
if (options == null)
{
return false;
}
boolean hasOption5 = !Strings.isNullOrEmpty(options[options.length - 1]);
boolean hasOption1 = !Strings.isNullOrEmpty(options[0]);
if (hasOption5 || hasOption1)
{
String option1 = options[0];
String option5 = options[options.length - 1];
if (reset && !hasOption1 // Won't have to reset anything cause
|| reset && !menuText.equalsIgnoreCase(option1) // theres nothing to reset
|| hasOption5 && !menuText.equalsIgnoreCase(option5))
{
return false;
}
options[0] = option5;
options[options.length - 1] = option1;
}
else
{
return false;
}
if (reset)
{
leftClickObjects.remove(objectID);
}
else
{
leftClickObjects.add(objectID);
}
return true;
}
@Subscribe
public void onPlayerMenuOptionsChanged(PlayerMenuOptionsChanged event)
{
@@ -349,6 +440,79 @@ public class MenuManager
@Subscribe
public void onMenuOptionClicked(MenuOptionClicked event)
{
if (!event.getMenuTarget().equals("do not edit") &&
!originalTypes.isEmpty() &&
event.getMenuAction() == MenuAction.WIDGET_DEFAULT)
{
for (MenuEntry e : originalTypes)
{
// Honestly, I was about to write a huge ass rant about
// how I hate whoever wrote the menuoptionclicked class
// but I decided that that'd be un-nice to them, and they
// probably spent over 24 hours writing it. Not because
// it was that difficult to write, of course, but because
// they must have the fucking iq of a retarded, under developed,
// braindead, basically good-for-nothing, idiotic chimp.
//
// Just kidding, of course, that would be too big of an
// insult towards those poor chimps. It's not their fault
// some dumbass is the way they are, right? Why should they
// feel bad for something they can't do anything about?
//
// Whoever wrote that class though, should actually feel
// 100% terrible. If they aren't depressed, I really wish
// they become depressed very, very soon. What the fuck
// were they even thinking.
if (event.getMenuAction().getId() != e.getType()
|| event.getId() != e.getIdentifier()
|| !event.getMenuOption().equals(e.getOption()))
{
continue;
}
event.consume();
client.invokeMenuAction(
event.getActionParam(),
event.getWidgetId(),
MenuAction.EXAMINE_ITEM_BANK_EQ.getId(),
event.getId(),
event.getMenuOption(),
"do not edit",
client.getMouseCanvasPosition().getX(),
client.getMouseCanvasPosition().getY()
);
break;
}
}
if (!event.getMenuTarget().equals("do not edit") &&
!leftClickObjects.isEmpty() &&
event.getMenuAction() == MenuAction.GAME_OBJECT_FIRST_OPTION &&
(
leftClickObjects.contains(event.getId())
||
client.getObjectDefinition(event.getId()) != null &&
client.getObjectDefinition(event.getId()).getImpostorIds() != null &&
client.getObjectDefinition(event.getId()).getImpostor() != null &&
client.getObjectDefinition(event.getId()).getImpostor().getId() == event.getId()))
{
event.consume();
client.invokeMenuAction(
event.getActionParam(),
event.getWidgetId(),
MenuAction.GAME_OBJECT_FIFTH_OPTION.getId(),
event.getId(),
event.getMenuOption(),
"do not edit",
client.getMouseCanvasPosition().getX(),
client.getMouseCanvasPosition().getY()
);
}
if (event.getMenuAction() != MenuAction.RUNELITE)
{
return; // not a player menu

View File

@@ -433,7 +433,7 @@ public interface EasyscapeConfig extends Config
@ConfigItem(
keyName = "easyConstruction",
name = "Easy Construction",
description = "Makes \"Remove\" the default option for listed items in build mode.",
description = "Makes \"Remove\"/\"Build\" the default option for listed item ID's in build mode.<br>Tip: Use dev tools \"Game Objects\" to find out the ID!",
position = 30,
group = "Miscellaneous swapper"
)
@@ -445,7 +445,7 @@ public interface EasyscapeConfig extends Config
@ConfigItem(
keyName = "constructionItems",
name = "Construction Items",
description = "Items listed here will have the default option set to \"Removed\" in build mode.",
description = "Makes \"Remove\"/\"Build\" the default option for listed item ID's in build mode.<br>Tip: Use dev tools \"Game Objects\" to find out the ID, and seperate values with a ','",
position = 31,
group = "Miscellaneous swapper",
hidden = true,

View File

@@ -29,6 +29,8 @@ package net.runelite.client.plugins.easyscape;
import com.google.common.base.Strings;
import com.google.inject.Provides;
import java.util.HashSet;
import java.util.Set;
import javax.inject.Inject;
import net.runelite.api.Client;
import net.runelite.api.GameState;
@@ -40,6 +42,7 @@ import net.runelite.api.Player;
import static net.runelite.api.Varbits.BUILDING_MODE;
import net.runelite.api.coords.WorldPoint;
import net.runelite.api.events.ConfigChanged;
import net.runelite.api.events.GameStateChanged;
import net.runelite.api.events.MenuEntryAdded;
import net.runelite.client.config.ConfigManager;
import net.runelite.client.eventbus.Subscribe;
@@ -61,6 +64,7 @@ public class EasyscapePlugin extends Plugin
private static final int PURO_PURO_REGION_ID = 10307;
private MenuEntry[] entries;
private final Set<Integer> leftClickConstructionIDs = new HashSet<>();
@Inject
private Client client;
@@ -81,12 +85,25 @@ public class EasyscapePlugin extends Plugin
public void startUp()
{
addSwaps();
loadConstructionIDs(config.getConstructionItems());
}
@Override
public void shutDown()
{
removeSwaps();
loadConstructionIDs("");
}
@Subscribe
public void onGameStateChanged(GameStateChanged event)
{
if (client.getGameState() != GameState.LOGGED_IN)
{
return;
}
loadConstructionIDs(config.getConstructionItems());
}
@Subscribe
@@ -301,35 +318,7 @@ public class EasyscapePlugin extends Plugin
}
}
if (config.getEasyConstruction() && client.getVar(BUILDING_MODE) == 1 && !Strings.isNullOrEmpty(config.getConstructionItems()))
{
if (event.getType() == WALK.getId())
{
MenuEntry menuEntry = entries[entries.length - 1];
menuEntry.setType(MenuAction.WALK.getId() + MENU_ACTION_DEPRIORITIZE_OFFSET);
}
swap(client, "Build", option, target);
for (int i = entries.length - 1; i >= 0; i--)
{
for (String item : Text.fromCSV(config.getConstructionItems()))
{
if (item.equalsIgnoreCase(Text.removeTags(entries[i].getTarget())))
{
if (!entries[i].getOption().equalsIgnoreCase("remove"))
{
entries = ArrayUtils.remove(entries, i);
i--;
}
}
}
}
client.setMenuEntries(entries);
}
if (config.getSwapSmithing() && option.contains("smith"))
else if (config.getSwapSmithing() && option.contains("smith"))
{
if (option.equalsIgnoreCase("Smith 1"))
{
@@ -396,6 +385,7 @@ public class EasyscapePlugin extends Plugin
return;
}
loadConstructionIDs(config.getConstructionItems());
removeSwaps();
addSwaps();
}
@@ -443,7 +433,6 @@ public class EasyscapePlugin extends Plugin
menuManager.addSwap("remove", "digsite pendant", config.getDigsitePendantMode().toString(), "digsite pendant", true, false);
}
if (config.getSlayerRing())
{
menuManager.addSwap("remove", "slayer ring", config.getSlayerRingMode().toString(), "slayer ring", true, false);
@@ -508,4 +497,45 @@ public class EasyscapePlugin extends Plugin
return location.getRegionID() == PURO_PURO_REGION_ID;
}
}
private void loadConstructionIDs(String from)
{
if (client.getGameState() != GameState.LOGGED_IN
|| Strings.isNullOrEmpty(from) && leftClickConstructionIDs.isEmpty())
{
return;
}
if (!leftClickConstructionIDs.isEmpty())
{
for (int i : leftClickConstructionIDs)
{
menuManager.toggleLeftClick("build", i, true);
menuManager.toggleLeftClick("remove", i, true);
}
leftClickConstructionIDs.clear();
}
if (!config.getEasyConstruction() &&
!Strings.isNullOrEmpty(from) &&
client.getVar(BUILDING_MODE) == 1)
{
for (String s : Text.fromCSV(from))
{
int id = Integer.parseInt(s.replaceAll("[^0-9]", ""));
if (leftClickConstructionIDs.contains(id))
{
continue;
}
if (menuManager.toggleLeftClick("build", id, false)
|| menuManager.toggleLeftClick("remove", id, false))
{
leftClickConstructionIDs.add(id);
}
}
}
}
}