aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/kotlin/moe/nea/firmament/gui/config/KeyBindingHandler.kt7
-rw-r--r--src/main/kotlin/moe/nea/firmament/keybindings/SavedKeyBinding.kt20
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)
}