Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/main/java/com/camerapoints/CameraPointsConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
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(Helper.CONFIG_GROUP)
public interface CameraPointsConfig extends Config
Expand All @@ -17,4 +18,20 @@ public interface CameraPointsConfig extends Config
default boolean disableWhileTyping() {
return true;
}

@ConfigItem(
position = 1,
keyName = "nextCameraPointKey",
name = "Keybind to cycle forward",
description = "When pressed, change to the next camera point in the list of camera points."
)
default Keybind nextCameraPointKey() { return Keybind.NOT_SET; }

@ConfigItem(
position = 2,
keyName = "previousCameraPointKey",
name = "Keybind to cycle backward",
description = "When pressed, change to the previous camera point in the list of camera points."
)
default Keybind previousCameraPointKey() { return Keybind.NOT_SET; }
}
56 changes: 55 additions & 1 deletion src/main/java/com/camerapoints/CameraPointsPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public class CameraPointsPlugin extends Plugin implements KeyListener

@Getter
private final List<CameraPoint> cameraPoints = new ArrayList<>();
private int cameraPointIndex;

@Provides
CameraPointsConfig getConfig(ConfigManager configManager)
Expand Down Expand Up @@ -123,7 +124,7 @@ public void onConfigChanged(ConfigChanged event)

public void addCameraPoint()
{
cameraPoints.add(new CameraPoint(Instant.now().toEpochMilli(), "Camera Point " + (cameraPoints.size() + 1), Direction.NONE, true, getZoom(), Keybind.NOT_SET));
cameraPoints.add(new CameraPoint(Instant.now().toEpochMilli(), "Camera Point " + (cameraPoints.size() + 1), Direction.NONE, true, getZoom(), Keybind.NOT_SET, true));
updateConfig();
}

Expand Down Expand Up @@ -168,6 +169,10 @@ private void loadConfig(String json)

public void setCamera(CameraPoint point)
{
if (point == null){
return;
}
System.out.println("Setting camera to " + point.getName());
clientThread.invoke(() -> {
if (point.isApplyZoom())
{
Expand All @@ -180,6 +185,48 @@ public void setCamera(CameraPoint point)
});
}

public CameraPoint nextCameraPoint() {
if (cameraPoints.isEmpty()) {
return null;
}
int startingIndex = cameraPointIndex;
int searchIndex = cameraPointIndex;
do {
searchIndex++;
if (searchIndex >= cameraPoints.size()) {
searchIndex = 0;
}

CameraPoint cameraPoint = cameraPoints.get(searchIndex);
if (cameraPoint.isEnabled()) {
cameraPointIndex = searchIndex;
return cameraPoint;
}
} while (searchIndex != startingIndex);
return null;
}

public CameraPoint previousCameraPoint() {
if (cameraPoints.isEmpty()) {
return null;
}
int startingIndex = cameraPointIndex;
int searchIndex = cameraPointIndex;
do {
searchIndex--;
if (searchIndex < 0) {
searchIndex = cameraPoints.size() - 1;
}

CameraPoint cameraPoint = cameraPoints.get(searchIndex);
if (cameraPoint.isEnabled()) {
cameraPointIndex = searchIndex;
return cameraPoint;
}
} while (searchIndex != startingIndex);
return null;
}

private boolean chatboxFocused()
{
Widget chatboxParent = client.getWidget(WidgetInfo.CHATBOX_PARENT);
Expand Down Expand Up @@ -215,6 +262,13 @@ public void keyPressed(KeyEvent e)
{
if ((!isTyping() && !isDialogOpen()) || !config.disableWhileTyping())
{
if (config.nextCameraPointKey().matches(e)) {
setCamera(nextCameraPoint());
}
else if (config.previousCameraPointKey().matches(e)) {
setCamera(previousCameraPoint());
}

for (CameraPoint point : cameraPoints) {
if (point.getKeybind().matches(e)) {
setCamera(point);
Expand Down
15 changes: 11 additions & 4 deletions src/main/java/com/camerapoints/ui/CameraPointPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@
import javax.swing.border.CompoundBorder;
import javax.swing.border.EmptyBorder;
import java.awt.*;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.*;
import java.awt.image.BufferedImage;
import java.util.Arrays;

Expand Down Expand Up @@ -244,6 +241,16 @@ public void mouseClicked(MouseEvent mouseEvent)
}
});

JCheckBox enableToggle = new JCheckBox("",point.isEnabled());
enableToggle.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent e) {
point.setEnabled(enableToggle.isSelected());
plugin.updateConfig();
}
});

nameWrapper.add(enableToggle, BorderLayout.WEST);
nameWrapper.add(nameInput, BorderLayout.CENTER);
nameWrapper.add(nameActions, BorderLayout.EAST);

Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/camerapoints/utility/CameraPoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ public class CameraPoint
private boolean applyZoom;
private int zoom;
private Keybind keybind;
private boolean enabled;
}