zoom plugin: add control to reset zoom

This commit is contained in:
Ryan
2019-07-12 23:33:12 -04:00
committed by Adam
parent 4bcaf1b9b6
commit ebed283f1d
4 changed files with 90 additions and 7 deletions

View File

@@ -139,6 +139,17 @@ public final class ScriptID
*/
public static final int DIARY_QUEST_UPDATE_LINECOUNT = 2523;
/**
* Handles zoom input
*
* Updates the VarClientInts (73, 74) to this same value
* <ul>
* <li> int Reset zoom position </li>
* <li> int Reset zoom position </li>
* </ul>
*/
public static final int CAMERA_DO_ZOOM = 42;
/**
* Does nothing
*

View File

@@ -0,0 +1,46 @@
/*
* Copyright (c) 2019, Jacob M <https://github.com/jacoblairm>
* 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 HOLDER 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.zoom;
import lombok.AllArgsConstructor;
import lombok.Getter;
@Getter
@AllArgsConstructor
public enum ControlFunction
{
NONE("None"),
CONTROL_TO_ZOOM("Hold to zoom"),
CONTROL_TO_RESET("Reset zoom");
private final String name;
@Override
public String toString()
{
return getName();
}
}

View File

@@ -73,13 +73,28 @@ public interface ZoomConfig extends Config
}
@ConfigItem(
keyName = "requireControlDown",
name = "Require control down",
description = "Configures if holding control is required for zooming",
keyName = "controlFunction",
name = "Control Function",
description = "Configures the zoom function when control is pressed",
position = 4
)
default boolean requireControlDown()
default ControlFunction controlFunction()
{
return false;
return ControlFunction.NONE;
}
@ConfigItem(
keyName = "ctrlZoomValue",
name = "Reset zoom position",
description = "Position of zoom when it is reset",
position = 5
)
@Range(
min = OUTER_LIMIT_MIN,
max = OUTER_LIMIT_MAX
)
default int ctrlZoomValue()
{
return 512;
}
}

View File

@@ -30,9 +30,11 @@ import com.google.inject.Inject;
import com.google.inject.Provides;
import java.awt.event.KeyEvent;
import net.runelite.api.Client;
import net.runelite.api.ScriptID;
import net.runelite.api.events.ConfigChanged;
import net.runelite.api.events.FocusChanged;
import net.runelite.api.events.ScriptCallbackEvent;
import net.runelite.client.callback.ClientThread;
import net.runelite.client.config.ConfigManager;
import net.runelite.client.eventbus.Subscribe;
import net.runelite.client.input.KeyListener;
@@ -60,6 +62,9 @@ public class ZoomPlugin extends Plugin implements KeyListener
@Inject
private Client client;
@Inject
private ClientThread clientThread;
@Inject
private ZoomConfig zoomConfig;
@@ -85,7 +90,7 @@ public class ZoomPlugin extends Plugin implements KeyListener
int[] intStack = client.getIntStack();
int intStackSize = client.getIntStackSize();
if ("scrollWheelZoom".equals(event.getEventName()) && zoomConfig.requireControlDown() && !controlDown)
if (!controlDown && "scrollWheelZoom".equals(event.getEventName()) && zoomConfig.controlFunction() == ControlFunction.CONTROL_TO_ZOOM)
{
intStack[intStackSize - 1] = 1;
}
@@ -138,7 +143,7 @@ public class ZoomPlugin extends Plugin implements KeyListener
controlDown = false;
}
}
@Override
protected void startUp()
{
@@ -180,6 +185,12 @@ public class ZoomPlugin extends Plugin implements KeyListener
if (e.getKeyCode() == KeyEvent.VK_CONTROL)
{
controlDown = false;
if (zoomConfig.controlFunction() == ControlFunction.CONTROL_TO_RESET)
{
final int zoomValue = Ints.constrainToRange(zoomConfig.ctrlZoomValue(), zoomConfig.OUTER_LIMIT_MIN, INNER_ZOOM_LIMIT);
clientThread.invokeLater(() -> client.runScript(ScriptID.CAMERA_DO_ZOOM, zoomValue, zoomValue));
}
}
}
}