Add online (aka ReplayCenter) module

Add localization extra (formally known as LocalizedResourcePack)
Add version checker extra
This commit is contained in:
johni0702
2015-11-14 15:36:49 +01:00
parent 5e5172fd3f
commit 7c8dde3322
54 changed files with 1186 additions and 1189 deletions

View File

@@ -0,0 +1,89 @@
package com.replaymod.online.gui;
import com.mojang.realmsclient.gui.ChatFormatting;
import com.replaymod.online.ReplayModOnline;
import com.replaymod.online.api.ApiClient;
import com.replaymod.online.api.ApiException;
import de.johni0702.minecraft.gui.container.AbstractGuiScreen;
import de.johni0702.minecraft.gui.container.GuiScreen;
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.gui.elements.listeners.ProgressUpdateListener;
import java.io.File;
import java.io.IOException;
public class GuiReplayDownloading extends AbstractGuiScreen<GuiReplayDownloading> implements ProgressUpdateListener {
private final GuiScreen cancelScreen;
private final ApiClient apiClient;
private GuiProgressBar progressBar = new GuiProgressBar(this).setHeight(20);
private GuiButton cancelButton = new GuiButton(this).setI18nLabel("gui.cancel").setSize(150, 20).onClick(new Runnable() {
@Override
public void run() {
apiClient.cancelDownload();
cancelScreen.display();
}
});
public GuiReplayDownloading(GuiScreen cancelScreen, final ReplayModOnline mod,
final int replayId, String name) {
this.cancelScreen = cancelScreen;
this.apiClient = mod.getApiClient();
setTitle(new GuiLabel().setI18nText("replaymod.gui.viewer.download.title"));
final GuiLabel subTitle = new GuiLabel(this).setI18nText("replaymod.gui.viewer.download.message",
ChatFormatting.UNDERLINE + name + 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 = mod.getDownloadedFile(replayId);
try {
apiClient.downloadFile(replayId, replayFile, GuiReplayDownloading.this);
if (replayFile.exists()) {
getMinecraft().addScheduledTask(new Runnable() {
@Override
public void run() {
try {
mod.getReplayModule().startReplay(replayFile);
} catch (IOException e) {
e.printStackTrace();
}
}
});
}
} catch (IOException | ApiException e) {
e.printStackTrace();
}
}
}).start();
}
@Override
public void onProgressChanged(float progress) {
progressBar.setProgress(progress);
}
@Override
public void onProgressChanged(float progress, String progressString) {
onProgressChanged(progress);
}
@Override
protected GuiReplayDownloading getThis() {
return this;
}
}