From 6b78733a5d41abc515a2092500acc92bdfbb6176 Mon Sep 17 00:00:00 2001 From: Johannes Schmelz Date: Sun, 24 Nov 2024 21:30:18 +0100 Subject: [PATCH] fixed server join --- .../monopoly/client/gui/CreateGameMenu.java | 29 ++++++++++++------- .../pp/monopoly/client/gui/LobbyMenu.java | 6 ++-- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/CreateGameMenu.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/CreateGameMenu.java index a7cd723..9cebf72 100644 --- a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/CreateGameMenu.java +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/CreateGameMenu.java @@ -12,6 +12,7 @@ import java.lang.System.Logger.Level; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; +import com.jme3.math.Vector3f; import com.simsilica.lemur.Button; import com.simsilica.lemur.Container; import com.simsilica.lemur.Label; @@ -40,6 +41,8 @@ public class CreateGameMenu extends SimpleDialog { private final TextField port = new TextField(DEFAULT_PORT); // private final Button serverButton = new Button(lookup("client.server-star")); private final Button serverButton = new Button(lookup("client.server-start")); + private final Button cancelButton = addChild(new Button("Abbrechen")); + private final Button joinButton = addChild(new Button("Beitreten")); private String hostname; private int portNumber; private Future connectionFuture; @@ -63,18 +66,21 @@ public class CreateGameMenu extends SimpleDialog { input.addChild(host, 1); input.addChild(new Label(lookup("port.number") + ": ")); input.addChild(port, 1); - - DialogBuilder.simple(app.getDialogManager()) - .setTitle(lookup("server.dialog")) - .setExtension(d -> d.addChild(input)) - .setOkButton(lookup("button.connect"), d -> connect()) - .setNoButton(lookup("button.cancel"), app::closeApp) - .setOkClose(false) - .setNoClose(false) - .build(this); - //Add the button to start the sever - addChild(serverButton).addClickCommands(s -> ifTopDialog(this::startServerInThread)); + addChild(input); + // "Abbrechen"-Button + cancelButton.setPreferredSize(new Vector3f(120, 40, 0)); + cancelButton.addClickCommands(source -> new StartMenu(app).open()); + addChild(cancelButton); + cancelButton.addClickCommands(s -> new StartMenu(app)); + + // "Selber hosten"-Button + addChild(serverButton).addClickCommands(s -> startServerInThread()); + + // "Beitreten"-Button + joinButton.setPreferredSize(new Vector3f(120, 40, 0)); + addChild(joinButton); + joinButton.addClickCommands(s -> connect()); } /** @@ -169,6 +175,7 @@ public class CreateGameMenu extends SimpleDialog { Thread serverThread = new Thread(() -> { try { MonopolyServer.main(null); + connect(); } catch (Exception e) { serverButton.setEnabled(true); LOGGER.log(Level.ERROR, "Server could not be started", e); 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 fcdfe00..c0a4b0d 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 @@ -38,6 +38,9 @@ public class LobbyMenu extends Dialog { private Container lowerLeftMenu; private Container lowerRightMenu; + private TextField playerInputField = new TextField("Spieler 1"); + private TextField startingCapital = new TextField("15000"); + public LobbyMenu(MonopolyApp app) { super(app.getDialogManager()); this.app = app; @@ -68,7 +71,7 @@ public class LobbyMenu extends Dialog { spacerBeforeInput.setPreferredSize(new Vector3f(20, 1, 0)); // Width of the spacer // Add an input field (TextField) - TextField startingCapital = horizontalContainer.addChild(new TextField("15000")); + horizontalContainer.addChild(startingCapital); startingCapital.setPreferredWidth(100); // Set the width of the input field startingCapital.setPreferredSize(new Vector3f(150, 50, 0)); startingCapital.setInsets(new Insets3f(5, 10, 5, 10)); // Add padding around the text inside the field @@ -95,7 +98,6 @@ public class LobbyMenu extends Dialog { playerInputContainer.setBackground(null); - TextField playerInputField = new TextField("Spieler 1"); playerInputField.setPreferredSize(new Vector3f(100, 20, 0)); playerInputField.setInsets(new Insets3f(5, 10, 5, 10)); // Add padding for the text inside the field playerInputField.setBackground(new QuadBackgroundComponent(ColorRGBA.Black));