Refactored and reformatted code to use less static variables

This commit is contained in:
CrushedPixel
2015-04-23 14:09:54 +02:00
parent f22416be2c
commit 0003f040ed
109 changed files with 9037 additions and 10229 deletions

View File

@@ -1,170 +1,163 @@
package eu.crushedpixel.replaymod.gui.online;
import java.awt.Color;
import java.io.IOException;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.GuiTextField;
import org.lwjgl.input.Keyboard;
import eu.crushedpixel.replaymod.gui.GuiConstants;
import eu.crushedpixel.replaymod.gui.PasswordTextField;
import eu.crushedpixel.replaymod.online.authentication.AuthenticationHandler;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.GuiTextField;
import org.lwjgl.input.Keyboard;
import java.awt.*;
import java.io.IOException;
public class GuiLoginPrompt extends GuiScreen {
private static final int EMPTY = 0;
private static final int LOGGING_IN = 1;
private static final int INVALID_LOGIN = 2;
private static final int NO_CONNECTION = 3;
private GuiScreen parent, successScreen;
private int textState = 0;
private static final int EMPTY = 0;
private static final int LOGGING_IN = 1;
private static final int INVALID_LOGIN = 2;
private static final int NO_CONNECTION = 3;
private static Minecraft mc = Minecraft.getMinecraft();
private GuiScreen parent, successScreen;
private int textState = 0;
private GuiTextField username;
private PasswordTextField password;
private GuiButton loginButton;
private GuiButton cancelButton;
private int lastMouseX, lastMouseY;
private float lastPartialTicks;
private static Minecraft mc = Minecraft.getMinecraft();
public GuiLoginPrompt(GuiScreen parent, GuiScreen successScreen) {
this.parent = parent;
this.successScreen = successScreen;
}
private GuiTextField username;
private PasswordTextField password;
private GuiButton loginButton;
private GuiButton cancelButton;
@Override
public void initGui() {
Keyboard.enableRepeatEvents(true);
public GuiLoginPrompt(GuiScreen parent, GuiScreen successScreen) {
this.parent = parent;
this.successScreen = successScreen;
}
username = new GuiTextField(GuiConstants.REPLAY_CENTER_LOGIN_TEXT_ID, fontRendererObj, this.width / 2 - 45, 30, 145, 20);
username.setEnabled(true);
username.setFocused(true);
@Override
public void initGui() {
Keyboard.enableRepeatEvents(true);
password = new PasswordTextField(GuiConstants.REPLAY_CENTER_PASSWORD_TEXT_ID, fontRendererObj, this.width / 2 - 45, 60, 145, 20);
password.setEnabled(true);
password.setFocused(false);
username = new GuiTextField(GuiConstants.REPLAY_CENTER_LOGIN_TEXT_ID, fontRendererObj, this.width/2 - 45, 30, 145, 20);
username.setEnabled(true);
username.setFocused(true);
loginButton = new GuiButton(GuiConstants.LOGIN_OKAY_BUTTON, this.width / 2 - 150 - 2, 110, "Login");
loginButton.width = 150;
loginButton.enabled = false;
buttonList.add(loginButton);
password = new PasswordTextField(GuiConstants.REPLAY_CENTER_PASSWORD_TEXT_ID, fontRendererObj, this.width/2 - 45, 60, 145, 20);
password.setEnabled(true);
password.setFocused(false);
cancelButton = new GuiButton(GuiConstants.LOGIN_CANCEL_BUTTON, this.width / 2 + 2, 110, "Cancel");
cancelButton.width = 150;
buttonList.add(cancelButton);
}
loginButton = new GuiButton(GuiConstants.LOGIN_OKAY_BUTTON, this.width/2 - 150 - 2, 110, "Login");
loginButton.width = 150;
loginButton.enabled = false;
buttonList.add(loginButton);
@Override
protected void actionPerformed(GuiButton button) throws IOException {
if(button.id == GuiConstants.LOGIN_OKAY_BUTTON) {
if(button.enabled) {
//Authenticate
textState = LOGGING_IN;
cancelButton = new GuiButton(GuiConstants.LOGIN_CANCEL_BUTTON, this.width/2 + 2, 110, "Cancel");
cancelButton.width = 150;
buttonList.add(cancelButton);
}
new Thread(new Runnable() {
@Override
public void run() {
switch(AuthenticationHandler.authenticate(username.getText(), password.getText())) {
case AuthenticationHandler.SUCCESS:
textState = EMPTY;
mc.addScheduledTask(new Runnable() {
@Override
public void run() {
mc.displayGuiScreen(successScreen);
}
});
break;
case AuthenticationHandler.INVALID:
textState = INVALID_LOGIN;
break;
case AuthenticationHandler.NO_CONNECTION:
textState = NO_CONNECTION;
break;
}
}
}).start();
}
} else if(button.id == GuiConstants.LOGIN_CANCEL_BUTTON) {
mc.displayGuiScreen(parent);
}
}
@Override
protected void actionPerformed(GuiButton button) throws IOException {
if(button.id == GuiConstants.LOGIN_OKAY_BUTTON) {
if(button.enabled) {
//Authenticate
textState = LOGGING_IN;
new Thread(new Runnable() {
@Override
public void run() {
switch(AuthenticationHandler.authenticate(username.getText(), password.getText())) {
case AuthenticationHandler.SUCCESS:
textState = EMPTY;
mc.addScheduledTask(new Runnable() {
@Override
public void run() {
mc.displayGuiScreen(successScreen);
}
});
break;
case AuthenticationHandler.INVALID:
textState = INVALID_LOGIN;
break;
case AuthenticationHandler.NO_CONNECTION:
textState = NO_CONNECTION;
break;
}
}
}).start();
}
} else if(button.id == GuiConstants.LOGIN_CANCEL_BUTTON) {
mc.displayGuiScreen(parent);
}
}
@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
lastMouseX = mouseX;
lastMouseY = mouseY;
lastPartialTicks = partialTicks;
private int lastMouseX, lastMouseY;
private float lastPartialTicks;
@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
lastMouseX = mouseX;
lastMouseY = mouseY;
lastPartialTicks = partialTicks;
this.drawDefaultBackground();
drawCenteredString(fontRendererObj, "Login to ReplayMod.com", this.width/2, 10, Color.WHITE.getRGB());
this.drawDefaultBackground();
drawCenteredString(fontRendererObj, "Login to ReplayMod.com", this.width / 2, 10, Color.WHITE.getRGB());
drawString(fontRendererObj, "Username", this.width/2 - 100, 37, Color.WHITE.getRGB());
username.drawTextBox();
drawString(fontRendererObj, "Username", this.width / 2 - 100, 37, Color.WHITE.getRGB());
username.drawTextBox();
drawString(fontRendererObj, "Password", this.width/2 - 100, 67, Color.WHITE.getRGB());
password.drawTextBox();
switch(textState) {
case INVALID_LOGIN:
drawCenteredString(fontRendererObj, "Incorrect username or password.", this.width/2, 92, Color.RED.getRGB());
break;
case LOGGING_IN:
drawCenteredString(fontRendererObj, "Logging in...", this.width/2, 92, Color.WHITE.getRGB());
break;
case NO_CONNECTION:
drawCenteredString(fontRendererObj, "Could not connect to ReplayMod.com", this.width/2, 92, Color.RED.getRGB());
break;
}
super.drawScreen(mouseX, mouseY, partialTicks);
}
drawString(fontRendererObj, "Password", this.width / 2 - 100, 67, Color.WHITE.getRGB());
password.drawTextBox();
@Override
public void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException {
super.mouseClicked(mouseX, mouseY, mouseButton);
username.mouseClicked(mouseX, mouseY, mouseButton);
password.mouseClicked(mouseX, mouseY, mouseButton);
}
switch(textState) {
case INVALID_LOGIN:
drawCenteredString(fontRendererObj, "Incorrect username or password.", this.width / 2, 92, Color.RED.getRGB());
break;
case LOGGING_IN:
drawCenteredString(fontRendererObj, "Logging in...", this.width / 2, 92, Color.WHITE.getRGB());
break;
case NO_CONNECTION:
drawCenteredString(fontRendererObj, "Could not connect to ReplayMod.com", this.width / 2, 92, Color.RED.getRGB());
break;
}
super.drawScreen(mouseX, mouseY, partialTicks);
}
@Override
public void updateScreen() {
username.updateCursorCounter();
password.updateCursorCounter();
}
@Override
public void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException {
super.mouseClicked(mouseX, mouseY, mouseButton);
username.mouseClicked(mouseX, mouseY, mouseButton);
password.mouseClicked(mouseX, mouseY, mouseButton);
}
@Override
public void onGuiClosed() {
Keyboard.enableRepeatEvents(false);
}
@Override
public void updateScreen() {
username.updateCursorCounter();
password.updateCursorCounter();
}
@Override
protected void keyTyped(char typedChar, int keyCode) throws IOException {
if(keyCode == Keyboard.KEY_TAB) {
if(password.isFocused()) {
password.setFocused(false);
username.setFocused(true);
} else {
username.setFocused(false);
password.setFocused(true);
}
return;
}
if(keyCode == 28) { //Enter key
actionPerformed(loginButton);
return;
}
if(username.isFocused()) {
username.textboxKeyTyped(typedChar, keyCode);
} else if(password.isFocused()) {
password.textboxKeyTyped(typedChar, keyCode);
}
loginButton.enabled = username.getText().length() > 0 && password.getText().length() > 0;
}
@Override
public void onGuiClosed() {
Keyboard.enableRepeatEvents(false);
}
@Override
protected void keyTyped(char typedChar, int keyCode) throws IOException {
if(keyCode == Keyboard.KEY_TAB) {
if(password.isFocused()) {
password.setFocused(false);
username.setFocused(true);
} else {
username.setFocused(false);
password.setFocused(true);
}
return;
}
if(keyCode == 28) { //Enter key
actionPerformed(loginButton);
return;
}
if(username.isFocused()) {
username.textboxKeyTyped(typedChar, keyCode);
} else if(password.isFocused()) {
password.textboxKeyTyped(typedChar, keyCode);
}
loginButton.enabled = username.getText().length() > 0 && password.getText().length() > 0;
}
}

