From ad3e7955295d114ecbdaf07eb51ba26f0dc95d96 Mon Sep 17 00:00:00 2001 From: isXander Date: Tue, 15 Aug 2023 12:03:27 +0100 Subject: Complete the controllers (except number fields) --- .../java/dev/isxander/yacl3/test/ConfigV2Test.java | 41 +++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) (limited to 'test-common/src/main/java') diff --git a/test-common/src/main/java/dev/isxander/yacl3/test/ConfigV2Test.java b/test-common/src/main/java/dev/isxander/yacl3/test/ConfigV2Test.java index d287604..04b7db0 100644 --- a/test-common/src/main/java/dev/isxander/yacl3/test/ConfigV2Test.java +++ b/test-common/src/main/java/dev/isxander/yacl3/test/ConfigV2Test.java @@ -1,6 +1,12 @@ 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.GsonConfigSerializerBuilder; import dev.isxander.yacl3.config.v2.api.SerialEntry; import dev.isxander.yacl3.config.v2.api.autogen.*; @@ -8,6 +14,8 @@ import dev.isxander.yacl3.platform.YACLPlatform; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; +import java.util.List; + public class ConfigV2Test { public static ConfigClassHandler INSTANCE = ConfigClassHandler.createBuilder(ConfigV2Test.class) .id(new ResourceLocation("yacl3", "config")) @@ -19,7 +27,7 @@ public class ConfigV2Test { .build(); @AutoGen(category = "test", group = "master_test") - @MasterTickBox({ "testTickBox", "testInt" }) + @MasterTickBox({ "testTickBox", "testInt", "testEnum" }) @SerialEntry(comment = "This option does this and that which is cool because this...") public boolean masterOption = true; @@ -32,6 +40,37 @@ public class ConfigV2Test { @IntSlider(min = 0, max = 10, step = 2) @SerialEntry public int testInt = 0; + @AutoGen(category = "test", group = "master_test") + @EnumCycler + @SerialEntry public Alphabet testEnum = Alphabet.A; + @AutoGen(category = "test", group = "misc") @Label private final Component testLabel = Component.literal("Test label"); + + @AutoGen(category = "test") + @ListGroup(valueFactory = TestListValueFactory.class, controllerFactory = TestListControllerFactory.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 TestListValueFactory implements ListGroup.ValueFactory { + @Override + public String provideNewValue() { + return ""; + } + } + + public static class TestListControllerFactory implements ListGroup.ControllerFactory { + @Override + public ControllerBuilder createController(ListGroup annotation, ConfigField> field, OptionStorage storage, Option option) { + return StringControllerBuilder.create(option); + } + } } -- cgit