Merge pull request #947 from se7enAte9/inventoryclickfix
menumanager: fix inaccurate left click options for inventory items
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright (c) 2019, 7ate9 <https://github.com/se7enAte9>
|
||||
* Copyright (c) 2019, https://runelitepl.us
|
||||
* 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.api.events;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* An event where a draggable widget has been pressed.
|
||||
*/
|
||||
@Data
|
||||
public class WidgetPressed
|
||||
{
|
||||
public static final WidgetPressed INSTANCE = new WidgetPressed();
|
||||
|
||||
private WidgetPressed()
|
||||
{
|
||||
// noop
|
||||
}
|
||||
}
|
||||
@@ -31,6 +31,7 @@ import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Multimap;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
@@ -62,6 +63,7 @@ import net.runelite.api.events.NpcActionChanged;
|
||||
import net.runelite.api.events.PlayerMenuOptionClicked;
|
||||
import net.runelite.api.events.PlayerMenuOptionsChanged;
|
||||
import net.runelite.api.events.WidgetMenuOptionClicked;
|
||||
import net.runelite.api.events.WidgetPressed;
|
||||
import net.runelite.api.widgets.WidgetInfo;
|
||||
import net.runelite.client.eventbus.EventBus;
|
||||
import net.runelite.client.eventbus.Subscribe;
|
||||
@@ -97,6 +99,7 @@ public class MenuManager
|
||||
private final LinkedHashSet<MenuEntry> entries = Sets.newLinkedHashSet();
|
||||
|
||||
private MenuEntry leftClickEntry = null;
|
||||
private MenuEntry firstEntry = null;
|
||||
|
||||
@Inject
|
||||
private MenuManager(Client client, EventBus eventBus)
|
||||
@@ -150,7 +153,7 @@ public class MenuManager
|
||||
// Need to reorder the list to normal, then rebuild with swaps
|
||||
MenuEntry[] oldEntries = event.getMenuEntries();
|
||||
|
||||
leftClickEntry = null;
|
||||
firstEntry = null;
|
||||
|
||||
client.sortMenuEntries();
|
||||
|
||||
@@ -280,24 +283,23 @@ public class MenuManager
|
||||
@Subscribe
|
||||
public void onBeforeRender(BeforeRender event)
|
||||
{
|
||||
leftClickEntry = null;
|
||||
|
||||
if (client.isMenuOpen())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
rebuildLeftClickMenu();
|
||||
}
|
||||
|
||||
private void rebuildLeftClickMenu()
|
||||
private MenuEntry rebuildLeftClickMenu()
|
||||
{
|
||||
if (client.isMenuOpen())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
firstEntry = null;
|
||||
entries.clear();
|
||||
entries.addAll(Arrays.asList(client.getMenuEntries()));
|
||||
|
||||
if (entries.size() < 2)
|
||||
{
|
||||
return;
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!hiddenEntries.isEmpty())
|
||||
@@ -316,22 +318,24 @@ public class MenuManager
|
||||
indexPriorityEntries(entries);
|
||||
}
|
||||
|
||||
if (leftClickEntry == null && !swaps.isEmpty())
|
||||
if (firstEntry == null && !swaps.isEmpty())
|
||||
{
|
||||
indexSwapEntries(entries);
|
||||
}
|
||||
|
||||
if (leftClickEntry != null)
|
||||
if (firstEntry != null)
|
||||
{
|
||||
entries.remove(leftClickEntry);
|
||||
entries.add(leftClickEntry);
|
||||
entries.remove(firstEntry);
|
||||
entries.add(firstEntry);
|
||||
}
|
||||
else if (!currentHiddenEntries.isEmpty())
|
||||
{
|
||||
leftClickEntry = Iterables.getLast(entries, null);
|
||||
firstEntry = Iterables.getLast(entries, null);
|
||||
}
|
||||
|
||||
client.setMenuEntries(entries.toArray(new MenuEntry[0]));
|
||||
|
||||
return firstEntry;
|
||||
}
|
||||
|
||||
public void addPlayerMenuItem(String menuText)
|
||||
@@ -435,12 +439,23 @@ public class MenuManager
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onWidgetPressed(WidgetPressed event)
|
||||
{
|
||||
leftClickEntry = rebuildLeftClickMenu();
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onMenuOptionClicked(MenuOptionClicked event)
|
||||
{
|
||||
if (!client.isMenuOpen() && event.isAuthentic())
|
||||
{
|
||||
rebuildLeftClickMenu();
|
||||
// The mouse button will not be 0 if a non draggable widget was clicked,
|
||||
// otherwise the left click entry will have been set in onWidgetPressed
|
||||
if (client.getMouseCurrentButton() != 0)
|
||||
{
|
||||
leftClickEntry = rebuildLeftClickMenu();
|
||||
}
|
||||
|
||||
if (leftClickEntry != null)
|
||||
{
|
||||
@@ -808,21 +823,31 @@ public class MenuManager
|
||||
}
|
||||
});
|
||||
|
||||
leftClickEntry = Iterables.getLast(safeCurrentPriorityEntries.entrySet().stream()
|
||||
firstEntry = Iterables.getLast(safeCurrentPriorityEntries.entrySet().stream()
|
||||
.sorted(Comparator.comparingInt(e -> e.getValue().getPriority()))
|
||||
.map(Map.Entry::getKey)
|
||||
.collect(Collectors.toList()), null);
|
||||
}
|
||||
|
||||
private void indexSwapEntries(Set<MenuEntry> entries)
|
||||
private void indexSwapEntries(Set<MenuEntry> entries)
|
||||
{
|
||||
MenuEntry first = Iterables.getLast(entries);
|
||||
|
||||
leftClickEntry = entries.parallelStream().filter(entry ->
|
||||
List<ComparableEntry> values = new ArrayList<>();
|
||||
|
||||
for (Map.Entry<ComparableEntry, ComparableEntry> pair : swaps.entrySet())
|
||||
{
|
||||
for (Map.Entry<ComparableEntry, ComparableEntry> p : swaps.entrySet())
|
||||
if (pair.getKey().matches(first))
|
||||
{
|
||||
if (p.getKey().matches(first) && p.getValue().matches(entry))
|
||||
values.add(pair.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
firstEntry = entries.parallelStream().filter(entry ->
|
||||
{
|
||||
for (ComparableEntry value : values)
|
||||
{
|
||||
if (value.matches(entry))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -87,6 +87,7 @@ import net.runelite.api.events.ResizeableChanged;
|
||||
import net.runelite.api.events.UsernameChanged;
|
||||
import net.runelite.api.events.VarbitChanged;
|
||||
import net.runelite.api.events.WidgetLoaded;
|
||||
import net.runelite.api.events.WidgetPressed;
|
||||
import net.runelite.api.hooks.Callbacks;
|
||||
import net.runelite.api.hooks.DrawCallbacks;
|
||||
import net.runelite.api.vars.AccountType;
|
||||
@@ -1305,6 +1306,16 @@ public abstract class RSClientMixin implements RSClient
|
||||
client.sendMenuAction(actionParam, widgetId, menuAction, id, menuOption, "!AUTHENTIC" + menuTarget, var6, var7);
|
||||
}
|
||||
|
||||
@Inject
|
||||
@FieldHook("tempMenuAction")
|
||||
public static void onTempMenuActionChanged(int idx)
|
||||
{
|
||||
if (client.getTempMenuAction() != null)
|
||||
{
|
||||
client.getCallbacks().post(WidgetPressed.INSTANCE);
|
||||
}
|
||||
}
|
||||
|
||||
@FieldHook("Login_username")
|
||||
@Inject
|
||||
public static void onUsernameChanged(int idx)
|
||||
|
||||
@@ -392,6 +392,9 @@ public interface RSClient extends RSGameShell, Client
|
||||
@Import("menuAction")
|
||||
void sendMenuAction(int n2, int n3, int n4, int n5, String string, String string2, int n6, int n7);
|
||||
|
||||
@Import("tempMenuAction")
|
||||
RSMenuAction getTempMenuAction();
|
||||
|
||||
@Import("decodeSprite")
|
||||
void decodeSprite(byte[] data);
|
||||
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright (c) 2019, https://runelitepl.us
|
||||
* 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.rs.api;
|
||||
|
||||
public interface RSMenuAction
|
||||
{
|
||||
}
|
||||
Reference in New Issue
Block a user