diff options
author | isXander <xandersmith2008@gmail.com> | 2023-08-12 15:04:45 +0100 |
---|---|---|
committer | isXander <xandersmith2008@gmail.com> | 2023-08-12 15:05:01 +0100 |
commit | 3083aebe47f63661238ee2b521b0451af2d95e9f (patch) | |
tree | 2e6ac26f024e045394bbc7b02c325641291c35d7 /test-common/src/main/java/dev | |
parent | f0482b7e6cab80ea770aeccc07820c675c93def8 (diff) | |
download | YetAnotherConfigLib-3083aebe47f63661238ee2b521b0451af2d95e9f.tar.gz YetAnotherConfigLib-3083aebe47f63661238ee2b521b0451af2d95e9f.tar.bz2 YetAnotherConfigLib-3083aebe47f63661238ee2b521b0451af2d95e9f.zip |
Fix `Option#setAvailable` not updating the reset button when used outside of a listener (@enjarai).
Made listener system more robust.
Diffstat (limited to 'test-common/src/main/java/dev')
-rw-r--r-- | test-common/src/main/java/dev/isxander/yacl3/test/GuiTest.java | 52 |
1 files changed, 30 insertions, 22 deletions
diff --git a/test-common/src/main/java/dev/isxander/yacl3/test/GuiTest.java b/test-common/src/main/java/dev/isxander/yacl3/test/GuiTest.java index 634c2ce..c490799 100644 --- a/test-common/src/main/java/dev/isxander/yacl3/test/GuiTest.java +++ b/test-common/src/main/java/dev/isxander/yacl3/test/GuiTest.java @@ -17,6 +17,7 @@ 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.Util; import net.minecraft.client.GraphicsStatus; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.components.toasts.SystemToast; @@ -29,6 +30,7 @@ import net.minecraft.resources.ResourceLocation; 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) { @@ -53,6 +55,8 @@ public class GuiTest { } private static Screen getFullTestSuite(Screen parent) { + AtomicReference<Option<Boolean>> booleanOption = new AtomicReference<>(); + return YetAnotherConfigLib.create(ConfigTest.GSON, (defaults, config, builder) -> builder .title(Component.literal("Test GUI")) .category(ConfigCategory.createBuilder() @@ -60,26 +64,30 @@ public class GuiTest { .tooltip(Component.literal("Example Category Description")) .group(OptionGroup.createBuilder() .name(Component.literal("Boolean Controllers")) - .option(Option.<Boolean>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(Path.of("D:\\Xander\\Code\\isXander\\Controlify\\src\\main\\resources\\assets\\controlify\\textures\\screenshots\\reach-around-placement.webp"), new ResourceLocation("yacl", "e.webp")) - .build()) - .binding( - defaults.booleanToggle, - () -> config.booleanToggle, - (value) -> config.booleanToggle = value - ) - .controller(BooleanControllerBuilder::create) - .flag(OptionFlag.GAME_RESTART) - .build()) + .option(Util.make(() -> { + var opt = Option.<Boolean>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(Path.of("D:\\Xander\\Code\\isXander\\Controlify\\src\\main\\resources\\assets\\controlify\\textures\\screenshots\\reach-around-placement.webp"), new ResourceLocation("yacl", "e.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.<Boolean>createBuilder() .name(Component.literal("Custom Boolean Toggle")) .description(val -> OptionDescription.createBuilder() @@ -94,9 +102,9 @@ public class GuiTest { .controller(opt -> BooleanControllerBuilder.create(opt) .valueFormatter(state -> state ? Component.literal("Amazing") : Component.literal("Not Amazing")) .coloured(true)) - .available(false) + .listener((opt, val) -> booleanOption.get().setAvailable(val)) .build()) - .option(Option.createBuilder(boolean.class) + .option(Option.<Boolean>createBuilder() .name(Component.literal("Tick Box")) .description(OptionDescription.of(Component.literal("There are even alternate methods of displaying the same data type!"))) .binding( |