From 865b14117981a8c39abc0e359fe738df5a503610 Mon Sep 17 00:00:00 2001 From: LucHeart Date: Sun, 25 Feb 2024 00:55:38 +0100 Subject: [PATCH] Add config shockers and options --- .../minecraft/ConfigGuiFactory.kt | 123 ++++++++++++++++++ .../minecraft/ModMenuEntryFactory.kt | 37 ------ .../{ModMenuEntry.kt => ModMenuEntryPoint.kt} | 4 +- .../minecraft/ShockCraftConfig.kt | 12 +- src/main/resources/fabric.mod.json | 4 +- 5 files changed, 139 insertions(+), 41 deletions(-) create mode 100644 src/main/kotlin/openshock/integrations/minecraft/ConfigGuiFactory.kt delete mode 100644 src/main/kotlin/openshock/integrations/minecraft/ModMenuEntryFactory.kt rename src/main/kotlin/openshock/integrations/minecraft/{ModMenuEntry.kt => ModMenuEntryPoint.kt} (76%) diff --git a/src/main/kotlin/openshock/integrations/minecraft/ConfigGuiFactory.kt b/src/main/kotlin/openshock/integrations/minecraft/ConfigGuiFactory.kt new file mode 100644 index 0000000..829e3d4 --- /dev/null +++ b/src/main/kotlin/openshock/integrations/minecraft/ConfigGuiFactory.kt @@ -0,0 +1,123 @@ +package openshock.integrations.minecraft + +import com.terraformersmc.modmenu.api.ConfigScreenFactory +import dev.isxander.yacl3.api.ConfigCategory +import dev.isxander.yacl3.api.ListOption +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.IntegerSliderControllerBuilder +import dev.isxander.yacl3.api.controller.StringControllerBuilder +import dev.isxander.yacl3.gui.controllers.slider.FloatSliderController +import dev.isxander.yacl3.gui.controllers.slider.IntegerSliderController +import net.minecraft.client.MinecraftClient +import net.minecraft.client.gui.screen.Screen +import net.minecraft.text.Text + +object ConfigGuiFactory : ConfigScreenFactory { + + override fun create(parent: Screen): Screen { + val yacl = + YetAnotherConfigLib.create(ShockCraftConfig.HANDLER) { defaults: ShockCraftConfig, config: ShockCraftConfig, builder: YetAnotherConfigLib.Builder -> + createBuilder( + defaults, + config, + builder + ) + } + + return yacl.generateScreen(MinecraftClient.getInstance().currentScreen) + } + + fun createBuilder( + defaults: ShockCraftConfig, + config: ShockCraftConfig, + builder: YetAnotherConfigLib.Builder + ): YetAnotherConfigLib.Builder { + return builder + .title(Text.literal("OpenShock")) + + + .category( + ConfigCategory.createBuilder() + .name(Text.literal("ShockCraft - OpenShock Config")) + + // Server group + .group(OptionGroup.createBuilder() + .name(Text.literal("Server")) + .description(OptionDescription.of(Text.literal("Server / OpenShock Backend Settings"))) + .option( + Option.createBuilder() + .name(Text.literal("API URL")) + .description(OptionDescription.of(Text.literal("The API base URL of the OpenShock Backend. For the official instance this is https://api.openshock.org"))) + .controller { option: Option? -> StringControllerBuilder.create(option) } + .binding( + defaults.apiBaseUrl, + { config.apiBaseUrl }, + { newVal: String -> config.apiBaseUrl = newVal }) + .build() + ) + .option( + Option.createBuilder() + .name(Text.literal("API Token")) + .description(OptionDescription.of(Text.literal("API Token generated on the web, needs shocker use permission"))) + .controller { option: Option -> StringControllerBuilder.create(option) } + .binding( + defaults.apiToken, + { config.apiToken }, + { newVal: String -> config.apiToken = newVal }) + .build() + ).build() + ) + + // Shocker group + .group(OptionGroup.createBuilder() + .name(Text.literal("Shocking Options")) + + .option(Option.createBuilder() + .name(Text.literal("Minimum Intensity")) + .controller { option: Option -> + IntegerSliderControllerBuilder.create(option) + .range(1, 100) + .step(1).formatValue { it -> Text.literal("$it minimum") } + } + .binding( + defaults.intensityMin, + { config.intensityMin }, + { newVal: Int -> config.intensityMin = newVal }) + .build() + ) + + + .option(Option.createBuilder() + .name(Text.literal("Maximum Intensity")) + .controller { option: Option -> + IntegerSliderControllerBuilder.create(option) + .range(1, 100) + .step(1).formatValue { it -> Text.literal("$it maximum") } + } + .binding( + defaults.intensityMax, + { config.intensityMax }, + { newVal: Int -> config.intensityMax = newVal }) + .build() + ) + .build() + ) + + .group(ListOption.createBuilder() + .name(Text.literal("Shockers")) + .controller { option: Option -> StringControllerBuilder.create(option) } + .binding( + defaults.shockers, + { config.shockers }, + { newVal: List -> config.shockers = newVal }) + .initial("Put your Shocker ID here") + .build() + ) + + .build() + ) + } +} diff --git a/src/main/kotlin/openshock/integrations/minecraft/ModMenuEntryFactory.kt b/src/main/kotlin/openshock/integrations/minecraft/ModMenuEntryFactory.kt deleted file mode 100644 index d21a88c..0000000 --- a/src/main/kotlin/openshock/integrations/minecraft/ModMenuEntryFactory.kt +++ /dev/null @@ -1,37 +0,0 @@ -package openshock.integrations.minecraft - -import com.terraformersmc.modmenu.api.ConfigScreenFactory -import dev.isxander.yacl3.api.ConfigCategory -import dev.isxander.yacl3.api.Option -import dev.isxander.yacl3.api.YetAnotherConfigLib -import dev.isxander.yacl3.api.controller.StringControllerBuilder -import net.minecraft.client.MinecraftClient -import net.minecraft.client.gui.screen.Screen -import net.minecraft.text.Text - -object ModMenuEntryFactory : ConfigScreenFactory { - - override fun create(parent: Screen): Screen { - val yacl = YetAnotherConfigLib.create(ShockCraftConfig.HANDLER) { - defaults: ShockCraftConfig, config: ShockCraftConfig, builder: YetAnotherConfigLib.Builder -> createBuilder(defaults, config, builder) } - - return yacl.generateScreen(MinecraftClient.getInstance().currentScreen) - } - - fun createBuilder(defaults: ShockCraftConfig, config: ShockCraftConfig, builder: YetAnotherConfigLib.Builder): YetAnotherConfigLib.Builder { - return builder - .title(Text.literal("OpenShock")) - .category( - ConfigCategory.createBuilder() - .name(Text.literal("Server")) - .option( - Option.createBuilder() - .name(Text.literal("API Url")) - .controller { option: Option? -> StringControllerBuilder.create(option) } - .binding(defaults.apiBaseUrl, { config.apiBaseUrl }, { newVal: String -> config.apiBaseUrl = newVal }) - .build() - ) - .build() - ) - } -} diff --git a/src/main/kotlin/openshock/integrations/minecraft/ModMenuEntry.kt b/src/main/kotlin/openshock/integrations/minecraft/ModMenuEntryPoint.kt similarity index 76% rename from src/main/kotlin/openshock/integrations/minecraft/ModMenuEntry.kt rename to src/main/kotlin/openshock/integrations/minecraft/ModMenuEntryPoint.kt index de2074f..ae44ece 100644 --- a/src/main/kotlin/openshock/integrations/minecraft/ModMenuEntry.kt +++ b/src/main/kotlin/openshock/integrations/minecraft/ModMenuEntryPoint.kt @@ -3,8 +3,8 @@ package openshock.integrations.minecraft import com.terraformersmc.modmenu.api.ConfigScreenFactory import com.terraformersmc.modmenu.api.ModMenuApi -class ModMenuEntry : ModMenuApi { +class ModMenuEntryPoint : ModMenuApi { override fun getModConfigScreenFactory(): ConfigScreenFactory<*> { - return ModMenuEntryFactory + return ConfigGuiFactory } } \ No newline at end of file diff --git a/src/main/kotlin/openshock/integrations/minecraft/ShockCraftConfig.kt b/src/main/kotlin/openshock/integrations/minecraft/ShockCraftConfig.kt index 3081ce1..8e5f5fa 100644 --- a/src/main/kotlin/openshock/integrations/minecraft/ShockCraftConfig.kt +++ b/src/main/kotlin/openshock/integrations/minecraft/ShockCraftConfig.kt @@ -16,12 +16,22 @@ class ShockCraftConfig { @SerialEntry(comment = "API Token generated on the web") var apiToken: String = "" + @SerialEntry(comment = "Intensity Min") + var intensityMin: Int = 0; + + @SerialEntry(comment = "Intensity Max") + var intensityMax: Int = 100; + + + @SerialEntry(comment = "Shockers to use") + var shockers: List = ArrayList() + companion object { var HANDLER: ConfigClassHandler = ConfigClassHandler.createBuilder(ShockCraftConfig::class.java) .id(Identifier("shockcraft", "config")) .serializer { config: ConfigClassHandler? -> GsonConfigSerializerBuilder.create(config) - .setPath(FabricLoader.getInstance().getConfigDir().resolve("ShockCraft.json5")) + .setPath(FabricLoader.getInstance().configDir.resolve("ShockCraft.json5")) .appendGsonBuilder(GsonBuilder::setPrettyPrinting) // not needed, pretty print by default .setJson5(true) .build() diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 75e2e7e..f544ab2 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -23,7 +23,9 @@ "adapter": "kotlin" } ], - "modmenu": [ "openshock.integrations.minecraft.ModMenuEntry" ] + "modmenu": [ + "openshock.integrations.minecraft.ModMenuEntryPoint" + ] }, "mixins": [ "shockcraft.mixins.json"