feat: Add /firm search command

This commit is contained in:
Linnea Gräf
2025-07-01 14:27:43 +02:00
parent e9a4ce5575
commit 6980170dbd
6 changed files with 137 additions and 107 deletions

View File

@@ -6,6 +6,6 @@ import moe.nea.firmament.gui.config.AllConfigsGui
class FirmamentModMenuPlugin : ModMenuApi { class FirmamentModMenuPlugin : ModMenuApi {
override fun getModConfigScreenFactory(): ConfigScreenFactory<*> { override fun getModConfigScreenFactory(): ConfigScreenFactory<*> {
return ConfigScreenFactory { AllConfigsGui.makeScreen(it) } return ConfigScreenFactory { AllConfigsGui.makeScreen(parent = it) }
} }
} }

View File

@@ -96,25 +96,27 @@ class MCConfigEditorIntegration : FirmamentConfigScreenProvider {
val mappedSetter = setter.xmap(fromT, toT) val mappedSetter = setter.xmap(fromT, toT)
private val delegateI by lazy { private val delegateI by lazy {
wrapComponent(RowComponent( wrapComponent(
AlignComponent( RowComponent(
TextComponent( AlignComponent(
IMinecraft.instance.defaultFontRenderer, TextComponent(
{ formatter(setter.get()) }, IMinecraft.instance.defaultFontRenderer,
25, { formatter(setter.get()) },
TextComponent.TextAlignment.CENTER, false, false 25,
TextComponent.TextAlignment.CENTER, false, false
),
GetSetter.constant(HorizontalAlign.CENTER),
GetSetter.constant(VerticalAlign.CENTER)
), ),
GetSetter.constant(HorizontalAlign.CENTER), SliderComponent(
GetSetter.constant(VerticalAlign.CENTER) mappedSetter,
), fromT(minValue),
SliderComponent( fromT(maxValue),
mappedSetter, minStep,
fromT(minValue), 40
fromT(maxValue), )
minStep,
40
) )
)) )
} }
} }
@@ -302,100 +304,109 @@ class MCConfigEditorIntegration : FirmamentConfigScreenProvider {
} }
} }
override fun open(parent: Screen?): Screen { val configObject = object : Config() {
val configObject = object : Config() { override fun saveNow() {
override fun saveNow() { ManagedConfig.allManagedConfigs.getAll().forEach { it.save() }
ManagedConfig.allManagedConfigs.getAll().forEach { it.save() } }
override fun shouldAutoFocusSearchbar(): Boolean {
return true
}
override fun getTitle(): String {
return "Firmament ${Firmament.version.friendlyString}"
}
@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 shouldAutoFocusSearchbar(): Boolean { override fun getTooltip(): List<String> {
return true return listOf(name)
} }
override fun getTitle(): String { override fun getIcon(): MyResourceLocation {
return "Firmament ${Firmament.version.friendlyString}" return identifier.toMoulConfig()
}
@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<String> {
return listOf(name)
}
override fun getIcon(): MyResourceLocation {
return identifier.toMoulConfig()
}
}
private val socials = listOf<Social>(
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<Social> {
return socials
} }
} }
val categories = ManagedConfig.Category.entries.map {
val options = mutableListOf<ProcessedOptionFirm>()
var nextAccordionId = 720
it.configs.forEach { config ->
val categoryAccordionId = nextAccordionId++
options.add(object : ProcessedOptionFirm(-1, configObject) {
override fun getDebugDeclarationLocation(): String {
return "FirmamentConfig:${config.name}"
}
override fun getName(): String { private val socials = listOf<Social>(
return config.labelText.string 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 getDescription(): String { override fun getSocials(): List<Social> {
return "Missing description" return socials
}
override fun get(): Any {
return Unit
}
override fun getType(): Type {
return Unit.javaClass
}
override fun set(value: Any?): Boolean {
return false
}
override fun createEditor(): GuiOptionEditor {
return GuiOptionEditorAccordion(this, categoryAccordionId)
}
})
config.allOptions.forEach { (key, option) ->
val processedOption = getHandler(option, categoryAccordionId, configObject)
options.add(processedOption)
}
}
return@map ProcessedCategoryFirm(it, options)
} }
}
val categories = ManagedConfig.Category.entries.map {
val options = mutableListOf<ProcessedOptionFirm>()
var nextAccordionId = 720
it.configs.forEach { config ->
val categoryAccordionId = nextAccordionId++
options.add(object : ProcessedOptionFirm(-1, configObject) {
override fun getDebugDeclarationLocation(): String {
return "FirmamentConfig:${config.name}"
}
override fun getName(): String {
return config.labelText.string
}
override fun getDescription(): String {
return "Missing description"
}
override fun get(): Any {
return Unit
}
override fun getType(): Type {
return Unit.javaClass
}
override fun set(value: Any?): Boolean {
return false
}
override fun createEditor(): GuiOptionEditor {
return GuiOptionEditorAccordion(this, categoryAccordionId)
}
})
config.allOptions.forEach { (key, option) ->
val processedOption = getHandler(option, categoryAccordionId, configObject)
options.add(processedOption)
}
}
return@map ProcessedCategoryFirm(it, options)
}
override fun open(search: String?, parent: Screen?): Screen {
val editor = MoulConfigEditor(ProcessedCategory.collect(categories), configObject) val editor = MoulConfigEditor(ProcessedCategory.collect(categories), configObject)
if (search != null)
editor.search(search)
return GuiElementWrapper(editor) // TODO : add parent support return GuiElementWrapper(editor) // TODO : add parent support
} }

View File

@@ -154,7 +154,7 @@ class YaclIntegration : FirmamentConfigScreenProvider {
override val key: String override val key: String
get() = "yacl" get() = "yacl"
override fun open(parent: Screen?): Screen { override fun open(search: String?, parent: Screen?): Screen {
return object : YACLScreen(buildConfig(), parent) { return object : YACLScreen(buildConfig(), parent) {
override fun setFocused(focused: Element?) { override fun setFocused(focused: Element?) {
if (this.focused is KeybindingWidget && if (this.focused is KeybindingWidget &&

View File

@@ -4,6 +4,12 @@ import io.github.notenoughupdates.moulconfig.observer.ObservableList
import io.github.notenoughupdates.moulconfig.xml.Bind import io.github.notenoughupdates.moulconfig.xml.Bind
import net.minecraft.client.gui.screen.Screen import net.minecraft.client.gui.screen.Screen
import net.minecraft.text.Text import net.minecraft.text.Text
import moe.nea.firmament.annotations.Subscribe
import moe.nea.firmament.commands.RestArgumentType
import moe.nea.firmament.commands.get
import moe.nea.firmament.commands.thenArgument
import moe.nea.firmament.commands.thenExecute
import moe.nea.firmament.events.CommandEvent
import moe.nea.firmament.util.MC import moe.nea.firmament.util.MC
import moe.nea.firmament.util.MoulConfigUtils import moe.nea.firmament.util.MoulConfigUtils
import moe.nea.firmament.util.ScreenUtil.setScreenLater import moe.nea.firmament.util.ScreenUtil.setScreenLater
@@ -66,7 +72,7 @@ object AllConfigsGui {
return MoulConfigUtils.loadScreen("config/main", CategoryView(), parent) return MoulConfigUtils.loadScreen("config/main", CategoryView(), parent)
} }
fun makeScreen(parent: Screen? = null): Screen { fun makeScreen(search: String? = null, parent: Screen? = null): Screen {
val wantedKey = when { val wantedKey = when {
ConfigConfig.enableMoulConfig -> "moulconfig" ConfigConfig.enableMoulConfig -> "moulconfig"
ConfigConfig.enableYacl -> "yacl" ConfigConfig.enableYacl -> "yacl"
@@ -74,10 +80,23 @@ object AllConfigsGui {
} }
val provider = FirmamentConfigScreenProvider.providers.find { it.key == wantedKey } val provider = FirmamentConfigScreenProvider.providers.find { it.key == wantedKey }
?: FirmamentConfigScreenProvider.providers.first() ?: FirmamentConfigScreenProvider.providers.first()
return provider.open(parent) return provider.open(search, parent)
} }
fun showAllGuis() { fun showAllGuis() {
setScreenLater(makeScreen()) setScreenLater(makeScreen())
} }
@Subscribe
fun registerCommands(event: CommandEvent.SubCommand) {
event.subcommand("search") {
thenArgument("search", RestArgumentType) { search ->
thenExecute {
val search = this[search]
setScreenLater(makeScreen(search = search))
}
}
}
}
} }

View File

@@ -8,7 +8,7 @@ class BuiltInConfigScreenProvider : FirmamentConfigScreenProvider {
override val key: String override val key: String
get() = "builtin" get() = "builtin"
override fun open(parent: Screen?): Screen { override fun open(search: String?, parent: Screen?): Screen {
return AllConfigsGui.makeBuiltInScreen(parent) return AllConfigsGui.makeBuiltInScreen(parent)
} }
} }

View File

@@ -7,7 +7,7 @@ interface FirmamentConfigScreenProvider {
val key: String val key: String
val isEnabled: Boolean get() = true val isEnabled: Boolean get() = true
fun open(parent: Screen?): Screen fun open(search: String?, parent: Screen?): Screen
companion object : CompatLoader<FirmamentConfigScreenProvider>(FirmamentConfigScreenProvider::class) { companion object : CompatLoader<FirmamentConfigScreenProvider>(FirmamentConfigScreenProvider::class) {
val providers by lazy { val providers by lazy {