diff options
Diffstat (limited to 'common/src/main/java/dev/isxander/yacl3/impl/controller')
15 files changed, 579 insertions, 0 deletions
diff --git a/common/src/main/java/dev/isxander/yacl3/impl/controller/AbstractControllerBuilderImpl.java b/common/src/main/java/dev/isxander/yacl3/impl/controller/AbstractControllerBuilderImpl.java new file mode 100644 index 0000000..66c025a --- /dev/null +++ b/common/src/main/java/dev/isxander/yacl3/impl/controller/AbstractControllerBuilderImpl.java @@ -0,0 +1,12 @@ +package dev.isxander.yacl3.impl.controller; + +import dev.isxander.yacl3.api.Option; +import dev.isxander.yacl3.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/yacl3/impl/controller/BooleanControllerBuilderImpl.java b/common/src/main/java/dev/isxander/yacl3/impl/controller/BooleanControllerBuilderImpl.java new file mode 100644 index 0000000..208f78e --- /dev/null +++ b/common/src/main/java/dev/isxander/yacl3/impl/controller/BooleanControllerBuilderImpl.java @@ -0,0 +1,56 @@ +package dev.isxander.yacl3.impl.controller; + +import dev.isxander.yacl3.api.Controller; +import dev.isxander.yacl3.api.Option; +import dev.isxander.yacl3.api.controller.BooleanControllerBuilder; +import dev.isxander.yacl3.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/yacl3/impl/controller/ColorControllerBuilderImpl.java b/common/src/main/java/dev/isxander/yacl3/impl/controller/ColorControllerBuilderImpl.java new file mode 100644 index 0000000..9412165 --- /dev/null +++ b/common/src/main/java/dev/isxander/yacl3/impl/controller/ColorControllerBuilderImpl.java @@ -0,0 +1,27 @@ +package dev.isxander.yacl3.impl.controller; + +import dev.isxander.yacl3.api.Controller; +import dev.isxander.yacl3.api.Option; +import dev.isxander.yacl3.api.controller.ColorControllerBuilder; +import dev.isxander.yacl3.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/yacl3/impl/controller/CyclingListControllerBuilderImpl.java b/common/src/main/java/dev/isxander/yacl3/impl/controller/CyclingListControllerBuilderImpl.java new file mode 100644 index 0000000..63045f2 --- /dev/null +++ b/common/src/main/java/dev/isxander/yacl3/impl/controller/CyclingListControllerBuilderImpl.java @@ -0,0 +1,43 @@ +package dev.isxander.yacl3.impl.controller; + +import com.google.common.collect.ImmutableList; +import dev.isxander.yacl3.api.Controller; +import dev.isxander.yacl3.api.Option; +import dev.isxander.yacl3.api.controller.CyclingListControllerBuilder; +import dev.isxander.yacl3.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/yacl3/impl/controller/DoubleFieldControllerBuilderImpl.java b/common/src/main/java/dev/isxander/yacl3/impl/controller/DoubleFieldControllerBuilderImpl.java new file mode 100644 index 0000000..56e1d44 --- /dev/null +++ b/common/src/main/java/dev/isxander/yacl3/impl/controller/DoubleFieldControllerBuilderImpl.java @@ -0,0 +1,50 @@ +package dev.isxander.yacl3.impl.controller; + +import dev.isxander.yacl3.api.Controller; +import dev.isxander.yacl3.api.Option; +import dev.isxander.yacl3.api.controller.DoubleFieldControllerBuilder; +import dev.isxander.yacl3.gui.controllers.slider.DoubleSliderController; +import dev.isxander.yacl3.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/yacl3/impl/controller/DoubleSliderControllerBuilderImpl.java b/common/src/main/java/dev/isxander/yacl3/impl/controller/DoubleSliderControllerBuilderImpl.java new file mode 100644 index 0000000..a636abf --- /dev/null +++ b/common/src/main/java/dev/isxander/yacl3/impl/controller/DoubleSliderControllerBuilderImpl.java @@ -0,0 +1,43 @@ +package dev.isxander.yacl3.impl.controller; + +import dev.isxander.yacl3.api.Controller; +import dev.isxander.yacl3.api.Option; +import dev.isxander.yacl3.api.controller.DoubleSliderControllerBuilder; +import dev.isxander.yacl3.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/yacl3/impl/controller/EnumControllerBuilderImpl.java b/common/src/main/java/dev/isxander/yacl3/impl/controller/EnumControllerBuilderImpl.java new file mode 100644 index 0000000..3237dbf --- /dev/null +++ b/common/src/main/java/dev/isxander/yacl3/impl/controller/EnumControllerBuilderImpl.java @@ -0,0 +1,35 @@ +package dev.isxander.yacl3.impl.controller; + +import dev.isxander.yacl3.api.Controller; +import dev.isxander.yacl3.api.Option; +import dev.isxander.yacl3.api.controller.EnumControllerBuilder; +import dev.isxander.yacl3.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/yacl3/impl/controller/FloatFieldControllerBuilderImpl.java b/common/src/main/java/dev/isxander/yacl3/impl/controller/FloatFieldControllerBuilderImpl.java new file mode 100644 index 0000000..09dbce0 --- /dev/null +++ b/common/src/main/java/dev/isxander/yacl3/impl/controller/FloatFieldControllerBuilderImpl.java @@ -0,0 +1,50 @@ +package dev.isxander.yacl3.impl.controller; + +import dev.isxander.yacl3.api.Controller; +import dev.isxander.yacl3.api.Option; +import dev.isxander.yacl3.api.controller.FloatFieldControllerBuilder; +import dev.isxander.yacl3.gui.controllers.slider.FloatSliderController; +import dev.isxander.yacl3.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/yacl3/impl/controller/FloatSliderControllerBuilderImpl.java b/common/src/main/java/dev/isxander/yacl3/impl/controller/FloatSliderControllerBuilderImpl.java new file mode 100644 index 0000000..c9699fb --- /dev/null +++ b/common/src/main/java/dev/isxander/yacl3/impl/controller/FloatSliderControllerBuilderImpl.java @@ -0,0 +1,43 @@ +package dev.isxander.yacl3.impl.controller; + +import dev.isxander.yacl3.api.Controller; +import dev.isxander.yacl3.api.Option; +import dev.isxander.yacl3.api.controller.FloatSliderControllerBuilder; +import dev.isxander.yacl3.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/yacl3/impl/controller/IntegerFieldControllerBuilderImpl.java b/common/src/main/java/dev/isxander/yacl3/impl/controller/IntegerFieldControllerBuilderImpl.java new file mode 100644 index 0000000..73b51a0 --- /dev/null +++ b/common/src/main/java/dev/isxander/yacl3/impl/controller/IntegerFieldControllerBuilderImpl.java @@ -0,0 +1,50 @@ +package dev.isxander.yacl3.impl.controller; + +import dev.isxander.yacl3.api.Controller; +import dev.isxander.yacl3.api.Option; +import dev.isxander.yacl3.api.controller.IntegerFieldControllerBuilder; +import dev.isxander.yacl3.gui.controllers.slider.IntegerSliderController; +import dev.isxander.yacl3.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/yacl3/impl/controller/IntegerSliderControllerBuilderImpl.java b/common/src/main/java/dev/isxander/yacl3/impl/controller/IntegerSliderControllerBuilderImpl.java new file mode 100644 index 0000000..106c22a --- /dev/null +++ b/common/src/main/java/dev/isxander/yacl3/impl/controller/IntegerSliderControllerBuilderImpl.java @@ -0,0 +1,43 @@ +package dev.isxander.yacl3.impl.controller; + +import dev.isxander.yacl3.api.Controller; +import dev.isxander.yacl3.api.Option; +import dev.isxander.yacl3.api.controller.IntegerSliderControllerBuilder; +import dev.isxander.yacl3.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/yacl3/impl/controller/LongFieldControllerBuilderImpl.java b/common/src/main/java/dev/isxander/yacl3/impl/controller/LongFieldControllerBuilderImpl.java new file mode 100644 index 0000000..88cb610 --- /dev/null +++ b/common/src/main/java/dev/isxander/yacl3/impl/controller/LongFieldControllerBuilderImpl.java @@ -0,0 +1,50 @@ +package dev.isxander.yacl3.impl.controller; + +import dev.isxander.yacl3.api.Controller; +import dev.isxander.yacl3.api.Option; +import dev.isxander.yacl3.api.controller.LongFieldControllerBuilder; +import dev.isxander.yacl3.gui.controllers.slider.LongSliderController; +import dev.isxander.yacl3.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/yacl3/impl/controller/LongSliderControllerBuilderImpl.java b/common/src/main/java/dev/isxander/yacl3/impl/controller/LongSliderControllerBuilderImpl.java new file mode 100644 index 0000000..2bd932a --- /dev/null +++ b/common/src/main/java/dev/isxander/yacl3/impl/controller/LongSliderControllerBuilderImpl.java @@ -0,0 +1,43 @@ +package dev.isxander.yacl3.impl.controller; + +import dev.isxander.yacl3.api.Controller; +import dev.isxander.yacl3.api.Option; +import dev.isxander.yacl3.api.controller.LongSliderControllerBuilder; +import dev.isxander.yacl3.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/yacl3/impl/controller/StringControllerBuilderImpl.java b/common/src/main/java/dev/isxander/yacl3/impl/controller/StringControllerBuilderImpl.java new file mode 100644 index 0000000..a0f51b9 --- /dev/null +++ b/common/src/main/java/dev/isxander/yacl3/impl/controller/StringControllerBuilderImpl.java @@ -0,0 +1,17 @@ +package dev.isxander.yacl3.impl.controller; + +import dev.isxander.yacl3.api.Controller; +import dev.isxander.yacl3.api.Option; +import dev.isxander.yacl3.api.controller.StringControllerBuilder; +import dev.isxander.yacl3.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/yacl3/impl/controller/TickBoxControllerBuilderImpl.java b/common/src/main/java/dev/isxander/yacl3/impl/controller/TickBoxControllerBuilderImpl.java new file mode 100644 index 0000000..3b29719 --- /dev/null +++ b/common/src/main/java/dev/isxander/yacl3/impl/controller/TickBoxControllerBuilderImpl.java @@ -0,0 +1,17 @@ +package dev.isxander.yacl3.impl.controller; + +import dev.isxander.yacl3.api.Controller; +import dev.isxander.yacl3.api.Option; +import dev.isxander.yacl3.api.controller.TickBoxControllerBuilder; +import dev.isxander.yacl3.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); + } +} |