Add sounds to devtools
This commit is contained in:
@@ -119,6 +119,8 @@ class DevToolsPanel extends PluginPanel
|
||||
}
|
||||
});
|
||||
|
||||
container.add(plugin.getSoundEffects());
|
||||
|
||||
return container;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,6 +100,9 @@ public class DevToolsPlugin extends Plugin
|
||||
@Inject
|
||||
private WorldMapRegionOverlay mapRegionOverlay;
|
||||
|
||||
@Inject
|
||||
private SoundEffectOverlay soundEffectOverlay;
|
||||
|
||||
@Inject
|
||||
private EventBus eventBus;
|
||||
|
||||
@@ -119,13 +122,14 @@ public class DevToolsPlugin extends Plugin
|
||||
private DevToolsButton validMovement;
|
||||
private DevToolsButton lineOfSight;
|
||||
private DevToolsButton cameraPosition;
|
||||
private DevToolsButton worldMapLocation ;
|
||||
private DevToolsButton worldMapLocation;
|
||||
private DevToolsButton tileLocation;
|
||||
private DevToolsButton interacting;
|
||||
private DevToolsButton examine;
|
||||
private DevToolsButton detachedCamera;
|
||||
private DevToolsButton widgetInspector;
|
||||
private DevToolsButton varInspector;
|
||||
private DevToolsButton soundEffects;
|
||||
private NavigationButton navButton;
|
||||
|
||||
@Provides
|
||||
@@ -166,6 +170,7 @@ public class DevToolsPlugin extends Plugin
|
||||
detachedCamera = new DevToolsButton("Detached Camera");
|
||||
widgetInspector = new DevToolsButton("Widget Inspector");
|
||||
varInspector = new DevToolsButton("Var Inspector");
|
||||
soundEffects = new DevToolsButton("Sound Effects");
|
||||
|
||||
overlayManager.add(overlay);
|
||||
overlayManager.add(locationOverlay);
|
||||
@@ -173,6 +178,7 @@ public class DevToolsPlugin extends Plugin
|
||||
overlayManager.add(cameraOverlay);
|
||||
overlayManager.add(worldMapLocationOverlay);
|
||||
overlayManager.add(mapRegionOverlay);
|
||||
overlayManager.add(soundEffectOverlay);
|
||||
|
||||
final DevToolsPanel panel = injector.getInstance(DevToolsPanel.class);
|
||||
|
||||
@@ -186,17 +192,21 @@ public class DevToolsPlugin extends Plugin
|
||||
.build();
|
||||
|
||||
clientToolbar.addNavigation(navButton);
|
||||
|
||||
eventBus.register(soundEffectOverlay);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void shutDown() throws Exception
|
||||
{
|
||||
eventBus.unregister(soundEffectOverlay);
|
||||
overlayManager.remove(overlay);
|
||||
overlayManager.remove(locationOverlay);
|
||||
overlayManager.remove(sceneOverlay);
|
||||
overlayManager.remove(cameraOverlay);
|
||||
overlayManager.remove(worldMapLocationOverlay);
|
||||
overlayManager.remove(mapRegionOverlay);
|
||||
overlayManager.remove(soundEffectOverlay);
|
||||
clientToolbar.removeNavigation(navButton);
|
||||
}
|
||||
|
||||
@@ -336,6 +346,12 @@ public class DevToolsPlugin extends Plugin
|
||||
player.getPlayerComposition().setHash();
|
||||
break;
|
||||
}
|
||||
case "sound":
|
||||
{
|
||||
int id = Integer.parseInt(args[0]);
|
||||
client.playSoundEffect(id);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,145 @@
|
||||
/*
|
||||
* Copyright (c) 2018, WooxSolo <https://github.com/WooxSolo>
|
||||
* 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 java.awt.Dimension;
|
||||
import java.awt.Graphics2D;
|
||||
import javax.inject.Inject;
|
||||
import net.runelite.api.Client;
|
||||
import net.runelite.api.Player;
|
||||
import net.runelite.api.coords.LocalPoint;
|
||||
import net.runelite.api.events.AreaSoundEffectPlayed;
|
||||
import net.runelite.api.events.SoundEffectPlayed;
|
||||
import net.runelite.client.eventbus.Subscribe;
|
||||
import net.runelite.client.ui.overlay.Overlay;
|
||||
import net.runelite.client.ui.overlay.OverlayPosition;
|
||||
import net.runelite.client.ui.overlay.components.LineComponent;
|
||||
import net.runelite.client.ui.overlay.components.PanelComponent;
|
||||
|
||||
class SoundEffectOverlay extends Overlay
|
||||
{
|
||||
private final static int MAX_LINES = 16;
|
||||
private final static Color COLOR_SOUND_EFFECT = Color.WHITE;
|
||||
private final static Color COLOR_AREA_SOUND_EFFECT = Color.YELLOW;
|
||||
private final static Color COLOR_SILENT_SOUND_EFFECT = Color.GRAY;
|
||||
|
||||
private final Client client;
|
||||
private final DevToolsPlugin plugin;
|
||||
private final PanelComponent panelComponent = new PanelComponent();
|
||||
|
||||
@Inject
|
||||
SoundEffectOverlay(Client client, DevToolsPlugin plugin)
|
||||
{
|
||||
this.client = client;
|
||||
this.plugin = plugin;
|
||||
panelComponent.setPreferredSize(new Dimension(200, 0));
|
||||
panelComponent.getChildren().add(LineComponent.builder()
|
||||
.left("Sound Effects")
|
||||
.leftColor(Color.CYAN)
|
||||
.build());
|
||||
setPosition(OverlayPosition.TOP_LEFT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dimension render(Graphics2D graphics)
|
||||
{
|
||||
if (!plugin.getSoundEffects().isActive())
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return panelComponent.render(graphics);
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onSoundEffectPlayed(SoundEffectPlayed event)
|
||||
{
|
||||
if (!plugin.getSoundEffects().isActive())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
String text =
|
||||
"Id: " + event.getSoundId() +
|
||||
" - D: " + event.getDelay();
|
||||
|
||||
panelComponent.getChildren().add(LineComponent.builder()
|
||||
.left(text)
|
||||
.leftColor(COLOR_SOUND_EFFECT)
|
||||
.build());
|
||||
|
||||
checkMaxLines();
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onAreaSoundEffectPlayed(AreaSoundEffectPlayed event)
|
||||
{
|
||||
if (!plugin.getSoundEffects().isActive())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Color textColor = COLOR_AREA_SOUND_EFFECT;
|
||||
|
||||
// Check if the player is within range to hear the sound
|
||||
Player localPlayer = client.getLocalPlayer();
|
||||
if (localPlayer != null)
|
||||
{
|
||||
LocalPoint lp = localPlayer.getLocalLocation();
|
||||
if (lp != null)
|
||||
{
|
||||
int sceneX = lp.getSceneX();
|
||||
int sceneY = lp.getSceneY();
|
||||
int distance = Math.abs(sceneX - event.getSceneX()) + Math.abs(sceneY - event.getSceneY());
|
||||
if (distance > event.getRange())
|
||||
{
|
||||
textColor = COLOR_SILENT_SOUND_EFFECT;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String text =
|
||||
"Id: " + event.getSoundId() +
|
||||
" - L: " + event.getSceneX() + "," + event.getSceneY() +
|
||||
" - R: " + event.getRange() +
|
||||
" - D: " + event.getDelay();
|
||||
|
||||
panelComponent.getChildren().add(LineComponent.builder()
|
||||
.left(text)
|
||||
.leftColor(textColor)
|
||||
.build());
|
||||
|
||||
checkMaxLines();
|
||||
}
|
||||
|
||||
private void checkMaxLines()
|
||||
{
|
||||
while (panelComponent.getChildren().size() > MAX_LINES)
|
||||
{
|
||||
panelComponent.getChildren().remove(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user