Skip to content

Commit

Permalink
Add YACL settings screen
Browse files Browse the repository at this point in the history
  • Loading branch information
Grayray75 committed Sep 27, 2023
1 parent b70994b commit e11af83
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 4 deletions.
9 changes: 9 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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) {
Expand Down Expand Up @@ -98,6 +105,7 @@ modrinth {
dependencies {
optional.project "modmenu"
optional.project "cloth-config"
optional.project "yacl"
}
}

Expand All @@ -121,6 +129,7 @@ curseforge {
relations {
optionalDependency "modmenu"
optionalDependency "cloth-config"
optionalDependency "yacl"
}
}

Expand Down
5 changes: 3 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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.<Boolean>createBuilder()
.name(Text.translatable("text.fpsdisplay.options.enabled"))
.binding(configDefaults.enabled, () -> config.enabled, newValue -> config.enabled = newValue)
.controller(YaclOptionScreen::createBooleanController)
.build()
);
categoryBuilder.option(Option.<Boolean>createBuilder()
.name(Text.translatable("text.fpsdisplay.options.advancedStats"))
.binding(configDefaults.advancedStats, () -> config.advancedStats, newValue -> config.advancedStats = newValue)
.controller(YaclOptionScreen::createBooleanController)
.build()
);

categoryBuilder.option(Option.<Float>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.<Color>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.<Integer>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.<Boolean>createBuilder()
.name(Text.translatable("text.fpsdisplay.options.textShadows"))
.binding(configDefaults.textShadows, () -> config.textShadows, newValue -> config.textShadows = newValue)
.controller(YaclOptionScreen::createBooleanController)
.build()
);

categoryBuilder.option(Option.<Integer>createBuilder()
.name(Text.translatable("text.fpsdisplay.options.offsetTop"))
.binding(configDefaults.offsetTop, () -> config.offsetTop, newValue -> config.offsetTop = newValue)
.controller(IntegerFieldControllerBuilder::create)
.build()
);
categoryBuilder.option(Option.<Integer>createBuilder()
.name(Text.translatable("text.fpsdisplay.options.textAlpha"))
.binding(configDefaults.offsetLeft, () -> config.offsetLeft, newValue -> config.offsetLeft = newValue)
.controller(IntegerFieldControllerBuilder::create)
.build()
);

categoryBuilder.option(Option.<ConfigData.KeyMode>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<Boolean> option) {
return BooleanControllerBuilder.create(option).yesNoFormatter().coloured(true);
}
}
3 changes: 2 additions & 1 deletion src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
},
"suggests": {
"cloth-config": "*",
"modmenu": "*"
"modmenu": "*",
"yet_another_config_lib_v3": "*"
}
}

0 comments on commit e11af83

Please sign in to comment.