diff options
Diffstat (limited to 'common/src/main')
3 files changed, 21 insertions, 2 deletions
diff --git a/common/src/main/java/dev/isxander/yacl3/api/ButtonOption.java b/common/src/main/java/dev/isxander/yacl3/api/ButtonOption.java index 943f9ac..4f53dd4 100644 --- a/common/src/main/java/dev/isxander/yacl3/api/ButtonOption.java +++ b/common/src/main/java/dev/isxander/yacl3/api/ButtonOption.java @@ -26,6 +26,11 @@ public interface ButtonOption extends Option<BiConsumer<YACLScreen, ButtonOption */ Builder name(@NotNull Component name); + /** + * Sets the button text to be displayed next to the name. + */ + Builder text(@NotNull Component text); + Builder description(@NotNull OptionDescription description); Builder action(@NotNull BiConsumer<YACLScreen, ButtonOption> action); diff --git a/common/src/main/java/dev/isxander/yacl3/impl/ButtonOptionImpl.java b/common/src/main/java/dev/isxander/yacl3/impl/ButtonOptionImpl.java index 99a6e83..7451f7c 100644 --- a/common/src/main/java/dev/isxander/yacl3/impl/ButtonOptionImpl.java +++ b/common/src/main/java/dev/isxander/yacl3/impl/ButtonOptionImpl.java @@ -26,13 +26,14 @@ public final class ButtonOptionImpl implements ButtonOption { @NotNull Component name, @Nullable OptionDescription description, @NotNull BiConsumer<YACLScreen, ButtonOption> action, + @Nullable Component text, boolean available ) { this.name = name; this.description = description; this.action = action; this.available = available; - this.controller = new ActionController(this); + this.controller = text != null ? new ActionController(this, text) : new ActionController(this); this.binding = new EmptyBinderImpl(); } @@ -141,6 +142,7 @@ public final class ButtonOptionImpl implements ButtonOption { @ApiStatus.Internal public static final class BuilderImpl implements Builder { private Component name; + private Component text = null; private OptionDescription description = OptionDescription.EMPTY; private boolean available = true; private BiConsumer<YACLScreen, ButtonOption> action; @@ -154,6 +156,14 @@ public final class ButtonOptionImpl implements ButtonOption { } @Override + public Builder text(@NotNull Component text) { + Validate.notNull(text, "`text` cannot be null"); + + this.text = text; + return this; + } + + @Override public Builder description(@NotNull OptionDescription description) { Validate.notNull(description, "`description` cannot be null"); @@ -189,7 +199,7 @@ public final class ButtonOptionImpl implements ButtonOption { Validate.notNull(name, "`name` must not be null when building `ButtonOption`"); Validate.notNull(action, "`action` must not be null when building `ButtonOption`"); - return new ButtonOptionImpl(name, description, action, available); + return new ButtonOptionImpl(name, description, action, text, available); } } } diff --git a/common/src/main/java/dev/isxander/yacl3/impl/OptionImpl.java b/common/src/main/java/dev/isxander/yacl3/impl/OptionImpl.java index 9b3a613..01a6287 100644 --- a/common/src/main/java/dev/isxander/yacl3/impl/OptionImpl.java +++ b/common/src/main/java/dev/isxander/yacl3/impl/OptionImpl.java @@ -251,6 +251,10 @@ public final class OptionImpl<T> implements Option<T> { Validate.notNull(binding, "`binding` must not be null when building `Option`"); Validate.isTrue(!instant || flags.isEmpty(), "instant application does not support option flags"); + if (instant) { + listeners.add((opt, pendingValue) -> opt.applyValue()); + } + return new OptionImpl<>(name, descriptionFunction, controlGetter, binding, available, ImmutableSet.copyOf(flags), listeners); } } |