mirror of
https://athene2.informatik.unibw-muenchen.de/progproj/gruppen-ht24/Gruppe-02.git
synced 2024-11-24 21:39:44 +01:00
Spieler Lobby
This commit is contained in:
parent
6e63de6e99
commit
7da8b3e545
@ -20,15 +20,13 @@ import pp.monopoly.client.MonopolyApp;
|
||||
import pp.monopoly.client.StartMenu;
|
||||
import pp.monopoly.server.MonopolyServer;
|
||||
|
||||
/**
|
||||
* CreateGameMenu class represents the menu for creating a new game.
|
||||
*/
|
||||
public class CreateGameMenu {
|
||||
|
||||
private final MonopolyApp app;
|
||||
private final Container menuContainer;
|
||||
private Geometry background;
|
||||
private Label serverStatusLabel;
|
||||
private TextField serverAddressField;
|
||||
private TextField portField;
|
||||
|
||||
public CreateGameMenu(MonopolyApp app) {
|
||||
this.app = app;
|
||||
@ -50,12 +48,12 @@ public class CreateGameMenu {
|
||||
inputContainer.setLocalTranslation(20, 0, 0); // Abstand vom Rand
|
||||
|
||||
inputContainer.addChild(new Label("Server-Adresse:"));
|
||||
TextField playerNameField = inputContainer.addChild(new TextField("localhost"));
|
||||
playerNameField.setPreferredWidth(400); // Breite des Textfelds
|
||||
serverAddressField = inputContainer.addChild(new TextField("localhost"));
|
||||
serverAddressField.setPreferredWidth(400); // Breite des Textfelds
|
||||
|
||||
inputContainer.addChild(new Label("Port:"));
|
||||
TextField serverAddressField = inputContainer.addChild(new TextField("42069"));
|
||||
serverAddressField.setPreferredWidth(400); // Breite des Textfelds
|
||||
portField = inputContainer.addChild(new TextField("42069"));
|
||||
portField.setPreferredWidth(400); // Breite des Textfelds
|
||||
|
||||
// Button-Container
|
||||
Container buttonContainer = menuContainer.addChild(new Container(new SpringGridLayout(Axis.X, Axis.Y)));
|
||||
@ -70,14 +68,15 @@ public class CreateGameMenu {
|
||||
// "Selber hosten"-Button
|
||||
Button hostButton = buttonContainer.addChild(new Button("Selber hosten"));
|
||||
hostButton.setPreferredSize(new Vector3f(120, 40, 0));
|
||||
hostButton.addClickCommands(source -> startServer());
|
||||
hostButton.addClickCommands(source -> startServerAndJoin());
|
||||
|
||||
// "Beitreten"-Button (vorerst funktionslos)
|
||||
Button joinButton = buttonContainer.addChild(new Button("Beitreten"));
|
||||
joinButton.setPreferredSize(new Vector3f(120, 40, 0));
|
||||
joinButton.addClickCommands(source -> joinServer());
|
||||
|
||||
// Serverstatus-Label
|
||||
serverStatusLabel = menuContainer.addChild(new Label("Serverstatus: Noch nicht gestartet"));
|
||||
Label serverStatusLabel = menuContainer.addChild(new Label("Serverstatus: Noch nicht gestartet"));
|
||||
serverStatusLabel.setFontSize(24);
|
||||
|
||||
// Zentrierung des Containers
|
||||
@ -86,7 +85,6 @@ public class CreateGameMenu {
|
||||
(app.getCamera().getHeight() + menuContainer.getPreferredSize().y) / 2,
|
||||
1 // Höhere Z-Ebene für den Vordergrund
|
||||
);
|
||||
|
||||
app.getInputManager().addMapping("OpenTestWorld", new com.jme3.input.controls.KeyTrigger(com.jme3.input.KeyInput.KEY_T));
|
||||
app.getInputManager().addListener(new com.jme3.input.controls.ActionListener() {
|
||||
@Override
|
||||
@ -124,9 +122,38 @@ public class CreateGameMenu {
|
||||
StartMenu.createStartMenu(app);
|
||||
}
|
||||
|
||||
private void startServer() {
|
||||
app.start();
|
||||
app.getServerConnection().connect();
|
||||
JOptionPane.showMessageDialog(null, "Server Started");
|
||||
/**
|
||||
* Startet den Server und tritt nach 2 Sekunden der Lobby bei.
|
||||
*/
|
||||
private void startServerAndJoin() {
|
||||
new Thread(() -> {
|
||||
app.start();
|
||||
MonopolyServer server = new MonopolyServer();
|
||||
server.run();
|
||||
|
||||
// Warte 2 Sekunden
|
||||
try {
|
||||
Thread.sleep(2000);
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
|
||||
// Verbinde mit dem Server
|
||||
app.enqueue(() -> joinServer());
|
||||
}).start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tritt dem Server basierend auf den Eingaben bei.
|
||||
*/
|
||||
private void joinServer() {
|
||||
String serverAddress = serverAddressField.getText();
|
||||
int port = Integer.parseInt(portField.getText());
|
||||
app.getServerConnection().connect(serverAddress, port);
|
||||
|
||||
// Öffnet die Lobby
|
||||
app.getGuiNode().detachChild(menuContainer);
|
||||
app.getGuiNode().detachChild(background); // Entfernt das Hintergrundbild
|
||||
new LobbyMenu(app);
|
||||
}
|
||||
}
|
||||
|
@ -1,51 +0,0 @@
|
||||
package pp.monopoly.client.gui;
|
||||
|
||||
|
||||
import com.jme3.math.ColorRGBA;
|
||||
import com.simsilica.lemur.Button;
|
||||
import com.simsilica.lemur.Label;
|
||||
import com.simsilica.lemur.style.ElementId;
|
||||
|
||||
import pp.dialog.Dialog;
|
||||
import pp.monopoly.client.MonopolyApp;
|
||||
|
||||
public class GameMenu extends Dialog {
|
||||
private final MonopolyApp app;
|
||||
|
||||
/**
|
||||
* Constructs the SettingsMenu dialog for the Monopoly application.
|
||||
*
|
||||
* @param app the MonopolyApp instance
|
||||
*/
|
||||
public GameMenu(MonopolyApp app) {
|
||||
super(app.getDialogManager());
|
||||
this.app = app;
|
||||
|
||||
// Add a title label for Settings
|
||||
Label settingsTitle = new Label("Einstellungen", new ElementId("settings-title"));
|
||||
settingsTitle.setFontSize(48); // Set font size for the title
|
||||
settingsTitle.setColor(ColorRGBA.White);
|
||||
|
||||
// Add any settings-related components here, such as volume control, toggles, etc.
|
||||
|
||||
// Add a back button to return to StartMenu
|
||||
Button backButton = new Button("Zurück", new ElementId("menu-button"));
|
||||
backButton.setColor(ColorRGBA.White);
|
||||
backButton.setFontSize(24);
|
||||
backButton.addClickCommands(source -> returnToStartMenu());
|
||||
|
||||
// Add components to this dialog
|
||||
addChild(settingsTitle);
|
||||
addChild(backButton);
|
||||
|
||||
// You can add more settings components here, like checkboxes or sliders.
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns to the StartMenu when the back button is clicked.
|
||||
*/
|
||||
private void returnToStartMenu() {
|
||||
app.getDialogManager().close(this); // Close the current settings dialog
|
||||
//TODO return zum Ausgangsmenü
|
||||
}
|
||||
}
|
@ -0,0 +1,99 @@
|
||||
package pp.monopoly.client.gui;
|
||||
|
||||
import com.jme3.material.Material;
|
||||
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.monopoly.client.MonopolyApp;
|
||||
|
||||
public class LobbyMenu {
|
||||
|
||||
private final MonopolyApp app;
|
||||
private final Container menuContainer;
|
||||
private Geometry background;
|
||||
|
||||
public LobbyMenu(MonopolyApp app) {
|
||||
this.app = app;
|
||||
|
||||
// Entfernt das CreateGameMenu (inklusive Hintergrund)
|
||||
app.getGuiNode().detachAllChildren();
|
||||
|
||||
// Hintergrundbild laden und hinzufügen
|
||||
addBackgroundImage();
|
||||
|
||||
// Hauptcontainer für das Menü
|
||||
menuContainer = new Container(new SpringGridLayout(Axis.Y, Axis.X));
|
||||
menuContainer.setPreferredSize(new Vector3f(600, 400, 0)); // Feste Größe des Containers
|
||||
|
||||
// Titel
|
||||
Label title = menuContainer.addChild(new Label("Lobby"));
|
||||
title.setFontSize(48);
|
||||
|
||||
// Spielerstatus anzeigen
|
||||
Container playerListContainer = menuContainer.addChild(new Container(new SpringGridLayout(Axis.Y, Axis.X)));
|
||||
playerListContainer.addChild(new Label("Spieler in der Lobby:"));
|
||||
Label playersLabel = playerListContainer.addChild(new Label("Noch keine Spieler verbunden.")); // Beispieltext
|
||||
|
||||
// Buttons
|
||||
Container buttonContainer = menuContainer.addChild(new Container(new SpringGridLayout(Axis.X, Axis.Y)));
|
||||
buttonContainer.setPreferredSize(new Vector3f(400, 50, 0));
|
||||
|
||||
// "Bereit"-Button
|
||||
Button readyButton = buttonContainer.addChild(new Button("Bereit"));
|
||||
readyButton.setPreferredSize(new Vector3f(120, 40, 0));
|
||||
readyButton.addClickCommands(source -> toggleReady(playersLabel));
|
||||
|
||||
// "Zurück"-Button
|
||||
Button backButton = buttonContainer.addChild(new Button("Zurück"));
|
||||
backButton.setPreferredSize(new Vector3f(120, 40, 0));
|
||||
backButton.addClickCommands(source -> goBackToCreateGame());
|
||||
|
||||
// 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.getGuiNode().attachChild(menuContainer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Lädt das Hintergrundbild und fügt es als geometrische Ebene hinzu.
|
||||
*/
|
||||
private void addBackgroundImage() {
|
||||
Texture backgroundImage = app.getAssetManager().loadTexture("Pictures/unibw-Bib2.png");
|
||||
Quad quad = new Quad(app.getCamera().getWidth(), app.getCamera().getHeight());
|
||||
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
|
||||
|
||||
app.getGuiNode().attachChild(background);
|
||||
}
|
||||
|
||||
/**
|
||||
* Schaltet den "Bereit"-Status um.
|
||||
*/
|
||||
private void toggleReady(Label playersLabel) {
|
||||
// Beispiel-Logik für das Umschalten des Status
|
||||
playersLabel.setText("Spielerstatus aktualisiert."); // Beispieltext
|
||||
}
|
||||
|
||||
/**
|
||||
* Geht zurück zum CreateGameMenu.
|
||||
*/
|
||||
private void goBackToCreateGame() {
|
||||
app.getGuiNode().detachChild(menuContainer);
|
||||
app.getGuiNode().detachChild(background); // Entfernt das Hintergrundbild
|
||||
new CreateGameMenu(app);
|
||||
}
|
||||
}
|
@ -1,89 +0,0 @@
|
||||
package pp.monopoly.client.gui;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.FlowLayout;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.SwingUtilities;
|
||||
|
||||
public class ServerScreen {
|
||||
private JFrame frame;
|
||||
private JTextField inputField;
|
||||
private JLabel label;
|
||||
private JButton startButton;
|
||||
private JButton stopButton;
|
||||
|
||||
public ServerScreen() {
|
||||
initialize();
|
||||
}
|
||||
|
||||
private void initialize() {
|
||||
// Erstelle das Hauptfenster
|
||||
frame = new JFrame("Server Placeholder"); // Setze den Titel
|
||||
frame.setSize(400, 200);
|
||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
frame.setLayout(new BorderLayout());
|
||||
|
||||
// Eingabefeld und Label im oberen Bereich
|
||||
JPanel topPanel = new JPanel();
|
||||
topPanel.setLayout(new FlowLayout());
|
||||
|
||||
label = new JLabel("Server-Port:");
|
||||
inputField = new JTextField("42069", 10);
|
||||
topPanel.add(label);
|
||||
topPanel.add(inputField);
|
||||
|
||||
// Buttons im unteren Bereich
|
||||
JPanel bottomPanel = new JPanel();
|
||||
bottomPanel.setLayout(new FlowLayout());
|
||||
|
||||
startButton = new JButton("Start Server");
|
||||
stopButton = new JButton("Stop Server");
|
||||
stopButton.setEnabled(false); // Stop-Button ist anfangs deaktiviert
|
||||
|
||||
bottomPanel.add(startButton);
|
||||
bottomPanel.add(stopButton);
|
||||
|
||||
// Füge die Panels zum Hauptfenster hinzu
|
||||
frame.add(topPanel, BorderLayout.NORTH);
|
||||
frame.add(bottomPanel, BorderLayout.SOUTH);
|
||||
|
||||
// Aktion für Start-Button
|
||||
startButton.addActionListener(e -> startServer());
|
||||
|
||||
// Aktion für Stop-Button
|
||||
stopButton.addActionListener(e -> stopServer());
|
||||
|
||||
// Zeige das Fenster
|
||||
frame.setVisible(true);
|
||||
}
|
||||
|
||||
private void startServer() {
|
||||
String port = inputField.getText();
|
||||
try {
|
||||
int portNumber = Integer.parseInt(port);
|
||||
// Server-Startlogik hier einfügen
|
||||
JOptionPane.showMessageDialog(frame, "Server gestartet auf Port " + portNumber);
|
||||
startButton.setEnabled(false); // Deaktiviere den Start-Button
|
||||
stopButton.setEnabled(true); // Aktiviere den Stop-Button
|
||||
} catch (NumberFormatException e) {
|
||||
JOptionPane.showMessageDialog(frame, "Ungültiger Port: " + port, "Fehler", JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
}
|
||||
|
||||
private void stopServer() {
|
||||
// Server-Stoplogik hier einfügen
|
||||
JOptionPane.showMessageDialog(frame, "Server gestoppt.");
|
||||
startButton.setEnabled(true); // Aktiviere den Start-Button
|
||||
stopButton.setEnabled(false); // Deaktiviere den Stop-Button
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
SwingUtilities.invokeLater(ServerScreen::new);
|
||||
}
|
||||
}
|
@ -1,50 +1,38 @@
|
||||
package pp.monopoly.message.client;
|
||||
|
||||
import pp.monopoly.game.server.PlayerColor;
|
||||
|
||||
/**
|
||||
* Represents a message indicating the player is ready to play.
|
||||
*/
|
||||
public class PlayerReady extends ClientMessage{
|
||||
public class PlayerReady extends ClientMessage {
|
||||
private boolean isReady;
|
||||
private String name;
|
||||
private PlayerColor color;
|
||||
private String figure;
|
||||
|
||||
/**
|
||||
* Constructs a PlayerReady message.
|
||||
*
|
||||
* @param isReady true if the player is ready, false otherwise
|
||||
* @param name the name of the player
|
||||
* @param color the color of the player (can be null)
|
||||
*/
|
||||
public PlayerReady(boolean isReady) {
|
||||
public PlayerReady(boolean isReady, String name, String figure) {
|
||||
this.isReady = isReady;
|
||||
this.name = name;
|
||||
this.figure = figure;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for the Name
|
||||
* @return the Name
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for the Playercolor
|
||||
* @return the Playercolor
|
||||
*/
|
||||
public PlayerColor getColor() {
|
||||
return color;
|
||||
public String getFigure() {
|
||||
return figure;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the player is ready.
|
||||
*
|
||||
* @return true if ready, false otherwise
|
||||
*/
|
||||
public boolean isReady() {
|
||||
return isReady;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void accept(ClientInterpreter interpreter, int from) {
|
||||
interpreter.received(this, from);
|
||||
|
Loading…
Reference in New Issue
Block a user