Add GuiTextArea
Reorder and add description to GuiUpload
This commit is contained in:
@@ -4,12 +4,14 @@ import eu.crushedpixel.replaymod.ReplayMod;
|
||||
import eu.crushedpixel.replaymod.api.replay.FileUploader;
|
||||
import eu.crushedpixel.replaymod.api.replay.holders.Category;
|
||||
import eu.crushedpixel.replaymod.gui.GuiConstants;
|
||||
import eu.crushedpixel.replaymod.gui.elements.GuiProgressBar;
|
||||
import eu.crushedpixel.replaymod.gui.elements.*;
|
||||
import eu.crushedpixel.replaymod.gui.replayviewer.GuiReplayViewer;
|
||||
import eu.crushedpixel.replaymod.online.authentication.AuthenticationHandler;
|
||||
import eu.crushedpixel.replaymod.recording.ReplayMetaData;
|
||||
import eu.crushedpixel.replaymod.registry.KeybindRegistry;
|
||||
import eu.crushedpixel.replaymod.registry.ResourceHelper;
|
||||
import eu.crushedpixel.replaymod.utils.ImageUtils;
|
||||
import eu.crushedpixel.replaymod.utils.MouseUtils;
|
||||
import eu.crushedpixel.replaymod.utils.ReplayFile;
|
||||
import eu.crushedpixel.replaymod.utils.ReplayFileIO;
|
||||
import net.minecraft.client.Minecraft;
|
||||
@@ -19,8 +21,8 @@ import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.gui.GuiTextField;
|
||||
import net.minecraft.client.renderer.texture.DynamicTexture;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.client.settings.GameSettings;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.fml.client.config.GuiCheckBox;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
@@ -33,9 +35,10 @@ import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class GuiUploadFile extends GuiScreen {
|
||||
@@ -48,20 +51,30 @@ public class GuiUploadFile extends GuiScreen {
|
||||
private final ResourceLocation textureResource;
|
||||
private DynamicTexture dynTex = null;
|
||||
|
||||
private GuiTextField fileTitleInput, fileTitlePlaceholder, tagInput, messageTextField, tagPlaceholder;
|
||||
private GuiCheckBox hideServerIP;
|
||||
private GuiButton categoryButton, startUploadButton, cancelUploadButton, backButton;
|
||||
private boolean initialized;
|
||||
|
||||
private int columnWidth, columnLeft, columnMiddle, columnRight;
|
||||
|
||||
private GuiAdvancedTextField name, tags;
|
||||
private GuiToggleButton category;
|
||||
private GuiString serverIP, duration;
|
||||
private GuiAdvancedCheckBox hideServerIP;
|
||||
private GuiTextArea description;
|
||||
|
||||
private ComposedElement content;
|
||||
|
||||
private GuiTextField messageTextField;
|
||||
private GuiButton startUploadButton, cancelUploadButton, backButton;
|
||||
private GuiProgressBar progressBar;
|
||||
|
||||
private File replayFile;
|
||||
|
||||
private ReplayMetaData metaData;
|
||||
private BufferedImage thumb;
|
||||
private boolean hasThumbnail;
|
||||
|
||||
private FileUploader uploader = new FileUploader();
|
||||
|
||||
private Category category = Category.MINIGAME;
|
||||
|
||||
private GuiReplayViewer parent;
|
||||
|
||||
private boolean lockUploadButton = false;
|
||||
@@ -86,6 +99,7 @@ public class GuiUploadFile extends GuiScreen {
|
||||
BufferedImage img = archive.thumb().get();
|
||||
if(img != null) {
|
||||
thumb = ImageUtils.scaleImage(img, new Dimension(1280, 720));
|
||||
hasThumbnail = true;
|
||||
}
|
||||
|
||||
archive.close();
|
||||
@@ -131,43 +145,77 @@ public class GuiUploadFile extends GuiScreen {
|
||||
return;
|
||||
}
|
||||
|
||||
if(fileTitleInput == null) {
|
||||
fileTitleInput = new GuiTextField(GuiConstants.UPLOAD_NAME_INPUT, fontRendererObj, (this.width / 2) + 20 + 10, 21, Math.min(200, this.width - 20 - 260), 20);
|
||||
String fname = FilenameUtils.getBaseName(replayFile.getAbsolutePath());
|
||||
fileTitleInput.setText(fname);
|
||||
fileTitleInput.setMaxStringLength(30);
|
||||
} else {
|
||||
fileTitleInput.xPosition = (this.width / 2) + 20 + 10;
|
||||
fileTitleInput.width = Math.min(200, this.width - 20 - 260);
|
||||
}
|
||||
if (!initialized) {
|
||||
initialized = true;
|
||||
|
||||
if(fileTitlePlaceholder == null) {
|
||||
fileTitlePlaceholder = new GuiTextField(GuiConstants.UPLOAD_NAME_PLACEHOLDER, fontRendererObj, fileTitleInput.xPosition, fileTitleInput.yPosition, fileTitleInput.width, 20);
|
||||
fileTitlePlaceholder.setTextColor(Color.DARK_GRAY.getRGB());
|
||||
fileTitlePlaceholder.setText(I18n.format("replaymod.gui.upload.namehint"));
|
||||
} else {
|
||||
fileTitlePlaceholder.xPosition = fileTitleInput.xPosition;
|
||||
fileTitlePlaceholder.width = fileTitleInput.width;
|
||||
}
|
||||
int y = 20;
|
||||
|
||||
if(hideServerIP == null) {
|
||||
hideServerIP = new GuiCheckBox(GuiConstants.UPLOAD_HIDE_SERVER_IP, 0, 80, I18n.format("replaymod.gui.upload.hideip"), false);
|
||||
name = new GuiAdvancedTextField(fontRendererObj, 0, y, 0, 20);
|
||||
name.hint = I18n.format("replaymod.gui.upload.namehint");
|
||||
name.text = FilenameUtils.getBaseName(replayFile.getAbsolutePath());
|
||||
name.setMaxStringLength(30);
|
||||
y+=25;
|
||||
|
||||
int secs = metaData.getDuration() / 1000;
|
||||
String durationString = I18n.format("replaymod.gui.duration") + String.format(": %02dm%02ds", secs / 60, secs % 60);
|
||||
duration = new GuiString(0, y, Color.WHITE, durationString);
|
||||
y+=15;
|
||||
|
||||
hideServerIP = new GuiAdvancedCheckBox(0, y, I18n.format("replaymod.gui.upload.hideip"), false);
|
||||
hideServerIP.enabled = !metaData.isSingleplayer();
|
||||
y+=15;
|
||||
|
||||
serverIP = new GuiString(0, y, Color.GRAY, new Callable<String>() {
|
||||
@Override
|
||||
public String call() throws Exception {
|
||||
if (hideServerIP.isChecked()){
|
||||
return I18n.format("replaymod.gui.iphidden");
|
||||
} else {
|
||||
return metaData.getServerName();
|
||||
}
|
||||
}
|
||||
});
|
||||
y+=15;
|
||||
|
||||
category = new GuiToggleButton(0, 0, y, I18n.format("replaymod.category") + ": ", Category.stringValues());
|
||||
y+=25;
|
||||
|
||||
tags = new GuiAdvancedTextField(fontRendererObj, 0, y, 0, 20);
|
||||
tags.setMaxStringLength(30);
|
||||
tags.hint = I18n.format("replaymod.gui.upload.tagshint");
|
||||
y+=20;
|
||||
|
||||
description = new GuiTextArea(fontRendererObj, 0, name.yPosition, 0, y - name.yPosition, 30, 15);
|
||||
}
|
||||
|
||||
if(hideServerIP.enabled) {
|
||||
hideServerIP.xPosition = (this.width / 2) + 20 + 9;
|
||||
buttonList.add(hideServerIP);
|
||||
}
|
||||
columnWidth = Math.min(200, (width - 60) / 3);
|
||||
columnLeft = width / 2 - columnWidth / 2 * 3 - 10;
|
||||
columnMiddle = width / 2 - columnWidth / 2;
|
||||
columnRight = width / 2 + columnWidth / 2 + 10;
|
||||
|
||||
if(categoryButton == null) {
|
||||
categoryButton = new GuiButton(GuiConstants.UPLOAD_CATEGORY_BUTTON, (this.width / 2) + 20 + 10 - 1, 95, I18n.format("replaymod.category")+": " + category.toNiceString());
|
||||
categoryButton.width = Math.min(202, this.width - 20 - 260 + 2);
|
||||
} else {
|
||||
categoryButton.xPosition = (this.width / 2) + 20 + 10 - 1;
|
||||
}
|
||||
name.xPosition = columnLeft;
|
||||
name.width = columnWidth;
|
||||
|
||||
buttonList.add(categoryButton);
|
||||
duration.positionX = columnLeft;
|
||||
hideServerIP.xPosition = columnLeft - 1;
|
||||
serverIP.positionX = columnLeft;
|
||||
|
||||
category.xPosition = columnLeft - 1;
|
||||
category.width = columnWidth + 2;
|
||||
|
||||
tags.xPosition = columnLeft;
|
||||
tags.width = columnWidth;
|
||||
|
||||
description.positionX = columnMiddle;
|
||||
description.setWidth(columnWidth);
|
||||
|
||||
List<GuiElement> elements = new ArrayList<GuiElement>(Arrays.asList(
|
||||
name, category, tags, description, serverIP, duration
|
||||
));
|
||||
if (!metaData.isSingleplayer()) {
|
||||
elements.add(hideServerIP);
|
||||
}
|
||||
content = new ComposedElement(elements.toArray(new GuiElement[elements.size()]));
|
||||
|
||||
if(startUploadButton == null) {
|
||||
List<GuiButton> bottomBar = new ArrayList<GuiButton>();
|
||||
@@ -228,23 +276,6 @@ public class GuiUploadFile extends GuiScreen {
|
||||
messageTextField.width = width - 40;
|
||||
}
|
||||
|
||||
if(tagInput == null) {
|
||||
tagInput = new GuiTextField(GuiConstants.UPLOAD_TAG_INPUT, fontRendererObj, (this.width / 2) + 20 + 10, categoryButton.yPosition + 20 + 5, Math.min(200, this.width - 20 - 260), 20);
|
||||
tagInput.setMaxStringLength(30);
|
||||
} else {
|
||||
tagInput.xPosition = (this.width / 2) + 20 + 10;
|
||||
tagInput.width = Math.min(200, this.width - 20 - 260);
|
||||
}
|
||||
|
||||
if(tagPlaceholder == null) {
|
||||
tagPlaceholder = new GuiTextField(GuiConstants.UPLOAD_TAG_PLACEHOLDER, fontRendererObj, (this.width / 2) + 20 + 10, tagInput.yPosition, Math.min(200, this.width - 20 - 260), 20);
|
||||
tagPlaceholder.setTextColor(Color.DARK_GRAY.getRGB());
|
||||
tagPlaceholder.setText(I18n.format("replaymod.gui.upload.tagshint"));
|
||||
} else {
|
||||
tagPlaceholder.xPosition = (this.width / 2) + 20 + 10;
|
||||
tagPlaceholder.width = Math.min(200, this.width - 20 - 260);
|
||||
}
|
||||
|
||||
if(progressBar == null) {
|
||||
progressBar = new GuiProgressBar(19, height - 52, width - (2*19), 15);
|
||||
} else {
|
||||
@@ -257,18 +288,15 @@ public class GuiUploadFile extends GuiScreen {
|
||||
@Override
|
||||
protected void actionPerformed(GuiButton button) throws IOException {
|
||||
if(!button.enabled) return;
|
||||
if(button.id == GuiConstants.UPLOAD_CATEGORY_BUTTON) {
|
||||
category = category.next();
|
||||
categoryButton.displayString = I18n.format("replaymod.category")+": " + category.toNiceString();
|
||||
} else if(button.id == GuiConstants.UPLOAD_BACK_BUTTON) {
|
||||
if(button.id == GuiConstants.UPLOAD_BACK_BUTTON) {
|
||||
mc.displayGuiScreen(parent);
|
||||
} else if(button.id == GuiConstants.UPLOAD_START_BUTTON) {
|
||||
final String name = fileTitleInput.getText().trim();
|
||||
final String name = this.name.getText().trim();
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
String tagsRaw = tagInput.getText();
|
||||
String tagsRaw = tags.getText();
|
||||
String[] split = tagsRaw.split(",");
|
||||
List<String> tags = new ArrayList<String>();
|
||||
for(String str : split) {
|
||||
@@ -277,6 +305,7 @@ public class GuiUploadFile extends GuiScreen {
|
||||
}
|
||||
}
|
||||
|
||||
Category category = Category.values()[GuiUploadFile.this.category.getValue()];
|
||||
if(hideServerIP.isChecked()) {
|
||||
File tmp = File.createTempFile("replay_hidden_ip", "mcpr");
|
||||
File tmpMeta = File.createTempFile("metadata", "json");
|
||||
@@ -316,16 +345,6 @@ public class GuiUploadFile extends GuiScreen {
|
||||
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
|
||||
this.drawDefaultBackground();
|
||||
|
||||
String durationString = I18n.format("replaymod.gui.duration") + ": " + String.format("%02dm%02ds",
|
||||
TimeUnit.MILLISECONDS.toMinutes(metaData.getDuration()),
|
||||
TimeUnit.MILLISECONDS.toSeconds(metaData.getDuration()) -
|
||||
TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(metaData.getDuration()))
|
||||
);
|
||||
|
||||
drawString(fontRendererObj, durationString, (this.width / 2) + 20 + 10, 50, Color.WHITE.getRGB());
|
||||
drawString(fontRendererObj, hideServerIP.isChecked() ? I18n.format("replaymod.gui.iphidden") : metaData.getServerName(),
|
||||
(this.width / 2) + 20 + 10, 65, Color.GRAY.getRGB());
|
||||
|
||||
drawCenteredString(fontRendererObj, I18n.format("replaymod.gui.upload.title"), this.width / 2, 5, Color.WHITE.getRGB());
|
||||
|
||||
//Draw thumbnail
|
||||
@@ -338,42 +357,37 @@ public class GuiUploadFile extends GuiScreen {
|
||||
}
|
||||
|
||||
mc.getTextureManager().bindTexture(textureResource); //Will be freed by the ResourceHelper
|
||||
int wid = (this.width) / 2;
|
||||
int hei = Math.round(wid * (720f / 1280f));
|
||||
Gui.drawScaledCustomSizeModalRect(19, 20, 0, 0, 1280, 720, wid, hei, 1280, 720);
|
||||
}
|
||||
int height = columnWidth * 720 / 1280;
|
||||
Gui.drawScaledCustomSizeModalRect(columnRight, 20, 0, 0, 1280, 720, columnWidth, height, 1280, 720);
|
||||
|
||||
if(fileTitleInput.getText().length() > 0 || fileTitleInput.isFocused()) {
|
||||
fileTitleInput.drawTextBox();
|
||||
} else {
|
||||
fileTitlePlaceholder.drawTextBox();
|
||||
if (!hasThumbnail) {
|
||||
String str = I18n.format("replaymod.gui.upload.nothumbnail",
|
||||
GameSettings.getKeyDisplayString(KeybindRegistry.getKeyBinding(KeybindRegistry.KEY_THUMBNAIL).getKeyCode()));
|
||||
int y = 20 + height + 10;
|
||||
fontRendererObj.drawSplitString(str, columnRight, y, columnWidth, Color.RED.getRGB());
|
||||
}
|
||||
}
|
||||
|
||||
messageTextField.drawTextBox();
|
||||
|
||||
if(tagInput.getText().length() > 0 || tagInput.isFocused()) {
|
||||
tagInput.drawTextBox();
|
||||
} else {
|
||||
tagPlaceholder.drawTextBox();
|
||||
}
|
||||
|
||||
super.drawScreen(mouseX, mouseY, partialTicks);
|
||||
|
||||
progressBar.setProgress(uploader.getUploadProgress());
|
||||
progressBar.drawProgressBar();
|
||||
|
||||
content.draw(mc, mouseX, mouseY);
|
||||
content.drawOverlay(mc, mouseX, mouseY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException {
|
||||
super.mouseClicked(mouseX, mouseY, mouseButton);
|
||||
fileTitleInput.mouseClicked(mouseX, mouseY, mouseButton);
|
||||
tagInput.mouseClicked(mouseX, mouseY, mouseButton);
|
||||
content.mouseClick(mc, mouseX, mouseY, mouseButton);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateScreen() {
|
||||
fileTitleInput.updateCursorCounter();
|
||||
tagInput.updateCursorCounter();
|
||||
content.tick(mc);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -385,11 +399,8 @@ public class GuiUploadFile extends GuiScreen {
|
||||
|
||||
@Override
|
||||
protected void keyTyped(char typedChar, int keyCode) throws IOException {
|
||||
if(fileTitleInput.isFocused()) {
|
||||
fileTitleInput.textboxKeyTyped(typedChar, keyCode);
|
||||
} else if(tagInput.isFocused()) {
|
||||
tagInput.textboxKeyTyped(typedChar, keyCode);
|
||||
}
|
||||
org.lwjgl.util.Point mouse = MouseUtils.getMousePos();
|
||||
content.buttonPressed(mc, mouse.getX(), mouse.getY(), typedChar, keyCode);
|
||||
|
||||
if(uploader.isUploading()) {
|
||||
startUploadButton.enabled = false;
|
||||
@@ -400,17 +411,17 @@ public class GuiUploadFile extends GuiScreen {
|
||||
|
||||
private void validateStartButton() {
|
||||
boolean enabled = true;
|
||||
if(fileTitleInput.getText().trim().length() < 5 || fileTitleInput.getText().trim().length() > 30) {
|
||||
if(name.getText().trim().length() < 5 || name.getText().trim().length() > 30) {
|
||||
enabled = false;
|
||||
} else if(titlePattern.matcher(fileTitleInput.getText()).find()) {
|
||||
} else if(titlePattern.matcher(name.getText()).find()) {
|
||||
enabled = false;
|
||||
fileTitleInput.setTextColor(Color.RED.getRGB());
|
||||
} else if(tagsPattern.matcher(tagInput.getText()).find()) {
|
||||
name.setTextColor(Color.RED.getRGB());
|
||||
} else if(tagsPattern.matcher(tags.getText()).find()) {
|
||||
enabled = false;
|
||||
tagInput.setTextColor(Color.RED.getRGB());
|
||||
tags.setTextColor(Color.RED.getRGB());
|
||||
} else {
|
||||
fileTitleInput.setTextColor(Color.WHITE.getRGB());
|
||||
tagInput.setTextColor(Color.WHITE.getRGB());
|
||||
name.setTextColor(Color.WHITE.getRGB());
|
||||
tags.setTextColor(Color.WHITE.getRGB());
|
||||
}
|
||||
|
||||
if(lockUploadButton) enabled = false;
|
||||
@@ -422,8 +433,9 @@ public class GuiUploadFile extends GuiScreen {
|
||||
startUploadButton.enabled = false;
|
||||
cancelUploadButton.enabled = true;
|
||||
backButton.enabled = false;
|
||||
categoryButton.enabled = false;
|
||||
fileTitleInput.setEnabled(false);
|
||||
category.enabled = false;
|
||||
name.setEnabled(false);
|
||||
description.enabled = false;
|
||||
messageTextField.setText(I18n.format("replaymod.gui.upload.uploading"));
|
||||
messageTextField.setTextColor(Color.WHITE.getRGB());
|
||||
}
|
||||
@@ -432,8 +444,9 @@ public class GuiUploadFile extends GuiScreen {
|
||||
validateStartButton();
|
||||
cancelUploadButton.enabled = false;
|
||||
backButton.enabled = true;
|
||||
categoryButton.enabled = true;
|
||||
fileTitleInput.setEnabled(true);
|
||||
category.enabled = true;
|
||||
name.setEnabled(true);
|
||||
description.enabled = true;
|
||||
if(success) {
|
||||
messageTextField.setText(I18n.format("replaymod.gui.upload.success"));
|
||||
messageTextField.setTextColor(Color.GREEN.getRGB());
|
||||
|
||||
Reference in New Issue
Block a user