Merge pull request #170 from devinfrench/queries

Add item queries
This commit is contained in:
Adam
2017-10-14 08:59:20 -04:00
committed by GitHub
18 changed files with 520 additions and 217 deletions

View File

@@ -28,7 +28,7 @@ import java.util.function.Predicate;
public abstract class Query<EntityType, QueryType>
{
protected Predicate<EntityType> predicate;
protected Predicate<EntityType> predicate = x -> true;
protected Query()
{

View File

@@ -0,0 +1,77 @@
/*
* Copyright (c) 2017, Devin French <https://github.com/devinfrench>
* 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<WidgetItem> widgetItems = getBankItems(client);
if (widgetItems != null)
{
return widgetItems.stream()
.filter(Objects::nonNull)
.filter(predicate)
.toArray(WidgetItem[]::new);
}
return new WidgetItem[0];
}
private Collection<WidgetItem> getBankItems(Client client)
{
Collection<WidgetItem> 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++)
{
if (children[i].getItemId() == ITEM_EMPTY)
{
continue;
}
// set bounds to same size as default inventory
Rectangle bounds = children[i].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(children[i].getItemId(), children[i].getItemQuantity(), 0, bounds));
}
}
return widgetItems;
}
}

View File

@@ -37,7 +37,10 @@ public class DecorativeObjectQuery extends TileObjectQuery<DecorativeObject, Dec
@Override
public DecorativeObject[] result(Client client)
{
return getDecorativeObjects(client).stream().filter(Objects::nonNull).filter(predicate).toArray(DecorativeObject[]::new);
return getDecorativeObjects(client).stream()
.filter(Objects::nonNull)
.filter(predicate)
.toArray(DecorativeObject[]::new);
}
private Collection<DecorativeObject> getDecorativeObjects(Client client)

View File

@@ -0,0 +1,99 @@
/*
* Copyright (c) 2017, Devin French <https://github.com/devinfrench>
* 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<WidgetInfo> slots = new ArrayList<>();
public EquipmentItemQuery slotEquals(WidgetInfo... slotWidgetInfo)
{
slots.addAll(Arrays.asList(slotWidgetInfo));
return this;
}
@Override
public WidgetItem[] result(Client client)
{
Collection<WidgetItem> widgetItems = getEquippedItems(client);
if (widgetItems != null)
{
return widgetItems.stream()
.filter(Objects::nonNull)
.filter(predicate)
.toArray(WidgetItem[]::new);
}
return new WidgetItem[0];
}
private Collection<WidgetItem> getEquippedItems(Client client)
{
Collection<WidgetItem> 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 widget = client.getWidget(slot).getChild(1);
// set bounds to same size as default inventory
Rectangle bounds = widget.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(widget.getItemId(), widget.getItemQuantity(), 0, bounds));
}
}
return widgetItems;
}
}

View File

@@ -38,7 +38,10 @@ public class GameObjectQuery extends TileObjectQuery<GameObject, GameObjectQuery
@Override
public GameObject[] result(Client client)
{
return getGameObjects(client).stream().filter(Objects::nonNull).filter(predicate).toArray(GameObject[]::new);
return getGameObjects(client).stream()
.filter(Objects::nonNull)
.filter(predicate)
.toArray(GameObject[]::new);
}
private Collection<GameObject> getGameObjects(Client client)

View File

@@ -37,7 +37,10 @@ public class GroundObjectQuery extends TileObjectQuery<GroundObject, GroundObjec
@Override
public GroundObject[] result(Client client)
{
return getGroundObjects(client).stream().filter(Objects::nonNull).filter(predicate).toArray(GroundObject[]::new);
return getGroundObjects(client).stream()
.filter(Objects::nonNull)
.filter(predicate)
.toArray(GroundObject[]::new);
}
private Collection<GroundObject> getGroundObjects(Client client)

View File

@@ -0,0 +1,91 @@
/*
* Copyright (c) 2017, Devin French <https://github.com/devinfrench>
* 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 InventoryItemQuery 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.INVENTORY
};
@Override
public WidgetItem[] result(Client client)
{
Collection<WidgetItem> widgetItems = getInventoryItems(client);
if (widgetItems != null)
{
return widgetItems.stream()
.filter(Objects::nonNull)
.filter(predicate)
.toArray(WidgetItem[]::new);
}
return new WidgetItem[0];
}
private Collection<WidgetItem> getInventoryItems(Client client)
{
Collection<WidgetItem> 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++)
{
// set bounds to same size as default inventory
Rectangle bounds = children[i].getBounds();
bounds.setBounds(bounds.x - 1, bounds.y - 1, 32, 32);
widgetItems.add(new WidgetItem(children[i].getItemId(), children[i].getItemQuantity(), i, bounds));
}
break;
}
}
return widgetItems;
}
}

View File

@@ -0,0 +1,70 @@
/*
* Copyright (c) 2017, Devin French <https://github.com/devinfrench>
* 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<WidgetItem> widgetItems = getShopItems(client);
if (widgetItems != null)
{
return widgetItems.stream()
.filter(Objects::nonNull)
.filter(predicate)
.toArray(WidgetItem[]::new);
}
return new WidgetItem[0];
}
private Collection<WidgetItem> getShopItems(Client client)
{
Collection<WidgetItem> 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++)
{
// set bounds to same size as default inventory
Rectangle bounds = children[i].getBounds();
bounds.setBounds(bounds.x - 1, bounds.y - 1, 32, 32);
widgetItems.add(new WidgetItem(children[i].getItemId(), children[i].getItemQuantity(), i - 1, bounds));
}
}
return widgetItems;
}
}

View File

@@ -37,7 +37,10 @@ public class WallObjectQuery extends TileObjectQuery<WallObject, WallObjectQuery
@Override
public WallObject[] result(Client client)
{
return getWallObjects(client).stream().filter(Objects::nonNull).filter(predicate).toArray(WallObject[]::new);
return getWallObjects(client).stream()
.filter(Objects::nonNull)
.filter(predicate)
.toArray(WallObject[]::new);
}
private Collection<WallObject> getWallObjects(Client client)

View File

@@ -26,21 +26,10 @@ package net.runelite.api.queries;
import net.runelite.api.Client;
import net.runelite.api.Query;
import net.runelite.api.widgets.Widget;
import net.runelite.api.widgets.WidgetInfo;
import net.runelite.api.widgets.WidgetItem;
import java.util.Collection;
import java.util.Objects;
public class WidgetItemQuery extends Query<WidgetItem, WidgetItemQuery>
public abstract class WidgetItemQuery extends Query<WidgetItem, WidgetItemQuery>
{
private final WidgetInfo widgetInfo;
public WidgetItemQuery(WidgetInfo widgetInfo)
{
this.widgetInfo = widgetInfo;
}
public WidgetItemQuery idEquals(int... ids)
{
@@ -81,17 +70,5 @@ public class WidgetItemQuery extends Query<WidgetItem, WidgetItemQuery>
}
@Override
public WidgetItem[] result(Client client)
{
Widget widget = client.getWidget(widgetInfo);
if (widget != null)
{
Collection<WidgetItem> widgetItems = widget.getWidgetItems();
if (widgetItems != null)
{
return widgetItems.stream().filter(Objects::nonNull).filter(predicate).toArray(WidgetItem[]::new);
}
}
return new WidgetItem[0];
}
public abstract WidgetItem[] result(Client client);
}

View File

@@ -27,6 +27,8 @@ package net.runelite.api.widgets;
class WidgetID
{
static final int BANK_GROUP_ID = 12;
static final int BANK_INVENTORY_GROUP_ID = 15;
static final int DEPOSIT_BOX_GROUP_ID = 192;
static final int INVENTORY_GROUP_ID = 149;
static final int EQUIPMENT_GROUP_ID = 387;
static final int PESTRCONTROL_GROUP_ID = 408;
@@ -38,6 +40,8 @@ class WidgetID
static final int RESIZABLE_VIEWPORT_OLD_SCHOOL_BOX_GROUP_ID = 161;
static final int RESIZABLE_VIEWPORT_BOTTOM_LINE_GROUP_ID = 164;
static final int PRAYER_GROUP_ID = 541;
static final int SHOP_GROUP_ID = 300;
static final int SHOP_INVENTORY_GROUP_ID = 301;
static class PestControl
{
@@ -70,6 +74,18 @@ class WidgetID
static class Bank
{
static final int ITEM_CONTAINER = 12;
static final int INVENTORY_ITEM_CONTAINER = 3;
}
static class DepositBox
{
static final int INVENTORY_ITEM_CONTAINER = 2;
}
static class Shop
{
static final int ITEMS_CONTAINER = 2;
static final int INVENTORY_ITEM_CONTAINER = 0;
}
static class Equipment

View File

@@ -64,6 +64,11 @@ public enum WidgetInfo
CLAN_CHAT_OWNER(WidgetID.CLAN_CHAT_GROUP_ID, WidgetID.ClanChat.OWNER),
BANK_ITEM_CONTAINER(WidgetID.BANK_GROUP_ID, WidgetID.Bank.ITEM_CONTAINER),
BANK_INVENTORY_ITEMS_CONTAINER(WidgetID.BANK_INVENTORY_GROUP_ID, WidgetID.Bank.INVENTORY_ITEM_CONTAINER),
DEPOSIT_BOX_INVENTORY_ITEMS_CONTAINER(WidgetID.DEPOSIT_BOX_GROUP_ID, WidgetID.DepositBox.INVENTORY_ITEM_CONTAINER),
SHOP_ITEMS_CONTAINER(WidgetID.SHOP_GROUP_ID, WidgetID.Shop.ITEMS_CONTAINER),
SHOP_INVENTORY_ITEMS_CONTAINER(WidgetID.SHOP_INVENTORY_GROUP_ID, WidgetID.Shop.INVENTORY_ITEM_CONTAINER),
MINIMAP_XP_ORB(WidgetID.MINIMAP_GROUP_ID, WidgetID.Minimap.XP_ORB),

View File

@@ -24,10 +24,8 @@
*/
package net.runelite.client.plugins.jewelrycount;
import java.awt.Font;
import net.runelite.client.RuneLite;
import net.runelite.client.plugins.Plugin;
import net.runelite.client.ui.FontManager;
import net.runelite.client.ui.overlay.Overlay;
public class JewelryCount extends Plugin
@@ -35,8 +33,6 @@ public class JewelryCount extends Plugin
private final JewelryCountConfig config = RuneLite.getRunelite().getConfigManager().getConfig(JewelryCountConfig.class);
private final Overlay overlay = new JewelryCountOverlay(this);
private Font font;
@Override
public Overlay getOverlay()
{
@@ -46,8 +42,6 @@ public class JewelryCount extends Plugin
@Override
protected void startUp() throws Exception
{
font = FontManager.getRunescapeSmallFont()
.deriveFont(Font.PLAIN, 16);
}
@Override
@@ -60,9 +54,4 @@ public class JewelryCount extends Plugin
{
return config;
}
public Font getFont()
{
return font;
}
}

View File

@@ -25,26 +25,32 @@
package net.runelite.client.plugins.jewelrycount;
import java.awt.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import net.runelite.api.Client;
import net.runelite.api.GameState;
import net.runelite.api.widgets.Widget;
import net.runelite.api.Query;
import net.runelite.api.queries.EquipmentItemQuery;
import net.runelite.api.queries.InventoryItemQuery;
import net.runelite.api.widgets.WidgetInfo;
import net.runelite.api.widgets.WidgetItem;
import net.runelite.client.RuneLite;
import net.runelite.client.ui.FontManager;
import net.runelite.client.ui.overlay.Overlay;
import net.runelite.client.ui.overlay.OverlayPosition;
class JewelryCountOverlay extends Overlay
{
private final RuneLite runelite = RuneLite.getRunelite();
private final JewelryCountConfig config;
private final JewelryCount plugin;
private final Font font = FontManager.getRunescapeSmallFont().deriveFont(Font.PLAIN, 16);
JewelryCountOverlay(JewelryCount plugin)
{
super(OverlayPosition.DYNAMIC);
this.config = plugin.getConfig();
this.plugin = plugin;
}
@Override
@@ -59,66 +65,44 @@ class JewelryCountOverlay extends Overlay
return null;
}
Widget inventory = client.getWidget(WidgetInfo.INVENTORY);
graphics.setFont(font);
if (inventory == null)
for (WidgetItem item : getJewelryWidgetItems())
{
return null;
}
JewelryCharges charges = JewelryCharges.getCharges(item.getId());
if (!inventory.isHidden())
{
for (WidgetItem item : inventory.getWidgetItems())
if (charges == null)
{
JewelryCharges charges = JewelryCharges.getCharges(item.getId());
if (charges == null)
{
continue;
}
renderWidgetText(graphics, item.getCanvasBounds(), charges.getCharges(), Color.white);
continue;
}
}
Widget equipment = client.getWidget(WidgetInfo.EQUIPMENT);
renderWidgetText(graphics, item.getCanvasBounds(), charges.getCharges(), Color.white);
if (equipment != null)
{
Widget[] equipmentSlots =
{
client.getWidget(WidgetInfo.EQUIPMENT_AMULET).getChild(1), client.getWidget(WidgetInfo.EQUIPMENT_RING).getChild(1),
client.getWidget(WidgetInfo.EQUIPMENT_GLOVES).getChild(1)
};
for (Widget widget : equipmentSlots)
{
JewelryCharges charges = JewelryCharges.getCharges(widget.getItemId());
if (charges == null || widget.isHidden())
{
continue;
}
Rectangle widgetBounds = widget.getBounds();
renderWidgetText(graphics, widgetBounds, charges.getCharges(), Color.white);
}
}
return null;
}
private Collection<WidgetItem> getJewelryWidgetItems()
{
Query inventoryQuery = new InventoryItemQuery();
WidgetItem[] inventoryWidgetItems = runelite.runQuery(inventoryQuery);
Query equipmentQuery = new EquipmentItemQuery().slotEquals(
WidgetInfo.EQUIPMENT_AMULET,
WidgetInfo.EQUIPMENT_RING,
WidgetInfo.EQUIPMENT_GLOVES
);
WidgetItem[] equipmentWidgetItems = runelite.runQuery(equipmentQuery);
Collection<WidgetItem> jewelry = new ArrayList<>();
jewelry.addAll(Arrays.asList(inventoryWidgetItems));
jewelry.addAll(Arrays.asList(equipmentWidgetItems));
return jewelry;
}
private void renderWidgetText(Graphics2D graphics, Rectangle bounds, int charges, Color color)
{
Font font = plugin.getFont();
if (font != null)
{
graphics.setFont(font);
}
FontMetrics fm = graphics.getFontMetrics();
int textX = (int) bounds.getX();

View File

@@ -27,27 +27,37 @@ package net.runelite.client.plugins.runecraft;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.geom.Rectangle2D;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import net.runelite.api.Client;
import net.runelite.api.GameState;
import static net.runelite.api.ItemID.BINDING_NECKLACE;
import net.runelite.api.widgets.Widget;
import net.runelite.api.Query;
import net.runelite.api.queries.EquipmentItemQuery;
import net.runelite.api.queries.InventoryItemQuery;
import net.runelite.api.widgets.WidgetInfo;
import net.runelite.api.widgets.WidgetItem;
import net.runelite.client.RuneLite;
import net.runelite.client.ui.FontManager;
import net.runelite.client.ui.overlay.Overlay;
import net.runelite.client.ui.overlay.OverlayPosition;
public class BindNeckOverlay extends Overlay
{
private final Client client = RuneLite.getClient();
private final RuneLite runelite = RuneLite.getRunelite();
private final RunecraftConfig config;
private final Font font = FontManager.getRunescapeSmallFont().deriveFont(Font.PLAIN, 16);
int bindingCharges;
public BindNeckOverlay(Runecraft plugin)
BindNeckOverlay(Runecraft plugin)
{
super(OverlayPosition.DYNAMIC);
this.config = plugin.getConfig();
@@ -63,69 +73,41 @@ public class BindNeckOverlay extends Overlay
return null;
}
Widget inventory = client.getWidget(WidgetInfo.INVENTORY);
graphics.setFont(font);
if (inventory == null)
for (WidgetItem necklace : getNecklaceWidgetItems())
{
return null;
}
if (!inventory.isHidden())
{
for (WidgetItem item : inventory.getWidgetItems())
{
if (item.getId() != BINDING_NECKLACE)
{
continue;
}
if (bindingCharges == 1)
{
renderBindNeck(graphics, item.getCanvasBounds(), bindingCharges, Color.red);
}
else
{
renderBindNeck(graphics, item.getCanvasBounds(), bindingCharges, Color.white);
}
}
}
Widget equipment = client.getWidget(WidgetInfo.EQUIPMENT);
if (equipment != null)
{
Widget amuletSlot = client.getWidget(WidgetInfo.EQUIPMENT_AMULET).getChild(1);
if (!amuletSlot.isHidden() && amuletSlot.getItemId() == BINDING_NECKLACE)
{
Rectangle widgetBounds = amuletSlot.getBounds();
//to match inventory text
widgetBounds.x -= 5;
widgetBounds.y -= 1;
if (bindingCharges == 1)
{
renderBindNeck(graphics, widgetBounds, bindingCharges, Color.red);
}
else
{
renderBindNeck(graphics, widgetBounds, bindingCharges, Color.white);
}
}
Color color = bindingCharges == 1 ? Color.RED : Color.WHITE;
renderBindNeck(graphics, necklace.getCanvasBounds(), bindingCharges, color);
}
return null;
}
private Collection<WidgetItem> getNecklaceWidgetItems()
{
Query inventoryQuery = new InventoryItemQuery()
.idEquals(BINDING_NECKLACE);
WidgetItem[] inventoryWidgetItems = runelite.runQuery(inventoryQuery);
Query equipmentQuery = new EquipmentItemQuery()
.slotEquals(WidgetInfo.EQUIPMENT_AMULET)
.idEquals(BINDING_NECKLACE);
WidgetItem[] equipmentWidgetItems = runelite.runQuery(equipmentQuery);
Collection<WidgetItem> necklaces = new ArrayList<>();
necklaces.addAll(Arrays.asList(inventoryWidgetItems));
necklaces.addAll(Arrays.asList(equipmentWidgetItems));
return necklaces;
}
private void renderBindNeck(Graphics2D graphics, Rectangle bounds, int charges, Color color)
{
String text = charges <= 0 ? "?" : charges + "";
FontMetrics fm = graphics.getFontMetrics();
Rectangle2D textBounds = fm.getStringBounds(text, graphics);
int textX = (int) (bounds.getX() + bounds.getWidth() - textBounds.getWidth());
int textY = (int) (bounds.getY() + (textBounds.getHeight()));
int textX = (int) bounds.getX();
int textY = (int) bounds.getY() + fm.getHeight();
//text shadow
graphics.setColor(Color.BLACK);

View File

@@ -25,6 +25,7 @@
package net.runelite.client.plugins.runecraft;
import com.google.common.eventbus.Subscribe;
import java.util.Arrays;
import java.util.Collection;
import java.util.regex.Matcher;
@@ -37,7 +38,7 @@ import net.runelite.client.ui.overlay.Overlay;
public class Runecraft extends Plugin
{
public static Pattern bindNeckString = Pattern.compile("You have ([0-9]+) charges left before your Binding necklace disintegrates.");
private static Pattern bindNeckString = Pattern.compile("You have ([0-9]+) charges left before your Binding necklace disintegrates.");
private final RunecraftConfig config = RuneLite.getRunelite().getConfigManager().getConfig(RunecraftConfig.class);
private final RunecraftOverlay overlay = new RunecraftOverlay(this);
@@ -97,7 +98,6 @@ public class Runecraft extends Plugin
{
//set it to 17 because this message is triggered first before the above chat event
bindNeckOverlay.bindingCharges = 17;
return;
}
}
}

View File

@@ -26,29 +26,37 @@ package net.runelite.client.plugins.runecraft;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import net.runelite.api.Client;
import net.runelite.api.GameState;
import net.runelite.api.ItemID;
import net.runelite.api.Point;
import net.runelite.api.Query;
import net.runelite.api.Varbits;
import net.runelite.api.widgets.Widget;
import net.runelite.api.queries.InventoryItemQuery;
import net.runelite.api.widgets.WidgetInfo;
import net.runelite.api.widgets.WidgetItem;
import net.runelite.client.RuneLite;
import net.runelite.client.ui.FontManager;
import net.runelite.client.ui.overlay.Overlay;
import net.runelite.client.ui.overlay.OverlayPosition;
public class RunecraftOverlay extends Overlay
{
private static final int MEDIUM_POUCH_DAMAGED = ItemID.MEDIUM_POUCH_5511;
private static final int LARGE_POUCH_DAMAGED = ItemID.LARGE_POUCH_5513;
private static final int GIANT_POUCH_DAMAGED = ItemID.GIANT_POUCH_5515;
private final Client client = RuneLite.getClient();
private final RuneLite runelite = RuneLite.getRunelite();
private final Font font = FontManager.getRunescapeSmallFont().deriveFont(Font.PLAIN, 16);
private final RunecraftConfig config;
private final int MEDIUM_POUCH_DAMAGED = ItemID.MEDIUM_POUCH_5511;
private final int LARGE_POUCH_DAMAGED = ItemID.LARGE_POUCH_5513;
private final int GIANT_POUCH_DAMAGED = ItemID.GIANT_POUCH_5515;
public RunecraftOverlay(Runecraft plugin)
RunecraftOverlay(Runecraft plugin)
{
super(OverlayPosition.DYNAMIC);
this.config = plugin.getConfig();
@@ -64,14 +72,11 @@ public class RunecraftOverlay extends Overlay
return null;
}
Widget inventoryWidget = client.getWidget(WidgetInfo.INVENTORY);
graphics.setFont(font);
if (inventoryWidget == null || inventoryWidget.isHidden())
{
return null;
}
for (WidgetItem item : inventoryWidget.getWidgetItems())
Query query = new InventoryItemQuery();
WidgetItem[] widgetItems = runelite.runQuery(query);
for (WidgetItem item : widgetItems)
{
Varbits varbits;
@@ -96,18 +101,25 @@ public class RunecraftOverlay extends Overlay
continue;
}
Point location = item.getCanvasLocation();
if (location != null)
{
int value = client.getSetting(varbits);
graphics.setColor(Color.black);
graphics.drawString("" + value, location.getX() + 1, location.getY() + graphics.getFontMetrics().getHeight() + 1);
graphics.setColor(Color.white);
graphics.drawString("" + value, location.getX(), location.getY() + graphics.getFontMetrics().getHeight());
}
renderPouch(graphics, item.getCanvasBounds(), varbits, Color.WHITE);
}
return null;
}
private void renderPouch(Graphics2D graphics, Rectangle bounds, Varbits varbits, Color color)
{
FontMetrics fm = graphics.getFontMetrics();
int textX = (int) bounds.getX();
int textY = (int) bounds.getY() + fm.getHeight();
int contents = client.getSetting(varbits);
//text shadow
graphics.setColor(Color.BLACK);
graphics.drawString(String.valueOf(contents), textX + 1, textY + 1);
graphics.setColor(color);
graphics.drawString(String.valueOf(contents), textX, textY);
}
}

