loading gui + converter
This commit is contained in:
parent
90de256e04
commit
987ed4059e
2 changed files with 205 additions and 0 deletions
120
java/src/game/gui/GuiLoading.java
Normal file
120
java/src/game/gui/GuiLoading.java
Normal file
|
@ -0,0 +1,120 @@
|
|||
package game.gui;
|
||||
|
||||
import game.Game;
|
||||
import game.Server;
|
||||
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;
|
||||
|
||||
public static GuiLoading makeLoadTask(final Server server) {
|
||||
return new GuiLoading("Lade Welt ...", new Callback() {
|
||||
public void poll(Game gm, GuiLoading gui) {
|
||||
if(server.isStarted()) {
|
||||
gm.displayGuiScreen(null);
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static GuiLoading makeSaveTask(final Server server) {
|
||||
return new GuiLoading("Speichere Welt ...", new Callback() {
|
||||
public void poll(Game gm, GuiLoading gui) {
|
||||
if(server.isStopped()) {
|
||||
gm.displayGuiScreen(GuiMenu.INSTANCE);
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
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, ""));
|
||||
this.progressBar1 = this.add(new Bar(0, 80, 500, 20));
|
||||
this.progressBar2 = this.add(new Bar(0, 120, 500, 20));
|
||||
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) {
|
||||
this.taskLabel.setText(task);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
85
java/src/game/gui/element/Bar.java
Normal file
85
java/src/game/gui/element/Bar.java
Normal file
|
@ -0,0 +1,85 @@
|
|||
package game.gui.element;
|
||||
|
||||
import game.renderer.Drawing;
|
||||
import game.util.ExtMath;
|
||||
|
||||
public class Bar extends Fill {
|
||||
private int color = 0x00ff00;
|
||||
private int progress = 0;
|
||||
private int total = 0;
|
||||
private String desc = "";
|
||||
private String unit = "";
|
||||
|
||||
public Bar(int x, int y, int w, int h, boolean top, boolean left) {
|
||||
super(x, y, w, h, "", top, left);
|
||||
}
|
||||
|
||||
public Bar(int x, int y, int w, int h, boolean left) {
|
||||
super(x, y, w, h, "", left);
|
||||
}
|
||||
|
||||
public Bar(int x, int y, int w, int h) {
|
||||
super(x, y, w, h, "");
|
||||
}
|
||||
|
||||
protected void drawBackground() {
|
||||
Drawing.drawGradient2Border(this.pos_x, this.pos_y, this.size_x, this.size_y, this.gm.style.fill_btm, this.gm.style.fill_top, this.gm.style.brdr_top, this.gm.style.brdr_btm);
|
||||
if(this.progress > 0)
|
||||
Drawing.drawGradient(this.pos_x + 2, this.pos_y + 2, this.progress, this.size_y - 4, this.color | 0xff000000, Drawing.mixColor(this.color | 0xff000000, 0xff000000));
|
||||
}
|
||||
|
||||
protected void drawForeground(int x1, int y1, int x2, int y2) {
|
||||
Drawing.drawText(this.text, x1 + this.text_x, y1 + this.text_y, this.gm.style.text_label);
|
||||
}
|
||||
|
||||
protected int getMargin() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public Bar setDescription(String desc, String unit, int total) {
|
||||
this.desc = desc == null ? "" : (desc + ": ");
|
||||
this.unit = unit == null ? "" : (" " + unit);
|
||||
this.total = total;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Bar setDescription(String desc, int total) {
|
||||
return this.setDescription(desc, null, total);
|
||||
}
|
||||
|
||||
public Bar setDescription(String desc) {
|
||||
this.desc = desc == null ? "" : (desc + ": ");
|
||||
this.unit = "";
|
||||
this.total = 0;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Bar resetProgress() {
|
||||
this.setText("");
|
||||
this.progress = 0;
|
||||
this.setDescription(null);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Bar setProgressFill(int progress) {
|
||||
this.progress = ExtMath.clampi(progress, 0, this.size_x - 4);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Bar setProgressFill(float progress) {
|
||||
return this.setProgressFill((int)(progress * (float)(this.size_x - 4)));
|
||||
}
|
||||
|
||||
public Bar setProgress(float progress) {
|
||||
if(this.total == 0)
|
||||
this.setText(String.format("%s%.1f %%", this.desc, progress * 100.0f));
|
||||
else
|
||||
this.setText(String.format("%s%d/%d%s (%.1f %%)", this.desc, (int)progress, this.total, this.unit, (progress / (float)this.total) * 100.0f));
|
||||
return this.setProgressFill(this.total == 0 ? progress : (progress / (float)this.total));
|
||||
}
|
||||
|
||||
public Bar setColor(int color) {
|
||||
this.color = color;
|
||||
return this;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue