Skip to content

Commit 9f6dcf5

Browse files
authored
Added Keybinds for Snapping Camera to Cardinal Directions (#14)
* Added functionality to bind cardinal directions to custom keybinds. * Update CompassCameraControlConfig.java * Update CompassCameraControlPlugin.java * update config formatting and text
1 parent 63af9b3 commit 9f6dcf5

File tree

2 files changed

+98
-3
lines changed

2 files changed

+98
-3
lines changed

src/main/java/com/compassCameraControl/CompassCameraControlConfig.java

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
package com.compassCameraControl;
22

3-
import net.runelite.client.config.Config;
4-
import net.runelite.client.config.ConfigGroup;
5-
import net.runelite.client.config.ConfigItem;
3+
import net.runelite.client.config.*;
4+
import java.awt.event.KeyEvent;
65

76
@ConfigGroup("compasscameracontrol")
87
public interface CompassCameraControlConfig extends Config
@@ -44,4 +43,58 @@ default ShiftMode shiftClickMode()
4443
{
4544
return ShiftMode.OFF;
4645
}
46+
47+
@ConfigSection(
48+
name = "Keybindings",
49+
position = 4,
50+
closedByDefault = true,
51+
description = "Settings for snapping the camera to cardinal directions<br/>" +
52+
"To prevent these keys from appearing in chat<br/>" +
53+
"Enable the \"Key Remapping\" plugin (included with RuneLite)"
54+
)
55+
String cardinalKeybindingSnap = "cardinalKeybindingSnap";
56+
57+
@ConfigItem(
58+
keyName = "lookNorthKey",
59+
name = "Look North Key",
60+
description = "Face camera North on key press",
61+
position = 5,
62+
section = cardinalKeybindingSnap
63+
)
64+
default ModifierlessKeybind lookNorthKey() {
65+
return new ModifierlessKeybind(KeyEvent.VK_UNDEFINED, 0);
66+
}
67+
68+
@ConfigItem(
69+
keyName = "lookSouthKey",
70+
name = "Look South Key",
71+
description = "Face camera South on key press",
72+
position = 6,
73+
section = cardinalKeybindingSnap
74+
)
75+
default ModifierlessKeybind lookSouthKey() {
76+
return new ModifierlessKeybind(KeyEvent.VK_UNDEFINED, 0);
77+
}
78+
79+
@ConfigItem(
80+
keyName = "lookEastKey",
81+
name = "Look East Key",
82+
description = "Face camera East on key press",
83+
position = 7,
84+
section = cardinalKeybindingSnap
85+
)
86+
default ModifierlessKeybind lookEastKey() {
87+
return new ModifierlessKeybind(KeyEvent.VK_UNDEFINED, 0);
88+
}
89+
90+
@ConfigItem(
91+
keyName = "lookWestKey",
92+
name = "Look West Key",
93+
description = "Face camera West on key press",
94+
position = 8,
95+
section = cardinalKeybindingSnap
96+
)
97+
default ModifierlessKeybind lookWestKey() {
98+
return new ModifierlessKeybind(KeyEvent.VK_UNDEFINED, 0);
99+
}
47100
}

src/main/java/com/compassCameraControl/CompassCameraControlPlugin.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.google.inject.Provides;
44
import javax.inject.Inject;
55
import javax.inject.Singleton;
6+
import java.awt.event.KeyEvent;
67
import java.util.Map;
78
import lombok.extern.slf4j.Slf4j;
89
import net.runelite.api.Client;
@@ -13,6 +14,8 @@
1314
import net.runelite.api.events.MenuEntryAdded;
1415
import net.runelite.client.config.ConfigManager;
1516
import net.runelite.client.eventbus.Subscribe;
17+
import net.runelite.client.input.KeyListener;
18+
import net.runelite.client.input.KeyManager;
1619
import net.runelite.client.plugins.Plugin;
1720
import net.runelite.client.plugins.PluginDescriptor;
1821

@@ -30,6 +33,10 @@ public class CompassCameraControlPlugin extends Plugin
3033
@Inject
3134
private CompassCameraControlConfig config;
3235

36+
@Inject
37+
private KeyManager keyManager;
38+
39+
3340
private static final int NORTH_YAW = 0;
3441
private static final int SOUTH_YAW = 1024;
3542
private static final int EAST_YAW = 1536;
@@ -180,4 +187,39 @@ private void alignYaw()
180187

181188
client.setCameraYawTarget(closestYaw);
182189
}
190+
191+
private final KeyListener keyListener = new KeyListener() {
192+
@Override
193+
public void keyTyped(KeyEvent e) {
194+
195+
}
196+
197+
@Override
198+
public void keyPressed(KeyEvent event) {
199+
if (event.getKeyCode() == config.lookNorthKey().getKeyCode()) {
200+
client.setCameraYawTarget(NORTH_YAW);
201+
} else if (event.getKeyCode() == config.lookSouthKey().getKeyCode()) {
202+
client.setCameraYawTarget(SOUTH_YAW);
203+
} else if (event.getKeyCode() == config.lookEastKey().getKeyCode()) {
204+
client.setCameraYawTarget(EAST_YAW);
205+
} else if (event.getKeyCode() == config.lookWestKey().getKeyCode()) {
206+
client.setCameraYawTarget(WEST_YAW);
207+
}
208+
}
209+
210+
@Override
211+
public void keyReleased(KeyEvent event) {
212+
// No action needed on key release
213+
}
214+
};
215+
216+
@Override
217+
protected void startUp() throws Exception {
218+
keyManager.registerKeyListener(keyListener);
219+
}
220+
221+
@Override
222+
protected void shutDown() throws Exception {
223+
keyManager.unregisterKeyListener(keyListener);
224+
}
183225
}

0 commit comments

Comments
 (0)