From 3ad765db6c7805453024ef4d27b5ebbf0963c637 Mon Sep 17 00:00:00 2001 From: CrushedPixel Date: Mon, 11 May 2015 16:50:34 +0200 Subject: [PATCH] Started adding support for downloading online files --- build.gradle | 2 +- gradle/wrapper/gradle-wrapper.properties | 4 +- .../eu/crushedpixel/replaymod/ReplayMod.java | 22 +++---- .../replaymod/gui/GuiConstants.java | 4 ++ .../gui/elements/GuiReplayListExtended.java | 4 ++ .../replaymod/gui/online/GuiReplayCenter.java | 58 +++++++++++++++++-- .../replaymod/gui/online/ReplayFileList.java | 11 +++- .../registry/DownloadedFileHandler.java | 43 ++++++++++++++ .../replaymod/replay/ReplaySender.java | 14 ++++- .../replaymod/settings/ReplaySettings.java | 10 ++-- .../assets/replaymod/lang/en_US.lang | 6 ++ 11 files changed, 153 insertions(+), 25 deletions(-) create mode 100644 src/main/java/eu/crushedpixel/replaymod/registry/DownloadedFileHandler.java diff --git a/build.gradle b/build.gradle index 7216917e..cc41ed11 100755 --- a/build.gradle +++ b/build.gradle @@ -24,7 +24,7 @@ group= "eu.crushedpixel.replaymod" archivesBaseName = "replaymod" minecraft { - version = "1.8-11.14.0.1255-1.8" + version = "1.8-11.14.1.1402" runDir = "eclipse" // the mappings can be changed at any time, and must be in the following format. diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 6d32b3d9..238f78bc 100755 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Wed Jul 02 15:54:47 CDT 2014 +#Sun May 10 21:57:58 CEST 2015 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME 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 diff --git a/src/main/java/eu/crushedpixel/replaymod/ReplayMod.java b/src/main/java/eu/crushedpixel/replaymod/ReplayMod.java index 99c70ff3..df6f1607 100755 --- a/src/main/java/eu/crushedpixel/replaymod/ReplayMod.java +++ b/src/main/java/eu/crushedpixel/replaymod/ReplayMod.java @@ -140,18 +140,18 @@ public class ReplayMod { /* boolean auth = false; - try { - auth = AuthenticationHandler.hasDonated(Minecraft.getMinecraft().getSession().getPlayerID()); - } catch(Exception e) { - JOptionPane.showMessageDialog(null, "Couldn't connect to the Replay Mod Server to verify whether you donated!"); - FMLCommonHandler.instance().exitJava(0, false); - } + try { + auth = AuthenticationHandler.hasDonated(Minecraft.getMinecraft().getSession().getPlayerID()); + } catch(Exception e) { + JOptionPane.showMessageDialog(null, "Couldn't connect to the Replay Mod Server to verify whether you donated!"); + FMLCommonHandler.instance().exitJava(0, false); + } - if(!auth) { - JOptionPane.showMessageDialog(null, "It seems like you didn't donate, so you can't use the Replay Mod yet."); - FMLCommonHandler.instance().exitJava(0, false); - } - */ + if(!auth) { + JOptionPane.showMessageDialog(null, "It seems like you didn't donate, so you can't use the Replay Mod yet."); + FMLCommonHandler.instance().exitJava(0, false); + } + */ } private void removeTmcprFiles() { diff --git a/src/main/java/eu/crushedpixel/replaymod/gui/GuiConstants.java b/src/main/java/eu/crushedpixel/replaymod/gui/GuiConstants.java index a5486672..af7c2e3b 100755 --- a/src/main/java/eu/crushedpixel/replaymod/gui/GuiConstants.java +++ b/src/main/java/eu/crushedpixel/replaymod/gui/GuiConstants.java @@ -9,6 +9,10 @@ public class GuiConstants { public static final int CENTER_RECENT_BUTTON = 2005; public static final int CENTER_BEST_BUTTON = 2006; 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_CATEGORY_BUTTON = 3002; diff --git a/src/main/java/eu/crushedpixel/replaymod/gui/elements/GuiReplayListExtended.java b/src/main/java/eu/crushedpixel/replaymod/gui/elements/GuiReplayListExtended.java index 85f43179..9d038227 100755 --- a/src/main/java/eu/crushedpixel/replaymod/gui/elements/GuiReplayListExtended.java +++ b/src/main/java/eu/crushedpixel/replaymod/gui/elements/GuiReplayListExtended.java @@ -82,6 +82,10 @@ public abstract class GuiReplayListExtended extends GuiListExtended { return entries.get(index); } + public List getEntries() { + return entries; + } + @Override protected int getSize() { return entries.size(); diff --git a/src/main/java/eu/crushedpixel/replaymod/gui/online/GuiReplayCenter.java b/src/main/java/eu/crushedpixel/replaymod/gui/online/GuiReplayCenter.java index dd788350..08aee344 100755 --- a/src/main/java/eu/crushedpixel/replaymod/gui/online/GuiReplayCenter.java +++ b/src/main/java/eu/crushedpixel/replaymod/gui/online/GuiReplayCenter.java @@ -5,7 +5,7 @@ import eu.crushedpixel.replaymod.api.client.SearchPagination; import eu.crushedpixel.replaymod.api.client.SearchQuery; import eu.crushedpixel.replaymod.api.client.holders.FileInfo; 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.online.authentication.AuthenticationHandler; 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 final SearchPagination recentFilePagination = new SearchPagination(recentFileSearchQuery); private final SearchPagination bestFilePagination = new SearchPagination(bestFileSearchQuery); - private GuiReplayListExtended currentList; + private ReplayFileList currentList; private ReplayFileList recentFileList, bestFileList, myFileList, searchFileList; private Tab currentTab = Tab.RECENT_FILES; private SearchPagination myFilePagination; + private GuiButton loadButton, favButton, likeButton, dislikeButton; + private List replayButtonBar; public static GuiYesNo getYesNoGui(GuiYesNoCallback p_152129_0_, int p_152129_2_) { String s1 = I18n.format("replaymod.gui.center.logoutcallback"); @@ -81,6 +83,38 @@ public class GuiReplayCenter extends GuiScreen implements GuiYesNoCallback { i++; } + //Replay specific actions (load, rate, etc) + replayButtonBar = new ArrayList(); + + 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) List bottomBar = new ArrayList(); @@ -111,6 +145,20 @@ public class GuiReplayCenter extends GuiScreen implements GuiYesNoCallback { 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 protected void actionPerformed(GuiButton button) throws java.io.IOException { if(!button.enabled) return; @@ -128,6 +176,8 @@ public class GuiReplayCenter extends GuiScreen implements GuiYesNoCallback { showOnlineOwnFiles(); } 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) { currentList = list; 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 { currentList.clearEntries(); currentList.width = width; currentList.height = height; currentList.top = 50; - currentList.bottom = height - 40; + currentList.bottom = height - 70; } if(pagination.getLoadedPages() < 0) { diff --git a/src/main/java/eu/crushedpixel/replaymod/gui/online/ReplayFileList.java b/src/main/java/eu/crushedpixel/replaymod/gui/online/ReplayFileList.java index 8581e59d..57fe175c 100755 --- a/src/main/java/eu/crushedpixel/replaymod/gui/online/ReplayFileList.java +++ b/src/main/java/eu/crushedpixel/replaymod/gui/online/ReplayFileList.java @@ -5,8 +5,17 @@ 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_, 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_); + this.parent = parent; + } + + @Override + protected void elementClicked(int slotIndex, boolean isDoubleClick, int mouseX, int mouseY) { + super.elementClicked(slotIndex, isDoubleClick, mouseX, mouseY); + parent.elementSelected(slotIndex); } } diff --git a/src/main/java/eu/crushedpixel/replaymod/registry/DownloadedFileHandler.java b/src/main/java/eu/crushedpixel/replaymod/registry/DownloadedFileHandler.java new file mode 100644 index 00000000..fc293155 --- /dev/null +++ b/src/main/java/eu/crushedpixel/replaymod/registry/DownloadedFileHandler.java @@ -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 downloadedFiles = new HashMap(); + + 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); + } +} diff --git a/src/main/java/eu/crushedpixel/replaymod/replay/ReplaySender.java b/src/main/java/eu/crushedpixel/replaymod/replay/ReplaySender.java index 85de915e..8938d12f 100755 --- a/src/main/java/eu/crushedpixel/replaymod/replay/ReplaySender.java +++ b/src/main/java/eu/crushedpixel/replaymod/replay/ReplaySender.java @@ -83,12 +83,15 @@ public class ReplaySender extends ChannelInboundHandlerAdapter { e.printStackTrace(); } + int i=0; + try { while(ctx == null && !terminate) { Thread.sleep(10); } while(!terminate) { if(startFromBeginning) { + System.out.println("start from beginning"); hasRestarted = true; hasWorldLoaded = false; currentTimeStamp = 0; @@ -100,6 +103,7 @@ public class ReplaySender extends ChannelInboundHandlerAdapter { } while(!terminate && !startFromBeginning && (!paused() || !hasWorldLoaded)) { + //System.out.println("read"); try { /* * LOGIC: @@ -133,7 +137,8 @@ public class ReplaySender extends ChannelInboundHandlerAdapter { lastTimeStamp = currentTimeStamp; if(hurryToTimestamp && currentTimeStamp >= desiredTimeStamp && !startFromBeginning) { - hurryToTimestamp = false; + System.out.println("STOPPED HURRYING"); + stopHurrying(); if(!ReplayHandler.isInPath() || hasRestarted) { MCTimerHandler.advanceRenderPartialTicks(5); MCTimerHandler.advancePartialTicks(5); @@ -164,7 +169,9 @@ public class ReplaySender extends ChannelInboundHandlerAdapter { e.printStackTrace(); } } + } + System.out.println("STOPPED FOREVER"); } catch(Exception e) { e.printStackTrace(); } @@ -245,23 +252,26 @@ public class ReplaySender extends ChannelInboundHandlerAdapter { } public void jumpToTime(int millis) { + System.out.println("Jumped to "+millis); if(!(ReplayHandler.isInPath() && ReplayProcess.isVideoRecording())) setReplaySpeed(replaySpeed); if((millis < currentTimeStamp && !isHurrying())) { if(ReplayHandler.isInPath()) { if(millis >= toleratedTimeStamp && toleratedTimeStamp >= 0) { + System.out.println("tolerated: "+toleratedTimeStamp); return; } } startFromBeginning = true; + System.out.println("has to start from beginning"); } desiredTimeStamp = millis; + System.out.println("Set desired Timestamp"); if(ReplayHandler.isInPath()) { toleratedTimeStamp = millis; } hurryToTimestamp = true; - } //private static Field dataWatcherField; diff --git a/src/main/java/eu/crushedpixel/replaymod/settings/ReplaySettings.java b/src/main/java/eu/crushedpixel/replaymod/settings/ReplaySettings.java index 62398404..6f2540d9 100755 --- a/src/main/java/eu/crushedpixel/replaymod/settings/ReplaySettings.java +++ b/src/main/java/eu/crushedpixel/replaymod/settings/ReplaySettings.java @@ -56,6 +56,8 @@ public class ReplaySettings { return (String) AdvancedOptions.renderPath.getValue(); } + public String getDownloadPath() { return (String) AdvancedOptions.downloadPath.getValue(); } + public int getVideoFramerate() { return (Integer) RenderOptions.videoFramerate.getValue(); } @@ -270,7 +272,7 @@ public class ReplaySettings { } public enum AdvancedOptions implements ValueEnum { - recordingPath("./replay_recordings/"), renderPath("./replay_videos/"); + recordingPath("./replay_recordings/"), renderPath("./replay_videos/"), downloadPath("./replay_downloads"); private Object value; @@ -287,9 +289,9 @@ public class ReplaySettings { } } - public static interface ValueEnum { - public Object getValue(); + public interface ValueEnum { + Object getValue(); - public void setValue(Object value); + void setValue(Object value); } } diff --git a/src/main/resources/assets/replaymod/lang/en_US.lang b/src/main/resources/assets/replaymod/lang/en_US.lang index c93277f5..826eb1f2 100644 --- a/src/main/resources/assets/replaymod/lang/en_US.lang +++ b/src/main/resources/assets/replaymod/lang/en_US.lang @@ -55,6 +55,9 @@ replaymod.gui.password=Password replaymod.gui.back=Back replaymod.gui.duration=Duration replaymod.gui.load=Load +replaymod.gui.download=Download +replaymod.gui.like=Like +replaymod.gui.dislike=Dislike replaymod.gui.save=Save replaymod.gui.upload=Upload replaymod.gui.rename=Rename @@ -121,6 +124,9 @@ replaymod.gui.center.best=Best Replays replaymod.gui.center.my=My Replays replaymod.gui.center.search=Search Replays +replaymod.gui.center.favorite=Favorite +replaymod.gui.center.favorites=Favorites + #Upload GUI replaymod.gui.upload.title=Upload File replaymod.gui.upload.start=Start Upload