Started adding support for downloading online files

This commit is contained in:
CrushedPixel
2015-05-11 16:50:34 +02:00
parent 2fe3e2091b
commit 3ad765db6c
11 changed files with 153 additions and 25 deletions

View File

@@ -24,7 +24,7 @@ group= "eu.crushedpixel.replaymod"
archivesBaseName = "replaymod" archivesBaseName = "replaymod"
minecraft { minecraft {
version = "1.8-11.14.0.1255-1.8" version = "1.8-11.14.1.1402"
runDir = "eclipse" runDir = "eclipse"
// the mappings can be changed at any time, and must be in the following format. // the mappings can be changed at any time, and must be in the following format.

View File

@@ -1,6 +1,6 @@
#Wed Jul 02 15:54:47 CDT 2014 #Sun May 10 21:57:58 CEST 2015
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists
distributionUrl=http\://services.gradle.org/distributions/gradle-2.0-bin.zip distributionUrl=http\://services.gradle.org/distributions/gradle-2.0-all.zip

View File

@@ -140,18 +140,18 @@ public class ReplayMod {
/* /*
boolean auth = false; boolean auth = false;
try { try {
auth = AuthenticationHandler.hasDonated(Minecraft.getMinecraft().getSession().getPlayerID()); auth = AuthenticationHandler.hasDonated(Minecraft.getMinecraft().getSession().getPlayerID());
} catch(Exception e) { } catch(Exception e) {
JOptionPane.showMessageDialog(null, "Couldn't connect to the Replay Mod Server to verify whether you donated!"); JOptionPane.showMessageDialog(null, "Couldn't connect to the Replay Mod Server to verify whether you donated!");
FMLCommonHandler.instance().exitJava(0, false); FMLCommonHandler.instance().exitJava(0, false);
} }
if(!auth) { if(!auth) {
JOptionPane.showMessageDialog(null, "It seems like you didn't donate, so you can't use the Replay Mod yet."); JOptionPane.showMessageDialog(null, "It seems like you didn't donate, so you can't use the Replay Mod yet.");
FMLCommonHandler.instance().exitJava(0, false); FMLCommonHandler.instance().exitJava(0, false);
} }
*/ */
} }
private void removeTmcprFiles() { private void removeTmcprFiles() {

View File

@@ -9,6 +9,10 @@ public class GuiConstants {
public static final int CENTER_RECENT_BUTTON = 2005; public static final int CENTER_RECENT_BUTTON = 2005;
public static final int CENTER_BEST_BUTTON = 2006; public static final int CENTER_BEST_BUTTON = 2006;
public static final int CENTER_MANAGER_BUTTON = 2007; public static final int CENTER_MANAGER_BUTTON = 2007;
public static final int CENTER_LOAD_REPLAY_BUTTON = 2008;
public static final int CENTER_FAV_REPLAY_BUTTON = 2009;
public static final int CENTER_LIKE_REPLAY_BUTTON = 2010;
public static final int CENTER_DISLIKE_REPLAY_BUTTON = 2011;
public static final int UPLOAD_NAME_INPUT = 3001; public static final int UPLOAD_NAME_INPUT = 3001;
public static final int UPLOAD_CATEGORY_BUTTON = 3002; public static final int UPLOAD_CATEGORY_BUTTON = 3002;

View File

@@ -82,6 +82,10 @@ public abstract class GuiReplayListExtended extends GuiListExtended {
return entries.get(index); return entries.get(index);
} }
public List<GuiReplayListEntry> getEntries() {
return entries;
}
@Override @Override
protected int getSize() { protected int getSize() {
return entries.size(); return entries.size();

View File

@@ -5,7 +5,7 @@ import eu.crushedpixel.replaymod.api.client.SearchPagination;
import eu.crushedpixel.replaymod.api.client.SearchQuery; import eu.crushedpixel.replaymod.api.client.SearchQuery;
import eu.crushedpixel.replaymod.api.client.holders.FileInfo; import eu.crushedpixel.replaymod.api.client.holders.FileInfo;
import eu.crushedpixel.replaymod.gui.GuiConstants; import eu.crushedpixel.replaymod.gui.GuiConstants;
import eu.crushedpixel.replaymod.gui.elements.GuiReplayListExtended; import eu.crushedpixel.replaymod.gui.elements.GuiReplayListEntry;
import eu.crushedpixel.replaymod.gui.replayviewer.GuiReplayViewer; import eu.crushedpixel.replaymod.gui.replayviewer.GuiReplayViewer;
import eu.crushedpixel.replaymod.online.authentication.AuthenticationHandler; import eu.crushedpixel.replaymod.online.authentication.AuthenticationHandler;
import net.minecraft.client.gui.*; import net.minecraft.client.gui.*;
@@ -27,10 +27,12 @@ public class GuiReplayCenter extends GuiScreen implements GuiYesNoCallback {
private static final int LOGOUT_CALLBACK_ID = 1; private static final int LOGOUT_CALLBACK_ID = 1;
private final SearchPagination recentFilePagination = new SearchPagination(recentFileSearchQuery); private final SearchPagination recentFilePagination = new SearchPagination(recentFileSearchQuery);
private final SearchPagination bestFilePagination = new SearchPagination(bestFileSearchQuery); private final SearchPagination bestFilePagination = new SearchPagination(bestFileSearchQuery);
private GuiReplayListExtended currentList; private ReplayFileList currentList;
private ReplayFileList recentFileList, bestFileList, myFileList, searchFileList; private ReplayFileList recentFileList, bestFileList, myFileList, searchFileList;
private Tab currentTab = Tab.RECENT_FILES; private Tab currentTab = Tab.RECENT_FILES;
private SearchPagination myFilePagination; private SearchPagination myFilePagination;
private GuiButton loadButton, favButton, likeButton, dislikeButton;
private List<GuiButton> replayButtonBar;
public static GuiYesNo getYesNoGui(GuiYesNoCallback p_152129_0_, int p_152129_2_) { public static GuiYesNo getYesNoGui(GuiYesNoCallback p_152129_0_, int p_152129_2_) {
String s1 = I18n.format("replaymod.gui.center.logoutcallback"); String s1 = I18n.format("replaymod.gui.center.logoutcallback");
@@ -81,6 +83,38 @@ public class GuiReplayCenter extends GuiScreen implements GuiYesNoCallback {
i++; i++;
} }
//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);
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++;
}
//Bottom Button Bar (dat alliteration) //Bottom Button Bar (dat alliteration)
List<GuiButton> bottomBar = new ArrayList<GuiButton>(); List<GuiButton> bottomBar = new ArrayList<GuiButton>();
@@ -111,6 +145,20 @@ public class GuiReplayCenter extends GuiScreen implements GuiYesNoCallback {
showOnlineRecent(); showOnlineRecent();
} }
public void elementSelected(int index) {
GuiReplayListEntry entry = currentList.getListEntry(index);
FileInfo info = entry.getFileInfo();
if(info != null) {
boolean downloaded = false;
loadButton.displayString = downloaded ? I18n.format("replaymod.gui.load") : I18n.format("replaymod.gui.download");
loadButton.enabled = true;
} else {
for(GuiButton b : replayButtonBar) {
b.enabled = false;
}
}
}
@Override @Override
protected void actionPerformed(GuiButton button) throws java.io.IOException { protected void actionPerformed(GuiButton button) throws java.io.IOException {
if(!button.enabled) return; if(!button.enabled) return;
@@ -128,6 +176,8 @@ public class GuiReplayCenter extends GuiScreen implements GuiYesNoCallback {
showOnlineOwnFiles(); showOnlineOwnFiles();
} else if(button.id == GuiConstants.CENTER_SEARCH_BUTTON) { } else if(button.id == GuiConstants.CENTER_SEARCH_BUTTON) {
} else if(button.id == GuiConstants.CENTER_LOAD_REPLAY_BUTTON) {
} }
} }
@@ -192,13 +242,13 @@ public class GuiReplayCenter extends GuiScreen implements GuiYesNoCallback {
private void updateCurrentList(ReplayFileList list, SearchPagination pagination) { private void updateCurrentList(ReplayFileList list, SearchPagination pagination) {
currentList = list; currentList = list;
if(currentList == null) { if(currentList == null) {
currentList = new ReplayFileList(mc, width, height, 50, height - 40, 36); currentList = new ReplayFileList(mc, width, height, 50, height - 70, 36, this);
} else { } else {
currentList.clearEntries(); currentList.clearEntries();
currentList.width = width; currentList.width = width;
currentList.height = height; currentList.height = height;
currentList.top = 50; currentList.top = 50;
currentList.bottom = height - 40; currentList.bottom = height - 70;
} }
if(pagination.getLoadedPages() < 0) { if(pagination.getLoadedPages() < 0) {

View File

@@ -5,8 +5,17 @@ import net.minecraft.client.Minecraft;
public class ReplayFileList extends GuiReplayListExtended { public class ReplayFileList extends GuiReplayListExtended {
private GuiReplayCenter parent;
public ReplayFileList(Minecraft mcIn, int p_i45010_2_, int p_i45010_3_, public ReplayFileList(Minecraft mcIn, int p_i45010_2_, int p_i45010_3_,
int p_i45010_4_, int p_i45010_5_, int p_i45010_6_) { int p_i45010_4_, int p_i45010_5_, int p_i45010_6_, GuiReplayCenter parent) {
super(mcIn, p_i45010_2_, p_i45010_3_, p_i45010_4_, p_i45010_5_, p_i45010_6_); super(mcIn, p_i45010_2_, p_i45010_3_, p_i45010_4_, p_i45010_5_, p_i45010_6_);
this.parent = parent;
}
@Override
protected void elementClicked(int slotIndex, boolean isDoubleClick, int mouseX, int mouseY) {
super.elementClicked(slotIndex, isDoubleClick, mouseX, mouseY);
parent.elementSelected(slotIndex);
} }
} }

View File

@@ -0,0 +1,43 @@
package eu.crushedpixel.replaymod.registry;
import eu.crushedpixel.replaymod.ReplayMod;
import eu.crushedpixel.replaymod.recording.ConnectionEventHandler;
import org.apache.commons.io.FilenameUtils;
import java.io.File;
import java.util.HashMap;
public class DownloadedFileHandler {
private HashMap<Integer, File> downloadedFiles = new HashMap<Integer, File>();
private File downloadFolder;
public DownloadedFileHandler() {
downloadFolder = new File(ReplayMod.replaySettings.getDownloadPath());
downloadFolder.mkdirs();
for(File f : downloadFolder.listFiles()) {
try {
Integer i = Integer.valueOf(FilenameUtils.getBaseName(f.getAbsolutePath()));
if(i != null) {
downloadedFiles.put(i, f);
}
} catch(Exception e) {
e.printStackTrace();
}
}
}
public void addToIndex(int id) {
try {
File f = new File(downloadFolder, id+"."+ConnectionEventHandler.ZIP_FILE_EXTENSION);
} catch(Exception e) {
e.printStackTrace();
}
}
public File getFileForID(int id) {
return downloadedFiles.get(id);
}
}

View File

@@ -83,12 +83,15 @@ public class ReplaySender extends ChannelInboundHandlerAdapter {
e.printStackTrace(); e.printStackTrace();
} }
int i=0;
try { try {
while(ctx == null && !terminate) { while(ctx == null && !terminate) {
Thread.sleep(10); Thread.sleep(10);
} }
while(!terminate) { while(!terminate) {
if(startFromBeginning) { if(startFromBeginning) {
System.out.println("start from beginning");
hasRestarted = true; hasRestarted = true;
hasWorldLoaded = false; hasWorldLoaded = false;
currentTimeStamp = 0; currentTimeStamp = 0;
@@ -100,6 +103,7 @@ public class ReplaySender extends ChannelInboundHandlerAdapter {
} }
while(!terminate && !startFromBeginning && (!paused() || !hasWorldLoaded)) { while(!terminate && !startFromBeginning && (!paused() || !hasWorldLoaded)) {
//System.out.println("read");
try { try {
/* /*
* LOGIC: * LOGIC:
@@ -133,7 +137,8 @@ public class ReplaySender extends ChannelInboundHandlerAdapter {
lastTimeStamp = currentTimeStamp; lastTimeStamp = currentTimeStamp;
if(hurryToTimestamp && currentTimeStamp >= desiredTimeStamp && !startFromBeginning) { if(hurryToTimestamp && currentTimeStamp >= desiredTimeStamp && !startFromBeginning) {
hurryToTimestamp = false; System.out.println("STOPPED HURRYING");
stopHurrying();
if(!ReplayHandler.isInPath() || hasRestarted) { if(!ReplayHandler.isInPath() || hasRestarted) {
MCTimerHandler.advanceRenderPartialTicks(5); MCTimerHandler.advanceRenderPartialTicks(5);
MCTimerHandler.advancePartialTicks(5); MCTimerHandler.advancePartialTicks(5);
@@ -164,7 +169,9 @@ public class ReplaySender extends ChannelInboundHandlerAdapter {
e.printStackTrace(); e.printStackTrace();
} }
} }
} }
System.out.println("STOPPED FOREVER");
} catch(Exception e) { } catch(Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
@@ -245,23 +252,26 @@ public class ReplaySender extends ChannelInboundHandlerAdapter {
} }
public void jumpToTime(int millis) { public void jumpToTime(int millis) {
System.out.println("Jumped to "+millis);
if(!(ReplayHandler.isInPath() && ReplayProcess.isVideoRecording())) setReplaySpeed(replaySpeed); if(!(ReplayHandler.isInPath() && ReplayProcess.isVideoRecording())) setReplaySpeed(replaySpeed);
if((millis < currentTimeStamp && !isHurrying())) { if((millis < currentTimeStamp && !isHurrying())) {
if(ReplayHandler.isInPath()) { if(ReplayHandler.isInPath()) {
if(millis >= toleratedTimeStamp && toleratedTimeStamp >= 0) { if(millis >= toleratedTimeStamp && toleratedTimeStamp >= 0) {
System.out.println("tolerated: "+toleratedTimeStamp);
return; return;
} }
} }
startFromBeginning = true; startFromBeginning = true;
System.out.println("has to start from beginning");
} }
desiredTimeStamp = millis; desiredTimeStamp = millis;
System.out.println("Set desired Timestamp");
if(ReplayHandler.isInPath()) { if(ReplayHandler.isInPath()) {
toleratedTimeStamp = millis; toleratedTimeStamp = millis;
} }
hurryToTimestamp = true; hurryToTimestamp = true;
} }
//private static Field dataWatcherField; //private static Field dataWatcherField;

View File

@@ -56,6 +56,8 @@ public class ReplaySettings {
return (String) AdvancedOptions.renderPath.getValue(); return (String) AdvancedOptions.renderPath.getValue();
} }
public String getDownloadPath() { return (String) AdvancedOptions.downloadPath.getValue(); }
public int getVideoFramerate() { public int getVideoFramerate() {
return (Integer) RenderOptions.videoFramerate.getValue(); return (Integer) RenderOptions.videoFramerate.getValue();
} }
@@ -270,7 +272,7 @@ public class ReplaySettings {
} }
public enum AdvancedOptions implements ValueEnum { public enum AdvancedOptions implements ValueEnum {
recordingPath("./replay_recordings/"), renderPath("./replay_videos/"); recordingPath("./replay_recordings/"), renderPath("./replay_videos/"), downloadPath("./replay_downloads");
private Object value; private Object value;
@@ -287,9 +289,9 @@ public class ReplaySettings {
} }
} }
public static interface ValueEnum { public interface ValueEnum {
public Object getValue(); Object getValue();
public void setValue(Object value); void setValue(Object value);
} }
} }

View File

@@ -55,6 +55,9 @@ replaymod.gui.password=Password
replaymod.gui.back=Back replaymod.gui.back=Back
replaymod.gui.duration=Duration replaymod.gui.duration=Duration
replaymod.gui.load=Load replaymod.gui.load=Load
replaymod.gui.download=Download
replaymod.gui.like=Like
replaymod.gui.dislike=Dislike
replaymod.gui.save=Save replaymod.gui.save=Save
replaymod.gui.upload=Upload replaymod.gui.upload=Upload
replaymod.gui.rename=Rename replaymod.gui.rename=Rename
@@ -121,6 +124,9 @@ replaymod.gui.center.best=Best Replays
replaymod.gui.center.my=My Replays replaymod.gui.center.my=My Replays
replaymod.gui.center.search=Search Replays replaymod.gui.center.search=Search Replays
replaymod.gui.center.favorite=Favorite
replaymod.gui.center.favorites=Favorites
#Upload GUI #Upload GUI
replaymod.gui.upload.title=Upload File replaymod.gui.upload.title=Upload File
replaymod.gui.upload.start=Start Upload replaymod.gui.upload.start=Start Upload