fixed server join

This commit is contained in:
Johannes Schmelz 2024-11-24 21:30:18 +01:00
parent c124a99901
commit 6b78733a5d
2 changed files with 22 additions and 13 deletions

View File

@ -12,6 +12,7 @@ import java.lang.System.Logger.Level;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future; import java.util.concurrent.Future;
import com.jme3.math.Vector3f;
import com.simsilica.lemur.Button; import com.simsilica.lemur.Button;
import com.simsilica.lemur.Container; import com.simsilica.lemur.Container;
import com.simsilica.lemur.Label; import com.simsilica.lemur.Label;
@ -40,6 +41,8 @@ public class CreateGameMenu extends SimpleDialog {
private final TextField port = new TextField(DEFAULT_PORT); 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-star"));
private final Button serverButton = new Button(lookup("client.server-start")); 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 String hostname;
private int portNumber; private int portNumber;
private Future<Object> connectionFuture; private Future<Object> connectionFuture;
@ -63,18 +66,21 @@ public class CreateGameMenu extends SimpleDialog {
input.addChild(host, 1); input.addChild(host, 1);
input.addChild(new Label(lookup("port.number") + ": ")); input.addChild(new Label(lookup("port.number") + ": "));
input.addChild(port, 1); 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(input);
addChild(serverButton).addClickCommands(s -> ifTopDialog(this::startServerInThread)); // "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(() -> { Thread serverThread = new Thread(() -> {
try { try {
MonopolyServer.main(null); MonopolyServer.main(null);
connect();
} catch (Exception e) { } catch (Exception e) {
serverButton.setEnabled(true); serverButton.setEnabled(true);
LOGGER.log(Level.ERROR, "Server could not be started", e); LOGGER.log(Level.ERROR, "Server could not be started", e);

View File

@ -38,6 +38,9 @@ public class LobbyMenu extends Dialog {
private Container lowerLeftMenu; private Container lowerLeftMenu;
private Container lowerRightMenu; private Container lowerRightMenu;
private TextField playerInputField = new TextField("Spieler 1");
private TextField startingCapital = new TextField("15000");
public LobbyMenu(MonopolyApp app) { public LobbyMenu(MonopolyApp app) {
super(app.getDialogManager()); super(app.getDialogManager());
this.app = app; this.app = app;
@ -68,7 +71,7 @@ public class LobbyMenu extends Dialog {
spacerBeforeInput.setPreferredSize(new Vector3f(20, 1, 0)); // Width of the spacer spacerBeforeInput.setPreferredSize(new Vector3f(20, 1, 0)); // Width of the spacer
// Add an input field (TextField) // 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.setPreferredWidth(100); // Set the width of the input field
startingCapital.setPreferredSize(new Vector3f(150, 50, 0)); startingCapital.setPreferredSize(new Vector3f(150, 50, 0));
startingCapital.setInsets(new Insets3f(5, 10, 5, 10)); // Add padding around the text inside the field 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); playerInputContainer.setBackground(null);
TextField playerInputField = new TextField("Spieler 1");
playerInputField.setPreferredSize(new Vector3f(100, 20, 0)); playerInputField.setPreferredSize(new Vector3f(100, 20, 0));
playerInputField.setInsets(new Insets3f(5, 10, 5, 10)); // Add padding for the text inside the field playerInputField.setInsets(new Insets3f(5, 10, 5, 10)); // Add padding for the text inside the field
playerInputField.setBackground(new QuadBackgroundComponent(ColorRGBA.Black)); playerInputField.setBackground(new QuadBackgroundComponent(ColorRGBA.Black));