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/main/kotlin/gui/config/AllConfigsGui.kt | 46 +++++++++++++++++++++++------ 1 file changed, 37 insertions(+), 9 deletions(-) (limited to 'src/main/kotlin/gui/config/AllConfigsGui.kt') diff --git a/src/main/kotlin/gui/config/AllConfigsGui.kt b/src/main/kotlin/gui/config/AllConfigsGui.kt index c72b8b0..0e68bc8 100644 --- a/src/main/kotlin/gui/config/AllConfigsGui.kt +++ b/src/main/kotlin/gui/config/AllConfigsGui.kt @@ -4,24 +4,35 @@ import io.github.notenoughupdates.moulconfig.observer.ObservableList import io.github.notenoughupdates.moulconfig.xml.Bind import net.minecraft.client.gui.screen.Screen import net.minecraft.text.Text -import moe.nea.firmament.features.FeatureManager import moe.nea.firmament.repo.RepoManager import moe.nea.firmament.util.MC import moe.nea.firmament.util.MoulConfigUtils import moe.nea.firmament.util.ScreenUtil.setScreenLater object AllConfigsGui { +// +// val allConfigs +// get() = listOf( +// RepoManager.Config +// ) + FeatureManager.allFeatures.mapNotNull { it.config } - val allConfigs - get() = listOf( - RepoManager.Config - ) + FeatureManager.allFeatures.mapNotNull { it.config } + object ConfigConfig : ManagedConfig("configconfig", Category.META) { + val enableYacl by toggle("enable-yacl") { false } + } fun List.toObservableList(): ObservableList = ObservableList(this) - class MainMapping(val allConfigs: List) { + class CategoryMapping(val category: ManagedConfig.Category) { @get:Bind("configs") - val configs = allConfigs.map { EntryMapping(it) }.toObservableList() + val configs = category.configs.map { EntryMapping(it) }.toObservableList() + + @Bind + fun name() = category.labelText.string + + @Bind + fun close() { + MC.screen?.close() + } class EntryMapping(val config: ManagedConfig) { @Bind @@ -34,12 +45,29 @@ object AllConfigsGui { } } + class CategoryView { + @get:Bind("categories") + val categories = ManagedConfig.Category.entries + .map { CategoryEntry(it) } + .toObservableList() + + class CategoryEntry(val category: ManagedConfig.Category) { + @Bind + fun name() = category.labelText.string + + @Bind + fun open() { + MC.screen = MoulConfigUtils.loadScreen("config/category", CategoryMapping(category), MC.screen) + } + } + } + fun makeBuiltInScreen(parent: Screen? = null): Screen { - return MoulConfigUtils.loadScreen("config/main", MainMapping(allConfigs), parent) + return MoulConfigUtils.loadScreen("config/main", CategoryView(), parent) } fun makeScreen(parent: Screen? = null): Screen { - val wantedKey = if (RepoManager.Config.enableYacl) "yacl" else "builtin" + val wantedKey = if (ConfigConfig.enableYacl) "yacl" else "builtin" val provider = FirmamentConfigScreenProvider.providers.find { it.key == wantedKey } ?: FirmamentConfigScreenProvider.providers.first() return provider.open(parent) -- cgit