aboutsummaryrefslogtreecommitdiff
path: root/src/compat
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2024-10-18 21:01:13 +0200
committerLinnea Gräf <nea@nea.moe>2024-10-18 21:01:13 +0200
commit6100b8c9a0fe42be52a759b429f532c12cc72a32 (patch)
tree347482e31b95491266a06a12bf478f3983bbd282 /src/compat
parentc42bfa6151e5c63ca5bbd74e9a4ce0e7119a8539 (diff)
downloadFirmament-6100b8c9a0fe42be52a759b429f532c12cc72a32.tar.gz
Firmament-6100b8c9a0fe42be52a759b429f532c12cc72a32.tar.bz2
Firmament-6100b8c9a0fe42be52a759b429f532c12cc72a32.zip
Hack Fix YACL unbinding keys
Diffstat (limited to 'src/compat')
-rw-r--r--src/compat/yacl/java/KeybindingController.kt70
-rw-r--r--src/compat/yacl/java/YaclIntegration.kt21
2 files changed, 61 insertions, 30 deletions
diff --git a/src/compat/yacl/java/KeybindingController.kt b/src/compat/yacl/java/KeybindingController.kt
index 6be9dd1..204d521 100644
--- a/src/compat/yacl/java/KeybindingController.kt
+++ b/src/compat/yacl/java/KeybindingController.kt
@@ -31,41 +31,53 @@ class KeybindingController(
{ option.pendingValue() },
{ option.requestSet(it) },
{ screen.focused = null },
- { screen.focused = button }
+ { screen.focused = button },
)
- button = object : ControllerWidget<KeybindingController>(this, screen, widgetDimension) {
- override fun getHoveredControlWidth(): Int {
- return 130
- }
+ button = KeybindingWidget(sm, this, screen, widgetDimension)
+ option.addListener { t, u ->
+ sm.updateLabel()
+ }
+ sm.updateLabel()
+ return button
+ }
+}
+
+class KeybindingWidget(
+ val sm: KeyBindingStateManager,
+ controller: KeybindingController,
+ screen: YACLScreen,
+ dimension: Dimension<Int>
+) : ControllerWidget<KeybindingController>(controller, screen, dimension) {
+ override fun getHoveredControlWidth(): Int {
+ return 130
+ }
+
+ override fun getValueText(): Text {
+ return sm.label
+ }
- override fun getValueText(): Text {
- return sm.label
- }
+ override fun keyPressed(keyCode: Int, scanCode: Int, modifiers: Int): Boolean {
+ return sm.keyboardEvent(keyCode, true)
+ }
- override fun keyPressed(keyCode: Int, scanCode: Int, modifiers: Int): Boolean {
- return sm.keyboardEvent(keyCode, true)
- }
+ override fun keyReleased(keyCode: Int, scanCode: Int, modifiers: Int): Boolean {
+ return sm.keyboardEvent(keyCode, false)
+ }
- override fun keyReleased(keyCode: Int, scanCode: Int, modifiers: Int): Boolean {
- return sm.keyboardEvent(keyCode, false)
- }
+ override fun unfocus() {
+ sm.onLostFocus()
+ }
- override fun unfocus() {
- sm.onLostFocus()
- }
+ override fun setFocused(focused: Boolean) {
+ super.setFocused(focused)
+ if (!focused) sm.onLostFocus()
+ }
- override fun mouseClicked(mouseX: Double, mouseY: Double, button: Int): Boolean {
- if (button == 0 && isHovered) {
- sm.onClick()
- return true
- }
- return super.mouseClicked(mouseX, mouseY, button)
- }
+ override fun mouseClicked(mouseX: Double, mouseY: Double, button: Int): Boolean {
+ if (button == 0 && isHovered) {
+ sm.onClick()
+ return true
}
- option.addListener { t, u ->
- sm.updateLabel()
- }
- sm.updateLabel()
- return button
+ return super.mouseClicked(mouseX, mouseY, button)
}
}
diff --git a/src/compat/yacl/java/YaclIntegration.kt b/src/compat/yacl/java/YaclIntegration.kt
index fc5ff59..239d3a0 100644
--- a/src/compat/yacl/java/YaclIntegration.kt
+++ b/src/compat/yacl/java/YaclIntegration.kt
@@ -13,9 +13,12 @@ import dev.isxander.yacl3.api.controller.DoubleSliderControllerBuilder
import dev.isxander.yacl3.api.controller.IntegerSliderControllerBuilder
import dev.isxander.yacl3.api.controller.StringControllerBuilder
import dev.isxander.yacl3.api.controller.TickBoxControllerBuilder
+import dev.isxander.yacl3.gui.YACLScreen
+import dev.isxander.yacl3.gui.tab.ListHolderWidget
import kotlin.time.Duration
import kotlin.time.Duration.Companion.seconds
import kotlin.time.DurationUnit
+import net.minecraft.client.gui.Element
import net.minecraft.client.gui.screen.Screen
import net.minecraft.text.Text
import moe.nea.firmament.gui.config.BooleanHandler
@@ -121,7 +124,23 @@ class YaclIntegration : FirmamentConfigScreenProvider {
get() = "yacl"
override fun open(parent: Screen?): Screen {
- return buildConfig().generateScreen(parent)
+ return object : YACLScreen(buildConfig(), parent) {
+ override fun setFocused(focused: Element?) {
+ if (this.focused is KeybindingWidget &&
+ focused is ListHolderWidget<*>
+ ) {
+ return
+ }
+ super.setFocused(focused)
+ }
+
+ override fun shouldCloseOnEsc(): Boolean {
+ if (focused is KeybindingWidget) {
+ return false
+ }
+ return super.shouldCloseOnEsc()
+ }
+ }
}
}