diff options
author | Linnea Gräf <nea@nea.moe> | 2024-12-22 16:08:31 +0100 |
---|---|---|
committer | Linnea Gräf <nea@nea.moe> | 2024-12-22 16:08:31 +0100 |
commit | 856f5e0e815c8ef3be77ef342e1b0ca91aab8b0a (patch) | |
tree | 4584afffa853e882fe3440a6e7f481d15f5ea5e7 /src/compat/yacl/java/YaclIntegration.kt | |
parent | a9a801048d694e5b250f3a23089075e9b7bd976c (diff) | |
download | Firmament-856f5e0e815c8ef3be77ef342e1b0ca91aab8b0a.tar.gz Firmament-856f5e0e815c8ef3be77ef342e1b0ca91aab8b0a.tar.bz2 Firmament-856f5e0e815c8ef3be77ef342e1b0ca91aab8b0a.zip |
fix: Add choice options to YACL integration
Diffstat (limited to 'src/compat/yacl/java/YaclIntegration.kt')
-rw-r--r-- | src/compat/yacl/java/YaclIntegration.kt | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/compat/yacl/java/YaclIntegration.kt b/src/compat/yacl/java/YaclIntegration.kt index 9aec501..45a0d02 100644 --- a/src/compat/yacl/java/YaclIntegration.kt +++ b/src/compat/yacl/java/YaclIntegration.kt @@ -11,9 +11,11 @@ import dev.isxander.yacl3.api.OptionGroup import dev.isxander.yacl3.api.YetAnotherConfigLib import dev.isxander.yacl3.api.controller.ControllerBuilder import dev.isxander.yacl3.api.controller.DoubleSliderControllerBuilder +import dev.isxander.yacl3.api.controller.EnumControllerBuilder 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.api.controller.ValueFormatter import dev.isxander.yacl3.gui.YACLScreen import dev.isxander.yacl3.gui.tab.ListHolderWidget import kotlin.time.Duration @@ -23,8 +25,10 @@ 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 +import moe.nea.firmament.gui.config.ChoiceHandler import moe.nea.firmament.gui.config.ClickHandler import moe.nea.firmament.gui.config.DurationHandler +import moe.nea.firmament.gui.config.EnumRenderer import moe.nea.firmament.gui.config.FirmamentConfigScreenProvider import moe.nea.firmament.gui.config.HudMeta import moe.nea.firmament.gui.config.HudMetaHandler @@ -89,6 +93,10 @@ class YaclIntegration : FirmamentConfigScreenProvider { } .build() + is ChoiceHandler<*> -> return createDefaultBinding { + createChoiceBinding(handler as ChoiceHandler<*>, managedOption as ManagedOption<*>, it as Option<*>) + }.build() + is BooleanHandler -> return createDefaultBinding(TickBoxControllerBuilder::create).build() is StringHandler -> return createDefaultBinding(StringControllerBuilder::create).build() is IntegerHandler -> return createDefaultBinding { @@ -114,6 +122,27 @@ class YaclIntegration : FirmamentConfigScreenProvider { } } + private enum class Sacrifice {} + + private fun createChoiceBinding( + handler: ChoiceHandler<*>, + managedOption: ManagedOption<*>, + option: Option<*> + ): ControllerBuilder<Any> { + val b = EnumControllerBuilder.create(option as Option<Sacrifice>) + b.enumClass(handler.enumClass as Class<Sacrifice>) + /** + * This is a function with E to avoid realizing the Sacrifice outside of a `X<E>` wrapper. + */ + fun <E : Enum<*>> makeValueFormatter(): ValueFormatter<E> { + return ValueFormatter<E> { + (handler.renderer as EnumRenderer<E>).getName(managedOption as ManagedOption<E>, it) + } + } + b.formatValue(makeValueFormatter()) + return b as ControllerBuilder<Any> + } + fun buildConfig(): YetAnotherConfigLib { return YetAnotherConfigLib.createBuilder() |