Merge pull request #35 from KronosDesign/dev-tools

Updated DevTools plugin to contain a Widget tree
This commit is contained in:
Adam
2017-04-28 08:00:51 -04:00
committed by GitHub
4 changed files with 262 additions and 101 deletions

View File

@@ -58,6 +58,11 @@ public class Widget
return widget.getType(); return widget.getType();
} }
public int getContentType()
{
return widget.getContentType();
}
public Widget getParent() public Widget getParent()
{ {
int id = getParentId(); int id = getParentId();
@@ -107,6 +112,26 @@ public class Widget
return widget.getText(); 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() public boolean isHidden()
{ {
Widget parent = getParent(); Widget parent = getParent();

View File

@@ -29,6 +29,7 @@ import java.awt.GraphicsEnvironment;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
import javax.swing.ImageIcon; import javax.swing.ImageIcon;
import net.runelite.client.RuneLite; import net.runelite.client.RuneLite;
import net.runelite.client.plugins.Plugin; import net.runelite.client.plugins.Plugin;
import net.runelite.client.ui.ClientUI; import net.runelite.client.ui.ClientUI;
@@ -39,8 +40,6 @@ import org.slf4j.LoggerFactory;
public class DevTools extends Plugin public class DevTools extends Plugin
{ {
private static final Logger logger = LoggerFactory.getLogger(DevTools.class);
private final DevToolsOverlay overlay = new DevToolsOverlay(this); private final DevToolsOverlay overlay = new DevToolsOverlay(this);
private final DevToolsPanel panel = new DevToolsPanel(this); private final DevToolsPanel panel = new DevToolsPanel(this);
private final NavigationButton navButton = new NavigationButton("DevTools"); private final NavigationButton navButton = new NavigationButton("DevTools");
@@ -54,7 +53,9 @@ public class DevTools extends Plugin
private boolean toggleWalls; private boolean toggleWalls;
private boolean toggleDecor; private boolean toggleDecor;
private boolean toggleInventory; private boolean toggleInventory;
private boolean toggleWidgets;
private int widgetParent = -1;
private int widgetChild = -1;
private Font font; private Font font;
@@ -91,98 +92,109 @@ public class DevTools extends Plugin
ui.expand(panel); ui.expand(panel);
} }
public Font getFont() Font getFont()
{ {
return font; return font;
} }
public void togglePlayers() void togglePlayers()
{ {
togglePlayers = !togglePlayers; togglePlayers = !togglePlayers;
} }
public void toggleNpcs() void toggleNpcs()
{ {
toggleNpcs = !toggleNpcs; toggleNpcs = !toggleNpcs;
} }
public void toggleGroundItems() void toggleGroundItems()
{ {
toggleGroundItems = !toggleGroundItems; toggleGroundItems = !toggleGroundItems;
} }
public void toggleGroundObjects() void toggleGroundObjects()
{ {
toggleGroundObjects = !toggleGroundObjects; toggleGroundObjects = !toggleGroundObjects;
} }
public void toggleGameObjects() void toggleGameObjects()
{ {
toggleGameObjects = !toggleGameObjects; toggleGameObjects = !toggleGameObjects;
} }
public void toggleWalls() void toggleWalls()
{ {
toggleWalls = !toggleWalls; toggleWalls = !toggleWalls;
} }
public void toggleDecor() void toggleDecor()
{ {
toggleDecor = !toggleDecor; toggleDecor = !toggleDecor;
} }
public void toggleInventory() void toggleInventory()
{ {
toggleInventory = !toggleInventory; toggleInventory = !toggleInventory;
} }
public void toggleWidgets() boolean isTogglePlayers()
{
toggleWidgets = !toggleWidgets;
}
public boolean isTogglePlayers()
{ {
return togglePlayers; return togglePlayers;
} }
public boolean isToggleNpcs() boolean isToggleNpcs()
{ {
return toggleNpcs; return toggleNpcs;
} }
public boolean isToggleGroundItems() boolean isToggleGroundItems()
{ {
return toggleGroundItems; return toggleGroundItems;
} }
public boolean isToggleGroundObjects() boolean isToggleGroundObjects()
{ {
return toggleGroundObjects; return toggleGroundObjects;
} }
public boolean isToggleGameObjects() boolean isToggleGameObjects()
{ {
return toggleGameObjects; return toggleGameObjects;
} }
public boolean isToggleWalls() boolean isToggleWalls()
{ {
return toggleWalls; return toggleWalls;
} }
public boolean isToggleDecor() boolean isToggleDecor()
{ {
return toggleDecor; return toggleDecor;
} }
public boolean isToggleInventory() boolean isToggleInventory()
{ {
return toggleInventory; 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 REGION_SIZE = 104;
private static final int MAX_DISTANCE = 2400; private static final int MAX_DISTANCE = 2400;
private final DevTools tools; private final DevTools plugin;
private final Client client = RuneLite.getClient(); private final Client client = RuneLite.getClient();
public DevToolsOverlay(DevTools tools) public DevToolsOverlay(DevTools plugin)
{ {
super(OverlayPosition.DYNAMIC); super(OverlayPosition.DYNAMIC);
this.tools = tools; this.plugin = plugin;
} }
@Override @Override
@@ -87,30 +87,27 @@ public class DevToolsOverlay extends Overlay
return null; return null;
} }
if (tools.isTogglePlayers()) if (plugin.isTogglePlayers())
{ {
renderPlayers(graphics); renderPlayers(graphics);
} }
if (tools.isToggleNpcs()) if (plugin.isToggleNpcs())
{ {
renderNpcs(graphics); 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); renderTileObjects(graphics);
} }
if (tools.isToggleInventory()) if (plugin.isToggleInventory())
{ {
renderInventory(graphics); renderInventory(graphics);
} }
if (tools.isToggleWidgets()) renderWidget(graphics);
{
renderWidgets(graphics);
}
return null; return null;
} }
@@ -143,7 +140,7 @@ public class DevToolsOverlay extends Overlay
int x = textLocation.getX(); int x = textLocation.getX();
int y = textLocation.getY(); int y = textLocation.getY();
Font font = tools.getFont(); Font font = plugin.getFont();
if (font != null) if (font != null)
{ {
graphics.setFont(font); graphics.setFont(font);
@@ -185,7 +182,7 @@ public class DevToolsOverlay extends Overlay
int x = textLocation.getX(); int x = textLocation.getX();
int y = textLocation.getY(); int y = textLocation.getY();
Font font = tools.getFont(); Font font = plugin.getFont();
if (font != null) if (font != null)
{ {
graphics.setFont(font); graphics.setFont(font);
@@ -270,27 +267,27 @@ public class DevToolsOverlay extends Overlay
continue; continue;
} }
if (tools.isToggleGroundItems()) if (plugin.isToggleGroundItems())
{ {
renderGroundItems(graphics, tile, player); renderGroundItems(graphics, tile, player);
} }
if (tools.isToggleGroundObjects()) if (plugin.isToggleGroundObjects())
{ {
renderGroundObject(graphics, tile, player); renderGroundObject(graphics, tile, player);
} }
if (tools.isToggleGameObjects()) if (plugin.isToggleGameObjects())
{ {
renderGameObjects(graphics, tile, player); renderGameObjects(graphics, tile, player);
} }
if (tools.isToggleWalls()) if (plugin.isToggleWalls())
{ {
renderWallObject(graphics, tile, player); renderWallObject(graphics, tile, player);
} }
if (tools.isToggleDecor()) if (plugin.isToggleDecor())
{ {
renderDecorObject(graphics, tile, player); 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(); int parentID = plugin.getWidgetParent();
boolean[] validInterfaces = client.getValidInterfaces(); int childID = plugin.getWidgetChild();
int idx = -1; if (parentID == -1)
for (Widget[] children : widgets)
{ {
++idx; return;
}
if (!validInterfaces[idx]) Widget widget = client.getWidget(parentID, (childID == -1) ? 0 : childID);
{ if (widget != null && !widget.isHidden())
continue; {
} Rectangle bounds = widget.getBounds();
graphics.setColor(CYAN);
if (children == null) graphics.draw(bounds);
{
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());
}
} }
} }

View File

@@ -24,15 +24,23 @@
*/ */
package net.runelite.client.plugins.devtools; package net.runelite.client.plugins.devtools;
import java.awt.Color; import java.awt.*;
import java.awt.Dimension; import javax.swing.*;
import java.awt.GridLayout; import javax.swing.border.EmptyBorder;
import javax.swing.JButton; import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.JPanel; 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; import net.runelite.client.ui.PluginPanel;
public class DevToolsPanel extends 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 renderPlayersBtn = new JButton();
private JButton renderNpcsBtn = new JButton(); private JButton renderNpcsBtn = new JButton();
private JButton renderGroundItemsBtn = new JButton(); private JButton renderGroundItemsBtn = new JButton();
@@ -41,24 +49,44 @@ public class DevToolsPanel extends PluginPanel
private JButton renderWallsBtn = new JButton(); private JButton renderWallsBtn = new JButton();
private JButton renderDecorBtn = new JButton(); private JButton renderDecorBtn = new JButton();
private JButton renderInventoryBtn = 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)); setMinimumSize(new Dimension(PANEL_WIDTH, PANEL_HEIGHT));
setPreferredSize(new Dimension(PANEL_WIDTH, PANEL_HEIGHT)); setPreferredSize(new Dimension(PANEL_WIDTH, PANEL_HEIGHT));
setSize(PANEL_WIDTH, PANEL_HEIGHT); setSize(PANEL_WIDTH, PANEL_HEIGHT);
setLayout(new BorderLayout());
setVisible(true); setVisible(true);
add(createOptionsPanel(), BorderLayout.NORTH);
add(createWidgetTreePanel(), BorderLayout.CENTER);
}
private JPanel createOptionsPanel()
{
JPanel container = new JPanel(); JPanel container = new JPanel();
container.setLayout(new GridLayout(5, 2, 3, 3)); container.setLayout(new GridLayout(4, 2, 3, 3));
add(container); container.setBorder(PADDING_BORDER);
renderPlayersBtn = new JButton("Players"); renderPlayersBtn = new JButton("Players");
renderPlayersBtn.addActionListener(e -> renderPlayersBtn.addActionListener(e ->
{ {
highlightButton(renderPlayersBtn); highlightButton(renderPlayersBtn);
tools.togglePlayers(); plugin.togglePlayers();
}); });
container.add(renderPlayersBtn); container.add(renderPlayersBtn);
@@ -66,7 +94,7 @@ public class DevToolsPanel extends PluginPanel
renderNpcsBtn.addActionListener(e -> renderNpcsBtn.addActionListener(e ->
{ {
highlightButton(renderNpcsBtn); highlightButton(renderNpcsBtn);
tools.toggleNpcs(); plugin.toggleNpcs();
}); });
container.add(renderNpcsBtn); container.add(renderNpcsBtn);
@@ -74,7 +102,7 @@ public class DevToolsPanel extends PluginPanel
renderGroundItemsBtn.addActionListener(e -> renderGroundItemsBtn.addActionListener(e ->
{ {
highlightButton(renderGroundItemsBtn); highlightButton(renderGroundItemsBtn);
tools.toggleGroundItems(); plugin.toggleGroundItems();
}); });
container.add(renderGroundItemsBtn); container.add(renderGroundItemsBtn);
@@ -82,7 +110,7 @@ public class DevToolsPanel extends PluginPanel
renderGroundObjectsBtn.addActionListener(e -> renderGroundObjectsBtn.addActionListener(e ->
{ {
highlightButton(renderGroundObjectsBtn); highlightButton(renderGroundObjectsBtn);
tools.toggleGroundObjects(); plugin.toggleGroundObjects();
}); });
container.add(renderGroundObjectsBtn); container.add(renderGroundObjectsBtn);
@@ -90,7 +118,7 @@ public class DevToolsPanel extends PluginPanel
renderGameObjectsBtn.addActionListener(e -> renderGameObjectsBtn.addActionListener(e ->
{ {
highlightButton(renderGameObjectsBtn); highlightButton(renderGameObjectsBtn);
tools.toggleGameObjects(); plugin.toggleGameObjects();
}); });
container.add(renderGameObjectsBtn); container.add(renderGameObjectsBtn);
@@ -98,7 +126,7 @@ public class DevToolsPanel extends PluginPanel
renderWallsBtn.addActionListener(e -> renderWallsBtn.addActionListener(e ->
{ {
highlightButton(renderWallsBtn); highlightButton(renderWallsBtn);
tools.toggleWalls(); plugin.toggleWalls();
}); });
container.add(renderWallsBtn); container.add(renderWallsBtn);
@@ -106,7 +134,7 @@ public class DevToolsPanel extends PluginPanel
renderDecorBtn.addActionListener(e -> renderDecorBtn.addActionListener(e ->
{ {
highlightButton(renderDecorBtn); highlightButton(renderDecorBtn);
tools.toggleDecor(); plugin.toggleDecor();
}); });
container.add(renderDecorBtn); container.add(renderDecorBtn);
@@ -114,17 +142,96 @@ public class DevToolsPanel extends PluginPanel
renderInventoryBtn.addActionListener(e -> renderInventoryBtn.addActionListener(e ->
{ {
highlightButton(renderInventoryBtn); highlightButton(renderInventoryBtn);
tools.toggleInventory(); plugin.toggleInventory();
}); });
container.add(renderInventoryBtn); container.add(renderInventoryBtn);
renderWidgetsBtn = new JButton("Widgets"); return container;
renderWidgetsBtn.addActionListener(e -> }
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); Object[] path = e.getPath().getPath();
tools.toggleWidgets(); 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) 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;
}
} }