Buttons im Startmenü ausgerichtet

This commit is contained in:
Yvonne Schmidt 2024-11-15 02:28:10 +01:00
parent 853b52b52d
commit b622d66942

View File

@ -1,14 +1,17 @@
package pp.monopoly.client;
import com.jme3.math.Vector3f;
import com.simsilica.lemur.Axis;
import com.simsilica.lemur.Button;
import com.simsilica.lemur.Container;
import com.simsilica.lemur.Label;
import com.simsilica.lemur.component.SpringGridLayout;
import pp.dialog.Dialog;
import pp.monopoly.client.gui.CreateGameMenu;
import pp.monopoly.client.gui.SettingsMenu;
/**
* Constructs the startup menu dialog for the Monopoly application.
*/
@ -30,28 +33,51 @@ public class StartMenu extends Dialog {
* opening settings, and quitting the application.
*/
public static void createStartMenu(MonopolyApp app) {
Container mainMenu = new Container();
mainMenu.setLocalTranslation(new Vector3f(300, 300, 0)); // Positionierung des Menüs
// Titel des Hauptmenüs
mainMenu.addChild(new Label("Hauptmenü"));
int screenWidth = app.getContext().getSettings().getWidth();
int screenHeight = app.getContext().getSettings().getHeight();
// Schaltfläche "Spielen" - Wechselt zum CreateGameMenu
Button startButton = mainMenu.addChild(new Button("Spielen"));
// Center container for header and play button
Container centerMenu = new Container(new SpringGridLayout(Axis.Y, Axis.X));
centerMenu.setLocalTranslation(new Vector3f(300, 300, 0)); // Position in the center of the screen
// Title of the main menu
centerMenu.addChild(new Label("Hauptmenü"));
// "Spielen" button - centered
Button startButton = centerMenu.addChild(new Button("Spielen"));
startButton.addClickCommands(source -> startGame(app));
// Schaltfläche "Einstellungen" - Öffnet das Einstellungsmenü
Button settingsButton = mainMenu.addChild(new Button("Einstellungen"));
settingsButton.addClickCommands(source -> openSettings(app));
// Position the center container in the middle of the screen
centerMenu.setLocalTranslation(new Vector3f(screenWidth / 2f - centerMenu.getPreferredSize().x / 2f,
screenHeight / 2f + centerMenu.getPreferredSize().y / 2f,
0));
// Schaltfläche "Spiel beenden" - Beendet das Spiel
Button quitButton = mainMenu.addChild(new Button("Spiel beenden"));
// Attach the center container to the GUI node
app.getGuiNode().attachChild(centerMenu);
// Lower-left container for "Spiel beenden" button
Container lowerLeftMenu = new Container();
lowerLeftMenu.setLocalTranslation(new Vector3f(50, 50, 0)); // Position in the lower-left corner
// "Spiel beenden" button - lower left corner
Button quitButton = lowerLeftMenu.addChild(new Button("Spiel beenden"));
quitButton.addClickCommands(source -> quitGame());
// Hauptmenü dem Bildschirm hinzufügen
app.getGuiNode().attachChild(mainMenu);
}
// Attach the lower-left container to the GUI node
app.getGuiNode().attachChild(lowerLeftMenu);
// Lower-right container for "Einstellungen" button
Container lowerRightMenu = new Container();
lowerRightMenu.setLocalTranslation(new Vector3f(screenWidth - 150, 50, 0)); // Position in the lower-right corner
// "Einstellungen" button - lower right corner
Button settingsButton = lowerRightMenu.addChild(new Button("Einstellungen"));
settingsButton.addClickCommands(source -> openSettings(app));
// Attach the lower-right container to the GUI node
app.getGuiNode().attachChild(lowerRightMenu);
}
/**
* Starts the game by transitioning to the CreateGameMenu.
*/