diff options
Diffstat (limited to 'common/src/main/java/dev/isxander/yacl/impl')
21 files changed, 601 insertions, 173 deletions
diff --git a/common/src/main/java/dev/isxander/yacl/impl/ButtonOptionImpl.java b/common/src/main/java/dev/isxander/yacl/impl/ButtonOptionImpl.java index afb2cb5..c63dd99 100644 --- a/common/src/main/java/dev/isxander/yacl/impl/ButtonOptionImpl.java +++ b/common/src/main/java/dev/isxander/yacl/impl/ButtonOptionImpl.java @@ -3,6 +3,7 @@ package dev.isxander.yacl.impl; import com.google.common.collect.ImmutableSet; import dev.isxander.yacl.api.*; import dev.isxander.yacl.gui.YACLScreen; +import dev.isxander.yacl.gui.controllers.ActionController; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.MutableComponent; import org.apache.commons.lang3.Validate; @@ -29,14 +30,13 @@ public final class ButtonOptionImpl implements ButtonOption { @NotNull Component name, @Nullable OptionDescription description, @NotNull BiConsumer<YACLScreen, ButtonOption> action, - boolean available, - @NotNull Function<ButtonOption, Controller<BiConsumer<YACLScreen, ButtonOption>>> controlGetter + boolean available ) { this.name = name; this.description = description; this.action = action; this.available = available; - this.controller = controlGetter.apply(this); + this.controller = new ActionController(this); this.binding = new EmptyBinderImpl(); } @@ -81,11 +81,6 @@ public final class ButtonOptionImpl implements ButtonOption { } @Override - public @NotNull Class<BiConsumer<YACLScreen, ButtonOption>> typeClass() { - throw new UnsupportedOperationException(); - } - - @Override public @NotNull ImmutableSet<OptionFlag> flags() { return ImmutableSet.of(); } @@ -150,9 +145,8 @@ public final class ButtonOptionImpl implements ButtonOption { @ApiStatus.Internal public static final class BuilderImpl implements Builder { private Component name; - private final List<Component> tooltipLines = new ArrayList<>(); + private OptionDescription description = OptionDescription.EMPTY; private boolean available = true; - private Function<ButtonOption, Controller<BiConsumer<YACLScreen, ButtonOption>>> controlGetter; private BiConsumer<YACLScreen, ButtonOption> action; @Override @@ -164,10 +158,10 @@ public final class ButtonOptionImpl implements ButtonOption { } @Override - public Builder tooltip(@NotNull Component... tooltips) { - Validate.notNull(tooltips, "`tooltips` cannot be empty"); + public Builder description(@NotNull OptionDescription description) { + Validate.notNull(description, "`description` cannot be null"); - //tooltipLines.addAll(List.of(tooltips)); + this.description = description; return this; } @@ -195,29 +189,11 @@ public final class ButtonOptionImpl implements ButtonOption { } @Override - public Builder controller(@NotNull Function<ButtonOption, Controller<BiConsumer<YACLScreen, ButtonOption>>> control) { - Validate.notNull(control, "`control` cannot be null"); - - this.controlGetter = control; - return this; - } - - @Override public ButtonOption build() { - Validate.notNull(name, "`name` must not be null when building `Option`"); - Validate.notNull(controlGetter, "`control` must not be null when building `Option`"); - Validate.notNull(action, "`action` must not be null when building `Option`"); - - MutableComponent concatenatedTooltip = Component.empty(); - boolean first = true; - for (Component line : tooltipLines) { - if (!first) concatenatedTooltip.append("\n"); - first = false; - - concatenatedTooltip.append(line); - } + Validate.notNull(name, "`name` must not be null when building `ButtonOption`"); + Validate.notNull(action, "`action` must not be null when building `ButtonOption`"); - return new ButtonOptionImpl(name, OptionDescription.createBuilder().description(concatenatedTooltip).build(), action, available, controlGetter); + return new ButtonOptionImpl(name, description, action, available); } } } diff --git a/common/src/main/java/dev/isxander/yacl/impl/ConfigCategoryImpl.java b/common/src/main/java/dev/isxander/yacl/impl/ConfigCategoryImpl.java index e593ce4..0690cda 100644 --- a/common/src/main/java/dev/isxander/yacl/impl/ConfigCategoryImpl.java +++ b/common/src/main/java/dev/isxander/yacl/impl/ConfigCategoryImpl.java @@ -3,6 +3,7 @@ package dev.isxander.yacl.impl; import com.google.common.collect.ImmutableList; import dev.isxander.yacl.api.*; import dev.isxander.yacl.impl.utils.YACLConstants; +import net.minecraft.network.chat.CommonComponents; import net.minecraft.network.chat.Component; import net.minecraft.network.chat.ComponentContents; import net.minecraft.network.chat.MutableComponent; @@ -111,7 +112,7 @@ public final class ConfigCategoryImpl implements ConfigCategory { Validate.notNull(name, "`name` must not be null to build `ConfigCategory`"); List<OptionGroup> combinedGroups = new ArrayList<>(); - combinedGroups.add(new OptionGroupImpl(Component.empty(), OptionDescription.empty(), ImmutableList.copyOf(rootOptions), false, true)); + combinedGroups.add(new OptionGroupImpl(CommonComponents.EMPTY, OptionDescription.EMPTY, ImmutableList.copyOf(rootOptions), false, true)); combinedGroups.addAll(groups); Validate.notEmpty(combinedGroups, "at least one option must be added to build `ConfigCategory`"); diff --git a/common/src/main/java/dev/isxander/yacl/impl/LabelOptionImpl.java b/common/src/main/java/dev/isxander/yacl/impl/LabelOptionImpl.java index a32121d..c1a6772 100644 --- a/common/src/main/java/dev/isxander/yacl/impl/LabelOptionImpl.java +++ b/common/src/main/java/dev/isxander/yacl/impl/LabelOptionImpl.java @@ -74,11 +74,6 @@ public final class LabelOptionImpl implements LabelOption { } @Override - public @NotNull Class<Component> typeClass() { - return Component.class; - } - - @Override public @NotNull ImmutableSet<OptionFlag> flags() { return ImmutableSet.of(); } diff --git a/common/src/main/java/dev/isxander/yacl/impl/ListOptionImpl.java b/common/src/main/java/dev/isxander/yacl/impl/ListOptionImpl.java index c21e733..4b37e9e 100644 --- a/common/src/main/java/dev/isxander/yacl/impl/ListOptionImpl.java +++ b/common/src/main/java/dev/isxander/yacl/impl/ListOptionImpl.java @@ -79,11 +79,6 @@ public final class ListOptionImpl<T> implements ListOption<T> { } @Override - public @NotNull Class<List<T>> typeClass() { - throw new UnsupportedOperationException(); - } - - @Override public @NotNull Class<T> elementTypeClass() { return typeClass; } @@ -218,8 +213,7 @@ public final class ListOptionImpl<T> implements ListOption<T> { @ApiStatus.Internal public static final class BuilderImpl<T> implements Builder<T> { private Component name = Component.empty(); - private OptionDescription description = null; - private OptionDescription.Builder legacyBuilder = null; + private OptionDescription description = OptionDescription.EMPTY; private Function<ListOptionEntry<T>, Controller<T>> controllerFunction; private Binding<List<T>> binding = null; private final Set<OptionFlag> flags = new HashSet<>(); @@ -243,7 +237,6 @@ public final class ListOptionImpl<T> implements ListOption<T> { @Override public Builder<T> description(@NotNull OptionDescription description) { - Validate.isTrue(legacyBuilder == null, "Cannot set description when deprecated `tooltip` method is used"); Validate.notNull(description, "`description` must not be null"); this.description = description; @@ -251,17 +244,6 @@ public final class ListOptionImpl<T> implements ListOption<T> { } @Override - public Builder<T> tooltip(@NotNull Component... tooltips) { - Validate.isTrue(description == null, "Cannot use deprecated `tooltip` method when `description` in use."); - Validate.notEmpty(tooltips, "`tooltips` cannot be empty"); - - ensureLegacyDescriptionBuilder(); - - legacyBuilder.description(tooltips); - return this; - } - - @Override public Builder<T> initial(@NotNull T initialValue) { Validate.notNull(initialValue, "`initialValue` cannot be empty"); @@ -341,23 +323,7 @@ public final class ListOptionImpl<T> implements ListOption<T> { Validate.notNull(binding, "`binding` must not be null"); Validate.notNull(initialValue, "`initialValue` must not be null"); - if (description == null) { - if (ensureLegacyDescriptionBuilder()) - YACLConstants.LOGGER.warn("Using deprecated `tooltip` method in list option {}. Use `description` instead.", name.getString()); - - description = legacyBuilder.build(); - } - return new ListOptionImpl<>(name, description, binding, initialValue, typeClass, controllerFunction, ImmutableSet.copyOf(flags), collapsed, available, listeners); } - - private boolean ensureLegacyDescriptionBuilder() { - if (legacyBuilder == null) { - legacyBuilder = OptionDescription.createBuilder(); - return false; - } else { - return true; - } - } } } diff --git a/common/src/main/java/dev/isxander/yacl/impl/OptionGroupImpl.java b/common/src/main/java/dev/isxander/yacl/impl/OptionGroupImpl.java index 2db8acd..37eddfd 100644 --- a/common/src/main/java/dev/isxander/yacl/impl/OptionGroupImpl.java +++ b/common/src/main/java/dev/isxander/yacl/impl/OptionGroupImpl.java @@ -64,8 +64,7 @@ public final class OptionGroupImpl implements OptionGroup { @ApiStatus.Internal public static final class BuilderImpl implements Builder { private Component name = Component.empty(); - private OptionDescription description = null; - private OptionDescription.Builder legacyBuilder = null; + private OptionDescription description = OptionDescription.EMPTY; private final List<Option<?>> options = new ArrayList<>(); private boolean collapsed = false; @@ -79,7 +78,6 @@ public final class OptionGroupImpl implements OptionGroup { @Override public Builder description(@NotNull OptionDescription description) { - Validate.isTrue(legacyBuilder == null, "Cannot set description when deprecated `tooltip` method is used"); Validate.notNull(description, "`description` must not be null"); this.description = description; @@ -87,17 +85,6 @@ public final class OptionGroupImpl implements OptionGroup { } @Override - public Builder tooltip(@NotNull Component... tooltips) { - Validate.isTrue(description == null, "Cannot use deprecated `tooltip` method when `description` in use."); - Validate.notEmpty(tooltips, "`tooltips` cannot be empty"); - - ensureLegacyDescriptionBuilder(); - - legacyBuilder.description(tooltips); - return this; - } - - @Override public Builder option(@NotNull Option<?> option) { Validate.notNull(option, "`option` must not be null"); @@ -129,23 +116,7 @@ public final class OptionGroupImpl implements OptionGroup { public OptionGroup build() { Validate.notEmpty(options, "`options` must not be empty to build `OptionGroup`"); - if (description == null) { - if (ensureLegacyDescriptionBuilder()) - YACLConstants.LOGGER.warn("Using deprecated `tooltip` method in option group '{}'. Use `description` instead.", name != null ? name.getString() : "unnamed group"); - - description = legacyBuilder.build(); - } - return new OptionGroupImpl(name, description, ImmutableList.copyOf(options), collapsed, false); } - - private boolean ensureLegacyDescriptionBuilder() { - if (legacyBuilder == null) { - legacyBuilder = OptionDescription.createBuilder(); - return false; - } else { - return true; - } - } } } diff --git a/common/src/main/java/dev/isxander/yacl/impl/OptionImpl.java b/common/src/main/java/dev/isxander/yacl/impl/OptionImpl.java index ebb1226..29ca48d 100644 --- a/common/src/main/java/dev/isxander/yacl/impl/OptionImpl.java +++ b/common/src/main/java/dev/isxander/yacl/impl/OptionImpl.java @@ -2,6 +2,7 @@ package dev.isxander.yacl.impl; import com.google.common.collect.ImmutableSet; import dev.isxander.yacl.api.*; +import dev.isxander.yacl.api.controller.ControllerBuilder; import dev.isxander.yacl.impl.utils.YACLConstants; import net.minecraft.ChatFormatting; import net.minecraft.network.chat.Component; @@ -28,8 +29,6 @@ public final class OptionImpl<T> implements Option<T> { private final ImmutableSet<OptionFlag> flags; - private final Class<T> typeClass; - private T pendingValue; private final List<BiConsumer<Option<T>, T>> listeners; @@ -41,14 +40,12 @@ public final class OptionImpl<T> implements Option<T> { @NotNull Binding<T> binding, boolean available, ImmutableSet<OptionFlag> flags, - @NotNull Class<T> typeClass, @NotNull Collection<BiConsumer<Option<T>, T>> listeners ) { this.name = name; this.binding = binding; this.available = available; this.flags = flags; - this.typeClass = typeClass; this.listeners = new ArrayList<>(listeners); this.controller = controlGetter.apply(this); @@ -93,11 +90,6 @@ public final class OptionImpl<T> implements Option<T> { } @Override - public @NotNull Class<T> typeClass() { - return typeClass; - } - - @Override public @NotNull ImmutableSet<OptionFlag> flags() { return flags; } @@ -151,8 +143,7 @@ public final class OptionImpl<T> implements Option<T> { public static class BuilderImpl<T> implements Builder<T> { private Component name = Component.literal("Name not specified!").withStyle(ChatFormatting.RED); - private Function<T, OptionDescription> descriptionFunction = null; - private final List<Function<T, Component>> tooltipGetters = new ArrayList<>(); + private Function<T, OptionDescription> descriptionFunction = pending -> OptionDescription.EMPTY; private Function<Option<T>, Controller<T>> controlGetter; @@ -164,14 +155,8 @@ public final class OptionImpl<T> implements Option<T> { private final Set<OptionFlag> flags = new HashSet<>(); - private final Class<T> typeClass; - private final List<BiConsumer<Option<T>, T>> listeners = new ArrayList<>(); - public BuilderImpl(Class<T> typeClass) { - this.typeClass = typeClass; - } - @Override public Builder<T> name(@NotNull Component name) { Validate.notNull(name, "`name` cannot be null"); @@ -192,35 +177,14 @@ public final class OptionImpl<T> implements Option<T> { } @Override - public Builder<T> tooltip(@NotNull Function<T, Component> tooltipGetter) { - Validate.notNull(tooltipGetter, "`tooltipGetter` cannot be null"); - - this.tooltipGetters.add(tooltipGetter); - return this; - } - - @Override - @SafeVarargs - @Deprecated - public final Builder<T> tooltip(@NotNull Function<T, Component>... tooltipGetter) { - Validate.notNull(tooltipGetter, "`tooltipGetter` cannot be null"); + public Builder<T> controller(@NotNull Function<Option<T>, ControllerBuilder<T>> controllerBuilder) { + Validate.notNull(controllerBuilder, "`controllerBuilder` cannot be null"); - this.tooltipGetters.addAll(List.of(tooltipGetter)); - return this; - } - - @Override - public Builder<T> tooltip(@NotNull Component... tooltips) { - var tooltipFunctions = Arrays.stream(tooltips) - .map(t -> (Function<T, Component>) opt -> t) - .toList(); - - this.tooltipGetters.addAll(tooltipFunctions); - return this; + return customController(opt -> controllerBuilder.apply(opt).build()); } @Override - public Builder<T> controller(@NotNull Function<Option<T>, Controller<T>> control) { + public Builder<T> customController(@NotNull Function<Option<T>, Controller<T>> control) { Validate.notNull(control, "`control` cannot be null"); this.controlGetter = control; @@ -260,7 +224,7 @@ public final class OptionImpl<T> implements Option<T> { } @Override - public Builder<T> flags(@NotNull Collection<OptionFlag> flags) { + public Builder<T> flags(@NotNull Collection<? extends OptionFlag> flags) { Validate.notNull(flags, "`flags` must not be null"); this.flags.addAll(flags); @@ -291,31 +255,7 @@ public final class OptionImpl<T> implements Option<T> { Validate.notNull(binding, "`binding` must not be null when building `Option`"); Validate.isTrue(!instant || flags.isEmpty(), "instant application does not support option flags"); - if (descriptionFunction == null) { - if (!tooltipGetters.isEmpty()) - YACLConstants.LOGGER.warn("Using deprecated `tooltip` method in option '{}'. Use `description` instead.", name.getString()); - - Function<T, Component> concatenatedTooltipGetter = value -> { - MutableComponent concatenatedTooltip = Component.empty(); - boolean first = true; - for (Function<T, Component> line : tooltipGetters) { - Component lineComponent = line.apply(value); - - if (lineComponent.getContents() == ComponentContents.EMPTY) - continue; - - if (!first) concatenatedTooltip.append("\n"); - first = false; - - concatenatedTooltip.append(lineComponent); - } - - return concatenatedTooltip; - }; - descriptionFunction = opt -> OptionDescription.createBuilder().description(concatenatedTooltipGetter.apply(opt)).build(); - } - - return new OptionImpl<>(name, descriptionFunction, controlGetter, binding, available, ImmutableSet.copyOf(flags), typeClass, listeners); + return new OptionImpl<>(name, descriptionFunction, controlGetter, binding, available, ImmutableSet.copyOf(flags), listeners); } } } diff --git a/common/src/main/java/dev/isxander/yacl/impl/controller/AbstractControllerBuilderImpl.java b/common/src/main/java/dev/isxander/yacl/impl/controller/AbstractControllerBuilderImpl.java new file mode 100644 index 0000000..206ab29 --- /dev/null +++ b/common/src/main/java/dev/isxander/yacl/impl/controller/AbstractControllerBuilderImpl.java @@ -0,0 +1,12 @@ +package dev.isxander.yacl.impl.controller; + +import dev.isxander.yacl.api.Option; +import dev.isxander.yacl.api.controller.ControllerBuilder; + +public abstract class AbstractControllerBuilderImpl<T> implements ControllerBuilder<T> { + protected final Option<T> option; + + protected AbstractControllerBuilderImpl(Option<T> option) { + this.option = option; + } +} diff --git a/common/src/main/java/dev/isxander/yacl/impl/controller/BooleanControllerBuilderImpl.java b/common/src/main/java/dev/isxander/yacl/impl/controller/BooleanControllerBuilderImpl.java new file mode 100644 index 0000000..99c5ffc --- /dev/null +++ b/common/src/main/java/dev/isxander/yacl/impl/controller/BooleanControllerBuilderImpl.java @@ -0,0 +1,56 @@ +package dev.isxander.yacl.impl.controller; + +import dev.isxander.yacl.api.Controller; +import dev.isxander.yacl.api.Option; +import dev.isxander.yacl.api.controller.BooleanControllerBuilder; +import dev.isxander.yacl.gui.controllers.BooleanController; +import net.minecraft.network.chat.Component; +import org.apache.commons.lang3.Validate; + +import java.util.function.Function; + +public class BooleanControllerBuilderImpl extends AbstractControllerBuilderImpl<Boolean> implements BooleanControllerBuilder { + private boolean coloured = false; + private Function<Boolean, Component> formatter = BooleanController.ON_OFF_FORMATTER; + + public BooleanControllerBuilderImpl(Option<Boolean> option) { + super(option); + } + + @Override + public BooleanControllerBuilder coloured(boolean coloured) { + this.coloured = coloured; + return this; + } + + @Override + public BooleanControllerBuilder valueFormatter(Function<Boolean, Component> formatter) { + Validate.notNull(formatter); + + this.formatter = formatter; + return this; + } + + @Override + public BooleanControllerBuilder onOffFormatter() { + this.formatter = BooleanController.ON_OFF_FORMATTER; + return this; + } + + @Override + public BooleanControllerBuilder yesNoFormatter() { + this.formatter = BooleanController.YES_NO_FORMATTER; + return this; + } + + @Override + public BooleanControllerBuilder trueFalseFormatter() { + this.formatter = BooleanController.TRUE_FALSE_FORMATTER; + return this; + } + + @Override + public Controller<Boolean> build() { + return new BooleanController(option, formatter, coloured); + } +} diff --git a/common/src/main/java/dev/isxander/yacl/impl/controller/ColorControllerBuilderImpl.java b/common/src/main/java/dev/isxander/yacl/impl/controller/ColorControllerBuilderImpl.java new file mode 100644 index 0000000..8b7851b --- /dev/null +++ b/common/src/main/java/dev/isxander/yacl/impl/controller/ColorControllerBuilderImpl.java @@ -0,0 +1,27 @@ +package dev.isxander.yacl.impl.controller; + +import dev.isxander.yacl.api.Controller; +import dev.isxander.yacl.api.Option; +import dev.isxander.yacl.api.controller.ColorControllerBuilder; +import dev.isxander.yacl.gui.controllers.ColorController; + +import java.awt.Color; + +public class ColorControllerBuilderImpl extends AbstractControllerBuilderImpl<Color> implements ColorControllerBuilder { + private boolean allowAlpha = false; + + public ColorControllerBuilderImpl(Option<Color> option) { + super(option); + } + + @Override + public ColorControllerBuilder allowAlpha(boolean allowAlpha) { + this.allowAlpha = allowAlpha; + return this; + } + + @Override + public Controller<Color> build() { + return new ColorController(option, allowAlpha); + } +} diff --git a/common/src/main/java/dev/isxander/yacl/impl/controller/CyclingListControllerBuilderImpl.java b/common/src/main/java/dev/isxander/yacl/impl/controller/CyclingListControllerBuilderImpl.java new file mode 100644 index 0000000..1af556c --- /dev/null +++ b/common/src/main/java/dev/isxander/yacl/impl/controller/CyclingListControllerBuilderImpl.java @@ -0,0 +1,43 @@ +package dev.isxander.yacl.impl.controller; + +import com.google.common.collect.ImmutableList; +import dev.isxander.yacl.api.Controller; +import dev.isxander.yacl.api.Option; +import dev.isxander.yacl.api.controller.CyclingListControllerBuilder; +import dev.isxander.yacl.gui.controllers.cycling.CyclingListController; +import net.minecraft.network.chat.Component; + +import java.util.function.Function; + +public final class CyclingListControllerBuilderImpl<T> extends AbstractControllerBuilderImpl<T> implements CyclingListControllerBuilder<T> { + private Iterable<? extends T> values; + private Function<T, Component> formatter = null; + + public CyclingListControllerBuilderImpl(Option<T> option) { + super(option); + } + + @Override + public CyclingListControllerBuilder<T> values(Iterable<? extends T> values) { + this.values = values; + return this; + } + + @SafeVarargs + @Override + public final CyclingListControllerBuilder<T> values(T... values) { + this.values = ImmutableList.copyOf(values); + return this; + } + + @Override + public CyclingListControllerBuilder<T> valueFormatter(Function<T, Component> formatter) { + this.formatter = formatter; + return this; + } + + @Override + public Controller<T> build() { + return new CyclingListController<>(option, values, formatter); + } +} diff --git a/common/src/main/java/dev/isxander/yacl/impl/controller/DoubleFieldControllerBuilderImpl.java b/common/src/main/java/dev/isxander/yacl/impl/controller/DoubleFieldControllerBuilderImpl.java new file mode 100644 index 0000000..e22e08b --- /dev/null +++ b/common/src/main/java/dev/isxander/yacl/impl/controller/DoubleFieldControllerBuilderImpl.java @@ -0,0 +1,50 @@ +package dev.isxander.yacl.impl.controller; + +import dev.isxander.yacl.api.Controller; +import dev.isxander.yacl.api.Option; +import dev.isxander.yacl.api.controller.DoubleFieldControllerBuilder; +import dev.isxander.yacl.gui.controllers.slider.DoubleSliderController; +import dev.isxander.yacl.gui.controllers.string.number.DoubleFieldController; +import net.minecraft.network.chat.Component; + +import java.util.function.Function; + +public class DoubleFieldControllerBuilderImpl extends AbstractControllerBuilderImpl<Double> implements DoubleFieldControllerBuilder { + private double min = Double.MIN_VALUE; + private double max = Double.MAX_VALUE; + private Function<Double, Component> formatter = DoubleSliderController.DEFAULT_FORMATTER; + + public DoubleFieldControllerBuilderImpl(Option<Double> option) { + super(option); + } + + @Override + public DoubleFieldControllerBuilder min(Double min) { + this.min = min; + return this; + } + + @Override + public DoubleFieldControllerBuilder max(Double max) { + this.max = max; + return this; + } + + @Override + public DoubleFieldControllerBuilder range(Double min, Double max) { + this.min = min; + this.max = max; + return this; + } + + @Override + public DoubleFieldControllerBuilder valueFormatter(Function<Double, Component> formatter) { + this.formatter = formatter; + return this; + } + + @Override + public Controller<Double> build() { + return new DoubleFieldController(option, min, max, formatter); + } +} diff --git a/common/src/main/java/dev/isxander/yacl/impl/controller/DoubleSliderControllerBuilderImpl.java b/common/src/main/java/dev/isxander/yacl/impl/controller/DoubleSliderControllerBuilderImpl.java new file mode 100644 index 0000000..1c3a664 --- /dev/null +++ b/common/src/main/java/dev/isxander/yacl/impl/controller/DoubleSliderControllerBuilderImpl.java @@ -0,0 +1,43 @@ +package dev.isxander.yacl.impl.controller; + +import dev.isxander.yacl.api.Controller; +import dev.isxander.yacl.api.Option; +import dev.isxander.yacl.api.controller.DoubleSliderControllerBuilder; +import dev.isxander.yacl.gui.controllers.slider.DoubleSliderController; +import net.minecraft.network.chat.Component; + +import java.util.function.Function; + +public class DoubleSliderControllerBuilderImpl extends AbstractControllerBuilderImpl<Double> implements DoubleSliderControllerBuilder { + private double min, max; + private double step; + private Function<Double, Component> formatter = DoubleSliderController.DEFAULT_FORMATTER; + + public DoubleSliderControllerBuilderImpl(Option<Double> option) { + super(option); + } + + @Override + public DoubleSliderControllerBuilder range(Double min, Double max) { + this.min = min; + this.max = max; + return this; + } + + @Override + public DoubleSliderControllerBuilder step(Double step) { + this.step = step; + return this; + } + + @Override + public DoubleSliderControllerBuilder valueFormatter(Function<Double, Component> formatter) { + this.formatter = formatter; + return this; + } + + @Override + public Controller<Double> build() { + return new DoubleSliderController(option, min, max, step, formatter); + } +} diff --git a/common/src/main/java/dev/isxander/yacl/impl/controller/EnumControllerBuilderImpl.java b/common/src/main/java/dev/isxander/yacl/impl/controller/EnumControllerBuilderImpl.java new file mode 100644 index 0000000..79016b5 --- /dev/null +++ b/common/src/main/java/dev/isxander/yacl/impl/controller/EnumControllerBuilderImpl.java @@ -0,0 +1,35 @@ +package dev.isxander.yacl.impl.controller; + +import dev.isxander.yacl.api.Controller; +import dev.isxander.yacl.api.Option; +import dev.isxander.yacl.api.controller.EnumControllerBuilder; +import dev.isxander.yacl.gui.controllers.cycling.EnumController; +import net.minecraft.network.chat.Component; + +import java.util.function.Function; + +public class EnumControllerBuilderImpl<T extends Enum<T>> extends AbstractControllerBuilderImpl<T> implements EnumControllerBuilder<T> { + private Class<T> enumClass; + private Function<T, Component> formatter = EnumController.getDefaultFormatter(); + + public EnumControllerBuilderImpl(Option<T> option) { + super(option); + } + + @Override + public EnumControllerBuilder<T> enumClass(Class<T> enumClass) { + this.enumClass = enumClass; + return this; + } + + @Override + public EnumControllerBuilder<T> valueFormatter(Function<T, Component> formatter) { + this.formatter = formatter; + return this; + } + + @Override + public Controller<T> build() { + return new EnumController<>(option, formatter, enumClass.getEnumConstants()); + } +} diff --git a/common/src/main/java/dev/isxander/yacl/impl/controller/FloatFieldControllerBuilderImpl.java b/common/src/main/java/dev/isxander/yacl/impl/controller/FloatFieldControllerBuilderImpl.java new file mode 100644 index 0000000..22dbf1a --- /dev/null +++ b/common/src/main/java/dev/isxander/yacl/impl/controller/FloatFieldControllerBuilderImpl.java @@ -0,0 +1,50 @@ +package dev.isxander.yacl.impl.controller; + +import dev.isxander.yacl.api.Controller; +import dev.isxander.yacl.api.Option; +import dev.isxander.yacl.api.controller.FloatFieldControllerBuilder; +import dev.isxander.yacl.gui.controllers.slider.FloatSliderController; +import dev.isxander.yacl.gui.controllers.string.number.FloatFieldController; +import net.minecraft.network.chat.Component; + +import java.util.function.Function; + +public class FloatFieldControllerBuilderImpl extends AbstractControllerBuilderImpl<Float> implements FloatFieldControllerBuilder { + private float min = Float.MIN_VALUE; + private float max = Float.MAX_VALUE; + private Function<Float, Component> formatter = FloatSliderController.DEFAULT_FORMATTER; + + public FloatFieldControllerBuilderImpl(Option<Float> option) { + super(option); + } + + @Override + public FloatFieldControllerBuilder min(Float min) { + this.min = min; + return this; + } + + @Override + public FloatFieldControllerBuilder max(Float max) { + this.max = max; + return this; + } + + @Override + public FloatFieldControllerBuilder range(Float min, Float max) { + this.min = min; + this.max = max; + return this; + } + + @Override + public FloatFieldControllerBuilder valueFormatter(Function<Float, Component> formatter) { + this.formatter = formatter; + return this; + } + + @Override + public Controller<Float> build() { + return new FloatFieldController(option, min, max, formatter); + } +} diff --git a/common/src/main/java/dev/isxander/yacl/impl/controller/FloatSliderControllerBuilderImpl.java b/common/src/main/java/dev/isxander/yacl/impl/controller/FloatSliderControllerBuilderImpl.java new file mode 100644 index 0000000..c49eee7 --- /dev/null +++ b/common/src/main/java/dev/isxander/yacl/impl/controller/FloatSliderControllerBuilderImpl.java @@ -0,0 +1,43 @@ +package dev.isxander.yacl.impl.controller; + +import dev.isxander.yacl.api.Controller; +import dev.isxander.yacl.api.Option; +import dev.isxander.yacl.api.controller.FloatSliderControllerBuilder; +import dev.isxander.yacl.gui.controllers.slider.FloatSliderController; +import net.minecraft.network.chat.Component; + +import java.util.function.Function; + +public class FloatSliderControllerBuilderImpl extends AbstractControllerBuilderImpl<Float> implements FloatSliderControllerBuilder { + private float min, max; + private float step; + private Function<Float, Component> formatter = FloatSliderController.DEFAULT_FORMATTER; + + public FloatSliderControllerBuilderImpl(Option<Float> option) { + super(option); + } + + @Override + public FloatSliderControllerBuilder range(Float min, Float max) { + this.min = min; + this.max = max; + return this; + } + + @Override + public FloatSliderControllerBuilder step(Float step) { + this.step = step; + return this; + } + + @Override + public FloatSliderControllerBuilder valueFormatter(Function<Float, Component> formatter) { + this.formatter = formatter; + return this; + } + + @Override + public Controller<Float> build() { + return new FloatSliderController(option, min, max, step, formatter); + } +} diff --git a/common/src/main/java/dev/isxander/yacl/impl/controller/IntegerFieldControllerBuilderImpl.java b/common/src/main/java/dev/isxander/yacl/impl/controller/IntegerFieldControllerBuilderImpl.java new file mode 100644 index 0000000..6514e81 --- /dev/null +++ b/common/src/main/java/dev/isxander/yacl/impl/controller/IntegerFieldControllerBuilderImpl.java @@ -0,0 +1,50 @@ +package dev.isxander.yacl.impl.controller; + +import dev.isxander.yacl.api.Controller; +import dev.isxander.yacl.api.Option; +import dev.isxander.yacl.api.controller.IntegerFieldControllerBuilder; +import dev.isxander.yacl.gui.controllers.slider.IntegerSliderController; +import dev.isxander.yacl.gui.controllers.string.number.IntegerFieldController; +import net.minecraft.network.chat.Component; + +import java.util.function.Function; + +public class IntegerFieldControllerBuilderImpl extends AbstractControllerBuilderImpl<Integer> implements IntegerFieldControllerBuilder { + private int min = Integer.MIN_VALUE; + private int max = Integer.MAX_VALUE; + private Function<Integer, Component> formatter = IntegerSliderController.DEFAULT_FORMATTER; + + public IntegerFieldControllerBuilderImpl(Option<Integer> option) { + super(option); + } + + @Override + public IntegerFieldControllerBuilder min(Integer min) { + this.min = min; + return this; + } + + @Override + public IntegerFieldControllerBuilder max(Integer max) { + this.max = max; + return this; + } + + @Override + public IntegerFieldControllerBuilder range(Integer min, Integer max) { + this.min = min; + this.max = max; + return this; + } + + @Override + public IntegerFieldControllerBuilder valueFormatter(Function<Integer, Component> formatter) { + this.formatter = formatter; + return this; + } + + @Override + public Controller<Integer> build() { + return new IntegerFieldController(option, min, max, formatter); + } +} diff --git a/common/src/main/java/dev/isxander/yacl/impl/controller/IntegerSliderControllerBuilderImpl.java b/common/src/main/java/dev/isxander/yacl/impl/controller/IntegerSliderControllerBuilderImpl.java new file mode 100644 index 0000000..154adb1 --- /dev/null +++ b/common/src/main/java/dev/isxander/yacl/impl/controller/IntegerSliderControllerBuilderImpl.java @@ -0,0 +1,43 @@ +package dev.isxander.yacl.impl.controller; + +import dev.isxander.yacl.api.Controller; +import dev.isxander.yacl.api.Option; +import dev.isxander.yacl.api.controller.IntegerSliderControllerBuilder; +import dev.isxander.yacl.gui.controllers.slider.IntegerSliderController; +import net.minecraft.network.chat.Component; + +import java.util.function.Function; + +public class IntegerSliderControllerBuilderImpl extends AbstractControllerBuilderImpl<Integer> implements IntegerSliderControllerBuilder { + private int min, max; + private int step; + private Function<Integer, Component> formatter = IntegerSliderController.DEFAULT_FORMATTER; + + public IntegerSliderControllerBuilderImpl(Option<Integer> option) { + super(option); + } + + @Override + public IntegerSliderControllerBuilder range(Integer min, Integer max) { + this.min = min; + this.max = max; + return this; + } + + @Override + public IntegerSliderControllerBuilder step(Integer step) { + this.step = step; + return this; + } + + @Override + public IntegerSliderControllerBuilder valueFormatter(Function<Integer, Component> formatter) { + this.formatter = formatter; + return this; + } + + @Override + public Controller<Integer> build() { + return new IntegerSliderController(option, min, max, step, formatter); + } +} diff --git a/common/src/main/java/dev/isxander/yacl/impl/controller/LongFieldControllerBuilderImpl.java b/common/src/main/java/dev/isxander/yacl/impl/controller/LongFieldControllerBuilderImpl.java new file mode 100644 index 0000000..0e76b3d --- /dev/null +++ b/common/src/main/java/dev/isxander/yacl/impl/controller/LongFieldControllerBuilderImpl.java @@ -0,0 +1,50 @@ +package dev.isxander.yacl.impl.controller; + +import dev.isxander.yacl.api.Controller; +import dev.isxander.yacl.api.Option; +import dev.isxander.yacl.api.controller.LongFieldControllerBuilder; +import dev.isxander.yacl.gui.controllers.slider.LongSliderController; +import dev.isxander.yacl.gui.controllers.string.number.LongFieldController; +import net.minecraft.network.chat.Component; + +import java.util.function.Function; + +public class LongFieldControllerBuilderImpl extends AbstractControllerBuilderImpl<Long> implements LongFieldControllerBuilder { + private long min = Long.MIN_VALUE; + private long max = Long.MAX_VALUE; + private Function<Long, Component> formatter = LongSliderController.DEFAULT_FORMATTER; + + public LongFieldControllerBuilderImpl(Option<Long> option) { + super(option); + } + + @Override + public LongFieldControllerBuilder min(Long min) { + this.min = min; + return this; + } + + @Override + public LongFieldControllerBuilder max(Long max) { + this.max = max; + return this; + } + + @Override + public LongFieldControllerBuilder range(Long min, Long max) { + this.min = min; + this.max = max; + return this; + } + + @Override + public LongFieldControllerBuilder valueFormatter(Function<Long, Component> formatter) { + this.formatter = formatter; + return this; + } + + @Override + public Controller<Long> build() { + return new LongFieldController(option, min, max, formatter); + } +} diff --git a/common/src/main/java/dev/isxander/yacl/impl/controller/LongSliderControllerBuilderImpl.java b/common/src/main/java/dev/isxander/yacl/impl/controller/LongSliderControllerBuilderImpl.java new file mode 100644 index 0000000..24926c4 --- /dev/null +++ b/common/src/main/java/dev/isxander/yacl/impl/controller/LongSliderControllerBuilderImpl.java @@ -0,0 +1,43 @@ +package dev.isxander.yacl.impl.controller; + +import dev.isxander.yacl.api.Controller; +import dev.isxander.yacl.api.Option; +import dev.isxander.yacl.api.controller.LongSliderControllerBuilder; +import dev.isxander.yacl.gui.controllers.slider.LongSliderController; +import net.minecraft.network.chat.Component; + +import java.util.function.Function; + +public class LongSliderControllerBuilderImpl extends AbstractControllerBuilderImpl<Long> implements LongSliderControllerBuilder { + private long min, max; + private long step; + private Function<Long, Component> formatter = LongSliderController.DEFAULT_FORMATTER; + + public LongSliderControllerBuilderImpl(Option<Long> option) { + super(option); + } + + @Override + public LongSliderControllerBuilder range(Long min, Long max) { + this.min = min; + this.max = max; + return this; + } + + @Override + public LongSliderControllerBuilder step(Long step) { + this.step = step; + return this; + } + + @Override + public LongSliderControllerBuilder valueFormatter(Function<Long, Component> formatter) { + this.formatter = formatter; + return this; + } + + @Override + public Controller<Long> build() { + return new LongSliderController(option, min, max, step, formatter); + } +} diff --git a/common/src/main/java/dev/isxander/yacl/impl/controller/StringControllerBuilderImpl.java b/common/src/main/java/dev/isxander/yacl/impl/controller/StringControllerBuilderImpl.java new file mode 100644 index 0000000..17d9e92 --- /dev/null +++ b/common/src/main/java/dev/isxander/yacl/impl/controller/StringControllerBuilderImpl.java @@ -0,0 +1,17 @@ +package dev.isxander.yacl.impl.controller; + +import dev.isxander.yacl.api.Controller; +import dev.isxander.yacl.api.Option; +import dev.isxander.yacl.api.controller.StringControllerBuilder; +import dev.isxander.yacl.gui.controllers.string.StringController; + +public class StringControllerBuilderImpl extends AbstractControllerBuilderImpl<String> implements StringControllerBuilder { + public StringControllerBuilderImpl(Option<String> option) { + super(option); + } + + @Override + public Controller<String> build() { + return new StringController(option); + } +} diff --git a/common/src/main/java/dev/isxander/yacl/impl/controller/TickBoxControllerBuilderImpl.java b/common/src/main/java/dev/isxander/yacl/impl/controller/TickBoxControllerBuilderImpl.java new file mode 100644 index 0000000..6d835cb --- /dev/null +++ b/common/src/main/java/dev/isxander/yacl/impl/controller/TickBoxControllerBuilderImpl.java @@ -0,0 +1,17 @@ +package dev.isxander.yacl.impl.controller; + +import dev.isxander.yacl.api.Controller; +import dev.isxander.yacl.api.Option; +import dev.isxander.yacl.api.controller.TickBoxControllerBuilder; +import dev.isxander.yacl.gui.controllers.TickBoxController; + +public class TickBoxControllerBuilderImpl extends AbstractControllerBuilderImpl<Boolean> implements TickBoxControllerBuilder { + public TickBoxControllerBuilderImpl(Option<Boolean> option) { + super(option); + } + + @Override + public Controller<Boolean> build() { + return new TickBoxController(option); + } +} |