mirror of
https://athene2.informatik.unibw-muenchen.de/progproj/gruppen-ht24/Gruppe-02.git
synced 2025-08-01 06:27:40 +02:00
Positionierung StartMenu Buttons & SettingsMenu
This commit is contained in:
@@ -5,9 +5,11 @@ import com.jme3.math.Vector3f;
|
||||
import com.jme3.scene.Geometry;
|
||||
import com.jme3.scene.shape.Quad;
|
||||
import com.jme3.texture.Texture;
|
||||
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;
|
||||
@@ -34,60 +36,72 @@ public class StartMenu extends Dialog {
|
||||
* opening settings, and quitting the application.
|
||||
*/
|
||||
public static void createStartMenu(MonopolyApp app) {
|
||||
Container mainMenu = new Container();
|
||||
int screenWidth = app.getContext().getSettings().getWidth();
|
||||
int screenHeight = app.getContext().getSettings().getHeight();
|
||||
|
||||
// Hintergrundbild für das Startmenü
|
||||
// Set up the background image
|
||||
Texture backgroundImage = app.getAssetManager().loadTexture("Pictures/unibw-Bib2.png");
|
||||
Quad quad = new Quad(app.getCamera().getWidth(), app.getCamera().getHeight()); // Vollbildgröße
|
||||
Quad quad = new Quad(screenWidth, screenHeight);
|
||||
Geometry background = new Geometry("Background", quad);
|
||||
Material backgroundMaterial = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
|
||||
backgroundMaterial.setTexture("ColorMap", backgroundImage);
|
||||
background.setMaterial(backgroundMaterial);
|
||||
background.setLocalTranslation(0, 0, -1); // Hintergrundebene
|
||||
background.setLocalTranslation(0, 0, -1); // Ensure it is behind other GUI elements
|
||||
app.getGuiNode().attachChild(background);
|
||||
|
||||
// Positionierung des Hauptmenüs
|
||||
mainMenu.setLocalTranslation(new Vector3f(300, 300, 0));
|
||||
// Center container for title and play button
|
||||
Container centerMenu = new Container(new SpringGridLayout(Axis.Y, Axis.X));
|
||||
Label titleLabel = new Label("Hauptmenü");
|
||||
titleLabel.setFontSize(48);
|
||||
centerMenu.addChild(titleLabel);
|
||||
|
||||
// Titel des Hauptmenüs
|
||||
mainMenu.addChild(new Label("Hauptmenü"));
|
||||
Button startButton = new Button("Spielen");
|
||||
startButton.addClickCommands(source -> startGame(app));
|
||||
centerMenu.addChild(startButton);
|
||||
|
||||
// Schaltfläche "Spielen" - Wechselt zum CreateGameMenu
|
||||
Button startButton = mainMenu.addChild(new Button("Spielen"));
|
||||
startButton.addClickCommands(source -> {
|
||||
if (!app.isSettingsMenuOpen()) { // Nur ausführen, wenn SettingsMenu geschlossen ist
|
||||
startGame(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));
|
||||
app.getGuiNode().attachChild(centerMenu);
|
||||
|
||||
// Schaltfläche "Einstellungen" - Öffnet das Einstellungsmenü
|
||||
Button settingsButton = mainMenu.addChild(new Button("Einstellungen"));
|
||||
// Lower-left container for "Spiel beenden" button
|
||||
Container lowerLeftMenu = new Container();
|
||||
lowerLeftMenu.setLocalTranslation(new Vector3f(50, 50, 0));
|
||||
Button quitButton = new Button("Spiel beenden");
|
||||
quitButton.addClickCommands(source -> quitGame());
|
||||
lowerLeftMenu.addChild(quitButton);
|
||||
app.getGuiNode().attachChild(lowerLeftMenu);
|
||||
|
||||
// Lower-right container for "Einstellungen" button
|
||||
Container lowerRightMenu = new Container();
|
||||
lowerRightMenu.setLocalTranslation(new Vector3f(screenWidth - 150, 50, 0));
|
||||
Button settingsButton = new Button("Einstellungen");
|
||||
settingsButton.addClickCommands(source -> openSettings(app));
|
||||
|
||||
// Schaltfläche "Spiel beenden" - Beendet das Spiel
|
||||
Button quitButton = mainMenu.addChild(new Button("Spiel beenden"));
|
||||
quitButton.addClickCommands(source -> {
|
||||
if (!app.isSettingsMenuOpen()) { // Nur ausführen, wenn SettingsMenu geschlossen ist
|
||||
quitGame();
|
||||
}
|
||||
});
|
||||
|
||||
// Hauptmenü dem Bildschirm hinzufügen
|
||||
app.getGuiNode().attachChild(mainMenu);
|
||||
lowerRightMenu.addChild(settingsButton);
|
||||
app.getGuiNode().attachChild(lowerRightMenu);
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts the game by transitioning to the CreateGameMenu.
|
||||
*/
|
||||
private static void startGame(MonopolyApp app) {
|
||||
app.getGuiNode().detachAllChildren();
|
||||
CreateGameMenu createGameMenu = new CreateGameMenu(app);
|
||||
// Weitere Initialisierung des CreateGameMenu
|
||||
new CreateGameMenu(app);
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens the settings menu.
|
||||
*/
|
||||
private static void openSettings(MonopolyApp app) {
|
||||
SettingsMenu settingsMenu = new SettingsMenu(app);
|
||||
app.setSettingsMenuOpen(true); // Markiert das SettingsMenu als geöffnet
|
||||
settingsMenu.open(() -> app.setSettingsMenuOpen(false)); // Callback, das den Status zurücksetzt
|
||||
app.getGuiNode().detachAllChildren();
|
||||
new SettingsMenu(app);
|
||||
}
|
||||
|
||||
/**
|
||||
* Quits the game application.
|
||||
*/
|
||||
private static void quitGame() {
|
||||
System.exit(0);
|
||||
}
|
||||
|
@@ -1,10 +1,12 @@
|
||||
package pp.monopoly.client.gui;
|
||||
|
||||
import com.jme3.math.ColorRGBA;
|
||||
import com.jme3.math.Vector3f;
|
||||
import com.simsilica.lemur.Button;
|
||||
import com.simsilica.lemur.Checkbox;
|
||||
import com.simsilica.lemur.Container;
|
||||
import com.simsilica.lemur.Label;
|
||||
import com.simsilica.lemur.Slider;
|
||||
import com.simsilica.lemur.component.QuadBackgroundComponent;
|
||||
import com.simsilica.lemur.style.ElementId;
|
||||
|
||||
import pp.dialog.Dialog;
|
||||
@@ -17,57 +19,60 @@ public class SettingsMenu extends Dialog {
|
||||
public SettingsMenu(MonopolyApp app) {
|
||||
super(app.getDialogManager());
|
||||
this.app = app;
|
||||
|
||||
settingsContainer = new Container();
|
||||
}
|
||||
|
||||
/**
|
||||
* Öffnet das SettingsMenu und führt das onCloseCallback aus, wenn das Menü geschlossen wird.
|
||||
*
|
||||
* @param onCloseCallback Callback, das beim Schließen des Menüs ausgeführt wird
|
||||
*/
|
||||
public void open(Runnable onCloseCallback) {
|
||||
settingsContainer.addChild(new Label("Einstellungen"));
|
||||
|
||||
// Hintergrundfarbe für das Container-Element setzen, um es undurchsichtig zu machen
|
||||
settingsContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.1f, 0.1f, 0.1f, 1f))); // Dunkelgrauer, undurchsichtiger Hintergrund
|
||||
|
||||
// Zurück-Button, der das Menü schließt und das Callback ausführt
|
||||
Button backButton = settingsContainer.addChild(new Button("Zurück"));
|
||||
backButton.addClickCommands(source -> {
|
||||
close(); // Menü schließen
|
||||
onCloseCallback.run(); // Callback ausführen, um den Status in MonopolyApp zurückzusetzen
|
||||
});
|
||||
// Titel "Einstellungen"
|
||||
Label settingsTitle = settingsContainer.addChild(new Label("Einstellungen", new ElementId("settings-title")));
|
||||
settingsTitle.setFontSize(48);
|
||||
settingsTitle.setColor(ColorRGBA.White);
|
||||
|
||||
app.getGuiNode().attachChild(settingsContainer);
|
||||
}
|
||||
// Effekt Sound mit Slider und Checkbox
|
||||
Container effectSoundContainer = settingsContainer.addChild(new Container());
|
||||
Label effectSoundLabel = effectSoundContainer.addChild(new Label("Effekt Sound", new ElementId("label")));
|
||||
effectSoundLabel.setFontSize(24);
|
||||
effectSoundLabel.setColor(ColorRGBA.White);
|
||||
|
||||
public void open() {
|
||||
settingsContainer.setLocalTranslation(new Vector3f(500, 300, 0));
|
||||
Slider effectSoundSlider = effectSoundContainer.addChild(new Slider());
|
||||
effectSoundSlider.setPreferredSize(new com.jme3.math.Vector3f(300, 30, 0));
|
||||
|
||||
// Titel des Einstellungsmenüs
|
||||
settingsContainer.addChild(new Label("Einstellungen"));
|
||||
Checkbox effectSoundCheckbox = effectSoundContainer.addChild(new Checkbox(""));
|
||||
effectSoundCheckbox.setChecked(true);
|
||||
|
||||
// Beispiel: Button zum Umschalten einer Option
|
||||
Label soundLabel = settingsContainer.addChild(new Label("Sound"));
|
||||
Button toggleSoundButton = settingsContainer.addChild(new Button("An/Aus"));
|
||||
toggleSoundButton.addClickCommands(source -> toggleSound());
|
||||
// Hintergrund Musik mit Slider und Checkbox
|
||||
Container backgroundMusicContainer = settingsContainer.addChild(new Container());
|
||||
Label backgroundMusicLabel = backgroundMusicContainer.addChild(new Label("Hintergrund Musik", new ElementId("label")));
|
||||
backgroundMusicLabel.setFontSize(24);
|
||||
backgroundMusicLabel.setColor(ColorRGBA.White);
|
||||
|
||||
// Button "Beenden" hinzufügen, um das Spiel zu schließen
|
||||
Slider backgroundMusicSlider = backgroundMusicContainer.addChild(new Slider());
|
||||
backgroundMusicSlider.setPreferredSize(new com.jme3.math.Vector3f(300, 30, 0));
|
||||
|
||||
Checkbox backgroundMusicCheckbox = backgroundMusicContainer.addChild(new Checkbox(""));
|
||||
backgroundMusicCheckbox.setChecked(true);
|
||||
|
||||
// Beenden Button
|
||||
Button quitButton = settingsContainer.addChild(new Button("Beenden", new ElementId("menu-button")));
|
||||
quitButton.setFontSize(24);
|
||||
quitButton.setFontSize(32);
|
||||
quitButton.setColor(ColorRGBA.White);
|
||||
quitButton.addClickCommands(source -> app.stop()); // Beendet das Spiel
|
||||
quitButton.addClickCommands(source -> app.stop());
|
||||
|
||||
// Zentrieren des Containers
|
||||
settingsContainer.setLocalTranslation(
|
||||
(app.getCamera().getWidth() - settingsContainer.getPreferredSize().x) / 2,
|
||||
(app.getCamera().getHeight() + settingsContainer.getPreferredSize().y) / 2,
|
||||
0
|
||||
);
|
||||
|
||||
// Container dem GUI-Knoten hinzufügen
|
||||
app.getGuiNode().attachChild(settingsContainer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
app.getGuiNode().detachChild(settingsContainer);
|
||||
}
|
||||
|
||||
private void toggleSound() {
|
||||
System.out.println("Sound umgeschaltet!");
|
||||
}
|
||||
|
||||
public Container getContainer() {
|
||||
return settingsContainer;
|
||||
app.setSettingsMenuOpen(false);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user