Compare commits

..

6 Commits

Author SHA1 Message Date
Johannes Schmelz
dcf10e0819 automatically join lobby when selfhosting 2024-11-24 21:36:03 +01:00
Johannes Schmelz
6b78733a5d fixed server join 2024-11-24 21:30:18 +01:00
Johannes Schmelz
c124a99901 fixed screen size 2024-11-24 21:29:41 +01:00
Johannes Schmelz
d7df4002da lobby menu 2024-11-24 21:01:57 +01:00
Johannes Schmelz
8b0ef97a82 connect menu cow working 2024-11-24 20:52:29 +01:00
Johannes Schmelz
75d3bef5c8 move start menu 2024-11-24 20:42:07 +01:00
7 changed files with 63 additions and 88 deletions

View File

@ -24,10 +24,10 @@ overlay.top.color=1, 1, 1, 1
settings.show=false
#
# Specifies the width of the application window in pixels.
settings.resolution.width=1920
settings.resolution.width=1200
#
# Specifies the height of the application window in pixels.
settings.resolution.height=1080
settings.resolution.height=800
#
# Determines whether the application runs in full-screen mode.
settings.full-screen=false

View File

@ -22,6 +22,7 @@ import com.simsilica.lemur.GuiGlobals;
import com.simsilica.lemur.style.BaseStyles;
import pp.monopoly.game.client.MonopolyClient;
import pp.monopoly.client.gui.SettingsMenu;
import pp.monopoly.client.gui.StartMenu;
import pp.monopoly.game.client.ClientGameLogic;
import pp.monopoly.game.client.ServerConnection;
import pp.monopoly.notification.ClientStateEvent;
@ -218,7 +219,7 @@ public class MonopolyApp extends SimpleApplication implements MonopolyClient, Ga
setupInput();
setupStates();
setupGui();
// serverConnection.connect();
new StartMenu(this).open();
}
/**
@ -318,6 +319,13 @@ public class MonopolyApp extends SimpleApplication implements MonopolyClient, Ga
return draw;
}
/**
* Tries to connect
*/
public void connect() {
serverConnection.connect();
}
/**
* Handles a request to close the application.
* If the request is initiated by pressing ESC, this parameter is true.

View File

@ -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;
@ -38,8 +39,9 @@ public class CreateGameMenu extends SimpleDialog {
private final NetworkSupport network;
private final TextField host = new TextField(LOCALHOST);
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 serverButton = new Button("Selber hosten");
private final Button cancelButton = new Button("Abbrechen");
private final Button joinButton = new Button("Beitreten");
private String hostname;
private int portNumber;
private Future<Object> connectionFuture;
@ -63,18 +65,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());
}
/**
@ -146,7 +151,7 @@ public class CreateGameMenu extends SimpleDialog {
connectionFuture = null;
progressDialog.close();
this.close();
network.getApp().setInfoText(lookup("wait.for.an.opponent"));
new LobbyMenu(network.getApp()).open();
}
/**
@ -176,5 +181,12 @@ public class CreateGameMenu extends SimpleDialog {
}
});
serverThread.start();
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
connect();
}
}

View File

@ -22,11 +22,14 @@ import com.simsilica.lemur.component.SpringGridLayout;
import com.simsilica.lemur.core.VersionedList;
import com.simsilica.lemur.core.VersionedReference;
import com.simsilica.lemur.style.ElementId;
import pp.dialog.Dialog;
import pp.monopoly.client.MonopolyApp;
import pp.monopoly.message.client.PlayerReady;
import java.util.Set;
public class LobbyMenu {
public class LobbyMenu extends Dialog {
private final MonopolyApp app;
private final Container menuContainer;
@ -35,7 +38,11 @@ public class LobbyMenu {
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;
// Entfernt das CreateGameMenu (inklusive Hintergrund)
@ -64,7 +71,7 @@ public class LobbyMenu {
spacerBeforeInput.setPreferredSize(new Vector3f(20, 1, 0)); // Width of the spacer
// Add an input field (TextField)
TextField startingCapital = horizontalContainer.addChild(new TextField("15 000"));
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
@ -91,7 +98,6 @@ public class LobbyMenu {
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));
@ -129,7 +135,7 @@ public class LobbyMenu {
Button cancelButton = new Button("Abbrechen");
cancelButton.setPreferredSize(new Vector3f(200, 60, 0)); // Set size to match the appearance in the image
cancelButton.setFontSize(18); // Adjust font size
cancelButton.addClickCommands(source -> goBackToCreateGame()); // Add functionality
cancelButton.addClickCommands(source -> close()); // Add functionality
lowerLeftMenu.addChild(cancelButton);
// Position the container near the bottom-left corner
@ -201,20 +207,12 @@ public class LobbyMenu {
* Schaltet den "Bereit"-Status um.
*/
private void toggleReady(Label playersLabel) {
// Beispiel-Logik für das Umschalten des Status
playersLabel.setText("Spielerstatus aktualisiert."); // Beispieltext
app.getGameLogic().send(new PlayerReady(true, "Test", "flugzeug", 15000));;
}
/**
* Geht zurück zum CreateGameMenu.
*/
private void goBackToCreateGame() {
app.getGuiNode().detachChild(menuContainer);
app.getGuiNode().detachChild(background);
app.getGuiNode().detachChild(circle);
app.getGuiNode().detachChild(lowerLeftMenu);
app.getGuiNode().detachChild(lowerRightMenu);
// app.getServerConnection().connect();
@Override
public void close() {
super.close();
}
/**
@ -269,7 +267,7 @@ public class LobbyMenu {
System.out.println("Gamma selected");
break;
case "[3]":
goBackToCreateGame();
close();
break;
default:
System.out.println("Unknown selection");

View File

@ -1,4 +1,4 @@
package pp.monopoly.client;
package pp.monopoly.client.gui;
import com.jme3.material.Material;
import com.jme3.math.Vector3f;
@ -13,8 +13,7 @@ import com.simsilica.lemur.component.QuadBackgroundComponent;
import com.simsilica.lemur.component.SpringGridLayout;
import pp.dialog.Dialog;
import pp.monopoly.client.gui.CreateGameMenu;
import pp.monopoly.client.gui.SettingsMenu;
import pp.monopoly.client.MonopolyApp;
/**
* Constructs the startup menu dialog for the Monopoly application.
@ -33,13 +32,7 @@ public class StartMenu extends Dialog {
public StartMenu(MonopolyApp app) {
super(app.getDialogManager());
this.app = app;
}
/**
* Creates and displays the Start Menu with buttons for starting the game,
* opening settings, and quitting the application.
*/
public static void createStartMenu(MonopolyApp app) {
int screenWidth = app.getContext().getSettings().getWidth();
int screenHeight = app.getContext().getSettings().getHeight();
@ -53,9 +46,6 @@ public class StartMenu extends Dialog {
background.setLocalTranslation(0, 0, -1); // Ensure it is behind other GUI elements
app.getGuiNode().attachChild(background);
createMonopolyLogo(app);
createUnibwLogo(app);
// Center container for title and play button
Container centerMenu = new Container(new SpringGridLayout(Axis.Y, Axis.X));
@ -64,7 +54,7 @@ public class StartMenu extends Dialog {
startButton.setFontSize(40); // Set the font size for the button text
startButton.setTextHAlignment(HAlignment.Center); // Center the text horizontally
startButton.addClickCommands(source -> startGame(app));
startButton.addClickCommands(s -> app.connect());
centerMenu.addChild(startButton);
// Position the center container in the middle of the screen
@ -79,7 +69,7 @@ public class StartMenu extends Dialog {
Button quitButton = new Button("Spiel beenden");
quitButton.setPreferredSize(new Vector3f(130, 40, 0)); // Increase button size slightly (width, height)
quitButton.setFontSize(18);
quitButton.addClickCommands(source -> quitGame());
quitButton.addClickCommands(source -> ifTopDialog(app::closeApp));
lowerLeftMenu.addChild(quitButton);
app.getGuiNode().attachChild(lowerLeftMenu);
@ -89,17 +79,10 @@ public class StartMenu extends Dialog {
Button settingsButton = new Button("Einstellungen");
settingsButton.setPreferredSize(new Vector3f(130, 40, 0)); // Increase button size slightly (width, height)
settingsButton.setFontSize(18); // Increase the font size for the text
settingsButton.addClickCommands(source -> openSettings(app));
settingsButton.addClickCommands(source -> new SettingsMenu(app).open());
lowerRightMenu.addChild(settingsButton);
app.getGuiNode().attachChild(lowerRightMenu);
}
/**
* Creates and positions the Monopoly logo container in the center of the screen.
*/
private static void createMonopolyLogo(MonopolyApp app) {
int screenWidth = app.getContext().getSettings().getWidth();
int screenHeight = app.getContext().getSettings().getHeight();
// Load the Monopoly logo as a texture
Texture logoTexture = app.getAssetManager().loadTexture("Pictures/logo-monopoly.png");
@ -123,14 +106,6 @@ public class StartMenu extends Dialog {
// Attach the container to the GUI node
app.getGuiNode().attachChild(logoContainer);
}
/**
* Creates and positions the Unibw logo container in the center of the screen.
*/
private static void createUnibwLogo(MonopolyApp app) {
int screenWidth = app.getContext().getSettings().getWidth();
int screenHeight = app.getContext().getSettings().getHeight();
// Load the Unibw logo as a texture
Texture unibwTexture = app.getAssetManager().loadTexture("Pictures/logo-unibw.png");
@ -156,26 +131,8 @@ public class StartMenu extends Dialog {
app.getGuiNode().attachChild(unibwContainer);
}
/**
* Starts the game by transitioning to the CreateGameMenu.
*/
private static void startGame(MonopolyApp app) {
app.getGuiNode().detachAllChildren();
// app.getServerConnection().connect();
}
/**
* Opens the settings menu.
*/
private static void openSettings(MonopolyApp app) {
app.getGuiNode().detachAllChildren();
new SettingsMenu(app);
}
/**
* Quits the game application.
*/
private static void quitGame() {
System.exit(0);
@Override
public void escape() {
close();
}
}

View File

@ -28,7 +28,7 @@ public class MonopolyConfig extends Config {
* The default port number for the Monopoly server.
*/
@Property("port")
private int port = 4321;
private int port = 42069;
/**
* The width of the game map in terms of grid units.

View File

@ -139,7 +139,7 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker {
*
* @param msg the message to be sent
*/
void send(ClientMessage msg) {
public void send(ClientMessage msg) {
if (clientSender == null) {
LOGGER.log(Level.ERROR, "trying to send {0} with sender==null", msg); //NON-NLS
} else {