diff options
author | Linnea Gräf <nea@nea.moe> | 2025-06-04 18:45:39 +0200 |
---|---|---|
committer | Linnea Gräf <nea@nea.moe> | 2025-06-04 18:45:39 +0200 |
commit | 3695589a47c7434f4c5abbe2ebead052c0d07ba6 (patch) | |
tree | a42301bac4000cd1f4f6a10d16dfb5a779f12d97 /src/main/kotlin/gui/config/KeyBindingStateManager.kt | |
parent | 9c32c6e824058181002b0518e7e12c3425715b4b (diff) | |
download | Firmament-3695589a47c7434f4c5abbe2ebead052c0d07ba6.tar.gz Firmament-3695589a47c7434f4c5abbe2ebead052c0d07ba6.tar.bz2 Firmament-3695589a47c7434f4c5abbe2ebead052c0d07ba6.zip |
feat: Add macro editing UI
Diffstat (limited to 'src/main/kotlin/gui/config/KeyBindingStateManager.kt')
-rw-r--r-- | src/main/kotlin/gui/config/KeyBindingStateManager.kt | 44 |
1 files changed, 41 insertions, 3 deletions
diff --git a/src/main/kotlin/gui/config/KeyBindingStateManager.kt b/src/main/kotlin/gui/config/KeyBindingStateManager.kt index cc8178d..1528ac4 100644 --- a/src/main/kotlin/gui/config/KeyBindingStateManager.kt +++ b/src/main/kotlin/gui/config/KeyBindingStateManager.kt @@ -1,8 +1,15 @@ package moe.nea.firmament.gui.config +import io.github.notenoughupdates.moulconfig.common.IMinecraft +import io.github.notenoughupdates.moulconfig.common.MyResourceLocation +import io.github.notenoughupdates.moulconfig.deps.libninepatch.NinePatch +import io.github.notenoughupdates.moulconfig.gui.GuiImmediateContext +import io.github.notenoughupdates.moulconfig.gui.KeyboardEvent +import io.github.notenoughupdates.moulconfig.gui.component.TextComponent import org.lwjgl.glfw.GLFW import net.minecraft.text.Text import net.minecraft.util.Formatting +import moe.nea.firmament.gui.FirmButtonComponent import moe.nea.firmament.keybindings.SavedKeyBinding class KeyBindingStateManager( @@ -51,9 +58,11 @@ class KeyBindingStateManager( ) { lastPressed = ch } else { - setValue(SavedKeyBinding( - ch, modifiers - )) + setValue( + SavedKeyBinding( + ch, modifiers + ) + ) editing = false blur() lastPressed = 0 @@ -104,5 +113,34 @@ class KeyBindingStateManager( label = stroke } + fun createButton(): FirmButtonComponent { + return object : FirmButtonComponent( + TextComponent( + IMinecraft.instance.defaultFontRenderer, + { this@KeyBindingStateManager.label.string }, + 130, + TextComponent.TextAlignment.LEFT, + false, + false + ), action = { + this@KeyBindingStateManager.onClick() + }) { + override fun keyboardEvent(event: KeyboardEvent, context: GuiImmediateContext): Boolean { + if (event is KeyboardEvent.KeyPressed) { + return this@KeyBindingStateManager.keyboardEvent(event.keycode, event.pressed) + } + return super.keyboardEvent(event, context) + } + + override fun getBackground(context: GuiImmediateContext): NinePatch<MyResourceLocation> { + if (this@KeyBindingStateManager.editing) return activeBg + return super.getBackground(context) + } + + override fun onLostFocus() { + this@KeyBindingStateManager.onLostFocus() + } + } + } } |