mirror of
https://athene2.informatik.unibw-muenchen.de/progproj/gruppen-ht24/Gruppe-02.git
synced 2024-11-28 18:59:47 +01:00
Erweitern des Setting und CreateGameMenü
This commit is contained in:
parent
15b3902bd3
commit
85756713df
@ -34,6 +34,8 @@ public class MonopolyApp extends SimpleApplication implements MonopolyClient, Ga
|
|||||||
private SettingsMenu settingsMenu;
|
private SettingsMenu settingsMenu;
|
||||||
private final Draw draw;
|
private final Draw draw;
|
||||||
|
|
||||||
|
private boolean isSettingsMenuOpen = false;
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
new MonopolyApp().start();
|
new MonopolyApp().start();
|
||||||
}
|
}
|
||||||
@ -66,6 +68,14 @@ public class MonopolyApp extends SimpleApplication implements MonopolyClient, Ga
|
|||||||
return settings;
|
return settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isSettingsMenuOpen() {
|
||||||
|
return isSettingsMenuOpen;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSettingsMenuOpen(boolean isOpen) {
|
||||||
|
this.isSettingsMenuOpen = isOpen;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void simpleInitApp() {
|
public void simpleInitApp() {
|
||||||
GuiGlobals.initialize(this);
|
GuiGlobals.initialize(this);
|
||||||
@ -74,6 +84,8 @@ public class MonopolyApp extends SimpleApplication implements MonopolyClient, Ga
|
|||||||
|
|
||||||
setupInput();
|
setupInput();
|
||||||
setupGui();
|
setupGui();
|
||||||
|
|
||||||
|
// Erst jetzt StartMenu erstellen, nachdem GuiGlobals initialisiert ist
|
||||||
StartMenu.createStartMenu(this);
|
StartMenu.createStartMenu(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,11 +105,13 @@ public class MonopolyApp extends SimpleApplication implements MonopolyClient, Ga
|
|||||||
|
|
||||||
private void handleEscape(boolean isPressed) {
|
private void handleEscape(boolean isPressed) {
|
||||||
if (isPressed) {
|
if (isPressed) {
|
||||||
if (settingsMenu != null && guiNode.hasChild(settingsMenu.getContainer())) {
|
if (isSettingsMenuOpen && settingsMenu != null) {
|
||||||
settingsMenu.close();
|
settingsMenu.close();
|
||||||
|
setSettingsMenuOpen(false);
|
||||||
} else {
|
} else {
|
||||||
settingsMenu = new SettingsMenu(this);
|
settingsMenu = new SettingsMenu(this);
|
||||||
settingsMenu.open();
|
settingsMenu.open();
|
||||||
|
setSettingsMenuOpen(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,6 +35,8 @@ public class StartMenu extends Dialog {
|
|||||||
*/
|
*/
|
||||||
public static void createStartMenu(MonopolyApp app) {
|
public static void createStartMenu(MonopolyApp app) {
|
||||||
Container mainMenu = new Container();
|
Container mainMenu = new Container();
|
||||||
|
|
||||||
|
// Hintergrundbild für das Startmenü
|
||||||
Texture backgroundImage = app.getAssetManager().loadTexture("Pictures/unibw-Bib2.png");
|
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(app.getCamera().getWidth(), app.getCamera().getHeight()); // Vollbildgröße
|
||||||
Geometry background = new Geometry("Background", quad);
|
Geometry background = new Geometry("Background", quad);
|
||||||
@ -42,17 +44,21 @@ public class StartMenu extends Dialog {
|
|||||||
backgroundMaterial.setTexture("ColorMap", backgroundImage);
|
backgroundMaterial.setTexture("ColorMap", backgroundImage);
|
||||||
background.setMaterial(backgroundMaterial);
|
background.setMaterial(backgroundMaterial);
|
||||||
background.setLocalTranslation(0, 0, -1); // Hintergrundebene
|
background.setLocalTranslation(0, 0, -1); // Hintergrundebene
|
||||||
|
|
||||||
// Bild zum guiNode hinzufügen, damit es im Hintergrund bleibt
|
|
||||||
app.getGuiNode().attachChild(background);
|
app.getGuiNode().attachChild(background);
|
||||||
mainMenu.setLocalTranslation(new Vector3f(300, 300, 0)); // Positionierung des Menüs
|
|
||||||
|
// Positionierung des Hauptmenüs
|
||||||
|
mainMenu.setLocalTranslation(new Vector3f(300, 300, 0));
|
||||||
|
|
||||||
// Titel des Hauptmenüs
|
// Titel des Hauptmenüs
|
||||||
mainMenu.addChild(new Label("Hauptmenü"));
|
mainMenu.addChild(new Label("Hauptmenü"));
|
||||||
|
|
||||||
// Schaltfläche "Spielen" - Wechselt zum CreateGameMenu
|
// Schaltfläche "Spielen" - Wechselt zum CreateGameMenu
|
||||||
Button startButton = mainMenu.addChild(new Button("Spielen"));
|
Button startButton = mainMenu.addChild(new Button("Spielen"));
|
||||||
startButton.addClickCommands(source -> startGame(app));
|
startButton.addClickCommands(source -> {
|
||||||
|
if (!app.isSettingsMenuOpen()) { // Nur ausführen, wenn SettingsMenu geschlossen ist
|
||||||
|
startGame(app);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// Schaltfläche "Einstellungen" - Öffnet das Einstellungsmenü
|
// Schaltfläche "Einstellungen" - Öffnet das Einstellungsmenü
|
||||||
Button settingsButton = mainMenu.addChild(new Button("Einstellungen"));
|
Button settingsButton = mainMenu.addChild(new Button("Einstellungen"));
|
||||||
@ -60,7 +66,11 @@ public class StartMenu extends Dialog {
|
|||||||
|
|
||||||
// Schaltfläche "Spiel beenden" - Beendet das Spiel
|
// Schaltfläche "Spiel beenden" - Beendet das Spiel
|
||||||
Button quitButton = mainMenu.addChild(new Button("Spiel beenden"));
|
Button quitButton = mainMenu.addChild(new Button("Spiel beenden"));
|
||||||
quitButton.addClickCommands(source -> quitGame());
|
quitButton.addClickCommands(source -> {
|
||||||
|
if (!app.isSettingsMenuOpen()) { // Nur ausführen, wenn SettingsMenu geschlossen ist
|
||||||
|
quitGame();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// Hauptmenü dem Bildschirm hinzufügen
|
// Hauptmenü dem Bildschirm hinzufügen
|
||||||
app.getGuiNode().attachChild(mainMenu);
|
app.getGuiNode().attachChild(mainMenu);
|
||||||
@ -73,9 +83,9 @@ public class StartMenu extends Dialog {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void openSettings(MonopolyApp app) {
|
private static void openSettings(MonopolyApp app) {
|
||||||
app.getGuiNode().detachAllChildren();
|
|
||||||
SettingsMenu settingsMenu = new SettingsMenu(app);
|
SettingsMenu settingsMenu = new SettingsMenu(app);
|
||||||
// Weitere Initialisierung des SettingsMenu
|
app.setSettingsMenuOpen(true); // Markiert das SettingsMenu als geöffnet
|
||||||
|
settingsMenu.open(() -> app.setSettingsMenuOpen(false)); // Callback, das den Status zurücksetzt
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void quitGame() {
|
private static void quitGame() {
|
||||||
|
@ -1,77 +1,70 @@
|
|||||||
package pp.monopoly.client.gui;
|
package pp.monopoly.client.gui;
|
||||||
|
|
||||||
import com.jme3.math.Vector3f;
|
import com.jme3.math.Vector3f;
|
||||||
|
import com.simsilica.lemur.Axis;
|
||||||
import com.simsilica.lemur.Button;
|
import com.simsilica.lemur.Button;
|
||||||
import com.simsilica.lemur.Container;
|
import com.simsilica.lemur.Container;
|
||||||
|
import com.simsilica.lemur.Insets3f;
|
||||||
import com.simsilica.lemur.Label;
|
import com.simsilica.lemur.Label;
|
||||||
|
import com.simsilica.lemur.TextField;
|
||||||
|
import com.simsilica.lemur.component.SpringGridLayout;
|
||||||
|
import com.simsilica.lemur.style.ElementId;
|
||||||
|
|
||||||
import pp.dialog.Dialog;
|
|
||||||
import pp.monopoly.client.MonopolyApp;
|
import pp.monopoly.client.MonopolyApp;
|
||||||
import pp.monopoly.client.StartMenu;
|
|
||||||
|
|
||||||
/**
|
public class CreateGameMenu {
|
||||||
* Menu for creating a new game, where players can configure settings before starting.
|
|
||||||
*/
|
|
||||||
public class CreateGameMenu extends Dialog {
|
|
||||||
private final MonopolyApp app;
|
private final MonopolyApp app;
|
||||||
|
private final Container createGameContainer;
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructs the CreateGameMenu dialog for the Monopoly application.
|
|
||||||
*
|
|
||||||
* @param app the MonopolyApp instance
|
|
||||||
*/
|
|
||||||
public CreateGameMenu(MonopolyApp app) {
|
public CreateGameMenu(MonopolyApp app) {
|
||||||
super(app.getDialogManager());
|
|
||||||
this.app = app;
|
this.app = app;
|
||||||
initializeMenu();
|
|
||||||
|
// Hauptcontainer für das Menü mit Innenabstand
|
||||||
|
createGameContainer = new Container();
|
||||||
|
createGameContainer.setInsets(new Insets3f(10, 10, 10, 10));
|
||||||
|
|
||||||
|
// Setzt den Titel des Menüs
|
||||||
|
Label title = createGameContainer.addChild(new Label("Neues Spiel", new ElementId("title")));
|
||||||
|
|
||||||
|
// Fügt zwei Eingabefelder unter dem Titel hinzu
|
||||||
|
TextField inputField1 = createGameContainer.addChild(new TextField("Eingabefeld 1"));
|
||||||
|
TextField inputField2 = createGameContainer.addChild(new TextField("Eingabefeld 2"));
|
||||||
|
|
||||||
|
// Erstellt einen Container mit einem Rasterlayout, um die Buttons nebeneinander anzuordnen
|
||||||
|
Container buttonContainer = new Container(new SpringGridLayout(Axis.X, Axis.Y));
|
||||||
|
buttonContainer.setInsets(new Insets3f(5, 5, 5, 5)); // Abstand zwischen den Buttons und dem Rand
|
||||||
|
|
||||||
|
// Buttons hinzufügen und jeweils einen Innenabstand hinzufügen
|
||||||
|
Button button1 = buttonContainer.addChild(new Button("1"));
|
||||||
|
button1.setInsets(new Insets3f(5, 5, 5, 5));
|
||||||
|
|
||||||
|
Button button2 = buttonContainer.addChild(new Button("2"));
|
||||||
|
button2.setInsets(new Insets3f(5, 5, 5, 5));
|
||||||
|
|
||||||
|
Button button3 = buttonContainer.addChild(new Button("3"));
|
||||||
|
button3.setInsets(new Insets3f(5, 5, 5, 5));
|
||||||
|
|
||||||
|
// Fügt den Button-Container zum Hauptcontainer hinzu
|
||||||
|
createGameContainer.addChild(buttonContainer);
|
||||||
|
|
||||||
|
// Setzt die Breite des Hauptcontainers
|
||||||
|
createGameContainer.setPreferredSize(new Vector3f(600, 400, 0));
|
||||||
|
|
||||||
|
// Zentriert den Container auf dem Bildschirm
|
||||||
|
createGameContainer.setLocalTranslation(
|
||||||
|
(app.getCamera().getWidth() - createGameContainer.getPreferredSize().x) / 2,
|
||||||
|
(app.getCamera().getHeight() + createGameContainer.getPreferredSize().y) / 2,
|
||||||
|
0
|
||||||
|
);
|
||||||
|
|
||||||
|
// Fügt das Menü zum GUI-Knoten der App hinzu
|
||||||
|
app.getGuiNode().attachChild(createGameContainer);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets up the Create Game Menu layout and buttons.
|
* Schließt das CreateGameMenu.
|
||||||
*/
|
*/
|
||||||
private void initializeMenu() {
|
public void close() {
|
||||||
Container menuContainer = new Container();
|
app.getGuiNode().detachChild(createGameContainer);
|
||||||
menuContainer.setLocalTranslation(new Vector3f(300, 300, 0)); // Positionierung des Menüs
|
|
||||||
|
|
||||||
// Titel des Menüs
|
|
||||||
menuContainer.addChild(new Label("Neues Spiel erstellen"));
|
|
||||||
|
|
||||||
// Beispiel-Button für die Spieleranzahl-Einstellung
|
|
||||||
Button playerCountButton = menuContainer.addChild(new Button("Spieleranzahl einstellen"));
|
|
||||||
playerCountButton.addClickCommands(source -> setPlayerCount());
|
|
||||||
|
|
||||||
// Start-Button zum Spielbeginn
|
|
||||||
Button startGameButton = menuContainer.addChild(new Button("Spiel starten"));
|
|
||||||
startGameButton.addClickCommands(source -> startGame());
|
|
||||||
|
|
||||||
// Zurück-Button zum Startmenü
|
|
||||||
Button backButton = menuContainer.addChild(new Button("Zurück"));
|
|
||||||
backButton.addClickCommands(source -> returnToStartMenu());
|
|
||||||
|
|
||||||
app.getGuiNode().attachChild(menuContainer);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Placeholder for setting the player count.
|
|
||||||
*/
|
|
||||||
private void setPlayerCount() {
|
|
||||||
// Logik zum Festlegen der Spieleranzahl
|
|
||||||
System.out.println("Spieleranzahl einstellen wurde ausgewählt");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Placeholder for starting the game.
|
|
||||||
*/
|
|
||||||
private void startGame() {
|
|
||||||
// Logik für den Start des Spiels
|
|
||||||
System.out.println("Spiel starten wurde ausgewählt");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns to the StartMenu.
|
|
||||||
*/
|
|
||||||
private void returnToStartMenu() {
|
|
||||||
app.getGuiNode().detachAllChildren(); // Schließt das CreateGameMenu
|
|
||||||
StartMenu.createStartMenu(app); // Zeigt das Startmenü erneut an
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
package pp.monopoly.client.gui;
|
package pp.monopoly.client.gui;
|
||||||
|
|
||||||
|
import com.jme3.math.ColorRGBA;
|
||||||
import com.jme3.math.Vector3f;
|
import com.jme3.math.Vector3f;
|
||||||
import com.simsilica.lemur.Button;
|
import com.simsilica.lemur.Button;
|
||||||
import com.simsilica.lemur.Container;
|
import com.simsilica.lemur.Container;
|
||||||
import com.simsilica.lemur.Label;
|
import com.simsilica.lemur.Label;
|
||||||
|
import com.simsilica.lemur.style.ElementId;
|
||||||
|
|
||||||
import pp.dialog.Dialog;
|
import pp.dialog.Dialog;
|
||||||
import pp.monopoly.client.MonopolyApp;
|
import pp.monopoly.client.MonopolyApp;
|
||||||
@ -18,8 +20,26 @@ public class SettingsMenu extends Dialog {
|
|||||||
settingsContainer = new Container();
|
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"));
|
||||||
|
|
||||||
|
// 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
|
||||||
|
});
|
||||||
|
|
||||||
|
app.getGuiNode().attachChild(settingsContainer);
|
||||||
|
}
|
||||||
|
|
||||||
public void open() {
|
public void open() {
|
||||||
settingsContainer.setLocalTranslation(new Vector3f(300, 300, 0));
|
settingsContainer.setLocalTranslation(new Vector3f(500, 300, 0));
|
||||||
|
|
||||||
// Titel des Einstellungsmenüs
|
// Titel des Einstellungsmenüs
|
||||||
settingsContainer.addChild(new Label("Einstellungen"));
|
settingsContainer.addChild(new Label("Einstellungen"));
|
||||||
@ -29,14 +49,16 @@ public class SettingsMenu extends Dialog {
|
|||||||
Button toggleSoundButton = settingsContainer.addChild(new Button("An/Aus"));
|
Button toggleSoundButton = settingsContainer.addChild(new Button("An/Aus"));
|
||||||
toggleSoundButton.addClickCommands(source -> toggleSound());
|
toggleSoundButton.addClickCommands(source -> toggleSound());
|
||||||
|
|
||||||
// Zurück-Button, um das Menü zu schließen
|
// Button "Beenden" hinzufügen, um das Spiel zu schließen
|
||||||
Button backButton = settingsContainer.addChild(new Button("Zurück"));
|
Button quitButton = settingsContainer.addChild(new Button("Beenden", new ElementId("menu-button")));
|
||||||
backButton.addClickCommands(source -> close());
|
quitButton.setFontSize(24);
|
||||||
|
quitButton.setColor(ColorRGBA.White);
|
||||||
|
quitButton.addClickCommands(source -> app.stop()); // Beendet das Spiel
|
||||||
|
|
||||||
// Container dem GUI-Knoten hinzufügen
|
// Container dem GUI-Knoten hinzufügen
|
||||||
app.getGuiNode().attachChild(settingsContainer);
|
app.getGuiNode().attachChild(settingsContainer);
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
public void close() {
|
public void close() {
|
||||||
app.getGuiNode().detachChild(settingsContainer);
|
app.getGuiNode().detachChild(settingsContainer);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user