Merge pull request #11063 from seandewar/zoom-music-slider-tooltips
music, camera: volume & zoom slider tooltips
This commit is contained in:
@@ -162,8 +162,8 @@ public final class ScriptID
|
||||
*
|
||||
* Updates the VarClientInts (73, 74) to this same value
|
||||
* <ul>
|
||||
* <li> int Reset zoom position </li>
|
||||
* <li> int Reset zoom position </li>
|
||||
* <li> int Reset zoom position for fixed viewport mode</li>
|
||||
* <li> int Reset zoom position for resizable viewport mode</li>
|
||||
* </ul>
|
||||
*/
|
||||
@ScriptArguments(integer = 2)
|
||||
|
||||
@@ -52,6 +52,12 @@ public enum VarClientInt
|
||||
*/
|
||||
INPUT_TYPE(5),
|
||||
|
||||
/**
|
||||
* The game sets this to the same value as {@link #CAMERA_ZOOM_RESIZABLE_VIEWPORT}
|
||||
*/
|
||||
CAMERA_ZOOM_FIXED_VIEWPORT(73),
|
||||
CAMERA_ZOOM_RESIZABLE_VIEWPORT(74),
|
||||
|
||||
MEMBERSHIP_STATUS(103),
|
||||
|
||||
INVENTORY_TAB(171),
|
||||
|
||||
@@ -870,6 +870,7 @@ public class WidgetID
|
||||
|
||||
static class Options
|
||||
{
|
||||
static final int CAMERA_ZOOM_SLIDER_HANDLE = 15;
|
||||
static final int MUSIC_SLIDER = 37;
|
||||
static final int SOUND_EFFECT_SLIDER = 43;
|
||||
static final int AREA_SOUND_SLIDER = 49;
|
||||
|
||||
@@ -525,6 +525,7 @@ public enum WidgetInfo
|
||||
SEED_VAULT_ITEM_TEXT(WidgetID.SEED_VAULT_GROUP_ID, WidgetID.SeedVault.ITEM_TEXT),
|
||||
SEED_VAULT_INVENTORY_ITEMS_CONTAINER(WidgetID.SEED_VAULT_INVENTORY_GROUP_ID, WidgetID.SeedVault.INVENTORY_ITEM_CONTAINER),
|
||||
|
||||
OPTIONS_CAMERA_ZOOM_SLIDER_HANDLE(WidgetID.OPTIONS_GROUP_ID, WidgetID.Options.CAMERA_ZOOM_SLIDER_HANDLE),
|
||||
OPTIONS_MUSIC_SLIDER(WidgetID.OPTIONS_GROUP_ID, WidgetID.Options.MUSIC_SLIDER),
|
||||
OPTIONS_SOUND_EFFECT_SLIDER(WidgetID.OPTIONS_GROUP_ID, WidgetID.Options.SOUND_EFFECT_SLIDER),
|
||||
OPTIONS_AREA_SOUND_SLIDER(WidgetID.OPTIONS_GROUP_ID, WidgetID.Options.AREA_SOUND_SLIDER),
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Copyright (c) 2020, Sean Dewar <https://github.com/seandewar>
|
||||
* 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.camera;
|
||||
|
||||
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.api.VarClientInt;
|
||||
import net.runelite.api.widgets.Widget;
|
||||
import net.runelite.api.widgets.WidgetInfo;
|
||||
import net.runelite.client.ui.overlay.Overlay;
|
||||
import net.runelite.client.ui.overlay.OverlayLayer;
|
||||
import net.runelite.client.ui.overlay.OverlayPosition;
|
||||
import net.runelite.client.ui.overlay.tooltip.Tooltip;
|
||||
import net.runelite.client.ui.overlay.tooltip.TooltipManager;
|
||||
|
||||
class CameraOverlay extends Overlay
|
||||
{
|
||||
private final CameraConfig config;
|
||||
private final Client client;
|
||||
private final TooltipManager tooltipManager;
|
||||
|
||||
@Inject
|
||||
private CameraOverlay(final CameraConfig config, final Client client, final TooltipManager tooltipManager)
|
||||
{
|
||||
this.config = config;
|
||||
this.client = client;
|
||||
this.tooltipManager = tooltipManager;
|
||||
setPosition(OverlayPosition.DYNAMIC);
|
||||
setLayer(OverlayLayer.ABOVE_WIDGETS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Dimension render(final Graphics2D graphics)
|
||||
{
|
||||
final Widget slider = client.getWidget(WidgetInfo.OPTIONS_CAMERA_ZOOM_SLIDER_HANDLE);
|
||||
final Point mousePos = client.getMouseCanvasPosition();
|
||||
|
||||
if (slider == null || slider.isHidden() || !slider.getBounds().contains(mousePos.getX(), mousePos.getY()))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
final int value = client.getVar(VarClientInt.CAMERA_ZOOM_RESIZABLE_VIEWPORT);
|
||||
final int max = config.innerLimit() ? config.INNER_ZOOM_LIMIT : CameraPlugin.DEFAULT_INNER_ZOOM_LIMIT;
|
||||
|
||||
tooltipManager.add(new Tooltip("Camera Zoom: " + value + " / " + max));
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -52,6 +52,7 @@ import net.runelite.client.input.MouseListener;
|
||||
import net.runelite.client.input.MouseManager;
|
||||
import net.runelite.client.plugins.Plugin;
|
||||
import net.runelite.client.plugins.PluginDescriptor;
|
||||
import net.runelite.client.ui.overlay.OverlayManager;
|
||||
|
||||
@PluginDescriptor(
|
||||
name = "Camera",
|
||||
@@ -62,6 +63,9 @@ import net.runelite.client.plugins.PluginDescriptor;
|
||||
public class CameraPlugin extends Plugin implements KeyListener, MouseListener
|
||||
{
|
||||
private static final int DEFAULT_ZOOM_INCREMENT = 25;
|
||||
private static final int DEFAULT_OUTER_ZOOM_LIMIT = 128;
|
||||
static final int DEFAULT_INNER_ZOOM_LIMIT = 896;
|
||||
|
||||
private static final String LOOK_NORTH = "Look North";
|
||||
private static final String LOOK_SOUTH = "Look South";
|
||||
private static final String LOOK_EAST = "Look East";
|
||||
@@ -91,6 +95,12 @@ public class CameraPlugin extends Plugin implements KeyListener, MouseListener
|
||||
@Inject
|
||||
private MouseManager mouseManager;
|
||||
|
||||
@Inject
|
||||
private OverlayManager overlayManager;
|
||||
|
||||
@Inject
|
||||
private CameraOverlay cameraOverlay;
|
||||
|
||||
@Provides
|
||||
CameraConfig getConfig(ConfigManager configManager)
|
||||
{
|
||||
@@ -106,11 +116,13 @@ public class CameraPlugin extends Plugin implements KeyListener, MouseListener
|
||||
client.setCameraPitchRelaxerEnabled(config.relaxCameraPitch());
|
||||
keyManager.registerKeyListener(this);
|
||||
mouseManager.registerMouseListener(this);
|
||||
overlayManager.add(cameraOverlay);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void shutDown()
|
||||
{
|
||||
overlayManager.remove(cameraOverlay);
|
||||
client.setCameraPitchRelaxerEnabled(false);
|
||||
keyManager.unregisterKeyListener(this);
|
||||
mouseManager.unregisterMouseListener(this);
|
||||
@@ -177,7 +189,7 @@ public class CameraPlugin extends Plugin implements KeyListener, MouseListener
|
||||
if ("outerZoomLimit".equals(event.getEventName()))
|
||||
{
|
||||
int outerLimit = Ints.constrainToRange(config.outerLimit(), CameraConfig.OUTER_LIMIT_MIN, CameraConfig.OUTER_LIMIT_MAX);
|
||||
int outerZoomLimit = 128 - outerLimit;
|
||||
int outerZoomLimit = DEFAULT_OUTER_ZOOM_LIMIT - outerLimit;
|
||||
intStack[intStackSize - 1] = outerZoomLimit;
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
/*
|
||||
* Copyright (c) 2019, Anthony Chen <https://github.com/achencoms>
|
||||
* Copyright (c) 2019, Adam <Adam@sigterm.info>
|
||||
* Copyright (c) 2020, Sean Dewar <https://github.com/seandewar>
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -50,10 +51,10 @@ import net.runelite.api.SpriteID;
|
||||
import net.runelite.api.VarClientInt;
|
||||
import net.runelite.api.VarPlayer;
|
||||
import net.runelite.api.events.AreaSoundEffectPlayed;
|
||||
import net.runelite.api.events.SoundEffectPlayed;
|
||||
import net.runelite.client.events.ConfigChanged;
|
||||
import net.runelite.api.events.BeforeRender;
|
||||
import net.runelite.api.events.GameStateChanged;
|
||||
import net.runelite.api.events.ScriptCallbackEvent;
|
||||
import net.runelite.api.events.SoundEffectPlayed;
|
||||
import net.runelite.api.events.VarClientIntChanged;
|
||||
import net.runelite.api.events.VolumeChanged;
|
||||
import net.runelite.api.events.WidgetLoaded;
|
||||
@@ -67,10 +68,13 @@ import net.runelite.api.widgets.WidgetType;
|
||||
import net.runelite.client.callback.ClientThread;
|
||||
import net.runelite.client.config.ConfigManager;
|
||||
import net.runelite.client.eventbus.Subscribe;
|
||||
import net.runelite.client.events.ConfigChanged;
|
||||
import net.runelite.client.game.chatbox.ChatboxPanelManager;
|
||||
import net.runelite.client.game.chatbox.ChatboxTextInput;
|
||||
import net.runelite.client.plugins.Plugin;
|
||||
import net.runelite.client.plugins.PluginDescriptor;
|
||||
import net.runelite.client.ui.overlay.tooltip.Tooltip;
|
||||
import net.runelite.client.ui.overlay.tooltip.TooltipManager;
|
||||
|
||||
@PluginDescriptor(
|
||||
name = "Music",
|
||||
@@ -125,6 +129,9 @@ public class MusicPlugin extends Plugin
|
||||
@Inject
|
||||
private ChatboxPanelManager chatboxPanelManager;
|
||||
|
||||
@Inject
|
||||
private TooltipManager tooltipManager;
|
||||
|
||||
private ChatboxTextInput searchInput;
|
||||
|
||||
private Widget musicSearchButton;
|
||||
@@ -134,6 +141,8 @@ public class MusicPlugin extends Plugin
|
||||
|
||||
private MusicState currentMusicFilter = MusicState.ALL;
|
||||
|
||||
private MusicSlider hoveredSlider;
|
||||
|
||||
@Override
|
||||
protected void startUp()
|
||||
{
|
||||
@@ -155,7 +164,7 @@ public class MusicPlugin extends Plugin
|
||||
}
|
||||
|
||||
tracks = null;
|
||||
|
||||
hoveredSlider = null;
|
||||
clientThread.invoke(this::teardownMusicOptions);
|
||||
}
|
||||
|
||||
@@ -407,10 +416,11 @@ public class MusicPlugin extends Plugin
|
||||
@Getter
|
||||
private enum MusicSlider
|
||||
{
|
||||
MUSIC(WidgetInfo.OPTIONS_MUSIC_SLIDER, VarPlayer.MUSIC_VOLUME, MusicConfig::getMusicVolume, MusicConfig::setMusicVolume, 255),
|
||||
AREA(WidgetInfo.OPTIONS_AREA_SOUND_SLIDER, VarPlayer.AREA_EFFECT_VOLUME, MusicConfig::getAreaSoundEffectVolume, MusicConfig::setAreaSoundEffectVolume, 127),
|
||||
EFFECT(WidgetInfo.OPTIONS_SOUND_EFFECT_SLIDER, VarPlayer.SOUND_EFFECT_VOLUME, MusicConfig::getSoundEffectVolume, MusicConfig::setSoundEffectVolume, 127);
|
||||
MUSIC("Music", WidgetInfo.OPTIONS_MUSIC_SLIDER, VarPlayer.MUSIC_VOLUME, MusicConfig::getMusicVolume, MusicConfig::setMusicVolume, 255),
|
||||
AREA("Area Sounds", WidgetInfo.OPTIONS_AREA_SOUND_SLIDER, VarPlayer.AREA_EFFECT_VOLUME, MusicConfig::getAreaSoundEffectVolume, MusicConfig::setAreaSoundEffectVolume, 127),
|
||||
EFFECT("Sound Effects", WidgetInfo.OPTIONS_SOUND_EFFECT_SLIDER, VarPlayer.SOUND_EFFECT_VOLUME, MusicConfig::getSoundEffectVolume, MusicConfig::setSoundEffectVolume, 127);
|
||||
|
||||
private final String name;
|
||||
private final WidgetInfo widgetID;
|
||||
private final VarPlayer var;
|
||||
private final ToIntFunction<MusicConfig> getter;
|
||||
@@ -434,6 +444,18 @@ public class MusicPlugin extends Plugin
|
||||
{
|
||||
return getTrack().getWidth() - (PADDING * 2) - handle.getWidth();
|
||||
}
|
||||
|
||||
private int getValue(final MusicConfig config, final Client client)
|
||||
{
|
||||
int value = getter.applyAsInt(config) - 1;
|
||||
if (value <= -1)
|
||||
{
|
||||
// Use the vanilla value
|
||||
value = ((4 - client.getVar(var)) * max) / 4;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
private void teardownMusicOptions()
|
||||
@@ -542,6 +564,9 @@ public class MusicPlugin extends Plugin
|
||||
handle.setOriginalHeight(16);
|
||||
handle.setClickMask(WidgetConfig.DRAG);
|
||||
|
||||
handle.setOnMouseRepeatListener((JavaScriptCallback) ev -> hoveredSlider = slider);
|
||||
handle.setHasListener(true);
|
||||
|
||||
JavaScriptCallback move = ev ->
|
||||
{
|
||||
int newVal = ((ev.getMouseX() - MusicSlider.PADDING - (slider.getHandle().getWidth() / 2)) * slider.getMax())
|
||||
@@ -568,20 +593,28 @@ public class MusicPlugin extends Plugin
|
||||
client.runScript(ScriptID.OPTIONS_ALLSOUNDS, -1, init[2], init[3], init[4], init[5], init[6]);
|
||||
}
|
||||
|
||||
int value = slider.getGetter().applyAsInt(musicConfig) - 1;
|
||||
if (value <= -1)
|
||||
{
|
||||
// Use the vanilla value
|
||||
value = ((4 - client.getVar(slider.getVar())) * slider.getMax()) / 4;
|
||||
}
|
||||
|
||||
int newX = ((value * slider.getWidth()) / slider.getMax()) + slider.getX();
|
||||
final int value = slider.getValue(musicConfig, client);
|
||||
final int newX = ((value * slider.getWidth()) / slider.getMax()) + slider.getX();
|
||||
slider.getHandle().setOriginalX(newX);
|
||||
slider.getHandle().setOriginalY(slider.getTrack().getOriginalY());
|
||||
slider.getHandle().revalidate();
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onBeforeRender(final BeforeRender event)
|
||||
{
|
||||
// Tooltips are auto-cleared before each render frame; create a new updated one for this frame
|
||||
if (hoveredSlider != null)
|
||||
{
|
||||
final int value = hoveredSlider.getValue(musicConfig, client);
|
||||
final int percent = (int) Math.round((value * 100.0 / hoveredSlider.getMax()));
|
||||
|
||||
tooltipManager.add(new Tooltip(hoveredSlider.getName() + ": " + percent + "%"));
|
||||
hoveredSlider = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onScriptCallbackEvent(ScriptCallbackEvent ev)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user