From 04fe933f4c24817100f3101f088accf55a621f8a Mon Sep 17 00:00:00 2001 From: isxander Date: Thu, 11 Apr 2024 18:43:06 +0100 Subject: Extremely fragile and broken multiversion build with stonecutter --- .../dev/isxander/yacl3/test/AutogenConfigTest.java | 130 ++++++ .../java/dev/isxander/yacl3/test/ConfigTest.java | 78 ++++ .../java/dev/isxander/yacl3/test/Entrypoint.java | 23 ++ .../java/dev/isxander/yacl3/test/GuiTest.java | 453 +++++++++++++++++++++ .../yacl3/test/mixin/TitleScreenMixin.java | 25 ++ 5 files changed, 709 insertions(+) create mode 100644 src/testmod/java/dev/isxander/yacl3/test/AutogenConfigTest.java create mode 100644 src/testmod/java/dev/isxander/yacl3/test/ConfigTest.java create mode 100644 src/testmod/java/dev/isxander/yacl3/test/Entrypoint.java create mode 100644 src/testmod/java/dev/isxander/yacl3/test/GuiTest.java create mode 100644 src/testmod/java/dev/isxander/yacl3/test/mixin/TitleScreenMixin.java (limited to 'src/testmod/java/dev/isxander') diff --git a/src/testmod/java/dev/isxander/yacl3/test/AutogenConfigTest.java b/src/testmod/java/dev/isxander/yacl3/test/AutogenConfigTest.java new file mode 100644 index 0000000..b3b49b6 --- /dev/null +++ b/src/testmod/java/dev/isxander/yacl3/test/AutogenConfigTest.java @@ -0,0 +1,130 @@ +package dev.isxander.yacl3.test; + +import com.google.common.collect.Lists; +import dev.isxander.yacl3.api.NameableEnum; +import dev.isxander.yacl3.api.Option; +import dev.isxander.yacl3.api.controller.ControllerBuilder; +import dev.isxander.yacl3.api.controller.StringControllerBuilder; +import dev.isxander.yacl3.config.v2.api.ConfigClassHandler; +import dev.isxander.yacl3.config.v2.api.ConfigField; +import dev.isxander.yacl3.config.v2.api.autogen.Boolean; +import dev.isxander.yacl3.config.v2.api.autogen.Label; +import dev.isxander.yacl3.config.v2.api.serializer.GsonConfigSerializerBuilder; +import dev.isxander.yacl3.config.v2.api.SerialEntry; +import dev.isxander.yacl3.config.v2.api.autogen.*; +import dev.isxander.yacl3.gui.ValueFormatters; +import dev.isxander.yacl3.platform.YACLPlatform; +import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.Items; + +import java.awt.*; +import java.util.List; + +public class AutogenConfigTest { + public static final ConfigClassHandler INSTANCE = ConfigClassHandler.createBuilder(AutogenConfigTest.class) + .id(new ResourceLocation("yacl3", "config")) + .serializer(config -> GsonConfigSerializerBuilder.create(config) + .setPath(YACLPlatform.getConfigDir().resolve("yacl-test-v2.json5")) + .setJson5(true) + .build()) + .build(); + + @AutoGen(category = "test", group = "master_test") + @MasterTickBox({ "testTickBox", "testBoolean", "testInt", "testDouble", "testFloat", "testLong", "testIntField", "testDoubleField", "testFloatField", "testLongField", "testEnum", "testColor", "testString", "testDropdown", "testItem" }) + @SerialEntry(comment = "This option disables all the other options in this group") + public boolean masterOption = true; + + @AutoGen(category = "test", group = "master_test") + @TickBox + @SerialEntry(comment = "This is a cool comment omg this is amazing") + public boolean testTickBox = true; + + @AutoGen(category = "test", group = "master_test") + @Boolean(formatter = Boolean.Formatter.YES_NO, colored = true) + @SerialEntry(comment = "This is a cool comment omg this is amazing") + public boolean testBoolean = true; + + @AutoGen(category = "test", group = "master_test") + @IntSlider(min = 0, max = 10, step = 2) + @SerialEntry public int testInt = 0; + + @AutoGen(category = "test", group = "master_test") + @DoubleSlider(min = 0.1, max = 10.2, step = 0.1) + @SerialEntry public double testDouble = 0.1; + + @AutoGen(category = "test", group = "master_test") + @FloatSlider(min = 0.0f, max = 1f, step = 0.01f) + @CustomFormat(ValueFormatters.PercentFormatter.class) + @CustomName("A cool percentage.") + @SerialEntry public float testFloat = 0.1f; + + @AutoGen(category = "test", group = "master_test") + @LongSlider(min = 0, max = 10, step = 2) + @SerialEntry public long testLong = 0; + + @AutoGen(category = "test", group = "master_test") + @IntField(min = 0, max = 10) + @SerialEntry public int testIntField = 0; + + @AutoGen(category = "test", group = "master_test") + @DoubleField(min = 0.1, max = 10.2) + @SerialEntry public double testDoubleField = 0.1; + + @AutoGen(category = "test", group = "master_test") + @FloatField(min = 0.1f, max = 10.2f) + @SerialEntry public float testFloatField = 0.1f; + + @AutoGen(category = "test", group = "master_test") + @LongField(min = 0, max = 10) + @SerialEntry public long testLongField = 0; + + @AutoGen(category = "test", group = "master_test") + @EnumCycler + @SerialEntry public Alphabet testEnum = Alphabet.A; + + @AutoGen(category = "test", group = "master_test") + @ColorField + @SerialEntry public Color testColor = new Color(0xFF0000FF, true); + + @AutoGen(category = "test", group = "master_test") + @StringField + @SerialEntry public String testString = "Test string"; + + @AutoGen(category = "test", group = "master_test") + @Dropdown(values = {"Apple", "Banana", "Cherry", "Date"}, allowAnyValue = true) + @SerialEntry public String testDropdown = "Cherry"; + + @AutoGen(category = "test", group = "master_test") + @ItemField + @SerialEntry public Item testItem = Items.AZURE_BLUET; + + @AutoGen(category = "test", group = "misc") @Label + private final Component testLabel = Component.literal("Test label"); + + @AutoGen(category = "test") + @ListGroup(valueFactory = TestListFactory.class, controllerFactory = TestListFactory.class) + @SerialEntry public List testList = Lists.newArrayList("A", "B"); + + public enum Alphabet implements NameableEnum { + A, B, C; + + @Override + public Component getDisplayName() { + return Component.literal(name()); + } + } + + public static class TestListFactory implements ListGroup.ValueFactory, ListGroup.ControllerFactory { + @Override + public String provideNewValue() { + return ""; + } + + @Override + public ControllerBuilder createController(ListGroup annotation, ConfigField> field, OptionAccess storage, Option option) { + return StringControllerBuilder.create(option); + } + } +} diff --git a/src/testmod/java/dev/isxander/yacl3/test/ConfigTest.java b/src/testmod/java/dev/isxander/yacl3/test/ConfigTest.java new file mode 100644 index 0000000..a8f49b0 --- /dev/null +++ b/src/testmod/java/dev/isxander/yacl3/test/ConfigTest.java @@ -0,0 +1,78 @@ +package dev.isxander.yacl3.test; + +import dev.isxander.yacl3.config.v2.api.ConfigClassHandler; +import dev.isxander.yacl3.config.v2.api.SerialEntry; +import dev.isxander.yacl3.config.v2.api.serializer.GsonConfigSerializerBuilder; +import dev.isxander.yacl3.platform.YACLPlatform; +import net.minecraft.ChatFormatting; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.Items; + +import java.awt.*; +import java.util.List; + +public class ConfigTest { + public static final ConfigClassHandler GSON = ConfigClassHandler.createBuilder(ConfigTest.class) + .serializer(config -> GsonConfigSerializerBuilder.create(config) + .setPath(YACLPlatform.getConfigDir().resolve("yacl-test.json")) + .build()) + .build(); + + @SerialEntry + public boolean booleanToggle = false; + @SerialEntry + public boolean customBooleanToggle = false; + @SerialEntry + public boolean tickbox = false; + @SerialEntry + public int intSlider = 0; + @SerialEntry + public double doubleSlider = 0; + @SerialEntry + public float floatSlider = 0; + @SerialEntry + public long longSlider = 0; + @SerialEntry + public String textField = "Hello"; + @SerialEntry + public Color colorOption = Color.red; + @SerialEntry + public double doubleField = 0.5; + @SerialEntry + public float floatField = 0.5f; + @SerialEntry + public int intField = 5; + @SerialEntry + public long longField = 5; + @SerialEntry + public Alphabet enumOption = Alphabet.A; + @SerialEntry + public String stringOptions = "Banana"; + @SerialEntry + public String stringSuggestions = ""; + @SerialEntry + public Item item = Items.OAK_LOG; + @SerialEntry + public ChatFormatting formattingOption = ChatFormatting.RED; + + @SerialEntry + public List stringList = List.of("This is quite cool.", "You can add multiple items!", "And it is integrated so well into Option groups!"); + @SerialEntry + public List intList = List.of(1, 2, 3); + + @SerialEntry + public boolean groupTestRoot = false; + @SerialEntry + public boolean groupTestFirstGroup = false; + @SerialEntry + public boolean groupTestFirstGroup2 = false; + @SerialEntry + public boolean groupTestSecondGroup = false; + + @SerialEntry + public int scrollingSlider = 0; + + public enum Alphabet { + A, B, C + } +} diff --git a/src/testmod/java/dev/isxander/yacl3/test/Entrypoint.java b/src/testmod/java/dev/isxander/yacl3/test/Entrypoint.java new file mode 100644 index 0000000..2c4875f --- /dev/null +++ b/src/testmod/java/dev/isxander/yacl3/test/Entrypoint.java @@ -0,0 +1,23 @@ +/*? if neoforge { *//* +package dev.isxander.yacl3.test; + +import net.neoforged.fml.common.Mod; + +@Mod("yacl_test") +public class Entrypoint { + public Entrypoint() { + + } +} +*//*?} elif forge {*//* +package dev.isxander.yacl3.test; + +import net.minecraftforge.fml.common.Mod; + +@Mod("yacl_test") +public class Entrypoint { + public Entrypoint() { + + } +} +*//*?}*/ diff --git a/src/testmod/java/dev/isxander/yacl3/test/GuiTest.java b/src/testmod/java/dev/isxander/yacl3/test/GuiTest.java new file mode 100644 index 0000000..473b04a --- /dev/null +++ b/src/testmod/java/dev/isxander/yacl3/test/GuiTest.java @@ -0,0 +1,453 @@ +package dev.isxander.yacl3.test; + +import dev.isxander.yacl3.api.*; +import dev.isxander.yacl3.api.controller.*; +import dev.isxander.yacl3.gui.RequireRestartScreen; +import dev.isxander.yacl3.gui.controllers.*; +import dev.isxander.yacl3.gui.controllers.cycling.EnumController; +import dev.isxander.yacl3.gui.controllers.slider.DoubleSliderController; +import dev.isxander.yacl3.gui.controllers.slider.FloatSliderController; +import dev.isxander.yacl3.gui.controllers.slider.IntegerSliderController; +import dev.isxander.yacl3.gui.controllers.slider.LongSliderController; +import dev.isxander.yacl3.gui.controllers.string.StringController; +import dev.isxander.yacl3.gui.controllers.string.number.DoubleFieldController; +import dev.isxander.yacl3.gui.controllers.string.number.FloatFieldController; +import dev.isxander.yacl3.gui.controllers.string.number.IntegerFieldController; +import dev.isxander.yacl3.gui.controllers.string.number.LongFieldController; +import net.minecraft.ChatFormatting; +import net.minecraft.Util; +import net.minecraft.client.GraphicsStatus; +import net.minecraft.client.Minecraft; +import net.minecraft.client.gui.components.toasts.SystemToast; +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.network.chat.ClickEvent; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.HoverEvent; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.Item; +import org.apache.commons.lang3.StringUtils; + +import java.awt.Color; +import java.nio.file.Path; +import java.util.List; +import java.util.concurrent.atomic.AtomicReference; + +public class GuiTest { + public static Screen getModConfigScreenFactory(Screen parent) { + return YetAnotherConfigLib.create(ConfigTest.GSON, (defaults, config, builder) -> builder + .title(Component.literal("Test Suites")) + .category(ConfigCategory.createBuilder() + .name(Component.literal("Suites")) + .option(ButtonOption.createBuilder() + .name(Component.literal("Full Test Suite")) + .action((screen, opt) -> Minecraft.getInstance().setScreen(getFullTestSuite(screen))) + .build()) + .option(ButtonOption.createBuilder() + .name(Component.literal("Auto-gen test")) + .action((screen, opt) -> { + AutogenConfigTest.INSTANCE.load(); + Minecraft.getInstance().setScreen(AutogenConfigTest.INSTANCE.generateGui().generateScreen(screen)); + }) + .build()) + .group(OptionGroup.createBuilder() + .name(Component.literal("Wiki")) + .option(ButtonOption.createBuilder() + .name(Component.literal("Get Started")) + .action((screen, opt) -> Minecraft.getInstance().setScreen(getWikiGetStarted(screen))) + .build()) + .build()) + .build()) + ) + .generateScreen(parent); + } + + private static Screen getFullTestSuite(Screen parent) { + AtomicReference> booleanOption = new AtomicReference<>(); + + ConfigTest.GSON.serializer().load(); + return YetAnotherConfigLib.create(ConfigTest.GSON, (defaults, config, builder) -> builder + .title(Component.literal("Test GUI")) + .category(ConfigCategory.createBuilder() + .name(Component.literal("Control Examples")) + .tooltip(Component.literal("Example Category Description")) + .group(OptionGroup.createBuilder() + .name(Component.literal("Boolean Controllers")) + .option(Util.make(() -> { + var opt = Option.createBuilder() + .name(Component.literal("Boolean Toggle")) + .description(OptionDescription.createBuilder() + .text(Component.empty() + .append(Component.literal("a").withStyle(style -> style.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Component.literal("a"))))) + .append(Component.literal("b").withStyle(style -> style.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Component.literal("b"))))) + .append(Component.literal("c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c").withStyle(style -> style.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Component.literal("c"))))) + .append(Component.literal("e").withStyle(style -> style.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Component.literal("e"))))) + .withStyle(style -> style.withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, "https://isxander.dev"))) + ) + .webpImage(new ResourceLocation("yacl3", "reach-around-placement.webp")) + .build()) + .binding( + defaults.booleanToggle, + () -> config.booleanToggle, + (value) -> config.booleanToggle = value + ) + .controller(BooleanControllerBuilder::create) + .flag(OptionFlag.GAME_RESTART) + .build(); + booleanOption.set(opt); + return opt; + })) + .option(Option.createBuilder() + .name(Component.literal("Custom Boolean Toggle")) + .description(val -> OptionDescription.createBuilder() + .text(Component.literal("You can customize controllers like so! YACL is truly infinitely customizable! This tooltip is long in order to demonstrate the cool, smooth scrolling of these descriptions. Did you know, they are also super clickable?! I know, cool right, YACL 3.x really is amazing.")) + .image(Path.of("D:\\Xander\\Downloads\\_MG_0860-Enhanced-NR.png"), new ResourceLocation("yacl", "f.webp")) // TODO: Add img file to git? + .build()) + .binding( + defaults.customBooleanToggle, + () -> config.customBooleanToggle, + (value) -> config.customBooleanToggle = value + ) + .controller(opt -> BooleanControllerBuilder.create(opt) + .formatValue(state -> state ? Component.literal("Amazing") : Component.literal("Not Amazing")) + .coloured(true)) + .listener((opt, val) -> booleanOption.get().setAvailable(val)) + .build()) + .option(Option.createBuilder() + .name(Component.literal("Tick Box")) + .description(OptionDescription.of(Component.literal("There are even alternate methods of displaying the same data type!"))) + .binding( + defaults.tickbox, + () -> config.tickbox, + (value) -> config.tickbox = value + ) + .controller(TickBoxControllerBuilder::create) + .build()) + .build()) + .group(OptionGroup.createBuilder() + .name(Component.literal("Slider Controllers")) + .option(Option.createBuilder() + .name(Component.literal("Int Slider")) + .binding( + defaults.intSlider, + () -> config.intSlider, + value -> config.intSlider = value + ) + .customController(opt -> new IntegerSliderController(opt, 0, 3, 1)) + .build()) + .option(Option.createBuilder() + .name(Component.literal("Double Slider")) + .binding( + defaults.doubleSlider, + () -> config.doubleSlider, + (value) -> config.doubleSlider = value + ) + .customController(opt -> new DoubleSliderController(opt, 0, 3, 0.05)) + .build()) + .option(Option.createBuilder() + .name(Component.literal("Float Slider")) + .binding( + defaults.floatSlider, + () -> config.floatSlider, + (value) -> config.floatSlider = value + ) + .customController(opt -> new FloatSliderController(opt, 0, 3, 0.1f)) + .build()) + .option(Option.createBuilder() + .name(Component.literal("Long Slider")) + .binding( + defaults.longSlider, + () -> config.longSlider, + (value) -> config.longSlider = value + ) + .customController(opt -> new LongSliderController(opt, 0, 1_000_000, 100)) + .build()) + .build()) + .group(OptionGroup.createBuilder() + .name(Component.literal("Input Field Controllers")) + .option(Option.createBuilder() + .name(Component.literal("Component Option")) + .binding( + defaults.textField, + () -> config.textField, + value -> config.textField = value + ) + .customController(StringController::new) + .build()) + .option(Option.createBuilder() + .name(Component.literal("Color Option")) + .binding( + defaults.colorOption, + () -> config.colorOption, + value -> config.colorOption = value + ) + .customController(ColorController::new) + .build()) + .build()) + .group(OptionGroup.createBuilder() + .name(Component.literal("Number Fields")) + .option(Option.createBuilder() + .name(Component.literal("Double Field")) + .binding( + defaults.doubleField, + () -> config.doubleField, + value -> config.doubleField = value + ) + .customController(DoubleFieldController::new) + .build()) + .option(Option.createBuilder() + .name(Component.literal("Float Field")) + .binding( + defaults.floatField, + () -> config.floatField, + value -> config.floatField = value + ) + .customController(FloatFieldController::new) + .build()) + .option(Option.createBuilder() + .name(Component.literal("Integer Field")) + .binding( + defaults.intField, + () -> config.intField, + value -> config.intField = value + ) + .customController(IntegerFieldController::new) + .build()) + .option(Option.createBuilder() + .name(Component.literal("Long Field")) + .binding( + defaults.longField, + () -> config.longField, + value -> config.longField = value + ) + .customController(LongFieldController::new) + .build()) + .build()) + .group(OptionGroup.createBuilder() + .name(Component.literal("Enum Controllers")) + .option(Option.createBuilder() + .name(Component.literal("Enum Cycler")) + .binding( + defaults.enumOption, + () -> config.enumOption, + (value) -> config.enumOption = value + ) + .customController(opt -> new EnumController<>(opt, ConfigTest.Alphabet.class)) + .build()) + .build()) + .group(OptionGroup.createBuilder() + .name(Component.literal("Dropdown Controllers")) + .option(Option.createBuilder() + .name(Component.literal("String Dropdown")) + .binding( + defaults.stringOptions, + () -> config.stringOptions, + (value) -> config.stringOptions = value + ) + .controller(opt -> DropdownStringControllerBuilder.create(opt) + .values("Apple", "Banana", "Cherry", "Date") + ) + .build()) + .option(Option.createBuilder() + .name(Component.literal("String suggestions")) + .binding( + defaults.stringSuggestions, + () -> config.stringSuggestions, + (value) -> config.stringSuggestions = value + ) + .controller(opt -> DropdownStringControllerBuilder.create(opt) + .values("Apple", "Banana", "Cherry", "Date") + .allowAnyValue(true) + ) + .build()) + .option(Option.createBuilder() + .name(Component.literal("Item Dropdown")) + .binding( + defaults.item, + () -> config.item, + (value) -> config.item = value + ) + .controller(ItemControllerBuilder::create) + .build()) + .option(Option.createBuilder() + .name(Component.literal("Enum Dropdown")) + .binding( + defaults.formattingOption, + () -> config.formattingOption, + (value) -> config.formattingOption = value + ) + .controller(option -> EnumDropdownControllerBuilder.create(option).formatValue(formatting -> Component.literal(StringUtils.capitalize(formatting.getName()).replaceAll("_", " ")))) + .build()) + .build()) + .group(OptionGroup.createBuilder() + .name(Component.literal("Options that aren't really options")) + .option(ButtonOption.createBuilder() + .name(Component.literal("Button \"Option\"")) + .action((screen, opt) -> opt.setAvailable(false)) + .build()) + .option(LabelOption.create( + Component.empty() + .append(Component.literal("a").withStyle(style -> style.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Component.literal("a"))))) + .append(Component.literal("b").withStyle(style -> style.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Component.literal("b"))))) + .append(Component.literal("c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c c").withStyle(style -> style.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Component.literal("c"))))) + .append(Component.literal("e").withStyle(style -> style.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Component.literal("e"))))) + .withStyle(style -> style.withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, "https://isxander.dev")))) + ) + .build()) + .group(OptionGroup.createBuilder() + .name(Component.literal("Minecraft Bindings")) + .description(OptionDescription.of(Component.literal("YACL can also bind Minecraft options!"))) + .option(Option.createBuilder() + .name(Component.literal("Minecraft AutoJump")) + .description(OptionDescription.of(Component.literal("You can even bind minecraft options!"))) + .binding(Binding.minecraft(Minecraft.getInstance().options.autoJump())) + .customController(TickBoxController::new) + .build()) + .option(Option.createBuilder() + .name(Component.literal("Minecraft Graphics Mode")) + .binding(Binding.minecraft(Minecraft.getInstance().options.graphicsMode())) + .customController(opt -> new EnumController<>(opt, GraphicsStatus.class)) + .build()) + .build()) + .build()) + .category(ConfigCategory.createBuilder() + .name(Component.literal("List Test")) + .group(ListOption.createBuilder() + .name(Component.literal("String List")) + .binding( + defaults.stringList, + () -> config.stringList, + val -> config.stringList = val + ) + .controller(StringControllerBuilder::create) + .initial("") + .minimumNumberOfEntries(3) + .maximumNumberOfEntries(5) + .insertEntriesAtEnd(true) + .build()) + .group(ListOption.createBuilder() + .name(Component.literal("Slider List")) + .binding( + defaults.intList, + () -> config.intList, + val -> config.intList = val + ) + .controller(opt -> IntegerSliderControllerBuilder.create(opt) + .range(0, 10).step(1)) + .initial(0) + .available(false) + .build()) + .group(ListOption.createBuilder() + .name(Component.literal("Useless Label List")) + .binding(Binding.immutable(List.of(Component.literal("It's quite impressive that literally every single controller works, without problem.")))) + .customController(LabelController::new) + .initial(Component.literal("Initial label")) + .build()) + .build()) + .category(ConfigCategory.createBuilder() + .name(Component.literal("Group Test")) + .option(Option.createBuilder() + .name(Component.literal("Root Test")) + .binding( + defaults.groupTestRoot, + () -> config.groupTestRoot, + value -> config.groupTestRoot = value + ) + .customController(TickBoxController::new) + .build()) + .group(OptionGroup.createBuilder() + .name(Component.literal("First Group")) + .option(Option.createBuilder() + .name(Component.literal("First Group Test 1")) + .binding( + defaults.groupTestFirstGroup, + () -> config.groupTestFirstGroup, + value -> config.groupTestFirstGroup = value + ) + .customController(TickBoxController::new) + .build()) + .option(Option.createBuilder() + .name(Component.literal("First Group Test 2")) + .binding( + defaults.groupTestFirstGroup2, + () -> config.groupTestFirstGroup2, + value -> config.groupTestFirstGroup2 = value + ) + .customController(TickBoxController::new) + .build()) + .build()) + .group(OptionGroup.createBuilder() + .name(Component.empty()) + .option(Option.createBuilder() + .name(Component.literal("Second Group Test")) + .binding( + defaults.groupTestSecondGroup, + () -> config.groupTestSecondGroup, + value -> config.groupTestSecondGroup = value + ) + .customController(TickBoxController::new) + .build()) + .build()) + .build()) + .category(ConfigCategory.createBuilder() + .name(Component.literal("Category Test")) + .option(LabelOption.create(Component.literal("This is a test category!"))) + .build()) + .category(ConfigCategory.createBuilder() + .name(Component.literal("Category Test")) + .option(LabelOption.create(Component.literal("This is a test category!"))) + .build()) + .category(ConfigCategory.createBuilder() + .name(Component.literal("Category Test")) + .option(LabelOption.create(Component.literal("This is a test category!"))) + .build()) + .category(ConfigCategory.createBuilder() + .name(Component.literal("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")) + .option(LabelOption.create(Component.literal("This is a test category!"))) + .build()) + .category(ConfigCategory.createBuilder() + .name(Component.literal("Category Test")) + .option(LabelOption.create(Component.literal("This is a test category!"))) + .build()) + .category(ConfigCategory.createBuilder() + .name(Component.literal("Category Test")) + .option(LabelOption.create(Component.literal("This is a test category!"))) + .build()) + .category(ConfigCategory.createBuilder() + .name(Component.literal("Category Test")) + .option(LabelOption.create(Component.literal("This is a test category!"))) + .build()) + .category(PlaceholderCategory.createBuilder() + .name(Component.literal("Placeholder Category")) + .screen((client, yaclScreen) -> new RequireRestartScreen(yaclScreen)) + .build()) + .save(() -> { + Minecraft.getInstance().options.save(); + ConfigTest.GSON.serializer().save(); + }) + ) + .generateScreen(parent); + } + + private static boolean myBooleanOption = true; + + private static Screen getWikiGetStarted(Screen parent) { + return YetAnotherConfigLib.createBuilder() + .title(Component.literal("Used for narration. Could be used to render a title in the future.")) + .category(ConfigCategory.createBuilder() + .name(Component.literal("Name of the category")) + .tooltip(Component.literal("This Component will appear as a tooltip when you hover or focus the button with Tab. There is no need to add \n to wrap as YACL will do it for you.")) + .group(OptionGroup.createBuilder() + .name(Component.literal("Name of the group")) + .description(OptionDescription.of(Component.literal("This Component will appear when you hover over the name or focus on the collapse button with Tab."))) + .option(Option.createBuilder() + .name(Component.literal("Boolean Option")) + .description(OptionDescription.of(Component.literal("This Component will appear as a tooltip when you hover over the option."))) + .binding(true, () -> myBooleanOption, newVal -> myBooleanOption = newVal) + .customController(TickBoxController::new) + .build()) + .build()) + .build()) + .build() + .generateScreen(parent); + } +} diff --git a/src/testmod/java/dev/isxander/yacl3/test/mixin/TitleScreenMixin.java b/src/testmod/java/dev/isxander/yacl3/test/mixin/TitleScreenMixin.java new file mode 100644 index 0000000..c3fddbc --- /dev/null +++ b/src/testmod/java/dev/isxander/yacl3/test/mixin/TitleScreenMixin.java @@ -0,0 +1,25 @@ +package dev.isxander.yacl3.test.mixin; + +import dev.isxander.yacl3.test.GuiTest; +import net.minecraft.client.gui.components.Button; +import net.minecraft.client.gui.screens.Screen; +import net.minecraft.client.gui.screens.TitleScreen; +import net.minecraft.network.chat.Component; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(TitleScreen.class) +public abstract class TitleScreenMixin extends Screen { + protected TitleScreenMixin(Component title) { + super(title); + } + + @Inject(method = "init", at = @At("RETURN")) + private void addButton(CallbackInfo ci) { + addRenderableWidget(Button.builder(Component.literal("YetAnotherConfigLib Test"), button -> { + minecraft.setScreen(GuiTest.getModConfigScreenFactory(minecraft.screen)); + }).width(150).build()); + } +} -- cgit