runelite-client: some work on overlays on widget items
This commit is contained in:
@@ -26,6 +26,7 @@ package net.runelite.api;
|
|||||||
|
|
||||||
import java.awt.Canvas;
|
import java.awt.Canvas;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import net.runelite.api.widgets.Widget;
|
||||||
|
|
||||||
public class Client
|
public class Client
|
||||||
{
|
{
|
||||||
@@ -174,4 +175,32 @@ public class Client
|
|||||||
{
|
{
|
||||||
return client.getBaseY();
|
return client.getBaseY();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Widget getWidget(int groupId, int childId)
|
||||||
|
{
|
||||||
|
net.runelite.rs.api.Widget[][] widgets = client.getWidgets();
|
||||||
|
|
||||||
|
if (widgets == null || widgets.length <= groupId)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
net.runelite.rs.api.Widget[] childWidgets = widgets[groupId];
|
||||||
|
if (childWidgets == null || childWidgets.length <= childId)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Widget(this, childWidgets[childId]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int[] getWidgetPositionsX()
|
||||||
|
{
|
||||||
|
return client.getWidgetPositionsX();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int[] getWidgetPositionsY()
|
||||||
|
{
|
||||||
|
return client.getWidgetPositionsY();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
147
runelite-api/src/main/java/net/runelite/api/widgets/Widget.java
Normal file
147
runelite-api/src/main/java/net/runelite/api/widgets/Widget.java
Normal file
@@ -0,0 +1,147 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2017, Adam <Adam@sigterm.info>
|
||||||
|
* 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.widgets;
|
||||||
|
|
||||||
|
import java.awt.Rectangle;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
import net.runelite.api.Client;
|
||||||
|
import net.runelite.api.Point;
|
||||||
|
|
||||||
|
public class Widget
|
||||||
|
{
|
||||||
|
private static final int WIDGET_ITEM_WIDTH = 42;
|
||||||
|
private static final int WIDGET_ITEM_HEIGHT = 36;
|
||||||
|
|
||||||
|
private final Client client;
|
||||||
|
private final net.runelite.rs.api.Widget widget;
|
||||||
|
|
||||||
|
public Widget(Client client, net.runelite.rs.api.Widget widget)
|
||||||
|
{
|
||||||
|
this.client = client;
|
||||||
|
this.widget = widget;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Widget getParent()
|
||||||
|
{
|
||||||
|
net.runelite.rs.api.Widget parent = widget.getParent();
|
||||||
|
|
||||||
|
if (parent == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Widget(client, parent);
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getRelativeX()
|
||||||
|
{
|
||||||
|
return widget.getRelativeX();
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getRelativeY()
|
||||||
|
{
|
||||||
|
return widget.getRelativeY();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Point getCanvasLocation()
|
||||||
|
{
|
||||||
|
int x = 0;
|
||||||
|
int y = 0;
|
||||||
|
|
||||||
|
int boundsIndex = widget.getBoundsIndex();
|
||||||
|
if (boundsIndex != -1)
|
||||||
|
{
|
||||||
|
int[] widgetBoundsWidth = client.getWidgetPositionsX();
|
||||||
|
int[] widgetBoundsHeight = client.getWidgetPositionsY();
|
||||||
|
|
||||||
|
x += widgetBoundsWidth[boundsIndex];
|
||||||
|
y += widgetBoundsHeight[boundsIndex];
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Widget cur = this; cur != null; cur = cur.getParent())
|
||||||
|
{
|
||||||
|
x += cur.getRelativeX();
|
||||||
|
y += cur.getRelativeY();
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Point(x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getWidth()
|
||||||
|
{
|
||||||
|
return widget.getWidth();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getHeight()
|
||||||
|
{
|
||||||
|
return widget.getHeight();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Collection<WidgetItem> getWidgetItems()
|
||||||
|
{
|
||||||
|
int[] itemIds = widget.getItemIds();
|
||||||
|
int[] itemQuantities = widget.getItemQuantities();
|
||||||
|
|
||||||
|
if (itemIds == null || itemQuantities == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<WidgetItem> items = new ArrayList<>(itemIds.length);
|
||||||
|
|
||||||
|
assert itemIds.length == itemQuantities.length;
|
||||||
|
|
||||||
|
int itemsX = getWidth(); // this appears to be the number of items that fit in the width
|
||||||
|
Point widgetCanvasLocation = getCanvasLocation();
|
||||||
|
|
||||||
|
for (int i = 0; i < itemIds.length; ++i)
|
||||||
|
{
|
||||||
|
int itemId = itemIds[i];
|
||||||
|
int itemQuantity = itemQuantities[i];
|
||||||
|
|
||||||
|
if (itemId <= 0 || itemQuantity <= 0)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
Rectangle bounds = null;
|
||||||
|
|
||||||
|
if (itemsX > 0)
|
||||||
|
{
|
||||||
|
int itemX = widgetCanvasLocation.getX() + (i % itemsX) * WIDGET_ITEM_WIDTH;
|
||||||
|
int itemY = widgetCanvasLocation.getY() + (i / itemsX) * WIDGET_ITEM_HEIGHT;
|
||||||
|
|
||||||
|
bounds = new Rectangle(itemX + 1, itemY - 1, WIDGET_ITEM_WIDTH - 2, WIDGET_ITEM_HEIGHT - 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
WidgetItem item = new WidgetItem(itemId - 1, itemQuantity, i, bounds);
|
||||||
|
items.add(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
return items;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2017, Adam <Adam@sigterm.info>
|
||||||
|
* 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.widgets;
|
||||||
|
|
||||||
|
public class WidgetID
|
||||||
|
{
|
||||||
|
public static final int INVENTORY_GROUP_ID = 149;
|
||||||
|
public static final int INVENTORY_CHILD_ID = 0;
|
||||||
|
}
|
||||||
@@ -0,0 +1,70 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2017, Adam <Adam@sigterm.info>
|
||||||
|
* 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.widgets;
|
||||||
|
|
||||||
|
import java.awt.Rectangle;
|
||||||
|
|
||||||
|
public class WidgetItem
|
||||||
|
{
|
||||||
|
private final int id;
|
||||||
|
private final int quantity;
|
||||||
|
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 + '}';
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getId()
|
||||||
|
{
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getQuantity()
|
||||||
|
{
|
||||||
|
return quantity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getIndex()
|
||||||
|
{
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Rectangle getCanvasBounds()
|
||||||
|
{
|
||||||
|
return canvasBounds;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -27,6 +27,7 @@ package net.runelite.client.plugins.debug;
|
|||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
|
import java.awt.Rectangle;
|
||||||
import net.runelite.api.Client;
|
import net.runelite.api.Client;
|
||||||
import net.runelite.api.DecorativeObject;
|
import net.runelite.api.DecorativeObject;
|
||||||
import net.runelite.api.GameObject;
|
import net.runelite.api.GameObject;
|
||||||
@@ -37,6 +38,9 @@ import net.runelite.api.Region;
|
|||||||
import net.runelite.api.Tile;
|
import net.runelite.api.Tile;
|
||||||
import net.runelite.api.TileObject;
|
import net.runelite.api.TileObject;
|
||||||
import net.runelite.api.WallObject;
|
import net.runelite.api.WallObject;
|
||||||
|
import net.runelite.api.widgets.Widget;
|
||||||
|
import net.runelite.api.widgets.WidgetID;
|
||||||
|
import net.runelite.api.widgets.WidgetItem;
|
||||||
import net.runelite.client.RuneLite;
|
import net.runelite.client.RuneLite;
|
||||||
import net.runelite.client.ui.overlay.Overlay;
|
import net.runelite.client.ui.overlay.Overlay;
|
||||||
import net.runelite.client.ui.overlay.OverlayPosition;
|
import net.runelite.client.ui.overlay.OverlayPosition;
|
||||||
@@ -60,6 +64,14 @@ public class DebugOverlay extends Overlay
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
renderTiles(graphics);
|
||||||
|
renderInventory(graphics);
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void renderTiles(Graphics2D graphics)
|
||||||
|
{
|
||||||
Region region = client.getRegion();
|
Region region = client.getRegion();
|
||||||
Tile[][][] tiles = region.getTiles();
|
Tile[][][] tiles = region.getTiles();
|
||||||
|
|
||||||
@@ -79,8 +91,30 @@ public class DebugOverlay extends Overlay
|
|||||||
render(graphics, tile);
|
render(graphics, tile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return null;
|
private void renderInventory(Graphics2D graphics)
|
||||||
|
{
|
||||||
|
Widget inventoryWidget = client.getWidget(WidgetID.INVENTORY_GROUP_ID, WidgetID.INVENTORY_CHILD_ID);
|
||||||
|
if (inventoryWidget == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (WidgetItem item : inventoryWidget.getWidgetItems())
|
||||||
|
{
|
||||||
|
Rectangle bounds = item.getCanvasBounds();
|
||||||
|
|
||||||
|
Color[] colors = new Color[]
|
||||||
|
{
|
||||||
|
Color.RED, Color.GREEN, Color.BLUE
|
||||||
|
};
|
||||||
|
graphics.setColor(colors[item.getIndex() % 3]);
|
||||||
|
if (bounds != null)
|
||||||
|
{
|
||||||
|
graphics.draw(bounds);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void render(Graphics2D graphics, Tile tile)
|
private void render(Graphics2D graphics, Tile tile)
|
||||||
|
|||||||
@@ -25,10 +25,9 @@
|
|||||||
|
|
||||||
package net.runelite.rs.api;
|
package net.runelite.rs.api;
|
||||||
|
|
||||||
|
import java.awt.Canvas;
|
||||||
import net.runelite.mapping.Import;
|
import net.runelite.mapping.Import;
|
||||||
|
|
||||||
import java.awt.*;
|
|
||||||
|
|
||||||
public interface Client extends GameEngine
|
public interface Client extends GameEngine
|
||||||
{
|
{
|
||||||
@Import("cameraX")
|
@Import("cameraX")
|
||||||
|
|||||||
@@ -122,9 +122,9 @@ public interface Widget
|
|||||||
@Import("itemQuantity")
|
@Import("itemQuantity")
|
||||||
int getItemQuantity();
|
int getItemQuantity();
|
||||||
|
|
||||||
@Import("x")
|
@Import("originalX")
|
||||||
int getX();
|
int getOriginalX();
|
||||||
|
|
||||||
@Import("y")
|
@Import("originalY")
|
||||||
int getY();
|
int getOriginalY();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user