Unify dev tools toggles to 1 button type

- Create custom button type with isActive property
- Query this new property instead of bunch of stored boolans and toggle
methods in dev tools overlays and panels

Signed-off-by: Tomas Slusny <slusnucky@gmail.com>
This commit is contained in:
Tomas Slusny
2018-11-26 11:13:54 +00:00
parent 6aec578aa9
commit cd34fa36cf
9 changed files with 189 additions and 424 deletions

View File

@@ -52,7 +52,7 @@ public class CameraOverlay extends Overlay
@Override @Override
public Dimension render(Graphics2D graphics) public Dimension render(Graphics2D graphics)
{ {
if (!plugin.isToggleCamera()) if (!plugin.getCameraPosition().isActive())
{ {
return null; return null;
} }

View File

@@ -0,0 +1,55 @@
/*
* Copyright (c) 2018, Tomas Slusny <slusnucky@gmail.com>
* 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.Color;
import javax.swing.JButton;
import lombok.Getter;
class DevToolsButton extends JButton
{
@Getter
private boolean active;
DevToolsButton(String title)
{
super(title);
addActionListener((ev) -> setActive(!active));
}
void setActive(boolean active)
{
this.active = active;
if (active)
{
setBackground(Color.GREEN);
}
else
{
setBackground(null);
}
}
}

View File

@@ -103,32 +103,32 @@ public class DevToolsOverlay extends Overlay
{ {
graphics.setFont(FONT); graphics.setFont(FONT);
if (plugin.isTogglePlayers()) if (plugin.getPlayers().isActive())
{ {
renderPlayers(graphics); renderPlayers(graphics);
} }
if (plugin.isToggleNpcs()) if (plugin.getNpcs().isActive())
{ {
renderNpcs(graphics); renderNpcs(graphics);
} }
if (plugin.isToggleGroundItems() || plugin.isToggleGroundObjects() || plugin.isToggleGameObjects() || plugin.isToggleWalls() || plugin.isToggleDecor() || plugin.isToggleTileLocation()) if (plugin.getGroundItems().isActive() || plugin.getGroundObjects().isActive() || plugin.getGameObjects().isActive() || plugin.getWalls().isActive() || plugin.getDecorations().isActive() || plugin.getTileLocation().isActive())
{ {
renderTileObjects(graphics); renderTileObjects(graphics);
} }
if (plugin.isToggleInventory()) if (plugin.getInventory().isActive())
{ {
renderInventory(graphics); renderInventory(graphics);
} }
if (plugin.isToggleProjectiles()) if (plugin.getProjectiles().isActive())
{ {
renderProjectiles(graphics); renderProjectiles(graphics);
} }
if (plugin.isToggleGraphicsObjects()) if (plugin.getGraphicsObjects().isActive())
{ {
renderGraphicsObjects(graphics); renderGraphicsObjects(graphics);
} }
@@ -211,32 +211,32 @@ public class DevToolsOverlay extends Overlay
continue; continue;
} }
if (plugin.isToggleGroundItems()) if (plugin.getGroundItems().isActive())
{ {
renderGroundItems(graphics, tile, player); renderGroundItems(graphics, tile, player);
} }
if (plugin.isToggleGroundObjects()) if (plugin.getGroundObjects().isActive())
{ {
renderGroundObject(graphics, tile, player); renderGroundObject(graphics, tile, player);
} }
if (plugin.isToggleGameObjects()) if (plugin.getGameObjects().isActive())
{ {
renderGameObjects(graphics, tile, player); renderGameObjects(graphics, tile, player);
} }
if (plugin.isToggleWalls()) if (plugin.getWalls().isActive())
{ {
renderWallObject(graphics, tile, player); renderWallObject(graphics, tile, player);
} }
if (plugin.isToggleDecor()) if (plugin.getDecorations().isActive())
{ {
renderDecorObject(graphics, tile, player); renderDecorObject(graphics, tile, player);
} }
if (plugin.isToggleTileLocation()) if (plugin.getTileLocation().isActive())
{ {
renderTileTooltip(graphics, tile); renderTileTooltip(graphics, tile);
} }

View File

@@ -25,10 +25,8 @@
*/ */
package net.runelite.client.plugins.devtools; package net.runelite.client.plugins.devtools;
import java.awt.Color;
import java.awt.GridLayout; import java.awt.GridLayout;
import javax.inject.Inject; import javax.inject.Inject;
import javax.swing.JButton;
import javax.swing.JPanel; import javax.swing.JPanel;
import net.runelite.api.Client; import net.runelite.api.Client;
import net.runelite.client.ui.ColorScheme; import net.runelite.client.ui.ColorScheme;
@@ -43,7 +41,7 @@ public class DevToolsPanel extends PluginPanel
private final VarInspector varInspector; private final VarInspector varInspector;
@Inject @Inject
public DevToolsPanel(Client client, DevToolsPlugin plugin, WidgetInspector widgetInspector, VarInspector varInspector) private DevToolsPanel(Client client, DevToolsPlugin plugin, WidgetInspector widgetInspector, VarInspector varInspector)
{ {
super(); super();
this.client = client; this.client = client;
@@ -62,204 +60,65 @@ public class DevToolsPanel extends PluginPanel
container.setBackground(ColorScheme.DARK_GRAY_COLOR); container.setBackground(ColorScheme.DARK_GRAY_COLOR);
container.setLayout(new GridLayout(0, 2, 3, 3)); container.setLayout(new GridLayout(0, 2, 3, 3));
final JButton renderPlayersBtn = new JButton("Players"); container.add(plugin.getPlayers());
renderPlayersBtn.addActionListener(e -> container.add(plugin.getNpcs());
{
highlightButton(renderPlayersBtn);
plugin.togglePlayers();
});
container.add(renderPlayersBtn);
final JButton renderNpcsBtn = new JButton("NPCs"); container.add(plugin.getGroundItems());
renderNpcsBtn.addActionListener(e -> container.add(plugin.getGroundObjects());
{ container.add(plugin.getGameObjects());
highlightButton(renderNpcsBtn); container.add(plugin.getGraphicsObjects());
plugin.toggleNpcs(); container.add(plugin.getWalls());
}); container.add(plugin.getDecorations());
container.add(renderNpcsBtn);
final JButton renderGroundItemsBtn = new JButton("Ground Items"); container.add(plugin.getInventory());
renderGroundItemsBtn.addActionListener(e -> container.add(plugin.getProjectiles());
{
highlightButton(renderGroundItemsBtn);
plugin.toggleGroundItems();
});
container.add(renderGroundItemsBtn);
final JButton renderGroundObjectsBtn = new JButton("Ground Objects"); container.add(plugin.getLocation());
renderGroundObjectsBtn.addActionListener(e -> container.add(plugin.getWorldMapLocation());
{ container.add(plugin.getTileLocation());
highlightButton(renderGroundObjectsBtn); container.add(plugin.getCameraPosition());
plugin.toggleGroundObjects();
});
container.add(renderGroundObjectsBtn);
final JButton renderGameObjectsBtn = new JButton("Game Objects"); container.add(plugin.getChunkBorders());
renderGameObjectsBtn.addActionListener(e -> container.add(plugin.getMapSquares());
{
highlightButton(renderGameObjectsBtn);
plugin.toggleGameObjects();
});
container.add(renderGameObjectsBtn);
final JButton renderWallsBtn = new JButton("Walls"); container.add(plugin.getLineOfSight());
renderWallsBtn.addActionListener(e -> container.add(plugin.getValidMovement());
{ container.add(plugin.getInteracting());
highlightButton(renderWallsBtn); container.add(plugin.getExamine());
plugin.toggleWalls();
});
container.add(renderWallsBtn);
final JButton renderDecorBtn = new JButton("Decorations"); container.add(plugin.getDetachedCamera());
renderDecorBtn.addActionListener(e -> plugin.getDetachedCamera().addActionListener((ev) ->
{ {
highlightButton(renderDecorBtn); client.setOculusOrbState(!plugin.getDetachedCamera().isActive() ? 1 : 0);
plugin.toggleDecor(); client.setOculusOrbNormalSpeed(!plugin.getDetachedCamera().isActive() ? 36 : 12);
}); });
container.add(renderDecorBtn);
final JButton renderInventoryBtn = new JButton("Inventory"); container.add(plugin.getWidgetInspector());
renderInventoryBtn.addActionListener(e -> plugin.getWidgetInspector().addActionListener((ev) ->
{ {
highlightButton(renderInventoryBtn); if (plugin.getWidgetInspector().isActive())
plugin.toggleInventory(); {
widgetInspector.close();
}
else
{
widgetInspector.open();
}
}); });
container.add(renderInventoryBtn);
final JButton renderProjectilesBtn = new JButton("Projectiles"); container.add(plugin.getVarInspector());
renderProjectilesBtn.addActionListener(e -> plugin.getVarInspector().addActionListener((ev) ->
{ {
highlightButton(renderProjectilesBtn); if (plugin.getVarInspector().isActive())
plugin.toggleProjectiles(); {
varInspector.close();
}
else
{
varInspector.open();
}
}); });
container.add(renderProjectilesBtn);
final JButton renderLocationBtn = new JButton("Location");
renderLocationBtn.addActionListener(e ->
{
highlightButton(renderLocationBtn);
plugin.toggleLocation();
});
container.add(renderLocationBtn);
final JButton widgetInspectorBtn = new JButton("Widget Tools");
widgetInspectorBtn.addActionListener(e ->
{
widgetInspector.setVisible(true);
widgetInspector.toFront();
widgetInspector.repaint();
});
container.add(widgetInspectorBtn);
final JButton varInspectorBtn = new JButton("Var Tools");
varInspectorBtn.addActionListener(e ->
{
varInspector.open();
});
container.add(varInspectorBtn);
final JButton chunkBordersBtn = new JButton("Chunk borders");
chunkBordersBtn.addActionListener(e ->
{
highlightButton(chunkBordersBtn);
plugin.toggleChunkBorders();
});
container.add(chunkBordersBtn);
final JButton mapSquaresBtn = new JButton("Map squares");
mapSquaresBtn.addActionListener(e ->
{
highlightButton(mapSquaresBtn);
plugin.toggleMapSquares();
});
container.add(mapSquaresBtn);
final JButton validMovementBtn = new JButton("Valid Moves");
validMovementBtn.addActionListener(e ->
{
highlightButton(validMovementBtn);
plugin.toggleValidMovement();
});
container.add(validMovementBtn);
final JButton lineOfSightBtn = new JButton("Line of Sight");
lineOfSightBtn.addActionListener(e ->
{
highlightButton(lineOfSightBtn);
plugin.toggleLineOfSight();
});
container.add(lineOfSightBtn);
final JButton graphicsObjectsBtn = new JButton("Graphics objects");
graphicsObjectsBtn.addActionListener(e ->
{
highlightButton(graphicsObjectsBtn);
plugin.toggleGraphicsObjects();
});
container.add(graphicsObjectsBtn);
final JButton cameraPositionBtn = new JButton("Camera Position");
cameraPositionBtn.addActionListener(e ->
{
highlightButton(cameraPositionBtn);
plugin.toggleCamera();
});
container.add(cameraPositionBtn);
final JButton worldMapBtn = new JButton("World Map Location");
worldMapBtn.addActionListener(e ->
{
highlightButton(worldMapBtn);
plugin.toggleWorldMapLocation();
});
container.add(worldMapBtn);
final JButton tileLocationBtn = new JButton("Tile Location Tooltip");
tileLocationBtn.addActionListener(e ->
{
highlightButton(tileLocationBtn);
plugin.toggleTileLocation();
});
container.add(tileLocationBtn);
final JButton oculusOrbBtn = new JButton("Detached camera");
oculusOrbBtn.addActionListener(e ->
{
highlightButton(oculusOrbBtn);
boolean enabled = oculusOrbBtn.getBackground().equals(Color.GREEN);
client.setOculusOrbState(enabled ? 1 : 0);
client.setOculusOrbNormalSpeed(enabled ? 36 : 12);
});
container.add(oculusOrbBtn);
final JButton interactingBtn = new JButton("Interacting");
interactingBtn.addActionListener(e ->
{
highlightButton(interactingBtn);
plugin.toggleInteracting();
});
container.add(interactingBtn);
final JButton examineInfoBtn = new JButton("Examine Info");
examineInfoBtn.addActionListener(e ->
{
highlightButton(examineInfoBtn);
plugin.toggleExamineInfo();
});
container.add(examineInfoBtn);
return container; return container;
} }
private void highlightButton(JButton button)
{
if (button.getBackground().equals(Color.GREEN))
{
button.setBackground(null);
}
else
{
button.setBackground(Color.GREEN);
}
}
} }

View File

@@ -30,11 +30,11 @@ import com.google.common.collect.ImmutableList;
import com.google.common.eventbus.EventBus; import com.google.common.eventbus.EventBus;
import com.google.common.eventbus.Subscribe; import com.google.common.eventbus.Subscribe;
import com.google.inject.Provides; import com.google.inject.Provides;
import java.awt.Font;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import static java.lang.Math.min; import static java.lang.Math.min;
import java.util.List; import java.util.List;
import javax.inject.Inject; import javax.inject.Inject;
import lombok.Getter;
import net.runelite.api.ChatMessageType; import net.runelite.api.ChatMessageType;
import net.runelite.api.Client; import net.runelite.api.Client;
import net.runelite.api.Experience; import net.runelite.api.Experience;
@@ -66,6 +66,7 @@ import org.slf4j.LoggerFactory;
tags = {"panel"}, tags = {"panel"},
developerPlugin = true developerPlugin = true
) )
@Getter
public class DevToolsPlugin extends Plugin public class DevToolsPlugin extends Plugin
{ {
private static final List<MenuAction> EXAMINE_MENU_ACTIONS = ImmutableList.of(MenuAction.EXAMINE_ITEM, private static final List<MenuAction> EXAMINE_MENU_ACTIONS = ImmutableList.of(MenuAction.EXAMINE_ITEM,
@@ -98,26 +99,29 @@ public class DevToolsPlugin extends Plugin
@Inject @Inject
private EventBus eventBus; private EventBus eventBus;
private boolean togglePlayers; private DevToolsButton players;
private boolean toggleNpcs; private DevToolsButton npcs;
private boolean toggleGroundItems; private DevToolsButton groundItems;
private boolean toggleGroundObjects; private DevToolsButton groundObjects;
private boolean toggleGameObjects; private DevToolsButton gameObjects;
private boolean toggleWalls; private DevToolsButton graphicsObjects;
private boolean toggleDecor; private DevToolsButton walls;
private boolean toggleInventory; private DevToolsButton decorations;
private boolean toggleProjectiles; private DevToolsButton inventory;
private boolean toggleLocation; private DevToolsButton projectiles;
private boolean toggleChunkBorders; private DevToolsButton location;
private boolean toggleMapSquares; private DevToolsButton chunkBorders;
private boolean toggleValidMovement; private DevToolsButton mapSquares;
private boolean toggleLineOfSight; private DevToolsButton validMovement;
private boolean toggleGraphicsObjects; private DevToolsButton lineOfSight;
private boolean toggleCamera; private DevToolsButton cameraPosition;
private boolean toggleWorldMapLocation; private DevToolsButton worldMapLocation ;
private boolean toggleTileLocation; private DevToolsButton tileLocation;
private boolean toggleInteracting; private DevToolsButton interacting;
private boolean toggleExamineInfo; private DevToolsButton examine;
private DevToolsButton detachedCamera;
private DevToolsButton widgetInspector;
private DevToolsButton varInspector;
Widget currentWidget; Widget currentWidget;
int itemIndex = -1; int itemIndex = -1;
@@ -133,6 +137,36 @@ public class DevToolsPlugin extends Plugin
@Override @Override
protected void startUp() throws Exception protected void startUp() throws Exception
{ {
players = new DevToolsButton("Players");
npcs = new DevToolsButton("NPCs");
groundItems = new DevToolsButton("Ground Items");
groundObjects = new DevToolsButton("Ground Objects");
gameObjects = new DevToolsButton("Game Objects");
graphicsObjects = new DevToolsButton("Graphics Objects");
walls = new DevToolsButton("Walls");
decorations = new DevToolsButton("Decorations");
inventory = new DevToolsButton("Inventory");
projectiles = new DevToolsButton("Projectiles");
location = new DevToolsButton("Location");
worldMapLocation = new DevToolsButton("World Map Location");
tileLocation = new DevToolsButton("Tile Location");
cameraPosition = new DevToolsButton("Camera Position");
chunkBorders = new DevToolsButton("Chunk Borders");
mapSquares = new DevToolsButton("Map Squares");
lineOfSight = new DevToolsButton("Line Of Sight");
validMovement = new DevToolsButton("Valid Movement");
interacting = new DevToolsButton("Interacting");
examine = new DevToolsButton("Examine");
detachedCamera = new DevToolsButton("Detached Camera");
widgetInspector = new DevToolsButton("Widget Inspector");
varInspector = new DevToolsButton("Var Inspector");
overlayManager.add(overlay); overlayManager.add(overlay);
overlayManager.add(locationOverlay); overlayManager.add(locationOverlay);
overlayManager.add(sceneOverlay); overlayManager.add(sceneOverlay);
@@ -281,7 +315,7 @@ public class DevToolsPlugin extends Plugin
@Subscribe @Subscribe
public void onMenuEntryAdded(MenuEntryAdded event) public void onMenuEntryAdded(MenuEntryAdded event)
{ {
if (!toggleExamineInfo) if (!examine.isActive())
{ {
return; return;
} }
@@ -316,199 +350,4 @@ public class DevToolsPlugin extends Plugin
client.setMenuEntries(entries); client.setMenuEntries(entries);
} }
} }
void togglePlayers()
{
togglePlayers = !togglePlayers;
}
void toggleNpcs()
{
toggleNpcs = !toggleNpcs;
}
void toggleGroundItems()
{
toggleGroundItems = !toggleGroundItems;
}
void toggleGroundObjects()
{
toggleGroundObjects = !toggleGroundObjects;
}
void toggleGameObjects()
{
toggleGameObjects = !toggleGameObjects;
}
void toggleWalls()
{
toggleWalls = !toggleWalls;
}
void toggleDecor()
{
toggleDecor = !toggleDecor;
}
void toggleInventory()
{
toggleInventory = !toggleInventory;
}
void toggleProjectiles()
{
toggleProjectiles = !toggleProjectiles;
}
void toggleLocation()
{
toggleLocation = !toggleLocation;
}
void toggleChunkBorders()
{
toggleChunkBorders = !toggleChunkBorders;
}
void toggleMapSquares()
{
toggleMapSquares = !toggleMapSquares;
}
void toggleValidMovement()
{
toggleValidMovement = !toggleValidMovement;
}
void toggleLineOfSight()
{
toggleLineOfSight = !toggleLineOfSight;
}
void toggleGraphicsObjects()
{
toggleGraphicsObjects = !toggleGraphicsObjects;
}
void toggleCamera()
{
toggleCamera = !toggleCamera;
}
void toggleWorldMapLocation()
{
toggleWorldMapLocation = !toggleWorldMapLocation;
}
void toggleTileLocation()
{
toggleTileLocation = !toggleTileLocation;
}
void toggleInteracting()
{
toggleInteracting = !toggleInteracting;
}
void toggleExamineInfo()
{
toggleExamineInfo = !toggleExamineInfo;
}
boolean isTogglePlayers()
{
return togglePlayers;
}
boolean isToggleNpcs()
{
return toggleNpcs;
}
boolean isToggleGroundItems()
{
return toggleGroundItems;
}
boolean isToggleGroundObjects()
{
return toggleGroundObjects;
}
boolean isToggleGameObjects()
{
return toggleGameObjects;
}
boolean isToggleWalls()
{
return toggleWalls;
}
boolean isToggleDecor()
{
return toggleDecor;
}
boolean isToggleInventory()
{
return toggleInventory;
}
boolean isToggleProjectiles()
{
return toggleProjectiles;
}
boolean isToggleLocation()
{
return toggleLocation;
}
boolean isToggleChunkBorders()
{
return toggleChunkBorders;
}
boolean isToggleMapSquares()
{
return toggleMapSquares;
}
boolean isToggleValidMovement()
{
return toggleValidMovement;
}
boolean isToggleLineOfSight()
{
return toggleLineOfSight;
}
boolean isToggleGraphicsObjects()
{
return toggleGraphicsObjects;
}
boolean isToggleCamera()
{
return toggleCamera;
}
boolean isToggleWorldMapLocation()
{
return toggleWorldMapLocation;
}
boolean isToggleTileLocation()
{
return toggleTileLocation;
}
boolean isToggleInteracting()
{
return toggleInteracting;
}
} }

View File

@@ -55,7 +55,7 @@ public class LocationOverlay extends Overlay
@Override @Override
public Dimension render(Graphics2D graphics) public Dimension render(Graphics2D graphics)
{ {
if (!plugin.isToggleLocation()) if (!plugin.getLocation().isActive())
{ {
return null; return null;
} }

View File

@@ -87,27 +87,27 @@ public class SceneOverlay extends Overlay
@Override @Override
public Dimension render(Graphics2D graphics) public Dimension render(Graphics2D graphics)
{ {
if (plugin.isToggleChunkBorders()) if (plugin.getChunkBorders().isActive())
{ {
renderChunkBorders(graphics); renderChunkBorders(graphics);
} }
if (plugin.isToggleMapSquares()) if (plugin.getMapSquares().isActive())
{ {
renderMapSquares(graphics); renderMapSquares(graphics);
} }
if (plugin.isToggleLineOfSight()) if (plugin.getLineOfSight().isActive())
{ {
renderLineOfSight(graphics); renderLineOfSight(graphics);
} }
if (plugin.isToggleValidMovement()) if (plugin.getValidMovement().isActive())
{ {
renderValidMovement(graphics); renderValidMovement(graphics);
} }
if (plugin.isToggleInteracting()) if (plugin.getInteracting().isActive())
{ {
renderInteracting(graphics); renderInteracting(graphics);
} }

View File

@@ -267,7 +267,7 @@ class WidgetInspector extends JFrame
infoTableModel.setWidget(plugin.currentWidget); infoTableModel.setWidget(plugin.currentWidget);
} }
public static WidgetInfo getWidgetInfo(int packedId) static WidgetInfo getWidgetInfo(int packedId)
{ {
if (widgetIdMap.size() == 0) if (widgetIdMap.size() == 0)
{ {
@@ -282,4 +282,16 @@ class WidgetInspector extends JFrame
return widgetIdMap.get(packedId); return widgetIdMap.get(packedId);
} }
public void open()
{
setVisible(true);
toFront();
repaint();
}
public void close()
{
setVisible(false);
}
} }

View File

@@ -62,7 +62,7 @@ public class WorldMapLocationOverlay extends Overlay
@Override @Override
public Dimension render(Graphics2D graphics) public Dimension render(Graphics2D graphics)
{ {
if (!plugin.isToggleWorldMapLocation()) if (!plugin.getWorldMapLocation().isActive())
{ {
return null; return null;
} }