aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com>2022-06-13 19:23:30 +0200
committerDeDiamondPro <67508414+DeDiamondPro@users.noreply.github.com>2022-06-13 19:23:30 +0200
commit1500cf9ad6bdb8240f2b01c117c06944ec30651a (patch)
tree04ca023e6c8b06e0e46140d256342902da265c0a /src
parent2fcd6f24968967f1ebe7515bab8c7f36cf6dd1a8 (diff)
downloadOneConfig-1500cf9ad6bdb8240f2b01c117c06944ec30651a.tar.gz
OneConfig-1500cf9ad6bdb8240f2b01c117c06944ec30651a.tar.bz2
OneConfig-1500cf9ad6bdb8240f2b01c117c06944ec30651a.zip
fix keybinds
Diffstat (limited to 'src')
-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
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigKeyBind.java8
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/internal/config/Preferences.java3
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/internal/config/core/KeyBindHandler.java1
5 files changed, 24 insertions, 14 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;
+ }
}
diff --git a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigKeyBind.java b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigKeyBind.java
index aa215a4..94224f1 100644
--- a/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigKeyBind.java
+++ b/src/main/java/cc/polyfrost/oneconfig/gui/elements/config/ConfigKeyBind.java
@@ -1,17 +1,16 @@
package cc.polyfrost.oneconfig.gui.elements.config;
import cc.polyfrost.oneconfig.config.annotations.KeyBind;
-import cc.polyfrost.oneconfig.internal.assets.Colors;
import cc.polyfrost.oneconfig.config.core.OneKeyBind;
import cc.polyfrost.oneconfig.config.elements.BasicOption;
import cc.polyfrost.oneconfig.gui.OneConfigGui;
import cc.polyfrost.oneconfig.gui.elements.BasicButton;
-import cc.polyfrost.oneconfig.internal.config.core.KeyBindHandler;
+import cc.polyfrost.oneconfig.internal.assets.Colors;
+import cc.polyfrost.oneconfig.internal.assets.SVGs;
+import cc.polyfrost.oneconfig.libs.universal.UKeyboard;
import cc.polyfrost.oneconfig.renderer.RenderManager;
import cc.polyfrost.oneconfig.renderer.font.Fonts;
-import cc.polyfrost.oneconfig.internal.assets.SVGs;
import cc.polyfrost.oneconfig.utils.color.ColorPalette;
-import cc.polyfrost.oneconfig.libs.universal.UKeyboard;
import java.lang.reflect.Field;
@@ -23,7 +22,6 @@ public class ConfigKeyBind extends BasicOption {
super(field, parent, name, category, subcategory, size);
button = new BasicButton(256, 32, "", SVGs.KEYSTROKE, null, BasicButton.ALIGNMENT_JUSTIFIED, ColorPalette.SECONDARY);
button.setToggleable(true);
- KeyBindHandler.INSTANCE.addKeyBind(getKeyBind());
}
public static ConfigKeyBind create(Field field, Object parent) {
diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/config/Preferences.java b/src/main/java/cc/polyfrost/oneconfig/internal/config/Preferences.java
index 10c14a8..ffb4b62 100644
--- a/src/main/java/cc/polyfrost/oneconfig/internal/config/Preferences.java
+++ b/src/main/java/cc/polyfrost/oneconfig/internal/config/Preferences.java
@@ -17,9 +17,10 @@ public class Preferences extends InternalConfig {
name = "OneConfig Keybind",
size = 2
)
- public static OneKeyBind oneConfigKeyBind = new OneKeyBind(() -> GuiUtils.displayScreen(OneConfigGui.create()), UKeyboard.KEY_RSHIFT);
+ public static OneKeyBind oneConfigKeyBind = new OneKeyBind(UKeyboard.KEY_RSHIFT);
public Preferences() {
super("Preferences", "Preferences.json");
+ registerKeyBind(oneConfigKeyBind, () -> GuiUtils.displayScreen(OneConfigGui.create()));
}
}
diff --git a/src/main/java/cc/polyfrost/oneconfig/internal/config/core/KeyBindHandler.java b/src/main/java/cc/polyfrost/oneconfig/internal/config/core/KeyBindHandler.java
index 6829ae4..e285b51 100644
--- a/src/main/java/cc/polyfrost/oneconfig/internal/config/core/KeyBindHandler.java
+++ b/src/main/java/cc/polyfrost/oneconfig/internal/config/core/KeyBindHandler.java
@@ -18,7 +18,6 @@ public class KeyBindHandler {
}
public void addKeyBind(OneKeyBind keyBind) {
- if (keyBind == null) return;
keyBinds.add(keyBind);
}