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