From 5e0574b1cb6ef22bf70ce52a0c0e187450189c6c Mon Sep 17 00:00:00 2001 From: xander Date: Sun, 11 Sep 2022 21:52:12 +0100 Subject: 1.1.0 better search - now searches every category rather than the current one option flags - flags are pieces of code ran when certain options' changes are applied (makes required restart redundant) fix scaling problems - make GUI a lot better at scaling bump gradle wrapper --- src/main/java/dev/isxander/yacl/api/Option.java | 47 +++++++++++++++++++++---- 1 file changed, 41 insertions(+), 6 deletions(-) (limited to 'src/main/java/dev/isxander/yacl/api/Option.java') diff --git a/src/main/java/dev/isxander/yacl/api/Option.java b/src/main/java/dev/isxander/yacl/api/Option.java index ced0772..10f2d10 100644 --- a/src/main/java/dev/isxander/yacl/api/Option.java +++ b/src/main/java/dev/isxander/yacl/api/Option.java @@ -1,5 +1,6 @@ package dev.isxander.yacl.api; +import com.google.common.collect.ImmutableSet; import dev.isxander.yacl.impl.OptionImpl; import net.minecraft.text.MutableText; import net.minecraft.text.Text; @@ -7,8 +8,7 @@ import net.minecraft.util.Formatting; import org.apache.commons.lang3.Validate; import org.jetbrains.annotations.NotNull; -import java.util.ArrayList; -import java.util.List; +import java.util.*; import java.util.function.Consumer; import java.util.function.Function; import java.util.function.Supplier; @@ -46,6 +46,11 @@ public interface Option { */ @NotNull Class typeClass(); + /** + * Tasks that needs to be executed upon applying changes. + */ + @NotNull ImmutableSet flags(); + /** * Checks if the pending value is not equal to the current set value */ @@ -54,6 +59,7 @@ public interface Option { /** * If true, modifying this option recommends a restart. */ + @Deprecated boolean requiresRestart(); /** @@ -69,8 +75,10 @@ public interface Option { /** * Applies the pending value to the bound value. * Cannot be undone. + * + * @return if there were changes to apply {@link Option#changed()} */ - void applyValue(); + boolean applyValue(); /** * Sets the pending value to the bound value. @@ -101,7 +109,7 @@ public interface Option { private Binding binding; - private boolean requiresRestart; + private final Set flags = new HashSet<>(); private final Class typeClass; @@ -179,12 +187,39 @@ public interface Option { return this; } + /** + * Adds a flag to the option. + * Upon applying changes, all flags are executed. + * {@link Option#flags()} + */ + public Builder flag(@NotNull OptionFlag... flag) { + Validate.notNull(flag, "`flag` must not be null"); + + this.flags.addAll(Arrays.asList(flag)); + return this; + } + + /** + * Adds a flag to the option. + * Upon applying changes, all flags are executed. + * {@link Option#flags()} + */ + public Builder flags(@NotNull Collection flags) { + Validate.notNull(flags, "`flags` must not be null"); + + this.flags.addAll(flags); + return this; + } + /** * Dictates whether the option should require a restart. * {@link Option#requiresRestart()} */ + @Deprecated public Builder requiresRestart(boolean requiresRestart) { - this.requiresRestart = requiresRestart; + if (requiresRestart) flag(OptionFlag.GAME_RESTART); + else flags.remove(OptionFlag.GAME_RESTART); + return this; } @@ -201,7 +236,7 @@ public interface Option { concatenatedTooltip.append(line); } - return new OptionImpl<>(name, concatenatedTooltip, controlGetter, binding, requiresRestart, typeClass); + return new OptionImpl<>(name, concatenatedTooltip, controlGetter, binding, ImmutableSet.copyOf(flags), typeClass); } } } -- cgit