Updated DevTools plugin to contain a Widget tree

This commit is contained in:
Kronos
2017-04-28 13:56:53 +10:00
parent 0ba4dc0b13
commit b5cc159fa3
4 changed files with 262 additions and 101 deletions

View File

@@ -58,6 +58,11 @@ public class Widget
return widget.getType();
}
public int getContentType()
{
return widget.getContentType();
}
public Widget getParent()
{
int id = getParentId();
@@ -107,6 +112,26 @@ public class Widget
return widget.getText();
}
public int getTextColor()
{
return widget.getTextColor();
}
public String getName()
{
return widget.getName();
}
public int getModelId()
{
return widget.getModelId();
}
public int getTextureId()
{
return widget.getTextureId();
}
public boolean isHidden()
{
Widget parent = getParent();

View File

@@ -29,6 +29,7 @@ import java.awt.GraphicsEnvironment;
import java.awt.event.ActionEvent;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import net.runelite.client.RuneLite;
import net.runelite.client.plugins.Plugin;
import net.runelite.client.ui.ClientUI;
@@ -39,8 +40,6 @@ import org.slf4j.LoggerFactory;
public class DevTools extends Plugin
{
private static final Logger logger = LoggerFactory.getLogger(DevTools.class);
private final DevToolsOverlay overlay = new DevToolsOverlay(this);
private final DevToolsPanel panel = new DevToolsPanel(this);
private final NavigationButton navButton = new NavigationButton("DevTools");
@@ -54,7 +53,9 @@ public class DevTools extends Plugin
private boolean toggleWalls;
private boolean toggleDecor;
private boolean toggleInventory;
private boolean toggleWidgets;
private int widgetParent = -1;
private int widgetChild = -1;
private Font font;
@@ -91,98 +92,109 @@ public class DevTools extends Plugin
ui.expand(panel);
}
public Font getFont()
Font getFont()
{
return font;
}
public void togglePlayers()
void togglePlayers()
{
togglePlayers = !togglePlayers;
}
public void toggleNpcs()
void toggleNpcs()
{
toggleNpcs = !toggleNpcs;
}
public void toggleGroundItems()
void toggleGroundItems()
{
toggleGroundItems = !toggleGroundItems;
}
public void toggleGroundObjects()
void toggleGroundObjects()
{
toggleGroundObjects = !toggleGroundObjects;
}
public void toggleGameObjects()
void toggleGameObjects()
{
toggleGameObjects = !toggleGameObjects;
}
public void toggleWalls()
void toggleWalls()
{
toggleWalls = !toggleWalls;
}
public void toggleDecor()
void toggleDecor()
{
toggleDecor = !toggleDecor;
}
public void toggleInventory()
void toggleInventory()
{
toggleInventory = !toggleInventory;
}
public void toggleWidgets()
{
toggleWidgets = !toggleWidgets;
}
public boolean isTogglePlayers()
boolean isTogglePlayers()
{
return togglePlayers;
}
public boolean isToggleNpcs()
boolean isToggleNpcs()
{
return toggleNpcs;
}
public boolean isToggleGroundItems()
boolean isToggleGroundItems()
{
return toggleGroundItems;
}
public boolean isToggleGroundObjects()
boolean isToggleGroundObjects()
{
return toggleGroundObjects;
}
public boolean isToggleGameObjects()
boolean isToggleGameObjects()
{
return toggleGameObjects;
}
public boolean isToggleWalls()
boolean isToggleWalls()
{
return toggleWalls;
}
public boolean isToggleDecor()
boolean isToggleDecor()
{
return toggleDecor;
}
public boolean isToggleInventory()
boolean isToggleInventory()
{
return toggleInventory;
}
public boolean isToggleWidgets()
void setWidgetParent(int id)
{
return toggleWidgets;
widgetParent = id;
}
void setWidgetChild(int id)
{
widgetChild = id;
}
int getWidgetParent()
{
return widgetParent;
}
int getWidgetChild()
{
return widgetChild;
}
}

View File

