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 {
override fun getModConfigScreenFactory(): ConfigScreenFactory<*> {
return ConfigScreenFactory { AllConfigsGui.makeScreen(it) }
return ConfigScreenFactory { AllConfigsGui.makeScreen(parent = it) }
}
}

View File

@@ -96,7 +96,8 @@ class MCConfigEditorIntegration : FirmamentConfigScreenProvider {
val mappedSetter = setter.xmap(fromT, toT)
private val delegateI by lazy {
wrapComponent(RowComponent(
wrapComponent(
RowComponent(
AlignComponent(
TextComponent(
IMinecraft.instance.defaultFontRenderer,
@@ -114,7 +115,8 @@ class MCConfigEditorIntegration : FirmamentConfigScreenProvider {
minStep,
40
)
))
)
)
}
}
@@ -302,7 +304,6 @@ class MCConfigEditorIntegration : FirmamentConfigScreenProvider {
}
}
override fun open(parent: Screen?): Screen {
val configObject = object : Config() {
override fun saveNow() {
ManagedConfig.allManagedConfigs.getAll().forEach { it.save() }
@@ -341,12 +342,18 @@ class MCConfigEditorIntegration : FirmamentConfigScreenProvider {
}
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()),
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> {
@@ -395,7 +402,11 @@ class MCConfigEditorIntegration : FirmamentConfigScreenProvider {
return@map ProcessedCategoryFirm(it, options)
}
override fun open(search: String?, parent: Screen?): Screen {
val editor = MoulConfigEditor(ProcessedCategory.collect(categories), configObject)
if (search != null)
editor.search(search)
return GuiElementWrapper(editor) // TODO : add parent support
}

View File

@@ -154,7 +154,7 @@ class YaclIntegration : FirmamentConfigScreenProvider {
override val key: String
get() = "yacl"
override fun open(parent: Screen?): Screen {
override fun open(search: String?, parent: Screen?): Screen {
return object : YACLScreen(buildConfig(), parent) {
override fun setFocused(focused: Element?) {
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 net.minecraft.client.gui.screen.Screen
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.MoulConfigUtils
import moe.nea.firmament.util.ScreenUtil.setScreenLater
@@ -66,7 +72,7 @@ object AllConfigsGui {
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 {
ConfigConfig.enableMoulConfig -> "moulconfig"
ConfigConfig.enableYacl -> "yacl"
@@ -74,10 +80,23 @@ object AllConfigsGui {
}
val provider = FirmamentConfigScreenProvider.providers.find { it.key == wantedKey }
?: FirmamentConfigScreenProvider.providers.first()
return provider.open(parent)
return provider.open(search, parent)
}
fun showAllGuis() {
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
get() = "builtin"
override fun open(parent: Screen?): Screen {
override fun open(search: String?, parent: Screen?): Screen {
return AllConfigsGui.makeBuiltInScreen(parent)
}
}

View File

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