mirror of
https://athene2.informatik.unibw-muenchen.de/progproj/gruppen-ht24/Gruppe-02.git
synced 2024-11-25 01:09:46 +01:00
Veränderung Erreichen der Testwelt
This commit is contained in:
parent
dbd9dd0001
commit
2933d022aa
@ -1,5 +1,8 @@
|
||||
package pp.monopoly.client.gui;
|
||||
|
||||
import com.jme3.input.KeyInput;
|
||||
import com.jme3.input.controls.ActionListener;
|
||||
import com.jme3.input.controls.KeyTrigger;
|
||||
import com.jme3.material.Material;
|
||||
import com.jme3.math.Vector3f;
|
||||
import com.jme3.scene.Geometry;
|
||||
@ -19,15 +22,11 @@ import pp.monopoly.client.StartMenu;
|
||||
* CreateGameMenu class represents the menu for creating a new game.
|
||||
*/
|
||||
public class CreateGameMenu {
|
||||
|
||||
private final MonopolyApp app;
|
||||
private final Container menuContainer;
|
||||
private Geometry background;
|
||||
|
||||
/**
|
||||
* Konstruktor für das CreateGameMenu.
|
||||
*
|
||||
* @param app Die Hauptanwendung (MonopolyApp)
|
||||
*/
|
||||
public CreateGameMenu(MonopolyApp app) {
|
||||
this.app = app;
|
||||
|
||||
@ -48,12 +47,12 @@ public class CreateGameMenu {
|
||||
inputContainer.setLocalTranslation(20, 0, 0); // Abstand vom Rand
|
||||
|
||||
inputContainer.addChild(new Label("Server-Adresse:"));
|
||||
TextField serverAddressField = inputContainer.addChild(new TextField("localhost"));
|
||||
serverAddressField.setPreferredWidth(400); // Breite des Textfelds
|
||||
TextField playerNameField = inputContainer.addChild(new TextField("localhost"));
|
||||
playerNameField.setPreferredWidth(400); // Breite des Textfelds
|
||||
|
||||
inputContainer.addChild(new Label("Port:"));
|
||||
TextField portField = inputContainer.addChild(new TextField("42069"));
|
||||
portField.setPreferredWidth(400); // Breite des Textfelds
|
||||
TextField serverAddressField = inputContainer.addChild(new TextField("42069"));
|
||||
serverAddressField.setPreferredWidth(400); // Breite des Textfelds
|
||||
|
||||
// Button-Container
|
||||
Container buttonContainer = menuContainer.addChild(new Container(new SpringGridLayout(Axis.X, Axis.Y)));
|
||||
@ -65,27 +64,27 @@ public class CreateGameMenu {
|
||||
cancelButton.setPreferredSize(new Vector3f(120, 40, 0));
|
||||
cancelButton.addClickCommands(source -> goBackToStartMenu());
|
||||
|
||||
// "Spiel hosten"-Button
|
||||
// "Spiel hosten"-Button (funktionslos)
|
||||
Button hostButton = buttonContainer.addChild(new Button("Spiel hosten"));
|
||||
hostButton.setPreferredSize(new Vector3f(120, 40, 0));
|
||||
hostButton.addClickCommands(source -> {
|
||||
closeCreateGameMenu(); // Schließt das Menü
|
||||
app.startTestWorld(); // Starte die TestWorld im selben Fenster
|
||||
});
|
||||
// Keine Funktion zugewiesen
|
||||
|
||||
// "Beitreten"-Button
|
||||
// "Beitreten"-Button (ebenfalls funktionslos, falls benötigt)
|
||||
Button joinButton = buttonContainer.addChild(new Button("Beitreten"));
|
||||
joinButton.setPreferredSize(new Vector3f(120, 40, 0));
|
||||
// Placeholder für die Beitrittslogik
|
||||
// Keine Funktion zugewiesen
|
||||
|
||||
// Zentrierung des Containers
|
||||
menuContainer.setLocalTranslation(
|
||||
(app.getCamera().getWidth() - menuContainer.getPreferredSize().x) / 2,
|
||||
(app.getCamera().getHeight() + menuContainer.getPreferredSize().y) / 2,
|
||||
1 // Höhere Z-Ebene für den Vordergrund
|
||||
(app.getCamera().getWidth() - menuContainer.getPreferredSize().x) / 2,
|
||||
(app.getCamera().getHeight() + menuContainer.getPreferredSize().y) / 2,
|
||||
1 // Höhere Z-Ebene für den Vordergrund
|
||||
);
|
||||
|
||||
app.getGuiNode().attachChild(menuContainer);
|
||||
|
||||
// Key-Mapping für Taste "T"
|
||||
setupKeyMappings();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -107,15 +106,34 @@ public class CreateGameMenu {
|
||||
* Geht zum Startmenü zurück, wenn "Abbrechen" angeklickt wird.
|
||||
*/
|
||||
private void goBackToStartMenu() {
|
||||
closeCreateGameMenu(); // Schließt das Menü
|
||||
StartMenu.createStartMenu(app); // Zeige das Startmenü
|
||||
app.getGuiNode().detachChild(menuContainer);
|
||||
app.getGuiNode().detachChild(background); // Entfernt das Hintergrundbild
|
||||
StartMenu.createStartMenu(app);
|
||||
}
|
||||
|
||||
/**
|
||||
* Entfernt das CreateGameMenu und dessen Hintergrund.
|
||||
* Fügt ein Key-Mapping hinzu, um die TestWorld mit der Taste "T" zu öffnen.
|
||||
*/
|
||||
private void closeCreateGameMenu() {
|
||||
app.getGuiNode().detachChild(menuContainer); // Entfernt den Menü-Container
|
||||
app.getGuiNode().detachChild(background); // Entfernt das Hintergrundbild
|
||||
private void setupKeyMappings() {
|
||||
app.getInputManager().addMapping("OpenTestWorld", new KeyTrigger(KeyInput.KEY_T));
|
||||
app.getInputManager().addListener(actionListener, "OpenTestWorld");
|
||||
}
|
||||
|
||||
/**
|
||||
* ActionListener, um auf Tastendrücke zu reagieren.
|
||||
*/
|
||||
private final ActionListener actionListener = (name, isPressed, tpf) -> {
|
||||
if (name.equals("OpenTestWorld") && isPressed) {
|
||||
openTestWorld();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Öffnet die TestWorld.
|
||||
*/
|
||||
private void openTestWorld() {
|
||||
app.getGuiNode().detachChild(menuContainer);
|
||||
app.getGuiNode().detachChild(background); // Entfernt das Hintergrundbild
|
||||
app.startTestWorld(); // Öffne die TestWorld
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user