Add option to require control to be held for zooming

This commit is contained in:
Magic fTail
2018-10-01 02:48:36 +02:00
parent de8047bbd6
commit c367488e61
4 changed files with 117 additions and 4 deletions

View File

@@ -34,7 +34,8 @@ public interface ZoomConfig extends Config
@ConfigItem(
keyName = "enabled",
name = "Expand outer zoom limit",
description = "Configures whether or not the outer zoom limit is reduced"
description = "Configures whether or not the outer zoom limit is reduced",
position = 1
)
default boolean outerLimit()
{
@@ -44,7 +45,8 @@ public interface ZoomConfig extends Config
@ConfigItem(
keyName = "inner",
name = "Expand inner zoom limit",
description = "Configures whether or not the inner zoom limit is reduced"
description = "Configures whether or not the inner zoom limit is reduced",
position = 2
)
default boolean innerLimit()
{
@@ -54,10 +56,22 @@ public interface ZoomConfig extends Config
@ConfigItem(
keyName = "relaxCameraPitch",
name = "Vertical camera",
description = "Relax the camera's upper pitch limit"
description = "Relax the camera's upper pitch limit",
position = 3
)
default boolean relaxCameraPitch()
{
return false;
}
@ConfigItem(
keyName = "requireControlDown",
name = "Require control down",
description = "Configures if holding control is required for zooming",
position = 4
)
default boolean requireControlDown()
{
return false;
}
}

View File

@@ -28,10 +28,14 @@ package net.runelite.client.plugins.zoom;
import com.google.common.eventbus.Subscribe;
import com.google.inject.Inject;
import com.google.inject.Provides;
import java.awt.event.KeyEvent;
import net.runelite.api.Client;
import net.runelite.api.events.ConfigChanged;
import net.runelite.api.events.FocusChanged;
import net.runelite.api.events.ScriptCallbackEvent;
import net.runelite.client.config.ConfigManager;
import net.runelite.client.input.KeyListener;
import net.runelite.client.input.KeyManager;
import net.runelite.client.plugins.Plugin;
import net.runelite.client.plugins.PluginDescriptor;
@@ -41,14 +45,19 @@ import net.runelite.client.plugins.PluginDescriptor;
tags = {"limit", "vertical"},
enabledByDefault = false
)
public class ZoomPlugin extends Plugin
public class ZoomPlugin extends Plugin implements KeyListener
{
private boolean controlDown;
@Inject
private Client client;
@Inject
private ZoomConfig zoomConfig;
@Inject
private KeyManager keyManager;
@Provides
ZoomConfig getConfig(ConfigManager configManager)
{
@@ -67,6 +76,12 @@ public class ZoomPlugin extends Plugin
int[] intStack = client.getIntStack();
int intStackSize = client.getIntStackSize();
if ("scrollWheelZoom".equals(event.getEventName()) && zoomConfig.requireControlDown() && !controlDown)
{
intStack[intStackSize - 1] = 1;
}
if (zoomConfig.outerLimit())
{
switch (event.getEventName())
@@ -117,16 +132,28 @@ public class ZoomPlugin extends Plugin
}
}
@Subscribe
public void onFocusChanged(FocusChanged event)
{
if (!event.isFocused())
{
controlDown = false;
}
}
@Override
protected void startUp()
{
client.setCameraPitchRelaxerEnabled(zoomConfig.relaxCameraPitch());
keyManager.registerKeyListener(this);
}
@Override
protected void shutDown()
{
client.setCameraPitchRelaxerEnabled(false);
keyManager.unregisterKeyListener(this);
controlDown = false;
}
@Subscribe
@@ -134,4 +161,27 @@ public class ZoomPlugin extends Plugin
{
client.setCameraPitchRelaxerEnabled(zoomConfig.relaxCameraPitch());
}
@Override
public void keyTyped(KeyEvent e)
{
}
@Override
public void keyPressed(KeyEvent e)
{
if (e.getKeyCode() == KeyEvent.VK_CONTROL)
{
controlDown = true;
}
}
@Override
public void keyReleased(KeyEvent e)
{
if (e.getKeyCode() == KeyEvent.VK_CONTROL)
{
controlDown = false;
}
}
}