diff options
author | Linnea Gräf <nea@nea.moe> | 2024-07-01 03:42:51 +0200 |
---|---|---|
committer | Linnea Gräf <nea@nea.moe> | 2024-07-03 21:05:51 +0200 |
commit | 5ee4b8d925eb12e068038a1fd2e1f35cdd8ef87e (patch) | |
tree | a5b0a6fbc8878ae62bb2c3a01dbb255388353fda /src/main/kotlin/moe/nea/firmament/keybindings/SavedKeyBinding.kt | |
parent | dff1f9c0e2b728dba902d72816104abccc61f511 (diff) | |
download | firmament-5ee4b8d925eb12e068038a1fd2e1f35cdd8ef87e.tar.gz firmament-5ee4b8d925eb12e068038a1fd2e1f35cdd8ef87e.tar.bz2 firmament-5ee4b8d925eb12e068038a1fd2e1f35cdd8ef87e.zip |
[WIP] Remove LibGUI
Diffstat (limited to 'src/main/kotlin/moe/nea/firmament/keybindings/SavedKeyBinding.kt')
-rw-r--r-- | src/main/kotlin/moe/nea/firmament/keybindings/SavedKeyBinding.kt | 38 |
1 files changed, 28 insertions, 10 deletions
diff --git a/src/main/kotlin/moe/nea/firmament/keybindings/SavedKeyBinding.kt b/src/main/kotlin/moe/nea/firmament/keybindings/SavedKeyBinding.kt index c5205bc..56865cc 100644 --- a/src/main/kotlin/moe/nea/firmament/keybindings/SavedKeyBinding.kt +++ b/src/main/kotlin/moe/nea/firmament/keybindings/SavedKeyBinding.kt @@ -6,11 +6,11 @@ package moe.nea.firmament.keybindings +import org.lwjgl.glfw.GLFW import kotlinx.serialization.Serializable -import moe.nea.firmament.util.MC import net.minecraft.client.MinecraftClient import net.minecraft.client.util.InputUtil -import org.lwjgl.glfw.GLFW +import moe.nea.firmament.util.MC @Serializable data class SavedKeyBinding( @@ -38,6 +38,24 @@ data class SavedKeyBinding( modifiers and GLFW.GLFW_MOD_ALT != 0 ) } + + fun getModInt(): Int { + val h = MC.window.handle + val ctrl = if (MinecraftClient.IS_SYSTEM_MAC) { + InputUtil.isKeyPressed(h, GLFW.GLFW_KEY_LEFT_SUPER) + || InputUtil.isKeyPressed(h, GLFW.GLFW_KEY_RIGHT_SUPER) + } else InputUtil.isKeyPressed(h, GLFW.GLFW_KEY_LEFT_CONTROL) + || InputUtil.isKeyPressed(h, GLFW.GLFW_KEY_RIGHT_CONTROL) + val shift = InputUtil.isKeyPressed(h, GLFW.GLFW_KEY_LEFT_SHIFT) + || InputUtil.isKeyPressed(h, GLFW.GLFW_KEY_RIGHT_SHIFT) + val alt = InputUtil.isKeyPressed(h, GLFW.GLFW_KEY_LEFT_ALT) + || InputUtil.isKeyPressed(h, GLFW.GLFW_KEY_RIGHT_ALT) + var mods = 0 + if (ctrl) mods = mods or GLFW.GLFW_MOD_CONTROL + if (shift) mods = mods or GLFW.GLFW_MOD_SHIFT + if (alt) mods = mods or GLFW.GLFW_MOD_ALT + return mods + } } fun isPressed(atLeast: Boolean = false): Boolean { @@ -47,21 +65,21 @@ data class SavedKeyBinding( val ctrl = if (MinecraftClient.IS_SYSTEM_MAC) { InputUtil.isKeyPressed(h, GLFW.GLFW_KEY_LEFT_SUPER) - || InputUtil.isKeyPressed(h, GLFW.GLFW_KEY_RIGHT_SUPER) + || InputUtil.isKeyPressed(h, GLFW.GLFW_KEY_RIGHT_SUPER) } else InputUtil.isKeyPressed(h, GLFW.GLFW_KEY_LEFT_CONTROL) - || InputUtil.isKeyPressed(h, GLFW.GLFW_KEY_RIGHT_CONTROL) + || InputUtil.isKeyPressed(h, GLFW.GLFW_KEY_RIGHT_CONTROL) val shift = InputUtil.isKeyPressed(h, GLFW.GLFW_KEY_LEFT_SHIFT) - || InputUtil.isKeyPressed(h, GLFW.GLFW_KEY_RIGHT_SHIFT) + || InputUtil.isKeyPressed(h, GLFW.GLFW_KEY_RIGHT_SHIFT) val alt = InputUtil.isKeyPressed(h, GLFW.GLFW_KEY_LEFT_ALT) - || InputUtil.isKeyPressed(h, GLFW.GLFW_KEY_RIGHT_ALT) + || InputUtil.isKeyPressed(h, GLFW.GLFW_KEY_RIGHT_ALT) if (atLeast) return (ctrl >= this.ctrl) && - (alt >= this.alt) && - (shift >= this.shift) + (alt >= this.alt) && + (shift >= this.shift) return (ctrl == this.ctrl) && - (alt == this.alt) && - (shift == this.shift) + (alt == this.alt) && + (shift == this.shift) } override fun matches(keyCode: Int, scanCode: Int, modifiers: Int): Boolean { |