From 1228c132df2d26fae6a0cf1effe9351841960e63 Mon Sep 17 00:00:00 2001 From: gazivodag Date: Mon, 24 Jun 2019 08:43:53 -0400 Subject: [PATCH] Looting bag viewer update Ability to see GP overlayed on looting bag Config Draft PR --- .../LootingBagViewerConfig.java | 69 ++++++++++ .../LootingBagViewerPlugin.java | 120 ++++++++++++++++-- .../LootingBagViewerWidgetOverlay.java | 85 +++++++++++++ 3 files changed, 266 insertions(+), 8 deletions(-) create mode 100644 runelite-client/src/main/java/net/runelite/client/plugins/lootingbagviewer/LootingBagViewerConfig.java create mode 100644 runelite-client/src/main/java/net/runelite/client/plugins/lootingbagviewer/LootingBagViewerWidgetOverlay.java diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/lootingbagviewer/LootingBagViewerConfig.java b/runelite-client/src/main/java/net/runelite/client/plugins/lootingbagviewer/LootingBagViewerConfig.java new file mode 100644 index 0000000000..6f216c47df --- /dev/null +++ b/runelite-client/src/main/java/net/runelite/client/plugins/lootingbagviewer/LootingBagViewerConfig.java @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2019, gazivodag + * 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.lootingbagviewer; + +import net.runelite.client.config.Config; +import net.runelite.client.config.ConfigGroup; +import net.runelite.client.config.ConfigItem; +import net.runelite.client.config.Stub; + +@ConfigGroup("lootingbagviewer") +public interface LootingBagViewerConfig extends Config +{ + @ConfigItem( + keyName = "overlayStub", + name = "Overlays", + description = "", + position = 0 + ) + default Stub overlayStub() + { + return new Stub(); + } + + @ConfigItem( + keyName = "renderViewer", + name = "Render Viewer", + description = "Shows second inventory on screen with looting bag items.", + position = 1, + parent = "overlayStub" + ) + default boolean renderViewer() + { + return true; + } + + @ConfigItem( + keyName = "renderLootingBag", + name = "Render Looting Bag Worth", + description = "Shows current amount of GP over the looting bag.", + position = 2, + parent = "overlayStub" + ) + default boolean renderLootingBag() + { + return true; + } +} diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/lootingbagviewer/LootingBagViewerPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/lootingbagviewer/LootingBagViewerPlugin.java index aea700c292..0a7ed4ba03 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/lootingbagviewer/LootingBagViewerPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/lootingbagviewer/LootingBagViewerPlugin.java @@ -1,5 +1,6 @@ /* * Copyright (c) 2018 AWPH-I + * Copyright (c) 2019, gazivodag * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -25,37 +26,140 @@ package net.runelite.client.plugins.lootingbagviewer; +import com.google.common.base.Strings; +import com.google.inject.Provides; import javax.inject.Inject; +import lombok.Getter; +import lombok.Setter; +import net.runelite.api.Client; +import net.runelite.api.events.ConfigChanged; +import net.runelite.api.events.WidgetHiddenChanged; +import net.runelite.api.widgets.Widget; +import net.runelite.client.callback.ClientThread; +import net.runelite.client.config.ConfigManager; +import net.runelite.client.eventbus.Subscribe; import net.runelite.client.plugins.Plugin; import net.runelite.client.plugins.PluginDescriptor; import net.runelite.client.plugins.PluginType; import net.runelite.client.ui.overlay.OverlayManager; @PluginDescriptor( - name = "PvP Looting Bag Viewer", - description = "Add an overlay showing the contents of your looting bag", - tags = {"alternate", "items", "overlay", "second"}, - type = PluginType.PVP, - enabledByDefault = false + name = "PvP Looting Bag Viewer", + description = "Add an overlay showing the contents of your looting bag", + tags = {"alternate", "items", "overlay", "second"}, + type = PluginType.PVP, + enabledByDefault = false ) - +/** + * TODO: Remember current looting bag value when client restarts + * TODO: Write an event for picking up an item (with opened looting bag) and add its price to the current looting bag value + * TODO: Write something to capture adding items to a looting bag and add its price to the current looting bag value + * TODO: Make if check for empty looting bag so it doesn't throw any errors + */ public class LootingBagViewerPlugin extends Plugin { @Inject - private net.runelite.client.plugins.lootingbagviewer.LootingBagViewerOverlay overlay; + private Client client; + + @Inject + private ClientThread clientThread; + + @Inject + private LootingBagViewerOverlay overlay; + + @Inject + private LootingBagViewerWidgetOverlay widgetOverlay; @Inject private OverlayManager overlayManager; + @Inject + private LootingBagViewerConfig config; + + @Getter + @Setter + private int valueToShow = -1; + + @Provides + LootingBagViewerConfig getConfig(ConfigManager configManager) + { + return configManager.getConfig(LootingBagViewerConfig.class); + } + @Override public void startUp() { - overlayManager.add(overlay); + if (config.renderViewer()) + { + overlayManager.add(overlay); + } + + if (config.renderLootingBag()) + { + overlayManager.add(widgetOverlay); + } } @Override public void shutDown() { overlayManager.remove(overlay); + overlayManager.remove(widgetOverlay); } + + @Subscribe + public void onConfigChanged(ConfigChanged configChanged) + { + if (configChanged.getKey().equals("renderViewer")) + { + if (Boolean.parseBoolean(configChanged.getNewValue()) == true) + { + overlayManager.add(overlay); + } + else + { + overlayManager.remove(overlay); + } + } + if (configChanged.getKey().equals("renderLootingBag")) + { + if (Boolean.parseBoolean(configChanged.getNewValue()) == true) + { + overlayManager.add(widgetOverlay); + } + else + { + overlayManager.remove(widgetOverlay); + } + } + } + + + /** + * @param widgetHiddenChanged + */ + @Subscribe + public void onWidgetHiddenChanged(WidgetHiddenChanged widgetHiddenChanged) + { + Widget widget = widgetHiddenChanged.getWidget(); + if (widget.getParentId() == 5308416 && !widget.isHidden()) + { + clientThread.invokeLater(() -> + { + Widget value = client.getWidget(81, 6); + if (!Strings.isNullOrEmpty(value.getText())) + { + String str = value.getText(); + str = str.replace("Bag value: ", "") + .replace("Value: ", "") + .replace(" coins", "") + .replace(",", ""); + + int val = Integer.parseInt(str); + setValueToShow(Math.round(val) / 1000); + } + }); + } + } + } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/lootingbagviewer/LootingBagViewerWidgetOverlay.java b/runelite-client/src/main/java/net/runelite/client/plugins/lootingbagviewer/LootingBagViewerWidgetOverlay.java new file mode 100644 index 0000000000..00c716f2fb --- /dev/null +++ b/runelite-client/src/main/java/net/runelite/client/plugins/lootingbagviewer/LootingBagViewerWidgetOverlay.java @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2019, gazivodag + * 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.lootingbagviewer; + +import java.awt.Color; +import java.awt.Graphics2D; +import javax.inject.Inject; +import net.runelite.api.Client; +import net.runelite.api.ItemID; +import net.runelite.api.Point; +import net.runelite.api.widgets.WidgetItem; +import net.runelite.client.ui.overlay.OverlayUtil; +import net.runelite.client.ui.overlay.WidgetItemOverlay; + +public class LootingBagViewerWidgetOverlay extends WidgetItemOverlay +{ + private Client client; + private LootingBagViewerPlugin plugin; + + @Inject + LootingBagViewerWidgetOverlay(Client client, LootingBagViewerPlugin plugin) + { + this.client = client; + this.plugin = plugin; + showOnInventory(); + } + + @Override + public void renderItemOverlay(Graphics2D graphics, int itemId, WidgetItem itemWidget) + { + if (plugin.getValueToShow() != -1) + { + switch (itemId) + { + case ItemID.LOOTING_BAG: + case ItemID.LOOTING_BAG_22586: + Point point = new Point(itemWidget.getCanvasLocation().getX() + lineX(plugin.getValueToShow()), itemWidget.getCanvasLocation().getY() + 25); + OverlayUtil.renderTextLocation(graphics, point, (plugin.getValueToShow() + "K"), Color.WHITE); + break; + } + } + } + + /** + * To align 16k (gp) or 4213k (gp) correctly between the looting bag without looking off + * + * @return + */ + private static int lineX(int lootingBagValue) + { + switch ((int) (Math.log10(lootingBagValue) + 1)) + { + case 1: + case 2: + return 8; + case 3: + case 4: + return 6; + default: + return 8; + } + } +}