Merge pull request #7341 from deathbeam/menu-collapser
Add menu entry collapser to ground items
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright (c) 2018 Tomas Slusny <slusnucky@gmail.com>
|
||||
* 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
|
||||
{
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<MenuEntryWithCount> 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<ItemStack> 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();
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (c) 2018, Tomas Slusny <slusnucky@gmail.com>
|
||||
* 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++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user