Merge remote-tracking branch 'runelite/master'

This commit is contained in:
Owain van Brakel
2019-12-05 13:09:03 +01:00
12 changed files with 591 additions and 316 deletions

View File

@@ -22,7 +22,7 @@
* (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;
package net.runelite.client.plugins.camera;
import net.runelite.client.config.Config;
import net.runelite.client.config.ConfigGroup;
@@ -30,7 +30,7 @@ import net.runelite.client.config.ConfigItem;
import net.runelite.client.config.Range;
@ConfigGroup("zoom")
public interface ZoomConfig extends Config
public interface CameraConfig extends Config
{
int OUTER_LIMIT_MIN = -400;
int OUTER_LIMIT_MAX = 400;
@@ -115,4 +115,36 @@ public interface ZoomConfig extends Config
return 25;
}
@ConfigItem(
keyName = "rightClickMovesCamera",
name = "Right click moves camera",
description = "Remaps right click to middle mouse click if there are no menu options",
position = 7
)
default boolean rightClickMovesCamera()
{
return false;
}
@ConfigItem(
keyName = "ignoreExamine",
name = "Ignore Examine",
description = "Ignore the Examine menu entry",
position = 8
)
default boolean ignoreExamine()
{
return false;
}
@ConfigItem(
keyName = "middleClickMenu",
name = "Middle-button opens menu",
description = "Middle-mouse button always opens the menu",
position = 9
)
default boolean middleClickMenu()
{
return false;
}
}

View File

@@ -0,0 +1,387 @@
/*
* Copyright (c) 2018 Abex
* Copyright (c) 2018, Adam <Adam@sigterm.info>
* Copyright (c) 2019, Wynadorn <https://github.com/Wynadorn>
* 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 com.google.inject.Inject;
import com.google.inject.Provides;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import javax.swing.SwingUtilities;
import net.runelite.api.Client;
import net.runelite.api.MenuEntry;
import net.runelite.api.ScriptID;
import net.runelite.api.VarPlayer;
import net.runelite.api.events.ClientTick;
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.events.ConfigChanged;
import net.runelite.client.input.KeyListener;
import net.runelite.client.input.KeyManager;
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.util.MiscUtils;
@PluginDescriptor(
name = "Camera Zoom",
description = "Expands zoom limit, provides vertical camera, and remaps mouse input keys",
tags = {"zoom", "limit", "vertical", "click", "mouse"},
enabledByDefault = false
)
public class CameraPlugin extends Plugin implements KeyListener, MouseListener
{
/**
* The largest (most zoomed in) value that can be used without the client crashing.
* <p>
* Larger values trigger an overflow in the engine's fov to scale code.
*/
private static final int INNER_ZOOM_LIMIT = 1004;
private static final int DEFAULT_ZOOM_INCREMENT = 25;
private boolean controlDown;
// flags used to store the mousedown states
private boolean rightClick;
private boolean middleClick;
/**
* Whether or not the current menu has any non-ignored menu entries
*/
private boolean menuHasEntries;
@Inject
private Client client;
@Inject
private ClientThread clientThread;
@Inject
private CameraConfig cameraConfig;
@Inject
private KeyManager keyManager;
@Inject
private MouseManager mouseManager;
@Provides
CameraConfig getConfig(ConfigManager configManager)
{
return configManager.getConfig(CameraConfig.class);
}
@Subscribe
private void onScriptCallbackEvent(ScriptCallbackEvent event)
{
if (client.getIndexScripts().isOverlayOutdated())
{
// if any cache overlay fails to load then assume at least one of the zoom scripts is outdated
// and prevent zoom extending entirely.
return;
}
int[] intStack = client.getIntStack();
int intStackSize = client.getIntStackSize();
if (!controlDown && "scrollWheelZoom".equals(event.getEventName()) && cameraConfig.controlFunction() == ControlFunction.CONTROL_TO_ZOOM)
{
intStack[intStackSize - 1] = 1;
}
if ("innerZoomLimit".equals(event.getEventName()) && cameraConfig.innerLimit())
{
intStack[intStackSize - 1] = INNER_ZOOM_LIMIT;
return;
}
if ("outerZoomLimit".equals(event.getEventName()))
{
int outerLimit = MiscUtils.clamp(cameraConfig.outerLimit(), CameraConfig.OUTER_LIMIT_MIN, CameraConfig.OUTER_LIMIT_MAX);
int outerZoomLimit = 128 - outerLimit;
intStack[intStackSize - 1] = outerZoomLimit;
return;
}
if ("scrollWheelZoomIncrement".equals(event.getEventName()) && cameraConfig.zoomIncrement() != DEFAULT_ZOOM_INCREMENT)
{
intStack[intStackSize - 1] = cameraConfig.zoomIncrement();
return;
}
if (cameraConfig.innerLimit())
{
// This lets the options panel's slider have an exponential rate
final double exponent = 2.d;
switch (event.getEventName())
{
case "zoomLinToExp":
{
double range = intStack[intStackSize - 1];
double value = intStack[intStackSize - 2];
value = Math.pow(value / range, exponent) * range;
intStack[intStackSize - 2] = (int) value;
break;
}
case "zoomExpToLin":
{
double range = intStack[intStackSize - 1];
double value = intStack[intStackSize - 2];
value = Math.pow(value / range, 1.d / exponent) * range;
intStack[intStackSize - 2] = (int) value;
break;
}
}
}
}
@Subscribe
private void onFocusChanged(FocusChanged event)
{
if (!event.isFocused())
{
controlDown = false;
}
}
@Override
protected void startUp()
{
rightClick = false;
middleClick = false;
menuHasEntries = false;
client.setCameraPitchRelaxerEnabled(cameraConfig.relaxCameraPitch());
keyManager.registerKeyListener(this);
mouseManager.registerMouseListener(this);
}
@Override
protected void shutDown()
{
client.setCameraPitchRelaxerEnabled(false);
keyManager.unregisterKeyListener(this);
mouseManager.unregisterMouseListener(this);
controlDown = false;
}
@Subscribe
private void onConfigChanged(ConfigChanged ev)
{
client.setCameraPitchRelaxerEnabled(cameraConfig.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;
if (cameraConfig.controlFunction() == ControlFunction.CONTROL_TO_RESET)
{
final int zoomValue = MiscUtils.clamp(cameraConfig.ctrlZoomValue(), cameraConfig.OUTER_LIMIT_MIN, INNER_ZOOM_LIMIT);
clientThread.invokeLater(() -> client.runScript(ScriptID.CAMERA_DO_ZOOM, zoomValue, zoomValue));
}
}
}
/**
* Checks if the menu has any non-ignored entries
*/
private boolean hasMenuEntries(MenuEntry[] menuEntries)
{
for (MenuEntry menuEntry : menuEntries)
{
switch (menuEntry.getMenuOpcode())
{
case CANCEL:
case WALK:
break;
case EXAMINE_OBJECT:
case EXAMINE_NPC:
case EXAMINE_ITEM_GROUND:
case EXAMINE_ITEM:
case EXAMINE_ITEM_BANK_EQ:
if (cameraConfig.ignoreExamine())
{
break;
}
default:
return true;
}
}
return false;
}
/**
* Checks if the menu has any options, because menu entries are built each
* tick and the MouseListener runs on the awt thread
*/
@Subscribe
public void onClientTick(ClientTick event)
{
menuHasEntries = hasMenuEntries(client.getMenuEntries());
}
/**
* 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
* <p>
* This method also provides the config option to enable the middle-mouse button to always open the right click menu
*/
@Override
public MouseEvent mousePressed(MouseEvent mouseEvent)
{
if (SwingUtilities.isRightMouseButton(mouseEvent) && cameraConfig.rightClickMovesCamera())
{
boolean oneButton = client.getVar(VarPlayer.MOUSE_BUTTONS) == 1;
// Only move the camera if there is nothing at the menu, or if
// in one-button mode. In one-button mode, left and right click always do the same thing,
// so always treat it as the menu is empty
if (!menuHasEntries || oneButton)
{
// Set the rightClick flag to true so we can release the button in mouseReleased() later
rightClick = true;
// Change the mousePressed() MouseEvent to the middle mouse button
mouseEvent = new MouseEvent((java.awt.Component) mouseEvent.getSource(),
mouseEvent.getID(),
mouseEvent.getWhen(),
mouseEvent.getModifiersEx(),
mouseEvent.getX(),
mouseEvent.getY(),
mouseEvent.getClickCount(),
mouseEvent.isPopupTrigger(),
MouseEvent.BUTTON2);
}
}
else if (SwingUtilities.isMiddleMouseButton((mouseEvent)) && cameraConfig.middleClickMenu())
{
// Set the middleClick flag to true so we can release it later in mouseReleased()
middleClick = true;
// Chance the middle mouse button MouseEvent to a right-click
mouseEvent = new MouseEvent((java.awt.Component) mouseEvent.getSource(),
mouseEvent.getID(),
mouseEvent.getWhen(),
mouseEvent.getModifiersEx(),
mouseEvent.getX(),
mouseEvent.getY(),
mouseEvent.getClickCount(),
mouseEvent.isPopupTrigger(),
MouseEvent.BUTTON3);
}
return mouseEvent;
}
/**
* Correct the MouseEvent to release the correct button
*/
@Override
public MouseEvent mouseReleased(MouseEvent mouseEvent)
{
if (rightClick)
{
rightClick = false;
// Change the MouseEvent to button 2 so the middle mouse button will be released
mouseEvent = new MouseEvent((java.awt.Component) mouseEvent.getSource(),
mouseEvent.getID(),
mouseEvent.getWhen(),
mouseEvent.getModifiersEx(),
mouseEvent.getX(),
mouseEvent.getY(),
mouseEvent.getClickCount(),
mouseEvent.isPopupTrigger(),
MouseEvent.BUTTON2);
}
if (middleClick)
{
middleClick = false;
// Change the MouseEvent ot button 3 so the right mouse button will be released
mouseEvent = new MouseEvent((java.awt.Component) mouseEvent.getSource(),
mouseEvent.getID(),
mouseEvent.getWhen(),
mouseEvent.getModifiersEx(),
mouseEvent.getX(),
mouseEvent.getY(),
mouseEvent.getClickCount(),
mouseEvent.isPopupTrigger(),
MouseEvent.BUTTON3);
}
return mouseEvent;
}
/*
* These methods are unused but required to be present in a MouseListener implementation
*/
// region Unused MouseListener methods
@Override
public MouseEvent mouseDragged(MouseEvent mouseEvent)
{
return mouseEvent;
}
@Override
public MouseEvent mouseMoved(MouseEvent mouseEvent)
{
return mouseEvent;
}
@Override
public MouseEvent mouseClicked(MouseEvent mouseEvent)
{
return mouseEvent;
}
@Override
public MouseEvent mouseEntered(MouseEvent mouseEvent)
{
return mouseEvent;
}
@Override
public MouseEvent mouseExited(MouseEvent mouseEvent)
{
return mouseEvent;
}
// endregion
}

