aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/cc/polyfrost/oneconfig/config
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/cc/polyfrost/oneconfig/config')
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/config/Config.java13
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/config/core/OneKeyBind.java13
2 files changed, 19 insertions, 7 deletions
diff --git a/src/main/java/cc/polyfrost/oneconfig/config/Config.java b/src/main/java/cc/polyfrost/oneconfig/config/Config.java
index 62609d4..d4b6022 100644
--- a/src/main/java/cc/polyfrost/oneconfig/config/Config.java
+++ b/src/main/java/cc/polyfrost/oneconfig/config/Config.java
@@ -4,6 +4,7 @@ import cc.polyfrost.oneconfig.config.annotations.CustomOption;
import cc.polyfrost.oneconfig.config.annotations.HUD;
import cc.polyfrost.oneconfig.config.annotations.Page;
import cc.polyfrost.oneconfig.config.core.ConfigUtils;
+import cc.polyfrost.oneconfig.config.core.OneKeyBind;
import cc.polyfrost.oneconfig.config.data.Mod;
import cc.polyfrost.oneconfig.config.data.PageLocation;
import cc.polyfrost.oneconfig.config.elements.BasicOption;
@@ -16,6 +17,7 @@ import cc.polyfrost.oneconfig.gui.pages.ModConfigPage;
import cc.polyfrost.oneconfig.hud.HUDUtils;
import cc.polyfrost.oneconfig.internal.config.annotations.Option;
import cc.polyfrost.oneconfig.internal.config.core.ConfigCore;
+import cc.polyfrost.oneconfig.internal.config.core.KeyBindHandler;
import cc.polyfrost.oneconfig.utils.gui.GuiUtils;
import com.google.gson.*;
@@ -215,4 +217,15 @@ public class Config {
if (!optionNames.containsKey(option)) return;
optionNames.get(option).addListener(runnable);
}
+
+ /**
+ * Register an action to a keybind
+ *
+ * @param keyBind The keybind
+ * @param runnable The code to be executed
+ */
+ protected void registerKeyBind(OneKeyBind keyBind, Runnable runnable) {
+ keyBind.setRunnable(runnable);
+ KeyBindHandler.INSTANCE.addKeyBind(keyBind);
+ }
}
diff --git a/src/main/java/cc/polyfrost/oneconfig/config/core/OneKeyBind.java b/src/main/java/cc/polyfrost/oneconfig/config/core/OneKeyBind.java
index 50a26e0..791bc4a 100644
--- a/src/main/java/cc/polyfrost/oneconfig/config/core/OneKeyBind.java
+++ b/src/main/java/cc/polyfrost/oneconfig/config/core/OneKeyBind.java
@@ -6,20 +6,15 @@ import java.util.ArrayList;
public class OneKeyBind {
protected final ArrayList<Integer> keyBinds = new ArrayList<>();
- protected transient final Runnable runnable;
+ protected transient Runnable runnable;
protected transient boolean hasRun;
- public OneKeyBind(Runnable runnable, int... keys) {
- this.runnable = runnable;
+ public OneKeyBind(int... keys) {
for (int key : keys) {
keyBinds.add(key);
}
}
- public OneKeyBind(int... keys) {
- this(null, keys);
- }
-
public boolean isActive() {
if (keyBinds.size() == 0) return false;
for (int keyBind : keyBinds) {
@@ -57,4 +52,8 @@ public class OneKeyBind {
public int getSize() {
return keyBinds.size();
}
+
+ public void setRunnable(Runnable runnable) {
+ this.runnable = runnable;
+ }
}