From 0d5eac1a88d8c2b59b02ee14dcdb49fbef7b7247 Mon Sep 17 00:00:00 2001 From: Tomas Slusny Date: Sun, 13 Jan 2019 18:28:45 +0100 Subject: [PATCH 1/2] Add ClientTick event Add ClientTick event that is fired every time game cycle counter is updated. Signed-off-by: Tomas Slusny --- .../net/runelite/api/events/ClientTick.java | 32 +++++++++++++++++++ .../net/runelite/mixins/RSClientMixin.java | 8 +++++ 2 files changed, 40 insertions(+) create mode 100644 runelite-api/src/main/java/net/runelite/api/events/ClientTick.java diff --git a/runelite-api/src/main/java/net/runelite/api/events/ClientTick.java b/runelite-api/src/main/java/net/runelite/api/events/ClientTick.java new file mode 100644 index 0000000000..369ff7982a --- /dev/null +++ b/runelite-api/src/main/java/net/runelite/api/events/ClientTick.java @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2018 Tomas Slusny + * 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; + +/** + * Posted every client tick + */ +public class ClientTick +{ +} 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 f1059583cb..991f9a3a43 100644 --- a/runelite-mixins/src/main/java/net/runelite/mixins/RSClientMixin.java +++ b/runelite-mixins/src/main/java/net/runelite/mixins/RSClientMixin.java @@ -74,6 +74,7 @@ import net.runelite.api.events.ChatMessage; import net.runelite.api.events.ClanChanged; import net.runelite.api.events.DraggingWidgetChanged; import net.runelite.api.events.ExperienceChanged; +import net.runelite.api.events.ClientTick; import net.runelite.api.events.GameStateChanged; import net.runelite.api.events.GrandExchangeOfferChanged; import net.runelite.api.events.MenuEntryAdded; @@ -1398,4 +1399,11 @@ public abstract class RSClientMixin implements RSClient { return skyboxColor; } + + @Inject + @FieldHook("cycleCntr") + public static void onCycleCntrChanged(int idx) + { + client.getCallbacks().post(new ClientTick()); + } } \ No newline at end of file From 67c89de8626b9089e2d6dd91fa61732e0bc1036b Mon Sep 17 00:00:00 2001 From: Adam Date: Sun, 13 Jan 2019 19:33:30 -0500 Subject: [PATCH 2/2] Add menu entry collapsing to ground items plugin Co-authored-by: Tomas Slusny --- .../grounditems/GroundItemsConfig.java | 10 ++++ .../grounditems/GroundItemsPlugin.java | 55 ++++++++++++++++++- .../grounditems/MenuEntryWithCount.java | 45 +++++++++++++++ 3 files changed, 109 insertions(+), 1 deletion(-) create mode 100644 runelite-client/src/main/java/net/runelite/client/plugins/grounditems/MenuEntryWithCount.java diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/grounditems/GroundItemsConfig.java b/runelite-client/src/main/java/net/runelite/client/plugins/grounditems/GroundItemsConfig.java index fceac2f2d4..da3db4a3f1 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/grounditems/GroundItemsConfig.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/grounditems/GroundItemsConfig.java @@ -336,4 +336,14 @@ public interface GroundItemsConfig extends Config return 250; } + @ConfigItem( + keyName = "collapseEntries", + name = "Collapse ground item menu entries", + description = "Collapses ground item menu entries together and appends count", + position = 26 + ) + default boolean collapseEntries() + { + return false; + } } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/grounditems/GroundItemsPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/grounditems/GroundItemsPlugin.java index 18fcdd6a9d..d4714453a2 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/grounditems/GroundItemsPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/grounditems/GroundItemsPlugin.java @@ -33,6 +33,7 @@ import com.google.inject.Provides; import java.awt.Color; import java.awt.Rectangle; import static java.lang.Boolean.TRUE; +import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; import java.util.LinkedHashMap; @@ -58,6 +59,7 @@ import net.runelite.api.Player; import net.runelite.api.Scene; import net.runelite.api.Tile; import net.runelite.api.coords.WorldPoint; +import net.runelite.api.events.ClientTick; import net.runelite.api.events.ConfigChanged; import net.runelite.api.events.FocusChanged; import net.runelite.api.events.GameStateChanged; @@ -102,6 +104,13 @@ public class GroundItemsPlugin extends Plugin private static final float HIGH_ALCHEMY_CONSTANT = 0.6f; // ItemID for coins private static final int COINS = ItemID.COINS_995; + // Ground item menu options + private static final int FIRST_OPTION = MenuAction.GROUND_ITEM_FIRST_OPTION.getId(); + private static final int SECOND_OPTION = MenuAction.GROUND_ITEM_SECOND_OPTION.getId(); + private static final int THIRD_OPTION = MenuAction.GROUND_ITEM_THIRD_OPTION.getId(); // this is Take + private static final int FOURTH_OPTION = MenuAction.GROUND_ITEM_FOURTH_OPTION.getId(); + private static final int FIFTH_OPTION = MenuAction.GROUND_ITEM_FIFTH_OPTION.getId(); + private static final int EXAMINE_ITEM = MenuAction.EXAMINE_ITEM_GROUND.getId(); @Getter(AccessLevel.PACKAGE) @Setter(AccessLevel.PACKAGE) @@ -287,6 +296,50 @@ public class GroundItemsPlugin extends Plugin lootReceived(items); } + @Subscribe + public void onClientTick(ClientTick event) + { + if (!config.collapseEntries()) + { + return; + } + + final MenuEntry[] menuEntries = client.getMenuEntries(); + final List newEntries = new ArrayList<>(menuEntries.length); + + outer: + for (MenuEntry menuEntry : menuEntries) + { + int menuType = menuEntry.getType(); + if (menuType == FIRST_OPTION || menuType == SECOND_OPTION || menuType == THIRD_OPTION + || menuType == FOURTH_OPTION || menuType == FIFTH_OPTION || menuType == EXAMINE_ITEM) + { + for (MenuEntryWithCount entryWCount : newEntries) + { + if (entryWCount.getEntry().equals(menuEntry)) + { + entryWCount.increment(); + continue outer; + } + } + } + + newEntries.add(new MenuEntryWithCount(menuEntry)); + } + + client.setMenuEntries(newEntries.stream().map(e -> + { + final MenuEntry entry = e.getEntry(); + final int count = e.getCount(); + if (count > 1) + { + entry.setTarget(entry.getTarget() + " x " + count); + } + + return entry; + }).toArray(MenuEntry[]::new)); + } + private void lootReceived(Collection items) { for (ItemStack itemStack : items) @@ -397,7 +450,7 @@ public class GroundItemsPlugin extends Plugin { if (config.itemHighlightMode() != OVERLAY && event.getOption().equals("Take") - && event.getType() == MenuAction.GROUND_ITEM_THIRD_OPTION.getId()) + && event.getType() == THIRD_OPTION) { int itemId = event.getIdentifier(); Scene scene = client.getScene(); diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/grounditems/MenuEntryWithCount.java b/runelite-client/src/main/java/net/runelite/client/plugins/grounditems/MenuEntryWithCount.java new file mode 100644 index 0000000000..a8539921c0 --- /dev/null +++ b/runelite-client/src/main/java/net/runelite/client/plugins/grounditems/MenuEntryWithCount.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2018, Tomas Slusny + * 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.plugins.grounditems; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import net.runelite.api.MenuEntry; + +@RequiredArgsConstructor +class MenuEntryWithCount +{ + @Getter + private final MenuEntry entry; + + @Getter + private int count = 1; + + void increment() + { + count++; + } +} +