aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/me/shedaniel/rei/gui/widget/TextFieldWidget.java
diff options
context:
space:
mode:
authorDaniel She <shekwancheung0528@gmail.com>2019-02-25 21:18:26 +0800
committerGitHub <noreply@github.com>2019-02-25 21:18:26 +0800
commit9e55b44b710f38c63a4bfd17d0b07318d5c68535 (patch)
treea2cc0c519b4327028d7b8f544ba5171fff2d8dc1 /src/main/java/me/shedaniel/rei/gui/widget/TextFieldWidget.java
parentb7e018527db2e9cae2db4226f6af9fc34054c964 (diff)
downloadRoughlyEnoughItems-9e55b44b710f38c63a4bfd17d0b07318d5c68535.tar.gz
RoughlyEnoughItems-9e55b44b710f38c63a4bfd17d0b07318d5c68535.tar.bz2
RoughlyEnoughItems-9e55b44b710f38c63a4bfd17d0b07318d5c68535.zip
REI v2.3.1 (#40)
- API Changes - Updated Config Screen - Added Tipped Arrows Recipes - Updated Mappings - Added IRecipeHelper - Turning things to Optional - Removed Cheats button, now included with the new config button - Buttons for switching gamemodes / time / weather (default: off) [Maybe not in this update] - Clickable Labels - 3+ recipes at the same time - Fixed RecipeBaseWidget bad rendering when too big - Fixed #42 Patched up item deleting & cheating - Choose Page Dialog
Diffstat (limited to 'src/main/java/me/shedaniel/rei/gui/widget/TextFieldWidget.java')
-rw-r--r--src/main/java/me/shedaniel/rei/gui/widget/TextFieldWidget.java127
1 files changed, 59 insertions, 68 deletions
diff --git a/src/main/java/me/shedaniel/rei/gui/widget/TextFieldWidget.java b/src/main/java/me/shedaniel/rei/gui/widget/TextFieldWidget.java
index 1dc8f7567..ac0fb5157 100644
--- a/src/main/java/me/shedaniel/rei/gui/widget/TextFieldWidget.java
+++ b/src/main/java/me/shedaniel/rei/gui/widget/TextFieldWidget.java
@@ -5,7 +5,7 @@ import com.mojang.blaze3d.platform.GlStateManager;
import net.minecraft.SharedConstants;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.font.TextRenderer;
-import net.minecraft.client.gui.Drawable;
+import net.minecraft.client.gui.DrawableHelper;
import net.minecraft.client.gui.Screen;
import net.minecraft.client.render.BufferBuilder;
import net.minecraft.client.render.Tessellator;
@@ -17,67 +17,62 @@ import java.util.ArrayList;
import java.util.List;
import java.util.function.BiFunction;
import java.util.function.Consumer;
+import java.util.function.Function;
import java.util.function.Predicate;
-public class TextFieldWidget extends Drawable implements IWidget {
+public class TextFieldWidget extends DrawableHelper implements HighlightableWidget {
- private final TextRenderer textRenderer;
- private int width;
- private int height;
- private int x;
- private int y;
+ protected final TextRenderer textRenderer;
+ public Function<String, String> stripInvaild;
+ private Rectangle bounds;
private String text;
private int maxLength;
- private int focusedTicks;
+ protected int focusedTicks;
private boolean hasBorder;
private boolean field_2096;
private boolean focused;
- private boolean editable;
+ protected boolean editable;
private boolean field_17037;
- private int field_2103;
- private int cursorMax;
- private int cursorMin;
- private int field_2100;
- private int field_2098;
+ protected int field_2103;
+ protected int cursorMax;
+ protected int cursorMin;
+ protected int editableColor;
+ protected int notEditableColor;
private boolean visible;
private String suggestion;
private Consumer<String> changedListener;
private Predicate<String> textPredicate;
- private BiFunction<String, Integer, String> field_2099;
+ protected BiFunction<String, Integer, String> renderTextProvider;
public TextFieldWidget(Rectangle rectangle) {
- this(rectangle.x, rectangle.y, rectangle.width, rectangle.height);
- }
-
- public TextFieldWidget(int x, int y, int width, int height) {
this.text = "";
this.maxLength = 32;
this.hasBorder = true;
this.field_2096 = true;
this.editable = true;
- this.field_2100 = 14737632;
- this.field_2098 = 7368816;
+ this.editableColor = 14737632;
+ this.notEditableColor = 7368816;
this.visible = true;
this.textPredicate = Predicates.alwaysTrue();
- this.field_2099 = (string_1, integer_1) -> {
+ this.renderTextProvider = (string_1, integer_1) -> {
return string_1;
};
this.textRenderer = MinecraftClient.getInstance().textRenderer;
- this.x = x;
- this.y = y;
- this.width = width;
- this.height = height;
+ this.bounds = rectangle;
+ this.stripInvaild = s -> SharedConstants.stripInvalidChars(s);
}
- public Rectangle getBounds() {
- return new Rectangle(x, y, width, height);
+ public TextFieldWidget(int x, int y, int width, int height) {
+ this(new Rectangle(x, y, width, height));
}
- public void setBounds(Rectangle rectangle) {
- this.x = rectangle.x;
- this.y = rectangle.y;
- this.width = rectangle.width;
- this.height = rectangle.height;
+ public String getSuggestion() {
+ return suggestion;
+ }
+
+ @Override
+ public Rectangle getBounds() {
+ return bounds;
}
public void setChangedListener(Consumer<String> biConsumer_1) {
@@ -85,7 +80,7 @@ public class TextFieldWidget extends Drawable implements IWidget {
}
public void method_1854(BiFunction<String, Integer, String> biFunction_1) {
- this.field_2099 = biFunction_1;
+ this.renderTextProvider = biFunction_1;
}
public void tick() {
@@ -121,7 +116,7 @@ public class TextFieldWidget extends Drawable implements IWidget {
public void addText(String string_1) {
String string_2 = "";
- String string_3 = SharedConstants.stripInvalidChars(string_1);
+ String string_3 = stripInvaild.apply(string_1);
int int_1 = this.cursorMax < this.cursorMin ? this.cursorMax : this.cursorMin;
int int_2 = this.cursorMax < this.cursorMin ? this.cursorMin : this.cursorMax;
int int_3 = this.maxLength - this.text.length() - (int_1 - int_2);
@@ -362,18 +357,18 @@ public class TextFieldWidget extends Drawable implements IWidget {
if (!this.isVisible()) {
return false;
} else {
- boolean boolean_1 = double_1 >= (double) this.x && double_1 < (double) (this.x + this.width) && double_2 >= (double) this.y && double_2 < (double) (this.y + this.height);
+ boolean boolean_1 = double_1 >= (double) this.bounds.x && double_1 < (double) (this.bounds.x + this.bounds.width) && double_2 >= (double) this.bounds.y && double_2 < (double) (this.bounds.y + this.bounds.height);
if (this.field_2096) {
this.setFocused(boolean_1);
}
if (this.focused && boolean_1 && int_1 == 0) {
- int int_2 = MathHelper.floor(double_1) - this.x;
+ int int_2 = MathHelper.floor(double_1) - this.bounds.x;
if (this.hasBorder) {
int_2 -= 4;
}
- String string_1 = this.textRenderer.trimToWidth(this.text.substring(this.field_2103), this.method_1859());
+ String string_1 = this.textRenderer.trimToWidth(this.text.substring(this.field_2103), this.getWidth());
this.method_1883(this.textRenderer.trimToWidth(string_1, int_2).length() + this.field_2103);
return true;
} else {
@@ -385,18 +380,18 @@ public class TextFieldWidget extends Drawable implements IWidget {
public void draw(int int_1, int int_2, float float_1) {
if (this.isVisible()) {
if (this.hasBorder()) {
- drawRect(this.x - 1, this.y - 1, this.x + this.width + 1, this.y + this.height + 1, -6250336);
- drawRect(this.x, this.y, this.x + this.width, this.y + this.height, -16777216);
+ drawRect(this.bounds.x - 1, this.bounds.y - 1, this.bounds.x + this.bounds.width + 1, this.bounds.y + this.bounds.height + 1, -6250336);
+ drawRect(this.bounds.x, this.bounds.y, this.bounds.x + this.bounds.width, this.bounds.y + this.bounds.height, -16777216);
}
- int int_3 = this.editable ? this.field_2100 : this.field_2098;
+ int color = this.editable ? this.editableColor : this.notEditableColor;
int int_4 = this.cursorMax - this.field_2103;
int int_5 = this.cursorMin - this.field_2103;
- String string_1 = this.textRenderer.trimToWidth(this.text.substring(this.field_2103), this.method_1859());
+ String string_1 = this.textRenderer.trimToWidth(this.text.substring(this.field_2103), this.getWidth());
boolean boolean_1 = int_4 >= 0 && int_4 <= string_1.length();
boolean boolean_2 = this.focused && this.focusedTicks / 6 % 2 == 0 && boolean_1;
- int int_6 = this.hasBorder ? this.x + 4 : this.x;
- int int_7 = this.hasBorder ? this.y + (this.height - 8) / 2 : this.y;
+ int int_6 = this.hasBorder ? this.bounds.x + 4 : this.bounds.x;
+ int int_7 = this.hasBorder ? this.bounds.y + (this.bounds.height - 8) / 2 : this.bounds.y;
int int_8 = int_6;
if (int_5 > string_1.length()) {
int_5 = string_1.length();
@@ -404,24 +399,24 @@ public class TextFieldWidget extends Drawable implements IWidget {
if (!string_1.isEmpty()) {
String string_2 = boolean_1 ? string_1.substring(0, int_4) : string_1;
- int_8 = this.textRenderer.drawWithShadow((String) this.field_2099.apply(string_2, this.field_2103), (float) int_6, (float) int_7, int_3);
+ int_8 = this.textRenderer.drawWithShadow((String) this.renderTextProvider.apply(string_2, this.field_2103), (float) int_6, (float) int_7, color);
}
boolean boolean_3 = this.cursorMax < this.text.length() || this.text.length() >= this.getMaxLength();
int int_9 = int_8;
if (!boolean_1) {
- int_9 = int_4 > 0 ? int_6 + this.width : int_6;
+ int_9 = int_4 > 0 ? int_6 + this.bounds.width : int_6;
} else if (boolean_3) {
int_9 = int_8 - 1;
--int_8;
}
if (!string_1.isEmpty() && boolean_1 && int_4 < string_1.length()) {
- this.textRenderer.drawWithShadow((String) this.field_2099.apply(string_1.substring(int_4), this.cursorMax), (float) int_8, (float) int_7, int_3);
+ this.textRenderer.drawWithShadow((String) this.renderTextProvider.apply(string_1.substring(int_4), this.cursorMax), (float) int_8, (float) int_7, color);
}
- if (!boolean_3 && this.suggestion != null) {
- this.textRenderer.drawWithShadow(this.suggestion, (float) (int_9 - 1), (float) int_7, -8355712);
+ if (!boolean_3 && text.isEmpty() && this.suggestion != null) {
+ this.textRenderer.drawWithShadow(this.textRenderer.trimToWidth(this.suggestion, this.getWidth()), (float) int_6, (float) int_7, -8355712);
}
int var10002;
@@ -432,9 +427,9 @@ public class TextFieldWidget extends Drawable implements IWidget {
var10002 = int_9 + 1;
var10003 = int_7 + 1;
this.textRenderer.getClass();
- Drawable.drawRect(int_9, var10001, var10002, var10003 + 9, -3092272);
+ DrawableHelper.drawRect(int_9, var10001, var10002, var10003 + 9, -3092272);
} else {
- this.textRenderer.drawWithShadow("_", (float) int_9, (float) int_7, int_3);
+ this.textRenderer.drawWithShadow("_", (float) int_9, (float) int_7, color);
}
}
@@ -450,7 +445,7 @@ public class TextFieldWidget extends Drawable implements IWidget {
}
}
- private void method_1886(int int_1, int int_2, int int_3, int int_4) {
+ protected void method_1886(int int_1, int int_2, int int_3, int int_4) {
int int_6;
if (int_1 < int_3) {
int_6 = int_1;
@@ -464,12 +459,12 @@ public class TextFieldWidget extends Drawable implements IWidget {
int_4 = int_6;
}
- if (int_3 > this.x + this.width) {
- int_3 = this.x + this.width;
+ if (int_3 > this.bounds.x + this.bounds.width) {
+ int_3 = this.bounds.x + this.bounds.width;
}
- if (int_1 > this.x + this.width) {
- int_1 = this.x + this.width;
+ if (int_1 > this.bounds.x + this.bounds.width) {
+ int_1 = this.bounds.x + this.bounds.width;
}
Tessellator tessellator_1 = Tessellator.getInstance();
@@ -516,12 +511,12 @@ public class TextFieldWidget extends Drawable implements IWidget {
this.hasBorder = boolean_1;
}
- public void method_1868(int int_1) {
- this.field_2100 = int_1;
+ public void setEditableColor(int int_1) {
+ this.editableColor = int_1;
}
- public void method_1860(int int_1) {
- this.field_2098 = int_1;
+ public void setNotEditableColor(int int_1) {
+ this.notEditableColor = int_1;
}
public void setHasFocus(boolean boolean_1) {
@@ -548,8 +543,8 @@ public class TextFieldWidget extends Drawable implements IWidget {
this.editable = boolean_1;
}
- public int method_1859() {
- return this.hasBorder() ? this.width - 8 : this.width;
+ public int getWidth() {
+ return this.hasBorder() ? this.bounds.width - 8 : this.bounds.width;
}
public void method_1884(int int_1) {
@@ -560,7 +555,7 @@ public class TextFieldWidget extends Drawable implements IWidget {
this.field_2103 = int_2;
}
- int int_3 = this.method_1859();
+ int int_3 = this.getWidth();
String string_1 = this.textRenderer.trimToWidth(this.text.substring(this.field_2103), int_3);
int int_4 = string_1.length() + this.field_2103;
if (this.cursorMin == this.field_2103) {
@@ -595,11 +590,7 @@ public class TextFieldWidget extends Drawable implements IWidget {
}
public int method_1889(int int_1) {
- return int_1 > this.text.length() ? this.x : this.x + this.textRenderer.getStringWidth(this.text.substring(0, int_1));
- }
-
- public void setX(int int_1) {
- this.x = int_1;
+ return int_1 > this.text.length() ? this.bounds.x : this.bounds.x + this.textRenderer.getStringWidth(this.text.substring(0, int_1));
}
}