From 13c7ba45ff201423eb8dba8a40cfb66ebb531439 Mon Sep 17 00:00:00 2001 From: Xander Date: Tue, 25 Apr 2023 16:28:41 +0100 Subject: Architectury! (#61) --- src/client/java/dev/isxander/yacl/api/Binding.java | 64 --- .../java/dev/isxander/yacl/api/ButtonOption.java | 66 --- .../java/dev/isxander/yacl/api/ConfigCategory.java | 94 ---- .../java/dev/isxander/yacl/api/Controller.java | 28 - .../java/dev/isxander/yacl/api/LabelOption.java | 41 -- .../java/dev/isxander/yacl/api/ListOption.java | 152 ------ .../dev/isxander/yacl/api/ListOptionEntry.java | 23 - .../java/dev/isxander/yacl/api/NameableEnum.java | 10 - src/client/java/dev/isxander/yacl/api/Option.java | 227 -------- .../java/dev/isxander/yacl/api/OptionAddable.java | 19 - .../java/dev/isxander/yacl/api/OptionFlag.java | 23 - .../java/dev/isxander/yacl/api/OptionGroup.java | 94 ---- .../dev/isxander/yacl/api/PlaceholderCategory.java | 52 -- .../dev/isxander/yacl/api/YetAnotherConfigLib.java | 107 ---- .../dev/isxander/yacl/api/utils/OptionUtils.java | 39 -- .../java/dev/isxander/yacl/gui/AbstractWidget.java | 107 ---- .../dev/isxander/yacl/gui/CategoryListWidget.java | 99 ---- .../java/dev/isxander/yacl/gui/CategoryWidget.java | 38 -- .../isxander/yacl/gui/ElementListWidgetExt.java | 179 ------- .../isxander/yacl/gui/LowProfileButtonWidget.java | 29 -- .../dev/isxander/yacl/gui/OptionListWidget.java | 568 --------------------- .../isxander/yacl/gui/RequireRestartScreen.java | 21 - .../dev/isxander/yacl/gui/SearchFieldWidget.java | 66 --- .../isxander/yacl/gui/TextScaledButtonWidget.java | 34 -- .../dev/isxander/yacl/gui/TooltipButtonWidget.java | 34 -- .../java/dev/isxander/yacl/gui/YACLScreen.java | 316 ------------ .../yacl/gui/controllers/ActionController.java | 120 ----- .../yacl/gui/controllers/BooleanController.java | 157 ------ .../yacl/gui/controllers/ColorController.java | 221 -------- .../yacl/gui/controllers/ControllerWidget.java | 170 ------ .../yacl/gui/controllers/LabelController.java | 193 ------- .../yacl/gui/controllers/ListEntryWidget.java | 133 ----- .../yacl/gui/controllers/TickBoxController.java | 120 ----- .../cycling/CyclingControllerElement.java | 60 --- .../controllers/cycling/CyclingListController.java | 79 --- .../gui/controllers/cycling/EnumController.java | 60 --- .../controllers/cycling/ICyclingController.java | 38 -- .../yacl/gui/controllers/package-info.java | 12 - .../controllers/slider/DoubleSliderController.java | 114 ----- .../controllers/slider/FloatSliderController.java | 114 ----- .../gui/controllers/slider/ISliderController.java | 54 -- .../slider/IntegerSliderController.java | 111 ---- .../controllers/slider/LongSliderController.java | 111 ---- .../slider/SliderControllerElement.java | 164 ------ .../yacl/gui/controllers/slider/package-info.java | 10 - .../gui/controllers/string/IStringController.java | 44 -- .../gui/controllers/string/StringController.java | 40 -- .../string/StringControllerElement.java | 408 --------------- .../string/number/DoubleFieldController.java | 104 ---- .../string/number/FloatFieldController.java | 104 ---- .../string/number/IntegerFieldController.java | 109 ---- .../string/number/LongFieldController.java | 109 ---- .../string/number/NumberFieldController.java | 69 --- .../controllers/string/number/package-info.java | 10 - .../java/dev/isxander/yacl/gui/utils/GuiUtils.java | 41 -- .../dev/isxander/yacl/impl/ButtonOptionImpl.java | 218 -------- .../dev/isxander/yacl/impl/ConfigCategoryImpl.java | 137 ----- .../dev/isxander/yacl/impl/GenericBindingImpl.java | 35 -- .../dev/isxander/yacl/impl/LabelOptionImpl.java | 154 ------ .../isxander/yacl/impl/ListOptionEntryImpl.java | 149 ------ .../dev/isxander/yacl/impl/ListOptionImpl.java | 338 ------------ .../dev/isxander/yacl/impl/OptionGroupImpl.java | 129 ----- .../java/dev/isxander/yacl/impl/OptionImpl.java | 304 ----------- .../yacl/impl/PlaceholderCategoryImpl.java | 99 ---- .../yacl/impl/YetAnotherConfigLibImpl.java | 122 ----- .../mixin/client/AbstractSelectionListMixin.java | 26 - .../yacl/mixin/client/OptionInstanceAccessor.java | 13 - 67 files changed, 7333 deletions(-) delete mode 100644 src/client/java/dev/isxander/yacl/api/Binding.java delete mode 100644 src/client/java/dev/isxander/yacl/api/ButtonOption.java delete mode 100644 src/client/java/dev/isxander/yacl/api/ConfigCategory.java delete mode 100644 src/client/java/dev/isxander/yacl/api/Controller.java delete mode 100644 src/client/java/dev/isxander/yacl/api/LabelOption.java delete mode 100644 src/client/java/dev/isxander/yacl/api/ListOption.java delete mode 100644 src/client/java/dev/isxander/yacl/api/ListOptionEntry.java delete mode 100644 src/client/java/dev/isxander/yacl/api/NameableEnum.java delete mode 100644 src/client/java/dev/isxander/yacl/api/Option.java delete mode 100644 src/client/java/dev/isxander/yacl/api/OptionAddable.java delete mode 100644 src/client/java/dev/isxander/yacl/api/OptionFlag.java delete mode 100644 src/client/java/dev/isxander/yacl/api/OptionGroup.java delete mode 100644 src/client/java/dev/isxander/yacl/api/PlaceholderCategory.java delete mode 100644 src/client/java/dev/isxander/yacl/api/YetAnotherConfigLib.java delete mode 100644 src/client/java/dev/isxander/yacl/api/utils/OptionUtils.java delete mode 100644 src/client/java/dev/isxander/yacl/gui/AbstractWidget.java delete mode 100644 src/client/java/dev/isxander/yacl/gui/CategoryListWidget.java delete mode 100644 src/client/java/dev/isxander/yacl/gui/CategoryWidget.java delete mode 100644 src/client/java/dev/isxander/yacl/gui/ElementListWidgetExt.java delete mode 100644 src/client/java/dev/isxander/yacl/gui/LowProfileButtonWidget.java delete mode 100644 src/client/java/dev/isxander/yacl/gui/OptionListWidget.java delete mode 100644 src/client/java/dev/isxander/yacl/gui/RequireRestartScreen.java delete mode 100644 src/client/java/dev/isxander/yacl/gui/SearchFieldWidget.java delete mode 100644 src/client/java/dev/isxander/yacl/gui/TextScaledButtonWidget.java delete mode 100644 src/client/java/dev/isxander/yacl/gui/TooltipButtonWidget.java delete mode 100644 src/client/java/dev/isxander/yacl/gui/YACLScreen.java delete mode 100644 src/client/java/dev/isxander/yacl/gui/controllers/ActionController.java delete mode 100644 src/client/java/dev/isxander/yacl/gui/controllers/BooleanController.java delete mode 100644 src/client/java/dev/isxander/yacl/gui/controllers/ColorController.java delete mode 100644 src/client/java/dev/isxander/yacl/gui/controllers/ControllerWidget.java delete mode 100644 src/client/java/dev/isxander/yacl/gui/controllers/LabelController.java delete mode 100644 src/client/java/dev/isxander/yacl/gui/controllers/ListEntryWidget.java delete mode 100644 src/client/java/dev/isxander/yacl/gui/controllers/TickBoxController.java delete mode 100644 src/client/java/dev/isxander/yacl/gui/controllers/cycling/CyclingControllerElement.java delete mode 100644 src/client/java/dev/isxander/yacl/gui/controllers/cycling/CyclingListController.java delete mode 100644 src/client/java/dev/isxander/yacl/gui/controllers/cycling/EnumController.java delete mode 100644 src/client/java/dev/isxander/yacl/gui/controllers/cycling/ICyclingController.java delete mode 100644 src/client/java/dev/isxander/yacl/gui/controllers/package-info.java delete mode 100644 src/client/java/dev/isxander/yacl/gui/controllers/slider/DoubleSliderController.java delete mode 100644 src/client/java/dev/isxander/yacl/gui/controllers/slider/FloatSliderController.java delete mode 100644 src/client/java/dev/isxander/yacl/gui/controllers/slider/ISliderController.java delete mode 100644 src/client/java/dev/isxander/yacl/gui/controllers/slider/IntegerSliderController.java delete mode 100644 src/client/java/dev/isxander/yacl/gui/controllers/slider/LongSliderController.java delete mode 100644 src/client/java/dev/isxander/yacl/gui/controllers/slider/SliderControllerElement.java delete mode 100644 src/client/java/dev/isxander/yacl/gui/controllers/slider/package-info.java delete mode 100644 src/client/java/dev/isxander/yacl/gui/controllers/string/IStringController.java delete mode 100644 src/client/java/dev/isxander/yacl/gui/controllers/string/StringController.java delete mode 100644 src/client/java/dev/isxander/yacl/gui/controllers/string/StringControllerElement.java delete mode 100644 src/client/java/dev/isxander/yacl/gui/controllers/string/number/DoubleFieldController.java delete mode 100644 src/client/java/dev/isxander/yacl/gui/controllers/string/number/FloatFieldController.java delete mode 100644 src/client/java/dev/isxander/yacl/gui/controllers/string/number/IntegerFieldController.java delete mode 100644 src/client/java/dev/isxander/yacl/gui/controllers/string/number/LongFieldController.java delete mode 100644 src/client/java/dev/isxander/yacl/gui/controllers/string/number/NumberFieldController.java delete mode 100644 src/client/java/dev/isxander/yacl/gui/controllers/string/number/package-info.java delete mode 100644 src/client/java/dev/isxander/yacl/gui/utils/GuiUtils.java delete mode 100644 src/client/java/dev/isxander/yacl/impl/ButtonOptionImpl.java delete mode 100644 src/client/java/dev/isxander/yacl/impl/ConfigCategoryImpl.java delete mode 100644 src/client/java/dev/isxander/yacl/impl/GenericBindingImpl.java delete mode 100644 src/client/java/dev/isxander/yacl/impl/LabelOptionImpl.java delete mode 100644 src/client/java/dev/isxander/yacl/impl/ListOptionEntryImpl.java delete mode 100644 src/client/java/dev/isxander/yacl/impl/ListOptionImpl.java delete mode 100644 src/client/java/dev/isxander/yacl/impl/OptionGroupImpl.java delete mode 100644 src/client/java/dev/isxander/yacl/impl/OptionImpl.java delete mode 100644 src/client/java/dev/isxander/yacl/impl/PlaceholderCategoryImpl.java delete mode 100644 src/client/java/dev/isxander/yacl/impl/YetAnotherConfigLibImpl.java delete mode 100644 src/client/java/dev/isxander/yacl/mixin/client/AbstractSelectionListMixin.java delete mode 100644 src/client/java/dev/isxander/yacl/mixin/client/OptionInstanceAccessor.java (limited to 'src/client/java/dev/isxander/yacl') diff --git a/src/client/java/dev/isxander/yacl/api/Binding.java b/src/client/java/dev/isxander/yacl/api/Binding.java deleted file mode 100644 index ba5a2c0..0000000 --- a/src/client/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.client.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 { - 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 Binding generic(T def, Supplier getter, Consumer 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 Binding minecraft(OptionInstance minecraftOption) { - Validate.notNull(minecraftOption, "`minecraftOption` must not be null"); - - return new GenericBindingImpl<>( - ((OptionInstanceAccessor) (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 Binding immutable(T value) { - Validate.notNull(value, "`value` must not be null"); - - return new GenericBindingImpl<>( - value, - () -> value, - changed -> {} - ); - } -} diff --git a/src/client/java/dev/isxander/yacl/api/ButtonOption.java b/src/client/java/dev/isxander/yacl/api/ButtonOption.java deleted file mode 100644 index 88e1c4b..0000000 --- a/src/client/java/dev/isxander/yacl/api/ButtonOption.java +++ /dev/null @@ -1,66 +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> { - /** - * Action to be executed upon button press - */ - BiConsumer action(); - - static dev.isxander.yacl.api.ButtonOption.Builder createBuilder() { - return new ButtonOptionImpl.BuilderImpl(); - } - - interface Builder { - /** - * Sets the name to be used by the option. - * - * @see Option#name() - */ - dev.isxander.yacl.api.ButtonOption.Builder name(@NotNull Component name); - - /** - * 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()}. - */ - dev.isxander.yacl.api.ButtonOption.Builder tooltip(@NotNull Component... tooltips); - - dev.isxander.yacl.api.ButtonOption.Builder action(@NotNull BiConsumer action); - - /** - * Action to be executed upon button press - * - * @see ButtonOption#action() - */ - @Deprecated - dev.isxander.yacl.api.ButtonOption.Builder action(@NotNull Consumer action); - - /** - * Sets if the option can be configured - * - * @see Option#available() - */ - dev.isxander.yacl.api.ButtonOption.Builder available(boolean available); - - /** - * Sets the controller for the option. - * This is how you interact and change the options. - * - * @see dev.isxander.yacl.gui.controllers - */ - dev.isxander.yacl.api.ButtonOption.Builder controller(@NotNull Function>> control); - - ButtonOption build(); - } -} diff --git a/src/client/java/dev/isxander/yacl/api/ConfigCategory.java b/src/client/java/dev/isxander/yacl/api/ConfigCategory.java deleted file mode 100644 index 7764479..0000000 --- a/src/client/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 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> 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 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/src/client/java/dev/isxander/yacl/api/Controller.java b/src/client/java/dev/isxander/yacl/api/Controller.java deleted file mode 100644 index 0b8e2ed..0000000 --- a/src/client/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 { - /** - * Gets the dedicated {@link Option} for this controller - */ - Option 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 widgetDimension); -} diff --git a/src/client/java/dev/isxander/yacl/api/LabelOption.java b/src/client/java/dev/isxander/yacl/api/LabelOption.java deleted file mode 100644 index 05c7214..0000000 --- a/src/client/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 { - @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 dev.isxander.yacl.api.LabelOption.Builder createBuilder() { - return new LabelOptionImpl.BuilderImpl(); - } - - interface Builder { - /** - * Appends a line to the label - */ - dev.isxander.yacl.api.LabelOption.Builder line(@NotNull Component line); - - /** - * Appends multiple lines to the label - */ - dev.isxander.yacl.api.LabelOption.Builder lines(@NotNull Collection lines); - - LabelOption build(); - } -} diff --git a/src/client/java/dev/isxander/yacl/api/ListOption.java b/src/client/java/dev/isxander/yacl/api/ListOption.java deleted file mode 100644 index afba8ee..0000000 --- a/src/client/java/dev/isxander/yacl/api/ListOption.java +++ /dev/null @@ -1,152 +0,0 @@ -package dev.isxander.yacl.api; - -import com.google.common.collect.ImmutableList; -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 - */ -public interface ListOption extends OptionGroup, Option> { - @Override - @NotNull ImmutableList> options(); - - /** - * Class of the entry type - */ - @NotNull Class elementTypeClass(); - - @ApiStatus.Internal - ListOptionEntry 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 Builder createBuilder(Class typeClass) { - return new ListOptionImpl.BuilderImpl<>(typeClass); - } - - interface Builder { - /** - * Sets name of the list, for UX purposes, a name should always be given, - * but isn't enforced. - * - * @see ListOption#name() - */ - Builder name(@NotNull Component name); - - /** - * Sets the tooltip to be used by the list. It is displayed like a normal - * group when you hover over the name. Entries do not allow a tooltip. - *

- * 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 dev.isxander.yacl.api.ListOption.Builder#build()}. - */ - Builder tooltip(@NotNull Component... tooltips); - - /** - * Sets the value that is used when creating new entries - */ - Builder initial(@NotNull T initialValue); - - /** - * Sets the controller for the option. - * This is how you interact and change the options. - * - * @see dev.isxander.yacl.gui.controllers - */ - Builder controller(@NotNull Function, Controller> control); - - /** - * Sets the binding for the option. - * Used for default, getter and setter. - * - * @see Binding - */ - Builder binding(@NotNull Binding> 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 binding(@NotNull List def, @NotNull Supplier<@NotNull List> getter, @NotNull Consumer<@NotNull List> setter); - - /** - * Sets if the option can be configured - * - * @see Option#available() - */ - Builder available(boolean available); - - /** - * Adds a flag to the option. - * Upon applying changes, all flags are executed. - * {@link Option#flags()} - */ - Builder flag(@NotNull OptionFlag... flag); - - /** - * Adds a flag to the option. - * Upon applying changes, all flags are executed. - * {@link Option#flags()} - */ - Builder flags(@NotNull Collection flags); - - /** - * Dictates if the group should be collapsed by default. - * If not set, it will not be collapsed by default. - * - * @see OptionGroup#collapsed() - */ - Builder collapsed(boolean collapsible); - - /** - * Adds a listener to the option. Invoked upon changing any of the list's entries. - * - * @see Option#addListener(BiConsumer) - */ - ListOption.Builder listener(@NotNull BiConsumer>, List> listener); - - /** - * Adds multiple listeners to the option. Invoked upon changing of any of the list's entries. - * - * @see Option#addListener(BiConsumer) - */ - ListOption.Builder listeners(@NotNull Collection>, List>> listeners); - - ListOption build(); - } -} diff --git a/src/client/java/dev/isxander/yacl/api/ListOptionEntry.java b/src/client/java/dev/isxander/yacl/api/ListOptionEntry.java deleted file mode 100644 index e0a3424..0000000 --- a/src/client/java/dev/isxander/yacl/api/ListOptionEntry.java +++ /dev/null @@ -1,23 +0,0 @@ -package dev.isxander.yacl.api; - -import com.google.common.collect.ImmutableSet; -import org.jetbrains.annotations.NotNull; - -public interface ListOptionEntry extends Option { - ListOption parentGroup(); - - @Override - default @NotNull Class typeClass() { - return parentGroup().elementTypeClass(); - } - - @Override - default @NotNull ImmutableSet flags() { - return parentGroup().flags(); - } - - @Override - default boolean available() { - return parentGroup().available(); - } -} diff --git a/src/client/java/dev/isxander/yacl/api/NameableEnum.java b/src/client/java/dev/isxander/yacl/api/NameableEnum.java deleted file mode 100644 index 4b04057..0000000 --- a/src/client/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/src/client/java/dev/isxander/yacl/api/Option.java b/src/client/java/dev/isxander/yacl/api/Option.java deleted file mode 100644 index a6c0311..0000000 --- a/src/client/java/dev/isxander/yacl/api/Option.java +++ /dev/null @@ -1,227 +0,0 @@ -package dev.isxander.yacl.api; - -import com.google.common.collect.ImmutableSet; -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 { - /** - * Name of the option - */ - @NotNull Component name(); - - /** - * Tooltip (or description) of the option. - * Rendered on hover. - */ - @NotNull Component tooltip(); - - /** - * Widget provider for a type of option. - * - * @see dev.isxander.yacl.gui.controllers - */ - @NotNull Controller controller(); - - /** - * Binding for the option. - * Controls setting, getting and default value. - * - * @see Binding - */ - @NotNull Binding 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); - - /** - * Class of the option type. - * Used by some controllers. - */ - @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 - */ - 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, T> changedListener); - - /** - * Creates a builder to construct an {@link Option} - * - * @param type of the option's value - * @param typeClass used to capture the type - */ - static Builder createBuilder(Class typeClass) { - return new OptionImpl.BuilderImpl<>(typeClass); - } - - interface Builder { - /** - * Sets the name to be used by the option. - * - * @see Option#name() - */ - Builder name(@NotNull Component name); - - /** - * 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()}. - */ - Builder tooltip(@NotNull Function 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 tooltip(@NotNull Function... tooltipGetter); - - /** - * 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 Builder#build()}. - */ - Builder tooltip(@NotNull Component... tooltips); - - /** - * Sets the controller for the option. - * This is how you interact and change the options. - * - * @see dev.isxander.yacl.gui.controllers - */ - Builder controller(@NotNull Function, Controller> control); - - /** - * Sets the binding for the option. - * Used for default, getter and setter. - * - * @see Binding - */ - Builder binding(@NotNull Binding 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 binding(@NotNull T def, @NotNull Supplier<@NotNull T> getter, @NotNull Consumer<@NotNull T> setter); - - /** - * Sets if the option can be configured - * - * @see Option#available() - */ - Builder available(boolean available); - - /** - * Adds a flag to the option. - * Upon applying changes, all flags are executed. - * {@link Option#flags()} - */ - Builder flag(@NotNull OptionFlag... flag); - - /** - * Adds a flag to the option. - * Upon applying changes, all flags are executed. - * {@link Option#flags()} - */ - Builder flags(@NotNull Collection flags); - - /** - * Instantly invokes the binder's setter when modified in the GUI. - * Prevents the user from undoing the change - *

- * Does not support {@link Option#flags()}! - */ - Builder instant(boolean instant); - - /** - * Adds a listener to the option. Invoked upon changing the pending value. - * - * @see Option#addListener(BiConsumer) - */ - Builder listener(@NotNull BiConsumer, T> listener); - - /** - * Adds multiple listeners to the option. Invoked upon changing the pending value. - * - * @see Option#addListener(BiConsumer) - */ - Builder listeners(@NotNull Collection, T>> listeners); - - Option build(); - } -} diff --git a/src/client/java/dev/isxander/yacl/api/OptionAddable.java b/src/client/java/dev/isxander/yacl/api/OptionAddable.java deleted file mode 100644 index 57be06c..0000000 --- a/src/client/java/dev/isxander/yacl/api/OptionAddable.java +++ /dev/null @@ -1,19 +0,0 @@ -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> options); -} diff --git a/src/client/java/dev/isxander/yacl/api/OptionFlag.java b/src/client/java/dev/isxander/yacl/api/OptionFlag.java deleted file mode 100644 index 51d57e4..0000000 --- a/src/client/java/dev/isxander/yacl/api/OptionFlag.java +++ /dev/null @@ -1,23 +0,0 @@ -package dev.isxander.yacl.api; - -import dev.isxander.yacl.gui.RequireRestartScreen; -import net.minecraft.client.Minecraft; - -import java.util.function.Consumer; - -/** - * Code that is executed upon certain options being applied. - * Each flag is executed only once per save, no matter the amount of options with the flag. - */ -@FunctionalInterface -public interface OptionFlag extends Consumer { - /** Warns the user that a game restart is required for the changes to take effect */ - OptionFlag GAME_RESTART = client -> client.setScreen(new RequireRestartScreen(client.screen)); - - /** Reloads chunks upon applying (F3+A) */ - OptionFlag RELOAD_CHUNKS = client -> client.levelRenderer.allChanged(); - - OptionFlag WORLD_RENDER_UPDATE = client -> client.levelRenderer.needsUpdate(); - - OptionFlag ASSET_RELOAD = Minecraft::delayTextureReload; -} diff --git a/src/client/java/dev/isxander/yacl/api/OptionGroup.java b/src/client/java/dev/isxander/yacl/api/OptionGroup.java deleted file mode 100644 index 4fe43c7..0000000 --- a/src/client/java/dev/isxander/yacl/api/OptionGroup.java +++ /dev/null @@ -1,94 +0,0 @@ -package dev.isxander.yacl.api; - -import com.google.common.collect.ImmutableList; -import dev.isxander.yacl.impl.OptionGroupImpl; -import net.minecraft.network.chat.Component; -import org.jetbrains.annotations.NotNull; - -import java.util.Collection; - -/** - * Serves as a separator between multiple chunks of options - * that may be too similar or too few to be placed in a separate {@link ConfigCategory}. - * Or maybe you just want your config to feel less dense. - */ -public interface OptionGroup { - /** - * Name of the option group, displayed as a separator in the option lists. - * Can be empty. - */ - Component name(); - - /** - * Tooltip displayed on hover. - */ - Component tooltip(); - - /** - * List of all options in the group - */ - @NotNull ImmutableList> options(); - - /** - * Dictates if the group should be collapsed by default. - */ - boolean collapsed(); - - /** - * Always false when using the {@link Builder} - * used to not render the separator if true - */ - boolean isRoot(); - - /** - * Creates a builder to construct a {@link OptionGroup} - */ - static Builder createBuilder() { - return new OptionGroupImpl.BuilderImpl(); - } - - interface Builder extends OptionAddable { - /** - * Sets name of the group, can be {@link Component#empty()} to just separate options, like sodium. - * - * @see OptionGroup#name() - */ - Builder name(@NotNull Component name); - - /** - * Sets the tooltip to be used by the option group. - * Can be invoked twice to append more lines. - * No need to wrap the Component yourself, the gui does this itself. - * - * @param tooltips Component lines - merged with a new-line on {@link Builder#build()}. - */ - Builder tooltip(@NotNull Component... tooltips); - - /** - * Adds an option to group. - * To construct an option, use {@link Option#createBuilder(Class)} - * - * @see OptionGroup#options() - */ - @Override - Builder option(@NotNull Option option); - - /** - * Adds multiple options to group. - * To construct an option, use {@link Option#createBuilder(Class)} - * - * @see OptionGroup#options() - */ - @Override - Builder options(@NotNull Collection> options); - - /** - * Dictates if the group should be collapsed by default - * - * @see OptionGroup#collapsed() - */ - Builder collapsed(boolean collapsible); - - OptionGroup build(); - } -} diff --git a/src/client/java/dev/isxander/yacl/api/PlaceholderCategory.java b/src/client/java/dev/isxander/yacl/api/PlaceholderCategory.java deleted file mode 100644 index 3641fad..0000000 --- a/src/client/java/dev/isxander/yacl/api/PlaceholderCategory.java +++ /dev/null @@ -1,52 +0,0 @@ -package dev.isxander.yacl.api; - -import dev.isxander.yacl.gui.YACLScreen; -import dev.isxander.yacl.impl.PlaceholderCategoryImpl; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.screens.Screen; -import net.minecraft.network.chat.Component; -import org.jetbrains.annotations.NotNull; - -import java.util.function.BiFunction; - -/** - * A placeholder category that actually just opens another screen, - * instead of displaying options - */ -public interface PlaceholderCategory extends ConfigCategory { - /** - * Function to create a screen to open upon changing to this category - */ - BiFunction screen(); - - static Builder createBuilder() { - return new PlaceholderCategoryImpl.BuilderImpl(); - } - - interface Builder { - /** - * Sets name of the category - * - * @see ConfigCategory#name() - */ - Builder name(@NotNull Component name); - - /** - * Sets the tooltip to be used by the category. - * Can be invoked twice to append more lines. - * No need to wrap the Component yourself, the gui does this itself. - * - * @param tooltips Component lines - merged with a new-line on {@link dev.isxander.yacl.api.PlaceholderCategory.Builder#build()}. - */ - Builder tooltip(@NotNull Component... tooltips); - - /** - * Screen to open upon selecting this category - * - * @see PlaceholderCategory#screen() - */ - Builder screen(@NotNull BiFunction screenFunction); - - PlaceholderCategory build(); - } -} diff --git a/src/client/java/dev/isxander/yacl/api/YetAnotherConfigLib.java b/src/client/java/dev/isxander/yacl/api/YetAnotherConfigLib.java deleted file mode 100644 index c6da1d1..0000000 --- a/src/client/java/dev/isxander/yacl/api/YetAnotherConfigLib.java +++ /dev/null @@ -1,107 +0,0 @@ -package dev.isxander.yacl.api; - -import com.google.common.collect.ImmutableList; -import dev.isxander.yacl.config.ConfigInstance; -import dev.isxander.yacl.gui.YACLScreen; -import dev.isxander.yacl.impl.YetAnotherConfigLibImpl; -import net.minecraft.client.gui.screens.Screen; -import net.minecraft.network.chat.Component; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.Collection; -import java.util.function.Consumer; - -/** - * Main class of the mod. - * Contains all data and used to provide a {@link Screen} - */ -public interface YetAnotherConfigLib { - /** - * Title of the GUI. Only used for Minecraft narration. - */ - Component title(); - - /** - * Gets all config categories. - */ - ImmutableList categories(); - - /** - * Ran when changes are saved. Can be used to save config to a file etc. - */ - Runnable saveFunction(); - - /** - * Ran every time the YACL screen initialises. Can be paired with FAPI to add custom widgets. - */ - Consumer initConsumer(); - - /** - * Generates a Screen to display based on this instance. - * - * @param parent parent screen to open once closed - */ - Screen generateScreen(@Nullable Screen parent); - - /** - * Creates a builder to construct YACL - */ - static Builder createBuilder() { - return new YetAnotherConfigLibImpl.BuilderImpl(); - } - - /** - * Creates an instance using a {@link ConfigInstance} which autofills the save() builder method. - * This also takes an easy functional interface that provides defaults and config to help build YACL bindings. - */ - static YetAnotherConfigLib create(ConfigInstance configInstance, ConfigBackedBuilder builder) { - return builder.build(configInstance.getDefaults(), configInstance.getConfig(), createBuilder().save(configInstance::save)).build(); - } - - interface Builder { - /** - * Sets title of GUI for Minecraft narration - * - * @see YetAnotherConfigLib#title() - */ - Builder title(@NotNull Component title); - - /** - * Adds a new category. - * To create a category you need to use {@link ConfigCategory#createBuilder()} - * - * @see YetAnotherConfigLib#categories() - */ - Builder category(@NotNull ConfigCategory category); - - /** - * Adds multiple categories at once. - * To create a category you need to use {@link ConfigCategory#createBuilder()} - * - * @see YetAnotherConfigLib#categories() - */ - Builder categories(@NotNull Collection categories); - - /** - * Used to define a save function for when user clicks the Save Changes button - * - * @see YetAnotherConfigLib#saveFunction() - */ - Builder save(@NotNull Runnable saveFunction); - - /** - * Defines a consumer that is accepted every time the YACL screen initialises - * - * @see YetAnotherConfigLib#initConsumer() - */ - Builder screenInit(@NotNull Consumer initConsumer); - - YetAnotherConfigLib build(); - } - - @FunctionalInterface - interface ConfigBackedBuilder { - YetAnotherConfigLib.Builder build(T defaults, T config, YetAnotherConfigLib.Builder builder); - } -} diff --git a/src/client/java/dev/isxander/yacl/api/utils/OptionUtils.java b/src/client/java/dev/isxander/yacl/api/utils/OptionUtils.java deleted file mode 100644 index 22032bd..0000000 --- a/src/client/java/dev/isxander/yacl/api/utils/OptionUtils.java +++ /dev/null @@ -1,39 +0,0 @@ -package dev.isxander.yacl.api.utils; - -import dev.isxander.yacl.api.*; - -import java.util.function.Consumer; -import java.util.function.Function; - -public class OptionUtils { - /** - * Consumes all options, ignoring groups and categories. - * When consumer returns true, this function stops iterating. - */ - public static void consumeOptions(YetAnotherConfigLib yacl, Function, Boolean> consumer) { - for (ConfigCategory category : yacl.categories()) { - for (OptionGroup group : category.groups()) { - if (group instanceof ListOption list) { - if (consumer.apply(list)) return; - } else { - for (Option option : group.options()) { - if (consumer.apply(option)) return; - } - } - - } - } - } - - /** - * Consumes all options, ignoring groups and categories. - * - * @see OptionUtils#consumeOptions(YetAnotherConfigLib, Function) - */ - public static void forEachOptions(YetAnotherConfigLib yacl, Consumer> consumer) { - consumeOptions(yacl, (opt) -> { - consumer.accept(opt); - return false; - }); - } -} diff --git a/src/client/java/dev/isxander/yacl/gui/AbstractWidget.java b/src/client/java/dev/isxander/yacl/gui/AbstractWidget.java deleted file mode 100644 index c6d2b09..0000000 --- a/src/client/java/dev/isxander/yacl/gui/AbstractWidget.java +++ /dev/null @@ -1,107 +0,0 @@ -package dev.isxander.yacl.gui; - -import com.mojang.blaze3d.systems.RenderSystem; -import com.mojang.blaze3d.vertex.PoseStack; -import dev.isxander.yacl.api.utils.Dimension; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.Font; -import net.minecraft.client.gui.GuiComponent; -import net.minecraft.client.gui.components.Renderable; -import net.minecraft.client.gui.components.events.GuiEventListener; -import net.minecraft.client.gui.narration.NarratableEntry; -import net.minecraft.client.gui.narration.NarrationElementOutput; -import net.minecraft.client.renderer.GameRenderer; -import net.minecraft.client.resources.sounds.SimpleSoundInstance; -import net.minecraft.sounds.SoundEvents; - -import java.awt.Color; - -public abstract class AbstractWidget implements GuiEventListener, Renderable, NarratableEntry { - protected final Minecraft client = Minecraft.getInstance(); - protected final Font textRenderer = client.font; - protected final int inactiveColor = 0xFFA0A0A0; - - private Dimension dim; - - public AbstractWidget(Dimension dim) { - this.dim = dim; - } - - public void postRender(PoseStack matrices, int mouseX, int mouseY, float delta) { - - } - - public boolean canReset() { - return false; - } - - @Override - public boolean isMouseOver(double mouseX, double mouseY) { - if (dim == null) return false; - return this.dim.isPointInside((int) mouseX, (int) mouseY); - } - - public void setDimension(Dimension dim) { - this.dim = dim; - } - - public Dimension getDimension() { - return dim; - } - - @Override - public NarrationPriority narrationPriority() { - return NarrationPriority.NONE; - } - - public void unfocus() { - - } - - public boolean matchesSearch(String query) { - return true; - } - - @Override - public void updateNarration(NarrationElementOutput builder) { - - } - - protected void drawButtonRect(PoseStack matrices, int x1, int y1, int x2, int y2, boolean hovered, boolean enabled) { - if (x1 > x2) { - int xx1 = x1; - x1 = x2; - x2 = xx1; - } - if (y1 > y2) { - int yy1 = y1; - y1 = y2; - y2 = yy1; - } - int width = x2 - x1; - int height = y2 - y1; - - RenderSystem.setShader(GameRenderer::getPositionTexShader); - RenderSystem.setShaderTexture(0, net.minecraft.client.gui.components.AbstractWidget.WIDGETS_LOCATION); - RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); - int i = !enabled ? 0 : hovered ? 2 : 1; - RenderSystem.enableBlend(); - RenderSystem.defaultBlendFunc(); - RenderSystem.enableDepthTest(); - GuiComponent.blit(matrices, x1, y1, 0, 0, 46 + i * 20, width / 2, height, 256, 256); - GuiComponent.blit(matrices, x1 + width / 2, y1, 0, 200 - width / 2f, 46 + i * 20, width / 2, height, 256, 256); - } - - protected int multiplyColor(int hex, float amount) { - Color color = new Color(hex, true); - - return new Color(Math.max((int)(color.getRed() * amount), 0), - Math.max((int)(color.getGreen() * amount), 0), - Math.max((int)(color.getBlue() * amount), 0), - color.getAlpha()).getRGB(); - } - - public void playDownSound() { - Minecraft.getInstance().getSoundManager().play(SimpleSoundInstance.forUI(SoundEvents.UI_BUTTON_CLICK, 1.0F)); - } -} diff --git a/src/client/java/dev/isxander/yacl/gui/CategoryListWidget.java b/src/client/java/dev/isxander/yacl/gui/CategoryListWidget.java deleted file mode 100644 index 41286ff..0000000 --- a/src/client/java/dev/isxander/yacl/gui/CategoryListWidget.java +++ /dev/null @@ -1,99 +0,0 @@ -package dev.isxander.yacl.gui; - -import com.google.common.collect.ImmutableList; -import com.mojang.blaze3d.systems.RenderSystem; -import com.mojang.blaze3d.vertex.PoseStack; -import dev.isxander.yacl.api.ConfigCategory; -import dev.isxander.yacl.gui.utils.GuiUtils; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.components.events.GuiEventListener; -import net.minecraft.client.gui.narration.NarratableEntry; - -import java.util.List; - -public class CategoryListWidget extends ElementListWidgetExt { - private final YACLScreen yaclScreen; - - public CategoryListWidget(Minecraft client, YACLScreen yaclScreen, int screenWidth, int screenHeight) { - super(client, 0, 0, screenWidth / 3, yaclScreen.searchFieldWidget.getY() - 5, true); - this.yaclScreen = yaclScreen; - setRenderBackground(false); - setRenderTopAndBottom(false); - - for (ConfigCategory category : yaclScreen.config.categories()) { - addEntry(new CategoryEntry(category)); - } - } - - @Override - public void render(PoseStack matrices, int mouseX, int mouseY, float delta) { - GuiUtils.enableScissor(0, 0, width, height); - super.render(matrices, mouseX, mouseY, delta); - RenderSystem.disableScissor(); - } - - @Override - public int getRowWidth() { - return Math.min(width - width / 10, 396); - } - - @Override - public int getRowLeft() { - return super.getRowLeft() - 2; - } - - @Override - protected int getScrollbarPosition() { - return width - 2; - } - - @Override - protected void renderBackground(PoseStack matrices) { - - } - - public class CategoryEntry extends Entry { - private final CategoryWidget categoryButton; - public final int categoryIndex; - - public CategoryEntry(ConfigCategory category) { - this.categoryIndex = yaclScreen.config.categories().indexOf(category); - categoryButton = new CategoryWidget( - yaclScreen, - category, - categoryIndex, - getRowLeft(), 0, - getRowWidth(), 20 - ); - } - - @Override - public void render(PoseStack matrices, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta) { - if (mouseY > y1) { - mouseY = -20; - } - - categoryButton.setY(y); - categoryButton.render(matrices, mouseX, mouseY, tickDelta); - } - - public void postRender(PoseStack matrices, int mouseX, int mouseY, float tickDelta) { - categoryButton.renderHoveredTooltip(matrices); - } - - @Override - public int getItemHeight() { - return 21; - } - - @Override - public List children() { - return ImmutableList.of(categoryButton); - } - - @Override - public List narratables() { - return ImmutableList.of(categoryButton); - } - } -} diff --git a/src/client/java/dev/isxander/yacl/gui/CategoryWidget.java b/src/client/java/dev/isxander/yacl/gui/CategoryWidget.java deleted file mode 100644 index 60817a2..0000000 --- a/src/client/java/dev/isxander/yacl/gui/CategoryWidget.java +++ /dev/null @@ -1,38 +0,0 @@ -package dev.isxander.yacl.gui; - -import dev.isxander.yacl.api.ConfigCategory; -import net.minecraft.client.sounds.SoundManager; - -public class CategoryWidget extends TooltipButtonWidget { - private final int categoryIndex; - - public CategoryWidget(YACLScreen screen, ConfigCategory category, int categoryIndex, int x, int y, int width, int height) { - super(screen, x, y, width, height, category.name(), category.tooltip(), btn -> { - screen.searchFieldWidget.setValue(""); - screen.changeCategory(categoryIndex); - }); - this.categoryIndex = categoryIndex; - } - - private boolean isCurrentCategory() { - return ((YACLScreen) screen).getCurrentCategoryIdx() == categoryIndex; - } - - @Override - protected int getTextureY() { - int i = 1; - if (!this.active) { - i = 0; - } else if (this.isHoveredOrFocused() || isCurrentCategory()) { - i = 2; - } - - return 46 + i * 20; - } - - @Override - public void playDownSound(SoundManager soundManager) { - if (!isCurrentCategory()) - super.playDownSound(soundManager); - } -} diff --git a/src/client/java/dev/isxander/yacl/gui/ElementListWidgetExt.java b/src/client/java/dev/isxander/yacl/gui/ElementListWidgetExt.java deleted file mode 100644 index 46503a6..0000000 --- a/src/client/java/dev/isxander/yacl/gui/ElementListWidgetExt.java +++ /dev/null @@ -1,179 +0,0 @@ -package dev.isxander.yacl.gui; - -import com.mojang.blaze3d.platform.InputConstants; -import com.mojang.blaze3d.vertex.PoseStack; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.components.ContainerObjectSelectionList; -import net.minecraft.client.gui.components.events.GuiEventListener; -import net.minecraft.util.Mth; -import org.jetbrains.annotations.Nullable; - -import java.util.Iterator; - -public class ElementListWidgetExt> extends ContainerObjectSelectionList { - protected final int x, y; - - private double smoothScrollAmount = getScrollAmount(); - private boolean returnSmoothAmount = false; - private final boolean doSmoothScrolling; - - public ElementListWidgetExt(Minecraft client, int x, int y, int width, int height, boolean smoothScrolling) { - super(client, width, height, y, y + height, 22); - this.x = this.x0 = x; - this.y = y; - this.x1 = this.x0 + width; - this.doSmoothScrolling = smoothScrolling; - } - - @Override - public boolean mouseScrolled(double mouseX, double mouseY, double amount) { - // default implementation bases scroll step from total height of entries, this is constant - this.setScrollAmount(this.getScrollAmount() - amount * 20); - return true; - } - - @Override - protected void renderBackground(PoseStack matrices) { - // render transparent background if in-game. - setRenderBackground(minecraft.level == null); - if (minecraft.level != null) - fill(matrices, x0, y0, x1, y1, 0x6B000000); - } - - @Override - protected int getScrollbarPosition() { - // default implementation does not respect left/right - return this.x1 - 2; - } - - @Override - public void render(PoseStack matrices, int mouseX, int mouseY, float delta) { - smoothScrollAmount = Mth.lerp(Minecraft.getInstance().getDeltaFrameTime() * 0.5, smoothScrollAmount, getScrollAmount()); - returnSmoothAmount = true; - super.render(matrices, mouseX, mouseY, delta); - returnSmoothAmount = false; - } - - /** - * awful code to only use smooth scroll state when rendering, - * not other code that needs target scroll amount - */ - @Override - public double getScrollAmount() { - if (returnSmoothAmount && doSmoothScrolling) - return smoothScrollAmount; - - return super.getScrollAmount(); - } - - protected void resetSmoothScrolling() { - this.smoothScrollAmount = getScrollAmount(); - } - - public void postRender(PoseStack matrices, int mouseX, int mouseY, float delta) { - for (E entry : children()) { - entry.postRender(matrices, mouseX, mouseY, delta); - } - } - - @Nullable - @Override - protected E getEntryAtPosition(double x, double y) { - y += getScrollAmount(); - - if (x < this.x0 || x > this.x1) - return null; - - int currentY = this.y0 - headerHeight + 4; - for (E entry : children()) { - if (y >= currentY && y <= currentY + entry.getItemHeight()) { - return entry; - } - - currentY += entry.getItemHeight(); - } - - return null; - } - - /* - below code is licensed from cloth-config under LGPL3 - modified to inherit vanilla's EntryListWidget and use yarn mappings - - code is responsible for having dynamic item heights - */ - - @Override - protected int getMaxPosition() { - return children().stream().map(E::getItemHeight).reduce(0, Integer::sum) + headerHeight; - } - - @Override - protected void centerScrollOn(E entry) { - double d = (this.height) / -2d; - for (int i = 0; i < this.children().indexOf(entry) && i < this.getItemCount(); i++) - d += children().get(i).getItemHeight(); - this.setScrollAmount(d); - } - - @Override - protected int getRowTop(int index) { - int integer = y0 + 4 - (int) this.getScrollAmount() + headerHeight; - for (int i = 0; i < children().size() && i < index; i++) - integer += children().get(i).getItemHeight(); - return integer; - } - - @Override - protected void renderList(PoseStack matrices, int mouseX, int mouseY, float delta) { - int left = this.getRowLeft(); - int right = this.getRowWidth(); - int count = this.getItemCount(); - - for(int i = 0; i < count; ++i) { - E entry = children().get(i); - int top = this.getRowTop(i); - int bottom = top + entry.getItemHeight(); - int entryHeight = entry.getItemHeight() - 4; - if (bottom >= this.y0 && top <= this.y1) { - this.renderItem(matrices, mouseX, mouseY, delta, i, left, top, right, entryHeight); - } - } - } - - /* END cloth config code */ - - public abstract static class Entry> extends ContainerObjectSelectionList.Entry { - @Override - public boolean mouseClicked(double mouseX, double mouseY, int button) { - for (GuiEventListener child : this.children()) { - if (child.mouseClicked(mouseX, mouseY, button)) { - if (button == InputConstants.MOUSE_BUTTON_LEFT) - this.setDragging(true); - return true; - } - } - - return false; - } - - @Override - public boolean mouseDragged(double mouseX, double mouseY, int button, double deltaX, double deltaY) { - if (isDragging() && button == InputConstants.MOUSE_BUTTON_LEFT) { - for (GuiEventListener child : this.children()) { - if (child.mouseDragged(mouseX, mouseY, button, deltaX, deltaY)) - return true; - } - } - return false; - } - - public void postRender(PoseStack matrices, int mouseX, int mouseY, float delta) { - - } - - public int getItemHeight() { - return 22; - } - } -} diff --git a/src/client/java/dev/isxander/yacl/gui/LowProfileButtonWidget.java b/src/client/java/dev/isxander/yacl/gui/LowProfileButtonWidget.java deleted file mode 100644 index 7e17aac..0000000 --- a/src/client/java/dev/isxander/yacl/gui/LowProfileButtonWidget.java +++ /dev/null @@ -1,29 +0,0 @@ -package dev.isxander.yacl.gui; - -import com.mojang.blaze3d.vertex.PoseStack; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.components.Button; -import net.minecraft.client.gui.components.Tooltip; -import net.minecraft.network.chat.Component; -import net.minecraft.util.Mth; - -public class LowProfileButtonWidget extends Button { - public LowProfileButtonWidget(int x, int y, int width, int height, Component message, OnPress onPress) { - super(x, y, width, height, message, onPress, DEFAULT_NARRATION); - } - - public LowProfileButtonWidget(int x, int y, int width, int height, Component message, OnPress onPress, Tooltip tooltip) { - this(x, y, width, height, message, onPress); - setTooltip(tooltip); - } - - @Override - public void renderWidget(PoseStack matrices, int mouseX, int mouseY, float deltaTicks) { - if (!isHoveredOrFocused() || !active) { - int j = this.active ? 0xFFFFFF : 0xA0A0A0; - this.renderString(matrices, Minecraft.getInstance().font, j); - } else { - super.renderWidget(matrices, mouseX, mouseY, deltaTicks); - } - } -} diff --git a/src/client/java/dev/isxander/yacl/gui/OptionListWidget.java b/src/client/java/dev/isxander/yacl/gui/OptionListWidget.java deleted file mode 100644 index 8f96ddf..0000000 --- a/src/client/java/dev/isxander/yacl/gui/OptionListWidget.java +++ /dev/null @@ -1,568 +0,0 @@ -package dev.isxander.yacl.gui; - -import com.google.common.collect.ImmutableList; -import com.mojang.blaze3d.vertex.PoseStack; -import dev.isxander.yacl.api.*; -import dev.isxander.yacl.api.utils.Dimension; -import dev.isxander.yacl.impl.utils.YACLConstants; -import net.minecraft.ChatFormatting; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.Font; -import net.minecraft.client.gui.components.MultiLineLabel; -import net.minecraft.client.gui.components.events.GuiEventListener; -import net.minecraft.client.gui.narration.NarratableEntry; -import net.minecraft.client.gui.narration.NarratedElem