Updated DevTools for viewing widget components
This commit is contained in:
@@ -54,6 +54,7 @@ public class DevTools extends Plugin
|
||||
|
||||
private int widgetParent = -1;
|
||||
private int widgetChild = -1;
|
||||
private int widgetItem = -1;
|
||||
|
||||
private Font font;
|
||||
|
||||
@@ -185,6 +186,11 @@ public class DevTools extends Plugin
|
||||
widgetChild = id;
|
||||
}
|
||||
|
||||
void setWidgetItem(int id)
|
||||
{
|
||||
widgetItem = id;
|
||||
}
|
||||
|
||||
int getWidgetParent()
|
||||
{
|
||||
return widgetParent;
|
||||
@@ -195,4 +201,9 @@ public class DevTools extends Plugin
|
||||
return widgetChild;
|
||||
}
|
||||
|
||||
int getWidgetItem()
|
||||
{
|
||||
return widgetItem;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -60,6 +60,9 @@ import net.runelite.client.ui.overlay.OverlayPosition;
|
||||
|
||||
public class DevToolsOverlay extends Overlay
|
||||
{
|
||||
public static final int ITEM_EMPTY = 6512;
|
||||
public static final int ITEM_FILLED = 20594;
|
||||
|
||||
private static final Color RED = new Color(221, 44, 0);
|
||||
private static final Color GREEN = new Color(0, 200, 83);
|
||||
private static final Color ORANGE = new Color(255, 109, 0);
|
||||
@@ -116,7 +119,7 @@ public class DevToolsOverlay extends Overlay
|
||||
renderInventory(graphics);
|
||||
}
|
||||
|
||||
renderWidget(graphics);
|
||||
renderWidgets(graphics);
|
||||
|
||||
return null;
|
||||
}
|
||||
@@ -393,23 +396,92 @@ public class DevToolsOverlay extends Overlay
|
||||
}
|
||||
}
|
||||
|
||||
public void renderWidget(Graphics2D graphics)
|
||||
public void renderWidgets(Graphics2D graphics)
|
||||
{
|
||||
int parentID = plugin.getWidgetParent();
|
||||
int childID = plugin.getWidgetChild();
|
||||
int itemIndex = plugin.getWidgetItem();
|
||||
|
||||
if (parentID == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Widget widget = client.getWidget(parentID, (childID == -1) ? 0 : childID);
|
||||
if (widget != null && !widget.isHidden())
|
||||
Widget widgetParent = client.getWidget(parentID, 0);
|
||||
if (widgetParent == null || widgetParent.isHidden())
|
||||
{
|
||||
Rectangle bounds = widget.getBounds();
|
||||
graphics.setColor(CYAN);
|
||||
graphics.draw(bounds);
|
||||
return;
|
||||
}
|
||||
|
||||
Rectangle parentBounds = widgetParent.getBounds();
|
||||
graphics.setColor(YELLOW);
|
||||
graphics.draw(parentBounds);
|
||||
|
||||
if (childID == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Widget widgetChild = client.getWidget(parentID, childID);
|
||||
if (widgetChild == null || widgetChild.isHidden())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Rectangle childBounds = widgetChild.getBounds();
|
||||
graphics.setColor(CYAN);
|
||||
graphics.draw(childBounds);
|
||||
|
||||
if (itemIndex == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Widget childComponent = widgetChild.getChild(itemIndex);
|
||||
if (childComponent != null && !childComponent.isHidden()
|
||||
&& childComponent.getItemId() != ITEM_EMPTY
|
||||
&& childComponent.getItemId() != ITEM_FILLED)
|
||||
{
|
||||
Rectangle componentBounds = childComponent.getBounds();
|
||||
|
||||
graphics.setColor(ORANGE);
|
||||
graphics.draw(componentBounds);
|
||||
|
||||
renderWidgetText(graphics, componentBounds, childComponent.getItemId(), YELLOW);
|
||||
}
|
||||
|
||||
WidgetItem widgetItem = widgetChild.getWidgetItem(itemIndex);
|
||||
if (widgetItem == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Rectangle itemBounds = widgetItem.getCanvasBounds();
|
||||
|
||||
graphics.setColor(ORANGE);
|
||||
graphics.draw(itemBounds);
|
||||
|
||||
renderWidgetText(graphics, itemBounds, widgetItem.getId(), YELLOW);
|
||||
}
|
||||
|
||||
private void renderWidgetText(Graphics2D graphics, Rectangle bounds, int itemId, Color color)
|
||||
{
|
||||
if (itemId == -1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
String text = itemId + "";
|
||||
FontMetrics fm = graphics.getFontMetrics();
|
||||
Rectangle2D textBounds = fm.getStringBounds(text, graphics);
|
||||
|
||||
int textX = (int) (bounds.getX() + (bounds.getWidth() / 2) - (textBounds.getWidth() / 2));
|
||||
int textY = (int) (bounds.getY() + (bounds.getHeight() / 2) + (textBounds.getHeight() / 2));
|
||||
|
||||
graphics.setColor(Color.BLACK);
|
||||
graphics.drawString(text, textX + 1, textY + 1);
|
||||
graphics.setColor(color);
|
||||
graphics.drawString(text, textX, textY);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
package net.runelite.client.plugins.devtools;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.Collection;
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.EmptyBorder;
|
||||
import javax.swing.tree.DefaultMutableTreeNode;
|
||||
@@ -32,7 +33,10 @@ import javax.swing.tree.DefaultTreeModel;
|
||||
|
||||
import net.runelite.api.Client;
|
||||
import net.runelite.api.widgets.Widget;
|
||||
import net.runelite.api.widgets.WidgetItem;
|
||||
import net.runelite.client.RuneLite;
|
||||
import static net.runelite.client.plugins.devtools.DevToolsOverlay.ITEM_EMPTY;
|
||||
import static net.runelite.client.plugins.devtools.DevToolsOverlay.ITEM_FILLED;
|
||||
import net.runelite.client.ui.PluginPanel;
|
||||
|
||||
public class DevToolsPanel extends PluginPanel
|
||||
@@ -174,6 +178,7 @@ public class DevToolsPanel extends PluginPanel
|
||||
Object[] path = e.getPath().getPath();
|
||||
plugin.setWidgetParent(Integer.parseInt(path[1].toString()));
|
||||
plugin.setWidgetChild((path.length > 2) ? Integer.parseInt(path[2].toString()) : -1);
|
||||
plugin.setWidgetItem((path.length > 3) ? Integer.parseInt(path[3].toString()) : -1);
|
||||
setWidgetInfo();
|
||||
});
|
||||
|
||||
@@ -266,6 +271,7 @@ public class DevToolsPanel extends PluginPanel
|
||||
|
||||
plugin.setWidgetParent(-1);
|
||||
plugin.setWidgetChild(-1);
|
||||
plugin.setWidgetItem(-1);
|
||||
|
||||
int idx = -1;
|
||||
|
||||
@@ -286,14 +292,50 @@ public class DevToolsPanel extends PluginPanel
|
||||
DefaultMutableTreeNode parent = new DefaultMutableTreeNode(idx);
|
||||
root.add(parent);
|
||||
|
||||
for (Widget child : children)
|
||||
for (Widget widgetChild : children)
|
||||
{
|
||||
if (child == null || child.isHidden())
|
||||
if (widgetChild == null || widgetChild.isHidden())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
parent.add(new DefaultMutableTreeNode(child.getId() & 0xFFFF));
|
||||
DefaultMutableTreeNode child = new DefaultMutableTreeNode(widgetChild.getId() & 0xFFFF);
|
||||
parent.add(child);
|
||||
|
||||
Widget[] childComponents = widgetChild.getChildren();
|
||||
if (childComponents != null)
|
||||
{
|
||||
int index = -1;
|
||||
for (Widget component : childComponents)
|
||||
{
|
||||
index++;
|
||||
if (component == null || component.isHidden()
|
||||
|| component.getItemId() == ITEM_EMPTY
|
||||
|| component.getItemId() == ITEM_FILLED)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
child.add(new DefaultMutableTreeNode(index));
|
||||
}
|
||||
}
|
||||
|
||||
Collection<WidgetItem> items = widgetChild.getWidgetItems();
|
||||
if (items == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
for (WidgetItem item : items)
|
||||
{
|
||||
|
||||
if (item == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
child.add(new DefaultMutableTreeNode(item.getIndex()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user