diff options
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.java | 188 |
1 files changed, 94 insertions, 94 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 3b54182f6..880a9eb36 100644 --- a/src/main/java/me/shedaniel/rei/gui/widget/TextFieldWidget.java +++ b/src/main/java/me/shedaniel/rei/gui/widget/TextFieldWidget.java @@ -27,7 +27,7 @@ import java.util.function.Function; import java.util.function.Predicate; public class TextFieldWidget extends WidgetWithBounds implements Tickable { - + public Function<String, String> stripInvaild; protected int focusedTicks; protected boolean editable; @@ -48,7 +48,7 @@ public class TextFieldWidget extends WidgetWithBounds implements Tickable { private String suggestion; private Consumer<String> changedListener; private Predicate<String> textPredicate; - + public TextFieldWidget(Rectangle rectangle) { this.text = ""; this.maxLength = 32; @@ -65,41 +65,41 @@ public class TextFieldWidget extends WidgetWithBounds implements Tickable { this.bounds = rectangle; this.stripInvaild = s -> SharedConstants.stripInvalidChars(s); } - + public TextFieldWidget(int x, int y, int width, int height) { this(new Rectangle(x, y, width, height)); } - + public String getSuggestion() { return suggestion; } - + public void setSuggestion(String string_1) { this.suggestion = string_1; } - + @Override public Rectangle getBounds() { return bounds; } - + public void setChangedListener(Consumer<String> biConsumer_1) { this.changedListener = biConsumer_1; } - + public void method_1854(BiFunction<String, Integer, String> biFunction_1) { this.renderTextProvider = biFunction_1; } - + @Override public void tick() { ++this.focusedTicks; } - + public String getText() { return this.text; } - + public void setText(String string_1) { if (this.textPredicate.test(string_1)) { if (string_1.length() > this.maxLength) { @@ -107,22 +107,22 @@ public class TextFieldWidget extends WidgetWithBounds implements Tickable { } else { this.text = string_1; } - + this.onChanged(string_1); this.method_1872(); } } - + public String getSelectedText() { int int_1 = this.cursorMax < this.cursorMin ? this.cursorMax : this.cursorMin; int int_2 = this.cursorMax < this.cursorMin ? this.cursorMin : this.cursorMax; return this.text.substring(int_1, int_2); } - + public void method_1890(Predicate<String> predicate_1) { this.textPredicate = predicate_1; } - + public void addText(String string_1) { String string_2 = ""; String string_3 = stripInvaild.apply(string_1); @@ -132,7 +132,7 @@ public class TextFieldWidget extends WidgetWithBounds implements Tickable { if (!this.text.isEmpty()) { string_2 = string_2 + this.text.substring(0, int_1); } - + int int_5; if (int_3 < string_3.length()) { string_2 = string_2 + string_3.substring(0, int_3); @@ -141,11 +141,11 @@ public class TextFieldWidget extends WidgetWithBounds implements Tickable { string_2 = string_2 + string_3; int_5 = string_3.length(); } - + if (!this.text.isEmpty() && int_2 < this.text.length()) { string_2 = string_2 + this.text.substring(int_2); } - + if (this.textPredicate.test(string_2)) { this.text = string_2; this.setCursor(int_1 + int_5); @@ -153,23 +153,23 @@ public class TextFieldWidget extends WidgetWithBounds implements Tickable { this.onChanged(this.text); } } - + public void onChanged(String string_1) { if (this.changedListener != null) { this.changedListener.accept(string_1); } - + } - + private void method_16873(int int_1) { if (Screen.hasControlDown()) { this.method_1877(int_1); } else { this.method_1878(int_1); } - + } - + public void method_1877(int int_1) { if (!this.text.isEmpty()) { if (this.cursorMin != this.cursorMax) { @@ -179,7 +179,7 @@ public class TextFieldWidget extends WidgetWithBounds implements Tickable { } } } - + public void method_1878(int int_1) { if (!this.text.isEmpty()) { if (this.cursorMin != this.cursorMax) { @@ -192,36 +192,36 @@ public class TextFieldWidget extends WidgetWithBounds implements Tickable { if (int_2 >= 0) { string_1 = this.text.substring(0, int_2); } - + if (int_3 < this.text.length()) { string_1 = string_1 + this.text.substring(int_3); } - + if (this.textPredicate.test(string_1)) { this.text = string_1; if (boolean_1) { this.moveCursor(int_1); } - + this.onChanged(this.text); } } } } - + public int method_1853(int int_1) { return this.method_1869(int_1, this.getCursor()); } - + public int method_1869(int int_1, int int_2) { return this.method_1864(int_1, int_2, true); } - + public int method_1864(int int_1, int int_2, boolean boolean_1) { int int_3 = int_2; boolean boolean_2 = int_1 < 0; int int_4 = Math.abs(int_1); - + for (int int_5 = 0; int_5 < int_4; ++int_5) { if (!boolean_2) { int int_6 = this.text.length(); @@ -237,37 +237,37 @@ public class TextFieldWidget extends WidgetWithBounds implements Tickable { while (boolean_1 && int_3 > 0 && this.text.charAt(int_3 - 1) == ' ') { --int_3; } - + while (int_3 > 0 && this.text.charAt(int_3 - 1) != ' ') { --int_3; } } } - + return int_3; } - + public void moveCursor(int int_1) { this.method_1883(this.cursorMax + int_1); } - + public void method_1883(int int_1) { this.setCursor(int_1); if (!this.field_17037) { this.method_1884(this.cursorMax); } - + this.onChanged(this.text); } - + public void method_1870() { this.method_1883(0); } - + public void method_1872() { this.method_1883(this.text.length()); } - + public boolean keyPressed(int int_1, int int_2, int int_3) { if (this.isVisible() && this.isFocused()) { this.field_17037 = Screen.hasShiftDown(); @@ -282,14 +282,14 @@ public class TextFieldWidget extends WidgetWithBounds implements Tickable { if (this.editable) { this.addText(minecraft.keyboard.getClipboard()); } - + return true; } else if (Screen.isCut(int_1)) { minecraft.keyboard.setClipboard(this.getSelectedText()); if (this.editable) { this.addText(""); } - + return true; } else { switch (int_1) { @@ -297,7 +297,7 @@ public class TextFieldWidget extends WidgetWithBounds implements Tickable { if (this.editable) { this.method_16873(-1); } - + return true; case 260: case 264: @@ -310,7 +310,7 @@ public class TextFieldWidget extends WidgetWithBounds implements Tickable { if (this.editable) { this.method_16873(1); } - + return true; case 262: if (Screen.hasControlDown()) { @@ -318,7 +318,7 @@ public class TextFieldWidget extends WidgetWithBounds implements Tickable { } else { this.moveCursor(1); } - + return true; case 263: if (Screen.hasControlDown()) { @@ -326,7 +326,7 @@ public class TextFieldWidget extends WidgetWithBounds implements Tickable { } else { this.moveCursor(-1); } - + return true; case 268: this.method_1870(); @@ -340,7 +340,7 @@ public class TextFieldWidget extends WidgetWithBounds implements Tickable { return false; } } - + @Override public boolean charTyped(char char_1, int int_1) { if (this.isVisible() && this.isFocused()) { @@ -348,7 +348,7 @@ public class TextFieldWidget extends WidgetWithBounds implements Tickable { if (this.editable) { this.addText(Character.toString(char_1)); } - + return true; } else { return false; @@ -357,12 +357,12 @@ public class TextFieldWidget extends WidgetWithBounds implements Tickable { return false; } } - + @Override public List<Widget> children() { return Collections.emptyList(); } - + public boolean mouseClicked(double double_1, double double_2, int int_1) { if (!this.isVisible()) { return false; @@ -371,13 +371,13 @@ public class TextFieldWidget extends WidgetWithBounds implements Tickable { if (this.field_2096) { this.setFocused(boolean_1); } - + if (this.focused && boolean_1 && int_1 == 0) { int int_2 = MathHelper.floor(double_1) - this.bounds.x; if (this.hasBorder) { int_2 -= 4; } - + String string_1 = this.font.trimToWidth(this.text.substring(this.field_2103), this.getWidth()); this.method_1883(this.font.trimToWidth(string_1, int_2).length() + this.field_2103); return true; @@ -386,7 +386,7 @@ public class TextFieldWidget extends WidgetWithBounds implements Tickable { } } } - + public void renderBorder() { if (this.hasBorder()) { if (containsMouse(PointHelper.fromMouse()) || focused) @@ -396,11 +396,11 @@ public class TextFieldWidget extends WidgetWithBounds implements Tickable { fill(this.bounds.x, this.bounds.y, this.bounds.x + this.bounds.width, this.bounds.y + this.bounds.height, -16777216); } } - + public void render(int int_1, int int_2, float float_1) { if (this.isVisible()) { renderBorder(); - + int color = this.editable ? this.editableColor : this.notEditableColor; int int_4 = this.cursorMax - this.field_2103; int int_5 = this.cursorMin - this.field_2103; @@ -413,12 +413,12 @@ public class TextFieldWidget extends WidgetWithBounds implements Tickable { if (int_5 > string_1.length()) { int_5 = string_1.length(); } - + if (!string_1.isEmpty()) { String string_2 = boolean_1 ? string_1.substring(0, int_4) : string_1; - int_8 = this.font.drawWithShadow((String) this.renderTextProvider.apply(string_2, this.field_2103), (float) int_6, (float) int_7, color); + int_8 = this.font.drawWithShadow(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) { @@ -427,15 +427,15 @@ public class TextFieldWidget extends WidgetWithBounds implements Tickable { int_9 = int_8 - 1; --int_8; } - + if (!string_1.isEmpty() && boolean_1 && int_4 < string_1.length()) { - this.font.drawWithShadow((String) this.renderTextProvider.apply(string_1.substring(int_4), this.cursorMax), (float) int_8, (float) int_7, color); + this.font.drawWithShadow(this.renderTextProvider.apply(string_1.substring(int_4), this.cursorMax), (float) int_8, (float) int_7, color); } - + if (!boolean_3 && text.isEmpty() && this.suggestion != null) { this.font.drawWithShadow(this.font.trimToWidth(this.suggestion, this.getWidth()), (float) int_6, (float) int_7, -8355712); } - + int var10002; int var10003; if (boolean_2) { @@ -449,7 +449,7 @@ public class TextFieldWidget extends WidgetWithBounds implements Tickable { this.font.drawWithShadow("_", (float) int_9, (float) int_7, color); } } - + if (int_5 != int_4) { int int_10 = int_6 + this.font.getStringWidth(string_1.substring(0, int_5)); var10002 = int_7 - 1; @@ -459,7 +459,7 @@ public class TextFieldWidget extends WidgetWithBounds implements Tickable { } } } - + protected void method_1886(int int_1, int int_2, int int_3, int int_4) { int int_6; if (int_1 < int_3) { @@ -467,21 +467,21 @@ public class TextFieldWidget extends WidgetWithBounds implements Tickable { int_1 = int_3; int_3 = int_6; } - + if (int_2 < int_4) { int_6 = int_2; int_2 = int_4; int_4 = int_6; } - + if (int_3 > this.bounds.x + this.bounds.width) { int_3 = this.bounds.x + this.bounds.width; } - + if (int_1 > this.bounds.x + this.bounds.width) { int_1 = this.bounds.x + this.bounds.width; } - + Tessellator tessellator_1 = Tessellator.getInstance(); BufferBuilder bufferBuilder_1 = tessellator_1.getBuffer(); RenderSystem.color4f(0.0F, 0.0F, 255.0F, 255.0F); @@ -489,19 +489,19 @@ public class TextFieldWidget extends WidgetWithBounds implements Tickable { RenderSystem.enableColorLogicOp(); RenderSystem.logicOp(GlStateManager.LogicOp.OR_REVERSE); bufferBuilder_1.begin(7, VertexFormats.POSITION); - bufferBuilder_1.vertex((double) int_1, (double) int_4, getBlitOffset() + 50d).next(); - bufferBuilder_1.vertex((double) int_3, (double) int_4, getBlitOffset() + 50d).next(); - bufferBuilder_1.vertex((double) int_3, (double) int_2, getBlitOffset() + 50d).next(); - bufferBuilder_1.vertex((double) int_1, (double) int_2, getBlitOffset() + 50d).next(); + bufferBuilder_1.vertex(int_1, int_4, getBlitOffset() + 50d).next(); + bufferBuilder_1.vertex(int_3, int_4, getBlitOffset() + 50d).next(); + bufferBuilder_1.vertex(int_3, int_2, getBlitOffset() + 50d).next(); + bufferBuilder_1.vertex(int_1, int_2, getBlitOffset() + 50d).next(); tessellator_1.draw(); RenderSystem.disableColorLogicOp(); RenderSystem.enableTexture(); } - + public int getMaxLength() { return this.maxLength; } - + public void setMaxLength(int int_1) { this.maxLength = int_1; if (this.text.length() > int_1) { @@ -509,31 +509,31 @@ public class TextFieldWidget extends WidgetWithBounds implements Tickable { this.onChanged(this.text); } } - + public int getCursor() { return this.cursorMax; } - + public void setCursor(int int_1) { this.cursorMax = MathHelper.clamp(int_1, 0, this.text.length()); } - + public boolean hasBorder() { return this.hasBorder; } - + public void setHasBorder(boolean boolean_1) { this.hasBorder = boolean_1; } - + public void setEditableColor(int int_1) { this.editableColor = int_1; } - + public void setNotEditableColor(int int_1) { this.notEditableColor = int_1; } - + public boolean changeFocus(boolean boolean_1) { if (this.visible && this.editable) { this.setFocused(!this.focused); @@ -541,25 +541,25 @@ public class TextFieldWidget extends WidgetWithBounds implements Tickable { } return false; } - + public boolean isFocused() { return this.focused; } - + public void setFocused(boolean boolean_1) { if (boolean_1 && !this.focused) this.focusedTicks = 0; this.focused = boolean_1; } - + public void setIsEditable(boolean boolean_1) { this.editable = boolean_1; } - + public int getWidth() { return this.hasBorder() ? this.bounds.width - 8 : this.bounds.width; } - + public void method_1884(int int_1) { int int_2 = this.text.length(); this.cursorMin = MathHelper.clamp(int_1, 0, int_2); @@ -567,39 +567,39 @@ public class TextFieldWidget extends WidgetWithBounds implements Tickable { if (this.field_2103 > int_2) { this.field_2103 = int_2; } - + int int_3 = this.getWidth(); String string_1 = this.font.trimToWidth(this.text.substring(this.field_2103), int_3); int int_4 = string_1.length() + this.field_2103; if (this.cursorMin == this.field_2103) { this.field_2103 -= this.font.trimToWidth(this.text, int_3, true).length(); } - + if (this.cursorMin > int_4) { this.field_2103 += this.cursorMin - int_4; } else if (this.cursorMin <= this.field_2103) { this.field_2103 -= this.field_2103 - this.cursorMin; } - + this.field_2103 = MathHelper.clamp(this.field_2103, 0, int_2); } - + } - + public void method_1856(boolean boolean_1) { this.field_2096 = boolean_1; } - + public boolean isVisible() { return this.visible; } - + public void setVisible(boolean boolean_1) { this.visible = boolean_1; } - + public int method_1889(int int_1) { return int_1 > this.text.length() ? this.bounds.x : this.bounds.x + this.font.getStringWidth(this.text.substring(0, int_1)); } - + } |
