diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/LobbyMenu.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/LobbyMenu.java index 5d71675..343587b 100644 --- a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/LobbyMenu.java +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/LobbyMenu.java @@ -42,6 +42,7 @@ public class LobbyMenu { private PlayerHandler playerHandler; // Reference to PlayerHandler private TextField startingCapital; // Reference to the starting capital input field + private TextField playerInputField; // Reference to the player name input field public LobbyMenu(MonopolyApp app) { @@ -161,6 +162,7 @@ public class LobbyMenu { readyButton.setBackground(new QuadBackgroundComponent(ColorRGBA.Green)); // Add color to match the style readyButton.addClickCommands(source -> toggleReady(null));// Add functionality readyButton.addClickCommands(source -> applyStartingCapital(playerID)); + readyButton.addClickCommands(source -> applyPlayerName(playerID)); lowerRightMenu.addChild(readyButton); // Position the container near the bottom-right corner @@ -209,6 +211,21 @@ public class LobbyMenu { } } + /** + * Apply the player name from the input field. + */ + private void applyPlayerName(int playerID) { + Player currentPlayer = playerHandler.getPlayerById(playerID); + + String playerName = playerInputField.getText().trim(); + if (!playerName.isEmpty()) { + currentPlayer.setName(playerName); + System.out.println("Player name set to: " + playerName); + } else { + System.err.println("Invalid player name: Name cannot be empty."); + } + } + /** * Lädt das Hintergrundbild und fügt es als geometrische Ebene hinzu. */ diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/game/server/Player.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/game/server/Player.java index 7dc6fab..92ceeaa 100644 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/game/server/Player.java +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/game/server/Player.java @@ -84,7 +84,7 @@ public class Player implements FieldVisitor{ * Set the name of the Player * @param name the new name */ - void setName(String name) { + public void setName(String name) { this.name = name; }