mirror of
https://athene2.informatik.unibw-muenchen.de/progproj/gruppen-ht24/Gruppe-02.git
synced 2024-11-25 04:39:43 +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;
|
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.material.Material;
|
||||||
import com.jme3.math.Vector3f;
|
import com.jme3.math.Vector3f;
|
||||||
import com.jme3.scene.Geometry;
|
import com.jme3.scene.Geometry;
|
||||||
@ -19,15 +22,11 @@ import pp.monopoly.client.StartMenu;
|
|||||||
* CreateGameMenu class represents the menu for creating a new game.
|
* CreateGameMenu class represents the menu for creating a new game.
|
||||||
*/
|
*/
|
||||||
public class CreateGameMenu {
|
public class CreateGameMenu {
|
||||||
|
|
||||||
private final MonopolyApp app;
|
private final MonopolyApp app;
|
||||||
private final Container menuContainer;
|
private final Container menuContainer;
|
||||||
private Geometry background;
|
private Geometry background;
|
||||||
|
|
||||||
/**
|
|
||||||
* Konstruktor für das CreateGameMenu.
|
|
||||||
*
|
|
||||||
* @param app Die Hauptanwendung (MonopolyApp)
|
|
||||||
*/
|
|
||||||
public CreateGameMenu(MonopolyApp app) {
|
public CreateGameMenu(MonopolyApp app) {
|
||||||
this.app = app;
|
this.app = app;
|
||||||
|
|
||||||
@ -48,12 +47,12 @@ public class CreateGameMenu {
|
|||||||
inputContainer.setLocalTranslation(20, 0, 0); // Abstand vom Rand
|
inputContainer.setLocalTranslation(20, 0, 0); // Abstand vom Rand
|
||||||
|
|
||||||
inputContainer.addChild(new Label("Server-Adresse:"));
|
inputContainer.addChild(new Label("Server-Adresse:"));
|
||||||
TextField serverAddressField = inputContainer.addChild(new TextField("localhost"));
|
TextField playerNameField = inputContainer.addChild(new TextField("localhost"));
|
||||||
serverAddressField.setPreferredWidth(400); // Breite des Textfelds
|
playerNameField.setPreferredWidth(400); // Breite des Textfelds
|
||||||
|
|
||||||
inputContainer.addChild(new Label("Port:"));
|
inputContainer.addChild(new Label("Port:"));
|
||||||
TextField portField = inputContainer.addChild(new TextField("42069"));
|
TextField serverAddressField = inputContainer.addChild(new TextField("42069"));
|
||||||
portField.setPreferredWidth(400); // Breite des Textfelds
|
serverAddressField.setPreferredWidth(400); // Breite des Textfelds
|
||||||
|
|
||||||
// Button-Container
|
// Button-Container
|
||||||
Container buttonContainer = menuContainer.addChild(new Container(new SpringGridLayout(Axis.X, Axis.Y)));
|
Container buttonContainer = menuContainer.addChild(new Container(new SpringGridLayout(Axis.X, Axis.Y)));
|
||||||
@ -65,18 +64,15 @@ public class CreateGameMenu {
|
|||||||
cancelButton.setPreferredSize(new Vector3f(120, 40, 0));
|
cancelButton.setPreferredSize(new Vector3f(120, 40, 0));
|
||||||
cancelButton.addClickCommands(source -> goBackToStartMenu());
|
cancelButton.addClickCommands(source -> goBackToStartMenu());
|
||||||
|
|
||||||
// "Spiel hosten"-Button
|
// "Spiel hosten"-Button (funktionslos)
|
||||||
Button hostButton = buttonContainer.addChild(new Button("Spiel hosten"));
|
Button hostButton = buttonContainer.addChild(new Button("Spiel hosten"));
|
||||||
hostButton.setPreferredSize(new Vector3f(120, 40, 0));
|
hostButton.setPreferredSize(new Vector3f(120, 40, 0));
|
||||||
hostButton.addClickCommands(source -> {
|
// Keine Funktion zugewiesen
|
||||||
closeCreateGameMenu(); // Schließt das Menü
|
|
||||||
app.startTestWorld(); // Starte die TestWorld im selben Fenster
|
|
||||||
});
|
|
||||||
|
|
||||||
// "Beitreten"-Button
|
// "Beitreten"-Button (ebenfalls funktionslos, falls benötigt)
|
||||||
Button joinButton = buttonContainer.addChild(new Button("Beitreten"));
|
Button joinButton = buttonContainer.addChild(new Button("Beitreten"));
|
||||||
joinButton.setPreferredSize(new Vector3f(120, 40, 0));
|
joinButton.setPreferredSize(new Vector3f(120, 40, 0));
|
||||||
// Placeholder für die Beitrittslogik
|
// Keine Funktion zugewiesen
|
||||||
|
|
||||||
// Zentrierung des Containers
|
// Zentrierung des Containers
|
||||||
menuContainer.setLocalTranslation(
|
menuContainer.setLocalTranslation(
|
||||||
@ -86,6 +82,9 @@ public class CreateGameMenu {
|
|||||||
);
|
);
|
||||||
|
|
||||||
app.getGuiNode().attachChild(menuContainer);
|
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.
|
* Geht zum Startmenü zurück, wenn "Abbrechen" angeklickt wird.
|
||||||
*/
|
*/
|
||||||
private void goBackToStartMenu() {
|
private void goBackToStartMenu() {
|
||||||
closeCreateGameMenu(); // Schließt das Menü
|
app.getGuiNode().detachChild(menuContainer);
|
||||||
StartMenu.createStartMenu(app); // Zeige das Startmenü
|
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() {
|
private void setupKeyMappings() {
|
||||||
app.getGuiNode().detachChild(menuContainer); // Entfernt den Menü-Container
|
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.getGuiNode().detachChild(background); // Entfernt das Hintergrundbild
|
||||||
|
app.startTestWorld(); // Öffne die TestWorld
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user