diff options
| author | isXander <xandersmith2008@gmail.com> | 2023-06-03 23:10:03 +0100 |
|---|---|---|
| committer | isXander <xandersmith2008@gmail.com> | 2023-06-04 16:25:09 +0100 |
| commit | 3e36feeef60e56ef8cb7f737ac8eeab9fbcd6abb (patch) | |
| tree | f9c3395b4da2235681b87a35ac5056a0724a181b /common/src/main/java/dev/isxander/yacl/api | |
| parent | d00a486d3bdf6105f8ca8af1034c384058b8c832 (diff) | |
| download | YetAnotherConfigLib-3e36feeef60e56ef8cb7f737ac8eeab9fbcd6abb.tar.gz YetAnotherConfigLib-3e36feeef60e56ef8cb7f737ac8eeab9fbcd6abb.tar.bz2 YetAnotherConfigLib-3e36feeef60e56ef8cb7f737ac8eeab9fbcd6abb.zip | |
Change package and modid to yacl3 and yet_another_config_lib_3 respectively
Diffstat (limited to 'common/src/main/java/dev/isxander/yacl/api')
36 files changed, 0 insertions, 1401 deletions
diff --git a/common/src/main/java/dev/isxander/yacl/api/Binding.java b/common/src/main/java/dev/isxander/yacl/api/Binding.java deleted file mode 100644 index b4cd2d0..0000000 --- a/common/src/main/java/dev/isxander/yacl/api/Binding.java +++ /dev/null @@ -1,64 +0,0 @@ -package dev.isxander.yacl.api; - -import dev.isxander.yacl.impl.GenericBindingImpl; -import dev.isxander.yacl.mixin.OptionInstanceAccessor; -import net.minecraft.client.OptionInstance; -import org.apache.commons.lang3.Validate; - -import java.util.function.Consumer; -import java.util.function.Supplier; - -/** - * Controls modifying the bound option. - * Provides the default value, a setter and a getter. - */ -public interface Binding<T> { - void setValue(T value); - - T getValue(); - - T defaultValue(); - - /** - * Creates a generic binding. - * - * @param def default value of the option, used to reset - * @param getter should return the current value of the option - * @param setter should set the option to the supplied value - */ - static <T> Binding<T> generic(T def, Supplier<T> getter, Consumer<T> setter) { - Validate.notNull(def, "`def` must not be null"); - Validate.notNull(getter, "`getter` must not be null"); - Validate.notNull(setter, "`setter` must not be null"); - - return new GenericBindingImpl<>(def, getter, setter); - } - - /** - * Creates a {@link Binding} for Minecraft's {@link OptionInstance} - */ - static <T> Binding<T> minecraft(OptionInstance<T> minecraftOption) { - Validate.notNull(minecraftOption, "`minecraftOption` must not be null"); - - return new GenericBindingImpl<>( - ((OptionInstanceAccessor<T>) (Object) minecraftOption).getInitialValue(), - minecraftOption::get, - minecraftOption::set - ); - } - - /** - * Creates an immutable binding that has no default and cannot be modified. - * - * @param value the value for the binding - */ - static <T> Binding<T> immutable(T value) { - Validate.notNull(value, "`value` must not be null"); - - return new GenericBindingImpl<>( - value, - () -> value, - changed -> {} - ); - } -} diff --git a/common/src/main/java/dev/isxander/yacl/api/ButtonOption.java b/common/src/main/java/dev/isxander/yacl/api/ButtonOption.java deleted file mode 100644 index 4acbe0e..0000000 --- a/common/src/main/java/dev/isxander/yacl/api/ButtonOption.java +++ /dev/null @@ -1,51 +0,0 @@ -package dev.isxander.yacl.api; - -import dev.isxander.yacl.gui.YACLScreen; -import dev.isxander.yacl.impl.ButtonOptionImpl; -import net.minecraft.network.chat.Component; -import org.jetbrains.annotations.NotNull; - -import java.util.function.BiConsumer; -import java.util.function.Consumer; -import java.util.function.Function; - -public interface ButtonOption extends Option<BiConsumer<YACLScreen, ButtonOption>> { - /** - * Action to be executed upon button press - */ - BiConsumer<YACLScreen, ButtonOption> action(); - - static Builder createBuilder() { - return new ButtonOptionImpl.BuilderImpl(); - } - - interface Builder { - /** - * Sets the name to be used by the option. - * - * @see Option#name() - */ - Builder name(@NotNull Component name); - - Builder description(@NotNull OptionDescription description); - - Builder action(@NotNull BiConsumer<YACLScreen, ButtonOption> action); - - /** - * Action to be executed upon button press - * - * @see ButtonOption#action() - */ - @Deprecated - Builder action(@NotNull Consumer<YACLScreen> action); - - /** - * Sets if the option can be configured - * - * @see Option#available() - */ - Builder available(boolean available); - - ButtonOption build(); - } -} diff --git a/common/src/main/java/dev/isxander/yacl/api/ConfigCategory.java b/common/src/main/java/dev/isxander/yacl/api/ConfigCategory.java deleted file mode 100644 index 7764479..0000000 --- a/common/src/main/java/dev/isxander/yacl/api/ConfigCategory.java +++ /dev/null @@ -1,94 +0,0 @@ -package dev.isxander.yacl.api; - -import com.google.common.collect.ImmutableList; -import dev.isxander.yacl.impl.ConfigCategoryImpl; -import net.minecraft.network.chat.Component; -import org.jetbrains.annotations.NotNull; - -import java.util.Collection; - -/** - * Separates {@link Option}s or {@link OptionGroup}s into multiple distinct sections. - * Served to a user as a button in the left column, - * upon pressing, the options list is filled with options contained within this category. - */ -public interface ConfigCategory { - /** - * Name of category, displayed as a button on the left column. - */ - @NotNull Component name(); - - /** - * Gets every {@link OptionGroup} in this category. - */ - @NotNull ImmutableList<OptionGroup> groups(); - - /** - * Tooltip (or description) of the category. - * Rendered on hover. - */ - @NotNull Component tooltip(); - - /** - * Creates a builder to construct a {@link ConfigCategory} - */ - static Builder createBuilder() { - return new ConfigCategoryImpl.BuilderImpl(); - } - - interface Builder extends OptionAddable { - /** - * Sets name of the category - * - * @see ConfigCategory#name() - */ - Builder name(@NotNull Component name); - - /** - * Adds an option to the root group of the category. - * To add to another group, use {@link Builder#group(OptionGroup)}. - * To construct an option, use {@link Option#createBuilder(Class)} - * - * @see ConfigCategory#groups() - * @see OptionGroup#isRoot() - */ - @Override - Builder option(@NotNull Option<?> option); - - /** - * Adds multiple options to the root group of the category. - * To add to another group, use {@link Builder#groups(Collection)}. - * To construct an option, use {@link Option#createBuilder(Class)} - * - * @see ConfigCategory#groups() - * @see OptionGroup#isRoot() - */ - @Override - Builder options(@NotNull Collection<? extends Option<?>> options); - - /** - * Adds an option group. - * To add an option to the root group, use {@link Builder#option(Option)} - * To construct a group, use {@link OptionGroup#createBuilder()} - */ - Builder group(@NotNull OptionGroup group); - - /** - * Adds multiple option groups. - * To add multiple options to the root group, use {@link Builder#options(Collection)} - * To construct a group, use {@link OptionGroup#createBuilder()} - */ - Builder groups(@NotNull Collection<OptionGroup> groups); - - /** - * Sets the tooltip to be used by the category. - * 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 Builder#build()}. - */ - Builder tooltip(@NotNull Component... tooltips); - - ConfigCategory build(); - } -} diff --git a/common/src/main/java/dev/isxander/yacl/api/Controller.java b/common/src/main/java/dev/isxander/yacl/api/Controller.java deleted file mode 100644 index 0b8e2ed..0000000 --- a/common/src/main/java/dev/isxander/yacl/api/Controller.java +++ /dev/null @@ -1,28 +0,0 @@ -package dev.isxander.yacl.api; - -import dev.isxander.yacl.api.utils.Dimension; -import dev.isxander.yacl.gui.AbstractWidget; -import dev.isxander.yacl.gui.YACLScreen; -import net.minecraft.network.chat.Component; - -/** - * Provides a widget to control the option. - */ -public interface Controller<T> { - /** - * Gets the dedicated {@link Option} for this controller - */ - Option<T> option(); - - /** - * Gets the formatted value based on {@link Option#pendingValue()} - */ - Component formatValue(); - - /** - * Provides a widget to display - * - * @param screen parent screen - */ - AbstractWidget provideWidget(YACLScreen screen, Dimension<Integer> widgetDimension); -} diff --git a/common/src/main/java/dev/isxander/yacl/api/LabelOption.java b/common/src/main/java/dev/isxander/yacl/api/LabelOption.java deleted file mode 100644 index f646c55..0000000 --- a/common/src/main/java/dev/isxander/yacl/api/LabelOption.java +++ /dev/null @@ -1,41 +0,0 @@ -package dev.isxander.yacl.api; - -import dev.isxander.yacl.impl.LabelOptionImpl; -import net.minecraft.network.chat.Component; -import org.jetbrains.annotations.NotNull; - -import java.util.Collection; - -/** - * A label option is an easier way of creating a label with a {@link dev.isxander.yacl.gui.controllers.LabelController}. - * This option is immutable and cannot be disabled. Tooltips are supported through - * {@link Component} styling. - */ -public interface LabelOption extends Option<Component> { - @NotNull Component label(); - - /** - * Creates a new label option with the given label, skipping a builder for ease. - */ - static LabelOption create(@NotNull Component label) { - return new LabelOptionImpl(label); - } - - static Builder createBuilder() { - return new LabelOptionImpl.BuilderImpl(); - } - - interface Builder { - /** - * Appends a line to the label - */ - Builder line(@NotNull Component line); - - /** - * Appends multiple lines to the label - */ - Builder lines(@NotNull Collection<? extends Component> lines); - - LabelOption build(); - } -} diff --git a/common/src/main/java/dev/isxander/yacl/api/ListOption.java b/common/src/main/java/dev/isxander/yacl/api/ListOption.java deleted file mode 100644 index e370f36..0000000 --- a/common/src/main/java/dev/isxander/yacl/api/ListOption.java +++ /dev/null @@ -1,146 +0,0 @@ -package dev.isxander.yacl.api; - -import com.google.common.collect.ImmutableList; -import dev.isxander.yacl.api.controller.ControllerBuilder; -import dev.isxander.yacl.impl.ListOptionImpl; -import net.minecraft.network.chat.Component; -import org.jetbrains.annotations.ApiStatus; -import org.jetbrains.annotations.NotNull; - -import java.util.*; -import java.util.function.BiConsumer; -import java.util.function.Consumer; -import java.util.function.Function; -import java.util.function.Supplier; - -/** - * A list option that takes form as an option group for UX. - * You add this option through {@link ConfigCategory.Builder#group(OptionGroup)}. Do NOT add as an option. - * Users can add remove and reshuffle a list type. You can use any controller you wish, there are no dedicated - * controllers for list types. List options do not manipulate your list but get and set the list with a - * regular binding for simplicity. - * - * You may apply option flags like a normal option and collapse like a normal group, it is a merge of them both. - * Methods in this interface marked with {@link ApiStatus.Internal} should not be used, and could be subject to - * change at any time - * @param <T> - */ -public interface ListOption<T> extends OptionGroup, Option<List<T>> { - @Override - @NotNull ImmutableList<ListOptionEntry<T>> options(); - - @ApiStatus.Internal - ListOptionEntry<T> insertNewEntryToTop(); - - @ApiStatus.Internal - void insertEntry(int index, ListOptionEntry<?> entry); - - @ApiStatus.Internal - int indexOf(ListOptionEntry<?> entry); - - @ApiStatus.Internal - void removeEntry(ListOptionEntry<?> entry); - - @ApiStatus.Internal - void addRefreshListener(Runnable changedListener); - - static <T> Builder<T> createBuilder() { - return new ListOptionImpl.BuilderImpl<>(); - } - - @Deprecated - static <T> Builder<T> createBuilder(Class<T> typeClass) { - return createBuilder(); - } - - interface Builder<T> { - /** - * Sets name of the list, for UX purposes, a name should always be given, - * but isn't enforced. - * - * @see ListOption#name() - */ - Builder<T> name(@NotNull Component name); - - Builder<T> description(@NotNull OptionDescription description); - - /** - * Sets the value that is used when creating new entries - */ - Builder<T> initial(@NotNull T initialValue); - - Builder<T> controller(@NotNull Function<Option<T>, ControllerBuilder<T>> controller); - - /** - * Sets the controller for the option. - * This is how you interact and change the options. - * - * @see dev.isxander.yacl.gui.controllers - */ - Builder<T> customController(@NotNull Function<ListOptionEntry<T>, Controller<T>> control); - - /** - * Sets the binding for the option. - * Used for default, getter and setter. - * - * @see Binding - */ - Builder<T> binding(@NotNull Binding<List<T>> binding); - - /** - * Sets the binding for the option. - * Shorthand of {@link Binding#generic(Object, Supplier, Consumer)} - * - * @param def default value of the option, used to reset - * @param getter should return the current value of the option - * @param setter should set the option to the supplied value - * @see Binding - */ - Builder<T> binding(@NotNull List<T> def, @NotNull Supplier<@NotNull List<T>> getter, @NotNull Consumer<@NotNull List<T>> setter); - - /** - * Sets if the option can be configured - * - * @see Option#available() - */ - Builder<T> available(boolean available); - - /** - * Adds a flag to the option. - * Upon applying changes, all flags are executed. - * {@link Option#flags()} - */ - Builder<T> flag(@NotNull OptionFlag... flag); - - /** - * Adds a flag to the option. - * Upon applying changes, all flags are executed. - * {@link Option#flags()} - */ - Builder<T> flags(@NotNull Collection<OptionFlag> flags); - - /** - * Dictates if the group should be collapsed by default. - * If not set, it will not be collapsed by default. - * - * @see OptionGroup#collapsed() - */ - Builder<T> collapsed(boolean collapsible); - - /** - * Adds a listener to the option. Invoked upon changing any of the list's entries. - * - * @see Option#addListener(BiConsumer) - */ - ListOption.Builder<T> listener(@NotNull BiConsumer<Option<List<T>>, List<T>> listener); - - /** - * Adds multiple listeners to the option. Invoked upon changing of any of the list's entries. - * - * @see Option#addListener(BiConsumer) - */ - ListOption.Builder<T> listeners(@NotNull Collection<BiConsumer<Option<List<T>>, List<T>>> listeners); - - ListOption<T> build(); - } -} diff --git a/common/src/main/java/dev/isxander/yacl/api/ListOptionEntry.java b/common/src/main/java/dev/isxander/yacl/api/ListOptionEntry.java deleted file mode 100644 index 2679fa3..0000000 --- a/common/src/main/java/dev/isxander/yacl/api/ListOptionEntry.java +++ /dev/null @@ -1,18 +0,0 @@ -package dev.isxander.yacl.api; - -import com.google.common.collect.ImmutableSet; -import org.jetbrains.annotations.NotNull; - -public interface ListOptionEntry<T> extends Option<T> { - ListOption<T> parentGroup(); - - @Override - default @NotNull ImmutableSet<OptionFlag> flags() { - return parentGroup().flags(); - } - - @Override - default boolean available() { - return parentGroup().available(); - } -} diff --git a/common/src/main/java/dev/isxander/yacl/api/NameableEnum.java b/common/src/main/java/dev/isxander/yacl/api/NameableEnum.java deleted file mode 100644 index 4b04057..0000000 --- a/common/src/main/java/dev/isxander/yacl/api/NameableEnum.java +++ /dev/null @@ -1,10 +0,0 @@ -package dev.isxander.yacl.api; - -import net.minecraft.network.chat.Component; - -/** - * Used for the default value formatter of {@link dev.isxander.yacl.gui.controllers.cycling.EnumController} - */ -public interface NameableEnum { - Component getDisplayName(); -} diff --git a/common/src/main/java/dev/isxander/yacl/api/Option.java b/common/src/main/java/dev/isxander/yacl/api/Option.java deleted file mode 100644 index df48a62..0000000 --- a/common/src/main/java/dev/isxander/yacl/api/Option.java +++ /dev/null @@ -1,223 +0,0 @@ -package dev.isxander.yacl.api; - -import com.google.common.collect.ImmutableSet; -import dev.isxander.yacl.api.controller.ControllerBuilder; -import dev.isxander.yacl.impl.OptionImpl; -import net.minecraft.network.chat.Component; -import org.jetbrains.annotations.NotNull; - -import java.util.*; -import java.util.function.BiConsumer; -import java.util.function.Consumer; -import java.util.function.Function; -import java.util.function.Supplier; - -public interface Option<T> { - /** - * Name of the option - */ - @NotNull Component name(); - - @NotNull OptionDescription description(); - - /** - * Tooltip (or description) of the option. - * Rendered on hover. - */ - @Deprecated - @NotNull Component tooltip(); - - /** - * Widget provider for a type of option. - * - * @see dev.isxander.yacl.gui.controllers - */ - @NotNull Controller<T> controller(); - - /** - * Binding for the option. - * Controls setting, getting and default value. - * - * @see Binding - */ - @NotNull Binding<T> binding(); - - /** - * If the option can be configured - */ - boolean available(); - - /** - * Sets if the option can be configured after being built - * - * @see Option#available() - */ - void setAvailable(boolean available); - - /** - * Tasks that needs to be executed upon applying changes. - */ - @NotNull ImmutableSet<OptionFlag> flags(); - - /** - * Checks if the pending value is not equal to the current set value - */ - boolean changed(); - - /** - * Value in the GUI, ready to set the actual bound value or be undone. - */ - @NotNull T pendingValue(); - - /** - * Sets the pending value - */ - void requestSet(T value); - - /** - * Applies the pending value to the bound value. - * Cannot be undone. - * - * @return if there were changes to apply {@link Option#changed()} - */ - boolean applyValue(); - - /** - * Sets the pending value to the bound value. - */ - void forgetPendingValue(); - - /** - * Sets the pending value to the default bound value. - */ - void requestSetDefault(); - - /** - * Checks if the current pending value is equal to its default value - */ - boolean isPendingValueDefault(); - - default boolean canResetToDefault() { - return true; - } - - /** - * Adds a listener for when the pending value changes - */ - void addListener(BiConsumer<Option<T>, T> changedListener); - - static <T> Builder<T> createBuilder() { - return new OptionImpl.BuilderImpl<>(); - } - - /** - * Creates a builder to construct an {@link Option} - * - * @param <T> type of the option's value - * @param typeClass used to capture the type - */ - @Deprecated - static <T> Builder<T> createBuilder(Class<T> typeClass) { - return createBuilder(); - } - - interface Builder<T> { - /** - * Sets the name to be used by the option. - * - * @see Option#name() - */ - Builder<T> name(@NotNull Component name); - - /** - * Sets the description to be used by the option. - * @see OptionDescription - * @param description the static description. - * @return this builder - */ - Builder<T> description(@NotNull OptionDescription description); - - /** - * Sets the function to get the description by the option's current value. - * - * @see OptionDescription - * @param descriptionFunction the function to get the description by the option's current value. - * @return this builder - */ - Builder<T> description(@NotNull Function<T, OptionDescription> descriptionFunction); - - Builder<T> controller(@NotNull Function<Option<T>, ControllerBuilder<T>> controllerBuilder); - - /** - * Sets the controller for the option. - * This is how you interact and change the options. - * - * @see dev.isxander.yacl.gui.controllers - */ - Builder<T> customController(@NotNull Function<Option<T>, Controller<T>> control); - - /** - * Sets the binding for the option. - * Used for default, getter and setter. - * - * @see Binding - */ - Builder<T> binding(@NotNull Binding<T> binding); - - /** - * Sets the binding for the option. - * Shorthand of {@link Binding#generic(Object, Supplier, Consumer)} - * - * @param def default value of the option, used to reset - * @param getter should return the current value of the option - * @param setter should set the option to the supplied value - * @see Binding - */ - Builder<T> binding(@NotNull T def, @NotNull Supplier<@NotNull T> getter, @NotNull Consumer<@NotNull T> setter); - - /** - * Sets |
