diff options
author | Linnea Gräf <nea@nea.moe> | 2024-07-05 22:52:06 +0200 |
---|---|---|
committer | Linnea Gräf <nea@nea.moe> | 2024-07-05 22:52:06 +0200 |
commit | dc3adecc1b34758ccd62b5086d0052ef70555282 (patch) | |
tree | dc487f4c14901c5dc59cabbaceaeae13c7feecf0 /src/main/kotlin/moe/nea/firmament/keybindings | |
parent | 3d792dbef7c7e0f186e29f2e3999f99c2c14f5d7 (diff) | |
download | firmament-dc3adecc1b34758ccd62b5086d0052ef70555282.tar.gz firmament-dc3adecc1b34758ccd62b5086d0052ef70555282.tar.bz2 firmament-dc3adecc1b34758ccd62b5086d0052ef70555282.zip |
Improve keybinding support
Diffstat (limited to 'src/main/kotlin/moe/nea/firmament/keybindings')
-rw-r--r-- | src/main/kotlin/moe/nea/firmament/keybindings/FirmamentKeyBindings.kt | 7 | ||||
-rw-r--r-- | src/main/kotlin/moe/nea/firmament/keybindings/SavedKeyBinding.kt | 17 |
2 files changed, 21 insertions, 3 deletions
diff --git a/src/main/kotlin/moe/nea/firmament/keybindings/FirmamentKeyBindings.kt b/src/main/kotlin/moe/nea/firmament/keybindings/FirmamentKeyBindings.kt index a5844e5..3fbdd84 100644 --- a/src/main/kotlin/moe/nea/firmament/keybindings/FirmamentKeyBindings.kt +++ b/src/main/kotlin/moe/nea/firmament/keybindings/FirmamentKeyBindings.kt @@ -9,10 +9,11 @@ package moe.nea.firmament.keybindings import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper import net.minecraft.client.option.KeyBinding import net.minecraft.client.util.InputUtil -import moe.nea.firmament.gui.config.ManagedConfig +import moe.nea.firmament.gui.config.KeyBindingHandler +import moe.nea.firmament.gui.config.ManagedOption object FirmamentKeyBindings { - fun registerKeyBinding(name: String, config: ManagedConfig) { + fun registerKeyBinding(name: String, config: ManagedOption<SavedKeyBinding>) { val vanillaKeyBinding = KeyBindingHelper.registerKeyBinding( KeyBinding( name, @@ -24,6 +25,6 @@ object FirmamentKeyBindings { keyBindings[vanillaKeyBinding] = config } - val keyBindings = mutableMapOf<KeyBinding, ManagedConfig>() + val keyBindings = mutableMapOf<KeyBinding, ManagedOption<SavedKeyBinding>>() } diff --git a/src/main/kotlin/moe/nea/firmament/keybindings/SavedKeyBinding.kt b/src/main/kotlin/moe/nea/firmament/keybindings/SavedKeyBinding.kt index 56865cc..f07cd29 100644 --- a/src/main/kotlin/moe/nea/firmament/keybindings/SavedKeyBinding.kt +++ b/src/main/kotlin/moe/nea/firmament/keybindings/SavedKeyBinding.kt @@ -10,6 +10,7 @@ import org.lwjgl.glfw.GLFW import kotlinx.serialization.Serializable import net.minecraft.client.MinecraftClient import net.minecraft.client.util.InputUtil +import net.minecraft.text.Text import moe.nea.firmament.util.MC @Serializable @@ -87,4 +88,20 @@ data class SavedKeyBinding( return keyCode == this.keyCode && getMods(modifiers) == Triple(shift, ctrl, alt) } + fun format(): Text { + val stroke = Text.literal("") + if (ctrl) { + stroke.append("CTRL + ") + } + if (alt) { + stroke.append("ALT + ") + } + if (shift) { + stroke.append("SHIFT + ") // TODO: translations? + } + + stroke.append(InputUtil.Type.KEYSYM.createFromCode(keyCode).localizedText) + return stroke + } + } |