diff --git a/build.gradle b/build.gradle index cfe18bb..8c79b22 100644 --- a/build.gradle +++ b/build.gradle @@ -13,6 +13,7 @@ group = project.maven_group repositories { maven { url = "https://maven.shedaniel.me/" } maven { url = "https://maven.terraformersmc.com/releases/" } + maven { url = "https://maven.isxander.dev/releases/" } } dependencies { @@ -30,6 +31,12 @@ dependencies { modApi("me.shedaniel.cloth:cloth-config-fabric:${project.cloth_config_version}") { exclude(group: "net.fabricmc.fabric-api") } + + modApi("dev.isxander.yacl:yet-another-config-lib-fabric:${project.yacl_config_version}") { + exclude(group: "org.quiltmc.parsers") + exclude(group: "com.twelvemonkeys.common") + exclude(group: "com.twelvemonkeys.imageio") + } } def includeFabricApiModule(String moduleName) { @@ -98,6 +105,7 @@ modrinth { dependencies { optional.project "modmenu" optional.project "cloth-config" + optional.project "yacl" } } @@ -121,6 +129,7 @@ curseforge { relations { optionalDependency "modmenu" optionalDependency "cloth-config" + optionalDependency "yacl" } } diff --git a/gradle.properties b/gradle.properties index fffc129..483c9e1 100644 --- a/gradle.properties +++ b/gradle.properties @@ -15,6 +15,7 @@ org.gradle.jvmargs=-Xmx2G # Dependencies # https://linkie.shedaniel.dev/ - fabric_version=0.89.0+1.20.2 - modmenu_version=8.0.0-beta.2 + fabric_version=0.89.2+1.20.2 + modmenu_version=8.0.0 cloth_config_version=12.0.107 + yacl_config_version=3.2.0+1.20.2 diff --git a/src/main/java/io/grayray75/mods/fpsdisplay/config/ModMenuIntegration.java b/src/main/java/io/grayray75/mods/fpsdisplay/config/ModMenuIntegration.java index 6a9acac..481e93a 100644 --- a/src/main/java/io/grayray75/mods/fpsdisplay/config/ModMenuIntegration.java +++ b/src/main/java/io/grayray75/mods/fpsdisplay/config/ModMenuIntegration.java @@ -4,12 +4,16 @@ import com.terraformersmc.modmenu.api.ModMenuApi; import io.grayray75.mods.fpsdisplay.gui.ClothOptionScreen; import io.grayray75.mods.fpsdisplay.gui.FallbackOptionScreen; +import io.grayray75.mods.fpsdisplay.gui.YaclOptionScreen; import net.fabricmc.loader.api.FabricLoader; public class ModMenuIntegration implements ModMenuApi { @Override public ConfigScreenFactory getModConfigScreenFactory() { - if (FabricLoader.getInstance().isModLoaded("cloth-config")) { + if (FabricLoader.getInstance().isModLoaded("yet_another_config_lib_v3")) { + return parent -> YaclOptionScreen.generateScreen(parent); + } + else if (FabricLoader.getInstance().isModLoaded("cloth-config")) { return parent -> ClothOptionScreen.generateScreen(parent); } else { diff --git a/src/main/java/io/grayray75/mods/fpsdisplay/gui/YaclOptionScreen.java b/src/main/java/io/grayray75/mods/fpsdisplay/gui/YaclOptionScreen.java new file mode 100644 index 0000000..5ecda3c --- /dev/null +++ b/src/main/java/io/grayray75/mods/fpsdisplay/gui/YaclOptionScreen.java @@ -0,0 +1,92 @@ +package io.grayray75.mods.fpsdisplay.gui; + +import dev.isxander.yacl3.api.ConfigCategory; +import dev.isxander.yacl3.api.Option; +import dev.isxander.yacl3.api.YetAnotherConfigLib; +import dev.isxander.yacl3.api.controller.*; +import io.grayray75.mods.fpsdisplay.config.ConfigData; +import io.grayray75.mods.fpsdisplay.config.ConfigManager; +import net.minecraft.client.gui.screen.Screen; +import net.minecraft.text.Text; + +import java.awt.Color; + +// https://docs.isxander.dev/yet-another-config-lib/ + +public class YaclOptionScreen { + public static Screen generateScreen(Screen parent) { + ConfigCategory.Builder categoryBuilder = ConfigCategory.createBuilder(); + categoryBuilder.name(Text.translatable("text.fpsdisplay.options.title")); + + final ConfigData configDefaults = new ConfigData(); + ConfigData config = ConfigManager.getConfig(); + + categoryBuilder.option(Option.createBuilder() + .name(Text.translatable("text.fpsdisplay.options.enabled")) + .binding(configDefaults.enabled, () -> config.enabled, newValue -> config.enabled = newValue) + .controller(YaclOptionScreen::createBooleanController) + .build() + ); + categoryBuilder.option(Option.createBuilder() + .name(Text.translatable("text.fpsdisplay.options.advancedStats")) + .binding(configDefaults.advancedStats, () -> config.advancedStats, newValue -> config.advancedStats = newValue) + .controller(YaclOptionScreen::createBooleanController) + .build() + ); + + categoryBuilder.option(Option.createBuilder() + .name(Text.translatable("text.fpsdisplay.options.textSize")) + .binding(configDefaults.textSize, () -> config.textSize, newValue -> config.textSize = newValue) + .controller(option -> FloatSliderControllerBuilder.create(option).range(0.1f, 3.0f).step(0.1f)) + .build() + ); + categoryBuilder.option(Option.createBuilder() + .name(Text.translatable("text.fpsdisplay.options.textColor")) + .binding(new Color(configDefaults.textColor), () -> new Color(config.textColor), newValue -> config.textColor = newValue.getRGB()) + .controller(option -> ColorControllerBuilder.create(option).allowAlpha(false)) + .build() + ); + categoryBuilder.option(Option.createBuilder() + .name(Text.translatable("text.fpsdisplay.options.textAlpha")) + .binding(configDefaults.textAlpha, () -> config.textAlpha, newValue -> config.textAlpha = newValue) + .controller(option -> IntegerSliderControllerBuilder.create(option).range(0, 255).step(1)) + .build() + ); + categoryBuilder.option(Option.createBuilder() + .name(Text.translatable("text.fpsdisplay.options.textShadows")) + .binding(configDefaults.textShadows, () -> config.textShadows, newValue -> config.textShadows = newValue) + .controller(YaclOptionScreen::createBooleanController) + .build() + ); + + categoryBuilder.option(Option.createBuilder() + .name(Text.translatable("text.fpsdisplay.options.offsetTop")) + .binding(configDefaults.offsetTop, () -> config.offsetTop, newValue -> config.offsetTop = newValue) + .controller(IntegerFieldControllerBuilder::create) + .build() + ); + categoryBuilder.option(Option.createBuilder() + .name(Text.translatable("text.fpsdisplay.options.textAlpha")) + .binding(configDefaults.offsetLeft, () -> config.offsetLeft, newValue -> config.offsetLeft = newValue) + .controller(IntegerFieldControllerBuilder::create) + .build() + ); + + categoryBuilder.option(Option.createBuilder() + .name(Text.translatable("text.fpsdisplay.options.keybindMode")) + .binding(configDefaults.keybindMode, () -> config.keybindMode, newValue -> config.keybindMode = newValue) + .controller(option -> EnumControllerBuilder.create(option).enumClass(ConfigData.KeyMode.class)) + .build() + ); + + YetAnotherConfigLib.Builder builder = YetAnotherConfigLib.createBuilder(); + builder.title(Text.translatable("text.fpsdisplay.options.title")); + builder.category(categoryBuilder.build()); + builder.save(() -> ConfigManager.saveConfig()); + return builder.build().generateScreen(parent); + } + + private static BooleanControllerBuilder createBooleanController(Option option) { + return BooleanControllerBuilder.create(option).yesNoFormatter().coloured(true); + } +} diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 234632a..7d3cc23 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -39,6 +39,7 @@ }, "suggests": { "cloth-config": "*", - "modmenu": "*" + "modmenu": "*", + "yet_another_config_lib_v3": "*" } }