@@ -70,13 +70,13 @@ public class DevToolsOverlay extends Overlay
private static final int REGION_SIZE = 104;
private static final int MAX_DISTANCE = 2400;
private final DevTools tools;
private final DevTools plugin;
private final Client client = RuneLite.getClient();
public DevToolsOverlay(DevTools tools)
public DevToolsOverlay(DevTools plugin)
{
super(OverlayPosition.DYNAMIC);
this.tools = tools;
this.plugin = plugin;
}
@Override
@@ -87,30 +87,27 @@ public class DevToolsOverlay extends Overlay
return null;
}
if (tools.isTogglePlayers())
if (plugin.isTogglePlayers())
{
renderPlayers(graphics);
}
if (tools.isToggleNpcs())
if (plugin.isToggleNpcs())
{
renderNpcs(graphics);
}
if (tools.isToggleGroundItems() || tools.isToggleGroundObjects() || tools.isToggleGameObjects() || tools.isToggleWalls() || tools.isToggleDecor())
if (plugin.isToggleGroundItems() || plugin.isToggleGroundObjects() || plugin.isToggleGameObjects() || plugin.isToggleWalls() || plugin.isToggleDecor())
{
renderTileObjects(graphics);
}
if (tools.isToggleInventory())
if (plugin.isToggleInventory())
{
renderInventory(graphics);
}
if (tools.isToggleWidgets())
{
renderWidgets(graphics);
}
renderWidget(graphics);
return null;
}
@@ -143,7 +140,7 @@ public class DevToolsOverlay extends Overlay
int x = textLocation.getX();
int y = textLocation.getY();
Font font = tools.getFont();
Font font = plugin.getFont();
if (font != null)
{
graphics.setFont(font);
@@ -185,7 +182,7 @@ public class DevToolsOverlay extends Overlay
int x = textLocation.getX();
int y = textLocation.getY();
Font font = tools.getFont();
Font font = plugin.getFont();
if (font != null)
{
graphics.setFont(font);
@@ -270,27 +267,27 @@ public class DevToolsOverlay extends Overlay
continue;
}
if (tools.isToggleGroundItems())
if (plugin.isToggleGroundItems())
{
renderGroundItems(graphics, tile, player);
}
if (tools.isToggleGroundObjects())
if (plugin.isToggleGroundObjects())
{
renderGroundObject(graphics, tile, player);
}
if (tools.isToggleGameObjects())
if (plugin.isToggleGameObjects())
{
renderGameObjects(graphics, tile, player);
}
if (tools.isToggleWalls())
if (plugin.isToggleWalls())
{
renderWallObject(graphics, tile, player);
}
if (tools.isToggleDecor())
if (plugin.isToggleDecor())
{
renderDecorObject(graphics, tile, player);
}
@@ -394,44 +391,22 @@ public class DevToolsOverlay extends Overlay
}
}
private void renderWidgets(Graphics2D graphics)
public void renderWidget(Graphics2D graphics)
{
Widget[][] widgets = client.getWidgets();
boolean[] validInterfaces = client.getValidInterfaces();
int parentID = plugin.getWidgetParent();
int childID = plugin.getWidgetChild();
int idx = -1;
for (Widget[] children : widgets)
if (parentID == -1)
{
++idx;
return;
}
if (!validInterfaces[idx])
{
continue;
}
if (children == null)
{
continue;
}
for (Widget child : children)
{
if (child == null || child.isHidden())
{
continue;
}
if (child.getText() == null)
{
continue;
}
Rectangle rectangle = child.getBounds();
//graphics.draw(rectangle);
graphics.drawString(child.getText(), (int) rectangle.getX(), (int) rectangle.getY());
}
Widget widget = client.getWidget(parentID, (childID == -1) ? 0 : childID);
if (widget != null && !widget.isHidden())
{
Rectangle bounds = widget.getBounds();
graphics.setColor(CYAN);
graphics.draw(bounds);
}
}

View File

