diff options
author | nea <nea@nea.moe> | 2023-08-24 02:34:10 +0200 |
---|---|---|
committer | nea <nea@nea.moe> | 2023-08-24 02:34:10 +0200 |
commit | 8186643dfc0d5cab0369c736d0765e5e3f864c12 (patch) | |
tree | 607c56f3bce98bfa625440998ff1c95affe7e526 /src/main/kotlin/io | |
parent | afd676b9377b336ab3d0eafc6b37190001b69414 (diff) | |
download | NotEnoughUpdates-8186643dfc0d5cab0369c736d0765e5e3f864c12.tar.gz NotEnoughUpdates-8186643dfc0d5cab0369c736d0765e5e3f864c12.tar.bz2 NotEnoughUpdates-8186643dfc0d5cab0369c736d0765e5e3f864c12.zip |
Moul Config
Diffstat (limited to 'src/main/kotlin/io')
3 files changed, 123 insertions, 34 deletions
diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.kt index 3c45d1e1..b318a80e 100644 --- a/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.kt +++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.kt @@ -23,7 +23,6 @@ import com.mojang.brigadier.arguments.StringArgumentType import io.github.moulberry.notenoughupdates.BuildFlags import io.github.moulberry.notenoughupdates.NotEnoughUpdates import io.github.moulberry.notenoughupdates.autosubscribe.NEUAutoSubscribe -import io.github.moulberry.notenoughupdates.core.config.GuiPositionEditor import io.github.moulberry.notenoughupdates.core.util.MiscUtils import io.github.moulberry.notenoughupdates.events.RegisterBrigadierCommandEvent import io.github.moulberry.notenoughupdates.miscfeatures.FishingHelper @@ -189,9 +188,6 @@ class DevTestCommand { ) ) }.withHelp("Display information about the special block zone at your cursor (Custom Texture Regions)") - thenLiteralExecute("positiontest") { - NotEnoughUpdates.INSTANCE.openGui = GuiPositionEditor() - }.withHelp("Open the gui position editor") thenLiteral("pt") { thenArgument("particle", EnumArgumentType.enum<EnumParticleTypes>()) { particle -> thenExecute { diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/help/SettingsCommand.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/help/SettingsCommand.kt index fe58c807..eb5d51b1 100644 --- a/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/help/SettingsCommand.kt +++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/help/SettingsCommand.kt @@ -19,35 +19,119 @@ package io.github.moulberry.notenoughupdates.commands.help +import io.github.moulberry.moulconfig.GuiTextures +import io.github.moulberry.moulconfig.annotations.ConfigOption +import io.github.moulberry.moulconfig.gui.GuiOptionEditor +import io.github.moulberry.moulconfig.gui.GuiScreenElementWrapper +import io.github.moulberry.moulconfig.gui.MoulConfigEditor +import io.github.moulberry.moulconfig.processor.* import io.github.moulberry.notenoughupdates.NotEnoughUpdates import io.github.moulberry.notenoughupdates.autosubscribe.NEUAutoSubscribe -import io.github.moulberry.notenoughupdates.core.GuiScreenElementWrapper -import io.github.moulberry.notenoughupdates.core.config.struct.ConfigProcessor +import io.github.moulberry.notenoughupdates.core.config.GuiOptionEditorBlocked import io.github.moulberry.notenoughupdates.events.RegisterBrigadierCommandEvent -import io.github.moulberry.notenoughupdates.options.NEUConfigEditor +import io.github.moulberry.notenoughupdates.miscfeatures.EnforcedConfigValues +import io.github.moulberry.notenoughupdates.miscfeatures.IQTest +import io.github.moulberry.notenoughupdates.options.NEUConfig import io.github.moulberry.notenoughupdates.util.brigadier.* +import net.minecraft.client.gui.GuiScreen +import net.minecraft.util.ResourceLocation import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import java.lang.reflect.Field @NEUAutoSubscribe -class SettingsCommand { +object SettingsCommand { @SubscribeEvent fun onCommands(event: RegisterBrigadierCommandEvent) { event.command("neu", "neusettings") { thenArgument("search", RestArgumentType) { search -> - suggestsList(ConfigProcessor.create(NotEnoughUpdates.INSTANCE.config).keys.toList()) + val searchSpace = mutableListOf<String>() + ConfigProcessorDriver.processConfig( + NotEnoughUpdates.INSTANCE.config.javaClass, + NotEnoughUpdates.INSTANCE.config, + object : ConfigStructureReader { + override fun beginCategory(p0: Any?, p1: Field?, p2: String, p3: String) { + searchSpace.add(p2) + searchSpace.add(p3) + } + + override fun endCategory() { + } + + override fun beginAccordion(p0: Any?, p1: Field?, p2: ConfigOption, p3: Int) { + searchSpace.add(p2.name) + searchSpace.add(p2.desc) + } + + override fun endAccordion() { + } + + override fun emitOption(p0: Any?, p1: Field?, p2: ConfigOption) { + searchSpace.add(p2.name) + searchSpace.add(p2.desc) + } + + override fun emitGuiOverlay(p0: Any?, p1: Field?, p2: ConfigOption?) { + } + + } + ) + suggestsList(searchSpace) thenExecute { - NotEnoughUpdates.INSTANCE.openGui = GuiScreenElementWrapper( - NEUConfigEditor( - NotEnoughUpdates.INSTANCE.config, - this[search] - ) - ) + NotEnoughUpdates.INSTANCE.openGui = createConfigScreen(this[search]) } }.withHelp("Search the NEU settings") thenExecute { - NotEnoughUpdates.INSTANCE.openGui = - GuiScreenElementWrapper(NEUConfigEditor(NotEnoughUpdates.INSTANCE.config)) + NotEnoughUpdates.INSTANCE.openGui = createConfigScreen("") } }.withHelp("Open the NEU settings") } + + class BlockingMoulConfigProcessor : MoulConfigProcessor<NEUConfig>(NotEnoughUpdates.INSTANCE.config) { + override fun createOptionGui( + processedOption: ProcessedOption, + field: Field, + option: ConfigOption + ): GuiOptionEditor? { + val default = super.createOptionGui(processedOption, field, option) ?: return null + if (EnforcedConfigValues.isBlockedFromEditing(processedOption.path)) { + return GuiOptionEditorBlocked(default) + } + return default + } + + var iqTestCopy: LinkedHashMap<String, ProcessedCategory>? = null + override fun getAllCategories(): LinkedHashMap<String, ProcessedCategory> { + val s = super.getAllCategories() + if (iqTestCopy == null) { + iqTestCopy = s.clone() as LinkedHashMap<String, ProcessedCategory> + } + iqTestCopy!!["apiData"] = IQTest.options + if (NotEnoughUpdates.INSTANCE.config.apiData.apiDataUnlocked) { + return s + } + return iqTestCopy!! + } + } + + var lastEditor = null as MoulConfigEditor<NEUConfig>? + fun createConfigScreen(search: String): GuiScreen { + return object : GuiScreenElementWrapper(createConfigElement(search)) { + } + } + fun createConfigElement(search: String): MoulConfigEditor<NEUConfig> { + val processor = BlockingMoulConfigProcessor() + BuiltinMoulConfigGuis.addProcessors(processor) + ConfigProcessorDriver.processConfig( + NotEnoughUpdates.INSTANCE.config.javaClass, + NotEnoughUpdates.INSTANCE.config, + processor + ) + val editor = MoulConfigEditor(processor) + editor.search(search) + lastEditor = editor + return editor + } + init { + GuiTextures.setTextureRoot(ResourceLocation("notenoughupdates:core")) + } } diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/miscfeatures/IQTest.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/miscfeatures/IQTest.kt index 157050b3..8817dac1 100644 --- a/src/main/kotlin/io/github/moulberry/notenoughupdates/miscfeatures/IQTest.kt +++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/miscfeatures/IQTest.kt @@ -19,11 +19,13 @@ package io.github.moulberry.notenoughupdates.miscfeatures +import io.github.moulberry.moulconfig.gui.editors.GuiOptionEditorButton +import io.github.moulberry.moulconfig.gui.editors.GuiOptionEditorInfoText +import io.github.moulberry.moulconfig.gui.editors.GuiOptionEditorText +import io.github.moulberry.moulconfig.processor.ProcessedCategory +import io.github.moulberry.moulconfig.processor.ProcessedOption import io.github.moulberry.notenoughupdates.NotEnoughUpdates -import io.github.moulberry.notenoughupdates.core.config.gui.GuiOptionEditorButton -import io.github.moulberry.notenoughupdates.core.config.gui.GuiOptionEditorFSR -import io.github.moulberry.notenoughupdates.core.config.gui.GuiOptionEditorText -import io.github.moulberry.notenoughupdates.core.config.struct.ConfigProcessor.ProcessedOption +import io.github.moulberry.notenoughupdates.commands.help.SettingsCommand import io.github.moulberry.notenoughupdates.util.Calculator import io.github.moulberry.notenoughupdates.util.Calculator.CalculatorException import java.math.BigDecimal @@ -40,6 +42,7 @@ object IQTest { Calculator.calculate(answer) } catch (e: CalculatorException) { wrongAnswer() + SettingsCommand.lastEditor?.updateSearchResults() return } val realAnswer = Calculator.calculate(question) @@ -49,6 +52,7 @@ object IQTest { } else { wrongAnswer() } + SettingsCommand.lastEditor?.updateSearchResults() } private fun wrongAnswer() { @@ -64,46 +68,51 @@ object IQTest { @JvmField var answer = "" + val cat = ProcessedCategory(javaClass.getField("answer"), "IQ Test", "IQ Test") val answerOption = ProcessedOption( "IQ Test Question", "Please type out the answer to §a$question", - -1, + "", javaClass.getField("answer"), + cat, this, - arrayOf() + NotEnoughUpdates.INSTANCE.config ).also { it.editor = GuiOptionEditorText(it) } val warningOption = ProcessedOption( "§4§lWARNING", "§4§lThis page is dangerous. Please make sure you know what you are doing!", - -1, + "", javaClass.getField("buttonPlaceHolder"), + cat, this, - arrayOf() + NotEnoughUpdates.INSTANCE.config ).also { it.editor = GuiOptionEditorButton(it, 27, "SUBMIT", NotEnoughUpdates.INSTANCE.config) } val wrongOption = ProcessedOption( "§4Wrong Answer", "§4Please think twice before accessing it.", - -1, + "", javaClass.getField("buttonPlaceHolder"), + cat, this, - arrayOf() + NotEnoughUpdates.INSTANCE.config ).also { - it.editor = GuiOptionEditorFSR(it, -1, "", NotEnoughUpdates.INSTANCE.config) + it.editor = GuiOptionEditorInfoText(it, "") } @get:JvmStatic - val options - get() = LinkedHashMap<String, ProcessedOption>().also { - it["iqTestAnswer"] = answerOption - it["iqTestSubmit"] = warningOption - + val options: ProcessedCategory + get() { + cat.options.clear() if (System.currentTimeMillis() - lastAnsweredTimestamp < 10_000L) { - it["iqTestWrong"] = wrongOption + cat.options.addAll(listOf(answerOption, warningOption, wrongOption)) + } else { + cat.options.addAll(listOf(answerOption, warningOption)) } + return cat } } |