From f27d31dcbb321779b3a03a6ca436992a0ac2ee9f Mon Sep 17 00:00:00 2001 From: CrushedPixel Date: Sat, 16 May 2015 23:54:00 +0200 Subject: [PATCH] Indicates current Tab in the Replay Center by deactivating the according button Restricted Favoriting Replays to downloaded ones --- .../gui/elements/GuiReplayListExtended.java | 2 + .../replaymod/gui/online/GuiReplayCenter.java | 53 +++++++++++++++---- .../registry/DownloadedFileHandler.java | 1 + .../assets/replaymod/lang/en_US.lang | 2 + 4 files changed, 48 insertions(+), 10 deletions(-) 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 3adecc1b..502dc3fb 100755 --- a/src/main/java/eu/crushedpixel/replaymod/gui/elements/GuiReplayListExtended.java +++ b/src/main/java/eu/crushedpixel/replaymod/gui/elements/GuiReplayListExtended.java @@ -115,6 +115,8 @@ public abstract class GuiReplayListExtended extends GuiListExtended { int l = k / this.slotHeight; if(this.mouseX >= i && this.mouseX <= j && l >= 0 && k >= 0 && l < this.getSize()) { + //LoadingListEntries should not do anything + if(this.getListEntry(l) instanceof GuiLoadingListEntry) return; boolean flag1 = l == this.selectedElement && Minecraft.getSystemTime() - this.lastClicked < 250L; this.elementClicked(l, flag1, this.mouseX, this.mouseY); this.selectedElement = l; 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 b267cb7f..c4654997 100755 --- a/src/main/java/eu/crushedpixel/replaymod/gui/online/GuiReplayCenter.java +++ b/src/main/java/eu/crushedpixel/replaymod/gui/online/GuiReplayCenter.java @@ -102,6 +102,11 @@ public class GuiReplayCenter extends GuiScreen implements GuiYesNoCallback { bottomBar.add(logoutButton); showOnlineRecent(); + disableTopBarButton(GuiConstants.CENTER_RECENT_BUTTON); + } + + if(currentList != null) { + currentList.height = height-60; } int i = 0; @@ -170,7 +175,8 @@ public class GuiReplayCenter extends GuiScreen implements GuiYesNoCallback { boolean favorited = ReplayMod.favoritedFileHandler.isFavorited(info.getId()); favButton.displayString = favorited ? I18n.format("replaymod.gui.center.unfavorite") : I18n.format("replaymod.gui.center.favorite"); - favButton.enabled = true; + //if not downloaded, disable favorising + favButton.enabled = favorited || downloaded; } else { for(GuiButton b : replayButtonBar) { b.enabled = false; @@ -178,6 +184,12 @@ public class GuiReplayCenter extends GuiScreen implements GuiYesNoCallback { } } + 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; @@ -188,15 +200,19 @@ public class GuiReplayCenter extends GuiScreen implements GuiYesNoCallback { } else if(button.id == GuiConstants.CENTER_MANAGER_BUTTON) { mc.displayGuiScreen(new GuiReplayViewer()); } 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); } else if(button.id == GuiConstants.CENTER_LOAD_REPLAY_BUTTON) { GuiReplayListEntry entry = (GuiReplayListEntry)currentList.getListEntry(currentList.selected); FileInfo info = entry.getFileInfo(); @@ -247,13 +263,18 @@ public class GuiReplayCenter extends GuiScreen implements GuiYesNoCallback { @Override public void drawScreen(int mouseX, int mouseY, float partialTicks) { this.drawDefaultBackground(); - this.drawCenteredString(fontRendererObj, I18n.format("replaymod.gui.replaycenter"), this.width / 2, 8, Color.WHITE.getRGB()); - 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.selected != -1) { + this.drawString(fontRendererObj, I18n.format("replaymod.gui.center.downloadrequired"), mouseX, mouseY + 4, Color.RED.getRGB()); + } + + this.drawCenteredString(fontRendererObj, I18n.format("replaymod.gui.replaycenter"), this.width / 2, 5, Color.WHITE.getRGB()); } @Override @@ -287,7 +308,7 @@ public class GuiReplayCenter extends GuiScreen implements GuiYesNoCallback { private void updateCurrentList(Pagination pagination) { elementSelected(-1); - currentList = new ReplayFileList(mc, width, height, 50, height - 70, 36, this); + currentList = new ReplayFileList(mc, width, height, 50, height - 60, 36, this); loadingListEntry = new GuiLoadingListEntry(currentList); currentList.addEntry(loadingListEntry); @@ -322,8 +343,8 @@ public class GuiReplayCenter extends GuiScreen implements GuiYesNoCallback { currentListLoader = new Thread(new Runnable() { @Override public void run() { - updateCurrentList(new SearchPagination(recentFileSearchQuery)); currentTab = Tab.RECENT_FILES; + updateCurrentList(new SearchPagination(recentFileSearchQuery)); } }); currentListLoader.start(); @@ -334,8 +355,8 @@ public class GuiReplayCenter extends GuiScreen implements GuiYesNoCallback { currentListLoader = new Thread(new Runnable() { @Override public void run() { - updateCurrentList(new SearchPagination(bestFileSearchQuery)); currentTab = Tab.BEST_FILES; + updateCurrentList(new SearchPagination(bestFileSearchQuery)); } }); currentListLoader.start(); @@ -346,8 +367,8 @@ public class GuiReplayCenter extends GuiScreen implements GuiYesNoCallback { currentListLoader = new Thread(new Runnable() { @Override public void run() { - updateCurrentList(new DownloadedFilePagination()); currentTab = Tab.DOWNLOADED_FILES; + updateCurrentList(new DownloadedFilePagination()); } }); currentListLoader.start(); @@ -358,15 +379,27 @@ public class GuiReplayCenter extends GuiScreen implements GuiYesNoCallback { currentListLoader = new Thread(new Runnable() { @Override public void run() { + currentTab = Tab.FAVORITED_FILES; ReplayMod.favoritedFileHandler.reloadFavorites(); updateCurrentList(new FavoritedFilePagination()); - currentTab = Tab.FAVORITED_FILES; } }); currentListLoader.start(); } private enum Tab { - RECENT_FILES, BEST_FILES, DOWNLOADED_FILES, FAVORITED_FILES, SEARCH; + RECENT_FILES("replaymod.gui.center.tab.recent"), + BEST_FILES("replaymod.gui.center.tab.best"), + DOWNLOADED_FILES("replaymod.gui.center.tab.downloaded"), + FAVORITED_FILES("replaymod.gui.center.tab.favorited"), + SEARCH("replaymod.gui.center.tab.search"); + + private String title; + + Tab(String title) { + this.title = title; + } + + public String getTitle() { return I18n.format(title); } } } diff --git a/src/main/java/eu/crushedpixel/replaymod/registry/DownloadedFileHandler.java b/src/main/java/eu/crushedpixel/replaymod/registry/DownloadedFileHandler.java index b4a09a78..59e8dddd 100644 --- a/src/main/java/eu/crushedpixel/replaymod/registry/DownloadedFileHandler.java +++ b/src/main/java/eu/crushedpixel/replaymod/registry/DownloadedFileHandler.java @@ -19,6 +19,7 @@ public class DownloadedFileHandler { downloadFolder.mkdirs(); for(File f : downloadFolder.listFiles()) { + if(!FilenameUtils.getExtension(f.getAbsolutePath()).equals("mcpr")) continue; try { Integer i = Integer.valueOf(FilenameUtils.getBaseName(f.getAbsolutePath())); if(i != null) { diff --git a/src/main/resources/assets/replaymod/lang/en_US.lang b/src/main/resources/assets/replaymod/lang/en_US.lang index ac264aa8..d5358b3f 100644 --- a/src/main/resources/assets/replaymod/lang/en_US.lang +++ b/src/main/resources/assets/replaymod/lang/en_US.lang @@ -127,6 +127,8 @@ replaymod.gui.center.top.downloaded=Downloaded replaymod.gui.center.top.favorited=Favorited replaymod.gui.center.top.search=Search +replaymod.gui.center.downloadrequired=Download the Replay to rate or favorite it + replaymod.gui.center.favorite=Favorite replaymod.gui.center.unfavorite=Unfavorite replaymod.gui.center.favorites=Favorites