add new files
This commit is contained in:
parent
4e90a93d68
commit
8038516a66
65 changed files with 7996 additions and 0 deletions
280
java/src/game/gui/GuiMenu.java
Normal file
280
java/src/game/gui/GuiMenu.java
Normal file
|
@ -0,0 +1,280 @@
|
|||
package game.gui;
|
||||
|
||||
import game.color.TextColor;
|
||||
import game.gui.element.ActButton;
|
||||
import game.gui.element.Label;
|
||||
import game.gui.element.Textbox;
|
||||
import game.gui.element.Textbox.Action;
|
||||
import game.gui.world.GuiWorlds;
|
||||
import game.init.Config;
|
||||
import game.renderer.Drawing;
|
||||
import game.rng.Random;
|
||||
import game.util.Splashes;
|
||||
import game.util.Timing;
|
||||
import game.window.Keysym;
|
||||
|
||||
public class GuiMenu extends Gui {
|
||||
public static final GuiMenu INSTANCE = new GuiMenu();
|
||||
|
||||
private GuiMenu() {
|
||||
}
|
||||
|
||||
public void drawMainBackground() {
|
||||
if(this.gm.theWorld != null)
|
||||
super.drawMainBackground();
|
||||
else
|
||||
this.gm.renderGlobal.renderStarField(this.gm.fb_x, this.gm.fb_y, 0x000000, 0xffffff, (float)this.ticks + (float)Timing.tick_fraction, this.rand);
|
||||
}
|
||||
|
||||
private final Random rand = new Random();
|
||||
|
||||
private Label splashLabel;
|
||||
|
||||
private int ticks;
|
||||
private int hacked;
|
||||
|
||||
private int animWidth = 32;
|
||||
private int animGrowth = 10;
|
||||
private int[] animGrow = new int[this.animWidth];
|
||||
private String animStr = "";
|
||||
private String animBack = "";
|
||||
private int animPos;
|
||||
private int animLen;
|
||||
private int animDir;
|
||||
private boolean animStep;
|
||||
|
||||
public void init(int width, int height) {
|
||||
if(this.gm.theWorld == null) {
|
||||
this.ticks = 0;
|
||||
this.hacked = 0;
|
||||
this.resetAnimation();
|
||||
this.add(new ActButton(0, 0, 400, 24, (Gui)GuiWorlds.INSTANCE, "Einzelspieler"));
|
||||
this.add(new ActButton(0, 28, 400, 24, (Gui)GuiConnect.INSTANCE, "Mehrspieler"));
|
||||
this.add(new ActButton(0, 56, 400, 24, GuiInfo.INSTANCE, "Info / Über / Mitwirkende"));
|
||||
this.add(new ActButton(0, 102, 196, 24, GuiOptions.getPage(), "Einstellungen"));
|
||||
this.add(new ActButton(204, 102, 196, 24, new ActButton.Callback() {
|
||||
public void use(ActButton elem, ActButton.Mode action) {
|
||||
GuiMenu.this.gm.interrupted = true;
|
||||
}
|
||||
}, "Spiel beenden"));
|
||||
this.shift();
|
||||
this.add(new Label(4, /* this.gm.fb_y - 2 */ 0, 200, 20, TextColor.VIOLET + Config.VERSION, true));
|
||||
this.splashLabel = this.add(new Label(0, 160, width, 24, ""));
|
||||
this.pickSplash();
|
||||
}
|
||||
else {
|
||||
this.add(new ActButton(0, 0, 400, 24, (Gui)null, "Zurück zum Spiel"));
|
||||
this.add(new ActButton(0, 28, 400, 24, GuiOptions.getPage(), "Einstellungen"));
|
||||
if(!this.gm.isRemote() && !this.gm.debugWorld) {
|
||||
this.add(new Textbox(0, 56, 96, 24, 5, true, new Textbox.Callback() {
|
||||
public void use(Textbox elem, Action value) {
|
||||
if(value == Action.SEND || value == Action.UNFOCUS) {
|
||||
int port = -1;
|
||||
try {
|
||||
port = Integer.parseInt(elem.getText());
|
||||
}
|
||||
catch(NumberFormatException e) {
|
||||
}
|
||||
if(port < 0 || port > 65535)
|
||||
elem.setText("" + GuiMenu.this.gm.port);
|
||||
else
|
||||
GuiMenu.this.gm.port = port;
|
||||
}
|
||||
}
|
||||
}, "" + this.gm.port)); // "srv_port"
|
||||
this.add(new ActButton(100, 56, 300, 24, new ActButton.Callback() {
|
||||
public void use(ActButton elem, ActButton.Mode action) {
|
||||
GuiMenu.this.gm.bind(GuiMenu.this.gm.bind = (GuiMenu.this.gm.bind != -1 ? -1 : GuiMenu.this.gm.port));
|
||||
elem.setText(GuiMenu.this.gm.bind != -1 ? "LAN-Welt schließen" : "LAN-Welt öffnen");
|
||||
}
|
||||
}, this.gm.bind != -1 ? "LAN-Welt schließen" : "LAN-Welt öffnen"));
|
||||
}
|
||||
this.add(new ActButton(0, 102, 400, 24, new ActButton.Callback() {
|
||||
public void use(ActButton elem, ActButton.Mode action) {
|
||||
GuiMenu.this.gm.unload();
|
||||
GuiMenu.this.gm.displayGuiScreen(INSTANCE);
|
||||
}
|
||||
}, this.gm.isRemote() ? "Verbindung trennen" : "Welt schließen"));
|
||||
this.shift();
|
||||
}
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return this.gm.theWorld == null ? "Hauptmenü" : "Menü";
|
||||
}
|
||||
|
||||
private void pickSplash() {
|
||||
this.splashLabel.setText(TextColor.VIOLET + this.rand.pick(Splashes.SPLASHES));
|
||||
}
|
||||
|
||||
private void resetAnimation() {
|
||||
this.animStr = "";
|
||||
this.animBack = "";
|
||||
this.animPos = 0;
|
||||
this.animLen = 0;
|
||||
this.animDir = 0;
|
||||
this.animStep = false;
|
||||
this.animWidth = Math.max(5, (this.gm.fb_x - 5) / 10);
|
||||
this.animGrowth = this.animWidth / 15;
|
||||
this.animGrow = new int[this.animWidth];
|
||||
}
|
||||
|
||||
private void updateAnimation() {
|
||||
if(this.animLen == 0) {
|
||||
this.animDir = this.rand.zrange(3) - 1;
|
||||
this.animLen = this.animDir == 0 ? (2 + this.rand.zrange(2)) : (8 + this.rand.zrange(96));
|
||||
}
|
||||
else {
|
||||
this.animPos += this.animDir;
|
||||
if(this.animPos == -1) {
|
||||
this.animPos = 0;
|
||||
this.animDir = 1;
|
||||
}
|
||||
else if(this.animPos == this.animWidth - 3) {
|
||||
this.animPos = this.animWidth - 4;
|
||||
this.animDir = -1;
|
||||
}
|
||||
this.animLen--;
|
||||
}
|
||||
this.animStep = !this.animStep;
|
||||
StringBuilder sb = new StringBuilder(11);
|
||||
sb.append(TextColor.GRAY);
|
||||
sb.append("[");
|
||||
sb.append(TextColor.YELLOW);
|
||||
switch(this.animDir) {
|
||||
case -1:
|
||||
sb.append((this.animStep ? '>' : '-') + "' ");
|
||||
break;
|
||||
case 0:
|
||||
sb.append("`" + (this.animStep ? 'O' : 'o') + "'");
|
||||
break;
|
||||
case 1:
|
||||
sb.append(" `" + (this.animStep ? '<' : '-'));
|
||||
break;
|
||||
}
|
||||
sb.append(TextColor.GRAY);
|
||||
sb.append("]");
|
||||
this.animStr = sb.toString();
|
||||
for(int z = this.animPos; z < this.animPos + 4; z++) {
|
||||
this.animGrow[z] = 0;
|
||||
}
|
||||
for(int z = 0; z < this.animGrowth; z++) {
|
||||
this.animGrow[this.rand.zrange(this.animWidth)] += 1;
|
||||
}
|
||||
sb = new StringBuilder(this.animWidth + 2);
|
||||
sb.append(TextColor.DGREEN);
|
||||
for(int z = 0; z < this.animWidth; z++) {
|
||||
switch(this.animGrow[z] / 5) {
|
||||
case 0:
|
||||
sb.append(TextColor.BLACK);
|
||||
break;
|
||||
case 1:
|
||||
sb.append(TextColor.GRAY);
|
||||
break;
|
||||
case 2:
|
||||
case 3:
|
||||
sb.append(TextColor.LGRAY);
|
||||
break;
|
||||
case 4:
|
||||
case 5:
|
||||
case 6:
|
||||
sb.append(TextColor.WHITE);
|
||||
break;
|
||||
case 7:
|
||||
case 8:
|
||||
case 9:
|
||||
case 10:
|
||||
sb.append(TextColor.MAGENTA);
|
||||
break;
|
||||
case 11:
|
||||
case 12:
|
||||
case 13:
|
||||
case 14:
|
||||
case 15:
|
||||
sb.append(TextColor.DVIOLET);
|
||||
break;
|
||||
default:
|
||||
sb.append(TextColor.VIOLET);
|
||||
break;
|
||||
}
|
||||
sb.append(",.");
|
||||
}
|
||||
this.animBack = sb.toString();
|
||||
}
|
||||
|
||||
public void updateScreen() {
|
||||
if(this.gm.theWorld == null) {
|
||||
this.ticks++;
|
||||
if(this.gm.shift() && !(this.selected instanceof Textbox))
|
||||
this.pickSplash();
|
||||
this.updateAnimation();
|
||||
}
|
||||
}
|
||||
|
||||
public void key(Keysym key, boolean ctrl, boolean shift) {
|
||||
super.key(key, ctrl, shift);
|
||||
if(this.gm.theWorld == null) {
|
||||
if((key == Keysym.UP || key == Keysym.W) && (this.hacked == 0 || this.hacked == 1))
|
||||
this.hacked++;
|
||||
else if((key == Keysym.DOWN || key == Keysym.S) && (this.hacked == 2 || this.hacked == 3))
|
||||
this.hacked++;
|
||||
else if((key == Keysym.LEFT || key == Keysym.A) && (this.hacked == 4 || this.hacked == 6))
|
||||
this.hacked++;
|
||||
else if((key == Keysym.RIGHT || key == Keysym.D) && (this.hacked == 5 || this.hacked == 7))
|
||||
this.hacked++;
|
||||
else
|
||||
this.hacked = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
protected void actionPerformed(Button button) throws IOException {
|
||||
if(button.id == 2 && this.hacked == 8) {
|
||||
this.hacked++;
|
||||
return;
|
||||
}
|
||||
else if(button.id == 1 && this.hacked == 9) {
|
||||
this.hacked++;
|
||||
return;
|
||||
}
|
||||
if(button.id != 3 || this.hacked != 10)
|
||||
this.hacked = 0;
|
||||
switch(button.id) {
|
||||
case 0:
|
||||
this.gm.displayGuiScreen(new GuiOptions(this));
|
||||
break;
|
||||
case 1:
|
||||
this.gm.displayGuiScreen(new GuiWorlds(this));
|
||||
break;
|
||||
case 2:
|
||||
this.gm.displayGuiScreen(new GuiMultiplayer(this));
|
||||
break;
|
||||
case 3:
|
||||
if(this.hacked == 10)
|
||||
Log.info("Hax!");
|
||||
this.gm.displayGuiScreen(new GuiCredits(this.hacked == 10));
|
||||
this.hacked = 0;
|
||||
break;
|
||||
// case 4:
|
||||
// this.gm.displayGuiScreen(new GuiLanguage());
|
||||
// break;
|
||||
case 4:
|
||||
this.gm.shutdown();
|
||||
break;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
public void drawOverlays() {
|
||||
super.drawOverlays();
|
||||
if(this.gm.theWorld == null) {
|
||||
int y = 164;
|
||||
int h = 16;
|
||||
int n = Drawing.getWidth(this.splashLabel.getText());
|
||||
Drawing.drawRectColor(0, y, this.gm.fb_x / 2 - n / 2 - 10, h, 0x7f7f00ff);
|
||||
Drawing.drawRectColor(this.gm.fb_x / 2 + n / 2 + 10, y, this.gm.fb_x - (this.gm.fb_x / 2 + n / 2 + 10), h, 0x7f7f00ff);
|
||||
Drawing.drawText(this.animBack, this.gm.fb_x - Drawing.getWidth(this.animBack) - 2, this.gm.fb_y - 18, 0xffffffff);
|
||||
Drawing.drawText(this.animStr, this.gm.fb_x - Drawing.getWidth(this.animStr) - ((this.animWidth - this.animPos - 4) * 10), this.gm.fb_y - 20, 0xffffffff);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue