Use new Gui API for GuiReplayDownloading

This commit is contained in:
johni0702
2015-07-09 18:30:31 +02:00
parent c66efc91b7
commit 59e6b87935
3 changed files with 39 additions and 69 deletions

View File

@@ -391,7 +391,7 @@ public class ReplayMod {
File file = ReplayMod.downloadedFileHandler.getFileForID(id);
if (file == null) {
FileInfo info = new FileInfo(id, null, null, null, 0, 0, 0, String.valueOf(id), false, 0);
mc.displayGuiScreen(new GuiReplayDownloading(info));
new GuiReplayDownloading(info).display();
} else {
try {
ReplayHandler.startReplay(file);

View File

@@ -284,7 +284,7 @@ public class GuiReplayCenter extends GuiScreen implements GuiYesNoCallback {
if(info != null) {
File f = ReplayMod.downloadedFileHandler.getFileForID(info.getId());
if(f == null) {
mc.displayGuiScreen(new GuiReplayDownloading(info));
new GuiReplayDownloading(info).display();
} else {
try {
ReplayHandler.startReplay(f);

View File

@@ -1,46 +1,56 @@
package eu.crushedpixel.replaymod.gui.online;
import com.mojang.realmsclient.gui.ChatFormatting;
import de.johni0702.minecraft.gui.container.AbstractGuiScreen;
import de.johni0702.minecraft.gui.element.GuiButton;
import de.johni0702.minecraft.gui.element.GuiLabel;
import de.johni0702.minecraft.gui.element.advanced.GuiProgressBar;
import de.johni0702.minecraft.gui.layout.CustomLayout;
import eu.crushedpixel.replaymod.ReplayMod;
import eu.crushedpixel.replaymod.api.replay.holders.FileInfo;
import eu.crushedpixel.replaymod.gui.GuiConstants;
import eu.crushedpixel.replaymod.gui.elements.GuiProgressBar;
import eu.crushedpixel.replaymod.gui.elements.listeners.ProgressUpdateListener;
import eu.crushedpixel.replaymod.replay.ReplayHandler;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.resources.I18n;
import java.awt.*;
import java.io.File;
import java.io.IOException;
public class GuiReplayDownloading extends GuiScreen implements ProgressUpdateListener {
public class GuiReplayDownloading extends AbstractGuiScreen<GuiReplayDownloading> implements ProgressUpdateListener {
private String title;
private String pleaseWait;
private String cancelCallback;
private boolean callback = false;
private boolean initialized = false;
private GuiProgressBar progressBar;
private GuiButton cancelButton;
private GuiProgressBar progressBar = new GuiProgressBar(this).setHeight(20);
private GuiButton cancelButton = new GuiButton(this).setI18nLabel("gui.cancel").setWidth(150).onClick(new Runnable() {
@Override
public void run() {
ReplayMod.apiClient.cancelDownload();
getMinecraft().displayGuiScreen(new GuiReplayCenter());
}
});
public GuiReplayDownloading(final FileInfo fileInfo) {
pleaseWait = I18n.format("replaymod.gui.viewer.download.message", ChatFormatting.UNDERLINE+fileInfo.getName()+ChatFormatting.RESET);
setTitle(new GuiLabel().setI18nText("replaymod.gui.viewer.download.title"));
final GuiLabel subTitle = new GuiLabel(this).setI18nText("replaymod.gui.viewer.download.message",
ChatFormatting.UNDERLINE + fileInfo.getName() + ChatFormatting.RESET);
setLayout(new CustomLayout<GuiReplayDownloading>() {
@Override
protected void layout(GuiReplayDownloading container, int width, int height) {
width(progressBar, width - 20);
pos(progressBar, 10, height - 50);
pos(cancelButton, width - 5 - 150, height - 5 - 20);
pos(subTitle, width / 2 - subTitle.getMinSize().getWidth() / 2, 40);
}
});
new Thread(new Runnable() {
@Override
public void run() {
final File replayFile = ReplayMod.downloadedFileHandler.downloadFileForID(fileInfo.getId(), GuiReplayDownloading.this);
if(replayFile.exists()) {
mc.addScheduledTask(new Runnable() {
getMinecraft().addScheduledTask(new Runnable() {
@Override
public void run() {
try {
ReplayHandler.startReplay(replayFile);
} catch(Exception e) {
} catch (Exception e) {
e.printStackTrace();
}
}
@@ -50,58 +60,18 @@ public class GuiReplayDownloading extends GuiScreen implements ProgressUpdateLis
}).start();
}
@Override
public void initGui() {
if(!initialized) {
title = I18n.format("replaymod.gui.viewer.download.title");
cancelCallback = I18n.format("replaymod.gui.rendering.cancel.callback");
progressBar = new GuiProgressBar();
cancelButton = new GuiButton(GuiConstants.REPLAY_DOWNLOADING_CANCEL_BUTTON, 0, 0, I18n.format("gui.cancel"));
}
progressBar.setBounds(10, this.height-30-20, this.width-20, 20);
cancelButton.xPosition = this.width - 5 - 150;
cancelButton.width = 150;
cancelButton.yPosition = this.height - 5 - 20;
buttonList.add(cancelButton);
initialized = true;
}
@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
this.drawDefaultBackground();
super.drawScreen(mouseX, mouseY, partialTicks);
this.drawCenteredString(mc.fontRendererObj, title, this.width / 2, 20, Color.WHITE.getRGB());
this.drawCenteredString(mc.fontRendererObj, pleaseWait, this.width / 2, 40, Color.WHITE.getRGB());
progressBar.drawProgressBar();
}
@Override
protected void actionPerformed(GuiButton button) throws IOException {
if(!button.enabled) return;
if(button.id == GuiConstants.REPLAY_DOWNLOADING_CANCEL_BUTTON) {
if(!callback) {
callback = true;
button.displayString = cancelCallback;
} else {
ReplayMod.apiClient.cancelDownload();
mc.displayGuiScreen(new GuiReplayCenter());
}
}
}
@Override
public void onProgressChanged(float progress) {
if(progressBar != null) progressBar.setProgress(progress);
progressBar.setProgress(progress);
}
@Override
public void onProgressChanged(float progress, String progressString) {
onProgressChanged(progress);
}
@Override
protected GuiReplayDownloading getThis() {
return this;
}
}