Added GuiProgressBar and implemented it in GuiUploadFile
Fixed incorrect success messages in GuiUploadFile
This commit is contained in:
@@ -112,20 +112,20 @@ public class FileUploader {
|
||||
success = true;
|
||||
is = con.getInputStream();
|
||||
} else {
|
||||
success = false;
|
||||
is = con.getErrorStream();
|
||||
}
|
||||
|
||||
if(is != null) {
|
||||
BufferedReader r = new BufferedReader(new InputStreamReader(is));
|
||||
info = null;
|
||||
String result = "";
|
||||
while(r.ready()) {
|
||||
result += r.readLine();
|
||||
}
|
||||
if(responseCode != 200) {
|
||||
String json = "";
|
||||
while(r.ready()) {
|
||||
json += r.readLine();
|
||||
}
|
||||
ApiError error = gson.fromJson(json, ApiError.class);
|
||||
ApiError error = gson.fromJson(result, ApiError.class);
|
||||
info = error.getTranslatedDesc();
|
||||
System.out.println(info);
|
||||
}
|
||||
}
|
||||
con.disconnect();
|
||||
@@ -133,8 +133,6 @@ public class FileUploader {
|
||||
if(info == null) info = I18n.format("replaymod.gui.unknownerror");
|
||||
|
||||
ReplayMod.uploadedFileHandler.markAsUploaded(file);
|
||||
|
||||
success = true;
|
||||
} catch(Exception e) {
|
||||
success = false;
|
||||
} finally {
|
||||
|
||||
@@ -7,6 +7,7 @@ import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraftforge.fml.client.config.GuiCheckBox;
|
||||
|
||||
import java.awt.*;
|
||||
import java.io.IOException;
|
||||
|
||||
public class GuiVideoRenderer extends GuiScreen {
|
||||
@@ -84,12 +85,14 @@ public class GuiVideoRenderer extends GuiScreen {
|
||||
drawBackground(0);
|
||||
|
||||
String framesProgress = I18n.format("replaymod.gui.rendering.progress", renderer.getFramesDone(), renderer.getTotalFrames());
|
||||
drawCenteredString(fontRendererObj, framesProgress, centerX, centerY - 45, 0xffffffff);
|
||||
drawCenteredString(fontRendererObj, framesProgress, centerX, centerY - 45, Color.WHITE.getRGB());
|
||||
|
||||
int previewX = width / 4;
|
||||
int previewY = height / 2 + 10;
|
||||
int previewWidth = width / 2;
|
||||
|
||||
int previewY = height / 2 + 10;
|
||||
int previewHeight = height - 30 - previewY;
|
||||
|
||||
if (previewCheckBox.isChecked()) {
|
||||
frameRenderer.renderPreview(previewX, previewY, previewWidth, previewHeight);
|
||||
} else {
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
package eu.crushedpixel.replaymod.gui.elements;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.Gui;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class GuiProgressBar extends Gui {
|
||||
|
||||
private static final int BORDER_WIDTH = 2;
|
||||
|
||||
private final Minecraft mc = Minecraft.getMinecraft();
|
||||
|
||||
private int xPosition, yPosition, width, height;
|
||||
|
||||
private float progress = 0;
|
||||
|
||||
public GuiProgressBar(int xPosition, int yPosition, int width, int height) {
|
||||
this(xPosition, yPosition, width, height, 0);
|
||||
}
|
||||
|
||||
public GuiProgressBar(int xPosition, int yPosition, int width, int height, float initialProgress) {
|
||||
this.xPosition = xPosition;
|
||||
this.yPosition = yPosition;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.progress = initialProgress;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the progress amount of this GuiProgressBar.
|
||||
* @param progress A value between 0 and 1
|
||||
*/
|
||||
public void setProgress(float progress) {
|
||||
this.progress = progress;
|
||||
}
|
||||
|
||||
public float getProgress() {
|
||||
return progress;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets position and size of this GuiProgressBar.
|
||||
*/
|
||||
public void setBounds(int xPosition, int yPosition, int width, int height) {
|
||||
this.xPosition = xPosition;
|
||||
this.yPosition = yPosition;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
public void drawProgressBar() {
|
||||
int progressWidth = Math.round((width - (2*BORDER_WIDTH)) * progress);
|
||||
String progressString = (int)Math.floor(progress * 100) + "%";
|
||||
|
||||
// Draws black outline
|
||||
drawRect(xPosition, yPosition, xPosition + width, yPosition + height, Color.BLACK.getRGB());
|
||||
|
||||
// Draws white background
|
||||
drawRect(xPosition + BORDER_WIDTH, yPosition + BORDER_WIDTH,
|
||||
xPosition + width - BORDER_WIDTH, yPosition + height - BORDER_WIDTH, Color.WHITE.getRGB());
|
||||
|
||||
// Draws red progress
|
||||
drawRect(xPosition + BORDER_WIDTH, yPosition + BORDER_WIDTH,
|
||||
xPosition + BORDER_WIDTH + progressWidth, yPosition + height - BORDER_WIDTH, Color.RED.getRGB());
|
||||
|
||||
|
||||
int xMiddle = xPosition + (width/2);
|
||||
int yMiddle = yPosition + (height/2);
|
||||
|
||||
int progressStringWidth = mc.fontRendererObj.getStringWidth(progressString);
|
||||
int progressStringHeight = mc.fontRendererObj.FONT_HEIGHT-3;
|
||||
|
||||
int progressStringXPosition = xMiddle - (progressStringWidth/2);
|
||||
int progressStringYPosition = yMiddle - (progressStringHeight/2);
|
||||
|
||||
mc.fontRendererObj.drawString(progressString, progressStringXPosition, progressStringYPosition, Color.BLACK.getRGB());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
package eu.crushedpixel.replaymod.gui.online;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import eu.crushedpixel.replaymod.api.ApiException;
|
||||
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.replayviewer.GuiReplayViewer;
|
||||
import eu.crushedpixel.replaymod.online.authentication.AuthenticationHandler;
|
||||
import eu.crushedpixel.replaymod.recording.ReplayMetaData;
|
||||
@@ -36,21 +36,31 @@ import java.util.regex.Pattern;
|
||||
|
||||
public class GuiUploadFile extends GuiScreen {
|
||||
|
||||
private static final Pattern p = Pattern.compile("[^a-z0-9 \\-_]", Pattern.CASE_INSENSITIVE);
|
||||
private static final Pattern pt = Pattern.compile("[^a-z0-9,]", Pattern.CASE_INSENSITIVE);
|
||||
private final Minecraft mc = Minecraft.getMinecraft();
|
||||
|
||||
private static final Pattern titlePattern = Pattern.compile("[^a-z0-9 \\-_]", Pattern.CASE_INSENSITIVE);
|
||||
private static final Pattern tagsPattern = Pattern.compile("[^a-z0-9,]", Pattern.CASE_INSENSITIVE);
|
||||
|
||||
private final ResourceLocation textureResource;
|
||||
private DynamicTexture dynTex = null;
|
||||
|
||||
private GuiTextField fileTitleInput, tagInput, messageTextField, tagPlaceholder;
|
||||
private GuiButton categoryButton, startUploadButton, cancelUploadButton, backButton;
|
||||
private Gson gson = new Gson();
|
||||
private GuiProgressBar progressBar;
|
||||
|
||||
private File replayFile;
|
||||
|
||||
private ReplayMetaData metaData;
|
||||
private BufferedImage thumb;
|
||||
|
||||
private FileUploader uploader = new FileUploader();
|
||||
|
||||
private Category category = Category.MINIGAME;
|
||||
private DynamicTexture dynTex = null;
|
||||
private Minecraft mc = Minecraft.getMinecraft();
|
||||
|
||||
private GuiReplayViewer parent;
|
||||
|
||||
private boolean lockUploadButton = false;
|
||||
|
||||
private final Logger logger = LogManager.getLogger();
|
||||
|
||||
public GuiUploadFile(File file, GuiReplayViewer parent) {
|
||||
@@ -204,6 +214,12 @@ public class GuiUploadFile extends GuiScreen {
|
||||
tagPlaceholder.width = Math.min(200, this.width - 20 - 260);
|
||||
}
|
||||
|
||||
if(progressBar == null) {
|
||||
progressBar = new GuiProgressBar(19, height - 52, width - (2*19), 15);
|
||||
} else {
|
||||
progressBar.setBounds(19, height - 52, width - (2*19), 15);
|
||||
}
|
||||
|
||||
validateStartButton();
|
||||
}
|
||||
|
||||
@@ -251,7 +267,7 @@ public class GuiUploadFile extends GuiScreen {
|
||||
this.drawDefaultBackground();
|
||||
|
||||
drawString(fontRendererObj, metaData.getServerName(), (this.width / 2) + 20 + 10, 50, Color.GRAY.getRGB());
|
||||
drawString(fontRendererObj, I18n.format("replaymod.gui.duration")+": " + String.format("%02dm%02ds",
|
||||
drawString(fontRendererObj, 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()))
|
||||
@@ -285,17 +301,8 @@ public class GuiUploadFile extends GuiScreen {
|
||||
|
||||
super.drawScreen(mouseX, mouseY, partialTicks);
|
||||
|
||||
this.drawRect(19, this.height - 52, width - 19, this.height - 37, Color.BLACK.getRGB());
|
||||
this.drawRect(21, this.height - 50, width - 21, this.height - 39, Color.WHITE.getRGB());
|
||||
|
||||
int width = this.width - 21 - 21;
|
||||
float prog = uploader.getUploadProgress();
|
||||
float w = width * prog;
|
||||
|
||||
this.drawRect(21, this.height - 50, Math.round(21 + w), this.height - 39, Color.RED.getRGB());
|
||||
|
||||
String perc = (int) Math.floor(prog * 100) + "%";
|
||||
fontRendererObj.drawString(perc, this.width / 2 - fontRendererObj.getStringWidth(perc) / 2, this.height - 48, Color.BLACK.getRGB());
|
||||
progressBar.setProgress(uploader.getUploadProgress());
|
||||
progressBar.drawProgressBar();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -337,16 +344,19 @@ public class GuiUploadFile extends GuiScreen {
|
||||
boolean enabled = true;
|
||||
if(fileTitleInput.getText().trim().length() < 5 || fileTitleInput.getText().trim().length() > 30) {
|
||||
enabled = false;
|
||||
} else if(p.matcher(fileTitleInput.getText()).find()) {
|
||||
} else if(titlePattern.matcher(fileTitleInput.getText()).find()) {
|
||||
enabled = false;
|
||||
fileTitleInput.setTextColor(Color.RED.getRGB());
|
||||
} else if(pt.matcher(tagInput.getText()).find()) {
|
||||
} else if(tagsPattern.matcher(tagInput.getText()).find()) {
|
||||
enabled = false;
|
||||
tagInput.setTextColor(Color.RED.getRGB());
|
||||
} else {
|
||||
fileTitleInput.setTextColor(Color.WHITE.getRGB());
|
||||
tagInput.setTextColor(Color.WHITE.getRGB());
|
||||
}
|
||||
|
||||
if(lockUploadButton) enabled = false;
|
||||
|
||||
startUploadButton.enabled = enabled;
|
||||
}
|
||||
|
||||
@@ -369,6 +379,8 @@ public class GuiUploadFile extends GuiScreen {
|
||||
if(success) {
|
||||
messageTextField.setText(I18n.format("replaymod.gui.upload.success"));
|
||||
messageTextField.setTextColor(Color.GREEN.getRGB());
|
||||
startUploadButton.enabled = false;
|
||||
lockUploadButton = true;
|
||||
} else {
|
||||
messageTextField.setText(info);
|
||||
messageTextField.setTextColor(Color.RED.getRGB());
|
||||
|
||||
@@ -25,6 +25,7 @@ replaymod.api.invalidmail=Invalid Email Address
|
||||
replaymod.api.nopermissions=You don't have permission to do this
|
||||
replaymod.api.authfailed=Authentication to the Minecraft Session Servers failed
|
||||
replaymod.api.mcuserexists=A ReplayMod account is already associated with this Minecraft account
|
||||
replaymod.api.filetoobig=The uploaded file is too big
|
||||
|
||||
#All of the chat messages
|
||||
replaymod.chat.recordingstarted=Recording started
|
||||
|
||||
Reference in New Issue
Block a user