Add online (aka ReplayCenter) module
Add localization extra (formally known as LocalizedResourcePack) Add version checker extra
This commit is contained in:
@@ -1,266 +0,0 @@
|
||||
package eu.crushedpixel.replaymod.api;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonParseException;
|
||||
import com.google.gson.JsonParser;
|
||||
import com.mojang.authlib.exceptions.AuthenticationException;
|
||||
import com.replaymod.core.ReplayMod;
|
||||
import eu.crushedpixel.replaymod.api.replay.ReplayModApiMethods;
|
||||
import eu.crushedpixel.replaymod.api.replay.SearchQuery;
|
||||
import eu.crushedpixel.replaymod.api.replay.holders.*;
|
||||
import eu.crushedpixel.replaymod.gui.elements.listeners.ProgressUpdateListener;
|
||||
import eu.crushedpixel.replaymod.online.authentication.AuthenticationHash;
|
||||
import eu.crushedpixel.replaymod.utils.Api;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.util.List;
|
||||
|
||||
public class ApiClient {
|
||||
|
||||
private static final Minecraft mc = Minecraft.getMinecraft();
|
||||
private static final Gson gson = new Gson();
|
||||
private static final JsonParser jsonParser = new JsonParser();
|
||||
|
||||
private final AuthData authData;
|
||||
|
||||
public ApiClient(AuthData authData) {
|
||||
this.authData = authData;
|
||||
}
|
||||
|
||||
public boolean isLoggedIn() {
|
||||
return authData.getUserName() != null && authData.getAuthKey() != null;
|
||||
}
|
||||
|
||||
public String getAuthKey() {
|
||||
return authData.getAuthKey();
|
||||
}
|
||||
|
||||
public void register(String userName, String eMail, String password) throws AuthenticationException, IOException, ApiException {
|
||||
AuthenticationHash authenticationHash = sessionserverJoin();
|
||||
|
||||
QueryBuilder builder = new QueryBuilder(ReplayModApiMethods.register);
|
||||
builder.put("username", userName);
|
||||
builder.put("email", eMail);
|
||||
builder.put("password", password);
|
||||
builder.put("uuid", mc.getSession().getProfile().getId().toString());
|
||||
builder.put("mcusername", authenticationHash.username);
|
||||
builder.put("timelong", authenticationHash.currentTime);
|
||||
builder.put("randomlong", authenticationHash.randomLong);
|
||||
AuthKey auth = invokeAndReturn(builder, AuthKey.class);
|
||||
|
||||
authData.setData(userName, auth.getAuth());
|
||||
}
|
||||
|
||||
public AuthData.AuthResult login(String userName, String password) {
|
||||
try {
|
||||
QueryBuilder builder = new QueryBuilder(ReplayModApiMethods.login);
|
||||
builder.put("user", userName);
|
||||
builder.put("pw", password);
|
||||
builder.put("mod", true);
|
||||
AuthKey result = invokeAndReturn(builder, AuthKey.class);
|
||||
authData.setData(userName, result.getAuth());
|
||||
return AuthData.AuthResult.SUCCESS;
|
||||
} catch(ApiException e) {
|
||||
return AuthData.AuthResult.INVALID_DATA;
|
||||
} catch(Exception e) {
|
||||
return AuthData.AuthResult.IO_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
public AuthData.AuthResult logout() {
|
||||
try {
|
||||
authData.setData(null, null);
|
||||
|
||||
QueryBuilder builder = new QueryBuilder(ReplayModApiMethods.logout);
|
||||
builder.put("auth", authData.getAuthKey());
|
||||
builder.put("mod", true);
|
||||
invokeAndReturn(builder, Success.class);
|
||||
return AuthData.AuthResult.SUCCESS;
|
||||
} catch(ApiException e) {
|
||||
return AuthData.AuthResult.INVALID_DATA;
|
||||
} catch(Exception e) {
|
||||
return AuthData.AuthResult.IO_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
private AuthenticationHash sessionserverJoin() throws AuthenticationException {
|
||||
AuthenticationHash hash = new AuthenticationHash();
|
||||
|
||||
mc.getSessionService().joinServer(
|
||||
mc.getSession().getProfile(), mc.getSession().getToken(), hash.hash);
|
||||
|
||||
return hash;
|
||||
}
|
||||
|
||||
public AuthConfirmation checkAuthkey(String auth) {
|
||||
try {
|
||||
QueryBuilder builder = new QueryBuilder(ReplayModApiMethods.check_authkey);
|
||||
builder.put("auth", auth);
|
||||
return invokeAndReturn(builder, AuthConfirmation.class);
|
||||
} catch(Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public FileInfo[] getFileInfo(List<Integer> ids) throws IOException, ApiException {
|
||||
QueryBuilder builder = new QueryBuilder(ReplayModApiMethods.file_details);
|
||||
builder.put("id", buildListString(ids));
|
||||
return invokeAndReturn(builder, FileInfo[].class);
|
||||
}
|
||||
|
||||
public FileInfo[] searchFiles(SearchQuery query) throws IOException, ApiException {
|
||||
QueryBuilder builder = new QueryBuilder(ReplayModApiMethods.search);
|
||||
return invokeAndReturn(builder.toString() + query.buildQuery(), SearchResult.class).getResults();
|
||||
}
|
||||
|
||||
public String getTranslation(String languageCode) throws IOException, ApiException {
|
||||
QueryBuilder builder = new QueryBuilder(ReplayModApiMethods.get_language);
|
||||
builder.put("language", languageCode);
|
||||
return SimpleApiClient.invokeUrl(builder.toString());
|
||||
}
|
||||
|
||||
public void downloadThumbnail(int file, File target) throws IOException {
|
||||
QueryBuilder builder = new QueryBuilder(ReplayModApiMethods.get_thumbnail);
|
||||
builder.put("id", file);
|
||||
URL url = new URL(builder.toString());
|
||||
FileUtils.copyURLToFile(url, target);
|
||||
}
|
||||
|
||||
private boolean cancelDownload = false;
|
||||
|
||||
public void downloadFile(int file, File target, ProgressUpdateListener listener) throws IOException, ApiException {
|
||||
cancelDownload = false;
|
||||
|
||||
QueryBuilder builder = new QueryBuilder(ReplayModApiMethods.download_file);
|
||||
builder.put("auth", authData.getAuthKey());
|
||||
builder.put("id", file);
|
||||
String url = builder.toString();
|
||||
URL website = new URL(url);
|
||||
HttpURLConnection con = (HttpURLConnection) website.openConnection();
|
||||
|
||||
int fileSize = con.getContentLength();
|
||||
|
||||
InputStream is = con.getInputStream();
|
||||
|
||||
if(con.getResponseCode() == 200) {
|
||||
BufferedInputStream bin = new BufferedInputStream(is);
|
||||
FileOutputStream fout = new FileOutputStream(target);
|
||||
try {
|
||||
final byte data[] = new byte[1024];
|
||||
int count;
|
||||
int read = 0;
|
||||
while ((count = bin.read(data, 0, 1024)) != -1) {
|
||||
if(cancelDownload) {
|
||||
bin.close();
|
||||
fout.close();
|
||||
|
||||
FileUtils.deleteQuietly(target);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
fout.write(data, 0, count);
|
||||
read += count;
|
||||
listener.onProgressChanged((float)(read)/fileSize);
|
||||
}
|
||||
} finally {
|
||||
bin.close();
|
||||
fout.close();
|
||||
}
|
||||
} else {
|
||||
JsonElement element = jsonParser.parse(IOUtils.toString(is));
|
||||
try {
|
||||
ApiError err = gson.fromJson(element, ApiError.class);
|
||||
if(err.getDesc() != null) {
|
||||
throw new ApiException(err);
|
||||
}
|
||||
} catch(JsonParseException e) {
|
||||
throw new ApiException(IOUtils.toString(is));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void cancelDownload() {
|
||||
this.cancelDownload = true;
|
||||
}
|
||||
|
||||
public void rateFile(int file, Rating.RatingType rating) throws IOException, ApiException {
|
||||
QueryBuilder builder = new QueryBuilder(ReplayModApiMethods.rate_file);
|
||||
builder.put("auth", authData.getAuthKey());
|
||||
builder.put("id", file);
|
||||
builder.put("rating", rating.getKey());
|
||||
invokeAndReturn(builder, Success.class);
|
||||
}
|
||||
|
||||
public FileRating[] getRatedFiles() throws IOException, ApiException {
|
||||
QueryBuilder builder = new QueryBuilder(ReplayModApiMethods.get_ratings);
|
||||
builder.put("auth", authData.getAuthKey());
|
||||
|
||||
return invokeAndReturn(builder, RatedFiles.class).getRated();
|
||||
}
|
||||
|
||||
public void favFile(int file, boolean fav) throws IOException, ApiException {
|
||||
QueryBuilder builder = new QueryBuilder(ReplayModApiMethods.fav_file);
|
||||
builder.put("auth", authData.getAuthKey());
|
||||
builder.put("id", file);
|
||||
builder.put("fav", fav);
|
||||
invokeAndReturn(builder, Success.class);
|
||||
}
|
||||
|
||||
public int[] getFavorites() throws IOException, ApiException {
|
||||
QueryBuilder builder = new QueryBuilder(ReplayModApiMethods.get_favorites);
|
||||
builder.put("auth", authData.getAuthKey());
|
||||
|
||||
return invokeAndReturn(builder, Favorites.class).getFavorited();
|
||||
}
|
||||
|
||||
@Api
|
||||
public void removeFile(int file) throws IOException, ApiException {
|
||||
QueryBuilder builder = new QueryBuilder(ReplayModApiMethods.remove_file);
|
||||
builder.put("auth", authData.getAuthKey());
|
||||
builder.put("id", file);
|
||||
invokeAndReturn(builder, Success.class);
|
||||
}
|
||||
|
||||
public boolean isVersionUpToDate(String versionIdentifier) throws IOException, ApiException {
|
||||
//in a development environment, getContainer().getVersion() will return ${version}
|
||||
if(versionIdentifier.equals("${version}")) return true;
|
||||
|
||||
QueryBuilder builder = new QueryBuilder(ReplayModApiMethods.up_to_date);
|
||||
builder.put("version", versionIdentifier);
|
||||
builder.put("minecraft", ReplayMod.getMinecraftVersion());
|
||||
return invokeAndReturn(builder, Success.class).isSuccess();
|
||||
}
|
||||
|
||||
private <T> T invokeAndReturn(QueryBuilder builder, Class<T> classOfT) throws IOException, ApiException {
|
||||
return invokeAndReturn(builder.toString(), classOfT);
|
||||
}
|
||||
|
||||
private <T> T invokeAndReturn(String url, Class<T> classOfT) throws IOException, ApiException {
|
||||
JsonElement ele = GsonApiClient.invokeJson(url);
|
||||
return gson.fromJson(ele, classOfT);
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
private String buildListString(List idList) {
|
||||
if(idList == null) return null;
|
||||
|
||||
String ids = "";
|
||||
Integer x = 0;
|
||||
for(Object id : idList) {
|
||||
x++;
|
||||
ids += id.toString();
|
||||
if(x != idList.size()) {
|
||||
ids += ",";
|
||||
}
|
||||
}
|
||||
|
||||
return ids;
|
||||
}
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
package eu.crushedpixel.replaymod.api;
|
||||
|
||||
import eu.crushedpixel.replaymod.api.replay.holders.ApiError;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class ApiException extends Exception {
|
||||
|
||||
private static final long serialVersionUID = 349073390504232810L;
|
||||
|
||||
private ApiError error;
|
||||
|
||||
public ApiException(ApiError error) {
|
||||
super(error.getTranslatedDesc());
|
||||
this.error = error;
|
||||
}
|
||||
|
||||
public ApiException(String error) {
|
||||
super(error);
|
||||
}
|
||||
|
||||
public ApiError getError() {
|
||||
return error;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
package eu.crushedpixel.replaymod.api;
|
||||
|
||||
/**
|
||||
* Represents a set of persistent authentication data.
|
||||
*/
|
||||
public interface AuthData {
|
||||
/**
|
||||
* Returns the user name of the authenticated user.
|
||||
* @return user name or {@code null} if not logged in
|
||||
*/
|
||||
String getUserName();
|
||||
|
||||
/**
|
||||
* Returns the authentication key of the authenticated user.
|
||||
* @return auth key or {@code null} if not logged in
|
||||
*/
|
||||
String getAuthKey();
|
||||
|
||||
/**
|
||||
* Store the authentication data after login.
|
||||
* @param userName The user name
|
||||
* @param authKey The authentication key
|
||||
*/
|
||||
void setData(String userName, String authKey);
|
||||
|
||||
/**
|
||||
* Result of authentication operations.
|
||||
*/
|
||||
enum AuthResult {
|
||||
/**
|
||||
* The operation succeeded without errors.
|
||||
*/
|
||||
SUCCESS,
|
||||
|
||||
/**
|
||||
* The data provided got rejected due to it being invalid.
|
||||
*/
|
||||
INVALID_DATA,
|
||||
|
||||
/**
|
||||
* Operation could not be performed due to connectivity problems.
|
||||
*/
|
||||
IO_ERROR,
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
package eu.crushedpixel.replaymod.api;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonParser;
|
||||
import org.apache.commons.lang3.StringEscapeUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class GsonApiClient {
|
||||
|
||||
private static final JsonParser parser = new JsonParser();
|
||||
|
||||
public static JsonElement invoke(QueryBuilder query) throws IOException, ApiException {
|
||||
String apiResult = SimpleApiClient.invoke(query);
|
||||
return wrapWithJson(apiResult);
|
||||
}
|
||||
|
||||
public static JsonElement invokeJson(String url) throws IOException, ApiException {
|
||||
String apiResult = StringEscapeUtils.unescapeHtml4(SimpleApiClient.invokeUrl(url).replace(""", "\\\""));
|
||||
return wrapWithJson(apiResult);
|
||||
}
|
||||
|
||||
private static JsonElement wrapWithJson(String apiResult) {
|
||||
return parser.parse(apiResult);
|
||||
}
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
package eu.crushedpixel.replaymod.api;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class QueryBuilder {
|
||||
|
||||
public String apiMethod;
|
||||
public Map<String, String> paramMap;
|
||||
|
||||
public QueryBuilder(String apiMethod) {
|
||||
this.apiMethod = apiMethod;
|
||||
}
|
||||
|
||||
public void put(String key, Object value) {
|
||||
if(key != null && value != null) {
|
||||
if(paramMap == null) {
|
||||
paramMap = new HashMap<String, String>();
|
||||
}
|
||||
paramMap.put(key, value.toString());
|
||||
}
|
||||
}
|
||||
|
||||
public void put(Map<String, Object> paraMap) {
|
||||
if(paraMap == null) return;
|
||||
for(String key : paraMap.keySet()) {
|
||||
put(key, paraMap.get(key));
|
||||
}
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
if(apiMethod == null) throw new IllegalArgumentException("apiMethod may not be null");
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
// build base url
|
||||
sb.append(apiMethod);
|
||||
|
||||
// process parameters
|
||||
try {
|
||||
if(paramMap != null) {
|
||||
boolean first = true;
|
||||
for(String paramName : paramMap.keySet()) {
|
||||
if(first) sb.append("?");
|
||||
if(!first) sb.append("&");
|
||||
first = false;
|
||||
sb.append(paramName);
|
||||
sb.append("=");
|
||||
String value = paramMap.get(paramName);
|
||||
sb.append(URLEncoder.encode(value, "UTF-8"));
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
} catch(UnsupportedEncodingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,123 +0,0 @@
|
||||
package eu.crushedpixel.replaymod.api;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParseException;
|
||||
import com.google.gson.JsonParser;
|
||||
import eu.crushedpixel.replaymod.api.replay.holders.ApiError;
|
||||
import org.apache.commons.io.IOUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.util.Map;
|
||||
|
||||
public class SimpleApiClient {
|
||||
|
||||
private static final JsonParser jsonParser = new JsonParser();
|
||||
private static final Gson gson = new Gson();
|
||||
|
||||
/**
|
||||
* Returns a Json String from the given QueryBuilder
|
||||
*
|
||||
* @param query The QueryBuilder to use
|
||||
* @return A Json String from the API
|
||||
* @throws IOException
|
||||
* @throws ApiException
|
||||
*/
|
||||
public static String invoke(QueryBuilder query) throws IOException, ApiException {
|
||||
return invokeImpl(query.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a Json String from the given URL
|
||||
*
|
||||
* @param url The URL to parse the Json from
|
||||
* @return A Json String from the API
|
||||
* @throws IOException
|
||||
* @throws ApiException
|
||||
*/
|
||||
public static String invokeUrl(String url) throws IOException, ApiException {
|
||||
return invokeImpl(url);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a Json String from the API
|
||||
*
|
||||
* @param method The apiMethod to be called
|
||||
* @param paramMap The parameters to apply
|
||||
* @return A Json String from the API
|
||||
* @throws IOException
|
||||
* @throws ApiException
|
||||
*/
|
||||
public static String invoke(String method, Map<String, Object> paramMap) throws IOException, ApiException {
|
||||
return invokeImpl(method, paramMap);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a Json String from the API
|
||||
*
|
||||
* @param method The apiMethod to be called
|
||||
* @return A Json String from the API
|
||||
* @throws IOException
|
||||
* @throws ApiException
|
||||
*/
|
||||
public static String invoke(String method) throws IOException, ApiException {
|
||||
return invokeImpl(method, null);
|
||||
}
|
||||
|
||||
private static String invokeImpl(String urlString) throws IOException, ApiException {
|
||||
|
||||
// read response
|
||||
String responseContent = null;
|
||||
InputStream is = null;
|
||||
HttpURLConnection httpUrlConnection = null;
|
||||
try {
|
||||
URL url = new URL(urlString);
|
||||
httpUrlConnection = (HttpURLConnection) url.openConnection();
|
||||
|
||||
httpUrlConnection.setRequestMethod("GET");
|
||||
|
||||
// give it 15 seconds to respond
|
||||
httpUrlConnection.setReadTimeout(15 * 1000);
|
||||
httpUrlConnection.connect();
|
||||
|
||||
int responseCode = httpUrlConnection.getResponseCode();
|
||||
|
||||
if(responseCode != 200) {
|
||||
is = httpUrlConnection.getErrorStream();
|
||||
if(is != null) {
|
||||
responseContent = IOUtils.toString(is, "UTF-8");
|
||||
} else {
|
||||
responseContent = "";
|
||||
}
|
||||
try {
|
||||
JsonObject response = jsonParser.parse(responseContent).getAsJsonObject();
|
||||
throw new ApiException(gson.fromJson(response, ApiError.class));
|
||||
} catch(JsonParseException e) {
|
||||
throw new ApiException(responseContent);
|
||||
}
|
||||
}
|
||||
|
||||
is = httpUrlConnection.getInputStream();
|
||||
|
||||
responseContent = IOUtils.toString(is, "UTF-8");
|
||||
|
||||
} finally {
|
||||
if(is != null) {
|
||||
is.close();
|
||||
}
|
||||
if(httpUrlConnection != null) {
|
||||
httpUrlConnection.disconnect();
|
||||
}
|
||||
}
|
||||
return responseContent;
|
||||
}
|
||||
|
||||
private static String invokeImpl(String method, Map<String, Object> paramMap) throws IOException, ApiException {
|
||||
QueryBuilder queryBuilder = new QueryBuilder(method);
|
||||
queryBuilder.put(paramMap);
|
||||
return invokeImpl(queryBuilder.toString());
|
||||
}
|
||||
}
|
||||
@@ -1,155 +0,0 @@
|
||||
package eu.crushedpixel.replaymod.api.replay;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.replaymod.core.ReplayMod;
|
||||
import eu.crushedpixel.replaymod.api.replay.holders.ApiError;
|
||||
import eu.crushedpixel.replaymod.api.replay.holders.Category;
|
||||
import eu.crushedpixel.replaymod.gui.online.GuiUploadFile;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.List;
|
||||
|
||||
public class FileUploader {
|
||||
private static final Gson gson = new Gson();
|
||||
|
||||
private boolean uploading = false;
|
||||
private long filesize;
|
||||
private long current;
|
||||
|
||||
private boolean cancel = false;
|
||||
|
||||
private GuiUploadFile parent;
|
||||
|
||||
public void uploadFile(GuiUploadFile gui, String filename, List<String> tags, File file, Category category, String description) {
|
||||
boolean success = false;
|
||||
String info = null;
|
||||
|
||||
try {
|
||||
parent = gui;
|
||||
gui.onStartUploading();
|
||||
filesize = 0;
|
||||
|
||||
if(uploading) throw new RuntimeException("FileUploader is already uploading");
|
||||
uploading = true;
|
||||
|
||||
String postData = "?auth=" + ReplayMod.apiClient.getAuthKey() + "&category=" + category.getId();
|
||||
|
||||
if(tags.size() > 0) {
|
||||
postData += "&tags=";
|
||||
for(String tag : tags) {
|
||||
postData += tag;
|
||||
if(!tag.equals(tags.get(tags.size() - 1))) {
|
||||
postData += ",";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(description != null && description.length() > 0) {
|
||||
postData += "&description=" + URLEncoder.encode(description, "UTF-8");
|
||||
}
|
||||
|
||||
postData += "&name=" + URLEncoder.encode(filename, "UTF-8");
|
||||
|
||||
String url = ReplayModApiMethods.upload_file + postData;
|
||||
HttpURLConnection con = (HttpURLConnection) new URL(url).openConnection();
|
||||
con.setUseCaches(false);
|
||||
con.setDoOutput(true);
|
||||
con.setRequestMethod("POST");
|
||||
con.setChunkedStreamingMode(1024);
|
||||
con.setRequestProperty("Connection", "Keep-Alive");
|
||||
con.setRequestProperty("Cache-Control", "no-cache");
|
||||
String boundary = "*****";
|
||||
con.setRequestProperty("Content-Type", "multipart/form-data;boundary=" + boundary);
|
||||
|
||||
DataOutputStream request = new DataOutputStream(con.getOutputStream());
|
||||
|
||||
String crlf = "\r\n";
|
||||
String twoHyphens = "--";
|
||||
request.writeBytes(twoHyphens + boundary + crlf);
|
||||
String attachmentName = "file";
|
||||
String attachmentFileName = "file.mcpr";
|
||||
request.writeBytes("Content-Disposition: form-data; name=\"" + attachmentName + "\";filename=\"" + attachmentFileName + "\"" + crlf);
|
||||
request.writeBytes(crlf);
|
||||
|
||||
byte[] buf = new byte[1024];
|
||||
FileInputStream fis = new FileInputStream(file);
|
||||
filesize = fis.getChannel().size();
|
||||
current = 0;
|
||||
int len;
|
||||
while((len = fis.read(buf)) != -1) {
|
||||
request.write(buf);
|
||||
current += len;
|
||||
|
||||
parent.onProgressChanged(getUploadProgress());
|
||||
|
||||
if(cancel) {
|
||||
parent.onProgressChanged(0f);
|
||||
|
||||
uploading = false;
|
||||
current = 0;
|
||||
cancel = false;
|
||||
parent.onFinishUploading(false, I18n.format("replaymod.gui.upload.canceled"));
|
||||
fis.close();
|
||||
return;
|
||||
}
|
||||
}
|
||||
fis.close();
|
||||
|
||||
request.writeBytes(crlf);
|
||||
request.writeBytes(twoHyphens + boundary + twoHyphens + crlf);
|
||||
|
||||
request.flush();
|
||||
request.close();
|
||||
|
||||
success = false;
|
||||
int responseCode = con.getResponseCode();
|
||||
InputStream is;
|
||||
if(responseCode == 200) {
|
||||
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) {
|
||||
ApiError error = gson.fromJson(result, ApiError.class);
|
||||
info = error.getTranslatedDesc();
|
||||
}
|
||||
}
|
||||
con.disconnect();
|
||||
|
||||
if(info == null) info = I18n.format("replaymod.gui.unknownerror");
|
||||
} catch(Exception e) {
|
||||
success = false;
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
parent.onFinishUploading(success, info);
|
||||
uploading = false;
|
||||
}
|
||||
}
|
||||
|
||||
public float getUploadProgress() {
|
||||
if(!uploading || filesize == 0) return 0;
|
||||
return (float) ((double) current / (double) filesize);
|
||||
}
|
||||
|
||||
public boolean isUploading() {
|
||||
return uploading;
|
||||
}
|
||||
|
||||
public void cancelUploading() {
|
||||
cancel = true;
|
||||
}
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
package eu.crushedpixel.replaymod.api.replay;
|
||||
|
||||
public class ReplayModApiMethods {
|
||||
|
||||
public static final String REPLAYMOD_BASE_URL = "http://ReplayMod.com/api/";
|
||||
|
||||
public static final String register = REPLAYMOD_BASE_URL+"register";
|
||||
public static final String check_authkey = REPLAYMOD_BASE_URL+"check_authkey";
|
||||
public static final String login = REPLAYMOD_BASE_URL+"login";
|
||||
public static final String logout = REPLAYMOD_BASE_URL+"logout";
|
||||
public static final String file_details = REPLAYMOD_BASE_URL+"file_details";
|
||||
public static final String upload_file = REPLAYMOD_BASE_URL+"upload_file";
|
||||
public static final String download_file = REPLAYMOD_BASE_URL+"download_file";
|
||||
public static final String get_thumbnail = REPLAYMOD_BASE_URL+"get_thumbnail";
|
||||
public static final String remove_file = REPLAYMOD_BASE_URL+"remove_file";
|
||||
public static final String rate_file = REPLAYMOD_BASE_URL+"rate_file";
|
||||
public static final String get_ratings = REPLAYMOD_BASE_URL+"get_ratings";
|
||||
public static final String fav_file = REPLAYMOD_BASE_URL+"fav_file";
|
||||
public static final String get_favorites = REPLAYMOD_BASE_URL+"get_favorites";
|
||||
public static final String check_auth = REPLAYMOD_BASE_URL+"check_auth";
|
||||
public static final String get_language = REPLAYMOD_BASE_URL+"get_language";
|
||||
public static final String search = REPLAYMOD_BASE_URL+"search";
|
||||
public static final String up_to_date = REPLAYMOD_BASE_URL+"up_to_date";
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
package eu.crushedpixel.replaymod.api.replay;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.net.URLEncoder;
|
||||
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class SearchQuery {
|
||||
|
||||
public Boolean order, singleplayer;
|
||||
public String player, tag, version, server, name, auth;
|
||||
public Integer category, offset;
|
||||
|
||||
public String buildQuery() {
|
||||
String query = "";
|
||||
boolean first = true;
|
||||
|
||||
//Please don't slaughter me for this code,
|
||||
//even if I deserve it, which I certainly do.
|
||||
for(Field f : this.getClass().getDeclaredFields()) {
|
||||
try {
|
||||
Object value = f.get(this);
|
||||
if(value == null) continue;
|
||||
query += first ? "?" : "&";
|
||||
first = false;
|
||||
query += f.getName() + "=";
|
||||
query += URLEncoder.encode(String.valueOf(value), "UTF-8");
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
return query;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return buildQuery();
|
||||
}
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
package eu.crushedpixel.replaymod.api.replay.holders;
|
||||
|
||||
import lombok.Data;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
|
||||
@Data
|
||||
public class ApiError {
|
||||
|
||||
private int id;
|
||||
private String desc;
|
||||
private String key;
|
||||
private String[] objects;
|
||||
|
||||
public String getTranslatedDesc() {
|
||||
try {
|
||||
return I18n.format(key, (Object[]) objects);
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
return desc;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
package eu.crushedpixel.replaymod.api.replay.holders;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class AuthConfirmation {
|
||||
private String username;
|
||||
private int id;
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
package eu.crushedpixel.replaymod.api.replay.holders;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class AuthKey {
|
||||
private String auth;
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
package eu.crushedpixel.replaymod.api.replay.holders;
|
||||
|
||||
import net.minecraft.client.resources.I18n;
|
||||
|
||||
public enum Category {
|
||||
|
||||
SURVIVAL(0, "replaymod.category.survival"), MINIGAME(1, "replaymod.category.minigame"),
|
||||
BUILD(2, "replaymod.category.build"), MISCELLANEOUS(3, "replaymod.category.misc");
|
||||
|
||||
private int id;
|
||||
private String name;
|
||||
|
||||
Category(int id, String name) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public static Category fromId(int id) {
|
||||
for(Category c : values()) {
|
||||
if(c.id == id) return c;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String toNiceString() {
|
||||
return I18n.format(this.name);
|
||||
}
|
||||
|
||||
public Category next() {
|
||||
for(int i = 0; i < values().length; i++) {
|
||||
if(values()[i] == this) {
|
||||
if(i == values().length - 1) {
|
||||
i = -1;
|
||||
}
|
||||
return values()[i + 1];
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public static String[] stringValues() {
|
||||
String[] values = new String[Category.values().length];
|
||||
int i = 0;
|
||||
for (Category c : Category.values()) {
|
||||
values[i++] = c.toNiceString();
|
||||
}
|
||||
return values;
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
package eu.crushedpixel.replaymod.api.replay.holders;
|
||||
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Data;
|
||||
import lombok.Getter;
|
||||
|
||||
@Data
|
||||
public class Donated {
|
||||
|
||||
@Getter(AccessLevel.NONE)
|
||||
private boolean donated = false;
|
||||
|
||||
public boolean hasDonated() {
|
||||
return donated;
|
||||
}
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
package eu.crushedpixel.replaymod.api.replay.holders;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class Favorites {
|
||||
private int[] favorited;
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
package eu.crushedpixel.replaymod.api.replay.holders;
|
||||
|
||||
import de.johni0702.replaystudio.replay.ReplayMetaData;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.Getter;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class FileInfo {
|
||||
private int id;
|
||||
private ReplayMetaData metadata;
|
||||
private String owner;
|
||||
private Rating ratings;
|
||||
private int size;
|
||||
private int category;
|
||||
private int downloads;
|
||||
private String name;
|
||||
@Getter(AccessLevel.NONE)
|
||||
private boolean thumbnail;
|
||||
private int favorites;
|
||||
|
||||
public boolean hasThumbnail() {
|
||||
return thumbnail;
|
||||
}
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
package eu.crushedpixel.replaymod.api.replay.holders;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class FileRating {
|
||||
private int file;
|
||||
@SerializedName("rating") private boolean ratingPositive;
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
package eu.crushedpixel.replaymod.api.replay.holders;
|
||||
|
||||
public enum MinecraftVersion {
|
||||
|
||||
MC_1_8("Minecraft 1.8", "1.8");
|
||||
|
||||
private String niceName, apiName;
|
||||
|
||||
MinecraftVersion(String niceName, String apiName) {
|
||||
this.niceName = niceName;
|
||||
this.apiName = apiName;
|
||||
}
|
||||
|
||||
public String toNiceName() {
|
||||
return niceName;
|
||||
}
|
||||
|
||||
public String getApiName() {
|
||||
return apiName;
|
||||
}
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
package eu.crushedpixel.replaymod.api.replay.holders;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class RatedFiles {
|
||||
private FileRating[] rated;
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
package eu.crushedpixel.replaymod.api.replay.holders;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class Rating {
|
||||
private int negative, positive;
|
||||
|
||||
public enum RatingType {
|
||||
|
||||
LIKE("like"), DISLIKE("dislike"), NEUTRAL("neutral");
|
||||
|
||||
private String key;
|
||||
|
||||
public String getKey() { return key; }
|
||||
|
||||
RatingType(String key) {
|
||||
this.key = key;
|
||||
}
|
||||
|
||||
public static RatingType fromBoolean(Boolean rating) {
|
||||
return rating == null ? RatingType.NEUTRAL :
|
||||
(rating ? RatingType.LIKE : RatingType.DISLIKE);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
package eu.crushedpixel.replaymod.api.replay.holders;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class SearchResult {
|
||||
private FileInfo[] results;
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
package eu.crushedpixel.replaymod.api.replay.holders;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class Success {
|
||||
private boolean success = false;
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
package eu.crushedpixel.replaymod.api.replay.holders;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class UserFiles {
|
||||
private String user;
|
||||
private FileInfo[] files;
|
||||
private int total_size;
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
package eu.crushedpixel.replaymod.api.replay.pagination;
|
||||
|
||||
import com.replaymod.core.ReplayMod;
|
||||
import eu.crushedpixel.replaymod.api.replay.holders.FileInfo;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class DownloadedFilePagination implements Pagination {
|
||||
|
||||
private int page;
|
||||
private HashMap<Integer, FileInfo> files = new HashMap<Integer, FileInfo>();
|
||||
|
||||
public DownloadedFilePagination() {
|
||||
this.page = -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<FileInfo> getFiles() {
|
||||
return new ArrayList<FileInfo>(files.values());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLoadedPages() {
|
||||
return page;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean fetchPage() {
|
||||
page++;
|
||||
|
||||
HashMap<Integer, File> f = ReplayMod.downloadedFileHandler.getDownloadedFiles();
|
||||
List<Integer> toAdd = new ArrayList<Integer>();
|
||||
for(int i : f.keySet()) {
|
||||
if(!files.containsKey(i)) {
|
||||
toAdd.add(i);
|
||||
if(toAdd.size() >= Pagination.PAGE_SIZE) break;
|
||||
}
|
||||
}
|
||||
|
||||
files.keySet().retainAll(f.keySet());
|
||||
|
||||
try {
|
||||
FileInfo[] fis = ReplayMod.apiClient.getFileInfo(toAdd);
|
||||
if(fis.length < 1) {
|
||||
page--;
|
||||
return false;
|
||||
}
|
||||
|
||||
for(FileInfo info : fis) {
|
||||
files.put(info.getId(), info);
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
page--;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
package eu.crushedpixel.replaymod.api.replay.pagination;
|
||||
|
||||
import com.replaymod.core.ReplayMod;
|
||||
import eu.crushedpixel.replaymod.api.replay.holders.FileInfo;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class FavoritedFilePagination implements Pagination {
|
||||
|
||||
private int page;
|
||||
private HashMap<Integer, FileInfo> files = new HashMap<Integer, FileInfo>();
|
||||
|
||||
public FavoritedFilePagination() {
|
||||
this.page = -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<FileInfo> getFiles() {
|
||||
return new ArrayList<FileInfo>(files.values());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLoadedPages() {
|
||||
return page;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean fetchPage() {
|
||||
page++;
|
||||
|
||||
try {
|
||||
List<Integer> f = ReplayMod.favoritedFileHandler.getFavorited();
|
||||
List<Integer> toAdd = new ArrayList<Integer>();
|
||||
for(int i : f) {
|
||||
if(!files.containsKey(i)) {
|
||||
toAdd.add(i);
|
||||
if(toAdd.size() >= Pagination.PAGE_SIZE) break;
|
||||
}
|
||||
}
|
||||
|
||||
FileInfo[] fis = ReplayMod.apiClient.getFileInfo(toAdd);
|
||||
if(fis.length < 1) {
|
||||
page--;
|
||||
return false;
|
||||
}
|
||||
|
||||
for(FileInfo info : fis) {
|
||||
files.put(info.getId(), info);
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
page--;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
package eu.crushedpixel.replaymod.api.replay.pagination;
|
||||
|
||||
import eu.crushedpixel.replaymod.api.replay.holders.FileInfo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface Pagination {
|
||||
List<FileInfo> getFiles();
|
||||
|
||||
int getLoadedPages();
|
||||
|
||||
boolean fetchPage();
|
||||
|
||||
int PAGE_SIZE = 30; //defined by the Website API
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
package eu.crushedpixel.replaymod.api.replay.pagination;
|
||||
|
||||
import com.replaymod.core.ReplayMod;
|
||||
import eu.crushedpixel.replaymod.api.replay.SearchQuery;
|
||||
import eu.crushedpixel.replaymod.api.replay.holders.FileInfo;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class SearchPagination implements Pagination {
|
||||
|
||||
private final SearchQuery searchQuery;
|
||||
private int page;
|
||||
private List<FileInfo> files = new ArrayList<FileInfo>();
|
||||
|
||||
public SearchPagination(SearchQuery searchQuery) {
|
||||
this.page = -1;
|
||||
this.searchQuery = searchQuery;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<FileInfo> getFiles() {
|
||||
return new ArrayList<FileInfo>(files);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLoadedPages() {
|
||||
return page;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean fetchPage() {
|
||||
page++;
|
||||
searchQuery.offset = page;
|
||||
|
||||
try {
|
||||
FileInfo[] fis = ReplayMod.apiClient.searchFiles(searchQuery);
|
||||
if(fis.length < 1) {
|
||||
page--;
|
||||
return false;
|
||||
}
|
||||
|
||||
files.addAll(Arrays.asList(fis));
|
||||
|
||||
return true;
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
page--;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -3,19 +3,15 @@ package eu.crushedpixel.replaymod.events.handlers;
|
||||
import com.replaymod.core.ReplayMod;
|
||||
import com.replaymod.core.gui.GuiReplaySettings;
|
||||
import eu.crushedpixel.replaymod.gui.GuiConstants;
|
||||
import eu.crushedpixel.replaymod.gui.online.GuiLoginPrompt;
|
||||
import eu.crushedpixel.replaymod.gui.online.GuiReplayCenter;
|
||||
import eu.crushedpixel.replaymod.gui.replayeditor.GuiReplayEditor;
|
||||
import eu.crushedpixel.replaymod.settings.ReplaySettings;
|
||||
import eu.crushedpixel.replaymod.studio.VersionValidator;
|
||||
import eu.crushedpixel.replaymod.utils.MouseUtils;
|
||||
import eu.crushedpixel.replaymod.utils.ReplayFileIO;
|
||||
import eu.crushedpixel.replaymod.utils.StringUtils;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.*;
|
||||
import net.minecraft.client.gui.inventory.GuiInventory;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.gui.GuiMainMenu;
|
||||
import net.minecraft.client.gui.GuiOptions;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraftforge.client.event.GuiOpenEvent;
|
||||
import net.minecraftforge.client.event.GuiScreenEvent.ActionPerformedEvent;
|
||||
import net.minecraftforge.client.event.GuiScreenEvent.DrawScreenEvent;
|
||||
import net.minecraftforge.client.event.GuiScreenEvent.InitGuiEvent;
|
||||
@@ -34,71 +30,16 @@ public class GuiEventHandler {
|
||||
public int replayCount = 0;
|
||||
private GuiButton editorButton;
|
||||
|
||||
@SubscribeEvent
|
||||
public void onGui(GuiOpenEvent event) {
|
||||
if(event.gui instanceof GuiMainMenu) {
|
||||
if(ReplayMod.firstMainMenu) {
|
||||
ReplayMod.firstMainMenu = false;
|
||||
if(!ReplayMod.apiClient.isLoggedIn() && ReplaySettings.AdvancedOptions.disableLoginPrompt.getValue() != Boolean.TRUE) {
|
||||
event.gui = new GuiLoginPrompt(event.gui, event.gui, false).toMinecraft();
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
mc.timer.timerSpeed = 1;
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!ReplayMod.apiClient.isLoggedIn()) return;
|
||||
|
||||
if(event.gui instanceof GuiChat || event.gui instanceof GuiInventory) {
|
||||
// TODO
|
||||
// if(ReplayHandler.isInReplay()) {
|
||||
// event.setCanceled(true);
|
||||
// }
|
||||
} else if(event.gui instanceof GuiDisconnected) {
|
||||
// TODO
|
||||
// if(!ReplayHandler.isInReplay() && System.currentTimeMillis() - ReplayHandler.lastExit < 5000) {
|
||||
// event.setCanceled(true);
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onDraw(DrawScreenEvent e) {
|
||||
if(e.gui instanceof GuiMainMenu) {
|
||||
e.gui.drawString(mc.fontRendererObj, I18n.format("replaymod.title")+":", 5, 5, Color.WHITE.getRGB());
|
||||
if(ReplayMod.apiClient.isLoggedIn()) {
|
||||
e.gui.drawString(mc.fontRendererObj, I18n.format("replaymod.gui.loggedin").toUpperCase(), 5, 15, DARK_GREEN.getRGB());
|
||||
} else {
|
||||
e.gui.drawString(mc.fontRendererObj, I18n.format("replaymod.gui.loggedout").toUpperCase(), 5, 15, DARK_RED.getRGB());
|
||||
}
|
||||
|
||||
//if version not up to date, display info string
|
||||
if(!ReplayMod.isLatestModVersion()) {
|
||||
int width = Math.max(100, e.gui.width / 2 - 100 - 10);
|
||||
|
||||
String[] lines = StringUtils.splitStringInMultipleRows(I18n.format("replaymod.gui.outdated"), width);
|
||||
|
||||
int maxLineWidth = 0;
|
||||
for(String line : lines) {
|
||||
int lineWidth = mc.fontRendererObj.getStringWidth(line);
|
||||
if(lineWidth > maxLineWidth) {
|
||||
maxLineWidth = lineWidth;
|
||||
}
|
||||
}
|
||||
|
||||
Gui.drawRect(2, 77, 5+maxLineWidth+3, 80+(lines.length * 10), 0x80FF0000);
|
||||
|
||||
int i = 0;
|
||||
for(String line : lines) {
|
||||
mc.fontRendererObj.drawStringWithShadow(line, 5, 80 + (i * 10), Color.WHITE.getRGB());
|
||||
i++;
|
||||
}
|
||||
}
|
||||
// TODO Do we need this?
|
||||
// e.gui.drawString(mc.fontRendererObj, I18n.format("replaymod.title")+":", 5, 5, Color.WHITE.getRGB());
|
||||
// if(ReplayMod.apiClient.isLoggedIn()) {
|
||||
// e.gui.drawString(mc.fontRendererObj, I18n.format("replaymod.gui.loggedin").toUpperCase(), 5, 15, DARK_GREEN.getRGB());
|
||||
// } else {
|
||||
// e.gui.drawString(mc.fontRendererObj, I18n.format("replaymod.gui.loggedout").toUpperCase(), 5, 15, DARK_RED.getRGB());
|
||||
// }
|
||||
|
||||
if(replayCount == 0) {
|
||||
if(editorButton.isMouseOver()) {
|
||||
@@ -141,10 +82,6 @@ public class GuiEventHandler {
|
||||
|
||||
editorButton = re;
|
||||
|
||||
GuiButton rc = new GuiButton(GuiConstants.REPLAY_CENTER_BUTTON_ID, event.gui.width / 2 - 100, i1 + 3 * 24, I18n.format("replaymod.gui.replaycenter"));
|
||||
rc.enabled = true;
|
||||
buttonList.add(rc);
|
||||
|
||||
} else if(event.gui instanceof GuiOptions) {
|
||||
buttonList.add(new GuiButton(GuiConstants.REPLAY_OPTIONS_BUTTON_ID,
|
||||
event.gui.width / 2 - 155, event.gui.height / 6 + 48 - 6 - 24, 310, 20, I18n.format("replaymod.gui.settings.title")));
|
||||
@@ -155,13 +92,7 @@ public class GuiEventHandler {
|
||||
public void onButton(ActionPerformedEvent event) {
|
||||
if(!event.button.enabled) return;
|
||||
if(event.gui instanceof GuiMainMenu) {
|
||||
if(event.button.id == GuiConstants.REPLAY_CENTER_BUTTON_ID) {
|
||||
if(ReplayMod.apiClient.isLoggedIn()) {
|
||||
mc.displayGuiScreen(new GuiReplayCenter());
|
||||
} else {
|
||||
mc.displayGuiScreen(new GuiLoginPrompt(event.gui, new GuiReplayCenter(), true).toMinecraft());
|
||||
}
|
||||
} else if(event.button.id == GuiConstants.REPLAY_EDITOR_BUTTON_ID) {
|
||||
if(event.button.id == GuiConstants.REPLAY_EDITOR_BUTTON_ID) {
|
||||
mc.displayGuiScreen(new GuiReplayEditor());
|
||||
}
|
||||
} else if(event.gui instanceof GuiOptions && event.button.id == GuiConstants.REPLAY_OPTIONS_BUTTON_ID) {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package eu.crushedpixel.replaymod.gui.elements;
|
||||
|
||||
import com.mojang.realmsclient.gui.ChatFormatting;
|
||||
import eu.crushedpixel.replaymod.api.replay.holders.Category;
|
||||
import eu.crushedpixel.replaymod.api.replay.holders.FileInfo;
|
||||
import com.replaymod.online.api.replay.holders.Category;
|
||||
import com.replaymod.online.api.replay.holders.FileInfo;
|
||||
import eu.crushedpixel.replaymod.registry.ResourceHelper;
|
||||
import eu.crushedpixel.replaymod.utils.DurationUtils;
|
||||
import net.minecraft.client.Minecraft;
|
||||
|
||||
@@ -1,125 +0,0 @@
|
||||
package eu.crushedpixel.replaymod.gui.online;
|
||||
|
||||
import de.johni0702.minecraft.gui.container.AbstractGuiScreen;
|
||||
import de.johni0702.minecraft.gui.element.GuiButton;
|
||||
import de.johni0702.minecraft.gui.element.GuiLabel;
|
||||
import de.johni0702.minecraft.gui.element.GuiPasswordField;
|
||||
import de.johni0702.minecraft.gui.element.GuiTextField;
|
||||
import de.johni0702.minecraft.gui.layout.CustomLayout;
|
||||
import com.replaymod.core.ReplayMod;
|
||||
import eu.crushedpixel.replaymod.gui.GuiConstants;
|
||||
|
||||
public class GuiLoginPrompt extends AbstractGuiScreen<GuiLoginPrompt> {
|
||||
|
||||
private final net.minecraft.client.gui.GuiScreen parent, successScreen;
|
||||
|
||||
private GuiLabel usernameLabel = new GuiLabel(this).setI18nText("replaymod.gui.username");
|
||||
private GuiLabel passwordLabel = new GuiLabel(this).setI18nText("replaymod.gui.password");
|
||||
private GuiLabel noAccountLabel = new GuiLabel(this).setI18nText("replaymod.gui.login.noacc");
|
||||
private GuiLabel statusLabel = new GuiLabel(this);
|
||||
private GuiButton loginButton = new GuiButton(this).setI18nLabel("replaymod.gui.login").setSize(150, 20).setEnabled(false);
|
||||
private GuiButton cancelButton = new GuiButton(this).setI18nLabel("replaymod.gui.cancel").setSize(150, 20);
|
||||
private GuiButton registerButton = new GuiButton(this).setI18nLabel("replaymod.gui.register").setSize(150, 20);
|
||||
private GuiTextField username = new GuiTextField(this).setSize(145, 20).setMaxLength(16).setFocused(true);
|
||||
private GuiPasswordField password = new GuiPasswordField(this).setSize(145, 20).setNext(username).setPrevious(username)
|
||||
.setMaxLength(GuiConstants.MAX_PW_LENGTH);
|
||||
|
||||
{
|
||||
Runnable doLogin = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (!loginButton.isEnabled()) return;
|
||||
statusLabel.setI18nText("replaymod.gui.login.logging");
|
||||
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
switch(ReplayMod.apiClient.login(username.getText(), password.getText())) {
|
||||
case SUCCESS:
|
||||
statusLabel.setText("");
|
||||
getMinecraft().addScheduledTask(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
getMinecraft().displayGuiScreen(successScreen);
|
||||
}
|
||||
});
|
||||
break;
|
||||
case INVALID_DATA:
|
||||
statusLabel.setI18nText("replaymod.gui.login.incorrect");
|
||||
break;
|
||||
case IO_ERROR:
|
||||
statusLabel.setI18nText("replaymod.gui.login.connectionerror");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}, "replaymod-auth").start();
|
||||
}
|
||||
};
|
||||
username.onEnter(doLogin);
|
||||
password.onEnter(doLogin);
|
||||
loginButton.onClick(doLogin);
|
||||
cancelButton.onClick(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
getMinecraft().displayGuiScreen(parent);
|
||||
}
|
||||
});
|
||||
registerButton.onClick(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
new GuiRegister(GuiLoginPrompt.this).display();
|
||||
}
|
||||
});
|
||||
Runnable contentValidation = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
loginButton.setEnabled(!username.getText().isEmpty() && !password.getText().isEmpty());
|
||||
}
|
||||
};
|
||||
username.onTextChanged(contentValidation);
|
||||
password.onTextChanged(contentValidation);
|
||||
}
|
||||
|
||||
public GuiLoginPrompt(net.minecraft.client.gui.GuiScreen parent,
|
||||
net.minecraft.client.gui.GuiScreen successScreen, boolean manuallyTriggered) {
|
||||
this.parent = parent;
|
||||
this.successScreen = successScreen;
|
||||
|
||||
//if the login prompt was opened automatically (on mod startup), show a "skip" instead of "cancel" button
|
||||
if(!manuallyTriggered) {
|
||||
cancelButton.setI18nLabel("replaymod.gui.login.skip");
|
||||
}
|
||||
|
||||
setLayout(new CustomLayout<GuiLoginPrompt>() {
|
||||
@Override
|
||||
protected void layout(GuiLoginPrompt container, int width, int height) {
|
||||
pos(username, width / 2 - 45, 30);
|
||||
pos(password, width / 2 - 45, 60);
|
||||
pos(loginButton, width / 2 - 152, 110);
|
||||
pos(cancelButton, width / 2 + 2, 110);
|
||||
|
||||
pos(usernameLabel, x(username) - 10 - usernameLabel.getMinSize().getWidth(), y(username) + 7);
|
||||
pos(passwordLabel, x(password) - 10 - passwordLabel.getMinSize().getWidth(), y(password) + 7);
|
||||
pos(statusLabel, width / 2 - statusLabel.getMinSize().getWidth() / 2, 92);
|
||||
|
||||
int labelWidth = noAccountLabel.getMinSize().getWidth();
|
||||
int buttonWidth = registerButton.getMaxSize().getWidth();
|
||||
int lineWidth = labelWidth + 5 + buttonWidth;
|
||||
int lineStart = width / 2 - lineWidth / 2;
|
||||
pos(noAccountLabel, lineStart, height - 22);
|
||||
pos(registerButton, lineStart + labelWidth + 5, height - 30);
|
||||
}
|
||||
});
|
||||
|
||||
setTitle(new GuiLabel().setI18nText("replaymod.gui.login.title"));
|
||||
}
|
||||
|
||||
public net.minecraft.client.gui.GuiScreen getSuccessScreen() {
|
||||
return successScreen;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected GuiLoginPrompt getThis() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -1,160 +0,0 @@
|
||||
package eu.crushedpixel.replaymod.gui.online;
|
||||
|
||||
import com.mojang.authlib.exceptions.AuthenticationException;
|
||||
import de.johni0702.minecraft.gui.container.AbstractGuiScreen;
|
||||
import de.johni0702.minecraft.gui.container.GuiPanel;
|
||||
import de.johni0702.minecraft.gui.element.*;
|
||||
import de.johni0702.minecraft.gui.layout.CustomLayout;
|
||||
import de.johni0702.minecraft.gui.layout.HorizontalLayout;
|
||||
import de.johni0702.minecraft.gui.layout.VerticalLayout;
|
||||
import com.replaymod.core.ReplayMod;
|
||||
import eu.crushedpixel.replaymod.api.ApiException;
|
||||
import eu.crushedpixel.replaymod.gui.GuiConstants;
|
||||
import eu.crushedpixel.replaymod.utils.EmailAddressUtils;
|
||||
import eu.crushedpixel.replaymod.utils.RegexUtils;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import org.lwjgl.util.Dimension;
|
||||
import org.lwjgl.util.ReadableColor;
|
||||
|
||||
public class GuiRegister extends AbstractGuiScreen<GuiRegister> {
|
||||
private final GuiPanel inputs;
|
||||
private final GuiTextField usernameInput, mailInput;
|
||||
private final GuiPasswordField passwordInput, passwordConfirmation;
|
||||
private final GuiButton registerButton = new GuiButton(this).setI18nLabel("replaymod.gui.register").setSize(150, 20).setDisabled();
|
||||
private final GuiButton cancelButton = new GuiButton(this).setI18nLabel("replaymod.gui.cancel").setSize(150, 20);
|
||||
private final GuiLabel disclaimerLabel = new GuiLabel(this).setI18nText("replaymod.gui.register.disclaimer");
|
||||
private final GuiLabel statusLabel = new GuiLabel(this).setColor(ReadableColor.RED);
|
||||
|
||||
{
|
||||
inputs = new GuiPanel(this).setLayout(new VerticalLayout().setSpacing(10));
|
||||
HorizontalLayout.Data data = new HorizontalLayout.Data(0.5);
|
||||
inputs.addElements(new VerticalLayout.Data(1),
|
||||
new GuiPanel().setLayout(new HorizontalLayout(HorizontalLayout.Alignment.RIGHT).setSpacing(10))
|
||||
.addElements(data, new GuiLabel().setI18nText("replaymod.gui.username"))
|
||||
.addElements(data, usernameInput = new GuiTextField().setMaxLength(16).setSize(145, 20)),
|
||||
new GuiPanel().setLayout(new HorizontalLayout(HorizontalLayout.Alignment.RIGHT).setSpacing(10))
|
||||
.addElements(data, new GuiLabel().setI18nText("replaymod.gui.mail"))
|
||||
.addElements(data, mailInput = new GuiTextField().setSize(145, 20)),
|
||||
new GuiPanel().setLayout(new HorizontalLayout(HorizontalLayout.Alignment.RIGHT).setSpacing(10))
|
||||
.addElements(data, new GuiLabel().setI18nText("replaymod.gui.password"))
|
||||
.addElements(data, passwordInput = new GuiPasswordField().setMaxLength(GuiConstants.MAX_PW_LENGTH+1).setSize(145, 20)),
|
||||
new GuiPanel().setLayout(new HorizontalLayout(HorizontalLayout.Alignment.RIGHT).setSpacing(10))
|
||||
.addElements(data, new GuiLabel().setI18nText("replaymod.gui.register.confirmpw"))
|
||||
.addElements(data, passwordConfirmation = new GuiPasswordField().setMaxLength(GuiConstants.MAX_PW_LENGTH+1).setSize(145, 20))
|
||||
);
|
||||
usernameInput.setNext(mailInput)
|
||||
.getNext().setNext(passwordInput)
|
||||
.getNext().setNext(passwordConfirmation)
|
||||
.getNext().setNext(usernameInput);
|
||||
|
||||
setLayout(new CustomLayout<GuiRegister>() {
|
||||
@Override
|
||||
protected void layout(GuiRegister container, int width, int height) {
|
||||
pos(inputs, width / 2 - inputs.getMinSize().getWidth() / 2, 30);
|
||||
pos(registerButton, width / 2 - 152, 170);
|
||||
pos(cancelButton, width / 2 + 2, 170);
|
||||
pos(statusLabel, width / 2 - statusLabel.getMinSize().getWidth() / 2, 152);
|
||||
|
||||
FontRenderer font = getMinecraft().fontRendererObj;
|
||||
int lineCount = font.listFormattedStringToWidth(disclaimerLabel.getText(), width - 10).size();
|
||||
Dimension dim = new Dimension(width - 10, font.FONT_HEIGHT * lineCount);
|
||||
disclaimerLabel.setSize(dim);
|
||||
pos(disclaimerLabel, 5, height - dim.getHeight() - 5);
|
||||
}
|
||||
});
|
||||
|
||||
setTitle(new GuiLabel().setI18nText("replaymod.gui.register.title"));
|
||||
|
||||
Runnable doRegister = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (!registerButton.isEnabled()) return;
|
||||
|
||||
inputs.forEach(IGuiTextField.class).setDisabled();
|
||||
statusLabel.setI18nText("replaymod.gui.login.logging");
|
||||
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
String username = usernameInput.getText().trim();
|
||||
String mail = mailInput.getText().trim();
|
||||
String password = passwordInput.getText();
|
||||
ReplayMod.apiClient.register(username, mail, password);
|
||||
|
||||
getMinecraft().addScheduledTask(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
getMinecraft().displayGuiScreen(parent.getSuccessScreen());
|
||||
}
|
||||
});
|
||||
} catch (ApiException ae) {
|
||||
statusLabel.setText(ae.getLocalizedMessage());
|
||||
} catch (AuthenticationException aue) {
|
||||
aue.printStackTrace();
|
||||
statusLabel.setI18nText("replaymod.gui.register.error.authfailed");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
statusLabel.setI18nText("replaymod.gui.login.connectionerror");
|
||||
} finally {
|
||||
inputs.forEach(IGuiTextField.class).setEnabled();
|
||||
}
|
||||
}
|
||||
}, "replaymod-register").start();
|
||||
}
|
||||
};
|
||||
inputs.forEach(IGuiTextField.class).onEnter(doRegister);
|
||||
registerButton.onClick(doRegister);
|
||||
|
||||
Runnable contentValidation = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
String status = null;
|
||||
if (usernameInput.getText().length() < 5) {
|
||||
status = "replaymod.gui.register.error.shortusername";
|
||||
} else if(!RegexUtils.isValid(RegexUtils.ALPHANUMERIC_UNDERSCORE, usernameInput.getText().trim())) {
|
||||
status = "replaymod.gui.register.error.invalidname";
|
||||
} else if (passwordInput.getText().length() < GuiConstants.MIN_PW_LENGTH) {
|
||||
status = "replaymod.gui.register.error.shortpw";
|
||||
} else if (passwordInput.getText().length() > GuiConstants.MAX_PW_LENGTH) {
|
||||
status = "replaymod.gui.register.error.longpw";
|
||||
} else if (!EmailAddressUtils.isValidEmailAddress(mailInput.getText())) {
|
||||
status = "replaymod.api.invalidmail";
|
||||
} else if (!passwordConfirmation.getText().equals(passwordInput.getText())) {
|
||||
status = "replaymod.gui.register.error.nomatch";
|
||||
}
|
||||
|
||||
registerButton.setEnabled(status == null);
|
||||
|
||||
if (status != null
|
||||
&& !usernameInput.getText().isEmpty()
|
||||
&& !mailInput.getText().isEmpty()
|
||||
&& !passwordInput.getText().isEmpty()
|
||||
&& !passwordConfirmation.getText().isEmpty()) {
|
||||
statusLabel.setI18nText(status);
|
||||
} else {
|
||||
statusLabel.setText("");
|
||||
}
|
||||
}
|
||||
};
|
||||
inputs.forEach(IGuiTextField.class).onTextChanged(contentValidation);
|
||||
|
||||
cancelButton.onClick(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
parent.display();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private GuiLoginPrompt parent;
|
||||
|
||||
public GuiRegister(GuiLoginPrompt parent) {
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected GuiRegister getThis() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -1,579 +0,0 @@
|
||||
package eu.crushedpixel.replaymod.gui.online;
|
||||
|
||||
import com.replaymod.core.ReplayMod;
|
||||
import eu.crushedpixel.replaymod.api.replay.SearchQuery;
|
||||
import eu.crushedpixel.replaymod.api.replay.holders.Category;
|
||||
import eu.crushedpixel.replaymod.api.replay.holders.FileInfo;
|
||||
import eu.crushedpixel.replaymod.api.replay.holders.MinecraftVersion;
|
||||
import eu.crushedpixel.replaymod.api.replay.holders.Rating;
|
||||
import eu.crushedpixel.replaymod.api.replay.pagination.DownloadedFilePagination;
|
||||
import eu.crushedpixel.replaymod.api.replay.pagination.FavoritedFilePagination;
|
||||
import eu.crushedpixel.replaymod.api.replay.pagination.Pagination;
|
||||
import eu.crushedpixel.replaymod.api.replay.pagination.SearchPagination;
|
||||
import eu.crushedpixel.replaymod.gui.GuiConstants;
|
||||
import eu.crushedpixel.replaymod.gui.elements.*;
|
||||
import eu.crushedpixel.replaymod.holders.GuiEntryListStringEntry;
|
||||
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;
|
||||
import java.util.Queue;
|
||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||
|
||||
public class GuiReplayCenter extends GuiScreen implements GuiYesNoCallback {
|
||||
|
||||
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 ReplayFileList currentList;
|
||||
private GuiButton loadButton, favButton, likeButton, dislikeButton;
|
||||
private List<GuiButton> replayButtonBar, bottomBar, topBar;
|
||||
|
||||
private GuiToggleButton searchGametypeToggle, searchSortToggle;
|
||||
private GuiDropdown<GuiEntryListStringEntry> searchCategoryDropdown, searchVersionDropdown;
|
||||
private GuiAdvancedTextField searchNameInput, searchServerInput;
|
||||
private GuiButton searchActionButton;
|
||||
|
||||
private Queue<GuiListExtended.IGuiListEntry> loadedReplaysQueue = new ConcurrentLinkedQueue<GuiListExtended.IGuiListEntry>();
|
||||
|
||||
private boolean showSearchFields = false;
|
||||
|
||||
public static GuiYesNo getYesNoGui(GuiYesNoCallback p_152129_0_, int p_152129_2_) {
|
||||
String s1 = I18n.format("replaymod.gui.center.logoutcallback");
|
||||
return new GuiYesNo(p_152129_0_, s1, "", I18n.format("replaymod.gui.logout"),
|
||||
I18n.format("replaymod.gui.cancel"), p_152129_2_);
|
||||
}
|
||||
|
||||
private boolean initialized = false;
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
Keyboard.enableRepeatEvents(true);
|
||||
|
||||
if(!initialized) {
|
||||
if(!ReplayMod.apiClient.isLoggedIn()) {
|
||||
mc.displayGuiScreen(new GuiLoginPrompt(new GuiMainMenu(), this, true).toMinecraft());
|
||||
}
|
||||
|
||||
//Top Button Bar
|
||||
topBar = new ArrayList<GuiButton>();
|
||||
|
||||
GuiButton recentButton = new GuiButton(GuiConstants.CENTER_RECENT_BUTTON, 20, 30, I18n.format("replaymod.gui.center.top.recent"));
|
||||
topBar.add(recentButton);
|
||||
|
||||
GuiButton bestButton = new GuiButton(GuiConstants.CENTER_BEST_BUTTON, 20, 30, I18n.format("replaymod.gui.center.top.best"));
|
||||
topBar.add(bestButton);
|
||||
|
||||
GuiButton downloadedReplayButton = new GuiButton(GuiConstants.CENTER_DOWNLOADED_REPLAYS_BUTTON, 20, 30, I18n.format("replaymod.gui.center.top.downloaded"));
|
||||
downloadedReplayButton.enabled = ReplayMod.apiClient.isLoggedIn();
|
||||
topBar.add(downloadedReplayButton);
|
||||
|
||||
GuiButton favoritedReplayButton = new GuiButton(GuiConstants.CENTER_FAVORITED_REPLAYS_BUTTON, 20, 30, I18n.format("replaymod.gui.center.top.favorited"));
|
||||
favoritedReplayButton.enabled = ReplayMod.apiClient.isLoggedIn();
|
||||
topBar.add(favoritedReplayButton);
|
||||
|
||||
GuiButton searchButton = new GuiButton(GuiConstants.CENTER_SEARCH_BUTTON, 20, 30, I18n.format("replaymod.gui.center.top.search"));
|
||||
topBar.add(searchButton);
|
||||
|
||||
//Replay specific actions (load, rate, etc)
|
||||
replayButtonBar = new ArrayList<GuiButton>();
|
||||
|
||||
loadButton = new GuiButton(GuiConstants.CENTER_LOAD_REPLAY_BUTTON, 20, 30, I18n.format("replaymod.gui.download"));
|
||||
replayButtonBar.add(loadButton);
|
||||
|
||||
favButton = new GuiButton(GuiConstants.CENTER_FAV_REPLAY_BUTTON, 20, 30, I18n.format("replaymod.gui.center.favorite"));
|
||||
replayButtonBar.add(favButton);
|
||||
|
||||
likeButton = new GuiButton(GuiConstants.CENTER_LIKE_REPLAY_BUTTON, 20, 30, I18n.format("replaymod.gui.like"));
|
||||
replayButtonBar.add(likeButton);
|
||||
|
||||
dislikeButton = new GuiButton(GuiConstants.CENTER_DISLIKE_REPLAY_BUTTON, 20, 30, I18n.format("replaymod.gui.dislike"));
|
||||
replayButtonBar.add(dislikeButton);
|
||||
|
||||
//Bottom Button Bar (dat alliteration)
|
||||
bottomBar = new ArrayList<GuiButton>();
|
||||
|
||||
GuiButton logoutButton = new GuiButton(GuiConstants.CENTER_LOGOUT_BUTTON, 20, 20, I18n.format("replaymod.gui.logout"));
|
||||
bottomBar.add(logoutButton);
|
||||
|
||||
GuiButton managerButton = new GuiButton(GuiConstants.CENTER_MANAGER_BUTTON, 20, 20, I18n.format("replaymod.gui.replayviewer"));
|
||||
bottomBar.add(managerButton);
|
||||
|
||||
GuiButton exitButton = new GuiButton(GuiConstants.CENTER_BACK_BUTTON, 20, 20, I18n.format("replaymod.gui.mainmenu"));
|
||||
bottomBar.add(exitButton);
|
||||
|
||||
showOnlineRecent();
|
||||
disableTopBarButton(GuiConstants.CENTER_RECENT_BUTTON);
|
||||
|
||||
//Search GUI
|
||||
searchActionButton = new GuiButton(GuiConstants.CENTER_SEARCH_ACTION_BUTTON, 20, 20, I18n.format("replaymod.gui.center.top.search"));
|
||||
searchGametypeToggle = new GuiToggleButton(GuiConstants.CENTER_SEARCH_GAMETYPE_TOGGLE, 0, 0, I18n.format("replaymod.gui.center.search.gametype")+": ",
|
||||
new String[]{I18n.format("options.particles.all"), I18n.format("menu.singleplayer"), I18n.format("menu.multiplayer")});
|
||||
searchSortToggle = new GuiToggleButton(GuiConstants.CENTER_SEARCH_ORDER_TOGGLE, 0, 0, I18n.format("replaymod.gui.center.search.order")+": ",
|
||||
new String[]{I18n.format("replaymod.gui.center.search.order.best"), I18n.format("replaymod.gui.center.search.order.recent")});
|
||||
searchCategoryDropdown = new GuiDropdown<GuiEntryListStringEntry>(fontRendererObj, 0, 0, 0, Category.values().length+1);
|
||||
searchVersionDropdown = new GuiDropdown<GuiEntryListStringEntry>(fontRendererObj, 0, 0, 0, 5);
|
||||
searchNameInput = new GuiAdvancedTextField(fontRendererObj, 0, 0, 50, 20);
|
||||
searchServerInput = new GuiAdvancedTextField(fontRendererObj, 0, 0, 50, 20);
|
||||
|
||||
searchNameInput.hint = I18n.format("replaymod.gui.center.search.name");
|
||||
searchServerInput.hint = I18n.format("replaymod.gui.center.search.server");
|
||||
|
||||
searchCategoryDropdown.addElement(new GuiEntryListStringEntry(I18n.format("replaymod.gui.center.search.category")));
|
||||
for(Category c : Category.values()) {
|
||||
searchCategoryDropdown.addElement(new GuiEntryListStringEntry(c.toNiceString()));
|
||||
}
|
||||
|
||||
searchVersionDropdown.addElement(new GuiEntryListStringEntry(I18n.format("replaymod.gui.center.search.version")));
|
||||
for(MinecraftVersion v : MinecraftVersion.values()) {
|
||||
searchVersionDropdown.addElement(new GuiEntryListStringEntry(v.toNiceName()));
|
||||
}
|
||||
}
|
||||
|
||||
int wd = this.width - 40;
|
||||
int sw = wd/3 + 4;
|
||||
|
||||
searchNameInput.xPosition = searchServerInput.xPosition = searchActionButton.xPosition = 20;
|
||||
searchCategoryDropdown.xPosition = searchVersionDropdown.xPosition = 20 + sw;
|
||||
searchGametypeToggle.xPosition = searchSortToggle.xPosition = 20 + 2*sw;
|
||||
|
||||
searchNameInput.width = searchCategoryDropdown.width = searchGametypeToggle.width = searchActionButton.width =
|
||||
searchServerInput.width = searchVersionDropdown.width = searchSortToggle.width = sw-7;
|
||||
|
||||
searchNameInput.yPosition = searchCategoryDropdown.yPosition = searchGametypeToggle.yPosition = 70;
|
||||
searchServerInput.yPosition = searchVersionDropdown.yPosition = searchSortToggle.yPosition = 100;
|
||||
searchActionButton.yPosition = 130;
|
||||
|
||||
if(showSearchFields) {
|
||||
showSearchFields();
|
||||
}
|
||||
|
||||
if(currentList != null) {
|
||||
currentList.setDimensions(this.width, this.height, 50, this.height - 60);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
List<GuiButton> buttonList = this.buttonList;
|
||||
|
||||
int i = 0;
|
||||
for(GuiButton b : topBar) {
|
||||
int w = this.width - 30;
|
||||
int w2 = w / topBar.size();
|
||||
|
||||
int x = 15 + (w2 * i);
|
||||
b.xPosition = x + 2;
|
||||
b.yPosition = 20;
|
||||
b.width = w2 - 4;
|
||||
|
||||
buttonList.add(b);
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
i = 0;
|
||||
for(GuiButton b : replayButtonBar) {
|
||||
int w = this.width - 30;
|
||||
int w2 = w / replayButtonBar.size();
|
||||
|
||||
int x = 15 + (w2 * i);
|
||||
b.xPosition = x + 2;
|
||||
b.yPosition = height - 55;
|
||||
b.width = w2 - 4;
|
||||
|
||||
b.enabled = false;
|
||||
|
||||
buttonList.add(b);
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
buttonList.add(b);
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
initialized = true;
|
||||
}
|
||||
|
||||
public void elementSelected(int index) {
|
||||
if(index < 0) {
|
||||
for(GuiButton b : replayButtonBar) {
|
||||
b.enabled = false;
|
||||
}
|
||||
return;
|
||||
}
|
||||
GuiReplayListEntry entry = (GuiReplayListEntry)currentList.getListEntry(index);
|
||||
FileInfo info = entry.getFileInfo();
|
||||
if(info != null) {
|
||||
boolean downloaded = ReplayMod.downloadedFileHandler.getFileForID(info.getId()) != null;
|
||||
loadButton.displayString = downloaded ? I18n.format("replaymod.gui.load") : I18n.format("replaymod.gui.download");
|
||||
loadButton.enabled = true;
|
||||
|
||||
boolean favorited = ReplayMod.favoritedFileHandler.isFavorited(info.getId());
|
||||
favButton.displayString = favorited ? I18n.format("replaymod.gui.center.unfavorite") : I18n.format("replaymod.gui.center.favorite");
|
||||
//if not downloaded, disable favorising
|
||||
favButton.enabled = favorited || downloaded;
|
||||
|
||||
likeButton.enabled = dislikeButton.enabled = downloaded;
|
||||
Rating.RatingType rating = ReplayMod.ratedFileHandler.getRating(info.getId());
|
||||
|
||||
likeButton.displayString = I18n.format("replaymod.gui.like");
|
||||
dislikeButton.displayString = I18n.format("replaymod.gui.dislike");
|
||||
|
||||
if(rating == Rating.RatingType.LIKE) {
|
||||
likeButton.displayString = I18n.format("replaymod.gui.removelike");
|
||||
} else if(rating == Rating.RatingType.DISLIKE) {
|
||||
dislikeButton.displayString = I18n.format("replaymod.gui.removedislike");
|
||||
}
|
||||
|
||||
} else {
|
||||
for(GuiButton b : replayButtonBar) {
|
||||
b.enabled = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void disableTopBarButton(int id) {
|
||||
for(GuiButton b : topBar) {
|
||||
b.enabled = b.id != id;
|
||||
}
|
||||
}
|
||||
|
||||
@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) {
|
||||
// TODO
|
||||
// mc.displayGuiScreen(new GuiReplayViewer(mod));
|
||||
} else if(button.id == GuiConstants.CENTER_RECENT_BUTTON) {
|
||||
disableTopBarButton(button.id);
|
||||
showOnlineRecent();
|
||||
} else if(button.id == GuiConstants.CENTER_BEST_BUTTON) {
|
||||
disableTopBarButton(button.id);
|
||||
showOnlineBest();
|
||||
} else if(button.id == GuiConstants.CENTER_DOWNLOADED_REPLAYS_BUTTON) {
|
||||
disableTopBarButton(button.id);
|
||||
showDownloadedFiles();
|
||||
} else if(button.id == GuiConstants.CENTER_FAVORITED_REPLAYS_BUTTON) {
|
||||
disableTopBarButton(button.id);
|
||||
showFavoritedFiles();
|
||||
} else if(button.id == GuiConstants.CENTER_SEARCH_BUTTON) {
|
||||
disableTopBarButton(button.id);
|
||||
showReplaySearch();
|
||||
} else if(button.id == GuiConstants.CENTER_LOAD_REPLAY_BUTTON) {
|
||||
GuiReplayListEntry entry = (GuiReplayListEntry)currentList.getListEntry(currentList.selected);
|
||||
FileInfo info = entry.getFileInfo();
|
||||
if(info != null) {
|
||||
File f = ReplayMod.downloadedFileHandler.getFileForID(info.getId());
|
||||
if(f == null) {
|
||||
new GuiReplayDownloading(info).display();
|
||||
} else {
|
||||
mc.displayGuiScreen(new GuiReplayInstanceChooser(info, f));
|
||||
}
|
||||
}
|
||||
} else if(button.id == GuiConstants.CENTER_FAV_REPLAY_BUTTON) {
|
||||
GuiReplayListEntry entry = (GuiReplayListEntry)currentList.getListEntry(currentList.selected);
|
||||
FileInfo info = entry.getFileInfo();
|
||||
if(info != null) {
|
||||
boolean favorited = ReplayMod.favoritedFileHandler.isFavorited(info.getId());
|
||||
try {
|
||||
if(favorited) ReplayMod.favoritedFileHandler.removeFromFavorites(info.getId());
|
||||
else ReplayMod.favoritedFileHandler.addToFavorites(info.getId());
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
elementSelected(currentList.selected);
|
||||
}
|
||||
} else if(button.id == GuiConstants.CENTER_LIKE_REPLAY_BUTTON) {
|
||||
GuiReplayListEntry entry = (GuiReplayListEntry)currentList.getListEntry(currentList.selected);
|
||||
FileInfo info = entry.getFileInfo();
|
||||
if(info != null) {
|
||||
try {
|
||||
if(ReplayMod.ratedFileHandler.getRating(info.getId()) == Rating.RatingType.LIKE) {
|
||||
ReplayMod.ratedFileHandler.rateFile(info.getId(), Rating.RatingType.NEUTRAL);
|
||||
} else {
|
||||
ReplayMod.ratedFileHandler.rateFile(info.getId(), Rating.RatingType.LIKE);
|
||||
}
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
elementSelected(currentList.selected);
|
||||
}
|
||||
} else if(button.id == GuiConstants.CENTER_DISLIKE_REPLAY_BUTTON) {
|
||||
GuiReplayListEntry entry = (GuiReplayListEntry)currentList.getListEntry(currentList.selected);
|
||||
FileInfo info = entry.getFileInfo();
|
||||
if(info != null) {
|
||||
try {
|
||||
if(ReplayMod.ratedFileHandler.getRating(info.getId()) == Rating.RatingType.DISLIKE) {
|
||||
ReplayMod.ratedFileHandler.rateFile(info.getId(), Rating.RatingType.NEUTRAL);
|
||||
} else {
|
||||
ReplayMod.ratedFileHandler.rateFile(info.getId(), Rating.RatingType.DISLIKE);
|
||||
}
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
elementSelected(currentList.selected);
|
||||
}
|
||||
}
|
||||
|
||||
//the search action button
|
||||
else if(button.id == GuiConstants.CENTER_SEARCH_ACTION_BUTTON) {
|
||||
SearchQuery searchQuery = new SearchQuery();
|
||||
|
||||
Boolean gameType = null;
|
||||
if(searchGametypeToggle.getValue() > 0) {
|
||||
gameType = searchGametypeToggle.getValue() == 1;
|
||||
}
|
||||
searchQuery.singleplayer = gameType;
|
||||
|
||||
Integer category = null;
|
||||
if(searchCategoryDropdown.getSelectionIndex() > 0) {
|
||||
category = searchCategoryDropdown.getSelectionIndex()-1;
|
||||
}
|
||||
searchQuery.category = category;
|
||||
|
||||
String mcversion = null;
|
||||
if(searchVersionDropdown.getSelectionIndex() > 0) {
|
||||
mcversion = MinecraftVersion.values()[searchVersionDropdown.getSelectionIndex()-1].getApiName();
|
||||
}
|
||||
searchQuery.version = mcversion;
|
||||
|
||||
if(searchNameInput.getText().trim().length() > 0) {
|
||||
searchQuery.name = searchNameInput.getText().trim();
|
||||
}
|
||||
|
||||
if(searchServerInput.getText().trim().length() > 0) {
|
||||
searchQuery.server = searchServerInput.getText().trim();
|
||||
}
|
||||
|
||||
searchQuery.order = searchSortToggle.getValue() == 0;
|
||||
|
||||
SearchPagination searchPagination = new SearchPagination(searchQuery);
|
||||
showReplaySearch(searchPagination);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void confirmClicked(boolean result, int id) {
|
||||
if(id == LOGOUT_CALLBACK_ID) {
|
||||
if(result) {
|
||||
mc.addScheduledTask(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ReplayMod.apiClient.logout();
|
||||
mc.displayGuiScreen(new GuiMainMenu());
|
||||
}
|
||||
});
|
||||
} else {
|
||||
mc.displayGuiScreen(this);
|
||||
elementSelected(currentList.selected);
|
||||
initGui();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
|
||||
this.drawDefaultBackground();
|
||||
if(currentList != null) {
|
||||
currentList.drawScreen(mouseX, mouseY, partialTicks);
|
||||
}
|
||||
|
||||
super.drawScreen(mouseX, mouseY, partialTicks);
|
||||
|
||||
if(((favButton.isMouseOver() && !favButton.enabled) || (likeButton.isMouseOver() && !likeButton.enabled)
|
||||
|| (dislikeButton.isMouseOver() && !dislikeButton.enabled )) && (currentList != null && currentList.selected != -1)) {
|
||||
ReplayMod.tooltipRenderer.drawTooltip(mouseX, mouseY, I18n.format("replaymod.gui.center.downloadrequired"), this, Color.RED);
|
||||
}
|
||||
|
||||
this.drawCenteredString(fontRendererObj, I18n.format("replaymod.gui.replaycenter"), this.width / 2, 5, Color.WHITE.getRGB());
|
||||
|
||||
//search fields
|
||||
if(showSearchFields) {
|
||||
this.drawString(fontRendererObj, I18n.format("replaymod.gui.center.search.filters"), searchActionButton.xPosition, 50, Color.WHITE.getRGB());
|
||||
searchActionButton.drawButton(mc, mouseX, mouseY);
|
||||
searchGametypeToggle.drawButton(mc, mouseX, mouseY);
|
||||
searchSortToggle.drawButton(mc, mouseX, mouseY);
|
||||
searchVersionDropdown.drawTextBox();
|
||||
searchCategoryDropdown.drawTextBox();
|
||||
searchNameInput.drawTextBox();
|
||||
searchServerInput.drawTextBox();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMouseInput() throws IOException {
|
||||
super.handleMouseInput();
|
||||
if(currentList != null) {
|
||||
this.currentList.handleMouseInput();
|
||||
}
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
|
||||
if(showSearchFields) {
|
||||
if(!searchCategoryDropdown.mouseClickedResult(mouseX, mouseY))
|
||||
searchVersionDropdown.mouseClicked(mouseX, mouseY, mouseButton);
|
||||
searchNameInput.mouseClicked(mouseX, mouseY, mouseButton);
|
||||
searchServerInput.mouseClicked(mouseX, mouseY, mouseButton);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateScreen() {
|
||||
if(showSearchFields) {
|
||||
searchNameInput.updateCursorCounter();
|
||||
searchServerInput.updateCursorCounter();
|
||||
}
|
||||
while (!loadedReplaysQueue.isEmpty()) {
|
||||
GuiListExtended.IGuiListEntry entry = loadedReplaysQueue.poll();
|
||||
if (entry instanceof GuiLoadingListEntry) {
|
||||
currentList.removeEntry(entry);
|
||||
} else {
|
||||
currentList.addEntry(currentList.getEntries().size() - 1, entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void keyTyped(char typedChar, int keyCode) throws IOException {
|
||||
if(showSearchFields) {
|
||||
searchNameInput.textboxKeyTyped(typedChar, keyCode);
|
||||
searchServerInput.textboxKeyTyped(typedChar, keyCode);
|
||||
}
|
||||
|
||||
super.keyTyped(typedChar, keyCode);
|
||||
}
|
||||
|
||||
@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 onGuiClosed() {
|
||||
Keyboard.enableRepeatEvents(false);
|
||||
}
|
||||
|
||||
private Thread currentListLoader;
|
||||
|
||||
private void cancelCurrentListLoader() {
|
||||
if(currentListLoader != null && currentListLoader.isAlive()) {
|
||||
currentListLoader.interrupt();
|
||||
try {
|
||||
currentListLoader.join();
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
loadedReplaysQueue.clear();
|
||||
}
|
||||
|
||||
public void show(final Pagination pagination) {
|
||||
cancelCurrentListLoader();
|
||||
|
||||
hideSearchFields();
|
||||
elementSelected(-1);
|
||||
currentList = new ReplayFileList(mc, width, height, 50, height - 60, this);
|
||||
final GuiLoadingListEntry loadingListEntry = new GuiLoadingListEntry();
|
||||
currentList.addEntry(loadingListEntry);
|
||||
|
||||
currentListLoader = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if(pagination.getLoadedPages() < 0) {
|
||||
pagination.fetchPage();
|
||||
}
|
||||
|
||||
for(FileInfo i : pagination.getFiles()) {
|
||||
if(Thread.interrupted()) break;
|
||||
try {
|
||||
File tmp = null;
|
||||
if(i.hasThumbnail()) {
|
||||
tmp = File.createTempFile("thumb_online_" + i.getId(), "jpg");
|
||||
ReplayMod.apiClient.downloadThumbnail(i.getId(), tmp);
|
||||
}
|
||||
final GuiReplayListEntry entry = new GuiReplayListEntry(currentList, i, tmp);
|
||||
loadedReplaysQueue.offer(entry);
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
loadedReplaysQueue.add(loadingListEntry);
|
||||
}
|
||||
}, "replaymod-list-loader");
|
||||
currentListLoader.start();
|
||||
}
|
||||
|
||||
public void showOnlineRecent() {
|
||||
show(new SearchPagination(recentFileSearchQuery));
|
||||
}
|
||||
|
||||
public void showOnlineBest() {
|
||||
show(new SearchPagination(bestFileSearchQuery));
|
||||
}
|
||||
|
||||
public void showDownloadedFiles() {
|
||||
show(new DownloadedFilePagination());
|
||||
}
|
||||
|
||||
public void showFavoritedFiles() {
|
||||
show(new FavoritedFilePagination());
|
||||
}
|
||||
|
||||
public void showReplaySearch() {
|
||||
cancelCurrentListLoader();
|
||||
currentList = null;
|
||||
showSearchFields();
|
||||
}
|
||||
|
||||
public void showReplaySearch(final SearchPagination searchPagination) {
|
||||
disableTopBarButton(-1);
|
||||
show(searchPagination);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private void showSearchFields() {
|
||||
showSearchFields = true;
|
||||
buttonList.add(searchActionButton);
|
||||
buttonList.add(searchGametypeToggle);
|
||||
buttonList.add(searchSortToggle);
|
||||
}
|
||||
|
||||
private void hideSearchFields() {
|
||||
showSearchFields = false;
|
||||
buttonList.remove(searchActionButton);
|
||||
buttonList.remove(searchGametypeToggle);
|
||||
buttonList.remove(searchSortToggle);
|
||||
}
|
||||
}
|
||||
@@ -1,77 +0,0 @@
|
||||
package eu.crushedpixel.replaymod.gui.online;
|
||||
|
||||
import com.mojang.realmsclient.gui.ChatFormatting;
|
||||
import com.replaymod.core.ReplayMod;
|
||||
import de.johni0702.minecraft.gui.container.AbstractGuiScreen;
|
||||
import de.johni0702.minecraft.gui.element.GuiButton;
|
||||
import de.johni0702.minecraft.gui.element.GuiLabel;
|
||||
import de.johni0702.minecraft.gui.element.advanced.GuiProgressBar;
|
||||
import de.johni0702.minecraft.gui.layout.CustomLayout;
|
||||
import eu.crushedpixel.replaymod.api.replay.holders.FileInfo;
|
||||
import eu.crushedpixel.replaymod.gui.elements.listeners.ProgressUpdateListener;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class GuiReplayDownloading extends AbstractGuiScreen<GuiReplayDownloading> implements ProgressUpdateListener {
|
||||
|
||||
private GuiProgressBar progressBar = new GuiProgressBar(this).setHeight(20);
|
||||
private GuiButton cancelButton = new GuiButton(this).setI18nLabel("gui.cancel").setSize(150, 20).onClick(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ReplayMod.apiClient.cancelDownload();
|
||||
getMinecraft().displayGuiScreen(new GuiReplayCenter());
|
||||
}
|
||||
});
|
||||
|
||||
public GuiReplayDownloading(final FileInfo fileInfo) {
|
||||
setTitle(new GuiLabel().setI18nText("replaymod.gui.viewer.download.title"));
|
||||
final GuiLabel subTitle = new GuiLabel(this).setI18nText("replaymod.gui.viewer.download.message",
|
||||
ChatFormatting.UNDERLINE + fileInfo.getName() + ChatFormatting.RESET);
|
||||
setLayout(new CustomLayout<GuiReplayDownloading>() {
|
||||
@Override
|
||||
protected void layout(GuiReplayDownloading container, int width, int height) {
|
||||
width(progressBar, width - 20);
|
||||
pos(progressBar, 10, height - 50);
|
||||
|
||||
pos(cancelButton, width - 5 - 150, height - 5 - 20);
|
||||
|
||||
pos(subTitle, width / 2 - subTitle.getMinSize().getWidth() / 2, 40);
|
||||
}
|
||||
});
|
||||
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final File replayFile = ReplayMod.downloadedFileHandler.downloadFileForID(fileInfo.getId(), GuiReplayDownloading.this);
|
||||
if(replayFile.exists()) {
|
||||
getMinecraft().addScheduledTask(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
// TODO
|
||||
// ReplayHandler.startReplay(replayFile);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProgressChanged(float progress) {
|
||||
progressBar.setProgress(progress);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProgressChanged(float progress, String progressString) {
|
||||
onProgressChanged(progress);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected GuiReplayDownloading getThis() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -1,167 +0,0 @@
|
||||
package eu.crushedpixel.replaymod.gui.online;
|
||||
|
||||
import com.mojang.realmsclient.gui.ChatFormatting;
|
||||
import eu.crushedpixel.replaymod.api.replay.holders.FileInfo;
|
||||
import eu.crushedpixel.replaymod.gui.elements.ComposedElement;
|
||||
import eu.crushedpixel.replaymod.gui.elements.GuiAdvancedButton;
|
||||
import eu.crushedpixel.replaymod.gui.elements.GuiDropdown;
|
||||
import eu.crushedpixel.replaymod.gui.elements.GuiString;
|
||||
import eu.crushedpixel.replaymod.holders.GuiEntryListValueEntry;
|
||||
import eu.crushedpixel.replaymod.utils.ReplayFileIO;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.awt.*;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class GuiReplayInstanceChooser extends GuiScreen {
|
||||
|
||||
private boolean initialized = false;
|
||||
|
||||
private GuiString dropdownTitle;
|
||||
private GuiDropdown<GuiEntryListValueEntry<File>> fileDropdown;
|
||||
private GuiAdvancedButton chooseButton, cancelButton;
|
||||
private ComposedElement composedElement;
|
||||
|
||||
private List<File> filesToChooseFrom = new ArrayList<File>();
|
||||
|
||||
private final String TITLE = I18n.format("replaymod.gui.viewer.chooser.title");
|
||||
private final String REPLAYFILE = I18n.format("replaymod.gui.editor.replayfile")+":";
|
||||
private final String MESSAGE;
|
||||
|
||||
private final String ORIGINAL = ChatFormatting.GREEN+I18n.format("replaymod.gui.original")+ChatFormatting.RESET;
|
||||
private final String MODIFIED = ChatFormatting.RED+I18n.format("replaymod.gui.modified")+ChatFormatting.RESET;
|
||||
|
||||
public GuiReplayInstanceChooser(final FileInfo fileInfo, File downloadedFile) {
|
||||
int id = fileInfo.getId();
|
||||
|
||||
this.MESSAGE = I18n.format("replaymod.gui.viewer.chooser.message", ChatFormatting.UNDERLINE+fileInfo.getName()+ChatFormatting.RESET);
|
||||
|
||||
//gather all applicable replay files
|
||||
try {
|
||||
File replayFolder = ReplayFileIO.getReplayFolder();
|
||||
|
||||
List<File> chooseableFiles = new ArrayList<File>();
|
||||
|
||||
File[] files = replayFolder.listFiles();
|
||||
if(files != null) {
|
||||
for(File file : files) {
|
||||
try {
|
||||
String extension = FilenameUtils.getExtension(file.getAbsolutePath());
|
||||
if(!"zip".equals(extension)) continue;
|
||||
|
||||
String filename = FilenameUtils.getBaseName(file.getAbsolutePath());
|
||||
String[] split = filename.split("_");
|
||||
String first = split[0];
|
||||
|
||||
if(StringUtils.isNumeric(first) && Integer.valueOf(first) == id) {
|
||||
chooseableFiles.add(file);
|
||||
}
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//if no modified versions of the replay were found, start the downloaded one
|
||||
if(chooseableFiles.isEmpty()) {
|
||||
// TODO
|
||||
// ReplayHandler.startReplay(downloadedFile);
|
||||
return;
|
||||
}
|
||||
|
||||
chooseableFiles.add(0, downloadedFile);
|
||||
this.filesToChooseFrom = chooseableFiles;
|
||||
|
||||
} catch(IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
if(!initialized) {
|
||||
dropdownTitle = new GuiString(0, 0, Color.WHITE, REPLAYFILE);
|
||||
|
||||
fileDropdown = new GuiDropdown<GuiEntryListValueEntry<File>>(fontRendererObj, 0, 0, 0, 5);
|
||||
|
||||
int i = 0;
|
||||
for(File file : filesToChooseFrom) {
|
||||
String displayName = FilenameUtils.getName(file.getAbsolutePath()) + " (" + (i == 0 ? ORIGINAL : MODIFIED) + ")";
|
||||
fileDropdown.addElement(new GuiEntryListValueEntry<File>(displayName, file));
|
||||
i++;
|
||||
}
|
||||
|
||||
chooseButton = new GuiAdvancedButton(0, 0, 100, 20, I18n.format("replaymod.gui.load"), new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
File file = fileDropdown.getElement(fileDropdown.getSelectionIndex()).getValue();
|
||||
//TODO
|
||||
// ReplayHandler.startReplay(file);
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}, null);
|
||||
|
||||
cancelButton = new GuiAdvancedButton(0, 0, 100, 20, I18n.format("replaymod.gui.cancel"), new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mc.displayGuiScreen(new GuiReplayCenter());
|
||||
}
|
||||
}, null);
|
||||
|
||||
composedElement = new ComposedElement(dropdownTitle, fileDropdown, chooseButton, cancelButton);
|
||||
}
|
||||
|
||||
fileDropdown.width = 200;
|
||||
|
||||
int strWidth = fontRendererObj.getStringWidth(REPLAYFILE);
|
||||
int totWidth = strWidth + fileDropdown.width + 5;
|
||||
|
||||
dropdownTitle.positionX = (this.width-totWidth)/2;
|
||||
fileDropdown.xPosition = dropdownTitle.positionX + strWidth + 5;
|
||||
|
||||
fileDropdown.yPosition = this.height/2 - 10;
|
||||
|
||||
dropdownTitle.positionY = fileDropdown.yPosition + 6;
|
||||
|
||||
cancelButton.xPosition = this.width - 100 - 5;
|
||||
chooseButton.xPosition = cancelButton.xPosition - 100 - 5;
|
||||
|
||||
cancelButton.yPosition = chooseButton.yPosition = this.height - 5 - 20;
|
||||
|
||||
this.initialized = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
|
||||
this.drawDefaultBackground();
|
||||
drawCenteredString(fontRendererObj, ChatFormatting.UNDERLINE+TITLE, this.width / 2, 15, Color.WHITE.getRGB());
|
||||
|
||||
String[] lines = eu.crushedpixel.replaymod.utils.StringUtils.splitStringInMultipleRows(MESSAGE, this.width-40);
|
||||
int i = 0;
|
||||
for(String line : lines) {
|
||||
drawString(fontRendererObj, line, 20, 40+(15*i), Color.WHITE.getRGB());
|
||||
i++;
|
||||
}
|
||||
|
||||
composedElement.draw(mc, mouseX, mouseY);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException {
|
||||
composedElement.mouseClick(mc, mouseX, mouseY, mouseButton);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mouseReleased(int mouseX, int mouseY, int state) {
|
||||
composedElement.mouseRelease(mc, mouseX, mouseY, state);
|
||||
}
|
||||
}
|
||||
@@ -1,472 +0,0 @@
|
||||
package eu.crushedpixel.replaymod.gui.online;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
import com.replaymod.core.ReplayMod;
|
||||
import com.replaymod.replay.gui.screen.GuiReplayViewer;
|
||||
import de.johni0702.replaystudio.replay.ReplayFile;
|
||||
import de.johni0702.replaystudio.replay.ReplayMetaData;
|
||||
import de.johni0702.replaystudio.replay.ZipReplayFile;
|
||||
import de.johni0702.replaystudio.studio.ReplayStudio;
|
||||
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.*;
|
||||
import eu.crushedpixel.replaymod.gui.elements.listeners.ProgressUpdateListener;
|
||||
import eu.crushedpixel.replaymod.registry.ResourceHelper;
|
||||
import eu.crushedpixel.replaymod.utils.ImageUtils;
|
||||
import eu.crushedpixel.replaymod.utils.MouseUtils;
|
||||
import eu.crushedpixel.replaymod.utils.RegexUtils;
|
||||
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.client.resources.I18n;
|
||||
import net.minecraft.client.settings.GameSettings;
|
||||
import net.minecraft.client.settings.KeyBinding;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.*;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
public class GuiUploadFile extends GuiScreen implements ProgressUpdateListener {
|
||||
|
||||
private final Minecraft mc = Minecraft.getMinecraft();
|
||||
|
||||
private final ResourceLocation textureResource;
|
||||
private DynamicTexture dynTex = null;
|
||||
|
||||
private boolean initialized;
|
||||
|
||||
private int columnWidth;
|
||||
private int 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 GuiAdvancedButton startUploadButton, cancelUploadButton, backButton;
|
||||
private GuiProgressBar progressBar;
|
||||
|
||||
private File replayFile;
|
||||
|
||||
private ReplayMetaData metaData;
|
||||
private BufferedImage thumb;
|
||||
private boolean hasThumbnail;
|
||||
|
||||
private FileUploader uploader = new FileUploader();
|
||||
|
||||
private GuiReplayViewer parent;
|
||||
|
||||
private boolean lockUploadButton = false;
|
||||
|
||||
public GuiUploadFile(File file, GuiReplayViewer parent) {
|
||||
this.parent = parent;
|
||||
|
||||
this.textureResource = new ResourceLocation("upload_thumbs/" + FilenameUtils.getBaseName(file.getAbsolutePath()));
|
||||
dynTex = null;
|
||||
|
||||
boolean correctFile = false;
|
||||
this.replayFile = file;
|
||||
|
||||
if(("." + FilenameUtils.getExtension(file.getAbsolutePath())).equals(".zip")) {
|
||||
ReplayFile archive = null;
|
||||
try {
|
||||
archive = new ZipReplayFile(new ReplayStudio(), file);
|
||||
|
||||
metaData = archive.getMetaData();
|
||||
Optional<BufferedImage> img = archive.getThumb();
|
||||
if(img.isPresent()) {
|
||||
thumb = ImageUtils.scaleImage(img.get(), new Dimension(1280, 720));
|
||||
hasThumbnail = true;
|
||||
}
|
||||
|
||||
archive.close();
|
||||
correctFile = true;
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
if (archive != null) {
|
||||
archive.close();
|
||||
}
|
||||
} catch (IOException ignored) {}
|
||||
}
|
||||
}
|
||||
|
||||
if(!correctFile) {
|
||||
Logger logger = LogManager.getLogger();
|
||||
logger.error("Invalid file provided to upload");
|
||||
parent.display();
|
||||
replayFile = null;
|
||||
return;
|
||||
}
|
||||
|
||||
//If thumb is null, set image to placeholder
|
||||
if(thumb == null) {
|
||||
try {
|
||||
thumb = ImageIO.read(GuiUploadFile.class.getClassLoader().getResourceAsStream("default_thumb.jpg"));
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
if(replayFile == null) {
|
||||
parent.display();
|
||||
return;
|
||||
}
|
||||
|
||||
if(!ReplayMod.apiClient.isLoggedIn()) {
|
||||
mc.displayGuiScreen(new GuiLoginPrompt(parent.toMinecraft(), this, true).toMinecraft());
|
||||
return;
|
||||
}
|
||||
|
||||
if (!initialized) {
|
||||
initialized = true;
|
||||
|
||||
int y = 20;
|
||||
|
||||
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, 1000, 100, 1000);
|
||||
}
|
||||
|
||||
columnWidth = Math.min(200, (width - 60) / 3);
|
||||
int columnLeft = width / 2 - columnWidth / 2 * 3 - 10;
|
||||
int columnMiddle = width / 2 - columnWidth / 2;
|
||||
columnRight = width / 2 + columnWidth / 2 + 10;
|
||||
|
||||
name.xPosition = columnLeft;
|
||||
name.width = columnWidth;
|
||||
|
||||
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()]));
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
List<GuiButton> buttonList = this.buttonList;
|
||||
if(startUploadButton == null) {
|
||||
List<GuiButton> bottomBar = new ArrayList<GuiButton>();
|
||||
startUploadButton = new GuiAdvancedButton(GuiConstants.UPLOAD_START_BUTTON, 0, 0, I18n.format("replaymod.gui.upload.start"));
|
||||
bottomBar.add(startUploadButton);
|
||||
|
||||
cancelUploadButton = new GuiAdvancedButton(GuiConstants.UPLOAD_CANCEL_BUTTON, 0, 0, I18n.format("replaymod.gui.upload.cancel"));
|
||||
cancelUploadButton.enabled = false;
|
||||
bottomBar.add(cancelUploadButton);
|
||||
|
||||
backButton = new GuiAdvancedButton(GuiConstants.UPLOAD_BACK_BUTTON, 0, 0, I18n.format("replaymod.gui.back"));
|
||||
bottomBar.add(backButton);
|
||||
|
||||
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;
|
||||
|
||||
buttonList.add(b);
|
||||
|
||||
i++;
|
||||
}
|
||||
} else {
|
||||
List<GuiButton> bottomBar = new ArrayList<GuiButton>();
|
||||
|
||||
bottomBar.add(startUploadButton);
|
||||
bottomBar.add(cancelUploadButton);
|
||||
bottomBar.add(backButton);
|
||||
|
||||
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;
|
||||
|
||||
buttonList.add(b);
|
||||
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
if(progressBar == null) {
|
||||
progressBar = new GuiProgressBar(19, height - 52, width - (2*19), 15);
|
||||
} else {
|
||||
progressBar.setBounds(19, height - 52, width - (2*19), 15);
|
||||
}
|
||||
|
||||
validateStartButton();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void actionPerformed(GuiButton button) throws IOException {
|
||||
if(!button.enabled) return;
|
||||
if(button.id == GuiConstants.UPLOAD_BACK_BUTTON) {
|
||||
parent.display();
|
||||
} else if(button.id == GuiConstants.UPLOAD_START_BUTTON) {
|
||||
final String name = this.name.getText().trim();
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
String tagsRaw = tags.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);
|
||||
}
|
||||
}
|
||||
|
||||
Category category = Category.values()[GuiUploadFile.this.category.getValue()];
|
||||
|
||||
String desc = StringUtils.join(description.getText(), '\n');
|
||||
|
||||
if(hideServerIP.isChecked()) {
|
||||
File tmp = File.createTempFile("replay_hidden_ip", "mcpr");
|
||||
|
||||
ReplayMetaData newMetaData = new ReplayMetaData(metaData);
|
||||
newMetaData.setServerName(null);
|
||||
ReplayFile replay = new ZipReplayFile(new ReplayStudio(), replayFile);
|
||||
replay.writeMetaData(newMetaData);
|
||||
replay.saveTo(tmp);
|
||||
|
||||
uploader.uploadFile(GuiUploadFile.this, name, tags, tmp, category, desc);
|
||||
|
||||
FileUtils.deleteQuietly(tmp);
|
||||
} else {
|
||||
uploader.uploadFile(GuiUploadFile.this, name, tags, replayFile, category, desc);
|
||||
}
|
||||
|
||||
ReplayMod.uploadedFileHandler.markAsUploaded(replayFile);
|
||||
} catch(Exception e) {
|
||||
messageTextField.setText(I18n.format("replaymod.gui.unknownerror"));
|
||||
messageTextField.setTextColor(Color.RED.getRGB());
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}, "replaymod-file-uploader").start();
|
||||
} else if(button.id == GuiConstants.UPLOAD_CANCEL_BUTTON) {
|
||||
uploader.cancelUploading();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
|
||||
this.drawDefaultBackground();
|
||||
|
||||
drawCenteredString(fontRendererObj, I18n.format("replaymod.gui.upload.title"), this.width / 2, 5, 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);
|
||||
}
|
||||
|
||||
mc.getTextureManager().bindTexture(textureResource); //Will be freed by the ResourceHelper
|
||||
int height = columnWidth * 720 / 1280;
|
||||
Gui.drawScaledCustomSizeModalRect(columnRight, 20, 0, 0, 1280, 720, columnWidth, height, 1280, 720);
|
||||
|
||||
if (!hasThumbnail) {
|
||||
KeyBinding keyBinding = ReplayMod.instance.getKeyBindingRegistry().getKeyBindings().get("replaymod.input.thumbnail");
|
||||
String str = I18n.format("replaymod.gui.upload.nothumbnail",
|
||||
keyBinding == null ? "???" : GameSettings.getKeyDisplayString(keyBinding.getKeyCode()));
|
||||
int y = 20 + height + 10;
|
||||
fontRendererObj.drawSplitString(str, columnRight, y, columnWidth, Color.RED.getRGB());
|
||||
}
|
||||
}
|
||||
|
||||
messageTextField.drawTextBox();
|
||||
|
||||
super.drawScreen(mouseX, mouseY, partialTicks);
|
||||
|
||||
progressBar.drawProgressBar();
|
||||
|
||||
startUploadButton.drawOverlay(mc, mouseX, mouseY);
|
||||
|
||||
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);
|
||||
content.mouseClick(mc, mouseX, mouseY, mouseButton);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateScreen() {
|
||||
content.tick(mc);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onGuiClosed() {
|
||||
ResourceHelper.freeAllResources();
|
||||
Keyboard.enableRepeatEvents(false);
|
||||
super.onGuiClosed();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void keyTyped(char typedChar, int keyCode) throws IOException {
|
||||
org.lwjgl.util.Point mouse = MouseUtils.getMousePos();
|
||||
content.buttonPressed(mc, mouse.getX(), mouse.getY(), typedChar, keyCode);
|
||||
|
||||
if(uploader.isUploading()) {
|
||||
startUploadButton.enabled = false;
|
||||
} else {
|
||||
validateStartButton();
|
||||
}
|
||||
}
|
||||
|
||||
private void validateStartButton() {
|
||||
boolean enabled = true;
|
||||
if(name.getText().trim().length() < 5 || name.getText().trim().length() > 30) {
|
||||
enabled = false;
|
||||
name.setTextColor(Color.RED.getRGB());
|
||||
startUploadButton.hoverText = I18n.format("replaymod.gui.upload.error.name.length");
|
||||
} else if(!RegexUtils.isValid(RegexUtils.ALPHANUMERIC_SPACE_HYPHEN_UNDERSCORE, name.getText())) {
|
||||
enabled = false;
|
||||
name.setTextColor(Color.RED.getRGB());
|
||||
startUploadButton.hoverText = I18n.format("replaymod.gui.upload.error.name");
|
||||
} else if(!RegexUtils.isValid(RegexUtils.ALPHANUMERIC_COMMA, tags.getText())) {
|
||||
enabled = false;
|
||||
tags.setTextColor(Color.RED.getRGB());
|
||||
startUploadButton.hoverText = I18n.format("replaymod.gui.upload.error.tags");
|
||||
} else {
|
||||
name.setTextColor(Color.WHITE.getRGB());
|
||||
tags.setTextColor(Color.WHITE.getRGB());
|
||||
startUploadButton.hoverText = null;
|
||||
}
|
||||
|
||||
if(lockUploadButton) enabled = false;
|
||||
|
||||
startUploadButton.enabled = enabled;
|
||||
}
|
||||
|
||||
public void onStartUploading() {
|
||||
startUploadButton.enabled = false;
|
||||
cancelUploadButton.enabled = true;
|
||||
backButton.enabled = false;
|
||||
category.enabled = false;
|
||||
name.setElementEnabled(false);
|
||||
description.enabled = false;
|
||||
messageTextField.setText(I18n.format("replaymod.gui.upload.uploading"));
|
||||
messageTextField.setTextColor(Color.WHITE.getRGB());
|
||||
}
|
||||
|
||||
public void onFinishUploading(boolean success, String info) {
|
||||
validateStartButton();
|
||||
cancelUploadButton.enabled = false;
|
||||
backButton.enabled = true;
|
||||
category.enabled = true;
|
||||
name.setElementEnabled(true);
|
||||
description.enabled = true;
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProgressChanged(float progress) {
|
||||
if(progressBar != null) progressBar.setProgress(progress);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProgressChanged(float progress, String progressString) {}
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
package eu.crushedpixel.replaymod.gui.online;
|
||||
|
||||
import eu.crushedpixel.replaymod.gui.elements.GuiReplayListExtended;
|
||||
import net.minecraft.client.Minecraft;
|
||||
|
||||
public class ReplayFileList extends GuiReplayListExtended {
|
||||
|
||||
private GuiReplayCenter parent;
|
||||
|
||||
public ReplayFileList(Minecraft mcIn, int p_i45010_2_, int p_i45010_3_,
|
||||
int p_i45010_4_, int p_i45010_5_, GuiReplayCenter parent) {
|
||||
super(mcIn, p_i45010_2_, p_i45010_3_, p_i45010_4_, p_i45010_5_, 50);
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void elementClicked(int slotIndex, boolean isDoubleClick, int mouseX, int mouseY) {
|
||||
super.elementClicked(slotIndex, isDoubleClick, mouseX, mouseY);
|
||||
parent.elementSelected(slotIndex);
|
||||
}
|
||||
}
|
||||
@@ -1,81 +0,0 @@
|
||||
package eu.crushedpixel.replaymod.localization;
|
||||
|
||||
import com.google.common.base.Charsets;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.replaymod.core.ReplayMod;
|
||||
import eu.crushedpixel.replaymod.api.ApiException;
|
||||
import net.minecraft.client.resources.IResourcePack;
|
||||
import net.minecraft.client.resources.data.IMetadataSection;
|
||||
import net.minecraft.client.resources.data.IMetadataSerializer;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import org.apache.commons.lang3.StringEscapeUtils;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.ConnectException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class LocalizedResourcePack implements IResourcePack {
|
||||
|
||||
private Map<String, String> availableLanguages = new HashMap<String, String>();
|
||||
private boolean websiteAvailable = true;
|
||||
|
||||
@Override
|
||||
public InputStream getInputStream(ResourceLocation loc) {
|
||||
if(!loc.getResourcePath().endsWith(".lang")) return null;
|
||||
String langcode = loc.getResourcePath().split("/")[1].split("\\.")[0];
|
||||
if(availableLanguages.containsKey(langcode)) return new ByteArrayInputStream(availableLanguages.get(langcode).getBytes(Charsets.UTF_8));
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean resourceExists(ResourceLocation loc) {
|
||||
if(!(loc.getResourcePath().endsWith(".lang"))) return false;
|
||||
String langcode = loc.getResourcePath().split("/")[1].split("\\.")[0];
|
||||
if(availableLanguages.containsKey(langcode)) return true;
|
||||
if(!websiteAvailable) return false;
|
||||
try {
|
||||
if (Boolean.parseBoolean(System.getProperty("replaymod.offline", "false"))) {
|
||||
return false;
|
||||
}
|
||||
String lang = ReplayMod.apiClient.getTranslation(langcode);
|
||||
String prop = StringEscapeUtils.unescapeHtml4(lang);
|
||||
availableLanguages.put(langcode, prop);
|
||||
return true;
|
||||
} catch (ApiException e) {
|
||||
if (e.getError().getId() != 16) { // This language has not been translated
|
||||
e.printStackTrace();
|
||||
}
|
||||
} catch(ConnectException ce) {
|
||||
websiteAvailable = false;
|
||||
ce.printStackTrace();
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set getResourceDomains() {
|
||||
return ImmutableSet.of("minecraft", "replaymod");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMetadataSection getPackMetadata(IMetadataSerializer p_135058_1_, String p_135058_2_) throws IOException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BufferedImage getPackImage() throws IOException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPackName() {
|
||||
return "ReplayModLocalizationResourcePack";
|
||||
}
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
package eu.crushedpixel.replaymod.online.authentication;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
public class AuthenticationHash {
|
||||
|
||||
private static final Random random = new Random();
|
||||
|
||||
public AuthenticationHash() {
|
||||
username = Minecraft.getMinecraft().getSession().getUsername();
|
||||
currentTime = System.currentTimeMillis();
|
||||
randomLong = random.nextLong();
|
||||
hash = getAuthenticationHash();
|
||||
}
|
||||
|
||||
public final String username;
|
||||
public final long currentTime;
|
||||
public final long randomLong;
|
||||
public final String hash;
|
||||
|
||||
private String getAuthenticationHash() {
|
||||
String md5 = username + currentTime + randomLong;
|
||||
|
||||
try {
|
||||
java.security.MessageDigest md = java.security.MessageDigest.getInstance("MD5");
|
||||
byte[] array = md.digest(md5.getBytes());
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (byte b : array) {
|
||||
sb.append(Integer.toHexString((b & 0xFF) | 0x100).substring(1, 3));
|
||||
}
|
||||
return sb.toString();
|
||||
} catch (java.security.NoSuchAlgorithmException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
package eu.crushedpixel.replaymod.online.authentication;
|
||||
|
||||
import eu.crushedpixel.replaymod.api.ApiClient;
|
||||
import eu.crushedpixel.replaymod.api.AuthData;
|
||||
import eu.crushedpixel.replaymod.api.replay.holders.AuthConfirmation;
|
||||
import net.minecraftforge.common.config.Configuration;
|
||||
import net.minecraftforge.common.config.Property;
|
||||
|
||||
/**
|
||||
* Auth data stored in a {@link Configuration}.
|
||||
*/
|
||||
public class ConfigurationAuthData implements AuthData {
|
||||
|
||||
private final Configuration config;
|
||||
private String userName;
|
||||
private String authKey;
|
||||
|
||||
public ConfigurationAuthData(Configuration config) {
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the data from the configuration and checks for its validity.
|
||||
* If the data is invalid, it is removed from the config.
|
||||
* @param apiClient Api client used for validating the auth data
|
||||
*/
|
||||
public void load(ApiClient apiClient) {
|
||||
Property property = config.get("authkey", "authkey", (String) null);
|
||||
if (property != null) {
|
||||
String authKey = property.getString();
|
||||
AuthConfirmation result = apiClient.checkAuthkey(authKey);
|
||||
if (result != null) {
|
||||
this.authKey = authKey;
|
||||
this.userName = result.getUsername();
|
||||
} else {
|
||||
setData(null, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUserName() {
|
||||
return userName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAuthKey() {
|
||||
return authKey;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setData(String userName, String authKey) {
|
||||
this.userName = userName;
|
||||
this.authKey = authKey;
|
||||
|
||||
config.removeCategory(config.getCategory("authkey"));
|
||||
if (authKey != null) {
|
||||
// Note: .get() actually creates the entry with the default value if it doesn't exist
|
||||
config.get("authkey", "authkey", authKey);
|
||||
}
|
||||
config.save();
|
||||
}
|
||||
}
|
||||
@@ -1,74 +0,0 @@
|
||||
package eu.crushedpixel.replaymod.registry;
|
||||
|
||||
import com.replaymod.core.ReplayMod;
|
||||
import eu.crushedpixel.replaymod.gui.elements.listeners.ProgressUpdateListener;
|
||||
import eu.crushedpixel.replaymod.utils.ReplayFileIO;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class DownloadedFileHandler {
|
||||
|
||||
private HashMap<Integer, File> downloadedFiles = new HashMap<Integer, File>();
|
||||
|
||||
private File downloadFolder;
|
||||
|
||||
public DownloadedFileHandler() {
|
||||
try {
|
||||
downloadFolder = ReplayFileIO.getReplayDownloadFolder();
|
||||
|
||||
for(File f : FileUtils.listFiles(downloadFolder, new String[]{"mcpr"}, false)) {
|
||||
try {
|
||||
int id = Integer.parseInt(FilenameUtils.getBaseName(f.getAbsolutePath()));
|
||||
downloadedFiles.put(id, f);
|
||||
} catch(NumberFormatException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private File generateFileForID(int id) {
|
||||
return new File(downloadFolder, id+ ".zip");
|
||||
}
|
||||
|
||||
public void addToIndex(int id) {
|
||||
try {
|
||||
File f = generateFileForID(id);
|
||||
if(f.exists()) downloadedFiles.put(id, f);
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public File getFileForID(int id) {
|
||||
return downloadedFiles.get(id);
|
||||
}
|
||||
|
||||
public File downloadFileForID(int id, ProgressUpdateListener progressUpdateListener) {
|
||||
File f = getFileForID(id);
|
||||
if(f != null) return f;
|
||||
|
||||
f = generateFileForID(id);
|
||||
|
||||
try {
|
||||
ReplayMod.apiClient.downloadFile(id, f, progressUpdateListener);
|
||||
if(f.exists()) {
|
||||
addToIndex(id);
|
||||
}
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return f;
|
||||
}
|
||||
|
||||
public HashMap<Integer, File> getDownloadedFiles() {
|
||||
return downloadedFiles;
|
||||
}
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
package eu.crushedpixel.replaymod.registry;
|
||||
|
||||
import com.google.common.primitives.Ints;
|
||||
import com.replaymod.core.ReplayMod;
|
||||
import eu.crushedpixel.replaymod.api.ApiException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class FavoritedFileHandler {
|
||||
|
||||
private List<Integer> favorited = new ArrayList<Integer>();
|
||||
|
||||
boolean retrieved = false;
|
||||
|
||||
public FavoritedFileHandler() {
|
||||
reloadFavorites();
|
||||
}
|
||||
|
||||
public List<Integer> getFavorited() { return favorited; }
|
||||
|
||||
public boolean isFavorited(int id) {
|
||||
return favorited.contains(id);
|
||||
}
|
||||
|
||||
public void addToFavorites(Integer id) throws IOException, ApiException {
|
||||
ReplayMod.apiClient.favFile(id, true);
|
||||
favorited.remove(id);
|
||||
favorited.add(id);
|
||||
}
|
||||
|
||||
public void removeFromFavorites(Integer id) throws IOException, ApiException {
|
||||
ReplayMod.apiClient.favFile(id, false);
|
||||
favorited.remove(id);
|
||||
}
|
||||
|
||||
public void reloadFavorites() {
|
||||
if(ReplayMod.apiClient.isLoggedIn()) {
|
||||
try {
|
||||
int[] ids = ReplayMod.apiClient.getFavorites();
|
||||
favorited = new ArrayList<Integer>(Ints.asList(ids));
|
||||
retrieved = true;
|
||||
} catch(Exception e) {
|
||||
retrieved = false;
|
||||
favorited = new ArrayList<Integer>();
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
retrieved = false;
|
||||
favorited = new ArrayList<Integer>();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
package eu.crushedpixel.replaymod.registry;
|
||||
|
||||
import com.replaymod.core.ReplayMod;
|
||||
import eu.crushedpixel.replaymod.api.ApiException;
|
||||
import eu.crushedpixel.replaymod.api.replay.holders.FileRating;
|
||||
import eu.crushedpixel.replaymod.api.replay.holders.Rating;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class RatedFileHandler {
|
||||
|
||||
private HashMap<Integer, Boolean> rated = new HashMap<Integer, Boolean>();
|
||||
|
||||
boolean retrieved = false;
|
||||
|
||||
public RatedFileHandler() {
|
||||
reloadRatings();
|
||||
}
|
||||
|
||||
public Rating.RatingType getRating(int id) {
|
||||
return Rating.RatingType.fromBoolean(rated.get(id));
|
||||
}
|
||||
|
||||
public void rateFile(int id, Rating.RatingType type) throws IOException, ApiException {
|
||||
ReplayMod.apiClient.rateFile(id, type);
|
||||
if(type == Rating.RatingType.LIKE || type == Rating.RatingType.DISLIKE) {
|
||||
rated.put(id, type == Rating.RatingType.LIKE);
|
||||
} else {
|
||||
rated.remove(id);
|
||||
}
|
||||
}
|
||||
|
||||
public void reloadRatings() {
|
||||
if(ReplayMod.apiClient.isLoggedIn()) {
|
||||
try {
|
||||
FileRating[] ratings = ReplayMod.apiClient.getRatedFiles();
|
||||
rated = new HashMap<Integer, Boolean>();
|
||||
|
||||
for(FileRating fr : ratings) {
|
||||
rated.put(fr.getFile(), fr.isRatingPositive());
|
||||
}
|
||||
|
||||
retrieved = true;
|
||||
} catch(Exception e) {
|
||||
retrieved = false;
|
||||
rated = new HashMap<Integer, Boolean>();
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
retrieved = false;
|
||||
rated = new HashMap<Integer, Boolean>();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user