aboutsummaryrefslogtreecommitdiff
path: root/src/client/java/dev/isxander/yacl/gui/controllers/string
diff options
context:
space:
mode:
authorXander <xander@isxander.dev>2023-04-25 16:28:41 +0100
committerGitHub <noreply@github.com>2023-04-25 16:28:41 +0100
commit13c7ba45ff201423eb8dba8a40cfb66ebb531439 (patch)
tree1e799aa9da11fbc0833bc6b7c6e6799633c2ec50 /src/client/java/dev/isxander/yacl/gui/controllers/string
parent8ba7196ae990fe9aa98680aba1b387e385fff99c (diff)
downloadYetAnotherConfigLib-13c7ba45ff201423eb8dba8a40cfb66ebb531439.tar.gz
YetAnotherConfigLib-13c7ba45ff201423eb8dba8a40cfb66ebb531439.tar.bz2
YetAnotherConfigLib-13c7ba45ff201423eb8dba8a40cfb66ebb531439.zip
Architectury! (#61)
Diffstat (limited to 'src/client/java/dev/isxander/yacl/gui/controllers/string')
-rw-r--r--src/client/java/dev/isxander/yacl/gui/controllers/string/IStringController.java44
-rw-r--r--src/client/java/dev/isxander/yacl/gui/controllers/string/StringController.java40
-rw-r--r--src/client/java/dev/isxander/yacl/gui/controllers/string/StringControllerElement.java408
-rw-r--r--src/client/java/dev/isxander/yacl/gui/controllers/string/number/DoubleFieldController.java104
-rw-r--r--src/client/java/dev/isxander/yacl/gui/controllers/string/number/FloatFieldController.java104
-rw-r--r--src/client/java/dev/isxander/yacl/gui/controllers/string/number/IntegerFieldController.java109
-rw-r--r--src/client/java/dev/isxander/yacl/gui/controllers/string/number/LongFieldController.java109
-rw-r--r--src/client/java/dev/isxander/yacl/gui/controllers/string/number/NumberFieldController.java69
-rw-r--r--src/client/java/dev/isxander/yacl/gui/controllers/string/number/package-info.java10
9 files changed, 0 insertions, 997 deletions
diff --git a/src/client/java/dev/isxander/yacl/gui/controllers/string/IStringController.java b/src/client/java/dev/isxander/yacl/gui/controllers/string/IStringController.java
deleted file mode 100644
index 6a603d2..0000000
--- a/src/client/java/dev/isxander/yacl/gui/controllers/string/IStringController.java
+++ /dev/null
@@ -1,44 +0,0 @@
-package dev.isxander.yacl.gui.controllers.string;
-
-import dev.isxander.yacl.api.Controller;
-import dev.isxander.yacl.api.Option;
-import dev.isxander.yacl.api.utils.Dimension;
-import dev.isxander.yacl.gui.AbstractWidget;
-import dev.isxander.yacl.gui.YACLScreen;
-import net.minecraft.network.chat.Component;
-
-/**
- * A controller that can be any type but can input and output a string.
- */
-public interface IStringController<T> extends Controller<T> {
- /**
- * Gets the option's pending value as a string.
- *
- * @see Option#pendingValue()
- */
- String getString();
-
- /**
- * Sets the option's pending value from a string.
- *
- * @see Option#requestSet(Object)
- */
- void setFromString(String value);
-
- /**
- * {@inheritDoc}
- */
- @Override
- default Component formatValue() {
- return Component.literal(getString());
- }
-
- default boolean isInputValid(String input) {
- return true;
- }
-
- @Override
- default AbstractWidget provideWidget(YACLScreen screen, Dimension<Integer> widgetDimension) {
- return new StringControllerElement(this, screen, widgetDimension, true);
- }
-}
diff --git a/src/client/java/dev/isxander/yacl/gui/controllers/string/StringController.java b/src/client/java/dev/isxander/yacl/gui/controllers/string/StringController.java
deleted file mode 100644
index 3a07641..0000000
--- a/src/client/java/dev/isxander/yacl/gui/controllers/string/StringController.java
+++ /dev/null
@@ -1,40 +0,0 @@
-package dev.isxander.yacl.gui.controllers.string;
-
-import dev.isxander.yacl.api.Option;
-import dev.isxander.yacl.api.utils.Dimension;
-import dev.isxander.yacl.gui.AbstractWidget;
-import dev.isxander.yacl.gui.YACLScreen;
-
-/**
- * A custom text field implementation for strings.
- */
-public class StringController implements IStringController<String> {
- private final Option<String> option;
-
- /**
- * Constructs a string controller
- *
- * @param option bound option
- */
- public StringController(Option<String> option) {
- this.option = option;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public Option<String> option() {
- return option;
- }
-
- @Override
- public String getString() {
- return option().pendingValue();
- }
-
- @Override
- public void setFromString(String value) {
- option().requestSet(value);
- }
-}
diff --git a/src/client/java/dev/isxander/yacl/gui/controllers/string/StringControllerElement.java b/src/client/java/dev/isxander/yacl/gui/controllers/string/StringControllerElement.java
deleted file mode 100644
index cb2ad4e..0000000
--- a/src/client/java/dev/isxander/yacl/gui/controllers/string/StringControllerElement.java
+++ /dev/null
@@ -1,408 +0,0 @@
-package dev.isxander.yacl.gui.controllers.string;
-
-import com.mojang.blaze3d.platform.InputConstants;
-import com.mojang.blaze3d.systems.RenderSystem;
-import com.mojang.blaze3d.vertex.PoseStack;
-import dev.isxander.yacl.api.utils.Dimension;
-import dev.isxander.yacl.gui.YACLScreen;
-import dev.isxander.yacl.gui.controllers.ControllerWidget;
-import dev.isxander.yacl.gui.utils.GuiUtils;
-import net.minecraft.ChatFormatting;
-import net.minecraft.client.gui.GuiComponent;
-import net.minecraft.client.gui.screens.Screen;
-import net.minecraft.network.chat.Component;
-
-import java.util.function.Consumer;
-
-public class StringControllerElement extends ControllerWidget<IStringController<?>> {
- protected final boolean instantApply;
-
- protected String inputField;
- protected Dimension<Integer> inputFieldBounds;
- protected boolean inputFieldFocused;
-
- protected int caretPos;
- protected int selectionLength;
-
- protected int renderOffset;
-
- protected float ticks;
-
- private final Component emptyText;
-
- public StringControllerElement(IStringController<?> control, YACLScreen screen, Dimension<Integer> dim, boolean instantApply) {
- super(control, screen, dim);
- this.instantApply = instantApply;
- inputField = control.getString();
- inputFieldFocused = false;
- selectionLength = 0;
- emptyText = Component.literal("Click to type...").withStyle(ChatFormatting.GRAY);
- control.option().addListener((opt, val) -> inputField = control.getString());
- setDimension(dim);
- }
-
- @Override
- protected void drawHoveredControl(PoseStack matrices, int mouseX, int mouseY, float delta) {
-
- }
-
- @Override
- protected void drawValueText(PoseStack matrices, int mouseX, int mouseY, float delta) {
- Component valueText = getValueText();
- if (!isHovered()) valueText = Component.literal(GuiUtils.shortenString(valueText.getString(), textRenderer, getMaxUnwrapLength(), "...")).setStyle(valueText.getStyle());
-
- matrices.pushPose();
- int textX = getDimension().xLimit() - textRenderer.width(valueText) + renderOffset - getXPadding();
- matrices.translate(textX, getTextY(), 0);
- GuiUtils.enableScissor(inputFieldBounds.x(), inputFieldBounds.y() - 2, inputFieldBounds.width() + 1, inputFieldBounds.height() + 4);
- textRenderer.drawShadow(matrices, valueText, 0, 0, getValueColor());
- matrices.popPose();
-
- if (isHovered()) {
- ticks += delta;
-
- String text = getValueText().getString();
-
- GuiComponent.fill(matrices, inputFieldBounds.x(), inputFieldBounds.yLimit(), inputFieldBounds.xLimit(), inputFieldBounds.yLimit() + 1, -1);
- GuiComponent.fill(matrices, inputFieldBounds.x() + 1, inputFieldBounds.yLimit() + 1, inputFieldBounds.xLimit() + 1, inputFieldBounds.yLimit() + 2, 0xFF404040);
-
- if (inputFieldFocused || focused) {
- if (caretPos > text.length())
- caretPos = text.length();
-
- int caretX = textX + textRenderer.width(text.substring(0, caretPos)) - 1;
- if (text.isEmpty())
- caretX = inputFieldBounds.x() + inputFieldBounds.width() / 2;
-
- if (ticks % 20 <= 10) {
- GuiComponent.fill(matrices, caretX, inputFieldBounds.y(), caretX + 1, inputFieldBounds.yLimit(), -1);
- }
-
- if (selectionLength != 0) {
- int selectionX = textX + textRenderer.width(text.substring(0, caretPos + selectionLength));
- GuiComponent.fill(matrices, caretX, inputFieldBounds.y() - 1, selectionX, inputFieldBounds.yLimit(), 0x803030FF);
- }
- }
- }
- RenderSystem.disableScissor();
- }
-
- @Override
- public boolean mouseClicked(double mouseX, double mouseY, int button) {
- if (isAvailable() && getDimension().isPointInside((int) mouseX, (int) mouseY)) {
- inputFieldFocused = true;
-
- if (!inputFieldBounds.isPointInside((int) mouseX, (int) mouseY)) {
- caretPos = getDefaultCaretPos();
- } else {
- // gets the appropriate caret position for where you click
- int textX = (int) mouseX - (inputFieldBounds.xLimit() - textRenderer.width(getValueText()));
- int pos = -1;
- int currentWidth = 0;
- for (char ch : inputField.toCharArray()) {
- pos++;
- int charLength = textRenderer.width(String.valueOf(ch));
- if (currentWidth + charLength / 2 > textX) { // if more than halfway past the characters select in front of that char
- caretPos = pos;
- break;
- } else if (pos == inputField.length() - 1) {
- // if we have reached the end and no matches, it must be the second half of the char so the last position
- caretPos = pos + 1;
- }
- currentWidth += charLength;
- }
-
- selectionLength = 0;
- }
- return true;
- } else {
- inputFieldFocused = false;
- }
-
- return false;
- }
-
- protected int getDefaultCaretPos() {
- return inputField.length();
- }
-
- @Override
- public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
- if (!inputFieldFocused)
- return false;
-
- switch (keyCode) {
- case InputConstants.KEY_ESCAPE, InputConstants.KEY_RETURN -> {
- unfocus();
- return true;
- }
- case InputConstants.KEY_LEFT -> {
- if (Screen.hasShiftDown()) {
- if (Screen.hasControlDown()) {
- int spaceChar = findSpaceIndex(true);
- selectionLength += caretPos - spaceChar;
- caretPos = spaceChar;
- } else if (caretPos > 0) {
- caretPos--;
- selectionLength += 1;
- }
- checkRenderOffset();
- } else {
- if (caretPos > 0) {
- if (selectionLength != 0)
- caretPos += Math.min(selectionLength, 0);
- else
- caretPos--;
- }
- checkRenderOffset();
- selectionLength = 0;
- }
-
- return true;
- }
- case InputConstants.KEY_RIGHT -> {
- if (Screen.hasShiftDown()) {
- if (Screen.hasControlDown()) {
- int spaceChar = findSpaceIndex(false);
- selectionLength -= spaceChar - caretPos;
- caretPos = spaceChar;
- } else if (caretPos < inputField.length()) {
- caretPos++;
- selectionLength -= 1;
- }
- checkRenderOffset();
- } else {
- if (caretPos < inputField.length()) {
- if (selectionLength != 0)
- caretPos += Math.max(selectionLength, 0);
- else
- caretPos++;
- checkRenderOffset();
- }
- selectionLength = 0;
- }
-
- return true;
- }
- case InputConstants.KEY_BACKSPACE -> {
- doBackspace();
- return true;
- }
- case InputConstants.KEY_DELETE -> {
- doDelete();
- return true;
- }
- }
-
- if (Screen.isPaste(keyCode)) {
- return doPaste();
- } else if (Screen.isCopy(keyCode)) {
- return doCopy();
- } else if (Screen.isCut(keyCode)) {
- return doCut();
- } else if (Screen.isSelectAll(keyCode)) {
- return doSelectAll();
- }
-
- return false;
- }
-
- protected boolean doPaste() {
- this.write(client.keyboardHandler.getClipboard());
- return true;
- }
-
- protected boolean doCopy() {
- if (selectionLength != 0) {
- client.keyboardHandler.setClipboard(getSelection());
- return true;
- }
- return false;
- }
-
- protected boolean doCut() {
- if (selectionLength != 0) {
- client.keyboardHandler.setClipboard(getSelection());
- this.write("");
- return true;
- }
- return false;
- }
-
- protected boolean doSelectAll() {
- caretPos = inputField.length();
- checkRenderOffset();
- selectionLength = -caretPos;
- return true;
- }
-
- protected void checkRenderOffset() {
- if (textRenderer.width(inputField) < getUnshiftedLength()) {
- renderOffset = 0;
- return;
- }
-
- int textX = getDimension().xLimit() - textRenderer.width(inputField) - getXPadding();
- int caretX = textX + textRenderer.width(inputField.substring(0, caretPos)) - 1;
-
- int minX = getDimension().xLimit() - getXPadding() - getUnshiftedLength();
- int maxX = minX + getUnshiftedLength();
-
- if (caretX + renderOffset < minX) {
- renderOffset = minX - caretX;
- } else if (caretX + renderOffset > maxX) {
- renderOffset = maxX - caretX;
- }
- }
-
- @Override
- public boolean charTyped(char chr, int modifiers) {
- if (!inputFieldFocused)
- return false;
-
- write(Character.toString(chr));
-
- return true;
- }
-
- protected void doBackspace() {
- if (selectionLength != 0) {
- write("");
- } else if (caretPos > 0) {
- if (modifyInput(builder -> builder.deleteCharAt(caretPos - 1))) {
- caretPos--;
- checkRenderOffset();
- }
- }
- }
-
- protected void doDelete() {
- if (selectionLength != 0) {
- write("");
- } else if (caretPos < inputField.length()) {
- modifyInput(builder -> builder.deleteCharAt(caretPos));
- }
- }
-
- public void write(String string) {
- if (selectionLength == 0) {
- if (modifyInput(builder -> builder.insert(caretPos, string))) {
- caretPos += string.length();
- checkRenderOffset();
- }
- } else {
- int start = getSelectionStart();
- int end = getSelectionEnd();
-
- if (modifyInput(builder -> builder.replace(start, end, string))) {
- caretPos = start + string.length();
- selectionLength = 0;
- checkRenderOffset();
- }
- }
- }
-
- public boolean modifyInput(Consumer<StringBuilder> consumer) {
- StringBuilder temp = new StringBuilder(inputField);
- consumer.accept(temp);
- if (!control.isInputValid(temp.toString()))
- return false;
- inputField = temp.toString();
- if (instantApply)
- updateControl();
- return true;
- }
-
- public int getUnshiftedLength() {
- if (optionNameString.isEmpty())
- return getDimension().width() - getXPadding() * 2;
- return getDimension().width() / 8 * 5;
- }
-
- public int getMaxUnwrapLength() {
- if (optionNameString.isEmpty())
- return getDimension().width() - getXPadding() * 2;
- return getDimension().width() / 2;
- }
-
- public int getSelectionStart() {
- return Math.min(caretPos, caretPos + selectionLength);
- }
-
- public int getSelectionEnd() {
- return Math.max(caretPos, caretPos + selectionLength);
- }
-
- protected String getSelection() {
- return inputField.substring(getSelectionStart(), getSelectionEnd());
- }
-
- protected int findSpaceIndex(boolean reverse) {
- int i;
- int fromIndex = caretPos;
- if (reverse) {
- if (caretPos > 0)
- fromIndex -= 1;
- i = this.inputField.lastIndexOf(" ", fromIndex);
-
- if (i == -1) i = 0;
- } else {
- if (caretPos < inputField.length())
- fromIndex += 1;
- i = this.inputField.indexOf(" ", fromIndex);
-
- if (i == -1) i = inputField.length();
- }
-
- return i;
- }
-
- @Override
- public void setFocused(boolean focused) {
- super.setFocused(focused);
- inputFieldFocused = focused;
- }
-
- @Override
- public void unfocus() {
- super.unfocus();
- inputFieldFocused = false;
- renderOffset = 0;
- if (!instantApply) updateControl();
- }
-
- @Override
- public void setDimension(Dimension<Integer> dim) {
- super.setDimension(dim);
-
- int width = Math.max(6, Math.min(textRenderer.width(getValueText()), getUnshiftedLength()));
- inputFieldBounds = Dimension.ofInt(dim.xLimit() - getXPadding() - width, dim.centerY() - textRenderer.lineHeight / 2, width, textRenderer.lineHeight);
- }
-
- @Override
- public boolean isHovered() {
- return super.isHovered() || inputFieldFocused;
- }
-
- protected void updateControl() {
- control.setFromString(inputField);
- }
-
- @Override
- protected int getUnhoveredControlWidth() {
- return !isHovered() ? Math.min(getHoveredControlWidth(), getMaxUnwrapLength()) : getHoveredControlWidth();
- }
-
- @Override
- protected int getHoveredControlWidth() {
- return Math.min(textRenderer.width(getValueText()), getUnshiftedLength());
- }
-
- @Override
- protected Component getValueText() {
- if (!inputFieldFocused && inputField.isEmpty())
- return emptyText;
-
- return instantApply || !inputFieldFocused ? control.formatValue() : Component.literal(inputField);
- }
-}
diff --git a/src/client/java/dev/isxander/yacl/gui/controllers/string/number/DoubleFieldController.java b/src/client/java/dev/isxander/yacl/gui/controllers/string/number/DoubleFieldController.java
deleted file mode 100644
index df28241..0000000
--- a/src/client/java/dev/isxander/yacl/gui/controllers/string/number/DoubleFieldController.java
+++ /dev/null
@@ -1,104 +0,0 @@
-package dev.isxander.yacl.gui.controllers.string.number;
-
-import dev.isxander.yacl.api.Option;
-import dev.isxander.yacl.gui.controllers.slider.DoubleSliderController;
-import net.minecraft.network.chat.Component;
-
-import java.util.function.Function;
-
-/**
- * {@inheritDoc}
- */
-public class DoubleFieldController extends NumberFieldController<Double> {
- private final double min, max;
-
- /**
- * Constructs a double field controller
- *
- * @param option option to bind controller to
- * @param min minimum allowed value (clamped on apply)
- * @param max maximum allowed value (clamped on apply)
- * @param formatter display text, not used whilst editing
- */
- public DoubleFieldController(Option<Double> option, double min, double max, Function<Double, Component> formatter) {
- super(option, formatter);
- this.min = min;
- this.max = max;
- }
-
- /**
- * Constructs a double field controller.
- * Uses {@link DoubleSliderController#DEFAULT_FORMATTER} as display text,
- * not used whilst editing.
- *
- * @param option option to bind controller to
- * @param min minimum allowed value (clamped on apply)
- * @param max maximum allowed value (clamped on apply)
- */
- public DoubleFieldController(Option<Double> option, double min, double max) {
- this(option, min, max, DoubleSliderController.DEFAULT_FORMATTER);
- }
-
- /**
- * Constructs a double field controller.
- * Does not have a minimum or a maximum range.
- *
- * @param option option to bind controller to
- * @param formatter display text, not used whilst editing
- */
- public DoubleFieldController(Option<Double> option, Function<Double, Component> formatter) {
- this(option, -Double.MAX_VALUE, Double.MAX_VALUE, formatter);
- }
-
- /**
- * Constructs a double field controller.
- * Uses {@link DoubleSliderController#DEFAULT_FORMATTER} as display text,
- * not used whilst editing.
- * Does not have a minimum or a maximum range.
- *
- * @param option option to bind controller to
- */
- public DoubleFieldController(Option<Double> option) {
- this(option, -Double.MAX_VALUE, Double.MAX_VALUE, DoubleSliderController.DEFAULT_FORMATTER);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public double min() {
- return this.min;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public double max() {
- return this.max;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public String getString() {
- return String.valueOf(option().pendingValue());
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void setPendingValue(double value) {
- option().requestSet(value);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public double pendingValue() {
- return option().pendingValue();
- }
-}
diff --git a/src/client/java/dev/isxander/yacl/gui/controllers/string/number/FloatFieldController.java b/src/client/java/dev/isxander/yacl/gui/controllers/string/number/FloatFieldController.java
deleted file mode 100644
index 957100a..0000000
--- a/src/client/java/dev/isxander/yacl/gui/controllers/string/number/FloatFieldController.java
+++ /dev/null
@@ -1,104 +0,0 @@
-package dev.isxander.yacl.gui.controllers.string.number;
-
-import dev.isxander.yacl.api.Option;
-import dev.isxander.yacl.gui.controllers.slider.FloatSliderController;
-import net.minecraft.network.chat.Component;
-
-import java.util.function.Function;
-
-/**
- * {@inheritDoc}
- */
-public class FloatFieldController extends NumberFieldController<Float> {
- private final float min, max;
-
- /**
- * Constructs a double field controller
- *
- * @param option option to bind controller to
- * @param min minimum allowed value (clamped on apply)
- * @param max maximum allowed value (clamped on apply)
- * @param formatter display text, not used whilst editing
- */
- public FloatFieldController(Option<Float> option, float min, float max, Function<Float, Component> formatter) {
- super(option, formatter);
- this.min = min;
- this.max = max;
- }
-
- /**
- * Constructs a double field controller.
- * Uses {@link FloatSliderController#DEFAULT_FORMATTER} as display text,
- * not used whilst editing.
- *
- * @param option option to bind controller to
- * @param min minimum allowed value (clamped on apply)
- * @param max maximum allowed value (clamped on apply)
- */
- public FloatFieldController(Option<Float> option, float min, float max) {
- this(option, min, max, FloatSliderController.DEFAULT_FORMATTER);
- }
-
- /**
- * Constructs a double field controller.
- * Does not have a minimum or a maximum range.
- *
- * @param option option to bind controller to
- * @param formatter display text, not used whilst editing
- */
- public FloatFieldController(Option<Float> option, Function<Float, Component> formatter) {
- this(option, -Float.MAX_VALUE, Float.MAX_VALUE, formatter);
- }
-
- /**
- * Constructs a double field controller.
- * Uses {@link FloatSliderController#DEFAULT_FORMATTER} as display text,
- * not used whilst editing.
- * Does not have a minimum or a maximum range.
- *
- * @param option option to bind controller to
- */
- public FloatFieldController(Option<Float> option) {
- this(option, -Float.MAX_VALUE, Float.MAX_VALUE, FloatSliderController.DEFAULT_FORMATTER);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public double min() {
- return this.min;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public double max() {
- return this.max;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public String getString() {
- return String.valueOf(option().pendingValue());
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void setPendingValue(double value) {
- option().requestSet((float) value);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public double pendingValue() {
- return option().pendingValue();
- }
-}
diff --git a/src/client/java/dev/isxander/yacl/gui/controllers/string/number/IntegerFieldController.java b/src/client/java/dev/isxander/yacl/gui/controllers/string/number/IntegerFieldController.java
deleted file mode 100644
index 2d64a3a..0000000
--- a/src/client/java/dev/isxander/yacl/gui/controllers/string/number/IntegerFieldController.java
+++ /dev/null
@@ -1,109 +0,0 @@
-package dev.isxander.yacl.gui.controllers.string.number;
-
-import dev.isxander.yacl.api.Option;
-import dev.isxander.yacl.gui.controllers.slider.IntegerSliderController;
-import net.minecraft.network.chat.Component;
-
-import java.util.function.Function;
-
-/**
- * {@inheritDoc}
- */
-public class IntegerFieldController extends NumberFieldController<Integer> {
- private final int min, max;
-
- /**
- * Constructs a double field controller
- *
- * @param option option to bind controller to
- * @param min minimum allowed value (clamped on apply)
- * @param max maximum allowed value (clamped on apply)
- * @param formatter display text, not used whilst editing
- */
- public IntegerFieldController(Option<Integer> option, int min, int max, Function<Integer, Component> formatter) {
- super(option, formatter);
- this.min = min;
- this.max = max;
- }
-
- /**
- * Constructs a double field controller.
- * Uses {@link IntegerSliderController#DEFAULT_FORMATTER} as display text,
- * not used whilst editing.
- *
- * @param option option to bind controller to
- * @param min minimum allowed value (clamped on apply)
- * @param max maximum allowed value (clamped on apply)
- */
- public IntegerFieldController(Option<Integer> option, int min, int max) {
- this(option, min, max, IntegerSliderController.DEFAULT_FORMATTER);
- }
-
- /**
- * Constructs a double field controller.
- * Does not have a minimum or a maximum range.
- *
- * @param option option to bind controller to
- * @param formatter display text, not used whilst editing
- */
- public IntegerFieldController(Option<Integer> option, Function<Integer, Component> formatter) {
- this(option, -Integer.MAX_VALUE, Integer.MAX_VALUE, formatter);
- }
-
- /**
- * Constructs a double field controller.
- * Uses {@link IntegerSliderController#DEFAULT_FORMATTER} as display text,
- * not used whilst editing.
- * Does not have a minimum or a maximum range.
- *
- * @param option option to bind controller to
- */
- public IntegerFieldController(Option<Integer> option) {
- this(option, -Integer.MAX_VALUE, Integer.MAX_VALUE, IntegerSliderController.DEFAULT_FORMATTER);
- }
-
- @Override
- public boolean isInputValid(String input) {
- return input.matches("\\d+|-|");
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public double min() {
- return this.min;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public double max() {
- return this.max;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public String getString() {
- return String.valueOf(option().pendingValue());
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void setPendingValue(double value) {
- option().requestSet((int) value);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public double pendingValue() {
- return option().pendingValue();
- }
-}
diff --git a/src/client/java/dev/isxander/yacl/gui/controllers/string/number/LongFieldController.java b/src/client/java/dev/isxander/yacl/gui/controllers/string/number/LongFieldController.java
deleted file mode 100644
index a640621..0000000
--- a/src/client/java/dev/isxander/yacl/gui/controllers/string/number/LongFieldController.java
+++ /dev/null
@@ -1,109 +0,0 @@
-package dev.isxander.yacl.gui.controllers.string.number;
-
-import dev.isxander.yacl.api.Option;
-import dev.isxander.yacl.gui.controllers.slider.LongSliderController;
-import net.minecraft.network.chat.Component;
-
-import java.util.function.Function;
-
-/**
- * {@inheritDoc}
- */
-public class LongFieldController extends NumberFieldController<Long> {
- private final long min, max;
-
- /**
- * Constructs a double field controller
- *
- * @param option option to bind controller to
- * @param min minimum allowed value (clamped on apply)
- * @param max maximum allowed value (clamped on apply)
- * @param formatter display text, not used whilst editing
- */
- public LongFieldController(Option<Long> option, long min, long max, Function<Long, Component> formatter) {
- super(option, formatter);
- this.min = min;
- this.max = max;
- }
-
- /**
- * Constructs a double field controller.
- * Uses {@link LongSliderController#DEFAULT_FORMATTER} as display text,
- * not used whilst editing.
- *
- * @param option option to bind controller to
- * @param min minimum allowed value (clamped on apply)
- * @param max maximum allowed value (clamped on apply)
- */
- public LongFieldController(Option<Long> option, long min, long max) {
- this(option, min, max, LongSliderController.DEFAULT_FORMATTER);
- }
-
- /**
- * Constructs a double field controller.
- * Does not have a minimum or a maximum range.
- *
- * @param option option to bind controller to
- * @param formatter display text, not used whilst editing
- */
- public LongFieldController(Option<Long> option, Function<Long, Component> formatter) {
- this(option, -Long.MAX_VALUE, Long.MAX_VALUE, formatter);
- }
-
- /**
- * Constructs a double field controller.
- * Uses {@link LongSliderController#DEFAULT_FORMATTER} as display text,
- * not used whilst editing.
- * Does not have a minimum or a maximum range.
- *
- * @param option option to bind controller to
- */
- public LongFieldController(Option<Long> option) {
- this(option, -Long.MAX_VALUE, Long.MAX_VALUE, LongSliderController.DEFAULT_FORMATTER);
- }
-
- @Override
- public boolean isInputValid(String input) {
- return input.matches("\\d+|-|");
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public double min() {
- return this.min;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public double max() {
- return this.max;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public String getString() {
- return String.valueOf(option().pendingValue());
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void setPendingValue(double value) {
- option().requestSet((long) value);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public double pendingValue() {
- return option().pendingValue();
- }
-}
diff --git a/src/client/java/dev/isxander/yacl/gui/controllers/string/number/NumberFieldController.java b/src/client/java/dev/isxander/yacl/gui/controllers/string/number/NumberFieldController.java
deleted file mode 100644
index 4240849..0000000
--- a/src/client/java/dev/isxander/yacl/gui/controllers/string/number/NumberFieldController.java
+++ /dev/null
@@ -1,69 +0,0 @@
-package dev.isxander.yacl.gui.controllers.string.number;
-
-import dev.isxander.yacl.api.Option;
-import dev.isxander.yacl.api.utils.Dimension;
-import dev.isxander.yacl.gui.AbstractWidget;
-import dev.isxander.yacl.gui.YACLScreen;
-import dev.isxander.yacl.gui.controllers.slider.ISliderController;
-import dev.isxander.yacl.gui.controllers.string.IStringController;
-import dev.isxander.yacl.gui.controllers.string.StringControllerElement;
-import net.minecraft.network.chat.Component;
-import net.minecraft.util.Mth;
-
-import java.text.DecimalFormatSymbols;
-import java.util.function.Function;
-
-/**
- * Controller that allows you to enter in numbers using a text field.
- *
- * @param <T> number type
- */
-public abstract class NumberFieldController<T extends Number> implements ISliderController<T>, IStringController<T> {
- private final Option<T> option;
- private final Function<T, Component> displayFormatter;
-
- public NumberFieldController(Option<T> option, Function<T, Component> displayFormatter) {
- this.option = option;
- this.displayFormatter = displayFormatter;
- }
-
- @Override
- public Option<T> option() {
- return this.option;
- }
-
- @Override
- public void setFromString(String value) {
- if (value.isEmpty() || value.equals(".") || value.equals("-")) value = "0";
- setPendingValue(Mth.clamp(Double.parseDouble(cleanupNumberString(value)), min(), max()));
- }
-
- @Override
- public double pendingValue() {
- return option().pendingValue().doubleValue();
- }
-
- @Override
- public boolean isInputValid(String input) {
- return input.matches("[+-]?([0-9]+([.][0-9]*)?|[.][0-9]+)|[.]||-");
- }
-
- @Override
- public Component formatValue() {
- return displayFormatter.apply(option().pendingValue());
- }
-
- @Override
- public AbstractWidget provideWidget(YACLScreen screen, Dimension<Integer> widgetDimension) {
- return new StringControllerElement(this, screen, widgetDimension, false);
- }
-
- protected String cleanupNumberString(String number) {
- return number.replace(String.valueOf(DecimalFormatSymbols.getInstance().getGroupingSeparator()), "");
- }
-
- @Override
- public double interval() {
- return -1;
- }
-}
diff --git a/src/client/java/dev/isxander/yacl/gui/controllers/string/number/package-info.java b/src/client/java/dev/isxander/yacl/gui/controllers/string/number/package-info.java
deleted file mode 100644
index 86b9314..0000000
--- a/src/client/java/dev/isxander/yacl/gui/controllers/string/number/package-info.java
+++ /dev/null
@@ -1,10 +0,0 @@
-/**
- * This package contains implementations of input fields for different number types
- * <ul>
- * <li>For doubles: {@link dev.isxander.yacl.gui.controllers.string.number.DoubleFieldController}</li>
- * <li>For floats: {@link dev.isxander.yacl.gui.controllers.string.number.FloatFieldController}</li>
- * <li>For integers: {@link dev.isxander.yacl.gui.controllers.string.number.IntegerFieldController}</li>
- * <li>For longs: {@link dev.isxander.yacl.gui.controllers.string.number.LongFieldController}</li>
- * </ul>
- */
-package dev.isxander.yacl.gui.controllers.string.number;