View File

@@ -32,8 +32,9 @@ import net.runelite.api.Client;
import net.runelite.api.GameState;
import net.runelite.api.ItemID;
import net.runelite.api.Point;
import net.runelite.api.Query;
import net.runelite.api.Varbits;
import net.runelite.api.widgets.Widget;
import net.runelite.api.queries.InventoryItemQuery;
import net.runelite.api.widgets.WidgetInfo;
import net.runelite.api.widgets.WidgetItem;
import net.runelite.client.RuneLite;
@@ -41,13 +42,9 @@ import net.runelite.client.ui.FontManager;
import net.runelite.client.ui.overlay.Overlay;
import net.runelite.client.ui.overlay.OverlayPosition;
import net.runelite.client.ui.overlay.OverlayUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class RunepouchOverlay extends Overlay
{
private static final Logger logger = LoggerFactory.getLogger(RunepouchOverlay.class);
private static final Varbits[] AMOUNT_VARBITS =
{
Varbits.RUNE_POUCH_AMOUNT1, Varbits.RUNE_POUCH_AMOUNT2, Varbits.RUNE_POUCH_AMOUNT3
@@ -58,14 +55,13 @@ public class RunepouchOverlay extends Overlay
};
private final Client client = RuneLite.getClient();
private final RuneLite runelite = RuneLite.getRunelite();
private final RuneImageCache runeImageCache = new RuneImageCache();
private final Runepouch plugin;
private final RunepouchConfig config;
public RunepouchOverlay(Runepouch plugin)
RunepouchOverlay(Runepouch plugin)
{
super(OverlayPosition.DYNAMIC);
this.plugin = plugin;
this.config = plugin.getConfig();
}
@@ -79,63 +75,56 @@ public class RunepouchOverlay extends Overlay
return null;
}
Widget inventoryWidget = client.getWidget(WidgetInfo.INVENTORY);
if (inventoryWidget == null || inventoryWidget.isHidden())
Query query = new InventoryItemQuery().idEquals(ItemID.RUNE_POUCH);
WidgetItem[] items = runelite.runQuery(query);
if (items.length == 0)
{
return null;
}
WidgetItem runePouch = items[0];
Point location = runePouch.getCanvasLocation();
if (location == null)
{
return null;
}
assert AMOUNT_VARBITS.length == RUNE_VARBITS.length;
graphics.setFont(FontManager.getRunescapeSmallFont());
for (WidgetItem item : inventoryWidget.getWidgetItems())
for (int i = 0; i < AMOUNT_VARBITS.length; i++)
{
if (item.getId() != ItemID.RUNE_POUCH)
Varbits amountVarbit = AMOUNT_VARBITS[i];
Varbits runeVarbit = RUNE_VARBITS[i];
int amount = client.getSetting(amountVarbit);
if (amount <= 0)
{
continue;
}
Point location = item.getCanvasLocation();
if (location == null)
graphics.setColor(Color.black);
graphics.drawString("" + formatNumber(amount), location.getX() + (config.showIcons() ? 13 : 1),
location.getY() + 14 + graphics.getFontMetrics().getHeight() * i);
graphics.setColor(config.fontColor());
graphics.drawString("" + formatNumber(amount), location.getX() + (config.showIcons() ? 12 : 0),
location.getY() + 13 + graphics.getFontMetrics().getHeight() * i);
if (!config.showIcons())
{
continue;
}
assert AMOUNT_VARBITS.length == RUNE_VARBITS.length;
int runeId = client.getSetting(runeVarbit);
for (int i = 0; i < AMOUNT_VARBITS.length; i++)
BufferedImage runeImg = runeImageCache.getImage(runeId);
if (runeImg != null)
{
Varbits amountVarbit = AMOUNT_VARBITS[i];
Varbits runeVarbit = RUNE_VARBITS[i];
int amount = client.getSetting(amountVarbit);
if (amount <= 0)
{
continue;
}
graphics.setColor(Color.black);
graphics.drawString("" + formatNumber(amount), location.getX() + (config.showIcons() ? 13 : 1),
location.getY() + 14 + graphics.getFontMetrics().getHeight() * i);
graphics.setColor(config.fontColor());
graphics.drawString("" + formatNumber(amount), location.getX() + (config.showIcons() ? 12 : 0),
location.getY() + 13 + graphics.getFontMetrics().getHeight() * i);
if (!config.showIcons())
{
continue;
}
int runeId = client.getSetting(runeVarbit);
BufferedImage runeImg = runeImageCache.getImage(runeId);
if (runeImg != null)
{
OverlayUtil.renderImageLocation(graphics,
new Point(location.getX(), location.getY() + 2 + (graphics.getFontMetrics().getHeight()) * i),
runeImg);
}
OverlayUtil.renderImageLocation(graphics,
new Point(location.getX(), location.getY() + 2 + (graphics.getFontMetrics().getHeight()) * i),
runeImg);
}
}
return null;