Compare commits

..

No commits in common. "c5e7ef855edfc47f713b69ae3980418aff6ad37e" and "0e405d2f9054b74b31c4860273151d671505c19f" have entirely different histories.

5 changed files with 49 additions and 185 deletions

View File

@ -493,9 +493,4 @@ public class MonopolyApp extends SimpleApplication implements MonopolyClient, Ga
public void disconnect() {
serverConnection.disconnect();
}
public int getId() {
if (serverConnection != null && serverConnection instanceof NetworkSupport) return ((NetworkSupport) serverConnection).getId();
return 0;
}
}

View File

@ -1,7 +1,5 @@
package pp.monopoly.client.gui;
import com.jme3.app.Application;
import com.jme3.app.state.BaseAppState;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
@ -9,175 +7,63 @@ 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.Insets3f;
import com.simsilica.lemur.Label;
import com.simsilica.lemur.Selector;
import com.simsilica.lemur.TextField;
import com.simsilica.lemur.component.QuadBackgroundComponent;
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.notification.Sound;
import java.util.Set;
public class ChoosePartner extends Dialog {
private final MonopolyApp app;
private Selector<String> playerSelector;
private final Button cancelButton = new Button("Abbrechen");
private final Button confirmButton = new Button("Bestätigen");
private final Container mainContainer;
private Container lowerLeftMenu;
private Container lowerRightMenu;
QuadBackgroundComponent translucentWhiteBackground =
new QuadBackgroundComponent(new ColorRGBA(1.0f, 1.0f, 1.0f, 0.5f));
/**
* Constructs the ChoosePartner dialog.
*
* @param app The Monopoly application instance.
*/
private final MonopolyApp app;
private final Container menuContainer;
private Geometry background;
public ChoosePartner(MonopolyApp app) {
super(app.getDialogManager());
this.app = app;
// Background Image
// Hintergrundbild laden und hinzufügen
addBackgroundImage();
// Main container for the UI components
mainContainer = new Container(new SpringGridLayout(Axis.Y, Axis.X));
mainContainer.setPreferredSize(new Vector3f(1000, 600, 0));
mainContainer.setBackground(translucentWhiteBackground);
QuadBackgroundComponent translucentWhiteBackground =
new QuadBackgroundComponent(new ColorRGBA(1.0f, 1.0f, 1.0f, 0.5f));
// Add title with background
Label headerLabel = mainContainer.addChild(new Label("Wähle deinen Handelspartner:", new ElementId("label-Bold")));
headerLabel.setFontSize(40);
headerLabel.setBackground(new QuadBackgroundComponent(new ColorRGBA(1.0f, 1.0f, 1.0f, 0.5f)));
menuContainer = new Container(new SpringGridLayout(Axis.Y, Axis.X));
menuContainer.setPreferredSize(new Vector3f(1000, 600, 0)); // Fixed size of the container
menuContainer.setBackground(translucentWhiteBackground);
// Dropdown for player selection
mainContainer.addChild(createDropdown());
// Create a smaller horizontal container for the label, input field, and spacers
Container horizontalContainer = menuContainer.addChild(new Container(new SpringGridLayout(Axis.X, Axis.Y)));
horizontalContainer.setPreferredSize(new Vector3f(600, 40, 0)); // Adjust container size
horizontalContainer.setBackground(null);
// Add buttons
mainContainer.addChild(createButtonContainer());
Label title = horizontalContainer.addChild(new Label("Wähle deinen Handelspartner:", new ElementId("label-Bold")));
title.setFontSize(40);
// Attach main container to GUI node
app.getGuiNode().attachChild(mainContainer);
mainContainer.setLocalTranslation(
(app.getCamera().getWidth() - mainContainer.getPreferredSize().x) / 2,
(app.getCamera().getHeight() + mainContainer.getPreferredSize().y) / 2,
0
);
}
/**
* Creates the dropdown menu for selecting a partner.
*
* @return The dropdown container.
*/
private Container createDropdown() {
Container dropdownContainer = new Container(new SpringGridLayout(Axis.Y, Axis.X));
dropdownContainer.setPreferredSize(new Vector3f(100, 80, 0));
dropdownContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(ColorRGBA.Black)));
VersionedList<String> playerOptions = new VersionedList<>();
playerOptions.add("Spieler 1");
playerOptions.add("Spieler 2");
playerOptions.add("Spieler 3");
playerOptions.add("Spieler 4");
playerSelector = new Selector<>(playerOptions, "glass");
dropdownContainer.addChild(playerSelector);
Vector3f dimens = dropdownContainer.getPreferredSize();
Vector3f dimens2 = playerSelector.getPopupContainer().getPreferredSize();
dimens2.setX( dimens.getX() );
playerSelector.getPopupContainer().setPreferredSize(new Vector3f(200,200,5));
return dropdownContainer;
}
/**
* Creates the button container with cancel and confirm buttons.
*
* @return The button container.
*/
private Container createButtonContainer() {
Container buttonContainer = new Container(new SpringGridLayout(Axis.X, Axis.Y));
buttonContainer.setBackground(translucentWhiteBackground);
// "Abbrechen" button
lowerLeftMenu = new Container();
cancelButton.setPreferredSize(new Vector3f(200, 60, 0));
cancelButton.setFontSize(30);
cancelButton.addClickCommands(s -> ifTopDialog(() -> {
app.getGameLogic().playSound(Sound.BUTTON);
this.close();
new Toolbar(app).open();
}));
lowerLeftMenu.addChild(cancelButton);
// Position the container near the bottom-left corner
lowerLeftMenu.setLocalTranslation(new Vector3f(120, 170, 3)); // Adjust X and Y to align with the bottom-left corner
app.getGuiNode().attachChild(lowerLeftMenu);
// "Bestätigen" button
lowerRightMenu = new Container();
confirmButton.setPreferredSize(new Vector3f(200, 60, 0));
confirmButton.setFontSize(30);
confirmButton.addClickCommands(s -> ifTopDialog(() -> {
app.getGameLogic().playSound(Sound.BUTTON);
String selectedPlayer = playerSelector.getSelectedItem();
System.out.println("Selected player: " + selectedPlayer);
this.close();
// TODO: Open trade menu or next step
}));
lowerRightMenu.addChild(confirmButton);
// Position the container near the bottom-right corner
lowerRightMenu.setLocalTranslation(new Vector3f(app.getCamera().getWidth() - 320, 170, 3)); // X: 220px from the right, Y: 50px above the bottom
app.getGuiNode().attachChild(lowerRightMenu);
return buttonContainer;
}
/**
* Adds a background image to the dialog.
* 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());
Geometry background = new Geometry("Background", quad);
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); // Position behind other GUI elements
background.setLocalTranslation(0, 0, -1); // Hintergrundebene
app.getGuiNode().attachChild(background);
}
/**
* Handles the escape action for the dialog.
*/
@Override
public void escape() {
new SettingsMenu(app).open();
}
/**
* Updates the dialog periodically, called by the dialog manager.
*
* @param delta The time elapsed since the last update.
*/
@Override
public void update(float delta) {
// Periodic updates (if needed) can be implemented here
}
}

