Created GuiReplayInstanceChooser which allows users to define whether they want to load their modified version of an online replay or load the original
This commit is contained in:
@@ -15,7 +15,6 @@ import eu.crushedpixel.replaymod.gui.elements.*;
|
|||||||
import eu.crushedpixel.replaymod.gui.replayviewer.GuiReplayViewer;
|
import eu.crushedpixel.replaymod.gui.replayviewer.GuiReplayViewer;
|
||||||
import eu.crushedpixel.replaymod.holders.GuiEntryListStringEntry;
|
import eu.crushedpixel.replaymod.holders.GuiEntryListStringEntry;
|
||||||
import eu.crushedpixel.replaymod.online.authentication.AuthenticationHandler;
|
import eu.crushedpixel.replaymod.online.authentication.AuthenticationHandler;
|
||||||
import eu.crushedpixel.replaymod.replay.ReplayHandler;
|
|
||||||
import net.minecraft.client.gui.*;
|
import net.minecraft.client.gui.*;
|
||||||
import net.minecraft.client.resources.I18n;
|
import net.minecraft.client.resources.I18n;
|
||||||
import org.lwjgl.input.Keyboard;
|
import org.lwjgl.input.Keyboard;
|
||||||
@@ -287,11 +286,7 @@ public class GuiReplayCenter extends GuiScreen implements GuiYesNoCallback {
|
|||||||
if(f == null) {
|
if(f == null) {
|
||||||
new GuiReplayDownloading(info).display();
|
new GuiReplayDownloading(info).display();
|
||||||
} else {
|
} else {
|
||||||
try {
|
mc.displayGuiScreen(new GuiReplayInstanceChooser(info, f));
|
||||||
ReplayHandler.startReplay(f);
|
|
||||||
} catch(Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if(button.id == GuiConstants.CENTER_FAV_REPLAY_BUTTON) {
|
} else if(button.id == GuiConstants.CENTER_FAV_REPLAY_BUTTON) {
|
||||||
|
|||||||
@@ -0,0 +1,164 @@
|
|||||||
|
package eu.crushedpixel.replaymod.gui.online;
|
||||||
|
|
||||||
|
import com.mojang.realmsclient.gui.ChatFormatting;
|
||||||
|
import eu.crushedpixel.replaymod.api.replay.holders.FileInfo;
|
||||||
|
import eu.crushedpixel.replaymod.gui.elements.ComposedElement;
|
||||||
|
import eu.crushedpixel.replaymod.gui.elements.GuiAdvancedButton;
|
||||||
|
import eu.crushedpixel.replaymod.gui.elements.GuiDropdown;
|
||||||
|
import eu.crushedpixel.replaymod.gui.elements.GuiString;
|
||||||
|
import eu.crushedpixel.replaymod.holders.GuiEntryListValueEntry;
|
||||||
|
import eu.crushedpixel.replaymod.replay.ReplayHandler;
|
||||||
|
import eu.crushedpixel.replaymod.utils.ReplayFile;
|
||||||
|
import eu.crushedpixel.replaymod.utils.ReplayFileIO;
|
||||||
|
import net.minecraft.client.gui.GuiScreen;
|
||||||
|
import net.minecraft.client.resources.I18n;
|
||||||
|
import org.apache.commons.io.FilenameUtils;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class GuiReplayInstanceChooser extends GuiScreen {
|
||||||
|
|
||||||
|
private boolean initialized = false;
|
||||||
|
|
||||||
|
private GuiString dropdownTitle;
|
||||||
|
private GuiDropdown<GuiEntryListValueEntry<File>> fileDropdown;
|
||||||
|
private GuiAdvancedButton chooseButton, cancelButton;
|
||||||
|
private ComposedElement composedElement;
|
||||||
|
|
||||||
|
private List<File> filesToChooseFrom = new ArrayList<File>();
|
||||||
|
|
||||||
|
private final String TITLE = I18n.format("replaymod.gui.viewer.chooser.title");
|
||||||
|
private final String REPLAYFILE = I18n.format("replaymod.gui.editor.replayfile")+":";
|
||||||
|
private final String MESSAGE;
|
||||||
|
|
||||||
|
private final String ORIGINAL = I18n.format("replaymod.gui.original");
|
||||||
|
private final String MODIFIED = I18n.format("replaymod.gui.modified");
|
||||||
|
|
||||||
|
public GuiReplayInstanceChooser(final FileInfo fileInfo, File downloadedFile) {
|
||||||
|
int id = fileInfo.getId();
|
||||||
|
|
||||||
|
this.MESSAGE = I18n.format("replaymod.gui.viewer.chooser.message", ChatFormatting.UNDERLINE+fileInfo.getName()+ChatFormatting.RESET);
|
||||||
|
|
||||||
|
//gather all applicable replay files
|
||||||
|
try {
|
||||||
|
File replayFolder = ReplayFileIO.getReplayFolder();
|
||||||
|
|
||||||
|
List<File> chooseableFiles = new ArrayList<File>();
|
||||||
|
|
||||||
|
for(File file : replayFolder.listFiles()) {
|
||||||
|
try {
|
||||||
|
String extension = FilenameUtils.getExtension(file.getAbsolutePath());
|
||||||
|
if(!("." + extension).equals(ReplayFile.ZIP_FILE_EXTENSION)) continue;
|
||||||
|
|
||||||
|
String filename = FilenameUtils.getBaseName(file.getAbsolutePath());
|
||||||
|
String[] split = filename.split("_");
|
||||||
|
String first = split[0];
|
||||||
|
|
||||||
|
if(StringUtils.isNumeric(first) && Integer.valueOf(first) == id) {
|
||||||
|
chooseableFiles.add(file);
|
||||||
|
}
|
||||||
|
} catch(Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//if no modified versions of the replay were found, start the downloaded one
|
||||||
|
if(chooseableFiles.isEmpty()) {
|
||||||
|
ReplayHandler.startReplay(downloadedFile);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
chooseableFiles.add(0, downloadedFile);
|
||||||
|
this.filesToChooseFrom = chooseableFiles;
|
||||||
|
|
||||||
|
} catch(IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void initGui() {
|
||||||
|
if(!initialized) {
|
||||||
|
dropdownTitle = new GuiString(0, 0, Color.WHITE, REPLAYFILE);
|
||||||
|
|
||||||
|
fileDropdown = new GuiDropdown<GuiEntryListValueEntry<File>>(fontRendererObj, 0, 0, 0, 5);
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
for(File file : filesToChooseFrom) {
|
||||||
|
String displayName = FilenameUtils.getName(file.getAbsolutePath()) + " (" + (i == 0 ? ORIGINAL : MODIFIED) + ")";
|
||||||
|
fileDropdown.addElement(new GuiEntryListValueEntry<File>(displayName, file));
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
chooseButton = new GuiAdvancedButton(0, 0, 100, 20, I18n.format("replaymod.gui.load"), new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
File file = fileDropdown.getElement(fileDropdown.getSelectionIndex()).getValue();
|
||||||
|
ReplayHandler.startReplay(file);
|
||||||
|
} catch(Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, null);
|
||||||
|
|
||||||
|
cancelButton = new GuiAdvancedButton(0, 0, 100, 20, I18n.format("replaymod.gui.cancel"), new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
mc.displayGuiScreen(new GuiReplayCenter());
|
||||||
|
}
|
||||||
|
}, null);
|
||||||
|
|
||||||
|
composedElement = new ComposedElement(dropdownTitle, fileDropdown, chooseButton, cancelButton);
|
||||||
|
}
|
||||||
|
|
||||||
|
fileDropdown.width = 200;
|
||||||
|
|
||||||
|
int strWidth = fontRendererObj.getStringWidth(REPLAYFILE);
|
||||||
|
int totWidth = strWidth + fileDropdown.width + 5;
|
||||||
|
|
||||||
|
dropdownTitle.positionX = (this.width-totWidth)/2;
|
||||||
|
fileDropdown.xPosition = dropdownTitle.positionX + strWidth + 5;
|
||||||
|
|
||||||
|
fileDropdown.yPosition = this.height/2 - 10;
|
||||||
|
|
||||||
|
dropdownTitle.positionY = fileDropdown.yPosition + 6;
|
||||||
|
|
||||||
|
cancelButton.xPosition = this.width - 100 - 5;
|
||||||
|
chooseButton.xPosition = cancelButton.xPosition - 100 - 5;
|
||||||
|
|
||||||
|
cancelButton.yPosition = chooseButton.yPosition = this.height - 5 - 20;
|
||||||
|
|
||||||
|
this.initialized = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
|
||||||
|
this.drawDefaultBackground();
|
||||||
|
drawCenteredString(fontRendererObj, ChatFormatting.UNDERLINE+TITLE, this.width / 2, 15, Color.WHITE.getRGB());
|
||||||
|
|
||||||
|
String[] lines = eu.crushedpixel.replaymod.utils.StringUtils.splitStringInMultipleRows(MESSAGE, this.width-40);
|
||||||
|
int i = 0;
|
||||||
|
for(String line : lines) {
|
||||||
|
drawString(fontRendererObj, line, 20, 40+(15*i), Color.WHITE.getRGB());
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
composedElement.draw(mc, mouseX, mouseY);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException {
|
||||||
|
composedElement.mouseClick(mc, mouseX, mouseY, mouseButton);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void mouseReleased(int mouseX, int mouseY, int state) {
|
||||||
|
composedElement.mouseRelease(mc, mouseX, mouseY, state);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -86,6 +86,9 @@ replaymod.gui.pleasewait=Please wait
|
|||||||
replaymod.gui.render=Render
|
replaymod.gui.render=Render
|
||||||
replaymod.gui.iphidden=Server IP Hidden
|
replaymod.gui.iphidden=Server IP Hidden
|
||||||
|
|
||||||
|
replaymod.gui.original=Original
|
||||||
|
replaymod.gui.modified=Modified
|
||||||
|
|
||||||
replaymod.gui.outdated=There is a newer Replay Mod version available. Please download it from replaymod.com
|
replaymod.gui.outdated=There is a newer Replay Mod version available. Please download it from replaymod.com
|
||||||
|
|
||||||
replaymod.gui.hours=h
|
replaymod.gui.hours=h
|
||||||
@@ -139,7 +142,10 @@ replaymod.gui.viewer.delete.linea=Are you sure you want to delete this replay?
|
|||||||
replaymod.gui.viewer.delete.lineb=will be lost forever! (a long time!)
|
replaymod.gui.viewer.delete.lineb=will be lost forever! (a long time!)
|
||||||
|
|
||||||
replaymod.gui.viewer.download.title=Downloading Replay File...
|
replaymod.gui.viewer.download.title=Downloading Replay File...
|
||||||
replaymod.gui.viewer.download.message=Please wait while %1$s is being downloaded.
|
replaymod.gui.viewer.download.message=Please wait while "%1$s" is being downloaded.
|
||||||
|
|
||||||
|
replaymod.gui.viewer.chooser.title=Choose Replay File
|
||||||
|
replaymod.gui.viewer.chooser.message=You have a modified version of "%1$s" on your computer. Which Replay do you want to load?
|
||||||
|
|
||||||
replaymod.gui.login.noacc=Don't have an account yet?
|
replaymod.gui.login.noacc=Don't have an account yet?
|
||||||
|
|
||||||
@@ -161,7 +167,6 @@ replaymod.gui.center.search.server=Server IP (Multiplayer only)
|
|||||||
replaymod.gui.center.search.category=Filter by Category
|
replaymod.gui.center.search.category=Filter by Category
|
||||||
replaymod.gui.center.search.version=Filter by Version
|
replaymod.gui.center.search.version=Filter by Version
|
||||||
|
|
||||||
|
|
||||||
replaymod.gui.center.downloadrequired=Download the Replay to rate or favorite it
|
replaymod.gui.center.downloadrequired=Download the Replay to rate or favorite it
|
||||||
|
|
||||||
replaymod.gui.center.favorite=Favorite
|
replaymod.gui.center.favorite=Favorite
|
||||||
|
|||||||
Reference in New Issue
Block a user