From 3e36feeef60e56ef8cb7f737ac8eeab9fbcd6abb Mon Sep 17 00:00:00 2001 From: isXander Date: Sat, 3 Jun 2023 23:10:03 +0100 Subject: Change package and modid to yacl3 and yet_another_config_lib_3 respectively --- .../main/java/dev/isxander/yacl3/api/Binding.java | 64 +++ .../java/dev/isxander/yacl3/api/ButtonOption.java | 50 ++ .../dev/isxander/yacl3/api/ConfigCategory.java | 94 ++++ .../java/dev/isxander/yacl3/api/Controller.java | 28 + .../java/dev/isxander/yacl3/api/LabelOption.java | 41 ++ .../java/dev/isxander/yacl3/api/ListOption.java | 146 ++++++ .../dev/isxander/yacl3/api/ListOptionEntry.java | 18 + .../java/dev/isxander/yacl3/api/NameableEnum.java | 10 + .../main/java/dev/isxander/yacl3/api/Option.java | 223 ++++++++ .../java/dev/isxander/yacl3/api/OptionAddable.java | 19 + .../dev/isxander/yacl3/api/OptionDescription.java | 161 ++++++ .../java/dev/isxander/yacl3/api/OptionFlag.java | 23 + .../java/dev/isxander/yacl3/api/OptionGroup.java | 90 ++++ .../isxander/yacl3/api/PlaceholderCategory.java | 55 ++ .../isxander/yacl3/api/YetAnotherConfigLib.java | 107 ++++ .../api/controller/BooleanControllerBuilder.java | 16 + .../api/controller/ColorControllerBuilder.java | 14 + .../yacl3/api/controller/ControllerBuilder.java | 9 + .../controller/CyclingListControllerBuilder.java | 15 + .../controller/DoubleFieldControllerBuilder.java | 10 + .../controller/DoubleSliderControllerBuilder.java | 10 + .../api/controller/EnumControllerBuilder.java | 12 + .../controller/FloatFieldControllerBuilder.java | 10 + .../controller/FloatSliderControllerBuilder.java | 10 + .../controller/IntegerFieldControllerBuilder.java | 10 + .../controller/IntegerSliderControllerBuilder.java | 10 + .../api/controller/LongFieldControllerBuilder.java | 10 + .../controller/LongSliderControllerBuilder.java | 10 + .../controller/NumberFieldControllerBuilder.java | 7 + .../api/controller/SliderControllerBuilder.java | 6 + .../api/controller/StringControllerBuilder.java | 10 + .../api/controller/TickBoxControllerBuilder.java | 10 + .../api/controller/ValueFormattableController.java | 9 + .../dev/isxander/yacl3/api/utils/Dimension.java | 33 ++ .../isxander/yacl3/api/utils/MutableDimension.java | 11 + .../dev/isxander/yacl3/api/utils/OptionUtils.java | 39 ++ .../dev/isxander/yacl3/config/ConfigEntry.java | 11 + .../dev/isxander/yacl3/config/ConfigInstance.java | 48 ++ .../isxander/yacl3/config/GsonConfigInstance.java | 212 ++++++++ .../dev/isxander/yacl3/gui/AbstractWidget.java | 94 ++++ .../isxander/yacl3/gui/DescriptionWithName.java | 11 + .../isxander/yacl3/gui/ElementListWidgetExt.java | 222 ++++++++ .../java/dev/isxander/yacl3/gui/ImageRenderer.java | 386 ++++++++++++++ .../isxander/yacl3/gui/LowProfileButtonWidget.java | 28 + .../yacl3/gui/OptionDescriptionWidget.java | 215 ++++++++ .../dev/isxander/yacl3/gui/OptionListWidget.java | 572 +++++++++++++++++++++ .../isxander/yacl3/gui/RequireRestartScreen.java | 21 + .../dev/isxander/yacl3/gui/SearchFieldWidget.java | 61 +++ .../isxander/yacl3/gui/TextScaledButtonWidget.java | 34 ++ .../isxander/yacl3/gui/TooltipButtonWidget.java | 25 + .../java/dev/isxander/yacl3/gui/YACLScreen.java | 358 +++++++++++++ .../isxander/yacl3/gui/YACLTooltipPositioner.java | 48 ++ .../yacl3/gui/controllers/ActionController.java | 120 +++++ .../yacl3/gui/controllers/BooleanController.java | 157 ++++++ .../yacl3/gui/controllers/ColorController.java | 220 ++++++++ .../yacl3/gui/controllers/ControllerWidget.java | 157 ++++++ .../yacl3/gui/controllers/LabelController.java | 193 +++++++ .../yacl3/gui/controllers/ListEntryWidget.java | 128 +++++ .../yacl3/gui/controllers/TickBoxController.java | 119 +++++ .../cycling/CyclingControllerElement.java | 60 +++ .../controllers/cycling/CyclingListController.java | 79 +++ .../gui/controllers/cycling/EnumController.java | 43 ++ .../controllers/cycling/ICyclingController.java | 38 ++ .../yacl3/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 | 157 ++++++ .../yacl3/gui/controllers/slider/package-info.java | 10 + .../gui/controllers/string/IStringController.java | 44 ++ .../gui/controllers/string/StringController.java | 37 ++ .../string/StringControllerElement.java | 403 +++++++++++++++ .../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 + .../isxander/yacl3/gui/tab/ListHolderWidget.java | 116 +++++ .../yacl3/gui/tab/ScrollableNavigationBar.java | 110 ++++ .../java/dev/isxander/yacl3/gui/tab/TabExt.java | 9 + .../dev/isxander/yacl3/gui/utils/GuiUtils.java | 32 ++ .../dev/isxander/yacl3/impl/ButtonOptionImpl.java | 195 +++++++ .../isxander/yacl3/impl/ConfigCategoryImpl.java | 135 +++++ .../isxander/yacl3/impl/GenericBindingImpl.java | 35 ++ .../dev/isxander/yacl3/impl/LabelOptionImpl.java | 158 ++++++ .../isxander/yacl3/impl/ListOptionEntryImpl.java | 154 ++++++ .../dev/isxander/yacl3/impl/ListOptionImpl.java | 325 ++++++++++++ .../isxander/yacl3/impl/OptionDescriptionImpl.java | 146 ++++++ .../dev/isxander/yacl3/impl/OptionGroupImpl.java | 121 +++++ .../java/dev/isxander/yacl3/impl/OptionImpl.java | 257 +++++++++ .../yacl3/impl/PlaceholderCategoryImpl.java | 99 ++++ .../yacl3/impl/YetAnotherConfigLibImpl.java | 122 +++++ .../controller/AbstractControllerBuilderImpl.java | 12 + .../controller/BooleanControllerBuilderImpl.java | 56 ++ .../controller/ColorControllerBuilderImpl.java | 27 + .../CyclingListControllerBuilderImpl.java | 43 ++ .../DoubleFieldControllerBuilderImpl.java | 50 ++ .../DoubleSliderControllerBuilderImpl.java | 43 ++ .../impl/controller/EnumControllerBuilderImpl.java | 35 ++ .../FloatFieldControllerBuilderImpl.java | 50 ++ .../FloatSliderControllerBuilderImpl.java | 43 ++ .../IntegerFieldControllerBuilderImpl.java | 50 ++ .../IntegerSliderControllerBuilderImpl.java | 43 ++ .../controller/LongFieldControllerBuilderImpl.java | 50 ++ .../LongSliderControllerBuilderImpl.java | 43 ++ .../controller/StringControllerBuilderImpl.java | 17 + .../controller/TickBoxControllerBuilderImpl.java | 17 + .../yacl3/impl/utils/DimensionIntegerImpl.java | 115 +++++ .../isxander/yacl3/impl/utils/YACLConstants.java | 13 + .../yacl3/mixin/AbstractSelectionListMixin.java | 25 + .../yacl3/mixin/ContainerEventHandlerMixin.java | 31 ++ .../dev/isxander/yacl3/mixin/MinecraftMixin.java | 16 + .../yacl3/mixin/OptionInstanceAccessor.java | 13 + 116 files changed, 9538 insertions(+) create mode 100644 common/src/main/java/dev/isxander/yacl3/api/Binding.java create mode 100644 common/src/main/java/dev/isxander/yacl3/api/ButtonOption.java create mode 100644 common/src/main/java/dev/isxander/yacl3/api/ConfigCategory.java create mode 100644 common/src/main/java/dev/isxander/yacl3/api/Controller.java create mode 100644 common/src/main/java/dev/isxander/yacl3/api/LabelOption.java create mode 100644 common/src/main/java/dev/isxander/yacl3/api/ListOption.java create mode 100644 common/src/main/java/dev/isxander/yacl3/api/ListOptionEntry.java create mode 100644 common/src/main/java/dev/isxander/yacl3/api/NameableEnum.java create mode 100644 common/src/main/java/dev/isxander/yacl3/api/Option.java create mode 100644 common/src/main/java/dev/isxander/yacl3/api/OptionAddable.java create mode 100644 common/src/main/java/dev/isxander/yacl3/api/OptionDescription.java create mode 100644 common/src/main/java/dev/isxander/yacl3/api/OptionFlag.java create mode 100644 common/src/main/java/dev/isxander/yacl3/api/OptionGroup.java create mode 100644 common/src/main/java/dev/isxander/yacl3/api/PlaceholderCategory.java create mode 100644 common/src/main/java/dev/isxander/yacl3/api/YetAnotherConfigLib.java create mode 100644 common/src/main/java/dev/isxander/yacl3/api/controller/BooleanControllerBuilder.java create mode 100644 common/src/main/java/dev/isxander/yacl3/api/controller/ColorControllerBuilder.java create mode 100644 common/src/main/java/dev/isxander/yacl3/api/controller/ControllerBuilder.java create mode 100644 common/src/main/java/dev/isxander/yacl3/api/controller/CyclingListControllerBuilder.java create mode 100644 common/src/main/java/dev/isxander/yacl3/api/controller/DoubleFieldControllerBuilder.java create mode 100644 common/src/main/java/dev/isxander/yacl3/api/controller/DoubleSliderControllerBuilder.java create mode 100644 common/src/main/java/dev/isxander/yacl3/api/controller/EnumControllerBuilder.java create mode 100644 common/src/main/java/dev/isxander/yacl3/api/controller/FloatFieldControllerBuilder.java create mode 100644 common/src/main/java/dev/isxander/yacl3/api/controller/FloatSliderControllerBuilder.java create mode 100644 common/src/main/java/dev/isxander/yacl3/api/controller/IntegerFieldControllerBuilder.java create mode 100644 common/src/main/java/dev/isxander/yacl3/api/controller/IntegerSliderControllerBuilder.java create mode 100644 common/src/main/java/dev/isxander/yacl3/api/controller/LongFieldControllerBuilder.java create mode 100644 common/src/main/java/dev/isxander/yacl3/api/controller/LongSliderControllerBuilder.java create mode 100644 common/src/main/java/dev/isxander/yacl3/api/controller/NumberFieldControllerBuilder.java create mode 100644 common/src/main/java/dev/isxander/yacl3/api/controller/SliderControllerBuilder.java create mode 100644 common/src/main/java/dev/isxander/yacl3/api/controller/StringControllerBuilder.java create mode 100644 common/src/main/java/dev/isxander/yacl3/api/controller/TickBoxControllerBuilder.java create mode 100644 common/src/main/java/dev/isxander/yacl3/api/controller/ValueFormattableController.java create mode 100644 common/src/main/java/dev/isxander/yacl3/api/utils/Dimension.java create mode 100644 common/src/main/java/dev/isxander/yacl3/api/utils/MutableDimension.java create mode 100644 common/src/main/java/dev/isxander/yacl3/api/utils/OptionUtils.java create mode 100644 common/src/main/java/dev/isxander/yacl3/config/ConfigEntry.java create mode 100644 common/src/main/java/dev/isxander/yacl3/config/ConfigInstance.java create mode 100644 common/src/main/java/dev/isxander/yacl3/config/GsonConfigInstance.java create mode 100644 common/src/main/java/dev/isxander/yacl3/gui/AbstractWidget.java create mode 100644 common/src/main/java/dev/isxander/yacl3/gui/DescriptionWithName.java create mode 100644 common/src/main/java/dev/isxander/yacl3/gui/ElementListWidgetExt.java create mode 100644 common/src/main/java/dev/isxander/yacl3/gui/ImageRenderer.java create mode 100644 common/src/main/java/dev/isxander/yacl3/gui/LowProfileButtonWidget.java create mode 100644 common/src/main/java/dev/isxander/yacl3/gui/OptionDescriptionWidget.java create mode 100644 common/src/main/java/dev/isxander/yacl3/gui/OptionListWidget.java create mode 100644 common/src/main/java/dev/isxander/yacl3/gui/RequireRestartScreen.java create mode 100644 common/src/main/java/dev/isxander/yacl3/gui/SearchFieldWidget.java create mode 100644 common/src/main/java/dev/isxander/yacl3/gui/TextScaledButtonWidget.java create mode 100644 common/src/main/java/dev/isxander/yacl3/gui/TooltipButtonWidget.java create mode 100644 common/src/main/java/dev/isxander/yacl3/gui/YACLScreen.java create mode 100644 common/src/main/java/dev/isxander/yacl3/gui/YACLTooltipPositioner.java create mode 100644 common/src/main/java/dev/isxander/yacl3/gui/controllers/ActionController.java create mode 100644 common/src/main/java/dev/isxander/yacl3/gui/controllers/BooleanController.java create mode 100644 common/src/main/java/dev/isxander/yacl3/gui/controllers/ColorController.java create mode 100644 common/src/main/java/dev/isxander/yacl3/gui/controllers/ControllerWidget.java create mode 100644 common/src/main/java/dev/isxander/yacl3/gui/controllers/LabelController.java create mode 100644 common/src/main/java/dev/isxander/yacl3/gui/controllers/ListEntryWidget.java create mode 100644 common/src/main/java/dev/isxander/yacl3/gui/controllers/TickBoxController.java create mode 100644 common/src/main/java/dev/isxander/yacl3/gui/controllers/cycling/CyclingControllerElement.java create mode 100644 common/src/main/java/dev/isxander/yacl3/gui/controllers/cycling/CyclingListController.java create mode 100644 common/src/main/java/dev/isxander/yacl3/gui/controllers/cycling/EnumController.java create mode 100644 common/src/main/java/dev/isxander/yacl3/gui/controllers/cycling/ICyclingController.java create mode 100644 common/src/main/java/dev/isxander/yacl3/gui/controllers/package-info.java create mode 100644 common/src/main/java/dev/isxander/yacl3/gui/controllers/slider/DoubleSliderController.java create mode 100644 common/src/main/java/dev/isxander/yacl3/gui/controllers/slider/FloatSliderController.java create mode 100644 common/src/main/java/dev/isxander/yacl3/gui/controllers/slider/ISliderController.java create mode 100644 common/src/main/java/dev/isxander/yacl3/gui/controllers/slider/IntegerSliderController.java create mode 100644 common/src/main/java/dev/isxander/yacl3/gui/controllers/slider/LongSliderController.java create mode 100644 common/src/main/java/dev/isxander/yacl3/gui/controllers/slider/SliderControllerElement.java create mode 100644 common/src/main/java/dev/isxander/yacl3/gui/controllers/slider/package-info.java create mode 100644 common/src/main/java/dev/isxander/yacl3/gui/controllers/string/IStringController.java create mode 100644 common/src/main/java/dev/isxander/yacl3/gui/controllers/string/StringController.java create mode 100644 common/src/main/java/dev/isxander/yacl3/gui/controllers/string/StringControllerElement.java create mode 100644 common/src/main/java/dev/isxander/yacl3/gui/controllers/string/number/DoubleFieldController.java create mode 100644 common/src/main/java/dev/isxander/yacl3/gui/controllers/string/number/FloatFieldController.java create mode 100644 common/src/main/java/dev/isxander/yacl3/gui/controllers/string/number/IntegerFieldController.java create mode 100644 common/src/main/java/dev/isxander/yacl3/gui/controllers/string/number/LongFieldController.java create mode 100644 common/src/main/java/dev/isxander/yacl3/gui/controllers/string/number/NumberFieldController.java create mode 100644 common/src/main/java/dev/isxander/yacl3/gui/controllers/string/number/package-info.java create mode 100644 common/src/main/java/dev/isxander/yacl3/gui/tab/ListHolderWidget.java create mode 100644 common/src/main/java/dev/isxander/yacl3/gui/tab/ScrollableNavigationBar.java create mode 100644 common/src/main/java/dev/isxander/yacl3/gui/tab/TabExt.java create mode 100644 common/src/main/java/dev/isxander/yacl3/gui/utils/GuiUtils.java create mode 100644 common/src/main/java/dev/isxander/yacl3/impl/ButtonOptionImpl.java create mode 100644 common/src/main/java/dev/isxander/yacl3/impl/ConfigCategoryImpl.java create mode 100644 common/src/main/java/dev/isxander/yacl3/impl/GenericBindingImpl.java create mode 100644 common/src/main/java/dev/isxander/yacl3/impl/LabelOptionImpl.java create mode 100644 common/src/main/java/dev/isxander/yacl3/impl/ListOptionEntryImpl.java create mode 100644 common/src/main/java/dev/isxander/yacl3/impl/ListOptionImpl.java create mode 100644 common/src/main/java/dev/isxander/yacl3/impl/OptionDescriptionImpl.java create mode 100644 common/src/main/java/dev/isxander/yacl3/impl/OptionGroupImpl.java create mode 100644 common/src/main/java/dev/isxander/yacl3/impl/OptionImpl.java create mode 100644 common/src/main/java/dev/isxander/yacl3/impl/PlaceholderCategoryImpl.java create mode 100644 common/src/main/java/dev/isxander/yacl3/impl/YetAnotherConfigLibImpl.java create mode 100644 common/src/main/java/dev/isxander/yacl3/impl/controller/AbstractControllerBuilderImpl.java create mode 100644 common/src/main/java/dev/isxander/yacl3/impl/controller/BooleanControllerBuilderImpl.java create mode 100644 common/src/main/java/dev/isxander/yacl3/impl/controller/ColorControllerBuilderImpl.java create mode 100644 common/src/main/java/dev/isxander/yacl3/impl/controller/CyclingListControllerBuilderImpl.java create mode 100644 common/src/main/java/dev/isxander/yacl3/impl/controller/DoubleFieldControllerBuilderImpl.java create mode 100644 common/src/main/java/dev/isxander/yacl3/impl/controller/DoubleSliderControllerBuilderImpl.java create mode 100644 common/src/main/java/dev/isxander/yacl3/impl/controller/EnumControllerBuilderImpl.java create mode 100644 common/src/main/java/dev/isxander/yacl3/impl/controller/FloatFieldControllerBuilderImpl.java create mode 100644 common/src/main/java/dev/isxander/yacl3/impl/controller/FloatSliderControllerBuilderImpl.java create mode 100644 common/src/main/java/dev/isxander/yacl3/impl/controller/IntegerFieldControllerBuilderImpl.java create mode 100644 common/src/main/java/dev/isxander/yacl3/impl/controller/IntegerSliderControllerBuilderImpl.java create mode 100644 common/src/main/java/dev/isxander/yacl3/impl/controller/LongFieldControllerBuilderImpl.java create mode 100644 common/src/main/java/dev/isxander/yacl3/impl/controller/LongSliderControllerBuilderImpl.java create mode 100644 common/src/main/java/dev/isxander/yacl3/impl/controller/StringControllerBuilderImpl.java create mode 100644 common/src/main/java/dev/isxander/yacl3/impl/controller/TickBoxControllerBuilderImpl.java create mode 100644 common/src/main/java/dev/isxander/yacl3/impl/utils/DimensionIntegerImpl.java create mode 100644 common/src/main/java/dev/isxander/yacl3/impl/utils/YACLConstants.java create mode 100644 common/src/main/java/dev/isxander/yacl3/mixin/AbstractSelectionListMixin.java create mode 100644 common/src/main/java/dev/isxander/yacl3/mixin/ContainerEventHandlerMixin.java create mode 100644 common/src/main/java/dev/isxander/yacl3/mixin/MinecraftMixin.java create mode 100644 common/src/main/java/dev/isxander/yacl3/mixin/OptionInstanceAccessor.java (limited to 'common/src/main/java/dev/isxander/yacl3') diff --git a/common/src/main/java/dev/isxander/yacl3/api/Binding.java b/common/src/main/java/dev/isxander/yacl3/api/Binding.java new file mode 100644 index 0000000..f41b78b --- /dev/null +++ b/common/src/main/java/dev/isxander/yacl3/api/Binding.java @@ -0,0 +1,64 @@ +package dev.isxander.yacl3.api; + +import dev.isxander.yacl3.impl.GenericBindingImpl; +import dev.isxander.yacl3.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 { + 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/common/src/main/java/dev/isxander/yacl3/api/ButtonOption.java b/common/src/main/java/dev/isxander/yacl3/api/ButtonOption.java new file mode 100644 index 0000000..943f9ac --- /dev/null +++ b/common/src/main/java/dev/isxander/yacl3/api/ButtonOption.java @@ -0,0 +1,50 @@ +package dev.isxander.yacl3.api; + +import dev.isxander.yacl3.gui.YACLScreen; +import dev.isxander.yacl3.impl.ButtonOptionImpl; +import net.minecraft.network.chat.Component; +import org.jetbrains.annotations.NotNull; + +import java.util.function.BiConsumer; +import java.util.function.Consumer; + +public interface ButtonOption extends Option> { + /** + * Action to be executed upon button press + */ + BiConsumer 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 action); + + /** + * Action to be executed upon button press + * + * @see ButtonOption#action() + */ + @Deprecated + Builder action(@NotNull Consumer 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/yacl3/api/ConfigCategory.java b/common/src/main/java/dev/isxander/yacl3/api/ConfigCategory.java new file mode 100644 index 0000000..d47b3ce --- /dev/null +++ b/common/src/main/java/dev/isxander/yacl3/api/ConfigCategory.java @@ -0,0 +1,94 @@ +package dev.isxander.yacl3.api; + +import com.google.common.collect.ImmutableList; +import dev.isxander.yacl3.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/common/src/main/java/dev/isxander/yacl3/api/Controller.java b/common/src/main/java/dev/isxander/yacl3/api/Controller.java new file mode 100644 index 0000000..25e4465 --- /dev/null +++ b/common/src/main/java/dev/isxander/yacl3/api/Controller.java @@ -0,0 +1,28 @@ +package dev.isxander.yacl3.api; + +import dev.isxander.yacl3.api.utils.Dimension; +import dev.isxander.yacl3.gui.AbstractWidget; +import dev.isxander.yacl3.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/common/src/main/java/dev/isxander/yacl3/api/LabelOption.java b/common/src/main/java/dev/isxander/yacl3/api/LabelOption.java new file mode 100644 index 0000000..a5f015e --- /dev/null +++ b/common/src/main/java/dev/isxander/yacl3/api/LabelOption.java @@ -0,0 +1,41 @@ +package dev.isxander.yacl3.api; + +import dev.isxander.yacl3.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.yacl3.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 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 lines); + + LabelOption build(); + } +} diff --git a/common/src/main/java/dev/isxander/yacl3/api/ListOption.java b/common/src/main/java/dev/isxander/yacl3/api/ListOption.java new file mode 100644 index 0000000..8094ee7 --- /dev/null +++ b/common/src/main/java/dev/isxander/yacl3/api/ListOption.java @@ -0,0 +1,146 @@ +package dev.isxander.yacl3.api; + +import com.google.common.collect.ImmutableList; +import dev.isxander.yacl3.api.controller.ControllerBuilder; +import dev.isxander.yacl3.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(); + + @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() { + return new ListOptionImpl.BuilderImpl<>(); + } + + @Deprecated + static Builder createBuilder(Class typeClass) { + return createBuilder(); + } + + 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); + + Builder description(@NotNull OptionDescription description); + + /** + * Sets the value that is used when creating new entries + */ + Builder initial(@NotNull T initialValue); + + Builder controller(@NotNull Function, ControllerBuilder> controller); + + /** + * Sets the controller for the option. + * This is how you interact and change the options. + * + * @see dev.isxander.yacl3.gui.controllers + */ + Builder customController(@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/common/src/main/java/dev/isxander/yacl3/api/ListOptionEntry.java b/common/src/main/java/dev/isxander/yacl3/api/ListOptionEntry.java new file mode 100644 index 0000000..23ec657 --- /dev/null +++ b/common/src/main/java/dev/isxander/yacl3/api/ListOptionEntry.java @@ -0,0 +1,18 @@ +package dev.isxander.yacl3.api; + +import com.google.common.collect.ImmutableSet; +import org.jetbrains.annotations.NotNull; + +public interface ListOptionEntry extends Option { + ListOption parentGroup(); + + @Override + default @NotNull ImmutableSet flags() { + return parentGroup().flags(); + } + + @Override + default boolean available() { + return parentGroup().available(); + } +} diff --git a/common/src/main/java/dev/isxander/yacl3/api/NameableEnum.java b/common/src/main/java/dev/isxander/yacl3/api/NameableEnum.java new file mode 100644 index 0000000..5a50207 --- /dev/null +++ b/common/src/main/java/dev/isxander/yacl3/api/NameableEnum.java @@ -0,0 +1,10 @@ +package dev.isxander.yacl3.api; + +import net.minecraft.network.chat.Component; + +/** + * Used for the default value formatter of {@link dev.isxander.yacl3.gui.controllers.cycling.EnumController} + */ +public interface NameableEnum { + Component getDisplayName(); +} diff --git a/common/src/main/java/dev/isxander/yacl3/api/Option.java b/common/src/main/java/dev/isxander/yacl3/api/Option.java new file mode 100644 index 0000000..31b7756 --- /dev/null +++ b/common/src/main/java/dev/isxander/yacl3/api/Option.java @@ -0,0 +1,223 @@ +package dev.isxander.yacl3.api; + +import com.google.common.collect.ImmutableSet; +import dev.isxander.yacl3.api.controller.ControllerBuilder; +import dev.isxander.yacl3.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(); + + @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.yacl3.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); + + /** + * 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); + + static Builder createBuilder() { + return new OptionImpl.BuilderImpl<>(); + } + + /** + * Creates a builder to construct an {@link Option} + * + * @param type of the option's value + * @param typeClass used to capture the type + */ + @Deprecated + static Builder createBuilder(Class typeClass) { + return createBuilder(); + } + + interface Builder { + /** + * Sets the name to be used by the option. + * + * @see Option#name() + */ + Builder name(@NotNull Component name); + + /** + * Sets the description to be used by the option. + * @see OptionDescription + * @param description the static description. + * @return this builder + */ + Builder 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 description(@NotNull Function descriptionFunction); + + Builder controller(@NotNull Function, ControllerBuilder> controllerBuilder); + + /** + * Sets the controller for the option. + * This is how you interact and change the options. + * + * @see dev.isxander.yacl3.gui.controllers + */ + Builder customController(@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/common/src/main/java/dev/isxander/yacl3/api/OptionAddable.java b/common/src/main/java/dev/isxander/yacl3/api/OptionAddable.java new file mode 100644 index 0000000..97ab352 --- /dev/null +++ b/common/src/main/java/dev/isxander/yacl3/api/OptionAddable.java @@ -0,0 +1,19 @@ +package dev.isxander.yacl3.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/common/src/main/java/dev/isxander/yacl3/api/OptionDescription.java b/common/src/main/java/dev/isxander/yacl3/api/OptionDescription.java new file mode 100644 index 0000000..40f1d68 --- /dev/null +++ b/common/src/main/java/dev/isxander/yacl3/api/OptionDescription.java @@ -0,0 +1,161 @@ +package dev.isxander.yacl3.api; + +import dev.isxander.yacl3.gui.ImageRenderer; +import dev.isxander.yacl3.impl.OptionDescriptionImpl; +import net.minecraft.network.chat.CommonComponents; +import net.minecraft.network.chat.Component; +import net.minecraft.resources.ResourceLocation; + +import java.nio.file.Path; +import java.util.Collection; +import java.util.Optional; +import java.util.concurrent.CompletableFuture; +import java.util.function.Supplier; + +/** + * Provides all information for the description panel in the GUI. + * This provides no functional benefit, and is purely for UX. + */ +public interface OptionDescription { + /** + * The description of the option, this is automatically wrapped and supports all styling, + * including {@link net.minecraft.network.chat.ClickEvent}s and {@link net.minecraft.network.chat.HoverEvent}s. + * @return The description of the option, with all lines merged with \n. + */ + Component text(); + + /** + * The image to display with the description. If the Optional is empty, no image has been provided. + * Usually, the image renderers are constructed asynchronously, so this method returns a {@link CompletableFuture}. + *

+ * Image renderers are cached throughout the whole lifecycle of the game, and should not be generated more than once + * per image. See {@link ImageRenderer#getOrMakeAsync(ResourceLocation, Supplier)} for implementation details. + */ + CompletableFuture> image(); + + /** + * @return a new builder for an {@link OptionDescription}. + */ + static Builder createBuilder() { + return new OptionDescriptionImpl.BuilderImpl(); + } + + static OptionDescription of(Component... description) { + return createBuilder().text(description).build(); + } + + OptionDescription EMPTY = new OptionDescriptionImpl(CommonComponents.EMPTY, CompletableFuture.completedFuture(Optional.empty())); + + interface Builder { + /** + * Appends lines to the main description of the option. This can be called multiple times. + * On {@link Builder#build()}, the lines are merged with \n. + * @see OptionDescription#text() + * + * @param description the lines to append to the description. + * @return this builder + */ + Builder text(Component... description); + + /** + * Appends lines to the main description of the option. This can be called multiple times. + * On {@link Builder#build()}, the lines are merged with \n. + * @see OptionDescription#text() + * + * @param lines the lines to append to the description. + * @return this builder + */ + Builder text(Collection lines); + + /** + * Sets a static image to display with the description. This is backed by a regular minecraft resource + * in your mod's /assets folder. + * + * @param image the location of the image to display from the resource manager + * @param width the width of the texture + * @param height the height of the texture + * @return this builder + */ + Builder image(ResourceLocation image, int width, int height); + + /** + * Sets a static image to display with the description. This is backed by a regular minecraft resource + * in your mod's /assets folder. This overload method allows you to specify a subsection of the texture to render. + * + * @param image the location of the image to display from the resource manager + * @param u the u coordinate + * @param v the v coordinate + * @param width the width of the subsection + * @param height the height of the subsection + * @param textureWidth the width of the whole texture file + * @param textureHeight the height of whole texture file + * @return this builder + */ + Builder image(ResourceLocation image, float u, float v, int width, int height, int textureWidth, int textureHeight); + + /** + * Sets a static image to display with the description. This is backed by a file on disk. + * The width and height is automatically determined from the image processing. + * + * @param path the absolute path to the image file + * @param uniqueLocation the unique identifier for the image, used for caching and resource manager registrar + * @return this builder + */ + Builder image(Path path, ResourceLocation uniqueLocation); + + /** + * Sets a static OR ANIMATED webP image to display with the description. This is backed by a regular minecraft resource + * in your mod's /assets folder. + * + * @param image the location of the image to display from the resource manager + * @return this builder + */ + Builder webpImage(ResourceLocation image); + + /** + * Sets a static OR ANIMATED webP image to display with the description. This is backed by a file on disk. + * The width and height is automatically determined from the image processing. + * + * @param path the absolute path to the image file + * @param uniqueLocation the unique identifier for the image, used for caching and resource manager registrar + * @return this builder + */ + Builder webpImage(Path path, ResourceLocation uniqueLocation); + + /** + * Sets a custom image renderer to display with the description. + * This is useful for rendering other abstract things relevant to your mod. + *

+ * However, THIS IS NOT API SAFE! As part of the gui package, things + * may change that could break compatibility with future versions of YACL. + * A helpful utility (that is also not API safe) is {@link ImageRenderer#getOrMakeAsync(ResourceLocation, Supplier)} + * which will cache the image renderer for the whole game lifecycle and construct it asynchronously to the render thread. + * @param image the image renderer to display + * @return this builder + */ + Builder customImage(CompletableFuture> image); + + /** + * Sets an animated GIF image to display with the description. This is backed by a regular minecraft resource + * in your mod's /assets folder. + * + * @param image the location of the image to display from the resource manager + * @return this builder + */ + @Deprecated + Builder gifImage(ResourceLocation image); + + /** + * Sets an animated GIF image to display with the description. This is backed by a file on disk. + * The width and height is automatically determined from the image processing. + * + * @param path the absolute path to the image file + * @param uniqueLocation the unique identifier for the image, used for caching and resource manager registrar + * @return this builder + */ + @Deprecated + Builder gifImage(Path path, ResourceLocation uniqueLocation); + + OptionDescription build(); + } +} diff --git a/common/src/main/java/dev/isxander/yacl3/api/OptionFlag.java b/common/src/main/java/dev/isxander/yacl3/api/OptionFlag.java new file mode 100644 index 0000000..6f35495 --- /dev/null +++ b/common/src/main/java/dev/isxander/yacl3/api/OptionFlag.java @@ -0,0 +1,23 @@ +package dev.isxander.yacl3.api; + +import dev.isxander.yacl3.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/common/src/main/java/dev/isxander/yacl3/api/OptionGroup.java b/common/src/main/java/dev/isxander/yacl3/api/OptionGroup.java new file mode 100644 index 0000000..ff31966 --- /dev/null +++ b/common/src/main/java/dev/isxander/yacl3/api/OptionGroup.java @@ -0,0 +1,90 @@ +package dev.isxander.yacl3.api; + +import com.google.common.collect.ImmutableList; +import dev.isxander.yacl3.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(); + + OptionDescription description(); + + /** + * Tooltip displayed on hover. + */ + @Deprecated + 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); + + Builder description(@NotNull OptionDescription description); + + /** + * 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/common/src/main/java/dev/isxander/yacl3/api/PlaceholderCategory.java b/common/src/main/java/dev/isxander/yacl3/api/PlaceholderCategory.java new file mode 100644 index 0000000..6eb82c5 --- /dev/null +++ b/common/src/main/java/dev/isxander/yacl3/api/PlaceholderCategory.java @@ -0,0 +1,55 @@ +package dev.isxander.yacl3.api; + +import dev.isxander.yacl3.gui.YACLScreen; +import dev.isxander.yacl3.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. + *

+ * Use of this is discouraged, as it is not very user-friendly and navigating to a placeholder + * tab that opens another screen is not very intuitive, making keyboard navigation impossible. + */ +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.yacl3.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/common/src/main/java/dev/isxander/yacl3/api/YetAnotherConfigLib.java b/common/src/main/java/dev/isxander/yacl3/api/YetAnotherConfigLib.java new file mode 100644 index 0000000..15ce5bc --- /dev/null +++ b/common/src/main/java/dev/isxander/yacl3/api/YetAnotherConfigLib.java @@ -0,0 +1,107 @@ +package dev.isxander.yacl3.api; + +import com.google.common.collect.ImmutableList; +import dev.isxander.yacl3.config.ConfigInstance; +import dev.isxander.yacl3.gui.YACLScreen; +import dev.isxander.yacl3.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/common/src/main/java/dev/isxander/yacl3/api/controller/BooleanControllerBuilder.java b/common/src/main/java/dev/isxander/yacl3/api/controller/BooleanControllerBuilder.java new file mode 100644 index 0000000..88f9a77 --- /dev/null +++ b/common/src/main/java/dev/isxander/yacl3/api/controller/BooleanControllerBuilder.java @@ -0,0 +1,16 @@ +package dev.isxander.yacl3.api.controller; + +import dev.isxander.yacl3.api.Option; +import dev.isxander.yacl3.impl.controller.BooleanControllerBuilderImpl; + +public interface BooleanControllerBuilder extends ValueFormattableController { + BooleanControllerBuilder coloured(boolean coloured); + + BooleanControllerBuilder onOffFormatter(); + BooleanControllerBuilder yesNoFormatter(); + BooleanControllerBuilder trueFalseFormatter(); + + static BooleanControllerBuilder create(Option option) { + return new BooleanControllerBuilderImpl(option); + } +} diff --git a/common/src/main/java/dev/isxander/yacl3/api/controller/ColorControllerBuilder.java b/common/src/main/java/dev/isxander/yacl3/api/controller/ColorControllerBuilder.java new file mode 100644 index 0000000..8e442ff --- /dev/null +++ b/common/src/main/java/dev/isxander/yacl3/api/controller/ColorControllerBuilder.java @@ -0,0 +1,14 @@ +package dev.isxander.yacl3.api.controller; + +import dev.isxander.yacl3.api.Option; +import dev.isxander.yacl3.impl.controller.ColorControllerBuilderImpl; + +import java.awt.Color; + +public interface ColorControllerBuilder extends ControllerBuilder { + ColorControllerBuilder allowAlpha(boolean allowAlpha); + + static ColorControllerBuilder create(Option option) { + return new ColorControllerBuilderImpl(option); + } +} diff --git a/common/src/main/java/dev/isxander/yacl3/api/controller/ControllerBuilder.java b/common/src/main/java/dev/isxander/yacl3/api/controller/ControllerBuilder.java new file mode 100644 index 0000000..0cd3a55 --- /dev/null +++ b/common/src/main/java/dev/isxander/yacl3/api/controller/ControllerBuilder.java @@ -0,0 +1,9 @@ +package dev.isxander.yacl3.api.controller; + +import dev.isxander.yacl3.api.Controller; +import org.jetbrains.annotations.ApiStatus; + +public interface ControllerBuilder { + @ApiStatus.Internal + Controller build(); +} diff --git a/common/src/main/java/dev/isxander/yacl3/api/controller/CyclingListControllerBuilder.java b/common/src/main/java/dev/isxander/yacl3/api/controller/CyclingListControllerBuilder.java new file mode 100644 index 0000000..8c9ea91 --- /dev/null +++ b/common/src/main/java/dev/isxander/yacl3/api/controller/CyclingListControllerBuilder.java @@ -0,0 +1,15 @@ +package dev.isxander.yacl3.api.controller; + +import dev.isxander.yacl3.api.Option; +import dev.isxander.yacl3.impl.controller.CyclingListControllerBuilderImpl; + +public interface CyclingListControllerBuilder extends ValueFormattableController> { + @SuppressWarnings("unchecked") + CyclingListControllerBuilder values(T... values); + + CyclingListControllerBuilder values(Iterable values); + + static CyclingListControllerBuilder create(Option option) { + return new CyclingListControllerBuilderImpl<>(option); + } +} diff --git a/common/src/main/java/dev/isxander/yacl3/api/controller/DoubleFieldControllerBuilder.java b/common/src/main/java/dev/isxander/yacl3/api/controller/DoubleFieldControllerBuilder.java new file mode 100644 index 0000000..db4af94 --- /dev/null +++ b/common/src/main/java/dev/isxander/yacl3/api/controller/DoubleFieldControllerBuilder.java @@ -0,0 +1,10 @@ +package dev.isxander.yacl3.api.controller; + +import dev.isxander.yacl3.api.Option; +import dev.isxander.yacl3.impl.controller.DoubleFieldControllerBuilderImpl; + +public interface DoubleFieldControllerBuilder extends NumberFieldControllerBuilder { + static DoubleFieldControllerBuilder create(Option option) { + return new DoubleFieldControllerBuilderImpl(option); + } +} diff --git a/common/src/main/java/dev/isxander/yacl3/api/controller/DoubleSliderControllerBuilder.java b/common/src/main/java/dev/isxander/yacl3/api/controller/DoubleSliderControllerBuilder.java new file mode 100644 index 0000000..7e4b6f9 --- /dev/null +++ b/common/src/main/java/dev/isxander/yacl3/api/controller/DoubleSliderControllerBuilder.java @@ -0,0 +1,10 @@ +package dev.isxander.yacl3.api.controller; + +import dev.isxander.yacl3.api.Opt