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,25 +96,27 @@ class MCConfigEditorIntegration : FirmamentConfigScreenProvider {
val mappedSetter = setter.xmap(fromT, toT)
private val delegateI by lazy {
wrapComponent(RowComponent(
AlignComponent(
TextComponent(
IMinecraft.instance.defaultFontRenderer,
{ formatter(setter.get()) },
25,
TextComponent.TextAlignment.CENTER, false, false
wrapComponent(
RowComponent(
AlignComponent(
TextComponent(
IMinecraft.instance.defaultFontRenderer,
{ formatter(setter.get()) },
25,
TextComponent.TextAlignment.CENTER, false, false
),
GetSetter.constant(HorizontalAlign.CENTER),
GetSetter.constant(VerticalAlign.CENTER)
),
GetSetter.constant(HorizontalAlign.CENTER),
GetSetter.constant(VerticalAlign.CENTER)
),
SliderComponent(
mappedSetter,
fromT(minValue),
fromT(maxValue),
minStep,
40
SliderComponent(
mappedSetter,
fromT(minValue),
fromT(maxValue),
minStep,
40
)
)
))
)
}
}
@@ -302,100 +304,109 @@ class MCConfigEditorIntegration : FirmamentConfigScreenProvider {
}
}
override fun open(parent: Screen?): Screen {
val configObject = object : Config() {
override fun saveNow() {
ManagedConfig.allManagedConfigs.getAll().forEach { it.save() }
val configObject = object : Config() {
override fun saveNow() {
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 {
return true
override fun getTooltip(): List<String> {
return listOf(name)
}
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 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
override fun getIcon(): MyResourceLocation {
return identifier.toMoulConfig()
}
}
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
}
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 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 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 {
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)
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 {