From 98f29ec5c30d23999fce37d7daf7aba8f10f25d3 Mon Sep 17 00:00:00 2001 From: isXander Date: Wed, 16 Aug 2023 12:56:15 +0100 Subject: Add @OverrideName and @OverrideFormat --- .../impl/controller/BooleanControllerBuilderImpl.java | 15 ++++++++------- .../impl/controller/CyclingListControllerBuilderImpl.java | 10 ++++------ .../impl/controller/DoubleFieldControllerBuilderImpl.java | 7 ++++--- .../controller/DoubleSliderControllerBuilderImpl.java | 7 ++++--- .../yacl3/impl/controller/EnumControllerBuilderImpl.java | 13 ++++++++++--- .../impl/controller/FloatFieldControllerBuilderImpl.java | 7 ++++--- .../impl/controller/FloatSliderControllerBuilderImpl.java | 7 ++++--- .../controller/IntegerFieldControllerBuilderImpl.java | 7 ++++--- .../controller/IntegerSliderControllerBuilderImpl.java | 7 ++++--- .../impl/controller/LongFieldControllerBuilderImpl.java | 7 ++++--- .../impl/controller/LongSliderControllerBuilderImpl.java | 7 ++++--- 11 files changed, 54 insertions(+), 40 deletions(-) (limited to 'common/src/main/java/dev/isxander/yacl3/impl') 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 index 208f78e..063a177 100644 --- a/common/src/main/java/dev/isxander/yacl3/impl/controller/BooleanControllerBuilderImpl.java +++ b/common/src/main/java/dev/isxander/yacl3/impl/controller/BooleanControllerBuilderImpl.java @@ -3,6 +3,7 @@ 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.api.controller.ValueFormatter; import dev.isxander.yacl3.gui.controllers.BooleanController; import net.minecraft.network.chat.Component; import org.apache.commons.lang3.Validate; @@ -11,7 +12,7 @@ import java.util.function.Function; public class BooleanControllerBuilderImpl extends AbstractControllerBuilderImpl implements BooleanControllerBuilder { private boolean coloured = false; - private Function formatter = BooleanController.ON_OFF_FORMATTER; + private ValueFormatter formatter = BooleanController.ON_OFF_FORMATTER::apply; public BooleanControllerBuilderImpl(Option option) { super(option); @@ -24,8 +25,8 @@ public class BooleanControllerBuilderImpl extends AbstractControllerBuilderImpl< } @Override - public BooleanControllerBuilder valueFormatter(Function formatter) { - Validate.notNull(formatter); + public BooleanControllerBuilder formatValue(ValueFormatter formatter) { + Validate.notNull(formatter, "formatter cannot be null"); this.formatter = formatter; return this; @@ -33,24 +34,24 @@ public class BooleanControllerBuilderImpl extends AbstractControllerBuilderImpl< @Override public BooleanControllerBuilder onOffFormatter() { - this.formatter = BooleanController.ON_OFF_FORMATTER; + this.formatter = BooleanController.ON_OFF_FORMATTER::apply; return this; } @Override public BooleanControllerBuilder yesNoFormatter() { - this.formatter = BooleanController.YES_NO_FORMATTER; + this.formatter = BooleanController.YES_NO_FORMATTER::apply; return this; } @Override public BooleanControllerBuilder trueFalseFormatter() { - this.formatter = BooleanController.TRUE_FALSE_FORMATTER; + this.formatter = BooleanController.TRUE_FALSE_FORMATTER::apply; return this; } @Override public Controller build() { - return new BooleanController(option, formatter, coloured); + return BooleanController.createInternal(option, formatter, coloured); } } 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 index 63045f2..8e2e481 100644 --- a/common/src/main/java/dev/isxander/yacl3/impl/controller/CyclingListControllerBuilderImpl.java +++ b/common/src/main/java/dev/isxander/yacl3/impl/controller/CyclingListControllerBuilderImpl.java @@ -4,14 +4,12 @@ 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.api.controller.ValueFormatter; import dev.isxander.yacl3.gui.controllers.cycling.CyclingListController; -import net.minecraft.network.chat.Component; - -import java.util.function.Function; public final class CyclingListControllerBuilderImpl extends AbstractControllerBuilderImpl implements CyclingListControllerBuilder { private Iterable values; - private Function formatter = null; + private ValueFormatter formatter = null; public CyclingListControllerBuilderImpl(Option option) { super(option); @@ -31,13 +29,13 @@ public final class CyclingListControllerBuilderImpl extends AbstractControlle } @Override - public CyclingListControllerBuilder valueFormatter(Function formatter) { + public CyclingListControllerBuilder formatValue(ValueFormatter formatter) { this.formatter = formatter; return this; } @Override public Controller build() { - return new CyclingListController<>(option, values, formatter); + return CyclingListController.createInternal(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 index 56e1d44..8d84e7d 100644 --- a/common/src/main/java/dev/isxander/yacl3/impl/controller/DoubleFieldControllerBuilderImpl.java +++ b/common/src/main/java/dev/isxander/yacl3/impl/controller/DoubleFieldControllerBuilderImpl.java @@ -3,6 +3,7 @@ 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.api.controller.ValueFormatter; import dev.isxander.yacl3.gui.controllers.slider.DoubleSliderController; import dev.isxander.yacl3.gui.controllers.string.number.DoubleFieldController; import net.minecraft.network.chat.Component; @@ -12,7 +13,7 @@ import java.util.function.Function; public class DoubleFieldControllerBuilderImpl extends AbstractControllerBuilderImpl implements DoubleFieldControllerBuilder { private double min = Double.MIN_VALUE; private double max = Double.MAX_VALUE; - private Function formatter = DoubleSliderController.DEFAULT_FORMATTER; + private ValueFormatter formatter = DoubleSliderController.DEFAULT_FORMATTER::apply; public DoubleFieldControllerBuilderImpl(Option option) { super(option); @@ -38,13 +39,13 @@ public class DoubleFieldControllerBuilderImpl extends AbstractControllerBuilderI } @Override - public DoubleFieldControllerBuilder valueFormatter(Function formatter) { + public DoubleFieldControllerBuilder formatValue(ValueFormatter formatter) { this.formatter = formatter; return this; } @Override public Controller build() { - return new DoubleFieldController(option, min, max, formatter); + return DoubleFieldController.createInternal(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 index a636abf..b696d57 100644 --- a/common/src/main/java/dev/isxander/yacl3/impl/controller/DoubleSliderControllerBuilderImpl.java +++ b/common/src/main/java/dev/isxander/yacl3/impl/controller/DoubleSliderControllerBuilderImpl.java @@ -3,6 +3,7 @@ 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.api.controller.ValueFormatter; import dev.isxander.yacl3.gui.controllers.slider.DoubleSliderController; import net.minecraft.network.chat.Component; @@ -11,7 +12,7 @@ import java.util.function.Function; public class DoubleSliderControllerBuilderImpl extends AbstractControllerBuilderImpl implements DoubleSliderControllerBuilder { private double min, max; private double step; - private Function formatter = DoubleSliderController.DEFAULT_FORMATTER; + private ValueFormatter formatter = DoubleSliderController.DEFAULT_FORMATTER::apply; public DoubleSliderControllerBuilderImpl(Option option) { super(option); @@ -31,13 +32,13 @@ public class DoubleSliderControllerBuilderImpl extends AbstractControllerBuilder } @Override - public DoubleSliderControllerBuilder valueFormatter(Function formatter) { + public DoubleSliderControllerBuilder formatValue(ValueFormatter formatter) { this.formatter = formatter; return this; } @Override public Controller build() { - return new DoubleSliderController(option, min, max, step, formatter); + return DoubleSliderController.createInternal(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 index 3237dbf..04ee2a0 100644 --- a/common/src/main/java/dev/isxander/yacl3/impl/controller/EnumControllerBuilderImpl.java +++ b/common/src/main/java/dev/isxander/yacl3/impl/controller/EnumControllerBuilderImpl.java @@ -3,6 +3,7 @@ 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.api.controller.ValueFormatter; import dev.isxander.yacl3.gui.controllers.cycling.EnumController; import net.minecraft.network.chat.Component; @@ -10,7 +11,7 @@ import java.util.function.Function; public class EnumControllerBuilderImpl> extends AbstractControllerBuilderImpl implements EnumControllerBuilder { private Class enumClass; - private Function formatter = EnumController.getDefaultFormatter(); + private ValueFormatter formatter = null; public EnumControllerBuilderImpl(Option option) { super(option); @@ -23,13 +24,19 @@ public class EnumControllerBuilderImpl> extends AbstractContro } @Override - public EnumControllerBuilder valueFormatter(Function formatter) { + public EnumControllerBuilder formatValue(ValueFormatter formatter) { this.formatter = formatter; return this; } @Override public Controller build() { - return new EnumController<>(option, formatter, enumClass.getEnumConstants()); + ValueFormatter formatter = this.formatter; + if (formatter == null) { + Function formatFunction = EnumController.getDefaultFormatter(); + formatter = formatFunction::apply; + } + + return EnumController.createInternal(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 index 09dbce0..08fefd0 100644 --- a/common/src/main/java/dev/isxander/yacl3/impl/controller/FloatFieldControllerBuilderImpl.java +++ b/common/src/main/java/dev/isxander/yacl3/impl/controller/FloatFieldControllerBuilderImpl.java @@ -3,6 +3,7 @@ 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.api.controller.ValueFormatter; import dev.isxander.yacl3.gui.controllers.slider.FloatSliderController; import dev.isxander.yacl3.gui.controllers.string.number.FloatFieldController; import net.minecraft.network.chat.Component; @@ -12,7 +13,7 @@ import java.util.function.Function; public class FloatFieldControllerBuilderImpl extends AbstractControllerBuilderImpl implements FloatFieldControllerBuilder { private float min = Float.MIN_VALUE; private float max = Float.MAX_VALUE; - private Function formatter = FloatSliderController.DEFAULT_FORMATTER; + private ValueFormatter formatter = FloatSliderController.DEFAULT_FORMATTER::apply; public FloatFieldControllerBuilderImpl(Option option) { super(option); @@ -38,13 +39,13 @@ public class FloatFieldControllerBuilderImpl extends AbstractControllerBuilderIm } @Override - public FloatFieldControllerBuilder valueFormatter(Function formatter) { + public FloatFieldControllerBuilder formatValue(ValueFormatter formatter) { this.formatter = formatter; return this; } @Override public Controller build() { - return new FloatFieldController(option, min, max, formatter); + return FloatFieldController.createInternal(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 index c9699fb..9b2d75b 100644 --- a/common/src/main/java/dev/isxander/yacl3/impl/controller/FloatSliderControllerBuilderImpl.java +++ b/common/src/main/java/dev/isxander/yacl3/impl/controller/FloatSliderControllerBuilderImpl.java @@ -3,6 +3,7 @@ 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.api.controller.ValueFormatter; import dev.isxander.yacl3.gui.controllers.slider.FloatSliderController; import net.minecraft.network.chat.Component; @@ -11,7 +12,7 @@ import java.util.function.Function; public class FloatSliderControllerBuilderImpl extends AbstractControllerBuilderImpl implements FloatSliderControllerBuilder { private float min, max; private float step; - private Function formatter = FloatSliderController.DEFAULT_FORMATTER; + private ValueFormatter formatter = FloatSliderController.DEFAULT_FORMATTER::apply; public FloatSliderControllerBuilderImpl(Option option) { super(option); @@ -31,13 +32,13 @@ public class FloatSliderControllerBuilderImpl extends AbstractControllerBuilderI } @Override - public FloatSliderControllerBuilder valueFormatter(Function formatter) { + public FloatSliderControllerBuilder formatValue(ValueFormatter formatter) { this.formatter = formatter; return this; } @Override public Controller build() { - return new FloatSliderController(option, min, max, step, formatter); + return FloatSliderController.createInternal(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 index 73b51a0..1435c49 100644 --- a/common/src/main/java/dev/isxander/yacl3/impl/controller/IntegerFieldControllerBuilderImpl.java +++ b/common/src/main/java/dev/isxander/yacl3/impl/controller/IntegerFieldControllerBuilderImpl.java @@ -3,6 +3,7 @@ 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.api.controller.ValueFormatter; import dev.isxander.yacl3.gui.controllers.slider.IntegerSliderController; import dev.isxander.yacl3.gui.controllers.string.number.IntegerFieldController; import net.minecraft.network.chat.Component; @@ -12,7 +13,7 @@ import java.util.function.Function; public class IntegerFieldControllerBuilderImpl extends AbstractControllerBuilderImpl implements IntegerFieldControllerBuilder { private int min = Integer.MIN_VALUE; private int max = Integer.MAX_VALUE; - private Function formatter = IntegerSliderController.DEFAULT_FORMATTER; + private ValueFormatter formatter = IntegerSliderController.DEFAULT_FORMATTER::apply; public IntegerFieldControllerBuilderImpl(Option option) { super(option); @@ -38,13 +39,13 @@ public class IntegerFieldControllerBuilderImpl extends AbstractControllerBuilder } @Override - public IntegerFieldControllerBuilder valueFormatter(Function formatter) { + public IntegerFieldControllerBuilder formatValue(ValueFormatter formatter) { this.formatter = formatter; return this; } @Override public Controller build() { - return new IntegerFieldController(option, min, max, formatter); + return IntegerFieldController.createInternal(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 index 106c22a..b9395a0 100644 --- a/common/src/main/java/dev/isxander/yacl3/impl/controller/IntegerSliderControllerBuilderImpl.java +++ b/common/src/main/java/dev/isxander/yacl3/impl/controller/IntegerSliderControllerBuilderImpl.java @@ -3,6 +3,7 @@ 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.api.controller.ValueFormatter; import dev.isxander.yacl3.gui.controllers.slider.IntegerSliderController; import net.minecraft.network.chat.Component; @@ -11,7 +12,7 @@ import java.util.function.Function; public class IntegerSliderControllerBuilderImpl extends AbstractControllerBuilderImpl implements IntegerSliderControllerBuilder { private int min, max; private int step; - private Function formatter = IntegerSliderController.DEFAULT_FORMATTER; + private ValueFormatter formatter = IntegerSliderController.DEFAULT_FORMATTER::apply; public IntegerSliderControllerBuilderImpl(Option option) { super(option); @@ -31,13 +32,13 @@ public class IntegerSliderControllerBuilderImpl extends AbstractControllerBuilde } @Override - public IntegerSliderControllerBuilder valueFormatter(Function formatter) { + public IntegerSliderControllerBuilder formatValue(ValueFormatter formatter) { this.formatter = formatter; return this; } @Override public Controller build() { - return new IntegerSliderController(option, min, max, step, formatter); + return IntegerSliderController.createInternal(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 index 88cb610..c7a3ea4 100644 --- a/common/src/main/java/dev/isxander/yacl3/impl/controller/LongFieldControllerBuilderImpl.java +++ b/common/src/main/java/dev/isxander/yacl3/impl/controller/LongFieldControllerBuilderImpl.java @@ -3,6 +3,7 @@ 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.api.controller.ValueFormatter; import dev.isxander.yacl3.gui.controllers.slider.LongSliderController; import dev.isxander.yacl3.gui.controllers.string.number.LongFieldController; import net.minecraft.network.chat.Component; @@ -12,7 +13,7 @@ import java.util.function.Function; public class LongFieldControllerBuilderImpl extends AbstractControllerBuilderImpl implements LongFieldControllerBuilder { private long min = Long.MIN_VALUE; private long max = Long.MAX_VALUE; - private Function formatter = LongSliderController.DEFAULT_FORMATTER; + private ValueFormatter formatter = LongSliderController.DEFAULT_FORMATTER::apply; public LongFieldControllerBuilderImpl(Option option) { super(option); @@ -38,13 +39,13 @@ public class LongFieldControllerBuilderImpl extends AbstractControllerBuilderImp } @Override - public LongFieldControllerBuilder valueFormatter(Function formatter) { + public LongFieldControllerBuilder formatValue(ValueFormatter formatter) { this.formatter = formatter; return this; } @Override public Controller build() { - return new LongFieldController(option, min, max, formatter); + return LongFieldController.createInternal(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 index 2bd932a..5eda424 100644 --- a/common/src/main/java/dev/isxander/yacl3/impl/controller/LongSliderControllerBuilderImpl.java +++ b/common/src/main/java/dev/isxander/yacl3/impl/controller/LongSliderControllerBuilderImpl.java @@ -3,6 +3,7 @@ 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.api.controller.ValueFormatter; import dev.isxander.yacl3.gui.controllers.slider.LongSliderController; import net.minecraft.network.chat.Component; @@ -11,7 +12,7 @@ import java.util.function.Function; public class LongSliderControllerBuilderImpl extends AbstractControllerBuilderImpl implements LongSliderControllerBuilder { private long min, max; private long step; - private Function formatter = LongSliderController.DEFAULT_FORMATTER; + private ValueFormatter formatter = LongSliderController.DEFAULT_FORMATTER::apply; public LongSliderControllerBuilderImpl(Option option) { super(option); @@ -31,13 +32,13 @@ public class LongSliderControllerBuilderImpl extends AbstractControllerBuilderIm } @Override - public LongSliderControllerBuilder valueFormatter(Function formatter) { + public LongSliderControllerBuilder formatValue(ValueFormatter formatter) { this.formatter = formatter; return this; } @Override public Controller build() { - return new LongSliderController(option, min, max, step, formatter); + return LongSliderController.createInternal(option, min, max, step, formatter); } } -- cgit