2025-03-16 21:58:55 +01:00
|
|
|
package game.gui;
|
|
|
|
|
|
|
|
import game.Game;
|
2025-05-01 15:13:38 +02:00
|
|
|
import game.ServerProcess;
|
2025-03-16 21:58:55 +01:00
|
|
|
import game.gui.element.Bar;
|
|
|
|
import game.gui.element.Label;
|
|
|
|
|
|
|
|
public class GuiLoading extends Gui {
|
|
|
|
public static interface Callback {
|
|
|
|
void poll(Game gm, GuiLoading gui);
|
|
|
|
}
|
|
|
|
|
|
|
|
private final String message;
|
|
|
|
private final Callback callback;
|
|
|
|
|
|
|
|
private Label headerLabel;
|
|
|
|
private Label taskLabel;
|
|
|
|
private Bar progressBar1;
|
|
|
|
private Bar progressBar2;
|
|
|
|
|
2025-05-03 18:01:17 +02:00
|
|
|
public static GuiLoading makeLoadTask(final ServerProcess server) {
|
|
|
|
return new GuiLoading("Starte Server ...", new Callback() {
|
2025-03-16 23:14:24 +01:00
|
|
|
boolean started = false;
|
|
|
|
|
2025-03-16 21:58:55 +01:00
|
|
|
public void poll(Game gm, GuiLoading gui) {
|
2025-03-16 23:14:24 +01:00
|
|
|
if(!this.started && server.isStarted()) {
|
|
|
|
this.started = true;
|
2025-05-03 18:01:17 +02:00
|
|
|
gm.displayGuiScreen(GuiMenu.INSTANCE);
|
2025-03-16 23:14:24 +01:00
|
|
|
}
|
|
|
|
int progress = server.getProgress();
|
|
|
|
if(progress < 0) {
|
|
|
|
gui.resetBar();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
gui.setBar(null, "Chunks", Math.max(1, server.getTotal()));
|
|
|
|
gui.setProgress(progress);
|
2025-03-16 21:58:55 +01:00
|
|
|
}
|
2025-03-16 23:14:24 +01:00
|
|
|
gui.setTask(server.getMessage());
|
2025-03-16 21:58:55 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2025-05-03 18:01:17 +02:00
|
|
|
public static GuiLoading makeSaveTask(final ServerProcess server) {
|
|
|
|
return new GuiLoading("Speichere Welt ...", new Callback() {
|
2025-03-28 14:30:37 +01:00
|
|
|
public void poll(Game gm, GuiLoading gui) {
|
2025-05-03 18:01:17 +02:00
|
|
|
if(server.isStopped()) {
|
|
|
|
gm.displayGuiScreen(GuiMenu.INSTANCE);
|
|
|
|
return;
|
|
|
|
}
|
2025-03-28 14:30:37 +01:00
|
|
|
int progress = server.getProgress();
|
|
|
|
if(progress < 0) {
|
|
|
|
gui.resetBar();
|
|
|
|
}
|
|
|
|
else {
|
2025-05-03 18:01:17 +02:00
|
|
|
gui.setBar(null, "Dimensionen", Math.max(1, server.getTotal()));
|
2025-03-28 14:30:37 +01:00
|
|
|
gui.setProgress(progress);
|
|
|
|
}
|
|
|
|
gui.setTask(server.getMessage());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2025-05-03 18:01:17 +02:00
|
|
|
public static GuiLoading makeServerTask(String message) {
|
|
|
|
return new GuiLoading(message, new Callback() {
|
2025-03-16 21:58:55 +01:00
|
|
|
public void poll(Game gm, GuiLoading gui) {
|
2025-05-03 18:01:17 +02:00
|
|
|
int progress = gm.progress;
|
2025-03-16 23:14:24 +01:00
|
|
|
if(progress < 0) {
|
|
|
|
gui.resetBar();
|
|
|
|
}
|
|
|
|
else {
|
2025-05-03 18:01:17 +02:00
|
|
|
gui.setBar(null, "Chunks", Math.max(1, gm.total));
|
2025-03-16 23:14:24 +01:00
|
|
|
gui.setProgress(progress);
|
|
|
|
}
|
2025-05-03 18:01:17 +02:00
|
|
|
gui.setTask(gm.message);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public static GuiLoading makeWaitTask(String message) {
|
|
|
|
return new GuiLoading(message, new Callback() {
|
|
|
|
public void poll(Game gm, GuiLoading gui) {
|
2025-03-16 21:58:55 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public GuiLoading(String message, Callback callback) {
|
|
|
|
this.message = message;
|
|
|
|
this.callback = callback;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void init(int width, int height) {
|
|
|
|
this.taskLabel = this.add(new Label(0, 40, 500, 20, ""));
|
2025-03-27 23:14:26 +01:00
|
|
|
this.progressBar1 = this.add(new Bar(0, 80, 500, 24));
|
|
|
|
this.progressBar2 = this.add(new Bar(0, 120, 500, 24));
|
2025-03-16 21:58:55 +01:00
|
|
|
this.shift();
|
|
|
|
this.headerLabel = this.add(new Label(0, 40, width, 20, this.message));
|
|
|
|
this.progressBar1.visible = false;
|
|
|
|
this.progressBar2.visible = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getTitle() {
|
|
|
|
return this.message;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setTask(String task) {
|
2025-03-16 23:14:24 +01:00
|
|
|
this.taskLabel.setText(task == null ? "" : task);
|
2025-03-16 21:58:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public void setBar(String desc) {
|
|
|
|
this.progressBar1.visible = true;
|
|
|
|
this.progressBar1.setDescription(desc);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setBar(String desc, String unit, int total) {
|
|
|
|
this.progressBar1.visible = true;
|
|
|
|
this.progressBar1.setDescription(desc, unit, total);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setBar(String desc, int total) {
|
|
|
|
this.progressBar1.visible = true;
|
|
|
|
this.progressBar1.setDescription(desc, total);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setProgress(float progress) {
|
|
|
|
this.progressBar1.setProgress(progress);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void resetBar() {
|
|
|
|
this.progressBar1.resetProgress();
|
|
|
|
this.progressBar1.visible = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setSub(String desc) {
|
|
|
|
this.progressBar2.visible = true;
|
|
|
|
this.progressBar2.setDescription(desc);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setSub(String desc, String unit, int total) {
|
|
|
|
this.progressBar2.visible = true;
|
|
|
|
this.progressBar2.setDescription(desc, unit, total);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setSub(String desc, int total) {
|
|
|
|
this.progressBar2.visible = true;
|
|
|
|
this.progressBar2.setDescription(desc, total);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setSubProgress(float progress) {
|
|
|
|
this.progressBar2.setProgress(progress);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void resetSub() {
|
|
|
|
this.progressBar2.resetProgress();
|
|
|
|
this.progressBar2.visible = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void updateScreen() {
|
|
|
|
if(this.callback != null)
|
|
|
|
this.callback.poll(this.gm, this);
|
|
|
|
}
|
|
|
|
}
|