View File

@ -88,7 +88,6 @@ public class LobbyMenu extends Dialog {
// Dropdowns and Labels
Container dropdownContainer = menuContainer.addChild(new Container(new SpringGridLayout(Axis.X, Axis.Y)));
dropdownContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(ColorRGBA.Black)));
dropdownContainer.setPreferredSize(new Vector3f(800, 200, 0));
dropdownContainer.setBackground(null);
dropdownContainer.setInsets(new Insets3f(10, 0, 0, 0));
@ -123,11 +122,6 @@ public class LobbyMenu extends Dialog {
figureDropdown.setBackground(new QuadBackgroundComponent(ColorRGBA.DarkGray));
figureDropdown.setPreferredSize(new Vector3f(100, 20, 0));
figureDropdownContainer.addChild(figureDropdown);
Vector3f dimens = dropdownContainer.getPreferredSize();
Vector3f dimens2 = figureDropdown.getPopupContainer().getPreferredSize();
dimens2.setX( dimens.getX() );
figureDropdown.getPopupContainer().setPreferredSize(new Vector3f(200,200,5));
addSelectionActionListener(figureDropdown, this::onDropdownSelectionChanged);

View File

@ -16,8 +16,6 @@ import com.simsilica.lemur.style.ElementId;
import pp.dialog.Dialog;
import pp.monopoly.client.MonopolyApp;
import pp.monopoly.game.server.Player;
import pp.monopoly.game.server.PlayerHandler;
import pp.monopoly.notification.Sound;
/**
@ -54,37 +52,32 @@ public class Toolbar extends Dialog {
);
toolbarContainer.setPreferredSize(new Vector3f(app.getCamera().getWidth(), 200, 0)); // Volle Breite
PlayerHandler playerHandler = app.getGameLogic().getPlayerHandler();
// Füge Buttons zur Toolbar hinzu
//initializeButtons();
// Menü-Container: Ein Nested-Container für Kontostand und "Meine Gulag Frei Karten"
Container accountContainer = toolbarContainer.addChild(new Container());
accountContainer.addChild(new Label("Kontostand", new ElementId("label-Bold")));
accountContainer.addChild(new Label(playerHandler.getPlayerById(app.getId()).getAccountBalance() + " EUR", new ElementId("label-Text"))); //TODO Variable hier einsetzen
accountContainer.addChild(new Label("6666€", new ElementId("label-Text"))); //TODO Variable hier einsetzen
accountContainer.addChild(new Label("Gulag Frei Karten", new ElementId("label-Bold")));
accountContainer.addChild(new Label(playerHandler.getPlayerById(app.getId()).getNumJailCard()+"", new ElementId("label-Text")));
accountContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.4657f, 0.4735f, 0.4892f, 1.0f)));
// // Add a spacer between accountContainer and overviewContainer
// Panel spacer = new Panel(); // Create an empty panel as a spacer
// spacer.setPreferredSize(new Vector3f(5, 0, 0)); // Adjust the width as needed
// spacer.setBackground(null);
// toolbarContainer.addChild(spacer);
// Add a spacer between accountContainer and overviewContainer
Panel spacer = new Panel(); // Create an empty panel as a spacer
spacer.setPreferredSize(new Vector3f(5, 0, 0)); // Adjust the width as needed
spacer.setBackground(null);
toolbarContainer.addChild(spacer);
// Menü-Container: Ein Container für Übersicht
Container overviewContainer = toolbarContainer.addChild(new Container());
overviewContainer.addChild(new Label("Übersicht", new ElementId("label-Bold")));
for (Player player : playerHandler.getPlayers()) {
if (player.getId() != app.getId()) { // Skip the current player (host)
overviewContainer.addChild(new Label(
player.getName() + ": " + player.getAccountBalance() + " EUR",
new ElementId("label-Text")
));
}
}
overviewContainer.addChild(new Label("„Spieler 1“: 1244€", new ElementId("label-Text")));//TODO Variable hier einsetzen
overviewContainer.addChild(new Label("„Spieler 2“: 1244€", new ElementId("label-Text")));//TODO Variable hier einsetzen
overviewContainer.addChild(new Label("„Spieler 3“: 1244€", new ElementId("label-Text")));//TODO Variable hier einsetzen
overviewContainer.addChild(new Label("„Spieler 4“: 1244€", new ElementId("label-Text")));//TODO Variable hier einsetzen
overviewContainer.addChild(new Label("„Spieler 5“: 1244€", new ElementId("label-Text")));//TODO Variable hier einsetzen
overviewContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.4657f, 0.4735f, 0.4892f, 1.0f)));
// Menü-Container: Ein Container für Würfel
@ -172,27 +165,26 @@ public class Toolbar extends Dialog {
return tradebutton;
}
private Button addPropertyMenuButton() {
Button propertyMenuButton = new Button("Grundstücke");
propertyMenuButton.setFontSize(30.0f);
propertyMenuButton.setPreferredSize(new Vector3f(150, 50, 0)); // Größe des Buttons
propertyMenuButton.addClickCommands(s -> ifTopDialog(() -> {
app.getGameLogic().playSound(Sound.BUTTON);
//TODO open property dialog
}));
return propertyMenuButton;
}
private Button addEndTurnButton() {
Button endTurnButton = new Button("Zug beenden");
Button endTurnButton = new Button("Grundstücke");
endTurnButton.setPreferredSize(new Vector3f(150, 50, 0)); // Größe des Buttons
endTurnButton.addClickCommands(s -> ifTopDialog(() -> {
app.getGameLogic().playSound(Sound.BUTTON);
//TODO send end turn
//TODO open property dialog
}));
return endTurnButton;
}
private Button addPropertyMenuButton() {
Button propertyMenuButton = new Button("Zug beenden");
propertyMenuButton.setPreferredSize(new Vector3f(150, 50, 0)); // Größe des Buttons
propertyMenuButton.addClickCommands(s -> ifTopDialog(() -> {
app.getGameLogic().playSound(Sound.BUTTON);
//TODO send end turn
}));
return propertyMenuButton;
}
/**
* Erstellt die Anzeige für die aktuelle Position.
*

View File

@ -3,7 +3,6 @@ package pp.monopoly.game.server;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.Set;
@ -16,7 +15,7 @@ import pp.monopoly.model.LimitedLinkedList;
*/
@Serializable
public class PlayerHandler {
private List<Player> players = new LinkedList<>();
private List<Player> players = new LimitedLinkedList<>(6);
private Set<Player> readyPlayers = new HashSet<>();
private transient ServerGameLogic logic;
private Player hostPlayer;
@ -166,10 +165,8 @@ public class PlayerHandler {
* @return the player with the required id
*/
public Player getPlayerById(int id) {
System.out.println("TEST");
for (Player player : players) {
if (player.getId() == id) return player;
System.out.println(player.getId());
}
throw new NoSuchElementException("Player mit id "+id+" existiert nicht");
}