View File

@@ -23,7 +23,7 @@
* 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;
package net.runelite.client.plugins.camera;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;

View File

@@ -24,9 +24,12 @@
*/
package net.runelite.client.plugins.chatcommands;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import net.runelite.client.config.Config;
import net.runelite.client.config.ConfigGroup;
import net.runelite.client.config.ConfigItem;
import net.runelite.client.config.Keybind;
@ConfigGroup("chatcommands")
public interface ChatCommandsConfig extends Config
@@ -121,17 +124,28 @@ public interface ChatCommandsConfig extends Config
@ConfigItem(
position = 8,
keyName = "clearShortcuts",
name = "Clear shortcuts",
description = "Enable shortcuts (ctrl+w and backspace) for clearing the chatbox"
keyName = "clearSingleWord",
name = "Clear Single Word",
description = "Enable hot key to clear single word at a time"
)
default boolean clearShortcuts()
default Keybind clearSingleWord()
{
return true;
return new Keybind(KeyEvent.VK_W, InputEvent.CTRL_DOWN_MASK);
}
@ConfigItem(
position = 5,
position = 9,
keyName = "clearEntireChatBox",
name = "Clear Chat Box",
description = "Enable hotkey to clear entire chat box"
)
default Keybind clearChatBox()
{
return new Keybind(KeyEvent.VK_BACK_SPACE, InputEvent.CTRL_DOWN_MASK);
}
@ConfigItem(
position = 10,
keyName = "clipboardShortcuts",
name = "Clipboard shortcuts",
description = "Enable clipboard shortcuts (ctrl+c and ctrl+v)"

View File

@@ -28,12 +28,10 @@ import java.awt.event.KeyEvent;
import javax.inject.Inject;
import javax.inject.Singleton;
import net.runelite.api.Client;
import net.runelite.api.GameState;
import net.runelite.api.ScriptID;
import net.runelite.api.VarClientStr;
import net.runelite.client.callback.ClientThread;
import net.runelite.client.input.KeyListener;
import net.runelite.client.util.Clipboard;
@Singleton
class ChatKeyboardListener implements KeyListener
@@ -56,85 +54,43 @@ class ChatKeyboardListener implements KeyListener
@Override
public void keyPressed(KeyEvent e)
{
if (!e.isControlDown() || client.getGameState() != GameState.LOGGED_IN)
if (chatCommandsConfig.clearSingleWord().matches(e))
{
return;
}
String input = client.getVar(VarClientStr.CHATBOX_TYPED_TEXT);
switch (e.getKeyCode())
{
case KeyEvent.VK_C:
if (!chatCommandsConfig.clipboardShortcuts())
String input = client.getVar(VarClientStr.CHATBOX_TYPED_TEXT);
if (input != null)
{
// remove trailing space
while (input.endsWith(" "))
{
break;
input = input.substring(0, input.length() - 1);
}
Clipboard.store(input);
break;
case KeyEvent.VK_V:
if (!chatCommandsConfig.clipboardShortcuts())
// find next word
int idx = input.lastIndexOf(' ');
final String replacement;
if (idx != -1)
{
break;
replacement = input.substring(0, idx);
}
else
{
replacement = "";
}
final String clipboard = Clipboard.retrieve();
if (clipboard != null && !clipboard.isEmpty())
{
final String replacement = input + clipboard;
clientThread.invoke(() -> client.setVar(VarClientStr.CHATBOX_TYPED_TEXT, replacement));
}
break;
case KeyEvent.VK_W:
if (!chatCommandsConfig.clearShortcuts())
{
break;
}
if (input != null)
{
// remove trailing space
while (input.endsWith(" "))
{
input = input.substring(0, input.length() - 1);
}
// find next word
int idx = input.lastIndexOf(' ');
final String replacement;
if (idx != -1)
{
replacement = input.substring(0, idx);
}
else
{
replacement = "";
}
clientThread.invoke(() ->
{
client.setVar(VarClientStr.CHATBOX_TYPED_TEXT, replacement);
client.runScript(ScriptID.CHAT_PROMPT_INIT);
});
}
break;
case KeyEvent.VK_BACK_SPACE:
clientThread.invoke(() ->
{
client.setVar(VarClientStr.CHATBOX_TYPED_TEXT, "");
client.setVar(VarClientStr.CHATBOX_TYPED_TEXT, replacement);
client.runScript(ScriptID.CHAT_PROMPT_INIT);
});
if (!chatCommandsConfig.clearShortcuts())
{
break;
}
clientThread.invoke(() -> client.setVar(VarClientStr.CHATBOX_TYPED_TEXT, ""));
break;
}
}
else if (chatCommandsConfig.clearChatBox().matches(e))
{
clientThread.invoke(() ->
{
client.setVar(VarClientStr.CHATBOX_TYPED_TEXT, "");
client.runScript(ScriptID.CHAT_PROMPT_INIT);
});
}
}

View File

@@ -54,7 +54,7 @@ import net.runelite.http.api.worlds.WorldResult;
import net.runelite.http.api.worlds.WorldType;
@PluginDescriptor(
name = "Chat League Icons",
name = "League Chat Icons",
description = "Changes the chat icon for players on league worlds",
enabledByDefault = false
)

View File

@@ -328,7 +328,7 @@ public class ObjectIndicatorsPlugin extends Plugin implements KeyListener
return;
}
markObject(name, object);
markObject(objectDefinition, name, object);
}
private void checkObjectPoints(TileObject object)
@@ -350,7 +350,8 @@ public class ObjectIndicatorsPlugin extends Plugin implements KeyListener
for (ObjectPoint objectPoint : objectPoints)
{
if (worldPoint.getRegionX() == objectPoint.getRegionX()
&& worldPoint.getRegionY() == objectPoint.getRegionY())
&& worldPoint.getRegionY() == objectPoint.getRegionY()
&& object.getPlane() == objectPoint.getZ())
{
// Transform object to get the name which matches against what we've stored
ObjectDefinition objectDefinition = getObjectDefinition(object.getId());
@@ -432,13 +433,14 @@ public class ObjectIndicatorsPlugin extends Plugin implements KeyListener
return false;
}
private void markObject(String name, final TileObject object)
/** mark or unmark an object
*
* @param objectComposition transformed composition of object based on vars
* @param name name of objectComposition
* @param object tile object, for multilocs object.getId() is the base id
*/
private void markObject(ObjectDefinition objectComposition, String name, final TileObject object)
{
if (object == null)
{
return;
}
final WorldPoint worldPoint = WorldPoint.fromLocalInstance(client, object.getLocalLocation());
if (worldPoint == null)
{
@@ -457,9 +459,11 @@ public class ObjectIndicatorsPlugin extends Plugin implements KeyListener
if (objects.remove(object))
{
// Use object id instead of name to match the object point with this object due to the object name being
// able to change because of multilocs.
if (!objectPoints.removeIf(op -> (op.getId() == -1 || op.getId() == object.getId())
// Find the object point that caused this object to be marked, there are two cases:
// 1) object is a multiloc, the name may have changed since marking - match from base id
// 2) not a multiloc, but an object has spawned with an identical name and a different
// id as what was originally marked
if (!objectPoints.removeIf(op -> ((op.getId() == -1 || op.getId() == object.getId()) || op.getName().equals(objectComposition.getName()))
&& op.getRegionX() == worldPoint.getRegionX()
&& op.getRegionY() == worldPoint.getRegionY()
&& op.getZ() == worldPoint.getPlane()))

View File

@@ -1,204 +0,0 @@
/*
* Copyright (c) 2018 Abex
* Copyright (c) 2018, Adam <Adam@sigterm.info>
* 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.zoom;
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.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.events.ConfigChanged;
import net.runelite.client.input.KeyListener;
import net.runelite.client.input.KeyManager;
import net.runelite.client.plugins.Plugin;
import net.runelite.client.plugins.PluginDescriptor;
import net.runelite.client.util.MiscUtils;
@PluginDescriptor(
name = "Camera Zoom",
description = "Expand zoom limit and/or enable vertical camera",
tags = {"limit", "vertical"},
enabledByDefault = false
)
public class ZoomPlugin extends Plugin implements KeyListener
{
/**
* The largest (most zoomed in) value that can be used without the client crashing.
* <p>
* Larger values trigger an overflow in the engine's fov to scale code.
*/
private static final int INNER_ZOOM_LIMIT = 1004;
private static final int DEFAULT_ZOOM_INCREMENT = 25;
private boolean controlDown;
@Inject
private Client client;
@Inject
private ClientThread clientThread;
@Inject
private ZoomConfig zoomConfig;
@Inject
private KeyManager keyManager;
@Provides
ZoomConfig getConfig(ConfigManager configManager)
{
return configManager.getConfig(ZoomConfig.class);
}
@Subscribe
private void onScriptCallbackEvent(ScriptCallbackEvent event)
{
if (client.getIndexScripts().isOverlayOutdated())
{
// if any cache overlay fails to load then assume at least one of the zoom scripts is outdated
// and prevent zoom extending entirely.
return;
}
int[] intStack = client.getIntStack();
int intStackSize = client.getIntStackSize();
if (!controlDown && "scrollWheelZoom".equals(event.getEventName()) && zoomConfig.controlFunction() == ControlFunction.CONTROL_TO_ZOOM)
{
intStack[intStackSize - 1] = 1;
}
if ("innerZoomLimit".equals(event.getEventName()) && zoomConfig.innerLimit())
{
intStack[intStackSize - 1] = INNER_ZOOM_LIMIT;
return;
}
if ("outerZoomLimit".equals(event.getEventName()))
{
int outerLimit = MiscUtils.clamp(zoomConfig.outerLimit(), ZoomConfig.OUTER_LIMIT_MIN, ZoomConfig.OUTER_LIMIT_MAX);
int outerZoomLimit = 128 - outerLimit;
intStack[intStackSize - 1] = outerZoomLimit;
return;
}
if ("scrollWheelZoomIncrement".equals(event.getEventName()) && zoomConfig.zoomIncrement() != DEFAULT_ZOOM_INCREMENT)
{
intStack[intStackSize - 1] = zoomConfig.zoomIncrement();
return;
}
if (zoomConfig.innerLimit())
{
// This lets the options panel's slider have an exponential rate
final double exponent = 2.d;
switch (event.getEventName())
{
case "zoomLinToExp":
{
double range = intStack[intStackSize - 1];
double value = intStack[intStackSize - 2];
value = Math.pow(value / range, exponent) * range;
intStack[intStackSize - 2] = (int) value;
break;
}
case "zoomExpToLin":
{
double range = intStack[intStackSize - 1];
double value = intStack[intStackSize - 2];
value = Math.pow(value / range, 1.d / exponent) * range;
intStack[intStackSize - 2] = (int) value;
break;
}
}
}
}
@Subscribe
private 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
private void onConfigChanged(ConfigChanged ev)
{
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;
if (zoomConfig.controlFunction() == ControlFunction.CONTROL_TO_RESET)
{
final int zoomValue = MiscUtils.clamp(zoomConfig.ctrlZoomValue(), zoomConfig.OUTER_LIMIT_MIN, INNER_ZOOM_LIMIT);
clientThread.invokeLater(() -> client.runScript(ScriptID.CAMERA_DO_ZOOM, zoomValue, zoomValue));
}
}
}
}