Fixed Pagination not being updated correctly
Added GuiLoadingListEntry to Lists while in Replay Center
This commit is contained in:
@@ -7,10 +7,7 @@ import eu.crushedpixel.replaymod.localization.LocalizedResourcePack;
|
||||
import eu.crushedpixel.replaymod.online.authentication.AuthenticationHandler;
|
||||
import eu.crushedpixel.replaymod.recording.ConnectionEventHandler;
|
||||
import eu.crushedpixel.replaymod.reflection.MCPNames;
|
||||
import eu.crushedpixel.replaymod.registry.DownloadedFileHandler;
|
||||
import eu.crushedpixel.replaymod.registry.KeybindRegistry;
|
||||
import eu.crushedpixel.replaymod.registry.ReplayFileAppender;
|
||||
import eu.crushedpixel.replaymod.registry.UploadedFileHandler;
|
||||
import eu.crushedpixel.replaymod.registry.*;
|
||||
import eu.crushedpixel.replaymod.renderer.SafeEntityRenderer;
|
||||
import eu.crushedpixel.replaymod.replay.ReplaySender;
|
||||
import eu.crushedpixel.replaymod.settings.ReplaySettings;
|
||||
@@ -69,6 +66,7 @@ public class ReplayMod {
|
||||
public static ReplayFileAppender replayFileAppender;
|
||||
public static UploadedFileHandler uploadedFileHandler;
|
||||
public static DownloadedFileHandler downloadedFileHandler;
|
||||
public static FavoritedFileHandler favoritedFileHandler;
|
||||
|
||||
private static Field defaultResourcePacksField;
|
||||
static {
|
||||
@@ -97,6 +95,8 @@ public class ReplayMod {
|
||||
|
||||
downloadedFileHandler = new DownloadedFileHandler();
|
||||
|
||||
favoritedFileHandler = new FavoritedFileHandler();
|
||||
|
||||
replayFileAppender = new ReplayFileAppender();
|
||||
replayFileAppender.start();
|
||||
}
|
||||
|
||||
@@ -2,10 +2,8 @@ package eu.crushedpixel.replaymod.api.client.pagination;
|
||||
|
||||
import eu.crushedpixel.replaymod.ReplayMod;
|
||||
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;
|
||||
|
||||
@@ -33,7 +31,7 @@ public class FavoritedFilePagination implements Pagination {
|
||||
page++;
|
||||
|
||||
try {
|
||||
int[] f = ReplayMod.apiClient.getFavorites(AuthenticationHandler.getKey());
|
||||
List<Integer> f = ReplayMod.favoritedFileHandler.getFavorited();
|
||||
List<Integer> toAdd = new ArrayList<Integer>();
|
||||
for(int i : f) {
|
||||
if(!files.containsKey(i)) {
|
||||
@@ -42,8 +40,6 @@ public class FavoritedFilePagination implements Pagination {
|
||||
}
|
||||
}
|
||||
|
||||
files.keySet().retainAll(Arrays.asList(f));
|
||||
|
||||
FileInfo[] fis = ReplayMod.apiClient.getFileInfo(toAdd);
|
||||
if(fis.length < 1) {
|
||||
page--;
|
||||
|
||||
@@ -4,9 +4,6 @@ import eu.crushedpixel.replaymod.api.client.holders.FileInfo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by mariusmetzger on 16/05/15.
|
||||
*/
|
||||
public interface Pagination {
|
||||
public List<FileInfo> getFiles();
|
||||
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
package eu.crushedpixel.replaymod.gui.elements;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiListExtended.IGuiListEntry;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public class GuiLoadingListEntry implements IGuiListEntry {
|
||||
|
||||
boolean registered = false;
|
||||
private final Minecraft mc = Minecraft.getMinecraft();
|
||||
private GuiReplayListExtended parent;
|
||||
private final String message = I18n.format("replaymod.gui.loading")+"...";
|
||||
|
||||
public GuiLoadingListEntry(GuiReplayListExtended parent) {
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawEntry(int slotIndex, int x, int y, int listWidth, int slotHeight, int mouseX, int mouseY, boolean isSelected) {
|
||||
try {
|
||||
int width = mc.fontRendererObj.getStringWidth(message);
|
||||
mc.fontRendererObj.drawString(message, x+(listWidth/2)-(width/2), y + (slotHeight/2)-(mc.fontRendererObj.FONT_HEIGHT/2) - 7
|
||||
, Color.LIGHT_GRAY.getRGB());
|
||||
|
||||
String bubbles = System.currentTimeMillis() % 500 >= 250 ? "oOo" : "OoO";
|
||||
|
||||
width = mc.fontRendererObj.getStringWidth(bubbles);
|
||||
mc.fontRendererObj.drawString(bubbles, x+(listWidth/2)-(width/2), y + (slotHeight/2)-(mc.fontRendererObj.FONT_HEIGHT/2) + 8
|
||||
, Color.LIGHT_GRAY.getRGB());
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSelected(int p_178011_1_, int p_178011_2_, int p_178011_3_) {}
|
||||
|
||||
@Override
|
||||
public boolean mousePressed(int p_148278_1_, int p_148278_2_, int p_148278_3_, int p_148278_4_, int p_148278_5_, int p_148278_6_) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseReleased(int slotIndex, int x, int y, int mouseEvent, int relativeX, int relativeY) {}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
package eu.crushedpixel.replaymod.gui.elements;
|
||||
|
||||
import eu.crushedpixel.replaymod.api.client.holders.FileInfo;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiListExtended;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
@@ -9,14 +8,13 @@ import net.minecraft.client.renderer.WorldRenderer;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import org.lwjgl.input.Mouse;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class GuiReplayListExtended extends GuiListExtended {
|
||||
|
||||
public int selected = -1;
|
||||
private List<GuiReplayListEntry> entries = new ArrayList<GuiReplayListEntry>();
|
||||
private List<IGuiListEntry> entries = new ArrayList<IGuiListEntry>();
|
||||
|
||||
public GuiReplayListExtended(Minecraft mcIn, int p_i45010_2_,
|
||||
int p_i45010_3_, int p_i45010_4_, int p_i45010_5_, int p_i45010_6_) {
|
||||
@@ -70,19 +68,27 @@ public abstract class GuiReplayListExtended extends GuiListExtended {
|
||||
}
|
||||
|
||||
public void clearEntries() {
|
||||
entries = new ArrayList<GuiReplayListEntry>();
|
||||
entries = new ArrayList<IGuiListEntry>();
|
||||
}
|
||||
|
||||
public void addEntry(FileInfo fileInfo, File image) {
|
||||
entries.add(new GuiReplayListEntry(this, fileInfo, image));
|
||||
public void addEntry(IGuiListEntry entry) {
|
||||
entries.add(entry);
|
||||
}
|
||||
|
||||
public void addEntry(int index, IGuiListEntry entry) {
|
||||
entries.add(index, entry);
|
||||
}
|
||||
|
||||
public void removeEntry(IGuiListEntry entry) {
|
||||
entries.remove(entry);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GuiReplayListEntry getListEntry(int index) {
|
||||
public IGuiListEntry getListEntry(int index) {
|
||||
return entries.get(index);
|
||||
}
|
||||
|
||||
public List<GuiReplayListEntry> getEntries() {
|
||||
public List<IGuiListEntry> getEntries() {
|
||||
return entries;
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ 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.GuiLoadingListEntry;
|
||||
import eu.crushedpixel.replaymod.gui.elements.GuiReplayListEntry;
|
||||
import eu.crushedpixel.replaymod.gui.replayviewer.GuiReplayViewer;
|
||||
import eu.crushedpixel.replaymod.online.authentication.AuthenticationHandler;
|
||||
@@ -29,14 +30,11 @@ 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 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 Tab currentTab = Tab.RECENT_FILES;
|
||||
private GuiButton loadButton, favButton, likeButton, dislikeButton;
|
||||
private List<GuiButton> replayButtonBar, bottomBar, topBar;
|
||||
private GuiLoadingListEntry loadingListEntry;
|
||||
|
||||
public static GuiYesNo getYesNoGui(GuiYesNoCallback p_152129_0_, int p_152129_2_) {
|
||||
String s1 = I18n.format("replaymod.gui.center.logoutcallback");
|
||||
@@ -163,12 +161,16 @@ public class GuiReplayCenter extends GuiScreen implements GuiYesNoCallback {
|
||||
}
|
||||
return;
|
||||
}
|
||||
GuiReplayListEntry entry = currentList.getListEntry(index);
|
||||
GuiReplayListEntry entry = (GuiReplayListEntry)currentList.getListEntry(index);
|
||||
FileInfo info = entry.getFileInfo();
|
||||
if(info != null) {
|
||||
boolean downloaded = ReplayMod.downloadedFileHandler.getFileForID(info.getId()) != null;
|
||||
loadButton.displayString = downloaded ? I18n.format("replaymod.gui.load") : I18n.format("replaymod.gui.download");
|
||||
loadButton.enabled = true;
|
||||
|
||||
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;
|
||||
} else {
|
||||
for(GuiButton b : replayButtonBar) {
|
||||
b.enabled = false;
|
||||
@@ -196,7 +198,7 @@ public class GuiReplayCenter extends GuiScreen implements GuiYesNoCallback {
|
||||
} else if(button.id == GuiConstants.CENTER_SEARCH_BUTTON) {
|
||||
|
||||
} else if(button.id == GuiConstants.CENTER_LOAD_REPLAY_BUTTON) {
|
||||
GuiReplayListEntry entry = currentList.getListEntry(currentList.selected);
|
||||
GuiReplayListEntry entry = (GuiReplayListEntry)currentList.getListEntry(currentList.selected);
|
||||
FileInfo info = entry.getFileInfo();
|
||||
if(info != null) {
|
||||
File f = ReplayMod.downloadedFileHandler.getFileForID(info.getId());
|
||||
@@ -209,6 +211,19 @@ public class GuiReplayCenter extends GuiScreen implements GuiYesNoCallback {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
} else if(button.id == GuiConstants.CENTER_FAV_REPLAY_BUTTON) {
|
||||
GuiReplayListEntry entry = (GuiReplayListEntry)currentList.getListEntry(currentList.selected);
|
||||
FileInfo info = entry.getFileInfo();
|
||||
if(info != null) {
|
||||
boolean favorited = ReplayMod.favoritedFileHandler.isFavorited(info.getId());
|
||||
try {
|
||||
if(favorited) ReplayMod.favoritedFileHandler.removeFromFavorites(info.getId());
|
||||
else ReplayMod.favoritedFileHandler.addToFavorites(info.getId());
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
elementSelected(currentList.selected);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -273,6 +288,8 @@ 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);
|
||||
loadingListEntry = new GuiLoadingListEntry(currentList);
|
||||
currentList.addEntry(loadingListEntry);
|
||||
|
||||
if(pagination.getLoadedPages() < 0) {
|
||||
pagination.fetchPage();
|
||||
@@ -285,11 +302,13 @@ public class GuiReplayCenter extends GuiScreen implements GuiYesNoCallback {
|
||||
tmp = File.createTempFile("thumb_online_" + i.getId(), "jpg");
|
||||
ReplayMod.apiClient.downloadThumbnail(i.getId(), tmp);
|
||||
}
|
||||
currentList.addEntry(i, tmp);
|
||||
currentList.addEntry(currentList.getEntries().size()-1, new GuiReplayListEntry(currentList, i, tmp));
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
currentList.removeEntry(loadingListEntry);
|
||||
}
|
||||
|
||||
private Thread currentListLoader;
|
||||
@@ -303,7 +322,7 @@ public class GuiReplayCenter extends GuiScreen implements GuiYesNoCallback {
|
||||
currentListLoader = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
updateCurrentList(recentFilePagination);
|
||||
updateCurrentList(new SearchPagination(recentFileSearchQuery));
|
||||
currentTab = Tab.RECENT_FILES;
|
||||
}
|
||||
});
|
||||
@@ -315,7 +334,7 @@ public class GuiReplayCenter extends GuiScreen implements GuiYesNoCallback {
|
||||
currentListLoader = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
updateCurrentList(bestFilePagination);
|
||||
updateCurrentList(new SearchPagination(bestFileSearchQuery));
|
||||
currentTab = Tab.BEST_FILES;
|
||||
}
|
||||
});
|
||||
@@ -327,7 +346,7 @@ public class GuiReplayCenter extends GuiScreen implements GuiYesNoCallback {
|
||||
currentListLoader = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
updateCurrentList(downloadedFilePagination);
|
||||
updateCurrentList(new DownloadedFilePagination());
|
||||
currentTab = Tab.DOWNLOADED_FILES;
|
||||
}
|
||||
});
|
||||
@@ -339,7 +358,8 @@ public class GuiReplayCenter extends GuiScreen implements GuiYesNoCallback {
|
||||
currentListLoader = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
updateCurrentList(favoritedFilePagination);
|
||||
ReplayMod.favoritedFileHandler.reloadFavorites();
|
||||
updateCurrentList(new FavoritedFilePagination());
|
||||
currentTab = Tab.FAVORITED_FILES;
|
||||
}
|
||||
});
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.mojang.realmsclient.util.Pair;
|
||||
import eu.crushedpixel.replaymod.ReplayMod;
|
||||
import eu.crushedpixel.replaymod.api.client.holders.FileInfo;
|
||||
import eu.crushedpixel.replaymod.gui.GuiReplaySettings;
|
||||
import eu.crushedpixel.replaymod.gui.elements.GuiReplayListEntry;
|
||||
import eu.crushedpixel.replaymod.gui.elements.GuiReplayListExtended;
|
||||
import eu.crushedpixel.replaymod.gui.online.GuiUploadFile;
|
||||
import eu.crushedpixel.replaymod.online.authentication.AuthenticationHandler;
|
||||
@@ -85,7 +86,7 @@ public class GuiReplayViewer extends GuiScreen implements GuiYesNoCallback {
|
||||
for(Pair<Pair<File, ReplayMetaData>, File> p : replayFileList) {
|
||||
FileInfo fileInfo = new FileInfo(-1, p.first().second(), null, null,
|
||||
-1, -1, -1, FilenameUtils.getBaseName(p.first().first().getName()), true, -1);
|
||||
replayGuiList.addEntry(fileInfo, p.second());
|
||||
replayGuiList.addEntry(new GuiReplayListEntry(replayGuiList, fileInfo, p.second()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -161,7 +162,7 @@ public class GuiReplayViewer extends GuiScreen implements GuiYesNoCallback {
|
||||
} else if(button.id == CANCEL_BUTTON_ID) {
|
||||
mc.displayGuiScreen(null);
|
||||
} else if(button.id == DELETE_BUTTON_ID) {
|
||||
String s = replayGuiList.getListEntry(replayGuiList.selected).getFileInfo().getName();
|
||||
String s = ((GuiReplayListEntry)replayGuiList.getListEntry(replayGuiList.selected)).getFileInfo().getName();
|
||||
|
||||
if(s != null) {
|
||||
delete_file = true;
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
package eu.crushedpixel.replaymod.registry;
|
||||
|
||||
import com.google.common.primitives.Ints;
|
||||
import eu.crushedpixel.replaymod.ReplayMod;
|
||||
import eu.crushedpixel.replaymod.api.client.ApiException;
|
||||
import eu.crushedpixel.replaymod.online.authentication.AuthenticationHandler;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class FavoritedFileHandler {
|
||||
|
||||
private List<Integer> favorited = new ArrayList<Integer>();
|
||||
|
||||
boolean retrieved = false;
|
||||
|
||||
public FavoritedFileHandler() {
|
||||
reloadFavorites();
|
||||
}
|
||||
|
||||
public List<Integer> getFavorited() { return favorited; }
|
||||
|
||||
public boolean isFavorited(int id) {
|
||||
return favorited.contains(id);
|
||||
}
|
||||
|
||||
public void addToFavorites(Integer id) throws IOException, ApiException {
|
||||
favorited.remove(id);
|
||||
favorited.add(id);
|
||||
ReplayMod.apiClient.favFile(AuthenticationHandler.getKey(), id, true);
|
||||
}
|
||||
|
||||
public void removeFromFavorites(Integer id) throws IOException, ApiException {
|
||||
favorited.remove(id);
|
||||
ReplayMod.apiClient.favFile(AuthenticationHandler.getKey(), id, false);
|
||||
}
|
||||
|
||||
public void reloadFavorites() {
|
||||
if(AuthenticationHandler.isAuthenticated()) {
|
||||
try {
|
||||
int[] ids = ReplayMod.apiClient.getFavorites(AuthenticationHandler.getKey());
|
||||
favorited = new ArrayList<Integer>(Ints.asList(ids));
|
||||
retrieved = true;
|
||||
} catch(Exception e) {
|
||||
retrieved = false;
|
||||
favorited = new ArrayList<Integer>();
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
retrieved = false;
|
||||
favorited = new ArrayList<Integer>();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -71,6 +71,7 @@ replaymod.gui.recording=Recording
|
||||
replaymod.gui.speed=Speed
|
||||
replaymod.gui.register=Register
|
||||
replaymod.gui.mail=Email Address
|
||||
replaymod.gui.loading=Loading
|
||||
|
||||
replaymod.gui.unknownerror=An unknown error occured
|
||||
|
||||
@@ -127,6 +128,7 @@ replaymod.gui.center.top.favorited=Favorited
|
||||
replaymod.gui.center.top.search=Search
|
||||
|
||||
replaymod.gui.center.favorite=Favorite
|
||||
replaymod.gui.center.unfavorite=Unfavorite
|
||||
replaymod.gui.center.favorites=Favorites
|
||||
|
||||
#Upload GUI
|
||||
|
||||
Reference in New Issue
Block a user