From c367488e61ef3ce1f11a15e813b1ff1809346729 Mon Sep 17 00:00:00 2001 From: Magic fTail Date: Mon, 1 Oct 2018 02:48:36 +0200 Subject: [PATCH] Add option to require control to be held for zooming --- .../client/plugins/zoom/ZoomConfig.java | 20 +++++-- .../client/plugins/zoom/ZoomPlugin.java | 52 ++++++++++++++++++- .../main/scripts/ScrollWheelZoomHandler.hash | 1 + .../scripts/ScrollWheelZoomHandler.rs2asm | 48 +++++++++++++++++ 4 files changed, 117 insertions(+), 4 deletions(-) create mode 100644 runelite-client/src/main/scripts/ScrollWheelZoomHandler.hash create mode 100644 runelite-client/src/main/scripts/ScrollWheelZoomHandler.rs2asm diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/zoom/ZoomConfig.java b/runelite-client/src/main/java/net/runelite/client/plugins/zoom/ZoomConfig.java index 4b70b48401..bd26a31f7f 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/zoom/ZoomConfig.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/zoom/ZoomConfig.java @@ -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; + } } diff --git a/runelite-client/src/main/java/net/runelite/client/plugins/zoom/ZoomPlugin.java b/runelite-client/src/main/java/net/runelite/client/plugins/zoom/ZoomPlugin.java index d215eb5227..76781b3224 100644 --- a/runelite-client/src/main/java/net/runelite/client/plugins/zoom/ZoomPlugin.java +++ b/runelite-client/src/main/java/net/runelite/client/plugins/zoom/ZoomPlugin.java @@ -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; + } + } } diff --git a/runelite-client/src/main/scripts/ScrollWheelZoomHandler.hash b/runelite-client/src/main/scripts/ScrollWheelZoomHandler.hash new file mode 100644 index 0000000000..9c425e86cd --- /dev/null +++ b/runelite-client/src/main/scripts/ScrollWheelZoomHandler.hash @@ -0,0 +1 @@ +49E9E1634C15928A1C5F03B8949E68C741D508A18B528CCB4B6D080EF29180D8 \ No newline at end of file diff --git a/runelite-client/src/main/scripts/ScrollWheelZoomHandler.rs2asm b/runelite-client/src/main/scripts/ScrollWheelZoomHandler.rs2asm new file mode 100644 index 0000000000..05dc611e98 --- /dev/null +++ b/runelite-client/src/main/scripts/ScrollWheelZoomHandler.rs2asm @@ -0,0 +1,48 @@ +.id 39 +.int_stack_count 1 +.string_stack_count 0 +.int_var_count 4 +.string_var_count 0 + load_int 1 + load_int 0 + load_string "scrollWheelZoom" + runelite_callback + if_icmpeq LABEL18 + load_int 0 + iload 0 + load_int 5 + imul + isub + istore 1 + load_int 320 + istore 2 + load_int 256 + istore 3 + get_varbit 6357 + load_int 0 + if_icmpeq LABEL14 + jump LABEL33 +LABEL14: + get_varbit 4606 + load_int 0 + if_icmpne LABEL18 + jump LABEL19 +LABEL18: + return +LABEL19: + get_zoom_distance + istore 2 + istore 3 + iload 3 + iload 1 + add_percent + istore 3 + iload 2 + iload 1 + add_percent + istore 2 + iload 3 + iload 2 + invoke 42 +LABEL33: + return \ No newline at end of file