aboutsummaryrefslogtreecommitdiff
path: root/src/client/java/dev/isxander/yacl/gui/controllers/slider
diff options
context:
space:
mode:
authorisXander <xandersmith2008@gmail.com>2023-01-19 21:15:26 +0000
committerisXander <xandersmith2008@gmail.com>2023-01-19 21:15:26 +0000
commitee53b51a1e8d88085c75f227f4710b68c03b19c8 (patch)
tree77a942242a982757da040a6120950bad30e49f77 /src/client/java/dev/isxander/yacl/gui/controllers/slider
parentffdd6e5ceacd71c76c55a8716702d4d6da17c7ab (diff)
downloadYetAnotherConfigLib-ee53b51a1e8d88085c75f227f4710b68c03b19c8.tar.gz
YetAnotherConfigLib-ee53b51a1e8d88085c75f227f4710b68c03b19c8.tar.bz2
YetAnotherConfigLib-ee53b51a1e8d88085c75f227f4710b68c03b19c8.zip
mojmap
Diffstat (limited to 'src/client/java/dev/isxander/yacl/gui/controllers/slider')
-rw-r--r--src/client/java/dev/isxander/yacl/gui/controllers/slider/DoubleSliderController.java12
-rw-r--r--src/client/java/dev/isxander/yacl/gui/controllers/slider/FloatSliderController.java12
-rw-r--r--src/client/java/dev/isxander/yacl/gui/controllers/slider/IntegerSliderController.java12
-rw-r--r--src/client/java/dev/isxander/yacl/gui/controllers/slider/LongSliderController.java12
-rw-r--r--src/client/java/dev/isxander/yacl/gui/controllers/slider/SliderControllerElement.java40
5 files changed, 44 insertions, 44 deletions
diff --git a/src/client/java/dev/isxander/yacl/gui/controllers/slider/DoubleSliderController.java b/src/client/java/dev/isxander/yacl/gui/controllers/slider/DoubleSliderController.java
index 54c7476..8e044b1 100644
--- a/src/client/java/dev/isxander/yacl/gui/controllers/slider/DoubleSliderController.java
+++ b/src/client/java/dev/isxander/yacl/gui/controllers/slider/DoubleSliderController.java
@@ -1,7 +1,7 @@
package dev.isxander.yacl.gui.controllers.slider;
import dev.isxander.yacl.api.Option;
-import net.minecraft.text.Text;
+import net.minecraft.network.chat.Component;
import org.apache.commons.lang3.Validate;
import java.util.function.Function;
@@ -13,13 +13,13 @@ public class DoubleSliderController implements ISliderController<Double> {
/**
* Formats doubles to two decimal places
*/
- public static final Function<Double, Text> DEFAULT_FORMATTER = value -> Text.of(String.format("%,.2f", value).replaceAll("[\u00a0\u202F]", " "));
+ public static final Function<Double, Component> DEFAULT_FORMATTER = value -> Component.literal(String.format("%,.2f", value).replaceAll("[\u00a0\u202F]", " "));
private final Option<Double> option;
private final double min, max, interval;
- private final Function<Double, Text> valueFormatter;
+ private final Function<Double, Component> valueFormatter;
/**
* Constructs a {@link ISliderController} for doubles
@@ -41,9 +41,9 @@ public class DoubleSliderController implements ISliderController<Double> {
* @param min minimum slider value
* @param max maximum slider value
* @param interval step size (or increments) for the slider
- * @param valueFormatter format the value into any {@link Text}
+ * @param valueFormatter format the value into any {@link Component}
*/
- public DoubleSliderController(Option<Double> option, double min, double max, double interval, Function<Double, Text> valueFormatter) {
+ public DoubleSliderController(Option<Double> option, double min, double max, double interval, Function<Double, Component> valueFormatter) {
Validate.isTrue(max > min, "`max` cannot be smaller than `min`");
Validate.isTrue(interval > 0, "`interval` must be more than 0");
Validate.notNull(valueFormatter, "`valueFormatter` must not be null");
@@ -67,7 +67,7 @@ public class DoubleSliderController implements ISliderController<Double> {
* {@inheritDoc}
*/
@Override
- public Text formatValue() {
+ public Component formatValue() {
return valueFormatter.apply(option().pendingValue());
}
diff --git a/src/client/java/dev/isxander/yacl/gui/controllers/slider/FloatSliderController.java b/src/client/java/dev/isxander/yacl/gui/controllers/slider/FloatSliderController.java
index 84ca9a2..25f2206 100644
--- a/src/client/java/dev/isxander/yacl/gui/controllers/slider/FloatSliderController.java
+++ b/src/client/java/dev/isxander/yacl/gui/controllers/slider/FloatSliderController.java
@@ -1,7 +1,7 @@
package dev.isxander.yacl.gui.controllers.slider;
import dev.isxander.yacl.api.Option;
-import net.minecraft.text.Text;
+import net.minecraft.network.chat.Component;
import org.apache.commons.lang3.Validate;
import java.util.function.Function;
@@ -13,13 +13,13 @@ public class FloatSliderController implements ISliderController<Float> {
/**
* Formats floats to one decimal place
*/
- public static final Function<Float, Text> DEFAULT_FORMATTER = value -> Text.of(String.format("%,.1f", value).replaceAll("[\u00a0\u202F]", " "));
+ public static final Function<Float, Component> DEFAULT_FORMATTER = value -> Component.literal(String.format("%,.1f", value).replaceAll("[\u00a0\u202F]", " "));
private final Option<Float> option;
private final float min, max, interval;
- private final Function<Float, Text> valueFormatter;
+ private final Function<Float, Component> valueFormatter;
/**
* Constructs a {@link ISliderController} for floats
@@ -41,9 +41,9 @@ public class FloatSliderController implements ISliderController<Float> {
* @param min minimum slider value
* @param max maximum slider value
* @param interval step size (or increments) for the slider
- * @param valueFormatter format the value into any {@link Text}
+ * @param valueFormatter format the value into any {@link Component}
*/
- public FloatSliderController(Option<Float> option, float min, float max, float interval, Function<Float, Text> valueFormatter) {
+ public FloatSliderController(Option<Float> option, float min, float max, float interval, Function<Float, Component> valueFormatter) {
Validate.isTrue(max > min, "`max` cannot be smaller than `min`");
Validate.isTrue(interval > 0, "`interval` must be more than 0");
Validate.notNull(valueFormatter, "`valueFormatter` must not be null");
@@ -67,7 +67,7 @@ public class FloatSliderController implements ISliderController<Float> {
* {@inheritDoc}
*/
@Override
- public Text formatValue() {
+ public Component formatValue() {
return valueFormatter.apply(option().pendingValue());
}
diff --git a/src/client/java/dev/isxander/yacl/gui/controllers/slider/IntegerSliderController.java b/src/client/java/dev/isxander/yacl/gui/controllers/slider/IntegerSliderController.java
index 50ec9d2..4a68497 100644
--- a/src/client/java/dev/isxander/yacl/gui/controllers/slider/IntegerSliderController.java
+++ b/src/client/java/dev/isxander/yacl/gui/controllers/slider/IntegerSliderController.java
@@ -1,7 +1,7 @@
package dev.isxander.yacl.gui.controllers.slider;
import dev.isxander.yacl.api.Option;
-import net.minecraft.text.Text;
+import net.minecraft.network.chat.Component;
import org.apache.commons.lang3.Validate;
import java.util.function.Function;
@@ -10,13 +10,13 @@ import java.util.function.Function;
* {@link ISliderController} for integers.
*/
public class IntegerSliderController implements ISliderController<Integer> {
- public static final Function<Integer, Text> DEFAULT_FORMATTER = value -> Text.of(String.format("%,d", value).replaceAll("[\u00a0\u202F]", " "));
+ public static final Function<Integer, Component> DEFAULT_FORMATTER = value -> Component.literal(String.format("%,d", value).replaceAll("[\u00a0\u202F]", " "));
private final Option<Integer> option;
private final int min, max, interval;
- private final Function<Integer, Text> valueFormatter;
+ private final Function<Integer, Component> valueFormatter;
/**
* Constructs a {@link ISliderController} for integers
@@ -38,9 +38,9 @@ public class IntegerSliderController implements ISliderController<Integer> {
* @param min minimum slider value
* @param max maximum slider value
* @param interval step size (or increments) for the slider
- * @param valueFormatter format the value into any {@link Text}
+ * @param valueFormatter format the value into any {@link Component}
*/
- public IntegerSliderController(Option<Integer> option, int min, int max, int interval, Function<Integer, Text> valueFormatter) {
+ public IntegerSliderController(Option<Integer> option, int min, int max, int interval, Function<Integer, Component> valueFormatter) {
Validate.isTrue(max > min, "`max` cannot be smaller than `min`");
Validate.isTrue(interval > 0, "`interval` must be more than 0");
Validate.notNull(valueFormatter, "`valueFormatter` must not be null");
@@ -64,7 +64,7 @@ public class IntegerSliderController implements ISliderController<Integer> {
* {@inheritDoc}
*/
@Override
- public Text formatValue() {
+ public Component formatValue() {
return valueFormatter.apply(option().pendingValue());
}
diff --git a/src/client/java/dev/isxander/yacl/gui/controllers/slider/LongSliderController.java b/src/client/java/dev/isxander/yacl/gui/controllers/slider/LongSliderController.java
index 3038402..681e7cf 100644
--- a/src/client/java/dev/isxander/yacl/gui/controllers/slider/LongSliderController.java
+++ b/src/client/java/dev/isxander/yacl/gui/controllers/slider/LongSliderController.java
@@ -1,7 +1,7 @@
package dev.isxander.yacl.gui.controllers.slider;
import dev.isxander.yacl.api.Option;
-import net.minecraft.text.Text;
+import net.minecraft.network.chat.Component;
import org.apache.commons.lang3.Validate;
import java.util.function.Function;
@@ -10,13 +10,13 @@ import java.util.function.Function;
* {@link ISliderController} for longs.
*/
public class LongSliderController implements ISliderController<Long> {
- public static final Function<Long, Text> DEFAULT_FORMATTER = value -> Text.of(String.format("%,d", value).replaceAll("[\u00a0\u202F]", " "));
+ public static final Function<Long, Component> DEFAULT_FORMATTER = value -> Component.literal(String.format("%,d", value).replaceAll("[\u00a0\u202F]", " "));
private final Option<Long> option;
private final long min, max, interval;
- private final Function<Long, Text> valueFormatter;
+ private final Function<Long, Component> valueFormatter;
/**
* Constructs a {@link ISliderController} for longs
@@ -38,9 +38,9 @@ public class LongSliderController implements ISliderController<Long> {
* @param min minimum slider value
* @param max maximum slider value
* @param interval step size (or increments) for the slider
- * @param valueFormatter format the value into any {@link Text}
+ * @param valueFormatter format the value into any {@link Component}
*/
- public LongSliderController(Option<Long> option, long min, long max, long interval, Function<Long, Text> valueFormatter) {
+ public LongSliderController(Option<Long> option, long min, long max, long interval, Function<Long, Component> valueFormatter) {
Validate.isTrue(max > min, "`max` cannot be smaller than `min`");
Validate.isTrue(interval > 0, "`interval` must be more than 0");
Validate.notNull(valueFormatter, "`valueFormatter` must not be null");
@@ -64,7 +64,7 @@ public class LongSliderController implements ISliderController<Long> {
* {@inheritDoc}
*/
@Override
- public Text formatValue() {
+ public Component formatValue() {
return valueFormatter.apply(option().pendingValue());
}
diff --git a/src/client/java/dev/isxander/yacl/gui/controllers/slider/SliderControllerElement.java b/src/client/java/dev/isxander/yacl/gui/controllers/slider/SliderControllerElement.java
index ea4e262..ddfdd4d 100644
--- a/src/client/java/dev/isxander/yacl/gui/controllers/slider/SliderControllerElement.java
+++ b/src/client/java/dev/isxander/yacl/gui/controllers/slider/SliderControllerElement.java
@@ -1,13 +1,13 @@
package dev.isxander.yacl.gui.controllers.slider;
+import com.mojang.blaze3d.platform.InputConstants;
+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 net.minecraft.client.gui.DrawableHelper;
-import net.minecraft.client.gui.screen.Screen;
-import net.minecraft.client.util.InputUtil;
-import net.minecraft.client.util.math.MatrixStack;
-import net.minecraft.util.math.MathHelper;
+import net.minecraft.client.gui.GuiComponent;
+import net.minecraft.client.gui.screens.Screen;
+import net.minecraft.util.Mth;
public class SliderControllerElement extends ControllerWidget<ISliderController<?>> {
private final double min, max, interval;
@@ -27,32 +27,32 @@ public class SliderControllerElement extends ControllerWidget<ISliderController<
}
@Override
- public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) {
+ public void render(PoseStack matrices, int mouseX, int mouseY, float delta) {
super.render(matrices, mouseX, mouseY, delta);
calculateInterpolation();
}
@Override
- protected void drawHoveredControl(MatrixStack matrices, int mouseX, int mouseY, float delta) {
+ protected void drawHoveredControl(PoseStack matrices, int mouseX, int mouseY, float delta) {
// track
- DrawableHelper.fill(matrices, sliderBounds.x(), sliderBounds.centerY() - 1, sliderBounds.xLimit(), sliderBounds.centerY(), -1);
+ GuiComponent.fill(matrices, sliderBounds.x(), sliderBounds.centerY() - 1, sliderBounds.xLimit(), sliderBounds.centerY(), -1);
// track shadow
- DrawableHelper.fill(matrices, sliderBounds.x() + 1, sliderBounds.centerY(), sliderBounds.xLimit() + 1, sliderBounds.centerY() + 1, 0xFF404040);
+ GuiComponent.fill(matrices, sliderBounds.x() + 1, sliderBounds.centerY(), sliderBounds.xLimit() + 1, sliderBounds.centerY() + 1, 0xFF404040);
// thumb shadow
- DrawableHelper.fill(matrices, getThumbX() - getThumbWidth() / 2 + 1, sliderBounds.y() + 1, getThumbX() + getThumbWidth() / 2 + 1, sliderBounds.yLimit() + 1, 0xFF404040);
+ GuiComponent.fill(matrices, getThumbX() - getThumbWidth() / 2 + 1, sliderBounds.y() + 1, getThumbX() + getThumbWidth() / 2 + 1, sliderBounds.yLimit() + 1, 0xFF404040);
// thumb
- DrawableHelper.fill(matrices, getThumbX() - getThumbWidth() / 2, sliderBounds.y(), getThumbX() + getThumbWidth() / 2, sliderBounds.yLimit(), -1);
+ GuiComponent.fill(matrices, getThumbX() - getThumbWidth() / 2, sliderBounds.y(), getThumbX() + getThumbWidth() / 2, sliderBounds.yLimit(), -1);
}
@Override
- protected void drawValueText(MatrixStack matrices, int mouseX, int mouseY, float delta) {
- matrices.push();
+ protected void drawValueText(PoseStack matrices, int mouseX, int mouseY, float delta) {
+ matrices.pushPose();
if (isHovered())
matrices.translate(-(sliderBounds.width() + 6 + getThumbWidth() / 2f), 0, 0);
super.drawValueText(matrices, mouseX, mouseY, delta);
- matrices.pop();
+ matrices.popPose();
}
@Override
@@ -76,7 +76,7 @@ public class SliderControllerElement extends ControllerWidget<ISliderController<
}
public void incrementValue(double amount) {
- control.setPendingValue(MathHelper.clamp(control.pendingValue() + interval * amount, min, max));
+ control.setPendingValue(Mth.clamp(control.pendingValue() + interval * amount, min, max));
calculateInterpolation();
}
@@ -104,8 +104,8 @@ public class SliderControllerElement extends ControllerWidget<ISliderController<
return false;
switch (keyCode) {
- case InputUtil.GLFW_KEY_LEFT, InputUtil.GLFW_KEY_DOWN -> incrementValue(-1);
- case InputUtil.GLFW_KEY_RIGHT, InputUtil.GLFW_KEY_UP -> incrementValue(1);
+ case InputConstants.KEY_LEFT, InputConstants.KEY_DOWN -> incrementValue(-1);
+ case InputConstants.KEY_RIGHT, InputConstants.KEY_UP -> incrementValue(1);
default -> {
return false;
}
@@ -126,7 +126,7 @@ public class SliderControllerElement extends ControllerWidget<ISliderController<
}
protected double roundToInterval(double value) {
- return MathHelper.clamp(min + (interval * Math.round(value / interval)), min, max); // extremely imprecise, requires clamping
+ return Mth.clamp(min + (interval * Math.round(value / interval)), min, max); // extremely imprecise, requires clamping
}
@Override
@@ -135,7 +135,7 @@ public class SliderControllerElement extends ControllerWidget<ISliderController<
}
protected void calculateInterpolation() {
- interpolation = MathHelper.clamp((float) ((control.pendingValue() - control.min()) * 1 / control.range()), 0f, 1f);
+ interpolation = Mth.clamp((float) ((control.pendingValue() - control.min()) * 1 / control.range()), 0f, 1f);
}
@Override
@@ -157,7 +157,7 @@ public class SliderControllerElement extends ControllerWidget<ISliderController<
}
@Override
- public void postRender(MatrixStack matrices, int mouseX, int mouseY, float delta) {
+ public void postRender(PoseStack matrices, int mouseX, int mouseY, float delta) {
if (super.isMouseOver(mouseX, mouseY))
super.postRender(matrices, mouseX, mouseY, delta);
}