View File

@@ -1,22 +1,6 @@
package eu.crushedpixel.replaymod.gui.online;
import java.awt.Color;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiMainMenu;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.GuiYesNo;
import net.minecraft.client.gui.GuiYesNoCallback;
import net.minecraft.client.resources.I18n;
import org.lwjgl.input.Keyboard;
import eu.crushedpixel.replaymod.ReplayMod;
import eu.crushedpixel.replaymod.api.client.ApiException;
import eu.crushedpixel.replaymod.api.client.SearchPagination;
import eu.crushedpixel.replaymod.api.client.SearchQuery;
import eu.crushedpixel.replaymod.api.client.holders.FileInfo;
@@ -24,247 +8,251 @@ import eu.crushedpixel.replaymod.gui.GuiConstants;
import eu.crushedpixel.replaymod.gui.elements.GuiReplayListExtended;
import eu.crushedpixel.replaymod.gui.replayviewer.GuiReplayViewer;
import eu.crushedpixel.replaymod.online.authentication.AuthenticationHandler;
import net.minecraft.client.gui.*;
import net.minecraft.client.resources.I18n;
import org.lwjgl.input.Keyboard;
import java.awt.*;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class GuiReplayCenter extends GuiScreen implements GuiYesNoCallback {
private enum Tab {
RECENT_FILES, BEST_FILES, MY_FILES, SEARCH;
}
private static final SearchQuery recentFileSearchQuery = new SearchQuery(false, null, null, null, null, null,
null, null, null, null);
private static final SearchQuery bestFileSearchQuery = new SearchQuery(true, null, null, null, null, null,
null, null, null, null);
private static final int LOGOUT_CALLBACK_ID = 1;
private final SearchPagination recentFilePagination = new SearchPagination(recentFileSearchQuery);
private final SearchPagination bestFilePagination = new SearchPagination(bestFileSearchQuery);
private GuiReplayListExtended currentList;
private ReplayFileList recentFileList, bestFileList, myFileList, searchFileList;
private Tab currentTab = Tab.RECENT_FILES;
private SearchPagination myFilePagination;
private GuiReplayListExtended currentList;
public static GuiYesNo getYesNoGui(GuiYesNoCallback p_152129_0_, int p_152129_2_) {
String s1 = I18n.format("Do you really want to log out?", new Object[0]);
GuiYesNo guiyesno = new GuiYesNo(p_152129_0_, s1, "", "Logout", "Cancel", p_152129_2_);
return guiyesno;
}
private ReplayFileList recentFileList, bestFileList, myFileList, searchFileList;
@Override
public void initGui() {
Keyboard.enableRepeatEvents(true);
private Tab currentTab = Tab.RECENT_FILES;
if(AuthenticationHandler.isAuthenticated()) {
SearchQuery query = new SearchQuery();
query.auth = AuthenticationHandler.getKey();
query.order = false;
myFilePagination = new SearchPagination(query);
}
private static final SearchQuery recentFileSearchQuery = new SearchQuery(false, null, null, null, null, null,
null, null, null, null);
//Top Button Bar
List<GuiButton> buttonBar = new ArrayList<GuiButton>();
private static final SearchQuery bestFileSearchQuery = new SearchQuery(true, null, null, null, null, null,
null, null, null, null);
GuiButton recentButton = new GuiButton(GuiConstants.CENTER_RECENT_BUTTON, 20, 30, "Newest Replays");
buttonBar.add(recentButton);
private final SearchPagination recentFilePagination = new SearchPagination(recentFileSearchQuery);
private final SearchPagination bestFilePagination = new SearchPagination(bestFileSearchQuery);
private SearchPagination myFilePagination;
GuiButton bestButton = new GuiButton(GuiConstants.CENTER_BEST_BUTTON, 20, 30, "Best Replays");
buttonBar.add(bestButton);
@Override
public void initGui() {
Keyboard.enableRepeatEvents(true);
GuiButton ownReplayButton = new GuiButton(GuiConstants.CENTER_MY_REPLAYS_BUTTON, 20, 30, "My Replays");
ownReplayButton.enabled = AuthenticationHandler.isAuthenticated();
buttonBar.add(ownReplayButton);
if(AuthenticationHandler.isAuthenticated()) {
SearchQuery query = new SearchQuery();
query.auth = AuthenticationHandler.getKey();
query.order = false;
myFilePagination = new SearchPagination(query);
}
GuiButton searchButton = new GuiButton(GuiConstants.CENTER_SEARCH_BUTTON, 20, 30, "Search");
buttonBar.add(searchButton);
//Top Button Bar
List<GuiButton> buttonBar = new ArrayList<GuiButton>();
int i = 0;
for(GuiButton b : buttonBar) {
int w = this.width - 30;
int w2 = w / buttonBar.size();
GuiButton recentButton = new GuiButton(GuiConstants.CENTER_RECENT_BUTTON, 20, 30, "Newest Replays");
buttonBar.add(recentButton);
int x = 15 + (w2 * i);
b.xPosition = x + 2;
b.yPosition = 20;
b.width = w2 - 4;
GuiButton bestButton = new GuiButton(GuiConstants.CENTER_BEST_BUTTON, 20, 30, "Best Replays");
buttonBar.add(bestButton);
buttonList.add(b);
GuiButton ownReplayButton = new GuiButton(GuiConstants.CENTER_MY_REPLAYS_BUTTON, 20, 30, "My Replays");
ownReplayButton.enabled = AuthenticationHandler.isAuthenticated();
buttonBar.add(ownReplayButton);
i++;
}
GuiButton searchButton = new GuiButton(GuiConstants.CENTER_SEARCH_BUTTON, 20, 30, "Search");
buttonBar.add(searchButton);
//Bottom Button Bar (dat alliteration)
List<GuiButton> bottomBar = new ArrayList<GuiButton>();
int i = 0;
for(GuiButton b : buttonBar) {
int w = this.width - 30;
int w2 = w/buttonBar.size();
GuiButton exitButton = new GuiButton(GuiConstants.CENTER_BACK_BUTTON, 20, 20, "Main Menu");
bottomBar.add(exitButton);
int x = 15+(w2*i);
b.xPosition = x+2;
b.yPosition = 20;
b.width = w2-4;
GuiButton managerButton = new GuiButton(GuiConstants.CENTER_MANAGER_BUTTON, 20, 20, "Replay Viewer");
bottomBar.add(managerButton);
buttonList.add(b);
GuiButton logoutButton = new GuiButton(GuiConstants.CENTER_LOGOUT_BUTTON, 20, 20, "Logout");
bottomBar.add(logoutButton);
i++;
}
i = 0;
for(GuiButton b : bottomBar) {
int w = this.width - 30;
int w2 = w / bottomBar.size();
//Bottom Button Bar (dat alliteration)
List<GuiButton> bottomBar = new ArrayList<GuiButton>();
int x = 15 + (w2 * i);
b.xPosition = x + 2;
b.yPosition = height - 30;
b.width = w2 - 4;
GuiButton exitButton = new GuiButton(GuiConstants.CENTER_BACK_BUTTON, 20, 20, "Main Menu");
bottomBar.add(exitButton);
buttonList.add(b);
GuiButton managerButton = new GuiButton(GuiConstants.CENTER_MANAGER_BUTTON, 20, 20, "Replay Viewer");
bottomBar.add(managerButton);
i++;
}
GuiButton logoutButton = new GuiButton(GuiConstants.CENTER_LOGOUT_BUTTON, 20, 20, "Logout");
bottomBar.add(logoutButton);
showOnlineRecent();
}
i = 0;
for(GuiButton b : bottomBar) {
int w = this.width - 30;
int w2 = w/bottomBar.size();
@Override
protected void actionPerformed(GuiButton button) throws java.io.IOException {
if(!button.enabled) return;
if(button.id == GuiConstants.CENTER_BACK_BUTTON) {
mc.displayGuiScreen(new GuiMainMenu());
} else if(button.id == GuiConstants.CENTER_LOGOUT_BUTTON) {
mc.displayGuiScreen(getYesNoGui(this, LOGOUT_CALLBACK_ID));
} else if(button.id == GuiConstants.CENTER_MANAGER_BUTTON) {
mc.displayGuiScreen(new GuiReplayViewer());
} else if(button.id == GuiConstants.CENTER_RECENT_BUTTON) {
showOnlineRecent();
} else if(button.id == GuiConstants.CENTER_BEST_BUTTON) {
showOnlineBest();
} else if(button.id == GuiConstants.CENTER_MY_REPLAYS_BUTTON) {
showOnlineOwnFiles();
} else if(button.id == GuiConstants.CENTER_SEARCH_BUTTON) {
int x = 15+(w2*i);
b.xPosition = x+2;
b.yPosition = height-30;
b.width = w2-4;
}
}
buttonList.add(b);
@Override
public void confirmClicked(boolean result, int id) {
if(id == LOGOUT_CALLBACK_ID) {
if(result) {
mc.addScheduledTask(new Runnable() {
@Override
public void run() {
AuthenticationHandler.logout();
mc.displayGuiScreen(new GuiMainMenu());
}
});
} else {
mc.displayGuiScreen(this);
}
}
}
i++;
}
@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
this.drawDefaultBackground();
this.drawCenteredString(fontRendererObj, "Replay Center", this.width / 2, 8, Color.WHITE.getRGB());
showOnlineRecent();
}
if(currentList != null) {
currentList.drawScreen(mouseX, mouseY, partialTicks);
}
@Override
protected void actionPerformed(GuiButton button) throws java.io.IOException {
if(!button.enabled) return;
if(button.id == GuiConstants.CENTER_BACK_BUTTON) {
mc.displayGuiScreen(new GuiMainMenu());
} else if(button.id == GuiConstants.CENTER_LOGOUT_BUTTON) {
mc.displayGuiScreen(getYesNoGui(this, LOGOUT_CALLBACK_ID));
} else if(button.id == GuiConstants.CENTER_MANAGER_BUTTON) {
mc.displayGuiScreen(new GuiReplayViewer());
} else if(button.id == GuiConstants.CENTER_RECENT_BUTTON) {
showOnlineRecent();
} else if(button.id == GuiConstants.CENTER_BEST_BUTTON) {
showOnlineBest();
} else if(button.id == GuiConstants.CENTER_MY_REPLAYS_BUTTON) {
showOnlineOwnFiles();
} else if(button.id == GuiConstants.CENTER_SEARCH_BUTTON) {
super.drawScreen(mouseX, mouseY, partialTicks);
}
}
}
@Override
public void handleMouseInput() throws IOException {
super.handleMouseInput();
if(currentList != null) {
this.currentList.handleMouseInput();
}
}
private static final int LOGOUT_CALLBACK_ID = 1;
@Override
public void confirmClicked(boolean result, int id) {
if(id == LOGOUT_CALLBACK_ID) {
if(result) {
mc.addScheduledTask(new Runnable() {
@Override
public void run() {
AuthenticationHandler.logout();
mc.displayGuiScreen(new GuiMainMenu());
}
});
} else {
mc.displayGuiScreen(this);
}
}
}
@Override
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException {
super.mouseClicked(mouseX, mouseY, mouseButton);
if(currentList != null) {
this.currentList.mouseClicked(mouseX, mouseY, mouseButton);
}
}
public static GuiYesNo getYesNoGui(GuiYesNoCallback p_152129_0_, int p_152129_2_) {
String s1 = I18n.format("Do you really want to log out?", new Object[0]);
GuiYesNo guiyesno = new GuiYesNo(p_152129_0_, s1, "", "Logout", "Cancel", p_152129_2_);
return guiyesno;
}
@Override
protected void mouseReleased(int mouseX, int mouseY, int state) {
super.mouseReleased(mouseX, mouseY, state);
if(currentList != null) {
this.currentList.mouseReleased(mouseX, mouseY, state);
}
}
@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
this.drawDefaultBackground();
this.drawCenteredString(fontRendererObj, "Replay Center", this.width/2, 8, Color.WHITE.getRGB());
@Override
public void onGuiClosed() {
Keyboard.enableRepeatEvents(false);
}
if(currentList != null) {
currentList.drawScreen(mouseX, mouseY, partialTicks);
}
private void updateCurrentList(ReplayFileList list, SearchPagination pagination) {
currentList = list;
if(currentList == null) {
currentList = new ReplayFileList(mc, width, height, 50, height - 40, 36);
} else {
currentList.clearEntries();
currentList.width = width;
currentList.height = height;
currentList.top = 50;
currentList.bottom = height - 40;
}
super.drawScreen(mouseX, mouseY, partialTicks);
}
if(pagination.getLoadedPages() < 0) {
pagination.fetchPage();
}
@Override
public void handleMouseInput() throws IOException {
super.handleMouseInput();
if(currentList != null) {
this.currentList.handleMouseInput();
}
}
for(FileInfo i : pagination.getFiles()) {
try {
File tmp = null;
if(i.hasThumbnail()) {
tmp = File.createTempFile("thumb_online_" + i.getId(), "jpg");
ReplayMod.apiClient.downloadThumbnail(i.getId(), tmp);
}
currentList.addEntry(i, tmp);
} catch(Exception e) {
e.printStackTrace();
}
}
}
@Override
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException {
super.mouseClicked(mouseX, mouseY, mouseButton);
if(currentList != null) {
this.currentList.mouseClicked(mouseX, mouseY, mouseButton);
}
}
public void showOnlineRecent() {
Thread t = new Thread(new Runnable() {
@Override
public void run() {
updateCurrentList(recentFileList, recentFilePagination);
currentTab = Tab.RECENT_FILES;
}
});
t.start();
}
@Override
protected void mouseReleased(int mouseX, int mouseY, int state) {
super.mouseReleased(mouseX, mouseY, state);
if(currentList != null) {
this.currentList.mouseReleased(mouseX, mouseY, state);
}
}
public void showOnlineBest() {
Thread t = new Thread(new Runnable() {
@Override
public void run() {
updateCurrentList(bestFileList, bestFilePagination);
currentTab = Tab.BEST_FILES;
}
});
t.start();
}
@Override
public void onGuiClosed() {
Keyboard.enableRepeatEvents(false);
}
public void showOnlineOwnFiles() {
if(!AuthenticationHandler.isAuthenticated() || myFilePagination == null) return;
Thread t = new Thread(new Runnable() {
@Override
public void run() {
updateCurrentList(myFileList, myFilePagination);
currentTab = Tab.MY_FILES;
}
});
t.start();
}
private void updateCurrentList(ReplayFileList list, SearchPagination pagination) {
currentList = list;
if(currentList == null) {
currentList = new ReplayFileList(mc, width, height, 50, height-40, 36);
} else {
currentList.clearEntries();
currentList.width = width;
currentList.height = height;
currentList.top = 50;
currentList.bottom = height-40;
}
if(pagination.getLoadedPages() < 0) {
pagination.fetchPage();
}
for(FileInfo i : pagination.getFiles()) {
try {
File tmp = null;
if(i.hasThumbnail()) {
tmp = File.createTempFile("thumb_online_"+i.getId(), "jpg");
ReplayMod.apiClient.downloadThumbnail(i.getId(), tmp);
}
currentList.addEntry(i, tmp);
} catch(Exception e) {
e.printStackTrace();
}
}
}
public void showOnlineRecent() {
Thread t = new Thread(new Runnable() {
@Override
public void run() {
updateCurrentList(recentFileList, recentFilePagination);
currentTab = Tab.RECENT_FILES;
}
});
t.start();
}
public void showOnlineBest() {
Thread t = new Thread(new Runnable() {
@Override
public void run() {
updateCurrentList(bestFileList, bestFilePagination);
currentTab = Tab.BEST_FILES;
}
});
t.start();
}
public void showOnlineOwnFiles() {
if(!AuthenticationHandler.isAuthenticated() || myFilePagination == null) return;
Thread t = new Thread(new Runnable() {
@Override
public void run() {
updateCurrentList(myFileList, myFilePagination);
currentTab = Tab.MY_FILES;
}
});
t.start();
}
private enum Tab {
RECENT_FILES, BEST_FILES, MY_FILES, SEARCH;
}
}