@@ -24,15 +24,23 @@
*/
package net.runelite.client.plugins.devtools;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridLayout;
import javax.swing.JButton;
import javax.swing.JPanel;
import java.awt.*;
import javax.swing.*;
import javax.swing.border.EmptyBorder;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import net.runelite.api.Client;
import net.runelite.api.widgets.Widget;
import net.runelite.client.RuneLite;
import net.runelite.client.ui.PluginPanel;
public class DevToolsPanel extends PluginPanel
{
private final EmptyBorder PADDING_BORDER = new EmptyBorder(3, 3, 3, 3);
private final Client client = RuneLite.getClient();
private JButton renderPlayersBtn = new JButton();
private JButton renderNpcsBtn = new JButton();
private JButton renderGroundItemsBtn = new JButton();
@@ -41,24 +49,44 @@ public class DevToolsPanel extends PluginPanel
private JButton renderWallsBtn = new JButton();
private JButton renderDecorBtn = new JButton();
private JButton renderInventoryBtn = new JButton();
private JButton renderWidgetsBtn = new JButton();
public DevToolsPanel(DevTools tools)
private JLabel textLbl = new JLabel();
private JLabel textColorLbl = new JLabel();
private JLabel nameLbl = new JLabel();
private JLabel modelLbl = new JLabel();
private JLabel textureLbl = new JLabel();
private JLabel typeLbl = new JLabel();
private JLabel contentTypeLbl = new JLabel();
private DevTools plugin;
private DefaultMutableTreeNode widgetListRoot = new DefaultMutableTreeNode();
public DevToolsPanel(DevTools plugin)
{
this.plugin = plugin;
setMinimumSize(new Dimension(PANEL_WIDTH, PANEL_HEIGHT));
setPreferredSize(new Dimension(PANEL_WIDTH, PANEL_HEIGHT));
setSize(PANEL_WIDTH, PANEL_HEIGHT);
setLayout(new BorderLayout());
setVisible(true);
add(createOptionsPanel(), BorderLayout.NORTH);
add(createWidgetTreePanel(), BorderLayout.CENTER);
}
private JPanel createOptionsPanel()
{
JPanel container = new JPanel();
container.setLayout(new GridLayout(5, 2, 3, 3));
add(container);
container.setLayout(new GridLayout(4, 2, 3, 3));
container.setBorder(PADDING_BORDER);
renderPlayersBtn = new JButton("Players");
renderPlayersBtn.addActionListener(e ->
{
highlightButton(renderPlayersBtn);
tools.togglePlayers();
plugin.togglePlayers();
});
container.add(renderPlayersBtn);
@@ -66,7 +94,7 @@ public class DevToolsPanel extends PluginPanel
renderNpcsBtn.addActionListener(e ->
{
highlightButton(renderNpcsBtn);
tools.toggleNpcs();
plugin.toggleNpcs();
});
container.add(renderNpcsBtn);
@@ -74,7 +102,7 @@ public class DevToolsPanel extends PluginPanel
renderGroundItemsBtn.addActionListener(e ->
{
highlightButton(renderGroundItemsBtn);
tools.toggleGroundItems();
plugin.toggleGroundItems();
});
container.add(renderGroundItemsBtn);
@@ -82,7 +110,7 @@ public class DevToolsPanel extends PluginPanel
renderGroundObjectsBtn.addActionListener(e ->
{
highlightButton(renderGroundObjectsBtn);
tools.toggleGroundObjects();
plugin.toggleGroundObjects();
});
container.add(renderGroundObjectsBtn);
@@ -90,7 +118,7 @@ public class DevToolsPanel extends PluginPanel
renderGameObjectsBtn.addActionListener(e ->
{
highlightButton(renderGameObjectsBtn);
tools.toggleGameObjects();
plugin.toggleGameObjects();
});
container.add(renderGameObjectsBtn);
@@ -98,7 +126,7 @@ public class DevToolsPanel extends PluginPanel
renderWallsBtn.addActionListener(e ->
{
highlightButton(renderWallsBtn);
tools.toggleWalls();
plugin.toggleWalls();
});
container.add(renderWallsBtn);
@@ -106,7 +134,7 @@ public class DevToolsPanel extends PluginPanel
renderDecorBtn.addActionListener(e ->
{
highlightButton(renderDecorBtn);
tools.toggleDecor();
plugin.toggleDecor();
});
container.add(renderDecorBtn);
@@ -114,17 +142,96 @@ public class DevToolsPanel extends PluginPanel
renderInventoryBtn.addActionListener(e ->
{
highlightButton(renderInventoryBtn);
tools.toggleInventory();
plugin.toggleInventory();
});
container.add(renderInventoryBtn);
renderWidgetsBtn = new JButton("Widgets");
renderWidgetsBtn.addActionListener(e ->
return container;
}
private JPanel createWidgetTreePanel()
{
JPanel container = new JPanel();
container.setLayout(new BorderLayout());
JTree tree = new JTree(widgetListRoot);
tree.setRootVisible(false);
tree.setShowsRootHandles(true);
tree.getSelectionModel().addTreeSelectionListener(e ->
{
highlightButton(renderWidgetsBtn);
tools.toggleWidgets();
Object[] path = e.getPath().getPath();
plugin.setWidgetParent(Integer.parseInt(path[1].toString()));
plugin.setWidgetChild((path.length > 2) ? Integer.parseInt(path[2].toString()) : -1);
setWidgetInfo();
});
container.add(renderWidgetsBtn);
JScrollPane scrollPane = new JScrollPane(tree);
scrollPane.setBorder(PADDING_BORDER);
container.add(scrollPane, BorderLayout.CENTER);
JButton refreshWidgetsBtn = new JButton("Refresh Widgets");
refreshWidgetsBtn.addActionListener(e ->
{
refreshWidgets();
tree.setModel(new DefaultTreeModel(widgetListRoot));
});
JPanel btnContainer = new JPanel();
btnContainer.setLayout(new BorderLayout());
btnContainer.setBorder(PADDING_BORDER);
btnContainer.add(refreshWidgetsBtn);
container.add(btnContainer, BorderLayout.NORTH);
JPanel infoContainer = new JPanel();
infoContainer.setLayout(new GridLayout(0, 1));
textLbl = new JLabel("Text: ");
textColorLbl = new JLabel("Text Color: ");
nameLbl = new JLabel("Name: ");
modelLbl = new JLabel("Model ID: ");
textureLbl = new JLabel("Texture ID: ");
typeLbl = new JLabel("Type: ");
contentTypeLbl = new JLabel("Content Type: ");
infoContainer.add(textLbl);
infoContainer.add(textColorLbl);
infoContainer.add(nameLbl);
infoContainer.add(modelLbl);
infoContainer.add(textureLbl);
infoContainer.add(typeLbl);
infoContainer.add(contentTypeLbl);
JScrollPane infoScrollPane = new JScrollPane(infoContainer);
infoScrollPane.setBorder(new EmptyBorder(6, 6, 6, 6));
container.add(infoScrollPane, BorderLayout.SOUTH);
return container;
}
private void setWidgetInfo()
{
int parent = plugin.getWidgetParent();
int child = plugin.getWidgetChild();
if (parent == -1)
{
return;
}
Widget widget = client.getWidget(parent, (child == -1) ? 0 : child);
if (widget == null)
{
return;
}
textLbl.setText("Text: " + widget.getText().trim());
textColorLbl.setText("Text Color: " + widget.getTextColor());
nameLbl.setText("Name: " + widget.getName().trim());
modelLbl.setText("Model ID: " + widget.getModelId());
textureLbl.setText("Texture ID: " + widget.getTextureId());
typeLbl.setText("Type: " + widget.getType());
contentTypeLbl.setText("Content Type: " + widget.getContentType());
}
private void highlightButton(JButton button)
@@ -139,4 +246,46 @@ public class DevToolsPanel extends PluginPanel
}
}
private void refreshWidgets()
{
Widget[][] widgets = client.getWidgets();
boolean[] validInterfaces = client.getValidInterfaces();
DefaultMutableTreeNode root = new DefaultMutableTreeNode();
plugin.setWidgetParent(-1);
plugin.setWidgetChild(-1);
int idx = -1;
for (Widget[] children : widgets)
{
++idx;
if (!validInterfaces[idx])
{
continue;
}
if (children == null)
{
continue;
}
DefaultMutableTreeNode parent = new DefaultMutableTreeNode(idx);
root.add(parent);
for (Widget child : children)
{
if (child == null || child.isHidden())
{
continue;
}
parent.add(new DefaultMutableTreeNode(child.getId() & 0xFFFF));
}
}
widgetListRoot = root;
}
}