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

@@ -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<GuiButton> 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<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)
List<GuiButton> bottomBar = new ArrayList<GuiButton>();
@@ -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) {

View File

@@ -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);
}
}