From 9b9aee3e2b7264057e068fd906cc068f1f68c959 Mon Sep 17 00:00:00 2001 From: Adam Date: Wed, 10 Apr 2019 19:16:37 -0400 Subject: [PATCH 1/3] Add WidgetItemOverlay This simplifies the logic required for plugins to draw an overlay over an item. --- .../net/runelite/api/hooks/Callbacks.java | 6 ++ .../net/runelite/api/widgets/WidgetItem.java | 18 +---- .../net/runelite/client/callback/Hooks.java | 18 +++++ .../client/ui/overlay/OverlayManager.java | 9 +++ .../client/ui/overlay/WidgetItemOverlay.java | 78 +++++++++++++++++++ .../net/runelite/mixins/RSClientMixin.java | 34 +++++++- 6 files changed, 145 insertions(+), 18 deletions(-) create mode 100644 runelite-client/src/main/java/net/runelite/client/ui/overlay/WidgetItemOverlay.java diff --git a/runelite-api/src/main/java/net/runelite/api/hooks/Callbacks.java b/runelite-api/src/main/java/net/runelite/api/hooks/Callbacks.java index 9a1a6eb3cb..b6960d761f 100644 --- a/runelite-api/src/main/java/net/runelite/api/hooks/Callbacks.java +++ b/runelite-api/src/main/java/net/runelite/api/hooks/Callbacks.java @@ -29,6 +29,7 @@ import java.awt.event.KeyEvent; import java.awt.event.MouseEvent; import java.awt.event.MouseWheelEvent; import net.runelite.api.MainBufferProvider; +import net.runelite.api.widgets.WidgetItem; /** * Interface of callbacks the injected client uses to send events @@ -79,6 +80,11 @@ public interface Callbacks */ void draw(MainBufferProvider mainBufferProvider, Graphics graphics, int x, int y); + /** + * Called before the client will render an item widget. + */ + void drawItem(int itemId, WidgetItem widgetItem); + /** * Mouse pressed event. If this event will be consumed it will not be propagated further to client. * diff --git a/runelite-api/src/main/java/net/runelite/api/widgets/WidgetItem.java b/runelite-api/src/main/java/net/runelite/api/widgets/WidgetItem.java index fbbc8938f2..51f63ad40f 100644 --- a/runelite-api/src/main/java/net/runelite/api/widgets/WidgetItem.java +++ b/runelite-api/src/main/java/net/runelite/api/widgets/WidgetItem.java @@ -25,11 +25,15 @@ package net.runelite.api.widgets; import java.awt.Rectangle; +import lombok.AllArgsConstructor; +import lombok.ToString; import net.runelite.api.Point; /** * An item that is being represented in a {@link Widget}. */ +@AllArgsConstructor +@ToString public class WidgetItem { private final int id; @@ -37,20 +41,6 @@ public class WidgetItem private final int index; private final Rectangle canvasBounds; - public WidgetItem(int id, int quantity, int index, Rectangle canvasBounds) - { - this.id = id; - this.quantity = quantity; - this.index = index; - this.canvasBounds = canvasBounds; - } - - @Override - public String toString() - { - return "WidgetItem{" + "id=" + id + ", quantity=" + quantity + ", index=" + index + ", canvasBounds=" + canvasBounds + '}'; - } - /** * Gets the ID of the item represented. * diff --git a/runelite-client/src/main/java/net/runelite/client/callback/Hooks.java b/runelite-client/src/main/java/net/runelite/client/callback/Hooks.java index 08cd4ea3fe..ae1dff022f 100644 --- a/runelite-client/src/main/java/net/runelite/client/callback/Hooks.java +++ b/runelite-client/src/main/java/net/runelite/client/callback/Hooks.java @@ -43,6 +43,7 @@ import lombok.extern.slf4j.Slf4j; import net.runelite.api.BufferProvider; import net.runelite.api.Client; import net.runelite.api.MainBufferProvider; +import net.runelite.api.NullItemID; import net.runelite.api.RenderOverview; import net.runelite.api.Renderable; import net.runelite.api.WorldMapManager; @@ -52,6 +53,7 @@ import net.runelite.api.hooks.Callbacks; import net.runelite.api.hooks.DrawCallbacks; import net.runelite.api.widgets.Widget; import static net.runelite.api.widgets.WidgetInfo.WORLD_MAP_VIEW; +import net.runelite.api.widgets.WidgetItem; import net.runelite.client.Notifier; import net.runelite.client.RuneLite; import net.runelite.client.chat.ChatMessageManager; @@ -62,6 +64,7 @@ import net.runelite.client.task.Scheduler; import net.runelite.client.ui.ClientUI; import net.runelite.client.ui.DrawManager; import net.runelite.client.ui.overlay.OverlayLayer; +import net.runelite.client.ui.overlay.OverlayManager; import net.runelite.client.ui.overlay.OverlayRenderer; import net.runelite.client.ui.overlay.infobox.InfoBoxManager; import net.runelite.client.util.DeferredEventBus; @@ -80,6 +83,7 @@ public class Hooks implements Callbacks private static final Injector injector = RuneLite.getInjector(); private static final Client client = injector.getInstance(Client.class); private static final OverlayRenderer renderer = injector.getInstance(OverlayRenderer.class); + private static final OverlayManager overlayManager = injector.getInstance(OverlayManager.class); private static final GameTick GAME_TICK = new GameTick(); private static final BeforeRender BEFORE_RENDER = new BeforeRender(); @@ -443,6 +447,10 @@ public class Hooks implements Callbacks { graphics2d.dispose(); } + + // WidgetItemOverlays render at ABOVE_WIDGETS, reset widget item + // list for next frame. + overlayManager.getItemWidgets().clear(); } @Override @@ -490,4 +498,14 @@ public class Hooks implements Callbacks pixelPos += pixelJump; } } + + @Override + public void drawItem(int itemId, WidgetItem widgetItem) + { + // Empty bank item + if (widgetItem.getId() != NullItemID.NULL_6512) + { + overlayManager.getItemWidgets().add(widgetItem); + } + } } diff --git a/runelite-client/src/main/java/net/runelite/client/ui/overlay/OverlayManager.java b/runelite-client/src/main/java/net/runelite/client/ui/overlay/OverlayManager.java index 5ee3303462..5a6e240f90 100644 --- a/runelite-client/src/main/java/net/runelite/client/ui/overlay/OverlayManager.java +++ b/runelite-client/src/main/java/net/runelite/client/ui/overlay/OverlayManager.java @@ -41,6 +41,7 @@ import lombok.AccessLevel; import lombok.Getter; import net.runelite.api.MenuAction; import net.runelite.api.events.MenuOptionClicked; +import net.runelite.api.widgets.WidgetItem; import net.runelite.client.config.ConfigGroup; import net.runelite.client.config.ConfigManager; import net.runelite.client.config.RuneLiteConfig; @@ -96,6 +97,8 @@ public class OverlayManager */ @Getter(AccessLevel.PACKAGE) private final List overlays = new ArrayList<>(); + @Getter + private final List itemWidgets = new ArrayList<>(); private final Map> overlayLayers = new EnumMap<>(OverlayLayer.class); @@ -168,6 +171,12 @@ public class OverlayManager // Add is always true overlays.add(overlay); loadOverlay(overlay); + // WidgetItemOverlays have a reference to the overlay manager in order to get the WidgetItems + // for each frame. + if (overlay instanceof WidgetItemOverlay) + { + ((WidgetItemOverlay) overlay).setOverlayManager(this); + } rebuildOverlayLayers(); return true; } diff --git a/runelite-client/src/main/java/net/runelite/client/ui/overlay/WidgetItemOverlay.java b/runelite-client/src/main/java/net/runelite/client/ui/overlay/WidgetItemOverlay.java new file mode 100644 index 0000000000..0eaae6e50b --- /dev/null +++ b/runelite-client/src/main/java/net/runelite/client/ui/overlay/WidgetItemOverlay.java @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2019, Adam + * 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.ui.overlay; + +import java.awt.Dimension; +import java.awt.Graphics2D; +import java.util.List; +import lombok.AccessLevel; +import lombok.Setter; +import net.runelite.api.widgets.WidgetItem; + +public abstract class WidgetItemOverlay extends Overlay +{ + @Setter(AccessLevel.PACKAGE) + private OverlayManager overlayManager; + + protected WidgetItemOverlay() + { + super.setPosition(OverlayPosition.DYNAMIC); + super.setPriority(OverlayPriority.LOW); + super.setLayer(OverlayLayer.ABOVE_WIDGETS); + } + + public abstract void renderItemOverlay(Graphics2D graphics, int itemId, WidgetItem itemWidget); + + @Override + public Dimension render(Graphics2D graphics) + { + final List itemWidgets = overlayManager.getItemWidgets(); + for (WidgetItem widget : itemWidgets) + { + renderItemOverlay(graphics, widget.getId(), widget); + } + return null; + } + + // Don't allow setting position, priority, or layer + + @Override + public void setPosition(OverlayPosition position) + { + throw new IllegalStateException(); + } + + @Override + public void setPriority(OverlayPriority priority) + { + throw new IllegalStateException(); + } + + @Override + public void setLayer(OverlayLayer layer) + { + throw new IllegalStateException(); + } +} 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 6c3d1f1ae0..56b9190ead 100644 --- a/runelite-mixins/src/main/java/net/runelite/mixins/RSClientMixin.java +++ b/runelite-mixins/src/main/java/net/runelite/mixins/RSClientMixin.java @@ -28,6 +28,7 @@ import com.google.common.cache.Cache; import com.google.common.cache.CacheBuilder; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collection; import java.util.EnumSet; import java.util.List; import java.util.Map; @@ -108,6 +109,8 @@ import net.runelite.api.mixins.Shadow; import net.runelite.api.vars.AccountType; import net.runelite.api.widgets.Widget; import net.runelite.api.widgets.WidgetInfo; +import net.runelite.api.widgets.WidgetItem; +import net.runelite.api.widgets.WidgetType; import net.runelite.rs.api.RSChatLineBuffer; import net.runelite.rs.api.RSClanMemberManager; import net.runelite.rs.api.RSClient; @@ -1324,8 +1327,11 @@ public abstract class RSClientMixin implements RSClient @MethodHook("renderWidgetLayer") @Inject - public static void renderWidgetLayer(Widget[] widgets, int parentId, int var2, int var3, int var4, int var5, int x, int y, int var8) + public static void renderWidgetLayer(Widget[] widgets, int parentId, int minX, int minY, int maxX, int maxY, int x, int y, int var8) { + Callbacks callbacks = client.getCallbacks(); + HashTable componentTable = client.getComponentTable(); + for (Widget rlWidget : widgets) { RSWidget widget = (RSWidget) rlWidget; @@ -1338,10 +1344,30 @@ public abstract class RSClientMixin implements RSClient { widget.setRenderParentId(parentId); } - widget.setRenderX(x + widget.getRelativeX()); - widget.setRenderY(y + widget.getRelativeY()); - HashTable componentTable = client.getComponentTable(); + final int renderX = x + widget.getRelativeX(); + final int renderY = y + widget.getRelativeY(); + widget.setRenderX(renderX); + widget.setRenderY(renderY); + + final int widgetType = widget.getType(); + if (widgetType == WidgetType.GRAPHIC && widget.getItemId() != -1) + { + if (renderX >= minX && renderX <= maxX && renderY >= minY && renderY <= maxY) + { + WidgetItem widgetItem = new WidgetItem(widget.getItemId(), widget.getItemQuantity(), -1, widget.getBounds()); + callbacks.drawItem(widget.getItemId(), widgetItem); + } + } + else if (widgetType == WidgetType.INVENTORY) + { + Collection widgetItems = widget.getWidgetItems(); + for (WidgetItem widgetItem : widgetItems) + { + callbacks.drawItem(widgetItem.getId(), widgetItem); + } + } + WidgetNode childNode = componentTable.get(widget.getId()); if (childNode != null) { From f661cc68695a6bfc306a3dc9bf305af96358507f Mon Sep 17 00:00:00 2001 From: Adam Date: Wed, 10 Apr 2019 19:16:43 -0400 Subject: [PATCH 2/3] client: modify plugins to use WidgetItemOverlay --- .../inventorytags/InventoryTagsOverlay.java | 50 ++---- .../inventorytags/InventoryTagsPlugin.java | 56 +----- .../itemcharges/ItemChargeOverlay.java | 136 ++++++--------- .../plugins/runepouch/RunepouchOverlay.java | 35 +--- .../client/plugins/slayer/SlayerOverlay.java | 160 +++++++----------- 5 files changed, 138 insertions(+), 299 deletions(-) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/inventorytags/InventoryTagsOverlay.java b/runelite-client/src/main/java/net/runelite/client/plugins/inventorytags/InventoryTagsOverlay.java index a759520dea..99798156ad 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/inventorytags/InventoryTagsOverlay.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/inventorytags/InventoryTagsOverlay.java @@ -25,65 +25,39 @@ package net.runelite.client.plugins.inventorytags; import java.awt.Color; -import java.awt.Dimension; import java.awt.Graphics2D; +import java.awt.Rectangle; import java.awt.image.BufferedImage; import javax.inject.Inject; -import net.runelite.api.Query; -import net.runelite.api.queries.InventoryWidgetItemQuery; import net.runelite.api.widgets.WidgetItem; import net.runelite.client.game.ItemManager; -import net.runelite.client.ui.overlay.Overlay; -import net.runelite.client.ui.overlay.OverlayLayer; -import net.runelite.client.ui.overlay.OverlayPosition; -import net.runelite.client.ui.overlay.OverlayPriority; -import net.runelite.client.util.QueryRunner; +import net.runelite.client.ui.overlay.WidgetItemOverlay; -public class InventoryTagsOverlay extends Overlay +public class InventoryTagsOverlay extends WidgetItemOverlay { - private final QueryRunner queryRunner; private final ItemManager itemManager; private final InventoryTagsPlugin plugin; @Inject - private InventoryTagsOverlay(QueryRunner queryRunner, ItemManager itemManager, InventoryTagsPlugin plugin) + private InventoryTagsOverlay(ItemManager itemManager, InventoryTagsPlugin plugin) { - setPosition(OverlayPosition.DYNAMIC); - setPriority(OverlayPriority.LOW); - setLayer(OverlayLayer.ABOVE_WIDGETS); - this.queryRunner = queryRunner; this.itemManager = itemManager; this.plugin = plugin; } @Override - public Dimension render(Graphics2D graphics) + public void renderItemOverlay(Graphics2D graphics, int itemId, WidgetItem itemWidget) { - if (!plugin.isHasTaggedItems()) + final String group = plugin.getTag(itemId); + if (group != null) { - return null; - } - - // Now query the inventory for the tagged item ids - final Query query = new InventoryWidgetItemQuery(); - final WidgetItem[] widgetItems = queryRunner.runQuery(query); - - // Iterate through all found items and draw the outlines - for (final WidgetItem item : widgetItems) - { - final String group = plugin.getTag(item.getId()); - - if (group != null) + final Color color = plugin.getGroupNameColor(group); + if (color != null) { - final Color color = plugin.getGroupNameColor(group); - if (color != null) - { - final BufferedImage outline = itemManager.getItemOutline(item.getId(), item.getQuantity(), color); - graphics.drawImage(outline, item.getCanvasLocation().getX() + 1, item.getCanvasLocation().getY() + 1, null); - } + Rectangle bounds = itemWidget.getCanvasBounds(); + final BufferedImage outline = itemManager.getItemOutline(itemId, itemWidget.getQuantity(), color); + graphics.drawImage(outline, (int) bounds.getX() + 1, (int) bounds.getY() + 1, null); } } - - return null; } } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/inventorytags/InventoryTagsPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/inventorytags/InventoryTagsPlugin.java index c513ebe3d5..4683328550 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/inventorytags/InventoryTagsPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/inventorytags/InventoryTagsPlugin.java @@ -30,15 +30,9 @@ import com.google.inject.Provides; import java.awt.Color; import java.util.List; import javax.inject.Inject; -import lombok.AccessLevel; -import lombok.Getter; import net.runelite.api.Client; -import net.runelite.api.InventoryID; -import net.runelite.api.Item; -import net.runelite.api.ItemContainer; import net.runelite.api.MenuAction; import net.runelite.api.MenuEntry; -import net.runelite.api.events.ItemContainerChanged; import net.runelite.api.events.MenuOpened; import net.runelite.api.events.MenuOptionClicked; import net.runelite.api.events.WidgetMenuOptionClicked; @@ -107,9 +101,6 @@ public class InventoryTagsPlugin extends Plugin @Inject private OverlayManager overlayManager; - @Getter(AccessLevel.PACKAGE) - private boolean hasTaggedItems; - private boolean editorMode; @Provides @@ -151,7 +142,7 @@ public class InventoryTagsPlugin extends Plugin { removeInventoryMenuOptions(); overlayManager.remove(overlay); - hasTaggedItems = editorMode = false; + editorMode = false; } @Subscribe @@ -179,14 +170,10 @@ public class InventoryTagsPlugin extends Plugin if (event.getMenuOption().equals(MENU_SET)) { setTag(event.getId(), selectedMenu); - - hasTaggedItems = true; } else if (event.getMenuOption().equals(MENU_REMOVE)) { unsetTag(event.getId()); - - checkForTags(client.getItemContainer(InventoryID.INVENTORY)); } } @@ -235,47 +222,6 @@ public class InventoryTagsPlugin extends Plugin } } - @Subscribe - public void onItemContainerChanged(ItemContainerChanged itemContainerChanged) - { - ItemContainer itemContainer = itemContainerChanged.getItemContainer(); - if (itemContainer == client.getItemContainer(InventoryID.INVENTORY)) - { - checkForTags(itemContainer); - } - } - - private void checkForTags(ItemContainer itemContainer) - { - hasTaggedItems = false; - - if (itemContainer == null) - { - return; - } - - Item[] items = itemContainer.getItems(); - if (items != null) - { - for (Item item : items) - { - if (item == null) - { - continue; - } - - String tag = getTag(item.getId()); - if (tag == null) - { - continue; - } - - hasTaggedItems = true; - return; - } - } - } - Color getGroupNameColor(final String name) { switch (name) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/itemcharges/ItemChargeOverlay.java b/runelite-client/src/main/java/net/runelite/client/plugins/itemcharges/ItemChargeOverlay.java index ca289d4013..a37570aa22 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/itemcharges/ItemChargeOverlay.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/itemcharges/ItemChargeOverlay.java @@ -24,125 +24,93 @@ */ package net.runelite.client.plugins.itemcharges; -import java.awt.Dimension; import java.awt.Graphics2D; import java.awt.Point; import java.awt.Rectangle; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; import javax.inject.Inject; import net.runelite.api.ItemID; -import net.runelite.api.Query; -import net.runelite.api.queries.EquipmentItemQuery; -import net.runelite.api.queries.InventoryWidgetItemQuery; -import net.runelite.api.widgets.WidgetInfo; import net.runelite.api.widgets.WidgetItem; -import static net.runelite.client.plugins.itemcharges.ItemChargeType.*; +import static net.runelite.client.plugins.itemcharges.ItemChargeType.ABYSSAL_BRACELET; +import static net.runelite.client.plugins.itemcharges.ItemChargeType.BELLOWS; +import static net.runelite.client.plugins.itemcharges.ItemChargeType.FUNGICIDE_SPRAY; +import static net.runelite.client.plugins.itemcharges.ItemChargeType.IMPBOX; +import static net.runelite.client.plugins.itemcharges.ItemChargeType.TELEPORT; +import static net.runelite.client.plugins.itemcharges.ItemChargeType.WATERCAN; +import static net.runelite.client.plugins.itemcharges.ItemChargeType.WATERSKIN; import net.runelite.client.ui.FontManager; -import net.runelite.client.ui.overlay.Overlay; -import net.runelite.client.ui.overlay.OverlayLayer; -import net.runelite.client.ui.overlay.OverlayPosition; +import net.runelite.client.ui.overlay.WidgetItemOverlay; import net.runelite.client.ui.overlay.components.TextComponent; -import net.runelite.client.util.QueryRunner; -class ItemChargeOverlay extends Overlay +class ItemChargeOverlay extends WidgetItemOverlay { - private final QueryRunner queryRunner; private final ItemChargePlugin itemChargePlugin; private final ItemChargeConfig config; @Inject - ItemChargeOverlay(QueryRunner queryRunner, ItemChargePlugin itemChargePlugin, ItemChargeConfig config) + ItemChargeOverlay(ItemChargePlugin itemChargePlugin, ItemChargeConfig config) { - setPosition(OverlayPosition.DYNAMIC); - setLayer(OverlayLayer.ABOVE_WIDGETS); - this.queryRunner = queryRunner; this.itemChargePlugin = itemChargePlugin; this.config = config; } @Override - public Dimension render(Graphics2D graphics) + public void renderItemOverlay(Graphics2D graphics, int itemId, WidgetItem itemWidget) { if (!displayOverlay()) { - return null; + return; } graphics.setFont(FontManager.getRunescapeSmallFont()); - for (WidgetItem item : getChargeWidgetItems()) + int charges; + if (itemId == ItemID.DODGY_NECKLACE) { - int charges; - if (item.getId() == ItemID.DODGY_NECKLACE) + if (!config.showDodgyCount()) { - if (!config.showDodgyCount()) - { - continue; - } - - charges = config.dodgyNecklace(); - } - else if (item.getId() == ItemID.BINDING_NECKLACE) - { - if (!config.showBindingNecklaceCharges()) - { - continue; - } - - charges = config.bindingNecklace(); - } - else - { - ItemWithCharge chargeItem = ItemWithCharge.findItem(item.getId()); - if (chargeItem == null) - { - continue; - } - - ItemChargeType type = chargeItem.getType(); - if ((type == TELEPORT && !config.showTeleportCharges()) - || (type == FUNGICIDE_SPRAY && !config.showFungicideCharges()) - || (type == IMPBOX && !config.showImpCharges()) - || (type == WATERCAN && !config.showWateringCanCharges()) - || (type == WATERSKIN && !config.showWaterskinCharges()) - || (type == BELLOWS && !config.showBellowCharges()) - || (type == ABYSSAL_BRACELET && !config.showAbyssalBraceletCharges())) - { - continue; - } - - charges = chargeItem.getCharges(); + return; } - final Rectangle bounds = item.getCanvasBounds(); - final TextComponent textComponent = new TextComponent(); - textComponent.setPosition(new Point(bounds.x, bounds.y + 16)); - textComponent.setText(charges < 0 ? "?" : String.valueOf(charges)); - textComponent.setColor(itemChargePlugin.getColor(charges)); - textComponent.render(graphics); + charges = config.dodgyNecklace(); } - return null; - } + else if (itemId == ItemID.BINDING_NECKLACE) + { + if (!config.showBindingNecklaceCharges()) + { + return; + } - private Collection getChargeWidgetItems() - { - Query inventoryQuery = new InventoryWidgetItemQuery(); - WidgetItem[] inventoryWidgetItems = queryRunner.runQuery(inventoryQuery); + charges = config.bindingNecklace(); + } + else + { + ItemWithCharge chargeItem = ItemWithCharge.findItem(itemId); + if (chargeItem == null) + { + return; + } - Query equipmentQuery = new EquipmentItemQuery().slotEquals( - WidgetInfo.EQUIPMENT_AMULET, - WidgetInfo.EQUIPMENT_RING, - WidgetInfo.EQUIPMENT_GLOVES, - WidgetInfo.EQUIPMENT_WEAPON - ); - WidgetItem[] equipmentWidgetItems = queryRunner.runQuery(equipmentQuery); + ItemChargeType type = chargeItem.getType(); + if ((type == TELEPORT && !config.showTeleportCharges()) + || (type == FUNGICIDE_SPRAY && !config.showFungicideCharges()) + || (type == IMPBOX && !config.showImpCharges()) + || (type == WATERCAN && !config.showWateringCanCharges()) + || (type == WATERSKIN && !config.showWaterskinCharges()) + || (type == BELLOWS && !config.showBellowCharges()) + || (type == ABYSSAL_BRACELET && !config.showAbyssalBraceletCharges())) + { + return; + } - Collection jewellery = new ArrayList<>(); - jewellery.addAll(Arrays.asList(inventoryWidgetItems)); - jewellery.addAll(Arrays.asList(equipmentWidgetItems)); - return jewellery; + charges = chargeItem.getCharges(); + } + + final Rectangle bounds = itemWidget.getCanvasBounds(); + final TextComponent textComponent = new TextComponent(); + textComponent.setPosition(new Point(bounds.x, bounds.y + 16)); + textComponent.setText(charges < 0 ? "?" : String.valueOf(charges)); + textComponent.setColor(itemChargePlugin.getColor(charges)); + textComponent.render(graphics); } private boolean displayOverlay() diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/runepouch/RunepouchOverlay.java b/runelite-client/src/main/java/net/runelite/client/plugins/runepouch/RunepouchOverlay.java index 9eac070c94..17486efe0d 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/runepouch/RunepouchOverlay.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/runepouch/RunepouchOverlay.java @@ -32,24 +32,19 @@ import javax.inject.Inject; import net.runelite.api.Client; import net.runelite.api.ItemID; import net.runelite.api.Point; -import net.runelite.api.Query; import net.runelite.api.Varbits; -import net.runelite.api.queries.InventoryWidgetItemQuery; import net.runelite.api.widgets.WidgetItem; import net.runelite.client.game.ItemManager; import static net.runelite.client.plugins.runepouch.config.RunePouchOverlayMode.BOTH; import static net.runelite.client.plugins.runepouch.config.RunePouchOverlayMode.MOUSE_HOVER; import net.runelite.client.ui.FontManager; -import net.runelite.client.ui.overlay.Overlay; -import net.runelite.client.ui.overlay.OverlayLayer; -import net.runelite.client.ui.overlay.OverlayPosition; import net.runelite.client.ui.overlay.OverlayUtil; +import net.runelite.client.ui.overlay.WidgetItemOverlay; import net.runelite.client.ui.overlay.tooltip.Tooltip; import net.runelite.client.ui.overlay.tooltip.TooltipManager; import net.runelite.client.util.ColorUtil; -import net.runelite.client.util.QueryRunner; -public class RunepouchOverlay extends Overlay +public class RunepouchOverlay extends WidgetItemOverlay { private static final Varbits[] AMOUNT_VARBITS = { @@ -61,8 +56,6 @@ public class RunepouchOverlay extends Overlay }; private static final Dimension IMAGE_SIZE = new Dimension(11, 11); - - private final QueryRunner queryRunner; private final Client client; private final RunepouchConfig config; private final TooltipManager tooltipManager; @@ -71,37 +64,26 @@ public class RunepouchOverlay extends Overlay private ItemManager itemManager; @Inject - RunepouchOverlay(QueryRunner queryRunner, Client client, RunepouchConfig config, TooltipManager tooltipManager) + RunepouchOverlay(Client client, RunepouchConfig config, TooltipManager tooltipManager) { - setPosition(OverlayPosition.DYNAMIC); - setLayer(OverlayLayer.ABOVE_WIDGETS); this.tooltipManager = tooltipManager; - this.queryRunner = queryRunner; this.client = client; this.config = config; } @Override - public Dimension render(Graphics2D graphics) + public void renderItemOverlay(Graphics2D graphics, int itemId, WidgetItem itemWidget) { - Query query = new InventoryWidgetItemQuery().idEquals(ItemID.RUNE_POUCH); - WidgetItem[] items = queryRunner.runQuery(query); - if (items.length == 0) + if (itemId != ItemID.RUNE_POUCH) { - return null; - } - - WidgetItem runePouch = items[0]; - Point location = runePouch.getCanvasLocation(); - if (location == null) - { - return null; + return; } assert AMOUNT_VARBITS.length == RUNE_VARBITS.length; graphics.setFont(FontManager.getRunescapeSmallFont()); + Point location = itemWidget.getCanvasLocation(); StringBuilder tooltipBuilder = new StringBuilder(); for (int i = 0; i < AMOUNT_VARBITS.length; i++) @@ -158,12 +140,11 @@ public class RunepouchOverlay extends Overlay String tooltip = tooltipBuilder.toString(); if (!tooltip.isEmpty() - && runePouch.getCanvasBounds().contains(client.getMouseCanvasPosition().getX(), client.getMouseCanvasPosition().getY()) + && itemWidget.getCanvasBounds().contains(client.getMouseCanvasPosition().getX(), client.getMouseCanvasPosition().getY()) && (config.runePouchOverlayMode() == MOUSE_HOVER || config.runePouchOverlayMode() == BOTH)) { tooltipManager.add(new Tooltip(tooltip)); } - return null; } private BufferedImage getRuneImage(Runes rune) diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/slayer/SlayerOverlay.java b/runelite-client/src/main/java/net/runelite/client/plugins/slayer/SlayerOverlay.java index 675381b1fb..e8c49b20a0 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/slayer/SlayerOverlay.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/slayer/SlayerOverlay.java @@ -24,111 +24,88 @@ */ package net.runelite.client.plugins.slayer; -import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; -import static com.google.common.collect.ObjectArrays.concat; -import java.awt.Dimension; import java.awt.Graphics2D; import java.awt.Point; import java.awt.Rectangle; import java.util.Set; import javax.inject.Inject; -import com.google.common.primitives.ImmutableIntArray; import net.runelite.api.ItemID; -import net.runelite.api.Query; -import net.runelite.api.queries.EquipmentItemQuery; -import net.runelite.api.queries.InventoryWidgetItemQuery; -import net.runelite.api.widgets.WidgetInfo; import net.runelite.api.widgets.WidgetItem; import net.runelite.client.ui.FontManager; -import net.runelite.client.ui.overlay.Overlay; -import net.runelite.client.ui.overlay.OverlayLayer; -import net.runelite.client.ui.overlay.OverlayPosition; +import net.runelite.client.ui.overlay.WidgetItemOverlay; import net.runelite.client.ui.overlay.components.TextComponent; -import net.runelite.client.util.QueryRunner; -class SlayerOverlay extends Overlay +class SlayerOverlay extends WidgetItemOverlay { private final static Set SLAYER_JEWELRY = ImmutableSet.of( - ItemID.SLAYER_RING_1, - ItemID.SLAYER_RING_2, - ItemID.SLAYER_RING_3, - ItemID.SLAYER_RING_4, - ItemID.SLAYER_RING_5, - ItemID.SLAYER_RING_6, - ItemID.SLAYER_RING_7, - ItemID.SLAYER_RING_8 + ItemID.SLAYER_RING_1, + ItemID.SLAYER_RING_2, + ItemID.SLAYER_RING_3, + ItemID.SLAYER_RING_4, + ItemID.SLAYER_RING_5, + ItemID.SLAYER_RING_6, + ItemID.SLAYER_RING_7, + ItemID.SLAYER_RING_8 ); - private final static ImmutableIntArray ALL_SLAYER_ITEMS = ImmutableIntArray.of( - ItemID.SLAYER_HELMET, - ItemID.SLAYER_HELMET_I, - ItemID.BLACK_SLAYER_HELMET, - ItemID.BLACK_SLAYER_HELMET_I, - ItemID.GREEN_SLAYER_HELMET, - ItemID.GREEN_SLAYER_HELMET_I, - ItemID.PURPLE_SLAYER_HELMET, - ItemID.PURPLE_SLAYER_HELMET_I, - ItemID.RED_SLAYER_HELMET, - ItemID.RED_SLAYER_HELMET_I, - ItemID.TURQUOISE_SLAYER_HELMET, - ItemID.TURQUOISE_SLAYER_HELMET_I, - ItemID.HYDRA_SLAYER_HELMET, - ItemID.HYDRA_SLAYER_HELMET_I, - ItemID.SLAYER_RING_ETERNAL, - ItemID.ENCHANTED_GEM, - ItemID.ETERNAL_GEM, - ItemID.BRACELET_OF_SLAUGHTER, - ItemID.EXPEDITIOUS_BRACELET, - ItemID.SLAYER_RING_1, - ItemID.SLAYER_RING_2, - ItemID.SLAYER_RING_3, - ItemID.SLAYER_RING_4, - ItemID.SLAYER_RING_5, - ItemID.SLAYER_RING_6, - ItemID.SLAYER_RING_7, - ItemID.SLAYER_RING_8 + private final static Set ALL_SLAYER_ITEMS = ImmutableSet.of( + ItemID.SLAYER_HELMET, + ItemID.SLAYER_HELMET_I, + ItemID.BLACK_SLAYER_HELMET, + ItemID.BLACK_SLAYER_HELMET_I, + ItemID.GREEN_SLAYER_HELMET, + ItemID.GREEN_SLAYER_HELMET_I, + ItemID.PURPLE_SLAYER_HELMET, + ItemID.PURPLE_SLAYER_HELMET_I, + ItemID.RED_SLAYER_HELMET, + ItemID.RED_SLAYER_HELMET_I, + ItemID.TURQUOISE_SLAYER_HELMET, + ItemID.TURQUOISE_SLAYER_HELMET_I, + ItemID.HYDRA_SLAYER_HELMET, + ItemID.HYDRA_SLAYER_HELMET_I, + ItemID.SLAYER_RING_ETERNAL, + ItemID.ENCHANTED_GEM, + ItemID.ETERNAL_GEM, + ItemID.BRACELET_OF_SLAUGHTER, + ItemID.EXPEDITIOUS_BRACELET, + ItemID.SLAYER_RING_1, + ItemID.SLAYER_RING_2, + ItemID.SLAYER_RING_3, + ItemID.SLAYER_RING_4, + ItemID.SLAYER_RING_5, + ItemID.SLAYER_RING_6, + ItemID.SLAYER_RING_7, + ItemID.SLAYER_RING_8 ); private final SlayerConfig config; private final SlayerPlugin plugin; - private final QueryRunner queryRunner; @Inject - private SlayerOverlay(SlayerPlugin plugin, SlayerConfig config, QueryRunner queryRunner) + private SlayerOverlay(SlayerPlugin plugin, SlayerConfig config) { - setPosition(OverlayPosition.DYNAMIC); - setLayer(OverlayLayer.ABOVE_WIDGETS); this.plugin = plugin; this.config = config; - this.queryRunner = queryRunner; - } - - private ImmutableList getSlayerItems() - { - int[] slayerItems = ALL_SLAYER_ITEMS.toArray(); - Query inventoryQuery = new InventoryWidgetItemQuery().idEquals(slayerItems); - WidgetItem[] inventoryWidgetItems = queryRunner.runQuery(inventoryQuery); - - Query equipmentQuery = new EquipmentItemQuery().slotEquals(WidgetInfo.EQUIPMENT_HELMET, WidgetInfo.EQUIPMENT_RING, WidgetInfo.EQUIPMENT_GLOVES).idEquals(slayerItems); - WidgetItem[] equipmentWidgetItems = queryRunner.runQuery(equipmentQuery); - - WidgetItem[] items = concat(inventoryWidgetItems, equipmentWidgetItems, WidgetItem.class); - return ImmutableList.copyOf(items); } @Override - public Dimension render(Graphics2D graphics) + public void renderItemOverlay(Graphics2D graphics, int itemId, WidgetItem itemWidget) { + if (!ALL_SLAYER_ITEMS.contains(itemId)) + { + return; + } + if (!config.showItemOverlay()) { - return null; + return; } int amount = plugin.getAmount(); if (amount <= 0) { - return null; + return; } int slaughterCount = plugin.getSlaughterChargeCount(); @@ -136,33 +113,26 @@ class SlayerOverlay extends Overlay graphics.setFont(FontManager.getRunescapeSmallFont()); - for (WidgetItem item : getSlayerItems()) + final Rectangle bounds = itemWidget.getCanvasBounds(); + final TextComponent textComponent = new TextComponent(); + + switch (itemId) { - int itemId = item.getId(); - - final Rectangle bounds = item.getCanvasBounds(); - final TextComponent textComponent = new TextComponent(); - - switch (item.getId()) - { - case ItemID.EXPEDITIOUS_BRACELET: - textComponent.setText(String.valueOf(expeditiousCount)); - break; - case ItemID.BRACELET_OF_SLAUGHTER: - textComponent.setText(String.valueOf(slaughterCount)); - break; - default: - textComponent.setText(String.valueOf(amount)); - break; - } - - // Draw the counter in the bottom left for equipment, and top left for jewelry - textComponent.setPosition(new Point(bounds.x, bounds.y + (SLAYER_JEWELRY.contains(itemId) - ? bounds.height - : graphics.getFontMetrics().getHeight()))); - textComponent.render(graphics); + case ItemID.EXPEDITIOUS_BRACELET: + textComponent.setText(String.valueOf(expeditiousCount)); + break; + case ItemID.BRACELET_OF_SLAUGHTER: + textComponent.setText(String.valueOf(slaughterCount)); + break; + default: + textComponent.setText(String.valueOf(amount)); + break; } - return null; + // Draw the counter in the bottom left for equipment, and top left for jewelry + textComponent.setPosition(new Point(bounds.x, bounds.y + (SLAYER_JEWELRY.contains(itemId) + ? bounds.height + : graphics.getFontMetrics().getHeight()))); + textComponent.render(graphics); } } From 99b513a8c5b9a4e947789e7161174cbf2f4d7f18 Mon Sep 17 00:00:00 2001 From: Adam Date: Wed, 10 Apr 2019 19:17:11 -0400 Subject: [PATCH 3/3] api: remove Query api --- .../runelite/api/queries/BankItemQuery.java | 78 -------------- .../api/queries/EquipmentItemQuery.java | 102 ------------------ .../api/queries/InventoryWidgetItemQuery.java | 95 ---------------- .../runelite/api/queries/ShopItemQuery.java | 71 ------------ .../runelite/api/queries/WidgetItemQuery.java | 74 ------------- .../net/runelite/client/RuneLiteModule.java | 2 - .../net/runelite/client/util/QueryRunner.java | 43 -------- 7 files changed, 465 deletions(-) delete mode 100644 runelite-api/src/main/java/net/runelite/api/queries/BankItemQuery.java delete mode 100644 runelite-api/src/main/java/net/runelite/api/queries/EquipmentItemQuery.java delete mode 100644 runelite-api/src/main/java/net/runelite/api/queries/InventoryWidgetItemQuery.java delete mode 100644 runelite-api/src/main/java/net/runelite/api/queries/ShopItemQuery.java delete mode 100644 runelite-api/src/main/java/net/runelite/api/queries/WidgetItemQuery.java delete mode 100644 runelite-client/src/main/java/net/runelite/client/util/QueryRunner.java diff --git a/runelite-api/src/main/java/net/runelite/api/queries/BankItemQuery.java b/runelite-api/src/main/java/net/runelite/api/queries/BankItemQuery.java deleted file mode 100644 index b0131dce32..0000000000 --- a/runelite-api/src/main/java/net/runelite/api/queries/BankItemQuery.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Copyright (c) 2017, Devin French - * 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.queries; - -import net.runelite.api.Client; -import net.runelite.api.widgets.Widget; -import net.runelite.api.widgets.WidgetInfo; -import net.runelite.api.widgets.WidgetItem; - -import java.awt.Rectangle; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Objects; - -public class BankItemQuery extends WidgetItemQuery -{ - private static final int ITEM_EMPTY = 6512; - - @Override - public WidgetItem[] result(Client client) - { - Collection widgetItems = getBankItems(client); - if (widgetItems != null) - { - return widgetItems.stream() - .filter(Objects::nonNull) - .filter(predicate) - .toArray(WidgetItem[]::new); - } - return new WidgetItem[0]; - } - - private Collection getBankItems(Client client) - { - Collection widgetItems = new ArrayList<>(); - Widget bank = client.getWidget(WidgetInfo.BANK_ITEM_CONTAINER); - if (bank != null && !bank.isHidden()) - { - Widget[] children = bank.getDynamicChildren(); - for (int i = 0; i < children.length; i++) - { - Widget child = children[i]; - if (child.getItemId() == ITEM_EMPTY || child.isSelfHidden()) - { - continue; - } - // set bounds to same size as default inventory - Rectangle bounds = child.getBounds(); - bounds.setBounds(bounds.x - 1, bounds.y - 1, 32, 32); - // Index is set to 0 because the widget's index does not correlate to the order in the bank - widgetItems.add(new WidgetItem(child.getItemId(), child.getItemQuantity(), 0, bounds)); - } - } - return widgetItems; - } -} diff --git a/runelite-api/src/main/java/net/runelite/api/queries/EquipmentItemQuery.java b/runelite-api/src/main/java/net/runelite/api/queries/EquipmentItemQuery.java deleted file mode 100644 index 210fc1e8d0..0000000000 --- a/runelite-api/src/main/java/net/runelite/api/queries/EquipmentItemQuery.java +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright (c) 2017, Devin French - * 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.queries; - -import net.runelite.api.Client; -import net.runelite.api.widgets.Widget; -import net.runelite.api.widgets.WidgetInfo; -import net.runelite.api.widgets.WidgetItem; - -import java.awt.Rectangle; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Objects; - -public class EquipmentItemQuery extends WidgetItemQuery -{ - private static final WidgetInfo[] ALL_EQUIPMENT_WIDGET_INFOS = - { - WidgetInfo.EQUIPMENT_HELMET, - WidgetInfo.EQUIPMENT_CAPE, - WidgetInfo.EQUIPMENT_AMULET, - WidgetInfo.EQUIPMENT_WEAPON, - WidgetInfo.EQUIPMENT_BODY, - WidgetInfo.EQUIPMENT_SHIELD, - WidgetInfo.EQUIPMENT_LEGS, - WidgetInfo.EQUIPMENT_GLOVES, - WidgetInfo.EQUIPMENT_BOOTS, - WidgetInfo.EQUIPMENT_RING, - WidgetInfo.EQUIPMENT_AMMO, - }; - - private final Collection slots = new ArrayList<>(); - - public EquipmentItemQuery slotEquals(WidgetInfo... slotWidgetInfo) - { - slots.addAll(Arrays.asList(slotWidgetInfo)); - return this; - } - - @Override - public WidgetItem[] result(Client client) - { - Collection widgetItems = getEquippedItems(client); - if (widgetItems != null) - { - return widgetItems.stream() - .filter(Objects::nonNull) - .filter(predicate) - .toArray(WidgetItem[]::new); - } - return new WidgetItem[0]; - } - - private Collection getEquippedItems(Client client) - { - Collection widgetItems = new ArrayList<>(); - Widget equipment = client.getWidget(WidgetInfo.EQUIPMENT); - if (equipment != null && !equipment.isHidden()) - { - if (slots.isEmpty()) - { - slots.addAll(Arrays.asList(ALL_EQUIPMENT_WIDGET_INFOS)); - } - for (WidgetInfo slot : slots) - { - Widget parentWidget = client.getWidget(slot); - Widget itemWidget = parentWidget.getChild(1); - // Check if background icon is hidden. if hidden, item is equipped. - boolean equipped = parentWidget.getChild(2).isSelfHidden(); - // set bounds to same size as default inventory - Rectangle bounds = itemWidget.getBounds(); - bounds.setBounds(bounds.x - 1, bounds.y - 1, 32, 32); - // Index is set to 0 because there is no set in stone order of equipment slots - widgetItems.add(new WidgetItem(equipped ? itemWidget.getItemId() : -1, itemWidget.getItemQuantity(), 0, bounds)); - } - } - return widgetItems; - } -} diff --git a/runelite-api/src/main/java/net/runelite/api/queries/InventoryWidgetItemQuery.java b/runelite-api/src/main/java/net/runelite/api/queries/InventoryWidgetItemQuery.java deleted file mode 100644 index 1872eeed65..0000000000 --- a/runelite-api/src/main/java/net/runelite/api/queries/InventoryWidgetItemQuery.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright (c) 2017, Devin French - * 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.queries; - -import net.runelite.api.Client; -import net.runelite.api.widgets.Widget; -import net.runelite.api.widgets.WidgetInfo; -import net.runelite.api.widgets.WidgetItem; - -import java.awt.Rectangle; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Objects; - -public class InventoryWidgetItemQuery extends WidgetItemQuery -{ - private static final WidgetInfo[] INVENTORY_WIDGET_INFOS = - { - WidgetInfo.DEPOSIT_BOX_INVENTORY_ITEMS_CONTAINER, - WidgetInfo.BANK_INVENTORY_ITEMS_CONTAINER, - WidgetInfo.SHOP_INVENTORY_ITEMS_CONTAINER, - WidgetInfo.GRAND_EXCHANGE_INVENTORY_ITEMS_CONTAINER, - WidgetInfo.GUIDE_PRICES_INVENTORY_ITEMS_CONTAINER, - WidgetInfo.EQUIPMENT_INVENTORY_ITEMS_CONTAINER, - WidgetInfo.INVENTORY - }; - - @Override - public WidgetItem[] result(Client client) - { - Collection widgetItems = getInventoryItems(client); - if (widgetItems != null) - { - return widgetItems.stream() - .filter(Objects::nonNull) - .filter(predicate) - .toArray(WidgetItem[]::new); - } - return new WidgetItem[0]; - } - - private Collection getInventoryItems(Client client) - { - Collection widgetItems = new ArrayList<>(); - for (WidgetInfo widgetInfo : INVENTORY_WIDGET_INFOS) - { - Widget inventory = client.getWidget(widgetInfo); - if (inventory == null || inventory.isHidden()) - { - continue; - } - if (widgetInfo == WidgetInfo.INVENTORY) - { - widgetItems.addAll(inventory.getWidgetItems()); - break; - } - else - { - Widget[] children = inventory.getDynamicChildren(); - for (int i = 0; i < children.length; i++) - { - Widget child = children[i]; - // set bounds to same size as default inventory - Rectangle bounds = child.getBounds(); - bounds.setBounds(bounds.x - 1, bounds.y - 1, 32, 32); - widgetItems.add(new WidgetItem(child.getItemId(), child.getItemQuantity(), i, bounds)); - } - break; - } - } - return widgetItems; - } -} diff --git a/runelite-api/src/main/java/net/runelite/api/queries/ShopItemQuery.java b/runelite-api/src/main/java/net/runelite/api/queries/ShopItemQuery.java deleted file mode 100644 index cd037f0a28..0000000000 --- a/runelite-api/src/main/java/net/runelite/api/queries/ShopItemQuery.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (c) 2017, Devin French - * 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.queries; - -import net.runelite.api.Client; -import net.runelite.api.widgets.Widget; -import net.runelite.api.widgets.WidgetInfo; -import net.runelite.api.widgets.WidgetItem; - -import java.awt.Rectangle; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Objects; - -public class ShopItemQuery extends WidgetItemQuery -{ - @Override - public WidgetItem[] result(Client client) - { - Collection widgetItems = getShopItems(client); - if (widgetItems != null) - { - return widgetItems.stream() - .filter(Objects::nonNull) - .filter(predicate) - .toArray(WidgetItem[]::new); - } - return new WidgetItem[0]; - } - - private Collection getShopItems(Client client) - { - Collection widgetItems = new ArrayList<>(); - Widget shop = client.getWidget(WidgetInfo.SHOP_ITEMS_CONTAINER); - if (shop != null && !shop.isHidden()) - { - Widget[] children = shop.getDynamicChildren(); - for (int i = 1; i < children.length; i++) - { - Widget child = children[i]; - // set bounds to same size as default inventory - Rectangle bounds = child.getBounds(); - bounds.setBounds(bounds.x - 1, bounds.y - 1, 32, 32); - widgetItems.add(new WidgetItem(child.getItemId(), child.getItemQuantity(), i - 1, bounds)); - } - } - return widgetItems; - } -} diff --git a/runelite-api/src/main/java/net/runelite/api/queries/WidgetItemQuery.java b/runelite-api/src/main/java/net/runelite/api/queries/WidgetItemQuery.java deleted file mode 100644 index 9a71a9bf3c..0000000000 --- a/runelite-api/src/main/java/net/runelite/api/queries/WidgetItemQuery.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright (c) 2017, Devin French - * 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.queries; - -import net.runelite.api.Client; -import net.runelite.api.Query; -import net.runelite.api.widgets.WidgetItem; - -public abstract class WidgetItemQuery extends Query -{ - - public WidgetItemQuery idEquals(int... ids) - { - predicate = and(item -> - { - for (int id : ids) - { - if (item.getId() == id) - { - return true; - } - } - return false; - }); - return this; - } - - public WidgetItemQuery indexEquals(int... indexes) - { - predicate = and(item -> - { - for (int index : indexes) - { - if (item.getIndex() == index) - { - return true; - } - } - return false; - }); - return this; - } - - public WidgetItemQuery quantityEquals(int quantity) - { - predicate = and(item -> item.getQuantity() == quantity); - return this; - } - - @Override - public abstract WidgetItem[] result(Client client); -} diff --git a/runelite-client/src/main/java/net/runelite/client/RuneLiteModule.java b/runelite-client/src/main/java/net/runelite/client/RuneLiteModule.java index 20384bffe8..af5e7e2631 100644 --- a/runelite-client/src/main/java/net/runelite/client/RuneLiteModule.java +++ b/runelite-client/src/main/java/net/runelite/client/RuneLiteModule.java @@ -50,7 +50,6 @@ import net.runelite.client.rs.ClientUpdateCheckMode; import net.runelite.client.task.Scheduler; import net.runelite.client.util.DeferredEventBus; import net.runelite.client.util.ExecutorServiceExceptionLogger; -import net.runelite.client.util.QueryRunner; import net.runelite.http.api.RuneLiteAPI; import okhttp3.OkHttpClient; import org.slf4j.Logger; @@ -75,7 +74,6 @@ public class RuneLiteModule extends AbstractModule bindConstant().annotatedWith(Names.named("developerMode")).to(developerMode); bind(ScheduledExecutorService.class).toInstance(new ExecutorServiceExceptionLogger(Executors.newSingleThreadScheduledExecutor())); bind(OkHttpClient.class).toInstance(RuneLiteAPI.CLIENT); - bind(QueryRunner.class); bind(MenuManager.class); bind(ChatMessageManager.class); bind(ItemManager.class); diff --git a/runelite-client/src/main/java/net/runelite/client/util/QueryRunner.java b/runelite-client/src/main/java/net/runelite/client/util/QueryRunner.java deleted file mode 100644 index 0f34fc5448..0000000000 --- a/runelite-client/src/main/java/net/runelite/client/util/QueryRunner.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2017, 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.util; - -import javax.inject.Inject; -import javax.inject.Singleton; -import net.runelite.api.Client; -import net.runelite.api.Query; - -@Singleton -public class QueryRunner -{ - @Inject - private Client client; - - @SuppressWarnings("unchecked") - public T[] runQuery(Query query) - { - return (T[]) query.result(client); - } -} \ No newline at end of file