|
@@ -1,21 +1,17 @@
|
|
|
package me.shedaniel.clothconfig2.gui.entries;
|
|
|
|
|
|
-import net.minecraft.client.MinecraftClient;
|
|
|
-import net.minecraft.client.gui.Element;
|
|
|
-import net.minecraft.client.gui.widget.TextFieldWidget;
|
|
|
import net.minecraft.client.resource.language.I18n;
|
|
|
import org.jetbrains.annotations.ApiStatus;
|
|
|
+import org.jetbrains.annotations.NotNull;
|
|
|
+import org.jetbrains.annotations.Nullable;
|
|
|
|
|
|
-import java.util.Collections;
|
|
|
import java.util.List;
|
|
|
-import java.util.Objects;
|
|
|
import java.util.Optional;
|
|
|
import java.util.function.Consumer;
|
|
|
import java.util.function.Supplier;
|
|
|
-import java.util.stream.Collectors;
|
|
|
|
|
|
@ApiStatus.Internal
|
|
|
-public class DoubleListListEntry extends AbstractListListEntry<Double, DoubleListListEntry.DoubleListCell, DoubleListListEntry> {
|
|
|
+public class DoubleListListEntry extends AbstractTextFieldListListEntry<Double, DoubleListListEntry.DoubleListCell, DoubleListListEntry> {
|
|
|
|
|
|
private double minimum, maximum;
|
|
|
|
|
@@ -46,11 +42,6 @@ public class DoubleListListEntry extends AbstractListListEntry<Double, DoubleLis
|
|
|
this.maximum = Double.POSITIVE_INFINITY;
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public List<Double> getValue() {
|
|
|
- return cells.stream().map(DoubleListCell::getValue).collect(Collectors.toList());
|
|
|
- }
|
|
|
-
|
|
|
public DoubleListListEntry setMaximum(Double maximum) {
|
|
|
this.maximum = maximum;
|
|
|
return this;
|
|
@@ -66,34 +57,24 @@ public class DoubleListListEntry extends AbstractListListEntry<Double, DoubleLis
|
|
|
return this;
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- protected DoubleListCell getFromValue(Double value) {
|
|
|
- return new DoubleListCell(value, this);
|
|
|
- }
|
|
|
-
|
|
|
- public static class DoubleListCell extends AbstractListListEntry.AbstractListCell<Double, DoubleListCell, DoubleListListEntry> {
|
|
|
-
|
|
|
- private TextFieldWidget widget;
|
|
|
+ public static class DoubleListCell extends AbstractTextFieldListListEntry.AbstractTextFieldListCell<Double, DoubleListCell, DoubleListListEntry> {
|
|
|
|
|
|
public DoubleListCell(Double value, final DoubleListListEntry listListEntry) {
|
|
|
super(value, listListEntry);
|
|
|
+ }
|
|
|
|
|
|
+ @Nullable
|
|
|
+ @Override
|
|
|
+ protected Double substituteDefault(@Nullable Double value) {
|
|
|
if (value == null)
|
|
|
- value = 0d;
|
|
|
- Double finalValue = value;
|
|
|
-
|
|
|
- this.setErrorSupplier(() -> Optional.ofNullable(listListEntry.cellErrorSupplier).flatMap(fn -> fn.apply(this.getValue())));
|
|
|
- widget = new TextFieldWidget(MinecraftClient.getInstance().textRenderer, 0, 0, 100, 18, "");
|
|
|
- widget.setTextPredicate(s -> s.chars().allMatch(c -> Character.isDigit(c) || c == '-' || c == '.'));
|
|
|
- widget.setMaxLength(Integer.MAX_VALUE);
|
|
|
- widget.setHasBorder(false);
|
|
|
- widget.setText(value.toString());
|
|
|
- widget.setChangedListener(s -> {
|
|
|
- widget.setEditableColor(getPreferredTextColor());
|
|
|
- if (!Objects.equals(s, finalValue.toString())) {
|
|
|
- this.listListEntry.getScreen().setEdited(true, this.listListEntry.isRequiresRestart());
|
|
|
- }
|
|
|
- });
|
|
|
+ return 0d;
|
|
|
+ else
|
|
|
+ return value;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected boolean isValidText(@NotNull String text) {
|
|
|
+ return text.chars().allMatch(c -> Character.isDigit(c) || c == '-' || c == '.');
|
|
|
}
|
|
|
|
|
|
public Double getValue() {
|
|
@@ -118,27 +99,6 @@ public class DoubleListListEntry extends AbstractListListEntry<Double, DoubleLis
|
|
|
return Optional.empty();
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public int getCellHeight() {
|
|
|
- return 20;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void render(int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean isSelected, float delta) {
|
|
|
- widget.setWidth(entryWidth - 12);
|
|
|
- widget.x = x;
|
|
|
- widget.y = y + 1;
|
|
|
- widget.setEditable(listListEntry.isEditable());
|
|
|
- widget.render(mouseX, mouseY, delta);
|
|
|
- if (isSelected && listListEntry.isEditable())
|
|
|
- fill(x, y + 12, x + entryWidth - 12, y + 13, getConfigError().isPresent() ? 0xffff5555 : 0xffe0e0e0);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public List<? extends Element> children() {
|
|
|
- return Collections.singletonList(widget);
|
|
|
- }
|
|
|
-
|
|
|
}
|
|
|
|
|
|
}
|