Fix menu swaps not working when left clicking items
This commit is contained in:
@@ -72,6 +72,16 @@ public class ComparableEntry
|
||||
this.strictTarget = strictTarget;
|
||||
}
|
||||
|
||||
// This is only used for type checking, which is why it has everything but target
|
||||
// target sometimes changes to option.
|
||||
public ComparableEntry(MenuEntry e)
|
||||
{
|
||||
this.option = e.getOption();
|
||||
this.id = e.getIdentifier();
|
||||
this.type = e.getType();
|
||||
this.strictOption = true;
|
||||
}
|
||||
|
||||
boolean matches(MenuEntry entry)
|
||||
{
|
||||
String opt = Text.standardize(entry.getOption());
|
||||
|
||||
@@ -39,6 +39,7 @@ import java.util.Set;
|
||||
import java.util.regex.Pattern;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.runelite.api.Client;
|
||||
import net.runelite.api.MenuAction;
|
||||
@@ -96,7 +97,7 @@ public class MenuManager
|
||||
private final Set<ComparableEntry> hiddenEntries = new HashSet<>();
|
||||
|
||||
private final Map<ComparableEntry, ComparableEntry> swaps = new HashMap<>();
|
||||
private final Map<MenuEntry, Integer> originalTypes = new HashMap<>();
|
||||
private EntryTypeMapping originalType;
|
||||
|
||||
@Inject
|
||||
private MenuManager(Client client, EventBus eventBus)
|
||||
@@ -227,7 +228,7 @@ public class MenuManager
|
||||
@Subscribe
|
||||
private void onClientTick(ClientTick event)
|
||||
{
|
||||
originalTypes.clear();
|
||||
originalType = null;
|
||||
client.sortMenuEntries();
|
||||
|
||||
final MenuEntry[] oldentries = client.getMenuEntries();
|
||||
@@ -273,8 +274,9 @@ public class MenuManager
|
||||
int newType = getLeftClickType(type);
|
||||
if (newType != -1 && newType != type)
|
||||
{
|
||||
MenuEntry original = MenuEntry.copy(e);
|
||||
e.setType(newType);
|
||||
originalTypes.put(e, type);
|
||||
originalType = new EntryTypeMapping(new ComparableEntry(e), original);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -409,18 +411,18 @@ public class MenuManager
|
||||
@Subscribe
|
||||
public void onMenuOptionClicked(MenuOptionClicked event)
|
||||
{
|
||||
if (originalTypes.containsKey(event.getMenuEntry()) &&
|
||||
!event.getTarget().equals("do not edit"))
|
||||
// Type is changed in check
|
||||
if (originalType != null && originalType.check(event))
|
||||
{
|
||||
event.consume();
|
||||
|
||||
client.invokeMenuAction(
|
||||
event.getActionParam0(),
|
||||
event.getActionParam1(),
|
||||
originalTypes.get(event.getMenuEntry()),
|
||||
event.getType(),
|
||||
event.getIdentifier(),
|
||||
event.getOption(),
|
||||
"do not edit",
|
||||
event.getTarget(),
|
||||
client.getMouseCanvasPosition().getX(),
|
||||
client.getMouseCanvasPosition().getY()
|
||||
);
|
||||
@@ -749,4 +751,24 @@ public class MenuManager
|
||||
{
|
||||
hiddenEntries.remove(entry);
|
||||
}
|
||||
|
||||
@AllArgsConstructor
|
||||
private class EntryTypeMapping
|
||||
{
|
||||
private final ComparableEntry comparable;
|
||||
private final MenuEntry target;
|
||||
|
||||
private boolean check(MenuOptionClicked event)
|
||||
{
|
||||
MenuEntry entry = event.getMenuEntry();
|
||||
|
||||
if (!entry.getTarget().equals(entry.getOption()) && !comparable.matches(entry))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
event.setMenuEntry(target);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user