Added a way to limit a GuiTextArea's maximum character count and used it in GuiUploadFile's Description Text Area
Set GuiUploadFile's Description Text Area's line and width limit to a high value for better results on the website | https://trello.com/c/YS9EyYPF/
This commit is contained in:
@@ -58,6 +58,7 @@ public class GuiTextArea extends Gui implements GuiElement {
|
||||
// Content
|
||||
private final int maxTextWidth;
|
||||
private final int maxTextHeight;
|
||||
private final int maxCharCount;
|
||||
|
||||
private String[] text = {""};
|
||||
private boolean isFocused;
|
||||
@@ -76,11 +77,16 @@ public class GuiTextArea extends Gui implements GuiElement {
|
||||
|
||||
public GuiTextArea(FontRenderer fontRenderer, int positionX, int positionY, int width, int height,
|
||||
int maxTextWidth, int maxTextHeight) {
|
||||
this(0, fontRenderer, positionX, positionY, width, height, maxTextWidth, maxTextHeight);
|
||||
this(0, fontRenderer, positionX, positionY, width, height, maxTextWidth, maxTextHeight, -1);
|
||||
}
|
||||
|
||||
public GuiTextArea(FontRenderer fontRenderer, int positionX, int positionY, int width, int height,
|
||||
int maxTextWidth, int maxTextHeight, int maxCharCount) {
|
||||
this(0, fontRenderer, positionX, positionY, width, height, maxTextWidth, maxTextHeight, maxCharCount);
|
||||
}
|
||||
|
||||
public GuiTextArea(int guiId, FontRenderer fontRenderer, int positionX, int positionY, int width, int height,
|
||||
int maxTextWidth, int maxTextHeight) {
|
||||
int maxTextWidth, int maxTextHeight, int maxCharCount) {
|
||||
this.guiId = guiId;
|
||||
this.fontRenderer = fontRenderer;
|
||||
this.positionX = positionX;
|
||||
@@ -89,6 +95,7 @@ public class GuiTextArea extends Gui implements GuiElement {
|
||||
this.height = height;
|
||||
this.maxTextWidth = maxTextWidth;
|
||||
this.maxTextHeight = maxTextHeight;
|
||||
this.maxCharCount = maxCharCount;
|
||||
}
|
||||
|
||||
public void setText(String[] lines) {
|
||||
@@ -219,6 +226,15 @@ public class GuiTextArea extends Gui implements GuiElement {
|
||||
return;
|
||||
}
|
||||
|
||||
int totalCharCount = 0;
|
||||
for(String line : text) {
|
||||
totalCharCount += line.length();
|
||||
}
|
||||
|
||||
if(totalCharCount-(getSelectedText().length()) >= maxCharCount) {
|
||||
return;
|
||||
}
|
||||
|
||||
deleteSelectedText();
|
||||
|
||||
if (c == '\n') {
|
||||
|
||||
@@ -186,7 +186,7 @@ public class GuiUploadFile extends GuiScreen implements ProgressUpdateListener {
|
||||
tags.hint = I18n.format("replaymod.gui.upload.tagshint");
|
||||
y+=20;
|
||||
|
||||
description = new GuiTextArea(fontRendererObj, 0, name.yPosition, 0, y - name.yPosition, 30, 15);
|
||||
description = new GuiTextArea(fontRendererObj, 0, name.yPosition, 0, y - name.yPosition, 1000, 100, 1000);
|
||||
}
|
||||
|
||||
columnWidth = Math.min(200, (width - 60) / 3);
|
||||
|
||||
Reference in New Issue
Block a user