From 9d7ffa56ae65e027dd8bd03dbac5785a9aa999a3 Mon Sep 17 00:00:00 2001 From: Seth Date: Tue, 6 Mar 2018 23:37:03 -0600 Subject: [PATCH] dev tools: add location to dev tools plugin Adds a panel which will display current tile in relation to world location as well as display the current map regions --- .../plugins/devtools/DevToolsPanel.java | 11 ++- .../plugins/devtools/DevToolsPlugin.java | 20 ++++- .../plugins/devtools/LocationOverlay.java | 81 +++++++++++++++++++ 3 files changed, 109 insertions(+), 3 deletions(-) create mode 100644 runelite-client/src/main/java/net/runelite/client/plugins/devtools/LocationOverlay.java diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/devtools/DevToolsPanel.java b/runelite-client/src/main/java/net/runelite/client/plugins/devtools/DevToolsPanel.java index ade7811931..f98739b42d 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/devtools/DevToolsPanel.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/devtools/DevToolsPanel.java @@ -65,6 +65,7 @@ public class DevToolsPanel extends PluginPanel private JButton renderInventoryBtn = new JButton(); private JButton renderProjectilesBtn = new JButton(); private JPanel boundsDebugPanel = new JPanel(); + private JButton renderLocationBtn = new JButton(); private JLabel textLbl = new JLabel(); private JLabel textColorLbl = new JLabel(); @@ -103,7 +104,7 @@ public class DevToolsPanel extends PluginPanel private JPanel createOptionsPanel() { JPanel container = new JPanel(); - container.setLayout(new GridLayout(6, 2, 3, 3)); + container.setLayout(new GridLayout(7, 2, 3, 3)); renderPlayersBtn = new JButton("Players"); renderPlayersBtn.addActionListener(e -> @@ -188,6 +189,14 @@ public class DevToolsPanel extends PluginPanel settingsClearBtn.addActionListener(settingsTracker::clear); container.add(settingsClearBtn); + renderLocationBtn = new JButton("Location"); + renderLocationBtn.addActionListener(e -> + { + highlightButton(renderLocationBtn); + plugin.toggleLocation(); + }); + container.add(renderLocationBtn); + return container; } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/devtools/DevToolsPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/devtools/DevToolsPlugin.java index 57af4a5570..752ae9de83 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/devtools/DevToolsPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/devtools/DevToolsPlugin.java @@ -26,6 +26,8 @@ package net.runelite.client.plugins.devtools; import java.awt.Font; import java.awt.image.BufferedImage; +import java.util.Arrays; +import java.util.Collection; import javax.imageio.ImageIO; import javax.inject.Inject; import net.runelite.api.widgets.Widget; @@ -48,6 +50,9 @@ public class DevToolsPlugin extends Plugin @Inject private DevToolsOverlay overlay; + @Inject + private LocationOverlay locationOverlay; + private boolean togglePlayers; private boolean toggleNpcs; private boolean toggleGroundItems; @@ -57,6 +62,7 @@ public class DevToolsPlugin extends Plugin private boolean toggleDecor; private boolean toggleInventory; private boolean toggleProjectiles; + private boolean toggleLocation; Widget currentWidget; int itemIndex = -1; @@ -93,9 +99,9 @@ public class DevToolsPlugin extends Plugin } @Override - public Overlay getOverlay() + public Collection getOverlays() { - return overlay; + return Arrays.asList(overlay, locationOverlay); } Font getFont() @@ -148,6 +154,11 @@ public class DevToolsPlugin extends Plugin toggleProjectiles = !toggleProjectiles; } + void toggleLocation() + { + toggleLocation = !toggleLocation; + } + boolean isTogglePlayers() { return togglePlayers; @@ -192,4 +203,9 @@ public class DevToolsPlugin extends Plugin { return toggleProjectiles; } + + boolean isToggleLocation() + { + return toggleLocation; + } } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/devtools/LocationOverlay.java b/runelite-client/src/main/java/net/runelite/client/plugins/devtools/LocationOverlay.java new file mode 100644 index 0000000000..dcdb765ac1 --- /dev/null +++ b/runelite-client/src/main/java/net/runelite/client/plugins/devtools/LocationOverlay.java @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2018, Seth + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this + * list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +package net.runelite.client.plugins.devtools; + +import java.awt.Dimension; +import java.awt.Graphics2D; +import javax.inject.Inject; +import net.runelite.api.Client; +import net.runelite.api.Point; +import net.runelite.client.ui.overlay.Overlay; +import net.runelite.client.ui.overlay.OverlayPosition; +import net.runelite.client.ui.overlay.components.PanelComponent; + +public class LocationOverlay extends Overlay +{ + private final Client client; + private final DevToolsPlugin plugin; + + private PanelComponent panelComponent; + + @Inject + LocationOverlay(Client client, DevToolsPlugin plugin) + { + setPosition(OverlayPosition.TOP_LEFT); + this.client = client; + this.plugin = plugin; + } + + @Override + public Dimension render(Graphics2D graphics, java.awt.Point parent) + { + if (!plugin.isToggleLocation()) + { + return null; + } + + panelComponent = new PanelComponent(); + + Point localWorld = client.getLocalPlayer().getWorldLocation(); + + panelComponent.getLines().add(new PanelComponent.Line( + "Tile", + localWorld.getX() + ", " + localWorld.getY() + ", " + client.getPlane() + )); + + for (int i = 0; i < client.getMapRegions().length; i++) + { + int region = client.getMapRegions()[i]; + + panelComponent.getLines().add(new PanelComponent.Line( + (i == 0) ? "Map region" : " ", + String.valueOf(region) + )); + } + + + return panelComponent.render(graphics, parent); + } +}