View File

@@ -1,36 +1,6 @@
package eu.crushedpixel.replaymod.gui.online;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.image.BufferedImage;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.regex.Pattern;
import javax.imageio.ImageIO;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiMainMenu;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.GuiTextField;
import net.minecraft.client.renderer.texture.DynamicTexture;
import net.minecraft.util.ResourceLocation;
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
import org.apache.commons.compress.archivers.zip.ZipFile;
import org.apache.commons.io.FilenameUtils;
import org.lwjgl.input.Keyboard;
import com.google.gson.Gson;
import eu.crushedpixel.replaymod.api.client.ApiException;
import eu.crushedpixel.replaymod.api.client.FileUploader;
import eu.crushedpixel.replaymod.api.client.holders.Category;
@@ -42,361 +12,374 @@ import eu.crushedpixel.replaymod.recording.ReplayMetaData;
import eu.crushedpixel.replaymod.reflection.MCPNames;
import eu.crushedpixel.replaymod.utils.ImageUtils;
import eu.crushedpixel.replaymod.utils.ResourceHelper;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.GuiTextField;
import net.minecraft.client.renderer.texture.DynamicTexture;
import net.minecraft.util.ResourceLocation;
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
import org.apache.commons.compress.archivers.zip.ZipFile;
import org.apache.commons.io.FilenameUtils;
import org.lwjgl.input.Keyboard;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.regex.Pattern;
public class GuiUploadFile extends GuiScreen {
private GuiTextField fileTitleInput, tagInput, messageTextField, tagPlaceholder;
private GuiButton categoryButton, startUploadButton, cancelUploadButton, backButton;
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 ResourceLocation textureResource;
private GuiTextField fileTitleInput, tagInput, messageTextField, tagPlaceholder;
private GuiButton categoryButton, startUploadButton, cancelUploadButton, backButton;
private Gson gson = new Gson();
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 Gson gson = new Gson();
public GuiUploadFile(File file, GuiReplayViewer parent) {
this.parent = parent;
private File replayFile;
private ReplayMetaData metaData;
private BufferedImage thumb;
this.textureResource = new ResourceLocation("upload_thumbs/" + FilenameUtils.getBaseName(file.getAbsolutePath()));
dynTex = null;
private FileUploader uploader = new FileUploader();
boolean correctFile = false;
this.replayFile = file;
private Category category = Category.MINIGAME;
if(("." + FilenameUtils.getExtension(file.getAbsolutePath())).equals(ConnectionEventHandler.ZIP_FILE_EXTENSION)) {
ZipFile archive = null;
try {
archive = new ZipFile(file);
ZipArchiveEntry recfile = archive.getEntry("recording" + ConnectionEventHandler.TEMP_FILE_EXTENSION);
ZipArchiveEntry metadata = archive.getEntry("metaData" + ConnectionEventHandler.JSON_FILE_EXTENSION);
private final ResourceLocation textureResource;
private DynamicTexture dynTex = null;
ZipArchiveEntry image = archive.getEntry("thumb");
BufferedImage img = null;
if(image != null) {
InputStream is = archive.getInputStream(image);
is.skip(7);
BufferedImage bimg = ImageIO.read(is);
if(bimg != null) {
thumb = ImageUtils.scaleImage(bimg, new Dimension(1280, 720));
}
}
private Minecraft mc = Minecraft.getMinecraft();
InputStream is = archive.getInputStream(metadata);
BufferedReader br = new BufferedReader(new InputStreamReader(is));
String json = br.readLine();
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);
metaData = gson.fromJson(json, ReplayMetaData.class);
private GuiReplayViewer parent;
public GuiUploadFile(File file, GuiReplayViewer parent) {
this.parent = parent;
this.textureResource = new ResourceLocation("upload_thumbs/"+FilenameUtils.getBaseName(file.getAbsolutePath()));
dynTex = null;
archive.close();
correctFile = true;
} catch(Exception e) {
e.printStackTrace();
} finally {
if(archive != null) {
try {
archive.close();
} catch(IOException e) {
}
}
}
}
boolean correctFile = false;
this.replayFile = file;
if(!correctFile) {
System.out.println("Invalid file provided to upload");
mc.displayGuiScreen(parent); //TODO: Error message
replayFile = null;
return;
}
if(("."+FilenameUtils.getExtension(file.getAbsolutePath())).equals(ConnectionEventHandler.ZIP_FILE_EXTENSION)) {
ZipFile archive = null;
try {
archive = new ZipFile(file);
ZipArchiveEntry recfile = archive.getEntry("recording"+ConnectionEventHandler.TEMP_FILE_EXTENSION);
ZipArchiveEntry metadata = archive.getEntry("metaData"+ConnectionEventHandler.JSON_FILE_EXTENSION);
//If thumb is null, set image to placeholder
if(thumb == null) {
try {
thumb = ImageIO.read(MCPNames.class.getClassLoader().getResourceAsStream("default_thumb.jpg"));
} catch(Exception e) {
e.printStackTrace();
}
}
}
ZipArchiveEntry image = archive.getEntry("thumb");
BufferedImage img = null;
if(image != null) {
InputStream is = archive.getInputStream(image);
is.skip(7);
BufferedImage bimg = ImageIO.read(is);
if(bimg != null) {
thumb = ImageUtils.scaleImage(bimg, new Dimension(1280, 720));
}
}
@Override
public void initGui() {
if(replayFile == null) return;
InputStream is = archive.getInputStream(metadata);
BufferedReader br = new BufferedReader(new InputStreamReader(is));
String json = br.readLine();
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.yPosition = 21;
fileTitleInput.width = Math.min(200, this.width - 20 - 260);
//fileTitleInput.height = 20;
}
metaData = gson.fromJson(json, ReplayMetaData.class);
if(categoryButton == null) {
categoryButton = new GuiButton(GuiConstants.UPLOAD_CATEGORY_BUTTON, (this.width / 2) + 20 + 10 - 1, 80, "Category: " + category.toNiceString());
categoryButton.width = Math.min(202, this.width - 20 - 260 + 2);
buttonList.add(categoryButton);
} else {
categoryButton.xPosition = (this.width / 2) + 20 + 10 - 1;
}
archive.close();
correctFile = true;
} catch(Exception e) {
e.printStackTrace();
} finally {
if(archive != null) {
try {
archive.close();
} catch (IOException e) {}
}
}
}
if(startUploadButton == null) {
List<GuiButton> bottomBar = new ArrayList<GuiButton>();
startUploadButton = new GuiButton(GuiConstants.UPLOAD_START_BUTTON, 0, 0, "Start Upload");
bottomBar.add(startUploadButton);
if(!correctFile) {
System.out.println("Invalid file provided to upload");
mc.displayGuiScreen(parent); //TODO: Error message
replayFile = null;
return;
}
cancelUploadButton = new GuiButton(GuiConstants.UPLOAD_CANCEL_BUTTON, 0, 0, "Cancel Upload");
cancelUploadButton.enabled = false;
bottomBar.add(cancelUploadButton);
//If thumb is null, set image to placeholder
if(thumb == null) {
try {
thumb = ImageIO.read(MCPNames.class.getClassLoader().getResourceAsStream("default_thumb.jpg"));
} catch(Exception e) {
e.printStackTrace();
}
}
}
backButton = new GuiButton(GuiConstants.UPLOAD_BACK_BUTTON, 0, 0, "Back");
bottomBar.add(backButton);
@Override
public void initGui() {
if(replayFile == null) return;
int i = 0;
for(GuiButton b : bottomBar) {
int w = this.width - 30;
int w2 = w / bottomBar.size();
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.yPosition = 21;
fileTitleInput.width = Math.min(200, this.width-20-260);
//fileTitleInput.height = 20;
}
int x = 15 + (w2 * i);
b.xPosition = x + 2;
b.yPosition = height - 30;
b.width = w2 - 4;
if(categoryButton == null) {
categoryButton = new GuiButton(GuiConstants.UPLOAD_CATEGORY_BUTTON, (this.width/2)+20+10-1, 80, "Category: "+category.toNiceString());
categoryButton.width = Math.min(202, this.width-20-260+2);
buttonList.add(categoryButton);
} else {
categoryButton.xPosition = (this.width/2)+20+10-1;
}
buttonList.add(b);
if(startUploadButton == null) {
List<GuiButton> bottomBar = new ArrayList<GuiButton>();
startUploadButton = new GuiButton(GuiConstants.UPLOAD_START_BUTTON, 0, 0, "Start Upload");
bottomBar.add(startUploadButton);
i++;
}
} else {
List<GuiButton> bottomBar = new ArrayList<GuiButton>();
cancelUploadButton = new GuiButton(GuiConstants.UPLOAD_CANCEL_BUTTON, 0, 0, "Cancel Upload");
cancelUploadButton.enabled = false;
bottomBar.add(cancelUploadButton);
bottomBar.add(startUploadButton);
bottomBar.add(cancelUploadButton);
bottomBar.add(backButton);
backButton = new GuiButton(GuiConstants.UPLOAD_BACK_BUTTON, 0, 0, "Back");
bottomBar.add(backButton);
int i = 0;
for(GuiButton b : bottomBar) {
int w = this.width - 30;
int w2 = w / bottomBar.size();
int i = 0;
for(GuiButton b : bottomBar) {
int w = this.width - 30;
int w2 = w/bottomBar.size();
int x = 15 + (w2 * i);
b.xPosition = x + 2;
b.yPosition = height - 30;
b.width = w2 - 4;
int x = 15+(w2*i);
b.xPosition = x+2;
b.yPosition = height-30;
b.width = w2-4;
buttonList.add(b);
buttonList.add(b);
i++;
}
}
i++;
}
} else {
List<GuiButton> bottomBar = new ArrayList<GuiButton>();
if(messageTextField == null) {
messageTextField = new GuiTextField(GuiConstants.UPLOAD_INFO_FIELD, fontRendererObj, 20, height - 80, width - 40, 20);
messageTextField.setEnabled(true);
messageTextField.setFocused(false);
messageTextField.setMaxStringLength(Integer.MAX_VALUE);
} else {
messageTextField.yPosition = height - 80;
messageTextField.width = width - 40;
}
bottomBar.add(startUploadButton);
bottomBar.add(cancelUploadButton);
bottomBar.add(backButton);
if(tagInput == null) {
tagInput = new GuiTextField(GuiConstants.UPLOAD_TAG_INPUT, fontRendererObj, (this.width / 2) + 20 + 10, 110, 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);
}
int i = 0;
for(GuiButton b : bottomBar) {
int w = this.width - 30;
int w2 = w/bottomBar.size();
if(tagPlaceholder == null) {
tagPlaceholder = new GuiTextField(GuiConstants.UPLOAD_TAG_PLACEHOLDER, fontRendererObj, (this.width / 2) + 20 + 10, 110, Math.min(200, this.width - 20 - 260), 20);
tagPlaceholder.setTextColor(Color.DARK_GRAY.getRGB());
tagPlaceholder.setText("Tags separated by comma");
} else {
tagPlaceholder.xPosition = (this.width / 2) + 20 + 10;
tagPlaceholder.width = Math.min(200, this.width - 20 - 260);
}
int x = 15+(w2*i);
b.xPosition = x+2;
b.yPosition = height-30;
b.width = w2-4;
validateStartButton();
}
buttonList.add(b);
@Override
protected void actionPerformed(GuiButton button) throws IOException {
if(!button.enabled) return;
if(button.id == GuiConstants.UPLOAD_CATEGORY_BUTTON) {
category = category.next();
categoryButton.displayString = "Category: " + category.toNiceString();
} else if(button.id == GuiConstants.UPLOAD_BACK_BUTTON) {
mc.displayGuiScreen(parent);
} else if(button.id == GuiConstants.UPLOAD_START_BUTTON) {
final String name = fileTitleInput.getText().trim();
new Thread(new Runnable() {
@Override
public void run() {
try {
String tagsRaw = tagInput.getText();
String[] split = tagsRaw.split(",");
List<String> tags = new ArrayList<String>();
for(String str : split) {
if(!tags.contains(str) && str.length() > 0) {
tags.add(str);
}
}
uploader.uploadFile(GuiUploadFile.this, AuthenticationHandler.getKey(), name, tags, replayFile, category);
} catch(ApiException e) { //TODO: Error handling
e.printStackTrace();
//mc.displayGuiScreen(new GuiMainMenu());
} catch(RuntimeException e) {
e.printStackTrace();
//mc.displayGuiScreen(new GuiMainMenu());
} catch(IOException e) {
e.printStackTrace();
}
}
}).start();
} else if(button.id == GuiConstants.UPLOAD_CANCEL_BUTTON) {
uploader.cancelUploading();
}
}
i++;
}
}
@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
this.drawDefaultBackground();
if(messageTextField == null) {
messageTextField = new GuiTextField(GuiConstants.UPLOAD_INFO_FIELD, fontRendererObj, 20, height-80, width-40, 20);
messageTextField.setEnabled(true);
messageTextField.setFocused(false);
messageTextField.setMaxStringLength(Integer.MAX_VALUE);
} else {
messageTextField.yPosition = height-80;
messageTextField.width = width-40;
}
drawString(fontRendererObj, metaData.getServerName(), (this.width / 2) + 20 + 10, 50, Color.GRAY.getRGB());
drawString(fontRendererObj, "Duration: " + String.format("%02dm%02ds",
TimeUnit.MILLISECONDS.toMinutes(metaData.getDuration()),
TimeUnit.MILLISECONDS.toSeconds(metaData.getDuration()) -
TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(metaData.getDuration()))
), (this.width / 2) + 20 + 10, 65, Color.GRAY.getRGB());
if(tagInput == null) {
tagInput = new GuiTextField(GuiConstants.UPLOAD_TAG_INPUT, fontRendererObj, (this.width/2)+20+10, 110, 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);
}
drawCenteredString(fontRendererObj, "Upload File", this.width / 2, 5, Color.WHITE.getRGB());
if(tagPlaceholder == null) {
tagPlaceholder = new GuiTextField(GuiConstants.UPLOAD_TAG_PLACEHOLDER, fontRendererObj, (this.width/2)+20+10, 110, Math.min(200, this.width-20-260), 20);
tagPlaceholder.setTextColor(Color.DARK_GRAY.getRGB());
tagPlaceholder.setText("Tags separated by comma");
} else {
tagPlaceholder.xPosition = (this.width/2)+20+10;
tagPlaceholder.width = Math.min(200, this.width-20-260);
}
//Draw thumbnail
if(thumb != null) {
if(dynTex == null) {
dynTex = new DynamicTexture(thumb);
mc.getTextureManager().loadTexture(textureResource, dynTex);
dynTex.updateDynamicTexture();
ResourceHelper.registerResource(textureResource);
}
validateStartButton();
}
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);
}
@Override
protected void actionPerformed(GuiButton button) throws IOException {
if(!button.enabled) return;
if(button.id == GuiConstants.UPLOAD_CATEGORY_BUTTON) {
category = category.next();
categoryButton.displayString = "Category: "+category.toNiceString();
} else if(button.id == GuiConstants.UPLOAD_BACK_BUTTON) {
mc.displayGuiScreen(parent);
} else if(button.id == GuiConstants.UPLOAD_START_BUTTON) {
final String name = fileTitleInput.getText().trim();
new Thread(new Runnable() {
@Override
public void run() {
try {
String tagsRaw = tagInput.getText();
String[] split = tagsRaw.split(",");
List<String> tags = new ArrayList<String>();
for(String str : split) {
if(!tags.contains(str) && str.length() > 0) {
tags.add(str);
}
}
uploader.uploadFile(GuiUploadFile.this, AuthenticationHandler.getKey(), name, tags, replayFile, category);
} catch (ApiException e) { //TODO: Error handling
e.printStackTrace();
//mc.displayGuiScreen(new GuiMainMenu());
} catch (RuntimeException e) {
e.printStackTrace();
//mc.displayGuiScreen(new GuiMainMenu());
} catch (IOException e) {
e.printStackTrace();
}
}
}).start();
} else if(button.id == GuiConstants.UPLOAD_CANCEL_BUTTON) {
uploader.cancelUploading();
}
}
fileTitleInput.drawTextBox();
messageTextField.drawTextBox();
@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
this.drawDefaultBackground();
if(tagInput.getText().length() > 0 || tagInput.isFocused()) {
tagInput.drawTextBox();
} else {
tagPlaceholder.drawTextBox();
}
drawString(fontRendererObj, metaData.getServerName(), (this.width/2)+20+10, 50, Color.GRAY.getRGB());
drawString(fontRendererObj, "Duration: "+String.format("%02dm%02ds",
TimeUnit.MILLISECONDS.toMinutes(metaData.getDuration()),
TimeUnit.MILLISECONDS.toSeconds(metaData.getDuration()) -
TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(metaData.getDuration()))
), (this.width/2)+20+10, 65, Color.GRAY.getRGB());
super.drawScreen(mouseX, mouseY, partialTicks);
drawCenteredString(fontRendererObj, "Upload File", this.width/2, 5, Color.WHITE.getRGB());
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());
//Draw thumbnail
if(thumb != null) {
if(dynTex == null) {
dynTex = new DynamicTexture(thumb);
mc.getTextureManager().loadTexture(textureResource, dynTex);
dynTex.updateDynamicTexture();
ResourceHelper.registerResource(textureResource);
}
int width = this.width - 21 - 21;
float prog = uploader.getUploadProgress();
float w = width * prog;
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);
}
this.drawRect(21, this.height - 50, Math.round(21 + w), this.height - 39, Color.RED.getRGB());
fileTitleInput.drawTextBox();
messageTextField.drawTextBox();
String perc = (int) Math.floor(prog * 100) + "%";
fontRendererObj.drawString(perc, this.width / 2 - fontRendererObj.getStringWidth(perc) / 2, this.height - 48, Color.BLACK.getRGB());
}
if(tagInput.getText().length() > 0 || tagInput.isFocused()) {
tagInput.drawTextBox();
} else {
tagPlaceholder.drawTextBox();
}
@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);
}
super.drawScreen(mouseX, mouseY, partialTicks);
@Override
public void updateScreen() {
fileTitleInput.updateCursorCounter();
tagInput.updateCursorCounter();
}
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());
@Override
public void onGuiClosed() {
Keyboard.enableRepeatEvents(false);
}
int width = this.width-21 - 21;
float prog = uploader.getUploadProgress();
float w = width*prog;
@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);
}
this.drawRect(21, this.height-50, Math.round(21+w), this.height-39, Color.RED.getRGB());
if(uploader.isUploading()) {
startUploadButton.enabled = false;
} else {
validateStartButton();
}
}
String perc = (int)Math.floor(prog*100)+"%";
fontRendererObj.drawString(perc, this.width/2 - fontRendererObj.getStringWidth(perc)/2, this.height-48, Color.BLACK.getRGB());
}
private void validateStartButton() {
boolean enabled = true;
if(fileTitleInput.getText().trim().length() < 5 || fileTitleInput.getText().trim().length() > 30) {
enabled = false;
} else if(p.matcher(fileTitleInput.getText()).find()) {
enabled = false;
fileTitleInput.setTextColor(Color.RED.getRGB());
} else if(pt.matcher(tagInput.getText()).find()) {
enabled = false;
tagInput.setTextColor(Color.RED.getRGB());
} else {
fileTitleInput.setTextColor(Color.WHITE.getRGB());
tagInput.setTextColor(Color.WHITE.getRGB());
}
startUploadButton.enabled = enabled;
}
@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);
}
public void onStartUploading() {
startUploadButton.enabled = false;
cancelUploadButton.enabled = true;
backButton.enabled = false;
categoryButton.enabled = false;
fileTitleInput.setEnabled(false);
messageTextField.setText("Uploading...");
messageTextField.setTextColor(Color.WHITE.getRGB());
}
@Override
public void updateScreen() {
fileTitleInput.updateCursorCounter();
tagInput.updateCursorCounter();
}
@Override
public void onGuiClosed() {
Keyboard.enableRepeatEvents(false);
}
@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);
}
if(uploader.isUploading()) {
startUploadButton.enabled = false;
} else {
validateStartButton();
}
}
private void validateStartButton() {
boolean enabled = true;
if(fileTitleInput.getText().trim().length() < 5 || fileTitleInput.getText().trim().length() > 30) {
enabled = false;
} else if(p.matcher(fileTitleInput.getText()).find()) {
enabled = false;
fileTitleInput.setTextColor(Color.RED.getRGB());
} else if(pt.matcher(tagInput.getText()).find()) {
enabled = false;
tagInput.setTextColor(Color.RED.getRGB());
} else {
fileTitleInput.setTextColor(Color.WHITE.getRGB());
tagInput.setTextColor(Color.WHITE.getRGB());
}
startUploadButton.enabled = enabled;
}
public void onStartUploading() {
startUploadButton.enabled = false;
cancelUploadButton.enabled = true;
backButton.enabled = false;
categoryButton.enabled = false;
fileTitleInput.setEnabled(false);
messageTextField.setText("Uploading...");
messageTextField.setTextColor(Color.WHITE.getRGB());
}
public void onFinishUploading(boolean success, String info) {
validateStartButton();
cancelUploadButton.enabled = false;
backButton.enabled = true;
categoryButton.enabled = true;
fileTitleInput.setEnabled(true);
if(success) {
messageTextField.setText("File has been successfully uploaded");
messageTextField.setTextColor(Color.GREEN.getRGB());
} else {
messageTextField.setText(info);
messageTextField.setTextColor(Color.RED.getRGB());
}
}
public void onFinishUploading(boolean success, String info) {
validateStartButton();
cancelUploadButton.enabled = false;
backButton.enabled = true;
categoryButton.enabled = true;
fileTitleInput.setEnabled(true);
if(success) {
messageTextField.setText("File has been successfully uploaded");
messageTextField.setTextColor(Color.GREEN.getRGB());
} else {
messageTextField.setText(info);
messageTextField.setTextColor(Color.RED.getRGB());
}
}
}

View File

@@ -1,12 +1,12 @@
package eu.crushedpixel.replaymod.gui.online;
import net.minecraft.client.Minecraft;
import eu.crushedpixel.replaymod.gui.elements.GuiReplayListExtended;
import net.minecraft.client.Minecraft;
public class ReplayFileList extends GuiReplayListExtended {
public ReplayFileList(Minecraft mcIn, int p_i45010_2_, int p_i45010_3_,
int p_i45010_4_, int p_i45010_5_, int p_i45010_6_) {
super(mcIn, p_i45010_2_, p_i45010_3_, p_i45010_4_, p_i45010_5_, p_i45010_6_);
}
public ReplayFileList(Minecraft mcIn, int p_i45010_2_, int p_i45010_3_,
int p_i45010_4_, int p_i45010_5_, int p_i45010_6_) {
super(mcIn, p_i45010_2_, p_i45010_3_, p_i45010_4_, p_i45010_5_, p_i45010_6_);
}
}