diff --git a/runelite-api/src/main/java/net/runelite/api/events/WidgetPressed.java b/runelite-api/src/main/java/net/runelite/api/events/WidgetPressed.java new file mode 100644 index 0000000000..12ee089c80 --- /dev/null +++ b/runelite-api/src/main/java/net/runelite/api/events/WidgetPressed.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2019, 7ate9 + * 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 + } +} diff --git a/runelite-client/src/main/java/net/runelite/client/menus/MenuManager.java b/runelite-client/src/main/java/net/runelite/client/menus/MenuManager.java index 5ff9277e18..70ab8ebadf 100644 --- a/runelite-client/src/main/java/net/runelite/client/menus/MenuManager.java +++ b/runelite-client/src/main/java/net/runelite/client/menus/MenuManager.java @@ -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 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 entries) + private void indexSwapEntries(Set entries) { MenuEntry first = Iterables.getLast(entries); - leftClickEntry = entries.parallelStream().filter(entry -> + List values = new ArrayList<>(); + + for (Map.Entry pair : swaps.entrySet()) { - for (Map.Entry 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; } diff --git a/runelite-mixins/src/main/java/net/runelite/mixins/RSClientMixin.java b/runelite-mixins/src/main/java/net/runelite/mixins/RSClientMixin.java index 849ec90fbc..5336cf43d2 100644 --- a/runelite-mixins/src/main/java/net/runelite/mixins/RSClientMixin.java +++ b/runelite-mixins/src/main/java/net/runelite/mixins/RSClientMixin.java @@ -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) diff --git a/runescape-api/src/main/java/net/runelite/rs/api/RSClient.java b/runescape-api/src/main/java/net/runelite/rs/api/RSClient.java index 421bc5e64e..81d2d25014 100644 --- a/runescape-api/src/main/java/net/runelite/rs/api/RSClient.java +++ b/runescape-api/src/main/java/net/runelite/rs/api/RSClient.java @@ -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); diff --git a/runescape-api/src/main/java/net/runelite/rs/api/RSMenuAction.java b/runescape-api/src/main/java/net/runelite/rs/api/RSMenuAction.java new file mode 100644 index 0000000000..02cf730a39 --- /dev/null +++ b/runescape-api/src/main/java/net/runelite/rs/api/RSMenuAction.java @@ -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 +{ +}