Updated inventory overlay in DevTools
Also, modified WidgetItem bounds to account for padding
This commit is contained in:
@@ -36,8 +36,7 @@ import net.runelite.api.XHashTable;
|
||||
|
||||
public class Widget
|
||||
{
|
||||
private static final int WIDGET_ITEM_WIDTH = 42;
|
||||
private static final int WIDGET_ITEM_HEIGHT = 36;
|
||||
private static final int ITEM_SLOT_SIZE = 32;
|
||||
|
||||
private final Client client;
|
||||
private final net.runelite.rs.api.Widget widget;
|
||||
@@ -210,7 +209,10 @@ public class Widget
|
||||
|
||||
assert itemIds.length == itemQuantities.length;
|
||||
|
||||
int itemsX = getWidth(); // this appears to be the number of items that fit in the width
|
||||
int columns = getWidth(); // the number of item slot columns is stored here
|
||||
int paddingX = getPaddingX();
|
||||
int paddingY = getPaddingY();
|
||||
|
||||
Point widgetCanvasLocation = getCanvasLocation();
|
||||
|
||||
for (int i = 0; i < itemIds.length; ++i)
|
||||
@@ -225,12 +227,14 @@ public class Widget
|
||||
|
||||
Rectangle bounds = null;
|
||||
|
||||
if (itemsX > 0)
|
||||
if (columns > 0)
|
||||
{
|
||||
int itemX = widgetCanvasLocation.getX() + (i % itemsX) * WIDGET_ITEM_WIDTH;
|
||||
int itemY = widgetCanvasLocation.getY() + (i / itemsX) * WIDGET_ITEM_HEIGHT;
|
||||
int row = i / columns;
|
||||
int col = i % columns;
|
||||
int itemX = widgetCanvasLocation.getX() + ((ITEM_SLOT_SIZE + paddingX) * col);
|
||||
int itemY = widgetCanvasLocation.getY() + ((ITEM_SLOT_SIZE + paddingY) * row);
|
||||
|
||||
bounds = new Rectangle(itemX + 1, itemY - 1, WIDGET_ITEM_WIDTH - 2, WIDGET_ITEM_HEIGHT - 2);
|
||||
bounds = new Rectangle(itemX - 1, itemY - 1, ITEM_SLOT_SIZE, ITEM_SLOT_SIZE);
|
||||
}
|
||||
|
||||
WidgetItem item = new WidgetItem(itemId - 1, itemQuantity, i, bounds);
|
||||
@@ -240,12 +244,12 @@ public class Widget
|
||||
return items;
|
||||
}
|
||||
|
||||
public int getPaddingX()
|
||||
private int getPaddingX()
|
||||
{
|
||||
return widget.getPaddingX();
|
||||
}
|
||||
|
||||
public int getPaddingY()
|
||||
private int getPaddingY()
|
||||
{
|
||||
return widget.getPaddingY();
|
||||
}
|
||||
|
||||
@@ -35,8 +35,6 @@ import net.runelite.client.plugins.Plugin;
|
||||
import net.runelite.client.ui.ClientUI;
|
||||
import net.runelite.client.ui.NavigationButton;
|
||||
import net.runelite.client.ui.overlay.Overlay;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class DevTools extends Plugin
|
||||
{
|
||||
@@ -71,7 +69,7 @@ public class DevTools extends Plugin
|
||||
|
||||
font = Font.createFont(Font.TRUETYPE_FONT, getClass().getResourceAsStream("/runescape.ttf"));
|
||||
|
||||
font = font.deriveFont(Font.PLAIN, 16);
|
||||
font = font.deriveFont(Font.BOLD, 16);
|
||||
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
|
||||
ge.registerFont(font);
|
||||
}
|
||||
|
||||
@@ -29,9 +29,12 @@ import java.awt.BasicStroke;
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Font;
|
||||
import java.awt.FontMetrics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Polygon;
|
||||
import java.awt.Rectangle;
|
||||
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import net.runelite.api.Actor;
|
||||
import net.runelite.api.Client;
|
||||
import net.runelite.api.DecorativeObject;
|
||||
@@ -87,6 +90,12 @@ public class DevToolsOverlay extends Overlay
|
||||
return null;
|
||||
}
|
||||
|
||||
Font font = plugin.getFont();
|
||||
if (font != null)
|
||||
{
|
||||
graphics.setFont(font);
|
||||
}
|
||||
|
||||
if (plugin.isTogglePlayers())
|
||||
{
|
||||
renderPlayers(graphics);
|
||||
@@ -140,12 +149,6 @@ public class DevToolsOverlay extends Overlay
|
||||
int x = textLocation.getX();
|
||||
int y = textLocation.getY();
|
||||
|
||||
Font font = plugin.getFont();
|
||||
if (font != null)
|
||||
{
|
||||
graphics.setFont(font);
|
||||
}
|
||||
|
||||
graphics.setColor(Color.BLACK);
|
||||
graphics.drawString(text, x + 1, y + 1);
|
||||
|
||||
@@ -182,12 +185,6 @@ public class DevToolsOverlay extends Overlay
|
||||
int x = textLocation.getX();
|
||||
int y = textLocation.getY();
|
||||
|
||||
Font font = plugin.getFont();
|
||||
if (font != null)
|
||||
{
|
||||
graphics.setFont(font);
|
||||
}
|
||||
|
||||
graphics.setColor(Color.BLACK);
|
||||
graphics.drawString(text, x + 1, y + 1);
|
||||
|
||||
@@ -370,24 +367,29 @@ public class DevToolsOverlay extends Overlay
|
||||
private void renderInventory(Graphics2D graphics)
|
||||
{
|
||||
Widget inventoryWidget = client.getWidget(WidgetInfo.INVENTORY);
|
||||
if (inventoryWidget == null)
|
||||
if (inventoryWidget == null || inventoryWidget.isHidden())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for (WidgetItem item : inventoryWidget.getWidgetItems())
|
||||
{
|
||||
Rectangle bounds = item.getCanvasBounds();
|
||||
Rectangle slotBounds = item.getCanvasBounds();
|
||||
|
||||
Color[] colors = new Color[]
|
||||
{
|
||||
Color.RED, Color.GREEN, Color.BLUE
|
||||
};
|
||||
graphics.setColor(colors[item.getIndex() % 3]);
|
||||
if (bounds != null)
|
||||
{
|
||||
graphics.draw(bounds);
|
||||
}
|
||||
String idText = "" + item.getId();
|
||||
FontMetrics fm = graphics.getFontMetrics();
|
||||
Rectangle2D textBounds = fm.getStringBounds(idText, graphics);
|
||||
|
||||
int textX = (int) (slotBounds.getX() + (slotBounds.getWidth() / 2) - (textBounds.getWidth() / 2));
|
||||
int textY = (int) (slotBounds.getY() + (slotBounds.getHeight() / 2) + (textBounds.getHeight() / 2));
|
||||
|
||||
graphics.setColor(new Color(255, 255, 255, 65));
|
||||
graphics.fill(slotBounds);
|
||||
|
||||
graphics.setColor(Color.BLACK);
|
||||
graphics.drawString(idText, textX + 1, textY + 1);
|
||||
graphics.setColor(YELLOW);
|
||||
graphics.drawString(idText, textX, textY);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user