diff options
author | nea <nea@nea.moe> | 2023-08-31 23:23:43 +0200 |
---|---|---|
committer | nea <nea@nea.moe> | 2023-08-31 23:23:43 +0200 |
commit | 41dc53e00e683c62cec8eb08641156077b84639c (patch) | |
tree | 1d9757fde571e27430573f7b2f4a69380e0608e1 /src/main/kotlin/moe | |
parent | 36d5ef29e45a57e88d9d608d1becb5cb7de27cf5 (diff) | |
download | Firmament-41dc53e00e683c62cec8eb08641156077b84639c.tar.gz Firmament-41dc53e00e683c62cec8eb08641156077b84639c.tar.bz2 Firmament-41dc53e00e683c62cec8eb08641156077b84639c.zip |
Add the ability to unbind keys using ESCAPE
Diffstat (limited to 'src/main/kotlin/moe')
-rw-r--r-- | src/main/kotlin/moe/nea/firmament/gui/config/KeyBindingHandler.kt | 7 | ||||
-rw-r--r-- | src/main/kotlin/moe/nea/firmament/keybindings/SavedKeyBinding.kt | 20 |
2 files changed, 6 insertions, 21 deletions
diff --git a/src/main/kotlin/moe/nea/firmament/gui/config/KeyBindingHandler.kt b/src/main/kotlin/moe/nea/firmament/gui/config/KeyBindingHandler.kt index 11c9c7a..42cf66c 100644 --- a/src/main/kotlin/moe/nea/firmament/gui/config/KeyBindingHandler.kt +++ b/src/main/kotlin/moe/nea/firmament/gui/config/KeyBindingHandler.kt @@ -8,16 +8,16 @@ package moe.nea.firmament.gui.config import io.github.cottonmc.cotton.gui.widget.WButton import io.github.cottonmc.cotton.gui.widget.data.InputResult +import org.lwjgl.glfw.GLFW import kotlinx.serialization.json.Json import kotlinx.serialization.json.JsonElement import kotlinx.serialization.json.decodeFromJsonElement import kotlinx.serialization.json.encodeToJsonElement -import moe.nea.firmament.keybindings.FirmamentKeyBindings -import moe.nea.firmament.keybindings.SavedKeyBinding import net.minecraft.client.util.InputUtil import net.minecraft.text.Text import net.minecraft.util.Formatting -import org.lwjgl.glfw.GLFW +import moe.nea.firmament.keybindings.FirmamentKeyBindings +import moe.nea.firmament.keybindings.SavedKeyBinding class KeyBindingHandler(name: String, managedConfig: ManagedConfig) : ManagedConfig.OptionHandler<SavedKeyBinding> { init { @@ -46,6 +46,7 @@ class KeyBindingHandler(name: String, managedConfig: ManagedConfig) : ManagedCon lastPressedNonModifier = 0 editing = false lastPressed = 0 + opt.value = SavedKeyBinding(GLFW.GLFW_KEY_UNKNOWN) updateButton!!() return InputResult.PROCESSED } diff --git a/src/main/kotlin/moe/nea/firmament/keybindings/SavedKeyBinding.kt b/src/main/kotlin/moe/nea/firmament/keybindings/SavedKeyBinding.kt index 606485b..e538ff0 100644 --- a/src/main/kotlin/moe/nea/firmament/keybindings/SavedKeyBinding.kt +++ b/src/main/kotlin/moe/nea/firmament/keybindings/SavedKeyBinding.kt @@ -38,25 +38,8 @@ data class SavedKeyBinding( } } - fun hasShiftDown(): Boolean { - return InputUtil.isKeyPressed( - MinecraftClient.getInstance().window.handle, - GLFW.GLFW_KEY_LEFT_SHIFT - ) || InputUtil.isKeyPressed( - MinecraftClient.getInstance().window.handle, GLFW.GLFW_KEY_RIGHT_SHIFT - ) - } - - fun hasAltDown(): Boolean { - return InputUtil.isKeyPressed( - MinecraftClient.getInstance().window.handle, - GLFW.GLFW_KEY_LEFT_ALT - ) || InputUtil.isKeyPressed( - MinecraftClient.getInstance().window.handle, GLFW.GLFW_KEY_RIGHT_ALT - ) - } - fun isPressed(): Boolean { + if (this.keyCode == GLFW.GLFW_KEY_UNKNOWN) return false val h = MC.window.handle if (!InputUtil.isKeyPressed(h, keyCode)) return false @@ -76,6 +59,7 @@ data class SavedKeyBinding( } override fun matches(keyCode: Int, scanCode: Int, modifiers: Int): Boolean { + if (this.keyCode == GLFW.GLFW_KEY_UNKNOWN) return false return keyCode == this.keyCode && getMods(modifiers) == Triple(shift, ctrl, alt) } |