From 4e9b0ded27df8b6ce7f5b2fa1b4b1ddbc1cbd452 Mon Sep 17 00:00:00 2001 From: Linnea Gräf Date: Sun, 13 Oct 2024 21:46:46 +0200 Subject: Add config categories --- src/compat/yacl/java/YaclIntegration.kt | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'src/compat/yacl') diff --git a/src/compat/yacl/java/YaclIntegration.kt b/src/compat/yacl/java/YaclIntegration.kt index 6c9354a..fc5ff59 100644 --- a/src/compat/yacl/java/YaclIntegration.kt +++ b/src/compat/yacl/java/YaclIntegration.kt @@ -6,6 +6,7 @@ import dev.isxander.yacl3.api.ButtonOption import dev.isxander.yacl3.api.ConfigCategory import dev.isxander.yacl3.api.LabelOption import dev.isxander.yacl3.api.Option +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 @@ -17,7 +18,6 @@ import kotlin.time.Duration.Companion.seconds import kotlin.time.DurationUnit import net.minecraft.client.gui.screen.Screen import net.minecraft.text.Text -import moe.nea.firmament.gui.config.AllConfigsGui import moe.nea.firmament.gui.config.BooleanHandler import moe.nea.firmament.gui.config.ClickHandler import moe.nea.firmament.gui.config.DurationHandler @@ -36,15 +36,20 @@ import moe.nea.firmament.util.FirmFormatters @AutoService(FirmamentConfigScreenProvider::class) class YaclIntegration : FirmamentConfigScreenProvider { fun buildCategories() = - AllConfigsGui.allConfigs + ManagedConfig.Category.entries .map(::buildCategory) - private fun buildCategory(managedConfig: ManagedConfig): ConfigCategory { + private fun buildCategory(category: ManagedConfig.Category): ConfigCategory { return ConfigCategory.createBuilder() - .name(managedConfig.labelText) - .also { - it.rootGroupBuilder() - .options(buildOptions(managedConfig.sortedOptions)) + .name(category.labelText) + .also { categoryB -> + category.configs.forEach { + categoryB.group( + OptionGroup.createBuilder() + .name(it.labelText) + .options(buildOptions(it.sortedOptions)) + .build()) + } } .build() } @@ -54,7 +59,10 @@ class YaclIntegration : FirmamentConfigScreenProvider { private fun buildOption(managedOption: ManagedOption): Option<*> { val handler = managedOption.handler - val binding = Binding.generic(managedOption.default(), managedOption::value, managedOption::value.setter) + val binding = Binding.generic(managedOption.default(), + managedOption::value, + { managedOption.value = it; managedOption.element.save() }) + fun createDefaultBinding(function: (Option) -> ControllerBuilder): Option.Builder { return Option.createBuilder() .name(managedOption.labelText) -- cgit