camera: add slider tooltip to main settings window
this replaces the overlay with onMouseRepeatListeners
This commit is contained in:
@@ -29,6 +29,8 @@ package net.runelite.api;
|
||||
*/
|
||||
public class SettingID
|
||||
{
|
||||
public static final int CAMERA_ZOOM = 14;
|
||||
|
||||
public static final int MUSIC_VOLUME = 30;
|
||||
public static final int EFFECT_VOLUME = 31;
|
||||
public static final int AREA_VOLUME = 32;
|
||||
|
||||
@@ -886,7 +886,7 @@ public class WidgetID
|
||||
|
||||
static class SettingsSide
|
||||
{
|
||||
static final int CAMERA_ZOOM_SLIDER_HANDLE = 55;
|
||||
static final int CAMERA_ZOOM_SLIDER_TRACK = 54;
|
||||
static final int MUSIC_SLIDER = 10;
|
||||
static final int SOUND_EFFECT_SLIDER = 14;
|
||||
static final int AREA_SOUND_SLIDER = 18;
|
||||
|
||||
@@ -532,7 +532,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),
|
||||
|
||||
SETTINGS_SIDE_CAMERA_ZOOM_SLIDER_HANDLE(WidgetID.SETTINGS_SIDE_GROUP_ID, WidgetID.SettingsSide.CAMERA_ZOOM_SLIDER_HANDLE),
|
||||
SETTINGS_SIDE_CAMERA_ZOOM_SLIDER_TRACK(WidgetID.SETTINGS_SIDE_GROUP_ID, WidgetID.SettingsSide.CAMERA_ZOOM_SLIDER_TRACK),
|
||||
SETTINGS_SIDE_MUSIC_SLIDER(WidgetID.SETTINGS_SIDE_GROUP_ID, WidgetID.SettingsSide.MUSIC_SLIDER),
|
||||
SETTINGS_SIDE_SOUND_EFFECT_SLIDER(WidgetID.SETTINGS_SIDE_GROUP_ID, WidgetID.SettingsSide.SOUND_EFFECT_SLIDER),
|
||||
SETTINGS_SIDE_AREA_SOUND_SLIDER(WidgetID.SETTINGS_SIDE_GROUP_ID, WidgetID.SettingsSide.AREA_SOUND_SLIDER),
|
||||
|
||||
@@ -1,74 +0,0 @@
|
||||
/*
|
||||
* 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.SETTINGS_SIDE_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;
|
||||
}
|
||||
}
|
||||
@@ -37,11 +37,20 @@ import net.runelite.api.Client;
|
||||
import net.runelite.api.MenuAction;
|
||||
import net.runelite.api.MenuEntry;
|
||||
import net.runelite.api.ScriptID;
|
||||
import net.runelite.api.SettingID;
|
||||
import net.runelite.api.VarClientInt;
|
||||
import net.runelite.api.VarPlayer;
|
||||
import net.runelite.api.events.BeforeRender;
|
||||
import net.runelite.api.events.ClientTick;
|
||||
import net.runelite.api.events.FocusChanged;
|
||||
import net.runelite.api.events.MenuEntryAdded;
|
||||
import net.runelite.api.events.ScriptCallbackEvent;
|
||||
import net.runelite.api.events.ScriptPreFired;
|
||||
import net.runelite.api.events.WidgetLoaded;
|
||||
import net.runelite.api.widgets.JavaScriptCallback;
|
||||
import net.runelite.api.widgets.Widget;
|
||||
import net.runelite.api.widgets.WidgetID;
|
||||
import net.runelite.api.widgets.WidgetInfo;
|
||||
import net.runelite.client.callback.ClientThread;
|
||||
import net.runelite.client.config.ConfigManager;
|
||||
import net.runelite.client.eventbus.Subscribe;
|
||||
@@ -52,7 +61,8 @@ 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;
|
||||
import net.runelite.client.ui.overlay.tooltip.Tooltip;
|
||||
import net.runelite.client.ui.overlay.tooltip.TooltipManager;
|
||||
|
||||
@PluginDescriptor(
|
||||
name = "Camera",
|
||||
@@ -96,10 +106,9 @@ public class CameraPlugin extends Plugin implements KeyListener, MouseListener
|
||||
private MouseManager mouseManager;
|
||||
|
||||
@Inject
|
||||
private OverlayManager overlayManager;
|
||||
private TooltipManager tooltipManager;
|
||||
|
||||
@Inject
|
||||
private CameraOverlay cameraOverlay;
|
||||
private Tooltip sliderTooltip;
|
||||
|
||||
@Provides
|
||||
CameraConfig getConfig(ConfigManager configManager)
|
||||
@@ -116,19 +125,50 @@ public class CameraPlugin extends Plugin implements KeyListener, MouseListener
|
||||
copyConfigs();
|
||||
keyManager.registerKeyListener(this);
|
||||
mouseManager.registerMouseListener(this);
|
||||
overlayManager.add(cameraOverlay);
|
||||
clientThread.invoke(() ->
|
||||
{
|
||||
Widget sideSlider = client.getWidget(WidgetInfo.SETTINGS_SIDE_CAMERA_ZOOM_SLIDER_TRACK);
|
||||
if (sideSlider != null)
|
||||
{
|
||||
addZoomTooltip(sideSlider);
|
||||
}
|
||||
|
||||
Widget settingsInit = client.getWidget(WidgetInfo.SETTINGS_INIT);
|
||||
if (settingsInit != null)
|
||||
{
|
||||
client.createScriptEvent(settingsInit.getOnLoadListener())
|
||||
.setSource(settingsInit)
|
||||
.run();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void shutDown()
|
||||
{
|
||||
overlayManager.remove(cameraOverlay);
|
||||
client.setCameraPitchRelaxerEnabled(false);
|
||||
client.setInvertYaw(false);
|
||||
client.setInvertPitch(false);
|
||||
keyManager.unregisterKeyListener(this);
|
||||
mouseManager.unregisterMouseListener(this);
|
||||
controlDown = false;
|
||||
|
||||
clientThread.invoke(() ->
|
||||
{
|
||||
Widget sideSlider = client.getWidget(WidgetInfo.SETTINGS_SIDE_CAMERA_ZOOM_SLIDER_TRACK);
|
||||
if (sideSlider != null)
|
||||
{
|
||||
sideSlider.setOnMouseRepeatListener((Object[]) null);
|
||||
}
|
||||
|
||||
Widget settingsInit = client.getWidget(WidgetInfo.SETTINGS_INIT);
|
||||
if (settingsInit != null)
|
||||
{
|
||||
client.createScriptEvent(settingsInit.getOnLoadListener())
|
||||
.setSource(settingsInit)
|
||||
.run();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void copyConfigs()
|
||||
@@ -318,6 +358,50 @@ public class CameraPlugin extends Plugin implements KeyListener, MouseListener
|
||||
menuHasEntries = hasMenuEntries(client.getMenuEntries());
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
private void onScriptPreFired(ScriptPreFired ev)
|
||||
{
|
||||
if (ev.getScriptId() == ScriptID.SETTINGS_SLIDER_CHOOSE_ONOP)
|
||||
{
|
||||
int arg = client.getIntStackSize() - 7;
|
||||
int[] is = client.getIntStack();
|
||||
|
||||
if (is[arg] == SettingID.CAMERA_ZOOM)
|
||||
{
|
||||
addZoomTooltip(client.getScriptActiveWidget());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
private void onWidgetLoaded(WidgetLoaded ev)
|
||||
{
|
||||
if (ev.getGroupId() == WidgetID.SETTINGS_SIDE_GROUP_ID)
|
||||
{
|
||||
addZoomTooltip(client.getWidget(WidgetInfo.SETTINGS_SIDE_CAMERA_ZOOM_SLIDER_TRACK));
|
||||
}
|
||||
}
|
||||
|
||||
private void addZoomTooltip(Widget w)
|
||||
{
|
||||
w.setOnMouseRepeatListener((JavaScriptCallback) ev ->
|
||||
{
|
||||
int value = client.getVar(VarClientInt.CAMERA_ZOOM_RESIZABLE_VIEWPORT);
|
||||
int max = config.innerLimit() ? config.INNER_ZOOM_LIMIT : CameraPlugin.DEFAULT_INNER_ZOOM_LIMIT;
|
||||
sliderTooltip = new Tooltip("Camera Zoom: " + value + " / " + max);
|
||||
});
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
private void onBeforeRender(BeforeRender ev)
|
||||
{
|
||||
if (sliderTooltip != null)
|
||||
{
|
||||
tooltipManager.add(sliderTooltip);
|
||||
sliderTooltip = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The event that is triggered when a mouse button is pressed
|
||||
* In this method the right click is changed to a middle-click to enable rotating the camera
|
||||
|
||||
Reference in New Issue
Block a user