From 6196fa3ee9b229b84082565733648201b06b5fa8 Mon Sep 17 00:00:00 2001 From: CrushedPixel Date: Sat, 16 May 2015 18:44:53 +0200 Subject: [PATCH] Added "Downloaded" Tab to Replay Center to be able to open downloaded replays --- .../pagination/DownloadedFilePagination.java | 4 +- .../pagination/FavoritedFilePagination.java | 7 +- .../client/pagination/SearchPagination.java | 2 +- .../replaymod/gui/GuiConstants.java | 3 +- .../replaymod/gui/online/GuiReplayCenter.java | 87 +++++++++++-------- .../registry/DownloadedFileHandler.java | 4 + .../assets/replaymod/lang/en_US.lang | 9 +- 7 files changed, 70 insertions(+), 46 deletions(-) diff --git a/src/main/java/eu/crushedpixel/replaymod/api/client/pagination/DownloadedFilePagination.java b/src/main/java/eu/crushedpixel/replaymod/api/client/pagination/DownloadedFilePagination.java index b1a1f1e0..21d8b6bd 100755 --- a/src/main/java/eu/crushedpixel/replaymod/api/client/pagination/DownloadedFilePagination.java +++ b/src/main/java/eu/crushedpixel/replaymod/api/client/pagination/DownloadedFilePagination.java @@ -40,9 +40,11 @@ public class DownloadedFilePagination implements Pagination { } } + files.keySet().retainAll(f.keySet()); + try { FileInfo[] fis = ReplayMod.apiClient.getFileInfo(toAdd); - if(fis.length <= 1) { + if(fis.length < 1) { page--; return false; } diff --git a/src/main/java/eu/crushedpixel/replaymod/api/client/pagination/FavoritedFilePagination.java b/src/main/java/eu/crushedpixel/replaymod/api/client/pagination/FavoritedFilePagination.java index 2f6ad62f..0a9287b9 100755 --- a/src/main/java/eu/crushedpixel/replaymod/api/client/pagination/FavoritedFilePagination.java +++ b/src/main/java/eu/crushedpixel/replaymod/api/client/pagination/FavoritedFilePagination.java @@ -5,6 +5,7 @@ import eu.crushedpixel.replaymod.api.client.holders.FileInfo; import eu.crushedpixel.replaymod.online.authentication.AuthenticationHandler; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; import java.util.List; @@ -40,9 +41,11 @@ public class FavoritedFilePagination implements Pagination { if(toAdd.size() >= Pagination.PAGE_SIZE) break; } } - + + files.keySet().retainAll(Arrays.asList(f)); + FileInfo[] fis = ReplayMod.apiClient.getFileInfo(toAdd); - if(fis.length <= 1) { + if(fis.length < 1) { page--; return false; } diff --git a/src/main/java/eu/crushedpixel/replaymod/api/client/pagination/SearchPagination.java b/src/main/java/eu/crushedpixel/replaymod/api/client/pagination/SearchPagination.java index 0fbdd114..63e4059b 100755 --- a/src/main/java/eu/crushedpixel/replaymod/api/client/pagination/SearchPagination.java +++ b/src/main/java/eu/crushedpixel/replaymod/api/client/pagination/SearchPagination.java @@ -36,7 +36,7 @@ public class SearchPagination implements Pagination { try { FileInfo[] fis = ReplayMod.apiClient.searchFiles(searchQuery); - if(fis.length <= 1) { + if(fis.length < 1) { page--; return false; } diff --git a/src/main/java/eu/crushedpixel/replaymod/gui/GuiConstants.java b/src/main/java/eu/crushedpixel/replaymod/gui/GuiConstants.java index af7c2e3b..39b20ac6 100755 --- a/src/main/java/eu/crushedpixel/replaymod/gui/GuiConstants.java +++ b/src/main/java/eu/crushedpixel/replaymod/gui/GuiConstants.java @@ -2,7 +2,7 @@ package eu.crushedpixel.replaymod.gui; public class GuiConstants { - public static final int CENTER_MY_REPLAYS_BUTTON = 2001; + public static final int CENTER_DOWNLOADED_REPLAYS_BUTTON = 2001; public static final int CENTER_SEARCH_BUTTON = 2002; public static final int CENTER_BACK_BUTTON = 2003; public static final int CENTER_LOGOUT_BUTTON = 2004; @@ -13,6 +13,7 @@ public class GuiConstants { 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 CENTER_FAVORITED_REPLAYS_BUTTON = 2012; 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/online/GuiReplayCenter.java b/src/main/java/eu/crushedpixel/replaymod/gui/online/GuiReplayCenter.java index b3d39922..a6cfacbc 100755 --- a/src/main/java/eu/crushedpixel/replaymod/gui/online/GuiReplayCenter.java +++ b/src/main/java/eu/crushedpixel/replaymod/gui/online/GuiReplayCenter.java @@ -1,9 +1,12 @@ package eu.crushedpixel.replaymod.gui.online; import eu.crushedpixel.replaymod.ReplayMod; -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.api.client.pagination.DownloadedFilePagination; +import eu.crushedpixel.replaymod.api.client.pagination.FavoritedFilePagination; +import eu.crushedpixel.replaymod.api.client.pagination.Pagination; +import eu.crushedpixel.replaymod.api.client.pagination.SearchPagination; import eu.crushedpixel.replaymod.gui.GuiConstants; import eu.crushedpixel.replaymod.gui.elements.GuiReplayListEntry; import eu.crushedpixel.replaymod.gui.replayviewer.GuiReplayViewer; @@ -26,12 +29,12 @@ public class GuiReplayCenter extends GuiScreen implements GuiYesNoCallback { private static final SearchQuery bestFileSearchQuery = new SearchQuery(true, null, null, null, null, null, null, null, null, null); private static final int LOGOUT_CALLBACK_ID = 1; - private final SearchPagination recentFilePagination = new SearchPagination(recentFileSearchQuery); - private final SearchPagination bestFilePagination = new SearchPagination(bestFileSearchQuery); + private final Pagination recentFilePagination = new SearchPagination(recentFileSearchQuery); + private final Pagination bestFilePagination = new SearchPagination(bestFileSearchQuery); + private final Pagination downloadedFilePagination = new DownloadedFilePagination(); + private final Pagination favoritedFilePagination = new FavoritedFilePagination(); 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, bottomBar, topBar; @@ -49,29 +52,28 @@ public class GuiReplayCenter extends GuiScreen implements GuiYesNoCallback { Keyboard.enableRepeatEvents(true); if(!initialized) { - if(AuthenticationHandler.isAuthenticated()) { - SearchQuery query = new SearchQuery(); - query.auth = AuthenticationHandler.getKey(); - query.order = false; - myFilePagination = new SearchPagination(query); - } else { + if(!AuthenticationHandler.isAuthenticated()) { mc.displayGuiScreen(new GuiLoginPrompt(new GuiMainMenu(), this)); } //Top Button Bar topBar = new ArrayList(); - GuiButton recentButton = new GuiButton(GuiConstants.CENTER_RECENT_BUTTON, 20, 30, I18n.format("replaymod.gui.center.newest")); + 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.best")); + GuiButton bestButton = new GuiButton(GuiConstants.CENTER_BEST_BUTTON, 20, 30, I18n.format("replaymod.gui.center.top.best")); topBar.add(bestButton); - GuiButton ownReplayButton = new GuiButton(GuiConstants.CENTER_MY_REPLAYS_BUTTON, 20, 30, I18n.format("replaymod.gui.center.my")); - ownReplayButton.enabled = AuthenticationHandler.isAuthenticated(); - topBar.add(ownReplayButton); + GuiButton downloadedReplayButton = new GuiButton(GuiConstants.CENTER_DOWNLOADED_REPLAYS_BUTTON, 20, 30, I18n.format("replaymod.gui.center.top.downloaded")); + downloadedReplayButton.enabled = AuthenticationHandler.isAuthenticated(); + topBar.add(downloadedReplayButton); - GuiButton searchButton = new GuiButton(GuiConstants.CENTER_SEARCH_BUTTON, 20, 30, I18n.format("replaymod.gui.center.search")); + GuiButton favoritedReplayButton = new GuiButton(GuiConstants.CENTER_FAVORITED_REPLAYS_BUTTON, 20, 30, I18n.format("replaymod.gui.center.top.favorited")); + favoritedReplayButton.enabled = AuthenticationHandler.isAuthenticated(); + 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) @@ -155,6 +157,12 @@ public class GuiReplayCenter extends GuiScreen implements GuiYesNoCallback { } public void elementSelected(int index) { + if(index < 0) { + for(GuiButton b : replayButtonBar) { + b.enabled = false; + } + return; + } GuiReplayListEntry entry = currentList.getListEntry(index); FileInfo info = entry.getFileInfo(); if(info != null) { @@ -181,8 +189,10 @@ public class GuiReplayCenter extends GuiScreen implements GuiYesNoCallback { showOnlineRecent(); } else if(button.id == GuiConstants.CENTER_BEST_BUTTON) { showOnlineBest(); - } else if(button.id == GuiConstants.CENTER_MY_REPLAYS_BUTTON) { - showOnlineOwnFiles(); + } else if(button.id == GuiConstants.CENTER_DOWNLOADED_REPLAYS_BUTTON) { + showDownloadedFiles(); + } else if(button.id == GuiConstants.CENTER_FAVORITED_REPLAYS_BUTTON) { + showFavoritedFiles(); } else if(button.id == GuiConstants.CENTER_SEARCH_BUTTON) { } else if(button.id == GuiConstants.CENTER_LOAD_REPLAY_BUTTON) { @@ -260,17 +270,9 @@ public class GuiReplayCenter extends GuiScreen implements GuiYesNoCallback { Keyboard.enableRepeatEvents(false); } - private void updateCurrentList(ReplayFileList list, SearchPagination pagination) { - currentList = list; - if(currentList == null) { - 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 - 70; - } + private void updateCurrentList(Pagination pagination) { + elementSelected(-1); + currentList = new ReplayFileList(mc, width, height, 50, height - 70, 36, this); if(pagination.getLoadedPages() < 0) { pagination.fetchPage(); @@ -301,7 +303,7 @@ public class GuiReplayCenter extends GuiScreen implements GuiYesNoCallback { currentListLoader = new Thread(new Runnable() { @Override public void run() { - updateCurrentList(recentFileList, recentFilePagination); + updateCurrentList(recentFilePagination); currentTab = Tab.RECENT_FILES; } }); @@ -313,27 +315,38 @@ public class GuiReplayCenter extends GuiScreen implements GuiYesNoCallback { currentListLoader = new Thread(new Runnable() { @Override public void run() { - updateCurrentList(bestFileList, bestFilePagination); + updateCurrentList(bestFilePagination); currentTab = Tab.BEST_FILES; } }); currentListLoader.start(); } - public void showOnlineOwnFiles() { + public void showDownloadedFiles() { cancelCurrentListLoader(); - if(!AuthenticationHandler.isAuthenticated() || myFilePagination == null) return; currentListLoader = new Thread(new Runnable() { @Override public void run() { - updateCurrentList(myFileList, myFilePagination); - currentTab = Tab.MY_FILES; + updateCurrentList(downloadedFilePagination); + currentTab = Tab.DOWNLOADED_FILES; + } + }); + currentListLoader.start(); + } + + public void showFavoritedFiles() { + cancelCurrentListLoader(); + currentListLoader = new Thread(new Runnable() { + @Override + public void run() { + updateCurrentList(favoritedFilePagination); + currentTab = Tab.FAVORITED_FILES; } }); currentListLoader.start(); } private enum Tab { - RECENT_FILES, BEST_FILES, MY_FILES, SEARCH; + RECENT_FILES, BEST_FILES, DOWNLOADED_FILES, FAVORITED_FILES, SEARCH; } } diff --git a/src/main/java/eu/crushedpixel/replaymod/registry/DownloadedFileHandler.java b/src/main/java/eu/crushedpixel/replaymod/registry/DownloadedFileHandler.java index 1c3eaad4..b4a09a78 100644 --- a/src/main/java/eu/crushedpixel/replaymod/registry/DownloadedFileHandler.java +++ b/src/main/java/eu/crushedpixel/replaymod/registry/DownloadedFileHandler.java @@ -62,4 +62,8 @@ public class DownloadedFileHandler { return f; } + + public HashMap getDownloadedFiles() { + return downloadedFiles; + } } diff --git a/src/main/resources/assets/replaymod/lang/en_US.lang b/src/main/resources/assets/replaymod/lang/en_US.lang index 7a6cc3ec..60d2e857 100644 --- a/src/main/resources/assets/replaymod/lang/en_US.lang +++ b/src/main/resources/assets/replaymod/lang/en_US.lang @@ -120,10 +120,11 @@ replaymod.gui.login.noacc=Don't have an account yet? #Replay Center GUI replaymod.gui.center.logoutcallback=Do you really want to log out? -replaymod.gui.center.newest=Newest Replays -replaymod.gui.center.best=Best Replays -replaymod.gui.center.my=My Replays -replaymod.gui.center.search=Search Replays +replaymod.gui.center.top.recent=Recent +replaymod.gui.center.top.best=Best +replaymod.gui.center.top.downloaded=Downloaded +replaymod.gui.center.top.favorited=Favorited +replaymod.gui.center.top.search=Search replaymod.gui.center.favorite=Favorite replaymod.gui.center.favorites=Favorites