2025-03-11 14:09:49 +01:00
|
|
|
package game.gui;
|
|
|
|
|
|
|
|
import game.color.TextColor;
|
2025-03-30 13:35:02 +02:00
|
|
|
import game.gui.character.GuiChar;
|
|
|
|
import game.gui.character.GuiCharacters;
|
2025-03-11 14:09:49 +01:00
|
|
|
import game.gui.element.ActButton;
|
2025-03-18 10:24:05 +01:00
|
|
|
import game.gui.element.ActButton.Mode;
|
2025-03-11 14:09:49 +01:00
|
|
|
import game.gui.element.Label;
|
2025-03-26 12:22:32 +01:00
|
|
|
import game.gui.element.NavButton;
|
2025-03-11 14:09:49 +01:00
|
|
|
import game.gui.element.Textbox;
|
2025-03-26 12:22:32 +01:00
|
|
|
import game.gui.options.GuiOptions;
|
2025-05-03 22:42:03 +02:00
|
|
|
import game.gui.world.GuiServers;
|
2025-03-11 14:09:49 +01:00
|
|
|
import game.gui.world.GuiWorlds;
|
|
|
|
import game.init.Config;
|
|
|
|
import game.renderer.Drawing;
|
|
|
|
import game.rng.Random;
|
2025-03-17 02:11:09 +01:00
|
|
|
import game.util.ExtMath;
|
2025-03-11 14:09:49 +01:00
|
|
|
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();
|
2025-03-17 02:11:09 +01:00
|
|
|
|
2025-03-11 14:09:49 +01:00
|
|
|
private Label splashLabel;
|
2025-03-17 02:11:09 +01:00
|
|
|
private ActButton infoButton;
|
2025-03-11 14:09:49 +01:00
|
|
|
|
|
|
|
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();
|
2025-03-17 02:11:09 +01:00
|
|
|
this.add(new ActButton(0, 0, 400, 24, new ActButton.Callback() {
|
|
|
|
public void use(ActButton elem, Mode action) {
|
|
|
|
if(GuiMenu.this.hacked == 9) {
|
|
|
|
GuiMenu.this.hacked++;
|
|
|
|
GuiMenu.this.splashLabel.setText(TextColor.VIOLET + "Hax!");
|
|
|
|
}
|
2025-05-03 18:01:17 +02:00
|
|
|
else if(GuiMenu.this.gm.isServerRunning()) {
|
|
|
|
GuiMenu.this.gm.stopServer(true);
|
|
|
|
}
|
2025-03-17 02:11:09 +01:00
|
|
|
else {
|
|
|
|
GuiMenu.this.gm.displayGuiScreen(GuiWorlds.INSTANCE);
|
|
|
|
}
|
|
|
|
}
|
2025-05-03 18:01:17 +02:00
|
|
|
}, this.gm.isServerRunning() ? "Server beenden" : "Server hosten"));
|
2025-03-17 02:11:09 +01:00
|
|
|
this.add(new ActButton(0, 28, 400, 24, new ActButton.Callback() {
|
|
|
|
public void use(ActButton elem, Mode action) {
|
|
|
|
if(GuiMenu.this.hacked == 8)
|
|
|
|
GuiMenu.this.hacked++;
|
|
|
|
else
|
2025-05-03 22:42:03 +02:00
|
|
|
GuiMenu.this.gm.displayGuiScreen(GuiServers.INSTANCE);
|
2025-03-17 02:11:09 +01:00
|
|
|
}
|
2025-05-03 18:01:17 +02:00
|
|
|
}, "Server beitreten"));
|
2025-03-17 02:11:09 +01:00
|
|
|
this.infoButton = this.add(new ActButton(0, 56, 400, 24, new ActButton.Callback() {
|
|
|
|
public void use(ActButton elem, Mode action) {
|
|
|
|
GuiMenu.this.gm.displayGuiScreen(GuiMenu.this.hacked == 10 ? GuiInfo.HAX : GuiInfo.INSTANCE);
|
|
|
|
}
|
|
|
|
}, "Info / Über / Mitwirkende") {
|
|
|
|
public void drawHover() {
|
|
|
|
if(GuiMenu.this.hacked == 10) {
|
2025-03-20 15:33:08 +01:00
|
|
|
Drawing.drawRect(this.pos_x, this.pos_y, this.size_x, this.size_y, 0x287f00ff);
|
2025-03-17 02:11:09 +01:00
|
|
|
GuiMenu.this.rand.setSeed(((long)this.gm.mouse_x * 7652657L) ^ ((long)this.gm.mouse_y * 87262826276L));
|
|
|
|
int width = Drawing.getWidth("Hax!");
|
|
|
|
for(int z = 0; z < 64; z++) {
|
|
|
|
Drawing.drawText("Hax!", GuiMenu.this.rand.zrange(Math.max(1, this.gm.fb_x - width)) +
|
|
|
|
(int)(ExtMath.sin(((float)(GuiMenu.this.ticks + GuiMenu.this.rand.zrange(256)) + (float)Timing.tick_fraction) / 100.0f * (float)Math.PI * 2.0f) * 16.0f),
|
|
|
|
GuiMenu.this.rand.zrange(Math.max(1, this.gm.fb_y - Font.YGLYPH)) +
|
|
|
|
(int)(ExtMath.sin(((float)(GuiMenu.this.ticks + GuiMenu.this.rand.zrange(256)) + (float)Timing.tick_fraction) / 100.0f * (float)Math.PI * 2.0f) * 16.0f),
|
|
|
|
0xff0000ff | (GuiMenu.this.rand.zrange(256) << 16));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
super.drawHover();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2025-03-26 12:22:32 +01:00
|
|
|
this.add(new NavButton(0, 102, 196, 24, GuiOptions.getPage(), "Einstellungen"));
|
2025-03-11 14:09:49 +01:00
|
|
|
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 {
|
2025-03-27 23:14:26 +01:00
|
|
|
this.add(new NavButton(0, 0, 400, 24, this.gm.charEditor ? GuiChar.INSTANCE : null, this.gm.charEditor ? "Zurück zum Charakter-Editor" : "Zurück zum Spiel"));
|
2025-03-27 17:54:03 +01:00
|
|
|
this.add(new NavButton(0, 28, this.gm.charEditor ? 400 : 198, 24, GuiOptions.getPage(), "Einstellungen"));
|
|
|
|
if(!this.gm.charEditor)
|
|
|
|
this.add(new NavButton(202, 28, 198, 24, GuiCharacters.INSTANCE, "Charakter"));
|
2025-03-11 14:09:49 +01:00
|
|
|
this.add(new ActButton(0, 102, 400, 24, new ActButton.Callback() {
|
|
|
|
public void use(ActButton elem, ActButton.Mode action) {
|
2025-03-16 23:14:24 +01:00
|
|
|
GuiMenu.this.gm.unload(true);
|
|
|
|
// GuiMenu.this.gm.displayGuiScreen(INSTANCE);
|
2025-03-11 14:09:49 +01:00
|
|
|
}
|
2025-05-03 18:01:17 +02:00
|
|
|
}, "Server verlassen und Verbindung trennen"));
|
2025-03-11 14:09:49 +01:00
|
|
|
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());
|
2025-03-19 21:54:09 +01:00
|
|
|
Drawing.drawRect(0, y, this.gm.fb_x / 2 - n / 2 - 10, h, 0x7f7f00ff);
|
|
|
|
Drawing.drawRect(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), this.gm.fb_y - 18, 0xffffffff);
|
|
|
|
Drawing.drawText(this.animStr, this.gm.fb_x - Drawing.getWidth(this.animStr) - 3 - ((this.animWidth - this.animPos - 4) * 10), this.gm.fb_y - 20, 0xffffffff);
|
2025-03-11 14:09:49 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|