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
public Dimension render(Graphics2D graphics)
{
if (!plugin.isToggleCamera())
if (!plugin.getCameraPosition().isActive())
{
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);
if (plugin.isTogglePlayers())
if (plugin.getPlayers().isActive())
{
renderPlayers(graphics);
}
if (plugin.isToggleNpcs())
if (plugin.getNpcs().isActive())
{
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);
}
if (plugin.isToggleInventory())
if (plugin.getInventory().isActive())
{
renderInventory(graphics);
}
if (plugin.isToggleProjectiles())
if (plugin.getProjectiles().isActive())
{
renderProjectiles(graphics);
}
if (plugin.isToggleGraphicsObjects())
if (plugin.getGraphicsObjects().isActive())
{
renderGraphicsObjects(graphics);
}
@@ -211,32 +211,32 @@ public class DevToolsOverlay extends Overlay
continue;
}
if (plugin.isToggleGroundItems())
if (plugin.getGroundItems().isActive())
{
renderGroundItems(graphics, tile, player);
}
if (plugin.isToggleGroundObjects())
if (plugin.getGroundObjects().isActive())
{
renderGroundObject(graphics, tile, player);
}
if (plugin.isToggleGameObjects())
if (plugin.getGameObjects().isActive())
{
renderGameObjects(graphics, tile, player);
}
if (plugin.isToggleWalls())
if (plugin.getWalls().isActive())
{
renderWallObject(graphics, tile, player);
}
if (plugin.isToggleDecor())
if (plugin.getDecorations().isActive())
{
renderDecorObject(graphics, tile, player);
}
if (plugin.isToggleTileLocation())
if (plugin.getTileLocation().isActive())
{
renderTileTooltip(graphics, tile);
}

View File

@@ -25,10 +25,8 @@
*/
package net.runelite.client.plugins.devtools;
import java.awt.Color;
import java.awt.GridLayout;
import javax.inject.Inject;
import javax.swing.JButton;
import javax.swing.JPanel;
import net.runelite.api.Client;
import net.runelite.client.ui.ColorScheme;
@@ -43,7 +41,7 @@ public class DevToolsPanel extends PluginPanel
private final VarInspector varInspector;
@Inject
public DevToolsPanel(Client client, DevToolsPlugin plugin, WidgetInspector widgetInspector, VarInspector varInspector)
private DevToolsPanel(Client client, DevToolsPlugin plugin, WidgetInspector widgetInspector, VarInspector varInspector)
{
super();
this.client = client;
@@ -62,204 +60,65 @@ public class DevToolsPanel extends PluginPanel
container.setBackground(ColorScheme.DARK_GRAY_COLOR);
container.setLayout(new GridLayout(0, 2, 3, 3));
final JButton renderPlayersBtn = new JButton("Players");
renderPlayersBtn.addActionListener(e ->
{
highlightButton(renderPlayersBtn);
plugin.togglePlayers();
});
container.add(renderPlayersBtn);
container.add(plugin.getPlayers());
container.add(plugin.getNpcs());
final JButton renderNpcsBtn = new JButton("NPCs");
renderNpcsBtn.addActionListener(e ->
{
highlightButton(renderNpcsBtn);
plugin.toggleNpcs();
});
container.add(renderNpcsBtn);
container.add(plugin.getGroundItems());
container.add(plugin.getGroundObjects());
container.add(plugin.getGameObjects());
container.add(plugin.getGraphicsObjects());
container.add(plugin.getWalls());
container.add(plugin.getDecorations());
final JButton renderGroundItemsBtn = new JButton("Ground Items");
renderGroundItemsBtn.addActionListener(e ->
{
highlightButton(renderGroundItemsBtn);
plugin.toggleGroundItems();
});
container.add(renderGroundItemsBtn);
container.add(plugin.getInventory());
container.add(plugin.getProjectiles());
final JButton renderGroundObjectsBtn = new JButton("Ground Objects");
renderGroundObjectsBtn.addActionListener(e ->
{
highlightButton(renderGroundObjectsBtn);
plugin.toggleGroundObjects();
});
container.add(renderGroundObjectsBtn);
container.add(plugin.getLocation());
container.add(plugin.getWorldMapLocation());
container.add(plugin.getTileLocation());
container.add(plugin.getCameraPosition());
final JButton renderGameObjectsBtn = new JButton("Game Objects");
renderGameObjectsBtn.addActionListener(e ->
{
highlightButton(renderGameObjectsBtn);
plugin.toggleGameObjects();
});
container.add(renderGameObjectsBtn);
container.add(plugin.getChunkBorders());
container.add(plugin.getMapSquares());
final JButton renderWallsBtn = new JButton("Walls");
renderWallsBtn.addActionListener(e ->
{
highlightButton(renderWallsBtn);
plugin.toggleWalls();
});
container.add(renderWallsBtn);
container.add(plugin.getLineOfSight());
container.add(plugin.getValidMovement());
container.add(plugin.getInteracting());
container.add(plugin.getExamine());
final JButton renderDecorBtn = new JButton("Decorations");
renderDecorBtn.addActionListener(e ->
container.add(plugin.getDetachedCamera());
plugin.getDetachedCamera().addActionListener((ev) ->
{
highlightButton(renderDecorBtn);
plugin.toggleDecor();
client.setOculusOrbState(!plugin.getDetachedCamera().isActive() ? 1 : 0);
client.setOculusOrbNormalSpeed(!plugin.getDetachedCamera().isActive() ? 36 : 12);
});
container.add(renderDecorBtn);
final JButton renderInventoryBtn = new JButton("Inventory");
renderInventoryBtn.addActionListener(e ->
container.add(plugin.getWidgetInspector());
plugin.getWidgetInspector().addActionListener((ev) ->
{
highlightButton(renderInventoryBtn);
plugin.toggleInventory();
if (plugin.getWidgetInspector().isActive())
{
widgetInspector.close();
}
else
{
widgetInspector.open();
}
});
container.add(renderInventoryBtn);
final JButton renderProjectilesBtn = new JButton("Projectiles");
renderProjectilesBtn.addActionListener(e ->
container.add(plugin.getVarInspector());
plugin.getVarInspector().addActionListener((ev) ->
{
highlightButton(renderProjectilesBtn);
plugin.toggleProjectiles();
if (plugin.getVarInspector().isActive())
{
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;
}
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.Subscribe;
import com.google.inject.Provides;
import java.awt.Font;
import java.awt.image.BufferedImage;
import static java.lang.Math.min;
import java.util.List;
import javax.inject.Inject;
import lombok.Getter;
import net.runelite.api.ChatMessageType;
import net.runelite.api.Client;
import net.runelite.api.Experience;
@@ -66,6 +66,7 @@ import org.slf4j.LoggerFactory;
tags = {"panel"},
developerPlugin = true
)
@Getter
public class DevToolsPlugin extends Plugin
{
private static final List<MenuAction> EXAMINE_MENU_ACTIONS = ImmutableList.of(MenuAction.EXAMINE_ITEM,
@@ -98,26 +99,29 @@ public class DevToolsPlugin extends Plugin
@Inject
private EventBus eventBus;
private boolean togglePlayers;
private boolean toggleNpcs;
private boolean toggleGroundItems;
private boolean toggleGroundObjects;
private boolean toggleGameObjects;
private boolean toggleWalls;
private boolean toggleDecor;
private boolean toggleInventory;
private boolean toggleProjectiles;
private boolean toggleLocation;
private boolean toggleChunkBorders;
private boolean toggleMapSquares;
private boolean toggleValidMovement;
private boolean toggleLineOfSight;
private boolean toggleGraphicsObjects;
private boolean toggleCamera;
private boolean toggleWorldMapLocation;
private boolean toggleTileLocation;
private boolean toggleInteracting;
private boolean toggleExamineInfo;
private DevToolsButton players;
private DevToolsButton npcs;
private DevToolsButton groundItems;
private DevToolsButton groundObjects;
private DevToolsButton gameObjects;
private DevToolsButton graphicsObjects;
private DevToolsButton walls;
private DevToolsButton decorations;
private DevToolsButton inventory;
private DevToolsButton projectiles;
private DevToolsButton location;
private DevToolsButton chunkBorders;
private DevToolsButton mapSquares;
private DevToolsButton validMovement;
private DevToolsButton lineOfSight;
private DevToolsButton cameraPosition;
private DevToolsButton worldMapLocation ;
private DevToolsButton tileLocation;
private DevToolsButton interacting;
private DevToolsButton examine;
private DevToolsButton detachedCamera;
private DevToolsButton widgetInspector;
private DevToolsButton varInspector;
Widget currentWidget;
int itemIndex = -1;
@@ -133,6 +137,36 @@ public class DevToolsPlugin extends Plugin
@Override
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(locationOverlay);
overlayManager.add(sceneOverlay);
@@ -281,7 +315,7 @@ public class DevToolsPlugin extends Plugin
@Subscribe
public void onMenuEntryAdded(MenuEntryAdded event)
{
if (!toggleExamineInfo)
if (!examine.isActive())
{
return;
}
@@ -316,199 +350,4 @@ public class DevToolsPlugin extends Plugin
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
public Dimension render(Graphics2D graphics)
{
if (!plugin.isToggleLocation())
if (!plugin.getLocation().isActive())
{
return null;
}

View File

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

View File

@@ -267,7 +267,7 @@ class WidgetInspector extends JFrame
infoTableModel.setWidget(plugin.currentWidget);
}
public static WidgetInfo getWidgetInfo(int packedId)
static WidgetInfo getWidgetInfo(int packedId)
{
if (widgetIdMap.size() == 0)
{
@@ -282,4 +282,16 @@ class WidgetInspector extends JFrame
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
public Dimension render(Graphics2D graphics)
{
if (!plugin.isToggleWorldMapLocation())
if (!plugin.getWorldMapLocation().isActive())
{
return null;
}