From fc88e54a2e88c87bcfd5e7dbd6866764faa3e503 Mon Sep 17 00:00:00 2001 From: Linnea Gräf Date: Tue, 12 Nov 2024 21:38:31 +0100 Subject: feat: Add descriptions for config options --- .../moulconfig/java/MCConfigEditorIntegration.kt | 51 +++++++++++++++++++++- .../moulconfig/java/ProcessedCategoryFirm.kt | 2 +- .../moulconfig/java/ProcessedEditableOptionFirm.kt | 2 +- src/compat/yacl/java/YaclIntegration.kt | 2 + 4 files changed, 54 insertions(+), 3 deletions(-) (limited to 'src/compat') diff --git a/src/compat/moulconfig/java/MCConfigEditorIntegration.kt b/src/compat/moulconfig/java/MCConfigEditorIntegration.kt index 7686beb..f1e7a98 100644 --- a/src/compat/moulconfig/java/MCConfigEditorIntegration.kt +++ b/src/compat/moulconfig/java/MCConfigEditorIntegration.kt @@ -2,7 +2,10 @@ package moe.nea.firmament.compat.moulconfig import com.google.auto.service.AutoService import io.github.notenoughupdates.moulconfig.Config +import io.github.notenoughupdates.moulconfig.DescriptionRendereringBehaviour +import io.github.notenoughupdates.moulconfig.Social import io.github.notenoughupdates.moulconfig.common.IMinecraft +import io.github.notenoughupdates.moulconfig.common.MyResourceLocation import io.github.notenoughupdates.moulconfig.gui.GuiComponent import io.github.notenoughupdates.moulconfig.gui.GuiElementWrapper import io.github.notenoughupdates.moulconfig.gui.GuiOptionEditor @@ -22,10 +25,14 @@ import io.github.notenoughupdates.moulconfig.observer.GetSetter import io.github.notenoughupdates.moulconfig.processor.ProcessedCategory import io.github.notenoughupdates.moulconfig.processor.ProcessedOption import java.lang.reflect.Type +import java.net.URI import kotlin.time.Duration import kotlin.time.Duration.Companion.seconds import kotlin.time.DurationUnit import net.minecraft.client.gui.screen.Screen +import net.minecraft.util.Identifier +import net.minecraft.util.Util +import moe.nea.firmament.Firmament import moe.nea.firmament.gui.config.BooleanHandler import moe.nea.firmament.gui.config.ClickHandler import moe.nea.firmament.gui.config.DurationHandler @@ -37,6 +44,7 @@ import moe.nea.firmament.gui.config.KeyBindingHandler import moe.nea.firmament.gui.config.ManagedConfig import moe.nea.firmament.gui.config.ManagedOption import moe.nea.firmament.gui.config.StringHandler +import moe.nea.firmament.gui.toMoulConfig import moe.nea.firmament.keybindings.SavedKeyBinding import moe.nea.firmament.util.ErrorUtil import moe.nea.firmament.util.FirmFormatters @@ -287,6 +295,47 @@ class MCConfigEditorIntegration : FirmamentConfigScreenProvider { override fun shouldAutoFocusSearchbar(): Boolean { return true } + + override fun getTitle(): String { + return "Firmament" + } + + @Deprecated("Deprecated in java") + override fun executeRunnable(runnableId: Int) { + if (runnableId >= 0) + ErrorUtil.softError("Executed runnable $runnableId") + } + + override fun getDescriptionBehaviour(option: ProcessedOption?): DescriptionRendereringBehaviour { + return DescriptionRendereringBehaviour.EXPAND_PANEL + } + + fun mkSocial(name: String, identifier: Identifier, link: String) = object : Social() { + override fun onClick() { + Util.getOperatingSystem().open(URI(link)) + } + + override fun getTooltip(): List { + return listOf(name) + } + + override fun getIcon(): MyResourceLocation { + return identifier.toMoulConfig() + } + } + + private val socials = listOf( + mkSocial("Discord", Firmament.identifier("textures/socials/discord.png"), + Firmament.modContainer.metadata.contact.get("discord").get()), + mkSocial("Source Code", Firmament.identifier("textures/socials/git.png"), + Firmament.modContainer.metadata.contact.get("sources").get()), + mkSocial("Modrinth", Firmament.identifier("textures/socials/modrinth.png"), + Firmament.modContainer.metadata.contact.get("modrinth").get()), + ) + + override fun getSocials(): List { + return socials + } } val categories = ManagedConfig.Category.entries.map { val options = mutableListOf() @@ -295,7 +344,7 @@ class MCConfigEditorIntegration : FirmamentConfigScreenProvider { val categoryAccordionId = nextAccordionId++ options.add(object : ProcessedOptionFirm(-1, configObject) { override fun getDebugDeclarationLocation(): String { - return "FirmamentConfig:$config.name" + return "FirmamentConfig:${config.name}" } override fun getName(): String { diff --git a/src/compat/moulconfig/java/ProcessedCategoryFirm.kt b/src/compat/moulconfig/java/ProcessedCategoryFirm.kt index 19e1112..5313441 100644 --- a/src/compat/moulconfig/java/ProcessedCategoryFirm.kt +++ b/src/compat/moulconfig/java/ProcessedCategoryFirm.kt @@ -26,7 +26,7 @@ class ProcessedCategoryFirm( } override fun getDescription(): String { - return "Missing description" // TODO: add description + return category.description.string } override fun getIdentifier(): String { diff --git a/src/compat/moulconfig/java/ProcessedEditableOptionFirm.kt b/src/compat/moulconfig/java/ProcessedEditableOptionFirm.kt index c42ad3f..2bc5cd4 100644 --- a/src/compat/moulconfig/java/ProcessedEditableOptionFirm.kt +++ b/src/compat/moulconfig/java/ProcessedEditableOptionFirm.kt @@ -18,7 +18,7 @@ abstract class ProcessedEditableOptionFirm( } override fun getDescription(): String { - return "Missing description" // TODO: add description + return managedOption.labelDescription.string } override fun explicitNotifyChange() { diff --git a/src/compat/yacl/java/YaclIntegration.kt b/src/compat/yacl/java/YaclIntegration.kt index 239d3a0..9aec501 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.OptionDescription import dev.isxander.yacl3.api.OptionGroup import dev.isxander.yacl3.api.YetAnotherConfigLib import dev.isxander.yacl3.api.controller.ControllerBuilder @@ -69,6 +70,7 @@ class YaclIntegration : FirmamentConfigScreenProvider { fun createDefaultBinding(function: (Option) -> ControllerBuilder): Option.Builder { return Option.createBuilder() .name(managedOption.labelText) + .description(OptionDescription.of(managedOption.labelDescription)) .binding(binding as Binding) .controller { function(it) } } -- cgit