diff options
author | isXander <xandersmith2008@gmail.com> | 2023-04-15 22:21:45 +0100 |
---|---|---|
committer | isXander <xandersmith2008@gmail.com> | 2023-04-15 22:21:45 +0100 |
commit | 74bcc11c74f864eda2f5e48a3c038846c20065ba (patch) | |
tree | 4cd72c84135c103ba55fc91742504c0d513ed3b3 /src/client | |
parent | 257a50da0880dac23a81933e39b27e381616bd61 (diff) | |
download | YetAnotherConfigLib-74bcc11c74f864eda2f5e48a3c038846c20065ba.tar.gz YetAnotherConfigLib-74bcc11c74f864eda2f5e48a3c038846c20065ba.tar.bz2 YetAnotherConfigLib-74bcc11c74f864eda2f5e48a3c038846c20065ba.zip |
2.4.1
Diffstat (limited to 'src/client')
6 files changed, 45 insertions, 5 deletions
diff --git a/src/client/java/dev/isxander/yacl/api/ConfigCategory.java b/src/client/java/dev/isxander/yacl/api/ConfigCategory.java index 0e8d1e5..7764479 100644 --- a/src/client/java/dev/isxander/yacl/api/ConfigCategory.java +++ b/src/client/java/dev/isxander/yacl/api/ConfigCategory.java @@ -36,7 +36,7 @@ public interface ConfigCategory { return new ConfigCategoryImpl.BuilderImpl(); } - interface Builder { + interface Builder extends OptionAddable { /** * Sets name of the category * @@ -52,6 +52,7 @@ public interface ConfigCategory { * @see ConfigCategory#groups() * @see OptionGroup#isRoot() */ + @Override Builder option(@NotNull Option<?> option); /** @@ -62,7 +63,8 @@ public interface ConfigCategory { * @see ConfigCategory#groups() * @see OptionGroup#isRoot() */ - Builder options(@NotNull Collection<Option<?>> options); + @Override + Builder options(@NotNull Collection<? extends Option<?>> options); /** * Adds an option group. diff --git a/src/client/java/dev/isxander/yacl/api/Option.java b/src/client/java/dev/isxander/yacl/api/Option.java index faa6f1c..a6c0311 100644 --- a/src/client/java/dev/isxander/yacl/api/Option.java +++ b/src/client/java/dev/isxander/yacl/api/Option.java @@ -132,7 +132,15 @@ public interface Option<T> { * * @param tooltipGetter function to get tooltip depending on value {@link Builder#build()}. */ - @SuppressWarnings("unchecked") + Builder<T> tooltip(@NotNull Function<T, Component> tooltipGetter); + + /** + * Sets the tooltip to be used by the option. + * No need to wrap the text yourself, the gui does this itself. + * + * @param tooltipGetter function to get tooltip depending on value {@link Builder#build()}. + */ + @Deprecated Builder<T> tooltip(@NotNull Function<T, Component>... tooltipGetter); /** diff --git a/src/client/java/dev/isxander/yacl/api/OptionAddable.java b/src/client/java/dev/isxander/yacl/api/OptionAddable.java new file mode 100644 index 0000000..57be06c --- /dev/null +++ b/src/client/java/dev/isxander/yacl/api/OptionAddable.java @@ -0,0 +1,19 @@ +package dev.isxander.yacl.api; + +import org.jetbrains.annotations.NotNull; + +import java.util.Collection; + +public interface OptionAddable { + /** + * Adds an option to an abstract builder. + * To construct an option, use {@link Option#createBuilder(Class)} + */ + OptionAddable option(@NotNull Option<?> option); + + /** + * Adds multiple options to an abstract builder. + * To construct an option, use {@link Option#createBuilder(Class)} + */ + OptionAddable options(@NotNull Collection<? extends Option<?>> options); +} diff --git a/src/client/java/dev/isxander/yacl/api/OptionGroup.java b/src/client/java/dev/isxander/yacl/api/OptionGroup.java index 9f78071..4fe43c7 100644 --- a/src/client/java/dev/isxander/yacl/api/OptionGroup.java +++ b/src/client/java/dev/isxander/yacl/api/OptionGroup.java @@ -47,7 +47,7 @@ public interface OptionGroup { return new OptionGroupImpl.BuilderImpl(); } - interface Builder { + interface Builder extends OptionAddable { /** * Sets name of the group, can be {@link Component#empty()} to just separate options, like sodium. * @@ -70,6 +70,7 @@ public interface OptionGroup { * * @see OptionGroup#options() */ + @Override Builder option(@NotNull Option<?> option); /** @@ -78,6 +79,7 @@ public interface OptionGroup { * * @see OptionGroup#options() */ + @Override Builder options(@NotNull Collection<? extends Option<?>> options); /** diff --git a/src/client/java/dev/isxander/yacl/impl/ConfigCategoryImpl.java b/src/client/java/dev/isxander/yacl/impl/ConfigCategoryImpl.java index efbd8c9..b3d28b3 100644 --- a/src/client/java/dev/isxander/yacl/impl/ConfigCategoryImpl.java +++ b/src/client/java/dev/isxander/yacl/impl/ConfigCategoryImpl.java @@ -74,7 +74,7 @@ public final class ConfigCategoryImpl implements ConfigCategory { } @Override - public Builder options(@NotNull Collection<Option<?>> options) { + public Builder options(@NotNull Collection<? extends Option<?>> options) { Validate.notNull(options, "`options` must not be null"); if (options.stream().anyMatch(ListOption.class::isInstance)) diff --git a/src/client/java/dev/isxander/yacl/impl/OptionImpl.java b/src/client/java/dev/isxander/yacl/impl/OptionImpl.java index d333e36..35ad620 100644 --- a/src/client/java/dev/isxander/yacl/impl/OptionImpl.java +++ b/src/client/java/dev/isxander/yacl/impl/OptionImpl.java @@ -176,7 +176,16 @@ public final class OptionImpl<T> implements Option<T> { } @Override + public Builder<T> tooltip(@NotNull Function<T, Component> tooltipGetter) { + Validate.notNull(tooltipGetter, "`tooltipGetter` cannot be null"); + + this.tooltipGetters.add(tooltipGetter); + return this; + } + + @Override @SafeVarargs + @Deprecated public final Option.Builder<T> tooltip(@NotNull Function<T, Component>... tooltipGetter) { Validate.notNull(tooltipGetter, "`tooltipGetter` cannot be null"); |