-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
111 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
src/main/java/io/grayray75/mods/fpsdisplay/gui/YaclOptionScreen.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,7 @@ | |
}, | ||
"suggests": { | ||
"cloth-config": "*", | ||
"modmenu": "*" | ||
"modmenu": "*", | ||
"yet_another_config_lib_v3": "*" | ||
} | ||
} |