From b9ce9513c8e55ed53321d78b6fbbd07aacd5e987 Mon Sep 17 00:00:00 2001 From: xander Date: Thu, 15 Sep 2022 19:22:40 +0100 Subject: available property + fix category tooltips not showing --- .../java/dev/isxander/yacl/api/ButtonOption.java | 41 ++++++++++++++++++++-- src/main/java/dev/isxander/yacl/api/Option.java | 19 +++++++++- 2 files changed, 57 insertions(+), 3 deletions(-) (limited to 'src/main/java/dev/isxander/yacl/api') diff --git a/src/main/java/dev/isxander/yacl/api/ButtonOption.java b/src/main/java/dev/isxander/yacl/api/ButtonOption.java index f3d1e6b..519131e 100644 --- a/src/main/java/dev/isxander/yacl/api/ButtonOption.java +++ b/src/main/java/dev/isxander/yacl/api/ButtonOption.java @@ -13,6 +13,9 @@ import java.util.function.Consumer; import java.util.function.Function; public interface ButtonOption extends Option> { + /** + * Action to be executed upon button press + */ Consumer action(); static Builder createBuilder() { @@ -22,6 +25,7 @@ public interface ButtonOption extends Option> { class Builder { private Text name; private final List tooltipLines = new ArrayList<>(); + private boolean available = true; private Function>> controlGetter; private Consumer action; @@ -29,6 +33,11 @@ public interface ButtonOption extends Option> { } + /** + * Sets the name to be used by the option. + * + * @see Option#name() + */ public Builder name(@NotNull Text name) { Validate.notNull(name, "`name` cannot be null"); @@ -36,13 +45,25 @@ public interface ButtonOption extends Option> { return this; } + /** + * Sets the tooltip to be used by the option. + * Can be invoked twice to append more lines. + * No need to wrap the text yourself, the gui does this itself. + * + * @param tooltips text lines - merged with a new-line on {@link Option.Builder#build()}. + */ public Builder tooltip(@NotNull Text... tooltips) { - Validate.notEmpty(tooltips, "`tooltips` cannot be empty"); + Validate.notNull(tooltips, "`tooltips` cannot be empty"); tooltipLines.addAll(List.of(tooltips)); return this; } + /** + * Action to be executed upon button press + * + * @see ButtonOption#action() + */ public Builder action(@NotNull Consumer action) { Validate.notNull(action, "`action` cannot be null"); @@ -50,6 +71,22 @@ public interface ButtonOption extends Option> { return this; } + /** + * Sets if the option can be configured + * + * @see Option#available() + */ + public Builder available(boolean available) { + this.available = available; + return this; + } + + /** + * Sets the controller for the option. + * This is how you interact and change the options. + * + * @see dev.isxander.yacl.gui.controllers + */ public Builder controller(@NotNull Function>> control) { Validate.notNull(control, "`control` cannot be null"); @@ -71,7 +108,7 @@ public interface ButtonOption extends Option> { concatenatedTooltip.append(line); } - return new ButtonOptionImpl(name, concatenatedTooltip, action, controlGetter); + return new ButtonOptionImpl(name, concatenatedTooltip, action, available, controlGetter); } } } diff --git a/src/main/java/dev/isxander/yacl/api/Option.java b/src/main/java/dev/isxander/yacl/api/Option.java index 10f2d10..ff72c4c 100644 --- a/src/main/java/dev/isxander/yacl/api/Option.java +++ b/src/main/java/dev/isxander/yacl/api/Option.java @@ -40,6 +40,11 @@ public interface Option { */ @NotNull Binding binding(); + /** + * If the option can be configured + */ + boolean available(); + /** * Class of the option type. * Used by some controllers. @@ -109,6 +114,8 @@ public interface Option { private Binding binding; + private boolean available = true; + private final Set flags = new HashSet<>(); private final Class typeClass; @@ -187,6 +194,16 @@ public interface Option { return this; } + /** + * Sets if the option can be configured + * + * @see Option#available() + */ + public Builder available(boolean available) { + this.available = available; + return this; + } + /** * Adds a flag to the option. * Upon applying changes, all flags are executed. @@ -236,7 +253,7 @@ public interface Option { concatenatedTooltip.append(line); } - return new OptionImpl<>(name, concatenatedTooltip, controlGetter, binding, ImmutableSet.copyOf(flags), typeClass); + return new OptionImpl<>(name, concatenatedTooltip, controlGetter, binding, available, ImmutableSet.copyOf(flags), typeClass); } } } -- cgit