Adapted new API System with search API call
Implemented raw Pagination support to Replay Center Fixed awkward time jumps caused by MCTimerHandler Fixed Java 1.6 incompatibility with List.sort Method in GuiSpectateSelection Fixed a LOT of compatibility issues with the Shader Mod
This commit is contained in:
@@ -2,7 +2,6 @@ package eu.crushedpixel.replaymod.gui;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
@@ -15,47 +14,31 @@ import javax.imageio.ImageIO;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.Gui;
|
||||
import net.minecraft.client.gui.GuiListExtended.IGuiListEntry;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.renderer.texture.DynamicTexture;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import eu.crushedpixel.replaymod.api.client.holders.FileInfo;
|
||||
import eu.crushedpixel.replaymod.gui.replaymanager.ResourceHelper;
|
||||
import eu.crushedpixel.replaymod.recording.ReplayMetaData;
|
||||
|
||||
public class GuiReplayListEntry implements IGuiListEntry {
|
||||
|
||||
private Minecraft minecraft = Minecraft.getMinecraft();
|
||||
private final DateFormat dateFormat = new SimpleDateFormat();
|
||||
|
||||
private ReplayMetaData metaData;
|
||||
private String fileName;
|
||||
|
||||
private FileInfo fileInfo;
|
||||
|
||||
private ResourceLocation textureResource;
|
||||
private DynamicTexture dynTex = null;
|
||||
|
||||
private File imageFile;
|
||||
private BufferedImage image = null;
|
||||
|
||||
public ReplayMetaData getMetaData() {
|
||||
return metaData;
|
||||
}
|
||||
|
||||
public void setMetaData(ReplayMetaData metaData) {
|
||||
this.metaData = metaData;
|
||||
}
|
||||
|
||||
public String getFileName() {
|
||||
return fileName;
|
||||
}
|
||||
|
||||
public void setFileName(String fileName) {
|
||||
this.fileName = fileName;
|
||||
}
|
||||
|
||||
private GuiReplayListExtended parent;
|
||||
|
||||
public FileInfo getFileInfo() {
|
||||
return fileInfo;
|
||||
}
|
||||
|
||||
public GuiReplayListEntry(GuiReplayListExtended parent, String fileName, ReplayMetaData metaData, File imageFile) {
|
||||
this.metaData = metaData;
|
||||
this.fileName = fileName;
|
||||
public GuiReplayListEntry(GuiReplayListExtended parent, FileInfo fileInfo, File imageFile) {
|
||||
this.fileInfo = fileInfo;
|
||||
this.parent = parent;
|
||||
dynTex = null;
|
||||
this.imageFile = imageFile;
|
||||
@@ -66,7 +49,10 @@ public class GuiReplayListEntry implements IGuiListEntry {
|
||||
@Override
|
||||
public void drawEntry(int slotIndex, int x, int y, int listWidth, int slotHeight, int mouseX, int mouseY, boolean isSelected) {
|
||||
try {
|
||||
minecraft.fontRendererObj.drawString(fileName, x + 3, y + 1, 16777215);
|
||||
if(fileInfo.getName() == null || fileInfo.getName().length() < 1) {
|
||||
fileInfo.setName("No Name");
|
||||
}
|
||||
minecraft.fontRendererObj.drawString(fileInfo.getName(), x + 3, y + 1, 16777215);
|
||||
|
||||
if(y < -slotHeight || y > parent.height) {
|
||||
if(registered) {
|
||||
@@ -79,7 +65,7 @@ public class GuiReplayListEntry implements IGuiListEntry {
|
||||
return;
|
||||
} else {
|
||||
if(!registered) {
|
||||
textureResource = new ResourceLocation("thumbs/"+fileName);
|
||||
textureResource = new ResourceLocation("thumbs/"+fileInfo.getName()+fileInfo.getId());
|
||||
if(imageFile == null) {
|
||||
image = ResourceHelper.getDefaultThumbnail();
|
||||
} else {
|
||||
@@ -97,12 +83,12 @@ public class GuiReplayListEntry implements IGuiListEntry {
|
||||
}
|
||||
|
||||
List<String> list = new ArrayList<String>();
|
||||
list.add(metaData.getServerName()+" ("+dateFormat.format(new Date(metaData.getDate()))+")");
|
||||
list.add(fileInfo.getMetadata().getServerName()+" ("+dateFormat.format(new Date(fileInfo.getMetadata().getDate()))+")");
|
||||
|
||||
list.add(String.format("%02dm%02ds",
|
||||
TimeUnit.MILLISECONDS.toMinutes(metaData.getDuration()),
|
||||
TimeUnit.MILLISECONDS.toSeconds(metaData.getDuration()) -
|
||||
TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(metaData.getDuration()))
|
||||
TimeUnit.MILLISECONDS.toMinutes(fileInfo.getMetadata().getDuration()),
|
||||
TimeUnit.MILLISECONDS.toSeconds(fileInfo.getMetadata().getDuration()) -
|
||||
TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(fileInfo.getMetadata().getDuration()))
|
||||
));
|
||||
|
||||
for (int l1 = 0; l1 < Math.min(list.size(), 2); ++l1) {
|
||||
|
||||
@@ -13,7 +13,7 @@ import net.minecraft.util.MathHelper;
|
||||
|
||||
import org.lwjgl.input.Mouse;
|
||||
|
||||
import eu.crushedpixel.replaymod.recording.ReplayMetaData;
|
||||
import eu.crushedpixel.replaymod.api.client.holders.FileInfo;
|
||||
|
||||
public abstract class GuiReplayListExtended extends GuiListExtended {
|
||||
|
||||
@@ -81,8 +81,8 @@ public abstract class GuiReplayListExtended extends GuiListExtended {
|
||||
entries = new ArrayList<GuiReplayListEntry>();
|
||||
}
|
||||
|
||||
public void addEntry(String fileName, ReplayMetaData metaData, File image) {
|
||||
entries.add(new GuiReplayListEntry(this, fileName, metaData, image));
|
||||
public void addEntry(FileInfo fileInfo, File image) {
|
||||
entries.add(new GuiReplayListEntry(this, fileInfo, image));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -3,6 +3,7 @@ package eu.crushedpixel.replaymod.gui;
|
||||
import java.awt.Color;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
@@ -14,7 +15,6 @@ import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EnumPlayerModelParts;
|
||||
import net.minecraft.potion.Potion;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.fml.common.versioning.ComparableVersion;
|
||||
|
||||
import com.mojang.realmsclient.util.Pair;
|
||||
|
||||
@@ -53,7 +53,7 @@ public class GuiSpectateSelection extends GuiScreen {
|
||||
public GuiSpectateSelection(List<EntityPlayer> players) {
|
||||
this.prevSpeed = ReplayHandler.getSpeed();
|
||||
|
||||
players.sort(new PlayerComparator());
|
||||
Collections.sort(players, new PlayerComparator());
|
||||
|
||||
this.players = new ArrayList<Pair<EntityPlayer, ResourceLocation>>();
|
||||
|
||||
|
||||
@@ -17,6 +17,8 @@ import org.lwjgl.input.Keyboard;
|
||||
|
||||
import eu.crushedpixel.replaymod.ReplayMod;
|
||||
import eu.crushedpixel.replaymod.api.client.ApiException;
|
||||
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.GuiReplayListExtended;
|
||||
@@ -35,12 +37,25 @@ public class GuiReplayCenter extends GuiScreen implements GuiYesNoCallback {
|
||||
|
||||
private Tab currentTab = Tab.RECENT_FILES;
|
||||
|
||||
private static final SearchQuery recentFileSearchQuery = new SearchQuery(false, null, null, null, null, null,
|
||||
null, null, null, null);
|
||||
|
||||
private static final SearchQuery bestFileSearchQuery = new SearchQuery(true, null, null, null, null, null,
|
||||
null, null, null, null);
|
||||
|
||||
private final SearchPagination recentFilePagination = new SearchPagination(recentFileSearchQuery);
|
||||
private final SearchPagination bestFilePagination = new SearchPagination(bestFileSearchQuery);
|
||||
private SearchPagination myFilePagination;
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
Keyboard.enableRepeatEvents(true);
|
||||
if(!AuthenticationHandler.isAuthenticated()) {
|
||||
mc.displayGuiScreen(new GuiLoginPrompt(new GuiMainMenu(), this));
|
||||
return;
|
||||
|
||||
if(AuthenticationHandler.isAuthenticated()) {
|
||||
SearchQuery query = new SearchQuery();
|
||||
query.auth = AuthenticationHandler.getKey();
|
||||
query.order = false;
|
||||
myFilePagination = new SearchPagination(query);
|
||||
}
|
||||
|
||||
//Top Button Bar
|
||||
@@ -53,6 +68,7 @@ public class GuiReplayCenter extends GuiScreen implements GuiYesNoCallback {
|
||||
buttonBar.add(bestButton);
|
||||
|
||||
GuiButton ownReplayButton = new GuiButton(GuiConstants.CENTER_MY_REPLAYS_BUTTON, 20, 30, "My Replays");
|
||||
ownReplayButton.enabled = AuthenticationHandler.isAuthenticated();
|
||||
buttonBar.add(ownReplayButton);
|
||||
|
||||
GuiButton searchButton = new GuiButton(GuiConstants.CENTER_SEARCH_BUTTON, 20, 30, "Search");
|
||||
@@ -115,9 +131,9 @@ public class GuiReplayCenter extends GuiScreen implements GuiYesNoCallback {
|
||||
} else if(button.id == GuiConstants.CENTER_RECENT_BUTTON) {
|
||||
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_SEARCH_BUTTON) {
|
||||
|
||||
}
|
||||
@@ -188,40 +204,67 @@ 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-40, 36);
|
||||
} else {
|
||||
currentList.clearEntries();
|
||||
currentList.width = width;
|
||||
currentList.height = height;
|
||||
currentList.top = 50;
|
||||
currentList.bottom = height-40;
|
||||
}
|
||||
|
||||
if(pagination.getLoadedPages() < 0) {
|
||||
pagination.fetchPage();
|
||||
}
|
||||
|
||||
for(FileInfo i : pagination.getFiles()) {
|
||||
try {
|
||||
File tmp = null;
|
||||
if(i.hasThumbnail()) {
|
||||
tmp = File.createTempFile("thumb_online_"+i.getId(), "jpg");
|
||||
ReplayMod.apiClient.downloadThumbnail(i.getId(), tmp);
|
||||
}
|
||||
currentList.addEntry(i, tmp);
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void showOnlineRecent() {
|
||||
Thread t = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
if(recentFileList == null) {
|
||||
recentFileList = new ReplayFileList(mc, width, height, 50, height-40, 36);
|
||||
} else {
|
||||
recentFileList.clearEntries();
|
||||
recentFileList.width = width;
|
||||
recentFileList.height = height;
|
||||
recentFileList.top = 50;
|
||||
recentFileList.bottom = height-40;
|
||||
}
|
||||
currentTab = Tab.RECENT_FILES;
|
||||
currentList = recentFileList;
|
||||
FileInfo[] files = ReplayMod.apiClient.getRecentFiles();
|
||||
for(FileInfo i : files) {
|
||||
File tmp = null;
|
||||
if(i.hasThumbnail()) {
|
||||
tmp = File.createTempFile("thumb_online_"+i.getId(), "jpg");
|
||||
ReplayMod.apiClient.downloadThumbnail(i.getId(), tmp);
|
||||
}
|
||||
recentFileList.addEntry(i.getName(), i.getMetadata(), tmp);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (ApiException e) { //TODO: Error message
|
||||
e.printStackTrace();
|
||||
}
|
||||
updateCurrentList(recentFileList, recentFilePagination);
|
||||
currentTab = Tab.RECENT_FILES;
|
||||
}
|
||||
});
|
||||
t.start();
|
||||
}
|
||||
|
||||
public void showOnlineBest() {
|
||||
Thread t = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
updateCurrentList(bestFileList, bestFilePagination);
|
||||
currentTab = Tab.BEST_FILES;
|
||||
}
|
||||
});
|
||||
t.start();
|
||||
}
|
||||
|
||||
public void showOnlineOwnFiles() {
|
||||
if(!AuthenticationHandler.isAuthenticated() || myFilePagination == null) return;
|
||||
Thread t = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
updateCurrentList(myFileList, myFilePagination);
|
||||
currentTab = Tab.MY_FILES;
|
||||
}
|
||||
});
|
||||
t.start();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@ import org.lwjgl.input.Keyboard;
|
||||
import com.google.gson.Gson;
|
||||
import com.mojang.realmsclient.util.Pair;
|
||||
|
||||
import eu.crushedpixel.replaymod.api.client.holders.FileInfo;
|
||||
import eu.crushedpixel.replaymod.gui.GuiReplayListExtended;
|
||||
import eu.crushedpixel.replaymod.gui.GuiReplaySettings;
|
||||
import eu.crushedpixel.replaymod.gui.online.GuiUploadFile;
|
||||
@@ -122,7 +123,9 @@ public class GuiReplayManager extends GuiScreen implements GuiYesNoCallback {
|
||||
Collections.sort(replayFileList, new FileAgeComparator());
|
||||
|
||||
for(Pair<Pair<File, ReplayMetaData>, File> p : replayFileList) {
|
||||
replayGuiList.addEntry(FilenameUtils.getBaseName(p.first().first().getName()), p.first().second(), p.second());
|
||||
FileInfo fileInfo = new FileInfo(-1, p.first().second(), null, null,
|
||||
-1, -1, -1, FilenameUtils.getBaseName(p.first().first().getName()), true);
|
||||
replayGuiList.addEntry(fileInfo, p.second());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -204,7 +207,7 @@ public class GuiReplayManager extends GuiScreen implements GuiYesNoCallback {
|
||||
mc.displayGuiScreen(parentScreen);
|
||||
}
|
||||
else if(button.id == DELETE_BUTTON_ID) {
|
||||
String s = replayGuiList.getListEntry(replayGuiList.selected).getFileName();
|
||||
String s = replayGuiList.getListEntry(replayGuiList.selected).getFileInfo().getName();
|
||||
|
||||
if (s != null) {
|
||||
delete_file = true;
|
||||
|
||||
Reference in New Issue
Block a user