From 4095d9e79d3e43d22abeaa71fc4e8b46a47a4909 Mon Sep 17 00:00:00 2001 From: Johannes Schmelz Date: Mon, 25 Nov 2024 21:29:00 +0100 Subject: [PATCH 01/31] fixed buyCard color and button function --- .../monopoly/client/gui/popups/BuyCard.java | 43 +++++++------------ 1 file changed, 15 insertions(+), 28 deletions(-) diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/BuyCard.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/BuyCard.java index 8a65d6a..565e0dc 100644 --- a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/BuyCard.java +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/BuyCard.java @@ -15,13 +15,13 @@ import pp.monopoly.client.MonopolyApp; import pp.monopoly.client.gui.SettingsMenu; import pp.monopoly.model.fields.BoardManager; import pp.monopoly.model.fields.BuildingProperty; +import pp.monopoly.notification.Sound; /** * SettingsMenu ist ein Overlay-Menü, das durch ESC aufgerufen werden kann. */ public class BuyCard extends Dialog { private final MonopolyApp app; - private final Geometry overlayBackground; private final Container buyCardContainer; private final Container backgroundContainer; @@ -34,22 +34,18 @@ public class BuyCard extends Dialog { //Generate the corresponfing field BuildingProperty field = (BuildingProperty) new BoardManager().getFieldAtIndex(index); - // Halbtransparentes Overlay hinzufügen - overlayBackground = createOverlayBackground(); - app.getGuiNode().attachChild(overlayBackground); - // Create the background container backgroundContainer = new Container(); backgroundContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.8657f, 0.8735f, 0.8892f, 1.0f))); // Darker background - app.getGuiNode().attachChild(backgroundContainer); + attachChild(backgroundContainer); // Hauptcontainer für die Gebäudekarte buyCardContainer = new Container(); - buyCardContainer.setBackground(new QuadBackgroundComponent(field.getColor().getColor())); - - - Label settingsTitle = buyCardContainer.addChild(new Label( field.getName(), new ElementId("settings-title"))); - settingsTitle.setFontSize(48); + + + Label title = buyCardContainer.addChild(new Label( field.getName(), new ElementId("label-Bold"))); + title.setBackground(new QuadBackgroundComponent(field.getColor().getColor())); + title.setFontSize(48); // Text, der auf der Karte steht // Die Preise werden dynamisch dem BoardManager entnommen @@ -70,9 +66,17 @@ public class BuyCard extends Dialog { // Beenden-Button Button quitButton = buyCardContainer.addChild(new Button("Beenden", new ElementId("button"))); quitButton.setFontSize(32); + quitButton.addClickCommands(s -> ifTopDialog(() -> { + app.getGameLogic().playSound(Sound.BUTTON); + close(); + })); // Kaufen-Button Button buyButton = buyCardContainer.addChild(new Button("Kaufen", new ElementId("button"))); buyButton.setFontSize(32); + buyButton.addClickCommands(s -> ifTopDialog( () -> { + app.getGameLogic().playSound(Sound.BUTTON); + //TODO send buy property request + })); float padding = 10; // Padding around the settingsContainer for the background backgroundContainer.setPreferredSize(buyCardContainer.getPreferredSize().addLocal(padding, padding, 0)); @@ -94,22 +98,6 @@ public class BuyCard extends Dialog { app.getGuiNode().attachChild(buyCardContainer); } - /** - * Erstellt einen halbtransparenten Hintergrund für das Menü. - * - * @return Geometrie des Overlays - */ - private Geometry createOverlayBackground() { - Quad quad = new Quad(app.getCamera().getWidth(), app.getCamera().getHeight()); - Geometry overlay = new Geometry("Overlay", quad); - Material material = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md"); - material.setColor("Color", new ColorRGBA(0, 0, 0, 0.5f)); // Halbtransparent - material.getAdditionalRenderState().setBlendMode(BlendMode.Alpha); - overlay.setMaterial(material); - overlay.setLocalTranslation(0, 0, 0); - return overlay; - } - /** * Schließt das Menü und entfernt die GUI-Elemente. */ @@ -117,7 +105,6 @@ public class BuyCard extends Dialog { public void close() { app.getGuiNode().detachChild(buyCardContainer); // Entferne das Menü app.getGuiNode().detachChild(backgroundContainer); //Entfernt Rand - app.getGuiNode().detachChild(overlayBackground); // Entferne das Overlay super.close(); } From f67810b2883852aca8ca98f42eddbf8c7fe50171 Mon Sep 17 00:00:00 2001 From: Yvonne Schmidt Date: Mon, 25 Nov 2024 21:29:54 +0100 Subject: [PATCH 02/31] fixed toolbar buttons --- .../pp/monopoly/client/gui/ChoosePartner.java | 6 ++--- .../java/pp/monopoly/client/gui/Toolbar.java | 25 ++++++++++--------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/ChoosePartner.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/ChoosePartner.java index c0c3596..0de8a3a 100644 --- a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/ChoosePartner.java +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/ChoosePartner.java @@ -34,13 +34,13 @@ public class ChoosePartner extends Dialog { 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.setPreferredSize(new Vector3f(1000, 600, 5)); // Fixed size of the container menuContainer.setBackground(translucentWhiteBackground); // 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); + horizontalContainer.setBackground(translucentWhiteBackground); Label title = horizontalContainer.addChild(new Label("Wähle deinen Handelspartner:", new ElementId("label-Bold"))); title.setFontSize(40); @@ -57,7 +57,7 @@ public class ChoosePartner extends Dialog { Material backgroundMaterial = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md"); backgroundMaterial.setTexture("ColorMap", backgroundImage); background.setMaterial(backgroundMaterial); - background.setLocalTranslation(0, 0, -1); // Hintergrundebene + background.setLocalTranslation(0, 0, 4); // Hintergrundebene app.getGuiNode().attachChild(background); } diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/Toolbar.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/Toolbar.java index 68e2b9d..da1b1a1 100644 --- a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/Toolbar.java +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/Toolbar.java @@ -165,26 +165,27 @@ public class Toolbar extends Dialog { return tradebutton; } - private Button addEndTurnButton() { - 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 open property dialog - })); - return endTurnButton; - } - private Button addPropertyMenuButton() { - Button propertyMenuButton = new Button("Zug beenden"); + 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 send end turn + //TODO open property dialog })); return propertyMenuButton; } + private Button addEndTurnButton() { + Button endTurnButton = new Button("Zug beenden"); + endTurnButton.setPreferredSize(new Vector3f(150, 50, 0)); // Größe des Buttons + endTurnButton.addClickCommands(s -> ifTopDialog(() -> { + app.getGameLogic().playSound(Sound.BUTTON); + //TODO send end turn + })); + return endTurnButton; + } + /** * Erstellt die Anzeige für die aktuelle Position. * From 0e405d2f9054b74b31c4860273151d671505c19f Mon Sep 17 00:00:00 2001 From: Johannes Schmelz Date: Mon, 25 Nov 2024 22:11:35 +0100 Subject: [PATCH 03/31] send PlayerHandler in GameStart --- .../monopoly/game/client/ClientGameLogic.java | 9 ++++--- .../java/pp/monopoly/game/server/Player.java | 4 +-- .../monopoly/game/server/PlayerHandler.java | 3 +-- .../monopoly/game/server/ServerGameLogic.java | 2 +- .../pp/monopoly/message/server/GameStart.java | 14 +++++----- .../pp/monopoly/server/MonopolyServer.java | 26 +------------------ 6 files changed, 16 insertions(+), 42 deletions(-) diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/game/client/ClientGameLogic.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/game/client/ClientGameLogic.java index 978b2e7..3a6df03 100644 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/game/client/ClientGameLogic.java +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/game/client/ClientGameLogic.java @@ -6,6 +6,7 @@ import java.util.ArrayList; import java.util.List; import pp.monopoly.game.server.Player; +import pp.monopoly.game.server.PlayerHandler; import pp.monopoly.message.client.ClientMessage; import pp.monopoly.message.server.BuyPropertyResponse; import pp.monopoly.message.server.DiceResult; @@ -52,7 +53,7 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker { /** The current state of the client game logic. */ private ClientState state = new LobbyState(this); - private List players; + private PlayerHandler playerHandler; private BoardManager boardManager = new BoardManager(); @@ -94,8 +95,8 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker { state.entry(); } - public List getPlayers() { - return players; + public PlayerHandler getPlayerHandler() { + return playerHandler; } /** @@ -255,7 +256,7 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker { */ @Override public void received(GameStart msg) { - players = msg.getPlayers(); + playerHandler = msg.getPlayerHandler(); setState(new WaitForTurnState(this)); } 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 649a38c..c350479 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 @@ -40,8 +40,8 @@ public class Player implements FieldVisitor{ private int getOutOfJailCard; private int fieldID; private DiceResult rollResult; - private final PlayerHandler handler; - private PlayerState state = new LobbyState(); + private transient final PlayerHandler handler; + private transient PlayerState state = new LobbyState(); /** * Default constructor for serialization purposes. diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/game/server/PlayerHandler.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/game/server/PlayerHandler.java index aebe09c..d9a8326 100644 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/game/server/PlayerHandler.java +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/game/server/PlayerHandler.java @@ -1,6 +1,5 @@ package pp.monopoly.game.server; -import java.util.LinkedList; import java.util.Collection; import java.util.Collections; import java.util.HashSet; @@ -18,7 +17,7 @@ import pp.monopoly.model.LimitedLinkedList; public class PlayerHandler { private List players = new LimitedLinkedList<>(6); private Set readyPlayers = new HashSet<>(); - private ServerGameLogic logic; + private transient ServerGameLogic logic; private Player hostPlayer; private Player extra = null; diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/game/server/ServerGameLogic.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/game/server/ServerGameLogic.java index d87d163..bcfd8da 100644 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/game/server/ServerGameLogic.java +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/game/server/ServerGameLogic.java @@ -204,7 +204,7 @@ public class ServerGameLogic implements ClientInterpreter { if(playerHandler.allPlayersReady()) { playerHandler.setStartBalance(startMoney); for (Player p : playerHandler.getPlayers()) { - send(p, new GameStart(playerHandler.getPlayers())); + send(p, new GameStart(playerHandler)); } playerHandler.randomOrder(); send(playerHandler.getPlayerAtIndex(0), new NextPlayerTurn()); diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/GameStart.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/GameStart.java index 9dfab8d..45ea0b3 100644 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/GameStart.java +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/GameStart.java @@ -1,27 +1,25 @@ package pp.monopoly.message.server; -import java.util.List; - import com.jme3.network.serializing.Serializable; -import pp.monopoly.game.server.Player; +import pp.monopoly.game.server.PlayerHandler; @Serializable public class GameStart extends ServerMessage{ - private List players; + private PlayerHandler playerHandler; /** * Default constructor for serialization purposes. */ private GameStart() { /* empty */ } - public GameStart(List players) { - this.players = players; + public GameStart(PlayerHandler playerHandler) { + this.playerHandler = playerHandler; } - public List getPlayers() { - return players; + public PlayerHandler getPlayerHandler() { + return playerHandler; } @Override diff --git a/Projekte/monopoly/server/src/main/java/pp/monopoly/server/MonopolyServer.java b/Projekte/monopoly/server/src/main/java/pp/monopoly/server/MonopolyServer.java index d373e64..4c1b56d 100644 --- a/Projekte/monopoly/server/src/main/java/pp/monopoly/server/MonopolyServer.java +++ b/Projekte/monopoly/server/src/main/java/pp/monopoly/server/MonopolyServer.java @@ -43,18 +43,6 @@ import pp.monopoly.message.server.ServerMessage; import pp.monopoly.model.Figure; import pp.monopoly.model.IntPoint; import pp.monopoly.model.LimitedLinkedList; -import pp.monopoly.model.fields.BuildingProperty; -import pp.monopoly.model.fields.EventField; -import pp.monopoly.model.fields.Field; -import pp.monopoly.model.fields.FieldColor; -import pp.monopoly.model.fields.FineField; -import pp.monopoly.model.fields.FoodField; -import pp.monopoly.model.fields.GateField; -import pp.monopoly.model.fields.GoField; -import pp.monopoly.model.fields.GulagField; -import pp.monopoly.model.fields.PropertyField; -import pp.monopoly.model.fields.TestStreckeField; -import pp.monopoly.model.fields.WacheField; /** * Server implementing the visitor pattern as MessageReceiver for ClientMessages @@ -141,19 +129,7 @@ public class MonopolyServer implements MessageListener, Connec Serializer.registerClass(NextPlayerTurn.class); Serializer.registerClass(Player.class); Serializer.registerClass(Figure.class); - // Serializer.registerClass(PlayerHandler.class); - // Serializer.registerClass(BuildingProperty.class); - // Serializer.registerClass(EventField.class); - // Serializer.registerClass(Field.class); - // // Serializer.registerClass(FieldColor.class); - // Serializer.registerClass(FineField.class); - // Serializer.registerClass(FoodField.class); - // Serializer.registerClass(GateField.class); - // Serializer.registerClass(GoField.class); - // Serializer.registerClass(GulagField.class); - // Serializer.registerClass(PropertyField.class); - // Serializer.registerClass(TestStreckeField.class); - // Serializer.registerClass(WacheField.class); + Serializer.registerClass(PlayerHandler.class); } private void registerListeners() { From 269aceaf1abd59ce4182b8ca67ecdfe7628198d4 Mon Sep 17 00:00:00 2001 From: Yvonne Schmidt Date: Tue, 26 Nov 2024 00:11:01 +0100 Subject: [PATCH 04/31] added ChoosePartner menu --- .../pp/monopoly/client/gui/ChoosePartner.java | 154 +++++++++++++++--- .../pp/monopoly/client/gui/LobbyMenu.java | 6 + 2 files changed, 140 insertions(+), 20 deletions(-) diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/ChoosePartner.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/ChoosePartner.java index 0de8a3a..0b2bfd7 100644 --- a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/ChoosePartner.java +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/ChoosePartner.java @@ -1,5 +1,7 @@ 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; @@ -7,63 +9,175 @@ 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 final Container menuContainer; - private Geometry background; - + private Selector 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. + */ public ChoosePartner(MonopolyApp app) { super(app.getDialogManager()); this.app = app; - // Hintergrundbild laden und hinzufügen + + // Background Image addBackgroundImage(); - QuadBackgroundComponent translucentWhiteBackground = - new QuadBackgroundComponent(new ColorRGBA(1.0f, 1.0f, 1.0f, 0.5f)); + // 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); - menuContainer = new Container(new SpringGridLayout(Axis.Y, Axis.X)); - menuContainer.setPreferredSize(new Vector3f(1000, 600, 5)); // Fixed size of the container - menuContainer.setBackground(translucentWhiteBackground); + // Add title with background + Label headerLabel = mainContainer.addChild(new Label("Wähle deinen Handelspartner:", new ElementId("header"))); + headerLabel.setFontSize(40); + headerLabel.setBackground(translucentWhiteBackground); - // 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(translucentWhiteBackground); + // Dropdown for player selection + mainContainer.addChild(createDropdown()); - Label title = horizontalContainer.addChild(new Label("Wähle deinen Handelspartner:", new ElementId("label-Bold"))); - title.setFontSize(40); + // Add buttons + mainContainer.addChild(createButtonContainer()); + // 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 + ); } /** - * Lädt das Hintergrundbild und fügt es als geometrische Ebene hinzu. + * 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 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. */ private void addBackgroundImage() { Texture backgroundImage = app.getAssetManager().loadTexture("Pictures/unibw-Bib2.png"); Quad quad = new Quad(app.getCamera().getWidth(), app.getCamera().getHeight()); - background = new Geometry("Background", quad); + Geometry 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, 4); // Hintergrundebene - + background.setLocalTranslation(0, 0, -1); // Position behind other GUI elements 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 + } } + + + 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 9e60d9f..a592ac5 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 @@ -88,6 +88,7 @@ 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)); @@ -122,6 +123,11 @@ 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); From 3956d8efa7943cb01d318c215581f0afdb9535a7 Mon Sep 17 00:00:00 2001 From: Johannes Schmelz Date: Tue, 26 Nov 2024 00:11:37 +0100 Subject: [PATCH 05/31] show all playe stats in toolbar --- .../java/pp/monopoly/client/MonopolyApp.java | 5 +++ .../java/pp/monopoly/client/gui/Toolbar.java | 37 +++++++++++-------- .../monopoly/game/server/PlayerHandler.java | 5 ++- 3 files changed, 31 insertions(+), 16 deletions(-) diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/MonopolyApp.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/MonopolyApp.java index 934890f..c6b44c0 100644 --- a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/MonopolyApp.java +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/MonopolyApp.java @@ -493,4 +493,9 @@ 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; + } } diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/Toolbar.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/Toolbar.java index 68e2b9d..c2b8dfe 100644 --- a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/Toolbar.java +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/Toolbar.java @@ -16,6 +16,8 @@ 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; /** @@ -52,32 +54,37 @@ public class Toolbar extends Dialog { ); toolbarContainer.setPreferredSize(new Vector3f(app.getCamera().getWidth(), 200, 0)); // Volle Breite - - // Füge Buttons zur Toolbar hinzu - //initializeButtons(); - + PlayerHandler playerHandler = app.getGameLogic().getPlayerHandler(); // 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("6666€", new ElementId("label-Text"))); //TODO Variable hier einsetzen + accountContainer.addChild(new Label(playerHandler.getPlayerById(app.getId()).getAccountBalance() + " EUR", 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"))); - 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 + + 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.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.4657f, 0.4735f, 0.4892f, 1.0f))); // Menü-Container: Ein Container für Würfel diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/game/server/PlayerHandler.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/game/server/PlayerHandler.java index d9a8326..c1f8793 100644 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/game/server/PlayerHandler.java +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/game/server/PlayerHandler.java @@ -3,6 +3,7 @@ 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; @@ -15,7 +16,7 @@ import pp.monopoly.model.LimitedLinkedList; */ @Serializable public class PlayerHandler { - private List players = new LimitedLinkedList<>(6); + private List players = new LinkedList<>(); private Set readyPlayers = new HashSet<>(); private transient ServerGameLogic logic; private Player hostPlayer; @@ -165,8 +166,10 @@ 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"); } From 170227c97f197fa9b9e4991054ec191b6e380090 Mon Sep 17 00:00:00 2001 From: Yvonne Schmidt Date: Tue, 26 Nov 2024 00:21:13 +0100 Subject: [PATCH 06/31] fixed header in ChoosePartner menu --- .../src/main/java/pp/monopoly/client/gui/ChoosePartner.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/ChoosePartner.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/ChoosePartner.java index 0b2bfd7..f908a0c 100644 --- a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/ChoosePartner.java +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/ChoosePartner.java @@ -55,9 +55,9 @@ public class ChoosePartner extends Dialog { mainContainer.setBackground(translucentWhiteBackground); // Add title with background - Label headerLabel = mainContainer.addChild(new Label("Wähle deinen Handelspartner:", new ElementId("header"))); + Label headerLabel = mainContainer.addChild(new Label("Wähle deinen Handelspartner:", new ElementId("label-Bold"))); headerLabel.setFontSize(40); - headerLabel.setBackground(translucentWhiteBackground); + headerLabel.setBackground(new QuadBackgroundComponent(new ColorRGBA(1.0f, 1.0f, 1.0f, 0.5f))); // Dropdown for player selection mainContainer.addChild(createDropdown()); From c5e7ef855edfc47f713b69ae3980418aff6ad37e Mon Sep 17 00:00:00 2001 From: Yvonne Schmidt Date: Tue, 26 Nov 2024 00:25:31 +0100 Subject: [PATCH 07/31] fixed background location --- .../src/main/java/pp/monopoly/client/gui/ChoosePartner.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/ChoosePartner.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/ChoosePartner.java index f908a0c..e663b56 100644 --- a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/ChoosePartner.java +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/ChoosePartner.java @@ -156,7 +156,7 @@ public class ChoosePartner extends Dialog { 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); // Position behind other GUI elements app.getGuiNode().attachChild(background); } From 840658b5902a6fd20864f13d35c0e75fd152e73a Mon Sep 17 00:00:00 2001 From: Yvonne Schmidt Date: Tue, 26 Nov 2024 00:34:49 +0100 Subject: [PATCH 08/31] fixed background location again --- .../main/java/pp/monopoly/client/gui/ChoosePartner.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/ChoosePartner.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/ChoosePartner.java index e663b56..aa23fcf 100644 --- a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/ChoosePartner.java +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/ChoosePartner.java @@ -70,7 +70,7 @@ public class ChoosePartner extends Dialog { mainContainer.setLocalTranslation( (app.getCamera().getWidth() - mainContainer.getPreferredSize().x) / 2, (app.getCamera().getHeight() + mainContainer.getPreferredSize().y) / 2, - 0 + 3 ); } @@ -95,7 +95,8 @@ public class ChoosePartner extends Dialog { Vector3f dimens = dropdownContainer.getPreferredSize(); Vector3f dimens2 = playerSelector.getPopupContainer().getPreferredSize(); dimens2.setX( dimens.getX() ); - playerSelector.getPopupContainer().setPreferredSize(new Vector3f(200,200,5)); + playerSelector.getPopupContainer().setPreferredSize(new Vector3f(200,200,3)); + playerSelector.setLocalTranslation(0,0,5); return dropdownContainer; } @@ -121,7 +122,7 @@ public class ChoosePartner extends Dialog { 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 + lowerLeftMenu.setLocalTranslation(new Vector3f(120, 170, 5)); // Adjust X and Y to align with the bottom-left corner app.getGuiNode().attachChild(lowerLeftMenu); @@ -139,7 +140,7 @@ public class ChoosePartner extends Dialog { 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 + lowerRightMenu.setLocalTranslation(new Vector3f(app.getCamera().getWidth() - 320, 170, 5)); // X: 220px from the right, Y: 50px above the bottom app.getGuiNode().attachChild(lowerRightMenu); From 7b91a679f58cdaa6d4f325703f7971939e24eadc Mon Sep 17 00:00:00 2001 From: Johannes Schmelz Date: Tue, 26 Nov 2024 00:57:22 +0100 Subject: [PATCH 09/31] abbrechen button in chossePatner --- .../pp/monopoly/client/gui/ChoosePartner.java | 28 +++++++++++-------- .../java/pp/monopoly/client/gui/Toolbar.java | 1 - 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/ChoosePartner.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/ChoosePartner.java index aa23fcf..d320ae7 100644 --- a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/ChoosePartner.java +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/ChoosePartner.java @@ -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; @@ -11,20 +9,16 @@ 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 playerSelector; @@ -33,6 +27,7 @@ public class ChoosePartner extends Dialog { private final Container mainContainer; private Container lowerLeftMenu; private Container lowerRightMenu; + private Geometry background; QuadBackgroundComponent translucentWhiteBackground = new QuadBackgroundComponent(new ColorRGBA(1.0f, 1.0f, 1.0f, 0.5f)); @@ -70,7 +65,7 @@ public class ChoosePartner extends Dialog { mainContainer.setLocalTranslation( (app.getCamera().getWidth() - mainContainer.getPreferredSize().x) / 2, (app.getCamera().getHeight() + mainContainer.getPreferredSize().y) / 2, - 3 + 4 ); } @@ -116,8 +111,7 @@ public class ChoosePartner extends Dialog { cancelButton.setFontSize(30); cancelButton.addClickCommands(s -> ifTopDialog(() -> { app.getGameLogic().playSound(Sound.BUTTON); - this.close(); - new Toolbar(app).open(); + close(); })); lowerLeftMenu.addChild(cancelButton); @@ -134,7 +128,7 @@ public class ChoosePartner extends Dialog { app.getGameLogic().playSound(Sound.BUTTON); String selectedPlayer = playerSelector.getSelectedItem(); System.out.println("Selected player: " + selectedPlayer); - this.close(); + close(); // TODO: Open trade menu or next step })); lowerRightMenu.addChild(confirmButton); @@ -153,11 +147,11 @@ public class ChoosePartner extends Dialog { 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, 3); // Position behind other GUI elements app.getGuiNode().attachChild(background); } @@ -178,6 +172,16 @@ public class ChoosePartner extends Dialog { public void update(float delta) { // Periodic updates (if needed) can be implemented here } + + @Override + public void close() { + app.getGuiNode().detachChild(playerSelector); + app.getGuiNode().detachChild(lowerLeftMenu); + app.getGuiNode().detachChild(lowerRightMenu); + app.getGuiNode().detachChild(mainContainer); + app.getGuiNode().detachChild(background); + super.close(); + } } diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/Toolbar.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/Toolbar.java index 35546eb..989a44e 100644 --- a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/Toolbar.java +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/Toolbar.java @@ -166,7 +166,6 @@ public class Toolbar extends Dialog { tradebutton.setPreferredSize(new Vector3f(150, 50, 0)); // Größe des Buttons tradebutton.addClickCommands(s -> ifTopDialog( () -> { app.getGameLogic().playSound(Sound.BUTTON); - this.close(); new ChoosePartner(app).open(); })); return tradebutton; From d8a2225038245fcc0966454e9bf78c53b52e498b Mon Sep 17 00:00:00 2001 From: Yvonne Schmidt Date: Tue, 26 Nov 2024 01:07:59 +0100 Subject: [PATCH 10/31] added framework for TradeMenu --- .../pp/monopoly/client/gui/ChoosePartner.java | 4 +- .../pp/monopoly/client/gui/TradeMenu.java | 178 ++++++++++++++++++ 2 files changed, 180 insertions(+), 2 deletions(-) create mode 100644 Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/TradeMenu.java diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/ChoosePartner.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/ChoosePartner.java index aa23fcf..379844a 100644 --- a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/ChoosePartner.java +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/ChoosePartner.java @@ -89,7 +89,7 @@ public class ChoosePartner extends Dialog { playerOptions.add("Spieler 2"); playerOptions.add("Spieler 3"); playerOptions.add("Spieler 4"); - + //TODO Selector Logik playerSelector = new Selector<>(playerOptions, "glass"); dropdownContainer.addChild(playerSelector); Vector3f dimens = dropdownContainer.getPreferredSize(); @@ -135,7 +135,7 @@ public class ChoosePartner extends Dialog { String selectedPlayer = playerSelector.getSelectedItem(); System.out.println("Selected player: " + selectedPlayer); this.close(); - // TODO: Open trade menu or next step + new TradeMenu(app).open(); })); lowerRightMenu.addChild(confirmButton); diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/TradeMenu.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/TradeMenu.java new file mode 100644 index 0000000..810f173 --- /dev/null +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/TradeMenu.java @@ -0,0 +1,178 @@ +package pp.monopoly.client.gui; + +import com.jme3.material.Material; +import com.jme3.math.ColorRGBA; +import com.jme3.math.Vector3f; +import com.jme3.scene.Geometry; +import com.jme3.scene.shape.Quad; +import com.jme3.texture.Texture; +import com.simsilica.lemur.*; +import com.simsilica.lemur.component.QuadBackgroundComponent; +import com.simsilica.lemur.component.SpringGridLayout; +import com.simsilica.lemur.core.VersionedList; +import com.simsilica.lemur.style.ElementId; +import pp.dialog.Dialog; +import pp.monopoly.client.MonopolyApp; +import pp.monopoly.notification.Sound; + +public class TradeMenu extends Dialog { + private final MonopolyApp app; + private final Container mainContainer; + private Selector leftBuildingSelector, leftCurrencySelector, leftSpecialCardSelector; + private Selector rightBuildingSelector, rightCurrencySelector, rightSpecialCardSelector; + private final Button cancelButton = new Button("Abbrechen"); + private final Button tradeButton = new Button("Handeln"); + private Container lowerLeftMenu, lowerRightMenu; + QuadBackgroundComponent translucentWhiteBackground = + new QuadBackgroundComponent(new ColorRGBA(ColorRGBA.White)); + + /** + * Constructs the TradeMenu dialog. + * + * @param app The Monopoly application instance. + */ + public TradeMenu(MonopolyApp app) { + super(app.getDialogManager()); + this.app = app; + + // Background Image + addBackgroundImage(); + + // Main container for the UI components + mainContainer = new Container(new SpringGridLayout(Axis.Y, Axis.X)); + mainContainer.setPreferredSize(new Vector3f(1200, 800, 0)); + mainContainer.setBackground(translucentWhiteBackground); + + + // Add title with background + Label headerLabel = mainContainer.addChild(new Label("Handelsmenu", new ElementId("label-Bold"))); + headerLabel.setFontSize(40); + headerLabel.setBackground(new QuadBackgroundComponent(new ColorRGBA(1.0f, 1.0f, 1.0f, 0.5f))); + + // Add main content (three columns: left, middle, right) + mainContainer.addChild(createMainContent()); + + // 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, + 7 + ); + } + //TODO Logik + //TODO Ebenen prüfen und eine Ebene Hochsetzen + //TODO Farben der Label anpassen + + /** + * Creates the main content layout (left, middle, right columns). + * + * @return The main content container. + */ + private Container createMainContent() { + Container mainContent = new Container(new SpringGridLayout(Axis.X, Axis.Y)); + + // Left Column + mainContent.addChild(createTradeColumn("Wähle Handelsobjekt:", true)); + + // Middle Section + Container middleSection = mainContent.addChild(new Container(new SpringGridLayout(Axis.Y, Axis.X))); + middleSection.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.8f, 0.8f, 0.8f, 1.0f))); + + TextField leftSelectionsField = middleSection.addChild(new TextField("Quellobjekte...")); + + + Label arrows = middleSection.addChild(new Label("⇅")); + arrows.setFontSize(40); + + TextField rightSelectionsField = middleSection.addChild(new TextField("Zielobjekte...")); + + + // Right Column + mainContent.addChild(createTradeColumn("Wähle Zielobjekt:", false)); + + return mainContent; + } + + /** + * Creates a column for trade objects (left or right side). + * + * @param label The label for the column. + * @param isLeft Whether this column is the left side. + * @return The column container. + */ + private Container createTradeColumn(String label, boolean isLeft) { + Container column = new Container(new SpringGridLayout(Axis.Y, Axis.X)); + column.setBackground(new QuadBackgroundComponent(new ColorRGBA(ColorRGBA.Black))); + + Label columnLabel = column.addChild(new Label(label)); + columnLabel.setFontSize(24); + columnLabel.setBackground(translucentWhiteBackground); + + // Add dropdowns + column.addChild(new Label("Gebäude:")); + Selector buildingSelector = column.addChild(new Selector<>(getSampleItems(),"glass")); + + column.addChild(new Label("Währung:")); + Selector currencySelector = column.addChild(new Selector<>(getSampleItems(),"glass")); + + column.addChild(new Label("Sonderkarten:")); + Selector specialCardSelector = column.addChild(new Selector<>(getSampleItems(),"glass")); + + // Assign selectors to corresponding fields + if (isLeft) { + leftBuildingSelector = buildingSelector; + leftCurrencySelector = currencySelector; + leftSpecialCardSelector = specialCardSelector; + } else { + rightBuildingSelector = buildingSelector; + rightCurrencySelector = currencySelector; + rightSpecialCardSelector = specialCardSelector; + } + + return column; + } + + /** + * Provides sample dropdown items. + */ + private VersionedList getSampleItems() { + VersionedList items = new VersionedList<>(); + items.add("Option 1"); + items.add("Option 2"); + items.add("Option 3"); + return items; + } + + /** + * Adds a background image to the dialog. + */ + 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); + Material backgroundMaterial = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md"); + backgroundMaterial.setTexture("ColorMap", backgroundImage); + background.setMaterial(backgroundMaterial); + background.setLocalTranslation(0, 0, 6); // Position behind other GUI elements + 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 + } +} From d6ce859fcda643ff04849a00445057c208f89b1f Mon Sep 17 00:00:00 2001 From: Yvonne Schmidt Date: Tue, 26 Nov 2024 01:12:29 +0100 Subject: [PATCH 11/31] ChoosePartner accept-button opens TradeMenu --- .../src/main/java/pp/monopoly/client/gui/ChoosePartner.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/ChoosePartner.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/ChoosePartner.java index d320ae7..09b5774 100644 --- a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/ChoosePartner.java +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/ChoosePartner.java @@ -129,7 +129,7 @@ public class ChoosePartner extends Dialog { String selectedPlayer = playerSelector.getSelectedItem(); System.out.println("Selected player: " + selectedPlayer); close(); - // TODO: Open trade menu or next step + new TradeMenu(app).open(); })); lowerRightMenu.addChild(confirmButton); From 27a0ab52e621732b3a4324be2dfb0497dc6dd6cb Mon Sep 17 00:00:00 2001 From: Johannes Schmelz Date: Tue, 26 Nov 2024 14:59:48 +0100 Subject: [PATCH 12/31] dice button now works and update dice images accordingly --- .../pp/monopoly/client/gui/TestWorld.java | 8 +-- .../java/pp/monopoly/client/gui/Toolbar.java | 64 ++++++++++++++++--- .../monopoly/game/client/ClientGameLogic.java | 7 +- .../java/pp/monopoly/game/server/Player.java | 5 +- .../monopoly/game/server/PlayerHandler.java | 1 - .../monopoly/game/server/ServerGameLogic.java | 3 +- .../pp/monopoly/message/client/RollDice.java | 2 +- .../monopoly/message/server/DiceResult.java | 19 ++++-- .../monopoly/notification/DiceRollEvent.java | 10 +++ .../notification/GameEventListener.java | 2 + .../pp/monopoly/server/MonopolyServer.java | 2 + 11 files changed, 96 insertions(+), 27 deletions(-) create mode 100644 Projekte/monopoly/model/src/main/java/pp/monopoly/notification/DiceRollEvent.java diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/TestWorld.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/TestWorld.java index 41d35bb..34fc1c4 100644 --- a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/TestWorld.java +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/TestWorld.java @@ -1,8 +1,6 @@ package pp.monopoly.client.gui; -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.TimeUnit; +import java.util.List; import com.jme3.material.Material; import com.jme3.math.ColorRGBA; @@ -21,6 +19,7 @@ public class TestWorld { private final MonopolyApp app; private CameraController cameraController; // Steuert die Kamera + private Toolbar toolbar; /** * Konstruktor für TestWorld. @@ -51,7 +50,8 @@ public class TestWorld { ); // Füge die Toolbar hinzu - new Toolbar(app).open(); + toolbar = new Toolbar(app); + toolbar.open(); cameraController.setPosition(0); } diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/Toolbar.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/Toolbar.java index 989a44e..a2bd72a 100644 --- a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/Toolbar.java +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/Toolbar.java @@ -1,6 +1,7 @@ package pp.monopoly.client.gui; +import java.util.List; import java.util.Random; import com.jme3.font.BitmapText; @@ -18,20 +19,23 @@ import pp.dialog.Dialog; import pp.monopoly.client.MonopolyApp; import pp.monopoly.game.server.Player; import pp.monopoly.game.server.PlayerHandler; +import pp.monopoly.message.client.RollDice; +import pp.monopoly.notification.DiceRollEvent; +import pp.monopoly.notification.GameEventListener; import pp.monopoly.notification.Sound; /** * Toolbar Klasse, die am unteren Rand der Szene angezeigt wird. * Die Buttons bewegen den Würfel auf dem Spielfeld. */ -public class Toolbar extends Dialog { +public class Toolbar extends Dialog implements GameEventListener{ private final MonopolyApp app; private final Container toolbarContainer; private final BitmapText positionText; // Anzeige für die aktuelle Position private int currentPosition = 0; // Aktuelle Position auf dem Spielfeld - private String diceOneImage = "Pictures/dice/one.png"; - private String diceTwoImage = "Pictures/dice/two.png"; + private Label imageLabel; + private Label imageLabel2; /** @@ -43,6 +47,8 @@ public class Toolbar extends Dialog { super(app.getDialogManager()); this.app = app; + app.getGameLogic().addListener(this); + // Erstelle die Toolbar toolbarContainer = new Container(new SpringGridLayout(Axis.X, Axis.Y), "toolbar"); @@ -99,13 +105,13 @@ public class Toolbar extends Dialog { Container leftContainer = new Container(); leftContainer.setPreferredSize(new Vector3f(100, 150, 0)); // Adjust size as needed - Label imageLabel = new Label(""); - IconComponent icon = new IconComponent(diceOneImage); // Icon mit Textur erstellen + imageLabel = new Label(""); + IconComponent icon = new IconComponent("Pictures/dice/one.png"); // Icon mit Textur erstellen icon.setIconSize(new Vector2f(100,100)); // Skalierung des Bildes imageLabel.setIcon(icon); - Label imageLabel2 = new Label(""); - IconComponent icon2 = new IconComponent(diceTwoImage); // Icon mit Textur erstellen + imageLabel2 = new Label(""); + IconComponent icon2 = new IconComponent("Pictures/dice/two.png"); // Icon mit Textur erstellen icon2.setIconSize(new Vector2f(100,100)); // Skalierung des Bildes imageLabel2.setIcon(icon2); @@ -138,7 +144,7 @@ public class Toolbar extends Dialog { Button diceButton = new Button("Würfeln"); diceButton.setPreferredSize(new Vector3f(200, 50, 0)); // Full width for Würfeln button diceButton.addClickCommands(s -> ifTopDialog(() -> { - //TODO dice roll logic + app.getGameLogic().send(new RollDice()); app.getGameLogic().playSound(Sound.BUTTON); })); diceContainer.addChild(diceButton); @@ -223,4 +229,46 @@ public class Toolbar extends Dialog { public void escape() { new SettingsMenu(app).open(); } + + @Override + public void receivedEvent(DiceRollEvent event) { + updateDiceImages(event.a(), event.b()); + } + + + private void updateDiceImages(int a, int b) { + IconComponent icon1 = new IconComponent(diceToString(a)); + IconComponent icon2 = new IconComponent(diceToString(b)); + icon1.setIconSize(new Vector2f(100, 100)); + icon2.setIconSize(new Vector2f(100, 100)); + imageLabel.setIcon(icon1); + imageLabel2.setIcon(icon2); + System.out.println("Dice images set"); + } + + private String diceToString(int i) { + switch (i) { + case 1: + return "Pictures/dice/one.png"; + + case 2: + return "Pictures/dice/two.png"; + + case 3: + return "Pictures/dice/three.png"; + + case 4: + return "Pictures/dice/four.png"; + + case 5: + return "Pictures/dice/five.png"; + + case 6: + return "Pictures/dice/six.png"; + + default: + throw new IllegalArgumentException("Invalid dice number: " + i); + } + + } } diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/game/client/ClientGameLogic.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/game/client/ClientGameLogic.java index 3a6df03..b432191 100644 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/game/client/ClientGameLogic.java +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/game/client/ClientGameLogic.java @@ -25,6 +25,7 @@ import pp.monopoly.model.Board; import pp.monopoly.model.IntPoint; import pp.monopoly.model.fields.BoardManager; import pp.monopoly.notification.ClientStateEvent; +import pp.monopoly.notification.DiceRollEvent; import pp.monopoly.notification.GameEvent; import pp.monopoly.notification.GameEventBroker; import pp.monopoly.notification.GameEventListener; @@ -214,9 +215,9 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker { */ @Override public void received(DiceResult msg) { - - //Set the dice images playSound(Sound.DICE_ROLL); + System.out.println("Message kam an"); + notifyListeners(new DiceRollEvent(msg.getRollResult().get(0), msg.getRollResult().get(1))); } /** @@ -226,7 +227,7 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker { */ @Override public void received(EventDrawCard msg) { - + // Kartenlogik playSound(Sound.EVENT_CARD); } 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 c350479..ac85ba2 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 @@ -395,6 +395,7 @@ public class Player implements FieldVisitor{ * @return the result of a dice roll (1 to 6) */ private static int rollDice() { + System.out.println("Gewuerfelt"); return random.nextInt(6) + 1; } } @@ -439,7 +440,7 @@ public class Player implements FieldVisitor{ @Override public DiceResult rollDice() { List roll = List.of(Dice.rollDice(), Dice.rollDice()); - rollResult = new DiceResult(roll); + rollResult = new DiceResult(roll.get(0), roll.get(1)); return rollResult; } @@ -491,7 +492,7 @@ public class Player implements FieldVisitor{ @Override public DiceResult rollDice() { List roll = List.of(Dice.rollDice(), Dice.rollDice()); - rollResult = new DiceResult(roll); + rollResult = new DiceResult(roll.get(0), roll.get(1)); if (rollResult.isDoublets()) { state = new ActiveState(); } else if (DoubletsCounter == 0) { diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/game/server/PlayerHandler.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/game/server/PlayerHandler.java index c1f8793..c9c1bbd 100644 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/game/server/PlayerHandler.java +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/game/server/PlayerHandler.java @@ -166,7 +166,6 @@ 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()); diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/game/server/ServerGameLogic.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/game/server/ServerGameLogic.java index bcfd8da..6751436 100644 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/game/server/ServerGameLogic.java +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/game/server/ServerGameLogic.java @@ -220,7 +220,8 @@ public class ServerGameLogic implements ClientInterpreter { @Override public void received(RollDice msg, int from) { Player player = playerHandler.getPlayerById(from); - if (player != null && state == ServerState.INGAME) { + if (player != null) { + System.out.println("Ergebniss gesendet"); send(player, player.rollDice()); } } diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/message/client/RollDice.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/message/client/RollDice.java index a4d5dfc..fe118d9 100644 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/message/client/RollDice.java +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/message/client/RollDice.java @@ -11,7 +11,7 @@ public class RollDice extends ClientMessage{ /** * Default constructor for serialization purposes. */ - private RollDice() { /* empty */ } + public RollDice() { /* empty */ } @Override public void accept(ClientInterpreter interpreter, int from) { diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/DiceResult.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/DiceResult.java index 4d63f91..864a347 100644 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/DiceResult.java +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/message/server/DiceResult.java @@ -7,19 +7,24 @@ import com.jme3.network.serializing.Serializable; @Serializable public class DiceResult extends ServerMessage{ - private List rollResult; + private final int a; + private final int b; /** * Default constructor for serialization purposes. */ - private DiceResult() { /* empty */ } + private DiceResult() { + a = 1; + b = 1; + } - public DiceResult(List rollResult) { - this.rollResult = rollResult; + public DiceResult(int a, int b) { + this.a = a; + this.b = b; } public List getRollResult() { - return rollResult; + return List.of(a,b); } @Override @@ -34,10 +39,10 @@ public class DiceResult extends ServerMessage{ } public boolean isDoublets() { - return rollResult.get(0) == rollResult.get(1); + return a == b; } public int calcTotal() { - return rollResult.get(0)+rollResult.get(1); + return a+b; } } diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/notification/DiceRollEvent.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/notification/DiceRollEvent.java new file mode 100644 index 0000000..ad54906 --- /dev/null +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/notification/DiceRollEvent.java @@ -0,0 +1,10 @@ +package pp.monopoly.notification; + +public record DiceRollEvent(int a, int b) implements GameEvent{ + + @Override + public void notifyListener(GameEventListener listener) { + listener.receivedEvent(this); + } + +} diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/notification/GameEventListener.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/notification/GameEventListener.java index 3dec0c6..a7592cf 100644 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/notification/GameEventListener.java +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/notification/GameEventListener.java @@ -45,4 +45,6 @@ public interface GameEventListener { * @param event the received event */ default void receivedEvent(ClientStateEvent event) { /* do nothing */ } + + default void receivedEvent(DiceRollEvent event) { /*Do nothing */} } diff --git a/Projekte/monopoly/server/src/main/java/pp/monopoly/server/MonopolyServer.java b/Projekte/monopoly/server/src/main/java/pp/monopoly/server/MonopolyServer.java index 4c1b56d..a79f960 100644 --- a/Projekte/monopoly/server/src/main/java/pp/monopoly/server/MonopolyServer.java +++ b/Projekte/monopoly/server/src/main/java/pp/monopoly/server/MonopolyServer.java @@ -37,6 +37,7 @@ import pp.monopoly.message.client.RollDice; import pp.monopoly.message.client.TradeOffer; import pp.monopoly.message.client.TradeResponse; import pp.monopoly.message.client.ViewAssetsRequest; +import pp.monopoly.message.server.DiceResult; import pp.monopoly.message.server.GameStart; import pp.monopoly.message.server.NextPlayerTurn; import pp.monopoly.message.server.ServerMessage; @@ -130,6 +131,7 @@ public class MonopolyServer implements MessageListener, Connec Serializer.registerClass(Player.class); Serializer.registerClass(Figure.class); Serializer.registerClass(PlayerHandler.class); + Serializer.registerClass(DiceResult.class); } private void registerListeners() { From efba3c496a18b87f48f5d7e868eb26d34e6e1f8f Mon Sep 17 00:00:00 2001 From: Simon Wilkening Date: Tue, 26 Nov 2024 15:15:29 +0100 Subject: [PATCH 13/31] Deckhelper korrigiert, Properties angepasst --- .../java/pp/monopoly/client/MonopolyApp.java | 2 +- .../pp/monopoly/model/card/DeckHelper.java | 30 +++++++++---------- .../src/main/resources/monopoly_de.properties | 10 +++---- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/MonopolyApp.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/MonopolyApp.java index c6b44c0..70d39d4 100644 --- a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/MonopolyApp.java +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/MonopolyApp.java @@ -221,7 +221,7 @@ public class MonopolyApp extends SimpleApplication implements MonopolyClient, Ga /** * Returns the current configuration settings for the Battleship client. * - * @return The {@link BattleshipClientConfig} instance. + * @return The {@link BattleshipClientConfig} instance. //TODO Fehler im Kommentar */ @Override public MonopolyAppConfig getConfig() { diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/model/card/DeckHelper.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/model/card/DeckHelper.java index c967efd..500d14a 100644 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/model/card/DeckHelper.java +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/model/card/DeckHelper.java @@ -16,38 +16,38 @@ public class DeckHelper{ public DeckHelper() { cards = new LinkedList(); - cards.add(new Card("Du wurdest mit einem Dienst KFZ geblitzt. Zahle: 800€", "dienst-kfz-blitzer")); + cards.add(new Card("Du wurdest mit einem Dienst KFZ geblitzt. Zahle: 800 EUR", "dienst-kfz-blitzer")); cards.add(new Card("Die erste Spoparty steht bevor. Ziehe vor zum 23er.", "spoparty")); cards.add(new Card("Du kommst aus dem Gulak frei.", "gulak-frei-1")); cards.add(new Card("Du kommst aus dem Gulak frei.", "gulak-frei-2")); cards.add(new Card("Du hast den Dienstführerschein bestanden. Ziehe vor bis Teststrecke.", "dienstfuehrerschein")); cards.add(new Card("Malkmus läd zum Pubquiz ein. Rücke vor bis zum 20er.", "pubquiz")); - cards.add(new Card("Du warst ohne Namensschild in der Truppenküche. Rücke vor zum 10er. Gehe nicht über Monatsgehalt. Ziehe keine 2000x€ ein.", "namensschild-truppenkueche")); - cards.add(new Card("Du hast heute die Spendierhosen an und gibst eine Runde in der Unibar. Zahle jedem Spieler: 400€", "spendierhosen-unibar")); + cards.add(new Card("Du warst ohne Namensschild in der Truppenküche. Rücke vor zum 10er. Gehe nicht über Monatsgehalt. Ziehe keine 2000x EUR ein.", "namensschild-truppenkueche")); + cards.add(new Card("Du hast heute die Spendierhosen an und gibst eine Runde in der Unibar. Zahle jedem Spieler: 400 EUR", "spendierhosen-unibar")); cards.add(new Card("Du warst in der Prüfungsphase krank. Gehe 3 Felder zurück.", "pruefungsphase-krank")); cards.add(new Card("Ziehe vor bis zum nächsten Monatsgehalt.", "naechstes-monatsgehalt")); - cards.add(new Card("Du hast ein Antreten verschlafen. Zahle: 500€", "antreten-verschlafen-1")); - cards.add(new Card("Du hast den Maibock organisiert. Du erhältst: 3000€", "maibock-organisiert")); - cards.add(new Card("Der Spieß macht eine unangekündigte Inventur. Zahle für jedes Haus: 400€ und jedes Hotel: 2800€", "inventur-haeuser-hotels")); + cards.add(new Card("Du hast ein Antreten verschlafen. Zahle: 500 EUR", "antreten-verschlafen-1")); + cards.add(new Card("Du hast den Maibock organisiert. Du erhältst: 3000 EUR", "maibock-organisiert")); + cards.add(new Card("Der Spieß macht eine unangekündigte Inventur. Zahle für jedes Haus: 400 EUR und jedes Hotel: 2800 EUR", "inventur-haeuser-hotels")); cards.add(new Card("Es gab keine Mozzarella Bällchen mehr für Thoma. Alle Spieler ziehen vor auf Gym.", "dienstsport-gym")); cards.add(new Card("Auf deiner Stube wurde Schimmel gefunden. Gehe ins Gulak. Begib Dich direkt dorthin. Gehe nicht über Monatsgehalt. Ziehe nicht ein.", "schimmel-gulak")); cards.add(new Card("Deine Stube ist nach einer Partynacht nicht mehr bewohnbar. Du ziehst ins Gulak. Begib Dich direkt dorthin. Gehe nicht über Monatsgehalt. Ziehe nicht ein.", "partynacht-gulak")); cards.add(new Card("Das Jahresabschlussantreten steht an. Ziehe vor bis Schwimmhalle.", "jahresabschlussantreten")); - cards.add(new Card("Du wurdest beim Verkaufen von Versicherungen erwischt. Zahle: 4000€", "verkaufen-versicherungen")); + cards.add(new Card("Du wurdest beim Verkaufen von Versicherungen erwischt. Zahle: 4000 EUR", "verkaufen-versicherungen")); cards.add(new Card("Du musstest einen Rückstuferantrag stellen. Setze eine Runde aus.", "rueckstuferantrag")); - cards.add(new Card("Auf einer Hausfeier bist du betrunken auf der Treppe gestürzt und dabei auf einen Kameraden gefallen. Zahle: 800€ und gehe zurück zu SanZ.", "hausfeier-sturz")); - cards.add(new Card("Beförderung. Beim nächsten Monatsgehalt ziehst du ein: 3000€", "befoerderung")); - cards.add(new Card("Du entscheidest dich für eine Dienstreise nach Lourd. Zahle: 1000€ und setze eine Runde aus.", "dienstreise-lourd")); + cards.add(new Card("Auf einer Hausfeier bist du betrunken auf der Treppe gestürzt und dabei auf einen Kameraden gefallen. Zahle: 800 EUR und gehe zurück zu SanZ.", "hausfeier-sturz")); + cards.add(new Card("Beförderung. Beim nächsten Monatsgehalt ziehst du ein: 3000 EUR", "befoerderung")); + cards.add(new Card("Du entscheidest dich für eine Dienstreise nach Lourd. Zahle: 1000 EUR und setze eine Runde aus.", "dienstreise-lourd")); cards.add(new Card("Du warst fleißig Blutspenden und erhältst einen Tag Sonderurlaub. Du bist nochmal an der Reihe.", "blutspenden-sonderurlaub")); cards.add(new Card("Dir wurde auf dem Oktoberfest dein Geldbeutel geklaut. Gebe 10% deines Vermögens ab.", "geldbeutel-oktoberfest")); - cards.add(new Card("Du wirst von deinem Chef für vorbildliches Verhalten gelobt. Du erhältst: 4000€", "lob-chef")); - cards.add(new Card("Deine Bekanntschaft von letzter Nacht war eine Spo. Lasse dich testen und zahle: 200€", "spo-testen")); + cards.add(new Card("Du wirst von deinem Chef für vorbildliches Verhalten gelobt. Du erhältst: 4000 EUR", "lob-chef")); + cards.add(new Card("Deine Bekanntschaft von letzter Nacht war eine Spo. Lasse dich testen und zahle: 200 EUR", "spo-testen")); cards.add(new Card("Du wurdest von Kranz geexmattet. Gehe zurück zu Prüfungsamt.", "kranz-exmatrikulation")); cards.add(new Card("Die letzte Party ist ein wenig eskaliert. Setze eine Runde aus.", "party-eskaliert")); - cards.add(new Card("Du wurdest zur VP gewählt und schmeißt eine Einstandsparty. Zahle: 800€", "vp-einstandsparty")); - cards.add(new Card("Du hast eine Party veranstaltet und dick Gewinn gemacht. Ziehe ein: 1500€", "party-gewinn")); + cards.add(new Card("Du wurdest zur VP gewählt und schmeißt eine Einstandsparty. Zahle: 800 EUR", "vp-einstandsparty")); + cards.add(new Card("Du hast eine Party veranstaltet und dick Gewinn gemacht. Ziehe ein: 1500 EUR", "party-gewinn")); cards.add(new Card("Zur falschen Zeit am falschen Ort. Du musst einen Bergmarsch planen und setzt eine Runde aus.", "bergmarsch")); - cards.add(new Card("Dein Jodel eines Eispenis mit Unterhodenbeleuchtung geht viral. Ziehe ein: 1000€", "jodel-eispenis")); + cards.add(new Card("Dein Jodel eines Eispenis mit Unterhodenbeleuchtung geht viral. Ziehe ein: 1000 EUR", "jodel-eispenis")); } public void visit(Card card, Player player) { diff --git a/Projekte/monopoly/model/src/main/resources/monopoly_de.properties b/Projekte/monopoly/model/src/main/resources/monopoly_de.properties index 95ff4be..de7d9b4 100644 --- a/Projekte/monopoly/model/src/main/resources/monopoly_de.properties +++ b/Projekte/monopoly/model/src/main/resources/monopoly_de.properties @@ -7,7 +7,7 @@ # monopoly.name=Monopoly button.play=Start Game -button.ready=Ready +button.ready=Bereit button.rotate=Rotate server.connection.failed=Failed to establish a server connection. its.your.turn=It's your turn! Click on the opponent's field to shoot... @@ -15,11 +15,11 @@ lost.connection.to.server=Lost connection to server. The game terminated. place.ships.in.your.map=Place ships in your map. wait.for.an.opponent=Wait for an opponent! wait.for.opponent=Wait for your opponent! -confirm.leaving=Would you really like to leave the game? +confirm.leaving=Möchtest du das Spiel wirklich beenden? you.lost.the.game=You lost the game! you.won.the.game=You won the game! -button.yes=Yes -button.no=No +button.yes=Ja +button.no=Nein button.ok=Ok button.connect=Connect button.cancel=Cancel @@ -36,7 +36,7 @@ menu.map.save=Save map in file... label.file=File: label.connecting=Connecting... dialog.error=Error -dialog.question=Question +dialog.question=Frage port.must.be.integer=Port must be an integer number map.doesnt.fit=The map doesn't fit to this game client.server-start=Start server From 6eeb6fd209a67d6b66e50dbd88fc05b2f747adc5 Mon Sep 17 00:00:00 2001 From: Simon Wilkening Date: Tue, 26 Nov 2024 15:29:45 +0100 Subject: [PATCH 14/31] =?UTF-8?q?Properties=5Fde=20=C3=BCbersetzt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/resources/monopoly_de.properties | 50 +++++++++---------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/Projekte/monopoly/model/src/main/resources/monopoly_de.properties b/Projekte/monopoly/model/src/main/resources/monopoly_de.properties index de7d9b4..ec8aa9c 100644 --- a/Projekte/monopoly/model/src/main/resources/monopoly_de.properties +++ b/Projekte/monopoly/model/src/main/resources/monopoly_de.properties @@ -6,37 +6,37 @@ ######################################## # monopoly.name=Monopoly -button.play=Start Game +button.play=Spiel starten button.ready=Bereit -button.rotate=Rotate -server.connection.failed=Failed to establish a server connection. -its.your.turn=It's your turn! Click on the opponent's field to shoot... -lost.connection.to.server=Lost connection to server. The game terminated. -place.ships.in.your.map=Place ships in your map. -wait.for.an.opponent=Wait for an opponent! -wait.for.opponent=Wait for your opponent! +button.rotate=Drehen +server.connection.failed=Fehler beim Herstellen einer Serververbindung. +its.your.turn=Du bist am Zug! Klicke auf das Feld des Gegners, um zu schießen... +lost.connection.to.server=Verbindung zum Server verloren. Das Spiel wurde beendet. +place.ships.in.your.map=Platziere Schiffe auf deiner Karte. +wait.for.an.opponent=Warte auf einen Gegner! +wait.for.opponent=Warte auf deinen Gegner! confirm.leaving=Möchtest du das Spiel wirklich beenden? -you.lost.the.game=You lost the game! -you.won.the.game=You won the game! +you.lost.the.game=Du hast das Spiel verloren! +you.won.the.game=Du hast das Spiel gewonnen! button.yes=Ja button.no=Nein button.ok=Ok -button.connect=Connect -button.cancel=Cancel +button.connect=Verbinden +button.cancel=Abbrechen server.dialog=Server host.name=Host port.number=Port -wait.its.not.your.turn=Wait, it's not your turn!! -menu.quit=Quit game -menu.return-to-game=Return to game -menu.sound-enabled=Sound switched on -menu.background-sound-enabled=Background music switched on -menu.map.load=Load map from file... -menu.map.save=Save map in file... -label.file=File: -label.connecting=Connecting... -dialog.error=Error +wait.its.not.your.turn=Warte, es ist nicht dein Zug!! +menu.quit=Spiel beenden +menu.return-to-game=Zum Spiel zurückkehren +menu.sound-enabled=Ton eingeschaltet +menu.background-sound-enabled=Hintergrundmusik eingeschaltet +menu.map.load=Karte aus Datei laden... +menu.map.save=Karte in Datei speichern... +label.file=Datei: +label.connecting=Verbinde... +dialog.error=Fehler dialog.question=Frage -port.must.be.integer=Port must be an integer number -map.doesnt.fit=The map doesn't fit to this game -client.server-start=Start server +port.must.be.integer=Port muss eine ganze Zahl sein +map.doesnt.fit=Die Karte passt nicht zu diesem Spiel +client.server-start=Server starten From f4c4f6bc93b0aa5e9c62b73c75391d8c223e0a82 Mon Sep 17 00:00:00 2001 From: Johannes Schmelz Date: Tue, 26 Nov 2024 17:53:49 +0100 Subject: [PATCH 15/31] cleanup --- .../java/pp/monopoly/client/gui/Toolbar.java | 48 ++++--------------- 1 file changed, 10 insertions(+), 38 deletions(-) diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/Toolbar.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/Toolbar.java index a2bd72a..eb2a74d 100644 --- a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/Toolbar.java +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/Toolbar.java @@ -19,6 +19,7 @@ import pp.dialog.Dialog; import pp.monopoly.client.MonopolyApp; import pp.monopoly.game.server.Player; import pp.monopoly.game.server.PlayerHandler; +import pp.monopoly.message.client.EndTurn; import pp.monopoly.message.client.RollDice; import pp.monopoly.notification.DiceRollEvent; import pp.monopoly.notification.GameEventListener; @@ -32,10 +33,11 @@ public class Toolbar extends Dialog implements GameEventListener{ private final MonopolyApp app; private final Container toolbarContainer; - private final BitmapText positionText; // Anzeige für die aktuelle Position - private int currentPosition = 0; // Aktuelle Position auf dem Spielfeld private Label imageLabel; private Label imageLabel2; + private Container overviewContainer; + private Container accountContainer; + private PlayerHandler playerHandler; /** @@ -48,6 +50,7 @@ public class Toolbar extends Dialog implements GameEventListener{ this.app = app; app.getGameLogic().addListener(this); + playerHandler = app.getGameLogic().getPlayerHandler(); // Erstelle die Toolbar toolbarContainer = new Container(new SpringGridLayout(Axis.X, Axis.Y), "toolbar"); @@ -60,24 +63,17 @@ public class Toolbar extends Dialog implements GameEventListener{ ); toolbarContainer.setPreferredSize(new Vector3f(app.getCamera().getWidth(), 200, 0)); // Volle Breite - PlayerHandler playerHandler = app.getGameLogic().getPlayerHandler(); // Menü-Container: Ein Nested-Container für Kontostand und "Meine Gulag Frei Karten" - Container accountContainer = toolbarContainer.addChild(new 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(playerHandler.getPlayerById(app.getId()).getAccountBalance() + " EUR", new ElementId("label-Text"))); 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); - // Menü-Container: Ein Container für Übersicht - Container overviewContainer = toolbarContainer.addChild(new Container()); + overviewContainer = toolbarContainer.addChild(new Container()); overviewContainer.addChild(new Label("Übersicht", new ElementId("label-Bold"))); for (Player player : playerHandler.getPlayers()) { @@ -161,10 +157,6 @@ public class Toolbar extends Dialog implements GameEventListener{ // Füge die Toolbar zur GUI hinzu app.getGuiNode().attachChild(toolbarContainer); - - // Erstelle die Position-Anzeige - positionText = createPositionDisplay(); - updatePositionDisplay(); // Initialisiere die Anzeige mit der Startposition } private Button addTradeMenuButton() { @@ -193,35 +185,14 @@ public class Toolbar extends Dialog implements GameEventListener{ endTurnButton.setPreferredSize(new Vector3f(150, 50, 0)); // Größe des Buttons endTurnButton.addClickCommands(s -> ifTopDialog(() -> { app.getGameLogic().playSound(Sound.BUTTON); - //TODO send end turn + app.getGameLogic().send(new EndTurn()); })); return endTurnButton; } - /** - * Erstellt die Anzeige für die aktuelle Position. - * - * @return Das BitmapText-Objekt für die Anzeige - */ - private BitmapText createPositionDisplay() { - BitmapText text = new BitmapText(app.getAssetManager().loadFont("Interface/Fonts/Default.fnt"), false); - text.setSize(20); // Schriftgröße - text.setLocalTranslation(10, app.getCamera().getHeight() - 10, 0); // Oben links - app.getGuiNode().attachChild(text); - return text; - } - - /** - * Aktualisiert die Anzeige für die aktuelle Position. - */ - private void updatePositionDisplay() { - positionText.setText("Feld-ID: " + currentPosition); - } - @Override public void close() { app.getGuiNode().detachChild(toolbarContainer); - app.getGuiNode().detachChild(positionText); super.close(); } @@ -237,6 +208,7 @@ public class Toolbar extends Dialog implements GameEventListener{ private void updateDiceImages(int a, int b) { + //TODO dice toll animation IconComponent icon1 = new IconComponent(diceToString(a)); IconComponent icon2 = new IconComponent(diceToString(b)); icon1.setIconSize(new Vector2f(100, 100)); From ada067a2a0eb6286d3826293e77e0dd287872f58 Mon Sep 17 00:00:00 2001 From: Yvonne Schmidt Date: Tue, 26 Nov 2024 18:25:23 +0100 Subject: [PATCH 16/31] added and centered buttons --- .../pp/monopoly/client/gui/TradeMenu.java | 75 +++++++++++++++++-- 1 file changed, 67 insertions(+), 8 deletions(-) diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/TradeMenu.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/TradeMenu.java index 810f173..94901b9 100644 --- a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/TradeMenu.java +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/TradeMenu.java @@ -43,12 +43,8 @@ public class TradeMenu extends Dialog { mainContainer.setPreferredSize(new Vector3f(1200, 800, 0)); mainContainer.setBackground(translucentWhiteBackground); - - // Add title with background - Label headerLabel = mainContainer.addChild(new Label("Handelsmenu", new ElementId("label-Bold"))); - headerLabel.setFontSize(40); - headerLabel.setBackground(new QuadBackgroundComponent(new ColorRGBA(1.0f, 1.0f, 1.0f, 0.5f))); - + // Add header container + mainContainer.addChild(createHeaderContainer()); // Add main content (three columns: left, middle, right) mainContainer.addChild(createMainContent()); @@ -64,6 +60,26 @@ public class TradeMenu extends Dialog { //TODO Ebenen prüfen und eine Ebene Hochsetzen //TODO Farben der Label anpassen + + /** + * Creates a container for the header with a fixed size. + * + * @return The header container. + */ + private Container createHeaderContainer() { + // Create a container for the header + Container headerContainer = new Container(new SpringGridLayout(Axis.X, Axis.Y)); + headerContainer.setPreferredSize(new Vector3f(200, 100, 0)); // Set fixed width and height + + // Add the header label + Label headerLabel = headerContainer.addChild(new Label("Handelsmenü", new ElementId("label-Bold"))); + headerLabel.setFontSize(32); // Adjust font size as needed + headerLabel.setInsets(new Insets3f(10, 10, 10, 10)); // Add padding around the label + headerLabel.setBackground(new QuadBackgroundComponent(new ColorRGBA(1.0f, 1.0f, 1.0f, 0.5f))); // Optional background + + return headerContainer; + } + /** * Creates the main content layout (left, middle, right columns). * @@ -71,6 +87,7 @@ public class TradeMenu extends Dialog { */ private Container createMainContent() { Container mainContent = new Container(new SpringGridLayout(Axis.X, Axis.Y)); + mainContent.setPreferredSize(new Vector3f(1200, 700, 0)); // Left Column mainContent.addChild(createTradeColumn("Wähle Handelsobjekt:", true)); @@ -86,11 +103,29 @@ public class TradeMenu extends Dialog { arrows.setFontSize(40); TextField rightSelectionsField = middleSection.addChild(new TextField("Zielobjekte...")); + // "Bestätigen" button + lowerRightMenu = new Container(); + tradeButton.setPreferredSize(new Vector3f(200, 60, 0)); + tradeButton.setFontSize(30); + tradeButton.addClickCommands(s -> ifTopDialog(() -> { + app.getGameLogic().playSound(Sound.BUTTON); + close(); + new TradeMenu(app).open(); + })); + lowerRightMenu.addChild(tradeButton); + + // Position the container near the bottom-right corner + lowerRightMenu.setLocalTranslation(new Vector3f(app.getCamera().getWidth() - 680, 100, 8)); // X: 220px from the right, Y: 50px above the bottom + app.getGuiNode().attachChild(lowerRightMenu); + // Right Column mainContent.addChild(createTradeColumn("Wähle Zielobjekt:", false)); + Label spacer = middleSection.addChild(new Label("")); // Spacer + spacer.setPreferredSize(new Vector3f(1, 50, 0)); + return mainContent; } @@ -103,7 +138,7 @@ public class TradeMenu extends Dialog { */ private Container createTradeColumn(String label, boolean isLeft) { Container column = new Container(new SpringGridLayout(Axis.Y, Axis.X)); - column.setBackground(new QuadBackgroundComponent(new ColorRGBA(ColorRGBA.Black))); + column.setBackground(new QuadBackgroundComponent(new ColorRGBA(ColorRGBA.White))); Label columnLabel = column.addChild(new Label(label)); columnLabel.setFontSize(24); @@ -112,22 +147,46 @@ public class TradeMenu extends Dialog { // Add dropdowns column.addChild(new Label("Gebäude:")); Selector buildingSelector = column.addChild(new Selector<>(getSampleItems(),"glass")); + buildingSelector.setBackground(new QuadBackgroundComponent(new ColorRGBA(ColorRGBA.Black))); column.addChild(new Label("Währung:")); Selector currencySelector = column.addChild(new Selector<>(getSampleItems(),"glass")); + currencySelector.setBackground(new QuadBackgroundComponent(new ColorRGBA(ColorRGBA.Black))); column.addChild(new Label("Sonderkarten:")); Selector specialCardSelector = column.addChild(new Selector<>(getSampleItems(),"glass")); + specialCardSelector.setBackground(new QuadBackgroundComponent(new ColorRGBA(ColorRGBA.Black))); // Assign selectors to corresponding fields if (isLeft) { leftBuildingSelector = buildingSelector; leftCurrencySelector = currencySelector; leftSpecialCardSelector = specialCardSelector; - } else { + + // "Abbrechen" button + lowerLeftMenu = new Container(); + cancelButton.setPreferredSize(new Vector3f(200, 60, 0)); + cancelButton.setFontSize(30); + cancelButton.addClickCommands(s -> ifTopDialog(() -> { + app.getGameLogic().playSound(Sound.BUTTON); + close(); + })); + lowerLeftMenu.addChild(cancelButton); + + // Position the container near the bottom-left corner + lowerLeftMenu.setLocalTranslation(new Vector3f(70, 100, 8)); // Adjust X and Y to align with the bottom-left corner + app.getGuiNode().attachChild(lowerLeftMenu); + + Label spacer = column.addChild(new Label("")); // Spacer + spacer.setPreferredSize(new Vector3f(1, 130, 0)); + + } else { rightBuildingSelector = buildingSelector; rightCurrencySelector = currencySelector; rightSpecialCardSelector = specialCardSelector; + + Label spacer = column.addChild(new Label("")); // Spacer + spacer.setPreferredSize(new Vector3f(1, 130, 0)); } return column; From c71e8b1e8ee37d627f541c45980226d0f3a4349e Mon Sep 17 00:00:00 2001 From: Johannes Schmelz Date: Tue, 26 Nov 2024 18:48:13 +0100 Subject: [PATCH 17/31] removed hostplayer as hostplayer always has id 0 --- .../java/pp/monopoly/game/server/PlayerHandler.java | 12 ------------ .../pp/monopoly/game/server/ServerGameLogic.java | 2 +- 2 files changed, 1 insertion(+), 13 deletions(-) diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/game/server/PlayerHandler.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/game/server/PlayerHandler.java index c9c1bbd..dbb57fb 100644 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/game/server/PlayerHandler.java +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/game/server/PlayerHandler.java @@ -19,7 +19,6 @@ public class PlayerHandler { private List players = new LinkedList<>(); private Set readyPlayers = new HashSet<>(); private transient ServerGameLogic logic; - private Player hostPlayer; private Player extra = null; /** @@ -55,14 +54,6 @@ public class PlayerHandler { players.addAll(players); } - /** - * Return the host player - * @return the host player - */ - public Player getHostPlayer() { - return hostPlayer; - } - /** * Return the number of players * @return number of players in the game @@ -114,9 +105,6 @@ public class PlayerHandler { throw new IllegalArgumentException("Player already registered"); } players.add(player); - if(hostPlayer == null) { - hostPlayer = player; - } } /** diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/game/server/ServerGameLogic.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/game/server/ServerGameLogic.java index 6751436..7e2c13e 100644 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/game/server/ServerGameLogic.java +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/game/server/ServerGameLogic.java @@ -189,7 +189,7 @@ public class ServerGameLogic implements ClientInterpreter { @Override public void received(PlayerReady msg, int from) { Player player = playerHandler.getPlayerById(from); - if(player == playerHandler.getHostPlayer()) { + if(player.getId() == 0) { startMoney = msg.getStartMoney(); } From 174958c6b1cdcf0b5af0891dfa903c7bb2cb10a4 Mon Sep 17 00:00:00 2001 From: Johannes Schmelz Date: Tue, 26 Nov 2024 18:50:24 +0100 Subject: [PATCH 18/31] can now dynamically update toolbar view --- .../java/pp/monopoly/client/gui/Toolbar.java | 65 ++++++++++++------- .../notification/GameEventListener.java | 12 ++++ .../notification/UpdatePlayerView.java | 13 ++++ 3 files changed, 68 insertions(+), 22 deletions(-) create mode 100644 Projekte/monopoly/model/src/main/java/pp/monopoly/notification/UpdatePlayerView.java diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/Toolbar.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/Toolbar.java index eb2a74d..408dad1 100644 --- a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/Toolbar.java +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/Toolbar.java @@ -1,14 +1,15 @@ package pp.monopoly.client.gui; -import java.util.List; -import java.util.Random; - -import com.jme3.font.BitmapText; import com.jme3.math.ColorRGBA; import com.jme3.math.Vector2f; import com.jme3.math.Vector3f; -import com.simsilica.lemur.*; +import com.simsilica.lemur.Axis; +import com.simsilica.lemur.Button; +import com.simsilica.lemur.Container; +import com.simsilica.lemur.HAlignment; +import com.simsilica.lemur.Label; +import com.simsilica.lemur.VAlignment; import com.simsilica.lemur.component.IconComponent; import com.simsilica.lemur.component.QuadBackgroundComponent; import com.simsilica.lemur.component.SpringGridLayout; @@ -24,6 +25,7 @@ import pp.monopoly.message.client.RollDice; import pp.monopoly.notification.DiceRollEvent; import pp.monopoly.notification.GameEventListener; import pp.monopoly.notification.Sound; +import pp.monopoly.notification.UpdatePlayerView; /** * Toolbar Klasse, die am unteren Rand der Szene angezeigt wird. @@ -66,25 +68,10 @@ public class Toolbar extends Dialog implements GameEventListener{ // Menü-Container: Ein Nested-Container für Kontostand und "Meine Gulag Frei Karten" 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"))); - 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))); - // Menü-Container: Ein Container für Übersicht 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") - )); - } - } - + + receivedEvent(new UpdatePlayerView()); overviewContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.4657f, 0.4735f, 0.4892f, 1.0f))); @@ -206,6 +193,40 @@ public class Toolbar extends Dialog implements GameEventListener{ updateDiceImages(event.a(), event.b()); } + @Override + public void receivedEvent(UpdatePlayerView event) { + // Clear existing accountContainer and overviewContainer content + accountContainer.clearChildren(); + overviewContainer.clearChildren(); + + // Update accountContainer + accountContainer.addChild(new Label("Kontostand", new ElementId("label-Bold"))); + accountContainer.addChild(new Label( + playerHandler.getPlayerById(app.getId()).getAccountBalance() + " EUR", + new ElementId("label-Text") + )); + accountContainer.addChild(new Label("Gulag 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))); + + // Update overviewContainer + overviewContainer.addChild(new Label("Übersicht", new ElementId("label-Bold"))); + for (Player player : playerHandler.getPlayers()) { + if (player.getId() != app.getId()) { // Skip the current player + overviewContainer.addChild(new Label( + player.getName() + ": " + player.getAccountBalance() + " EUR", + new ElementId("label-Text") + )); + } + } + overviewContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.4657f, 0.4735f, 0.4892f, 1.0f))); + System.out.println("pdate"); + } + + private void updateDiceImages(int a, int b) { //TODO dice toll animation diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/notification/GameEventListener.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/notification/GameEventListener.java index a7592cf..d5cc0bf 100644 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/notification/GameEventListener.java +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/notification/GameEventListener.java @@ -46,5 +46,17 @@ public interface GameEventListener { */ default void receivedEvent(ClientStateEvent event) { /* do nothing */ } + /** + * Indicates that the dice result has changed. + * + * @param event the received event + */ default void receivedEvent(DiceRollEvent event) { /*Do nothing */} + + /** + * Indicates that the players assets have changed. + * + * @param event the received event + */ +default void receivedEvent(UpdatePlayerView event) { /*Do nothing */} } diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/notification/UpdatePlayerView.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/notification/UpdatePlayerView.java new file mode 100644 index 0000000..af3cad1 --- /dev/null +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/notification/UpdatePlayerView.java @@ -0,0 +1,13 @@ +package pp.monopoly.notification; + +public record UpdatePlayerView() implements GameEvent{ + /** + * Notifies the game event listener of this event. + * + * @param listener the game event listener + */ + @Override + public void notifyListener(GameEventListener listener) { + listener.receivedEvent(this); + } +} From 0242587a5f612a929e4b0ef18b50569155ec064a Mon Sep 17 00:00:00 2001 From: Yvonne Schmidt Date: Tue, 26 Nov 2024 19:54:02 +0100 Subject: [PATCH 19/31] added groundwork for selection listeners --- .../pp/monopoly/client/gui/TradeMenu.java | 105 ++++++++++++++++-- 1 file changed, 96 insertions(+), 9 deletions(-) diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/TradeMenu.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/TradeMenu.java index 94901b9..280edc2 100644 --- a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/TradeMenu.java +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/TradeMenu.java @@ -1,5 +1,7 @@ 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; @@ -10,11 +12,15 @@ import com.simsilica.lemur.*; 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 com.simsilica.lemur.text.DocumentModel; import pp.dialog.Dialog; import pp.monopoly.client.MonopolyApp; import pp.monopoly.notification.Sound; +import java.util.Set; + public class TradeMenu extends Dialog { private final MonopolyApp app; private final Container mainContainer; @@ -23,6 +29,7 @@ public class TradeMenu extends Dialog { private final Button cancelButton = new Button("Abbrechen"); private final Button tradeButton = new Button("Handeln"); private Container lowerLeftMenu, lowerRightMenu; + private TextField leftSelectionsField; QuadBackgroundComponent translucentWhiteBackground = new QuadBackgroundComponent(new ColorRGBA(ColorRGBA.White)); @@ -57,9 +64,6 @@ public class TradeMenu extends Dialog { ); } //TODO Logik - //TODO Ebenen prüfen und eine Ebene Hochsetzen - //TODO Farben der Label anpassen - /** * Creates a container for the header with a fixed size. @@ -73,7 +77,7 @@ public class TradeMenu extends Dialog { // Add the header label Label headerLabel = headerContainer.addChild(new Label("Handelsmenü", new ElementId("label-Bold"))); - headerLabel.setFontSize(32); // Adjust font size as needed + headerLabel.setFontSize(50); // Adjust font size as needed headerLabel.setInsets(new Insets3f(10, 10, 10, 10)); // Add padding around the label headerLabel.setBackground(new QuadBackgroundComponent(new ColorRGBA(1.0f, 1.0f, 1.0f, 0.5f))); // Optional background @@ -96,12 +100,32 @@ public class TradeMenu extends Dialog { Container middleSection = mainContent.addChild(new Container(new SpringGridLayout(Axis.Y, Axis.X))); middleSection.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.8f, 0.8f, 0.8f, 1.0f))); - TextField leftSelectionsField = middleSection.addChild(new TextField("Quellobjekte...")); + // Add combined label + Label middleLabel = middleSection.addChild(new Label("Gebäude: Währung: Sonderkarten:")); + middleLabel.setFontSize(24); // Adjust font size as needed + middleLabel.setInsets(new Insets3f(5, 5, 5, 5)); // Add padding around the label + + // Add the Quellobjekte TextField + leftSelectionsField = middleSection.addChild(new TextField("")); + leftSelectionsField.setPreferredSize(new Vector3f(600, 50, 0)); // Larger width to fit the split sections + + // Add listeners to update the TextField dynamically + addCustomSelectionListener(leftBuildingSelector, newSelection -> updateLeftSelectionsField(leftSelectionsField)); + addCustomSelectionListener(leftSpecialCardSelector, newSelection -> updateLeftSelectionsField(leftSelectionsField)); + + + + Label arrows = middleSection.addChild(new Label("⇅")); arrows.setFontSize(40); + // Add combined label + middleLabel = middleSection.addChild(new Label("Gebäude: Währung: Sonderkarten:")); + middleLabel.setFontSize(24); // Adjust font size as needed + middleLabel.setInsets(new Insets3f(5, 5, 5, 5)); // Add padding around the label + TextField rightSelectionsField = middleSection.addChild(new TextField("Zielobjekte...")); // "Bestätigen" button lowerRightMenu = new Container(); @@ -147,22 +171,29 @@ public class TradeMenu extends Dialog { // Add dropdowns column.addChild(new Label("Gebäude:")); Selector buildingSelector = column.addChild(new Selector<>(getSampleItems(),"glass")); + buildingSelector.setInsets(new Insets3f(5, 10, 5, 10)); buildingSelector.setBackground(new QuadBackgroundComponent(new ColorRGBA(ColorRGBA.Black))); column.addChild(new Label("Währung:")); - Selector currencySelector = column.addChild(new Selector<>(getSampleItems(),"glass")); - currencySelector.setBackground(new QuadBackgroundComponent(new ColorRGBA(ColorRGBA.Black))); + TextField currencyInput = column.addChild(new TextField("")); + currencyInput.setInsets(new Insets3f(5, 10, 5, 10)); + currencyInput.setBackground(new QuadBackgroundComponent(new ColorRGBA(ColorRGBA.Black))); column.addChild(new Label("Sonderkarten:")); Selector specialCardSelector = column.addChild(new Selector<>(getSampleItems(),"glass")); + specialCardSelector.setInsets(new Insets3f(5, 10, 5, 10)); specialCardSelector.setBackground(new QuadBackgroundComponent(new ColorRGBA(ColorRGBA.Black))); + // Assign selectors to corresponding fields if (isLeft) { leftBuildingSelector = buildingSelector; - leftCurrencySelector = currencySelector; leftSpecialCardSelector = specialCardSelector; + // Add listeners for left selectors to update the middle text field + addCustomSelectionListener(buildingSelector, newSelection -> updateLeftSelectionsField(leftSelectionsField)); + addCustomSelectionListener(specialCardSelector, newSelection -> updateLeftSelectionsField(leftSelectionsField)); + // "Abbrechen" button lowerLeftMenu = new Container(); cancelButton.setPreferredSize(new Vector3f(200, 60, 0)); @@ -182,7 +213,6 @@ public class TradeMenu extends Dialog { } else { rightBuildingSelector = buildingSelector; - rightCurrencySelector = currencySelector; rightSpecialCardSelector = specialCardSelector; Label spacer = column.addChild(new Label("")); // Spacer @@ -217,6 +247,26 @@ public class TradeMenu extends Dialog { app.getGuiNode().attachChild(background); } + private void updateLeftSelectionsField(TextField leftSelectionsField) { + // Get all selections from the leftBuildingSelector and leftSpecialCardSelector + String buildingSelections = leftBuildingSelector.getSelectedItem() != null + ? leftBuildingSelector.getSelectedItem() + : ""; + String specialCardSelections = leftSpecialCardSelector.getSelectedItem() != null + ? leftSpecialCardSelector.getSelectedItem() + : ""; + + // Get the direct input from the middle part of the TextField + String manualInput = leftSelectionsField.getText(); + + // Combine all parts into one formatted string + String combinedText = String.format("%-30s %-30s %-30s", buildingSelections, manualInput, specialCardSelections); + + // Update the content of the TextField + leftSelectionsField.setText(combinedText); + } + + /** * Handles the escape action for the dialog. */ @@ -234,4 +284,41 @@ public class TradeMenu extends Dialog { public void update(float delta) { // Periodic updates (if needed) can be implemented here } + + /** + * Functional interface for a selection action listener. + */ + @FunctionalInterface + private interface SelectionActionListener { + void onSelectionChanged(T selection); + } + /** + * Adds a custom action listener to the Selector. + */ + private void addCustomSelectionListener(Selector selector, SelectionActionListener listener) { + VersionedReference> selectionRef = selector.getSelectionModel().createReference(); + + app.getStateManager().attach(new BaseAppState() { + @Override + public void update(float tpf) { + if (selectionRef.update()) { + String selected = selector.getSelectedItem(); + listener.onSelectionChanged(selected); + } + } + + @Override + protected void initialize(Application app) {} + + @Override + protected void cleanup(Application app) {} + + @Override + protected void onEnable() {} + + @Override + protected void onDisable() {} + }); + } + } From 9107a08011132411f9ef68daa5141b83dd86dd80 Mon Sep 17 00:00:00 2001 From: Johannes Schmelz Date: Tue, 26 Nov 2024 20:00:50 +0100 Subject: [PATCH 20/31] dynamically set players in ChoosePatner --- .../pp/monopoly/client/gui/ChoosePartner.java | 90 +++++++++++++++++-- .../java/pp/monopoly/model/TradeHandler.java | 58 ++++++++++-- 2 files changed, 134 insertions(+), 14 deletions(-) diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/ChoosePartner.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/ChoosePartner.java index 09b5774..4d89b01 100644 --- a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/ChoosePartner.java +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/ChoosePartner.java @@ -1,5 +1,9 @@ package pp.monopoly.client.gui; +import java.util.Set; + +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; @@ -14,9 +18,12 @@ import com.simsilica.lemur.Selector; 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.game.server.Player; +import pp.monopoly.model.TradeHandler; import pp.monopoly.notification.Sound; public class ChoosePartner extends Dialog { @@ -28,6 +35,7 @@ public class ChoosePartner extends Dialog { private Container lowerLeftMenu; private Container lowerRightMenu; private Geometry background; + private TradeHandler tradeHandler; QuadBackgroundComponent translucentWhiteBackground = new QuadBackgroundComponent(new ColorRGBA(1.0f, 1.0f, 1.0f, 0.5f)); @@ -39,7 +47,7 @@ public class ChoosePartner extends Dialog { public ChoosePartner(MonopolyApp app) { super(app.getDialogManager()); this.app = app; - + tradeHandler = new TradeHandler(app.getGameLogic().getPlayerHandler().getPlayerById(app.getId())); // Background Image addBackgroundImage(); @@ -60,6 +68,8 @@ public class ChoosePartner extends Dialog { // Add buttons mainContainer.addChild(createButtonContainer()); + addSelectionActionListener(playerSelector, this::onDropdownSelectionChanged); + // Attach main container to GUI node app.getGuiNode().attachChild(mainContainer); mainContainer.setLocalTranslation( @@ -80,10 +90,12 @@ public class ChoosePartner extends Dialog { dropdownContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(ColorRGBA.Black))); VersionedList playerOptions = new VersionedList<>(); - playerOptions.add("Spieler 1"); - playerOptions.add("Spieler 2"); - playerOptions.add("Spieler 3"); - playerOptions.add("Spieler 4"); + + for (Player player : app.getGameLogic().getPlayerHandler().getPlayers()) { + if (player.getId() != app.getId()) { + playerOptions.add(player.getName() + " (ID: "+player.getId()+")"); + } + } playerSelector = new Selector<>(playerOptions, "glass"); dropdownContainer.addChild(playerSelector); @@ -126,8 +138,6 @@ public class ChoosePartner extends Dialog { confirmButton.setFontSize(30); confirmButton.addClickCommands(s -> ifTopDialog(() -> { app.getGameLogic().playSound(Sound.BUTTON); - String selectedPlayer = playerSelector.getSelectedItem(); - System.out.println("Selected player: " + selectedPlayer); close(); new TradeMenu(app).open(); })); @@ -182,6 +192,72 @@ public class ChoosePartner extends Dialog { app.getGuiNode().detachChild(background); super.close(); } + + /** + * Adds a custom action listener to the Selector. + */ + private void addSelectionActionListener(Selector selector, SelectionActionListener listener) { + VersionedReference> selectionRef = selector.getSelectionModel().createReference(); + + app.getStateManager().attach(new BaseAppState() { + @Override + public void update(float tpf) { + if (selectionRef.update()) { + String selected = selectionRef.get().toString(); + System.out.println(selected); + listener.onSelectionChanged(selected); + } + } + + @Override + protected void initialize(Application app) { + } + + @Override + protected void cleanup(Application app) { + } + + @Override + protected void onEnable() { + + } + + @Override + protected void onDisable() { + + } + }); + } + + /** + * Callback for when the dropdown selection changes. + */ + private void onDropdownSelectionChanged(String selected) { + System.out.println("Selected: " + selected); + app.getGameLogic().playSound(Sound.BUTTON); + int idStart = selected.indexOf("(ID: ") + 5; // Find start of the ID + int idEnd = selected.indexOf(")", idStart); // Find end of the ID + String idStr = selected.substring(idStart, idEnd); // Extract the ID as a string + int playerId = Integer.parseInt(idStr); // Convert the ID to an integer + + // Find the player by ID + Player selectedPlayer = app.getGameLogic().getPlayerHandler().getPlayerById(playerId); + + if (selectedPlayer != null) { + tradeHandler.setReceiver(selectedPlayer); // Set the receiver in TradeHandler + System.out.println("Receiver set to: " + selectedPlayer.getName() + " (ID: " + selectedPlayer.getId() + ")"); + } else { + System.err.println("Player with ID " + playerId + " not found."); + } + } + + /** + * Functional interface for a selection action listener. + */ + @FunctionalInterface + private interface SelectionActionListener { + void onSelectionChanged(T selection); + } } diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/model/TradeHandler.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/model/TradeHandler.java index 6f63d8e..6e6a89e 100644 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/model/TradeHandler.java +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/model/TradeHandler.java @@ -12,13 +12,13 @@ import java.util.List; public class TradeHandler { private final Player sender; - private final Player receiver; - private final int offeredAmount; - private final List offeredProperties; - private final int offeredJailCards; - private final int requestedAmount; - private final List requestedProperties; - private final int requestedJailCards; + private Player receiver; + private int offeredAmount; + private List offeredProperties; + private int offeredJailCards; + private int requestedAmount; + private List requestedProperties; + private int requestedJailCards; private Boolean status = null; /** @@ -45,6 +45,22 @@ public class TradeHandler { this.requestedJailCards = requestedJailCards; } + /** + * Constructs a TradeHandler for a single trade instance. + * + * @param sender the Player initiating the trade + * @param receiver the Player receiving the trade offer + * @param offeredAmount the amount of money offered by the sender + * @param offeredProperties the properties offered by the sender + * @param offeredJailCards the jail cards offered by the sender + * @param requestedAmount the amount of money requested from the receiver + * @param requestedProperties the properties requested from the receiver + * @param requestedJailCards the jail cards requested from the receiver + */ + public TradeHandler(Player sender) { + this.sender = sender; + } + public int getOfferedAmount() { return offeredAmount; } @@ -209,4 +225,32 @@ public class TradeHandler { } System.out.println(numCards + " jail card(s) transferred from " + from.getName() + " to " + to.getName()); } + + public void setOfferedAmount(int offeredAmount) { + this.offeredAmount = offeredAmount; + } + + public void setOfferedJailCards(int offeredJailCards) { + this.offeredJailCards = offeredJailCards; + } + + public void setOfferedProperties(List offeredProperties) { + this.offeredProperties = offeredProperties; + } + + public void setReceiver(Player receiver) { + this.receiver = receiver; + } + + public void setRequestedAmount(int requestedAmount) { + this.requestedAmount = requestedAmount; + } + + public void setRequestedJailCards(int requestedJailCards) { + this.requestedJailCards = requestedJailCards; + } + + public void setRequestedProperties(List requestedProperties) { + this.requestedProperties = requestedProperties; + } } From 29cc73e83b11828aa57383320449254f32710e74 Mon Sep 17 00:00:00 2001 From: Johannes Schmelz Date: Tue, 26 Nov 2024 20:58:57 +0100 Subject: [PATCH 21/31] automaticyally set player name as 'Spieler'+ id+1 --- .../client/src/main/java/pp/monopoly/client/gui/LobbyMenu.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 a592ac5..61dfbcd 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 @@ -39,7 +39,7 @@ public class LobbyMenu extends Dialog { private Container lowerLeftMenu; private Container lowerRightMenu; - private TextField playerInputField = new TextField("Spieler 1"); + private TextField playerInputField; private TextField startingCapital = new TextField("15000"); private String figure; @@ -47,6 +47,7 @@ public class LobbyMenu extends Dialog { super(app.getDialogManager()); this.app = app; + playerInputField = new TextField("Spieler "+app.getId()+1); // Hintergrundbild laden und hinzufügen addBackgroundImage(); From 89587a4c7899f0435ed220dc66d034cd44cb5ae0 Mon Sep 17 00:00:00 2001 From: Johannes Schmelz Date: Tue, 26 Nov 2024 21:28:41 +0100 Subject: [PATCH 22/31] set default value for drop down selection --- .../main/java/pp/monopoly/client/gui/ChoosePartner.java | 4 +++- .../src/main/java/pp/monopoly/client/gui/LobbyMenu.java | 7 +++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/ChoosePartner.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/ChoosePartner.java index 4d89b01..439740e 100644 --- a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/ChoosePartner.java +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/ChoosePartner.java @@ -68,7 +68,7 @@ public class ChoosePartner extends Dialog { // Add buttons mainContainer.addChild(createButtonContainer()); - addSelectionActionListener(playerSelector, this::onDropdownSelectionChanged); + addSelectionActionListener(playerSelector, this::onDropdownSelectionChanged); // Attach main container to GUI node app.getGuiNode().attachChild(mainContainer); @@ -104,6 +104,7 @@ public class ChoosePartner extends Dialog { dimens2.setX( dimens.getX() ); playerSelector.getPopupContainer().setPreferredSize(new Vector3f(200,200,3)); playerSelector.setLocalTranslation(0,0,5); + onDropdownSelectionChanged(playerOptions.get(0)); return dropdownContainer; } @@ -211,6 +212,7 @@ public class ChoosePartner extends Dialog { @Override protected void initialize(Application app) { + update(1); } @Override 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 61dfbcd..e817671 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 @@ -47,7 +47,7 @@ public class LobbyMenu extends Dialog { super(app.getDialogManager()); this.app = app; - playerInputField = new TextField("Spieler "+app.getId()+1); + playerInputField = new TextField("Spieler "+(app.getId()+1)); // Hintergrundbild laden und hinzufügen addBackgroundImage(); @@ -120,6 +120,8 @@ public class LobbyMenu extends Dialog { figures.add("OOP"); figures.add("Handyholster"); + + Selector figureDropdown = new Selector<>(figures, "glass"); figureDropdown.setBackground(new QuadBackgroundComponent(ColorRGBA.DarkGray)); figureDropdown.setPreferredSize(new Vector3f(100, 20, 0)); @@ -128,7 +130,8 @@ public class LobbyMenu extends Dialog { Vector3f dimens2 = figureDropdown.getPopupContainer().getPreferredSize(); dimens2.setX( dimens.getX() ); figureDropdown.getPopupContainer().setPreferredSize(new Vector3f(200,200,5)); - + figureDropdown.getSelectionModel().setSelection(0); + figure = "Laptop"; addSelectionActionListener(figureDropdown, this::onDropdownSelectionChanged); From 156e76fe0a6237b1d5cc3ed97288749b1625de5a Mon Sep 17 00:00:00 2001 From: Johannes Schmelz Date: Tue, 26 Nov 2024 21:31:21 +0100 Subject: [PATCH 23/31] cleanup --- .../pp/monopoly/client/gui/ChoosePartner.java | 5 ---- .../pp/monopoly/client/gui/LobbyMenu.java | 2 -- .../java/pp/monopoly/client/gui/Toolbar.java | 2 -- .../monopoly/game/client/ClientGameLogic.java | 3 --- .../java/pp/monopoly/game/server/Player.java | 1 - .../monopoly/game/server/PlayerHandler.java | 1 - .../monopoly/game/server/ServerGameLogic.java | 2 -- .../java/pp/monopoly/model/TradeHandler.java | 24 +++++++++---------- .../pp/monopoly/server/MonopolyServer.java | 2 -- 9 files changed, 12 insertions(+), 30 deletions(-) diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/ChoosePartner.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/ChoosePartner.java index 439740e..46acfdf 100644 --- a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/ChoosePartner.java +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/ChoosePartner.java @@ -205,7 +205,6 @@ public class ChoosePartner extends Dialog { public void update(float tpf) { if (selectionRef.update()) { String selected = selectionRef.get().toString(); - System.out.println(selected); listener.onSelectionChanged(selected); } } @@ -235,7 +234,6 @@ public class ChoosePartner extends Dialog { * Callback for when the dropdown selection changes. */ private void onDropdownSelectionChanged(String selected) { - System.out.println("Selected: " + selected); app.getGameLogic().playSound(Sound.BUTTON); int idStart = selected.indexOf("(ID: ") + 5; // Find start of the ID int idEnd = selected.indexOf(")", idStart); // Find end of the ID @@ -247,9 +245,6 @@ public class ChoosePartner extends Dialog { if (selectedPlayer != null) { tradeHandler.setReceiver(selectedPlayer); // Set the receiver in TradeHandler - System.out.println("Receiver set to: " + selectedPlayer.getName() + " (ID: " + selectedPlayer.getId() + ")"); - } else { - System.err.println("Player with ID " + playerId + " not found."); } } 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 e817671..720582f 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 @@ -241,7 +241,6 @@ public class LobbyMenu extends Dialog { public void update(float tpf) { if (selectionRef.update()) { String selected = selectionRef.get().toString(); - System.out.println(selected); listener.onSelectionChanged(selected); } } @@ -270,7 +269,6 @@ public class LobbyMenu extends Dialog { * Callback for when the dropdown selection changes. */ private void onDropdownSelectionChanged(String selected) { - System.out.println("Selected: " + selected); app.getGameLogic().playSound(Sound.BUTTON); switch (selected) { case "[0]": diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/Toolbar.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/Toolbar.java index 408dad1..81aa4ef 100644 --- a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/Toolbar.java +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/Toolbar.java @@ -223,7 +223,6 @@ public class Toolbar extends Dialog implements GameEventListener{ } } overviewContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.4657f, 0.4735f, 0.4892f, 1.0f))); - System.out.println("pdate"); } @@ -236,7 +235,6 @@ public class Toolbar extends Dialog implements GameEventListener{ icon2.setIconSize(new Vector2f(100, 100)); imageLabel.setIcon(icon1); imageLabel2.setIcon(icon2); - System.out.println("Dice images set"); } private String diceToString(int i) { diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/game/client/ClientGameLogic.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/game/client/ClientGameLogic.java index b432191..7a7ecdf 100644 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/game/client/ClientGameLogic.java +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/game/client/ClientGameLogic.java @@ -146,7 +146,6 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker { LOGGER.log(Level.ERROR, "trying to send {0} with sender==null", msg); //NON-NLS } else { clientSender.send(msg); - System.out.println("Message gesendet"); } } @@ -216,7 +215,6 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker { @Override public void received(DiceResult msg) { playSound(Sound.DICE_ROLL); - System.out.println("Message kam an"); notifyListeners(new DiceRollEvent(msg.getRollResult().get(0), msg.getRollResult().get(1))); } @@ -344,7 +342,6 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker { @Override public void received(NextPlayerTurn msg) { - System.out.println("Du bsit am zug message empfangen"); setState(new ActiveState(this)); } } 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 ac85ba2..4cb0323 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 @@ -395,7 +395,6 @@ public class Player implements FieldVisitor{ * @return the result of a dice roll (1 to 6) */ private static int rollDice() { - System.out.println("Gewuerfelt"); return random.nextInt(6) + 1; } } diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/game/server/PlayerHandler.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/game/server/PlayerHandler.java index dbb57fb..b1d4a56 100644 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/game/server/PlayerHandler.java +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/game/server/PlayerHandler.java @@ -156,7 +156,6 @@ public class PlayerHandler { public Player getPlayerById(int id) { for (Player player : players) { if (player.getId() == id) return player; - System.out.println(player.getId()); } throw new NoSuchElementException("Player mit id "+id+" existiert nicht"); } diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/game/server/ServerGameLogic.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/game/server/ServerGameLogic.java index 7e2c13e..1d1c7ce 100644 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/game/server/ServerGameLogic.java +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/game/server/ServerGameLogic.java @@ -132,7 +132,6 @@ public class ServerGameLogic implements ClientInterpreter { playerHandler.addPlayer(player); LOGGER.log(Level.DEBUG, "Player added: {0}", player.getId()); - System.out.println("Anzahl Spieler verbunden:"+ playerHandler.getPlayerCount()); return player; } @@ -221,7 +220,6 @@ public class ServerGameLogic implements ClientInterpreter { public void received(RollDice msg, int from) { Player player = playerHandler.getPlayerById(from); if (player != null) { - System.out.println("Ergebniss gesendet"); send(player, player.rollDice()); } } diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/model/TradeHandler.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/model/TradeHandler.java index 6e6a89e..fe0aa48 100644 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/model/TradeHandler.java +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/model/TradeHandler.java @@ -104,10 +104,10 @@ public class TradeHandler { */ public boolean initiateTrade() { if (!validateTrade()) { - System.out.println("Trade offer is invalid."); + return false; } - System.out.println("Trade initiated by " + sender.getName() + " to " + receiver.getName()); + return true; } @@ -138,14 +138,14 @@ public class TradeHandler { transferJailCards(sender, receiver, offeredJailCards); transferJailCards(receiver, sender, requestedJailCards); - System.out.println("Trade completed between " + sender.getName() + " and " + receiver.getName()); + } /** * Rejects the trade. */ public void rejectTrade() { - System.out.println(receiver.getName() + " rejected the trade."); + } /** @@ -156,13 +156,13 @@ public class TradeHandler { private boolean validateTrade() { // Validate sender's ability to offer money if (sender.getAccountBalance() < offeredAmount) { - System.out.println("Sender does not have enough money to offer."); + return false; } // Validate receiver's ability to fulfill the requested amount if (receiver.getAccountBalance() < requestedAmount) { - System.out.println("Receiver does not have enough money to fulfill the request."); + return false; } @@ -170,7 +170,7 @@ public class TradeHandler { if (offeredProperties != null) { for (PropertyField property : offeredProperties) { if (!sender.getProperties().contains(property)) { - System.out.println("Sender does not own property: " + property.getName()); + return false; } } @@ -178,7 +178,7 @@ public class TradeHandler { if (requestedProperties != null) { for (PropertyField property : requestedProperties) { if (!receiver.getProperties().contains(property)) { - System.out.println("Receiver does not own property: " + property.getName()); + return false; } } @@ -186,11 +186,11 @@ public class TradeHandler { // Validate jail cards if (sender.getNumJailCard() < offeredJailCards) { - System.out.println("Sender does not have enough jail cards to offer."); + return false; } if (receiver.getNumJailCard() < requestedJailCards) { - System.out.println("Receiver does not have enough jail cards to fulfill the request."); + return false; } @@ -208,7 +208,7 @@ public class TradeHandler { from.sellProperty(property); to.buyProperty(property); property.setOwner(to); - System.out.println("Property " + property.getName() + " transferred from " + from.getName() + " to " + to.getName()); + } /** @@ -223,7 +223,7 @@ public class TradeHandler { from.removeJailCard(); to.addJailCard(); } - System.out.println(numCards + " jail card(s) transferred from " + from.getName() + " to " + to.getName()); + } public void setOfferedAmount(int offeredAmount) { diff --git a/Projekte/monopoly/server/src/main/java/pp/monopoly/server/MonopolyServer.java b/Projekte/monopoly/server/src/main/java/pp/monopoly/server/MonopolyServer.java index a79f960..92557bf 100644 --- a/Projekte/monopoly/server/src/main/java/pp/monopoly/server/MonopolyServer.java +++ b/Projekte/monopoly/server/src/main/java/pp/monopoly/server/MonopolyServer.java @@ -147,7 +147,6 @@ public class MonopolyServer implements MessageListener, Connec @Override public void messageReceived(HostedConnection source, Message message) { - System.out.println("Message recieved"); LOGGER.log(Level.INFO, "message received from {0}: {1}", source.getId(), message); //NON-NLS if (message instanceof ClientMessage clientMessage) pendingMessages.add(new ReceivedMessage(clientMessage, source.getId())); @@ -157,7 +156,6 @@ public class MonopolyServer implements MessageListener, Connec public void connectionAdded(Server server, HostedConnection hostedConnection) { LOGGER.log(Level.INFO, "New connection established: {0}", hostedConnection); //NON-NLS logic.addPlayer(hostedConnection.getId()); - System.out.println("Spieler verbunden: ID = " + hostedConnection.getId()); } @Override From a6054e825eca35ab7410e4a5bd8550b2e47adbf4 Mon Sep 17 00:00:00 2001 From: Yvonne Schmidt Date: Tue, 26 Nov 2024 22:24:03 +0100 Subject: [PATCH 24/31] fixed trade display --- .../pp/monopoly/client/gui/TradeMenu.java | 116 +++++++++++++----- 1 file changed, 87 insertions(+), 29 deletions(-) diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/TradeMenu.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/TradeMenu.java index 280edc2..83c7e76 100644 --- a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/TradeMenu.java +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/TradeMenu.java @@ -30,6 +30,10 @@ public class TradeMenu extends Dialog { private final Button tradeButton = new Button("Handeln"); private Container lowerLeftMenu, lowerRightMenu; private TextField leftSelectionsField; + private TextField rightSelectionsField; + private TextField leftCurrencyInput; + private TextField rightCurrencyInput; + QuadBackgroundComponent translucentWhiteBackground = new QuadBackgroundComponent(new ColorRGBA(ColorRGBA.White)); @@ -63,7 +67,7 @@ public class TradeMenu extends Dialog { 7 ); } - //TODO Logik + /** * Creates a container for the header with a fixed size. @@ -109,24 +113,34 @@ public class TradeMenu extends Dialog { leftSelectionsField = middleSection.addChild(new TextField("")); leftSelectionsField.setPreferredSize(new Vector3f(600, 50, 0)); // Larger width to fit the split sections - // Add listeners to update the TextField dynamically - addCustomSelectionListener(leftBuildingSelector, newSelection -> updateLeftSelectionsField(leftSelectionsField)); - addCustomSelectionListener(leftSpecialCardSelector, newSelection -> updateLeftSelectionsField(leftSelectionsField)); - - - - - + addCustomSelectionListener(leftBuildingSelector, newSelection -> updateSelectionsField(leftSelectionsField, leftBuildingSelector, leftCurrencyInput, leftSpecialCardSelector)); + addCustomSelectionListener(leftSpecialCardSelector, newSelection -> updateSelectionsField(leftSelectionsField, leftBuildingSelector, leftCurrencyInput, leftSpecialCardSelector)); + // Add change listener for the currency input + monitorTextFieldChanges(leftCurrencyInput, () -> updateSelectionsField(leftSelectionsField, leftBuildingSelector, leftCurrencyInput, leftSpecialCardSelector)); Label arrows = middleSection.addChild(new Label("⇅")); arrows.setFontSize(40); + // Right Column + mainContent.addChild(createTradeColumn("Wähle Zielobjekt:", false)); + + // Add combined label middleLabel = middleSection.addChild(new Label("Gebäude: Währung: Sonderkarten:")); middleLabel.setFontSize(24); // Adjust font size as needed middleLabel.setInsets(new Insets3f(5, 5, 5, 5)); // Add padding around the label - TextField rightSelectionsField = middleSection.addChild(new TextField("Zielobjekte...")); + // Add the Zielobjekte TextField + rightSelectionsField = middleSection.addChild(new TextField("")); + rightSelectionsField.setPreferredSize(new Vector3f(600, 50, 0)); + + addCustomSelectionListener(rightBuildingSelector, newSelection -> updateSelectionsField(rightSelectionsField, rightBuildingSelector, rightCurrencyInput, rightSpecialCardSelector)); + addCustomSelectionListener(rightSpecialCardSelector, newSelection -> updateSelectionsField(rightSelectionsField, rightBuildingSelector, rightCurrencyInput, rightSpecialCardSelector)); + + // Add change listener for the currency input + monitorTextFieldChanges(rightCurrencyInput, () -> updateSelectionsField(rightSelectionsField, rightBuildingSelector, rightCurrencyInput, rightSpecialCardSelector)); + + // "Bestätigen" button lowerRightMenu = new Container(); tradeButton.setPreferredSize(new Vector3f(200, 60, 0)); @@ -144,9 +158,6 @@ public class TradeMenu extends Dialog { - // Right Column - mainContent.addChild(createTradeColumn("Wähle Zielobjekt:", false)); - Label spacer = middleSection.addChild(new Label("")); // Spacer spacer.setPreferredSize(new Vector3f(1, 50, 0)); @@ -189,10 +200,7 @@ public class TradeMenu extends Dialog { if (isLeft) { leftBuildingSelector = buildingSelector; leftSpecialCardSelector = specialCardSelector; - - // Add listeners for left selectors to update the middle text field - addCustomSelectionListener(buildingSelector, newSelection -> updateLeftSelectionsField(leftSelectionsField)); - addCustomSelectionListener(specialCardSelector, newSelection -> updateLeftSelectionsField(leftSelectionsField)); + leftCurrencyInput = currencyInput; // "Abbrechen" button lowerLeftMenu = new Container(); @@ -214,6 +222,7 @@ public class TradeMenu extends Dialog { } else { rightBuildingSelector = buildingSelector; rightSpecialCardSelector = specialCardSelector; + rightCurrencyInput = currencyInput; Label spacer = column.addChild(new Label("")); // Spacer spacer.setPreferredSize(new Vector3f(1, 130, 0)); @@ -247,26 +256,50 @@ public class TradeMenu extends Dialog { app.getGuiNode().attachChild(background); } - private void updateLeftSelectionsField(TextField leftSelectionsField) { - // Get all selections from the leftBuildingSelector and leftSpecialCardSelector - String buildingSelections = leftBuildingSelector.getSelectedItem() != null - ? leftBuildingSelector.getSelectedItem() - : ""; - String specialCardSelections = leftSpecialCardSelector.getSelectedItem() != null - ? leftSpecialCardSelector.getSelectedItem() + private String truncateText(String text, int maxLength) { + return text.length() > maxLength ? text.substring(0, maxLength) + "..." : text; + } + + private void updateSelectionsField(TextField selectionsField, Selector buildingSelector, TextField currencyInput, Selector specialCardSelector) { + // Get selections from the building selector + String buildingSelections = buildingSelector != null && buildingSelector.getSelectedItem() != null + ? buildingSelector.getSelectedItem().trim() : ""; - // Get the direct input from the middle part of the TextField - String manualInput = leftSelectionsField.getText(); + // Get text from the currency input + String currencySelections = currencyInput != null + ? currencyInput.getText().trim() + : ""; - // Combine all parts into one formatted string - String combinedText = String.format("%-30s %-30s %-30s", buildingSelections, manualInput, specialCardSelections); + // Get selections from the special card selector + String specialCardSelections = specialCardSelector != null && specialCardSelector.getSelectedItem() != null + ? specialCardSelector.getSelectedItem().trim() + : ""; + // Build the combined text without adding unnecessary spaces + StringBuilder combinedText = new StringBuilder(); + + if (!buildingSelections.isEmpty()) { + combinedText.append(buildingSelections); + } + if (!currencySelections.isEmpty()) { + if (combinedText.length() > 0) { + combinedText.append(" | "); // Add a separator if there's already text + } + combinedText.append(currencySelections); + } + if (!specialCardSelections.isEmpty()) { + if (combinedText.length() > 0) { + combinedText.append(" | "); // Add a separator if there's already text + } + combinedText.append(specialCardSelections); + } // Update the content of the TextField - leftSelectionsField.setText(combinedText); + selectionsField.setText(combinedText.toString()); } + /** * Handles the escape action for the dialog. */ @@ -321,4 +354,29 @@ public class TradeMenu extends Dialog { }); } + private void monitorTextFieldChanges(TextField textField, Runnable onChange) { + VersionedReference ref = textField.getDocumentModel().createReference(); + + app.getStateManager().attach(new BaseAppState() { + @Override + public void update(float tpf) { + if (ref.update()) { + onChange.run(); + } + } + + @Override + protected void initialize(Application app) {} + + @Override + protected void cleanup(Application app) {} + + @Override + protected void onEnable() {} + + @Override + protected void onDisable() {} + }); + } + } From bdc5f0269f061266104f7a0fba04c5022b3cbfd2 Mon Sep 17 00:00:00 2001 From: Yvonne Schmidt Date: Tue, 26 Nov 2024 22:27:55 +0100 Subject: [PATCH 25/31] fixed cancel button position --- .../src/main/java/pp/monopoly/client/gui/TradeMenu.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/TradeMenu.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/TradeMenu.java index 83c7e76..bff95e2 100644 --- a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/TradeMenu.java +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/TradeMenu.java @@ -208,12 +208,12 @@ public class TradeMenu extends Dialog { cancelButton.setFontSize(30); cancelButton.addClickCommands(s -> ifTopDialog(() -> { app.getGameLogic().playSound(Sound.BUTTON); - close(); + this.close(); })); lowerLeftMenu.addChild(cancelButton); // Position the container near the bottom-left corner - lowerLeftMenu.setLocalTranslation(new Vector3f(70, 100, 8)); // Adjust X and Y to align with the bottom-left corner + lowerLeftMenu.setLocalTranslation(new Vector3f(50, 100, 8)); // Adjust X and Y to align with the bottom-left corner app.getGuiNode().attachChild(lowerLeftMenu); Label spacer = column.addChild(new Label("")); // Spacer From 7f6011720ca7eac9004d34165881eecb83a16282 Mon Sep 17 00:00:00 2001 From: Yvonne Schmidt Date: Tue, 26 Nov 2024 22:30:13 +0100 Subject: [PATCH 26/31] lobbyMenu ready button toggles to grey --- .../client/src/main/java/pp/monopoly/client/gui/LobbyMenu.java | 1 + 1 file changed, 1 insertion(+) 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 720582f..820375d 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 @@ -163,6 +163,7 @@ public class LobbyMenu extends Dialog { readyButton.addClickCommands(s -> ifTopDialog(() -> { toggleReady(); app.getGameLogic().playSound(Sound.BUTTON); + readyButton.setBackground(new QuadBackgroundComponent(ColorRGBA.DarkGray)); })); lowerRightMenu.addChild(readyButton); From c8b69efca2f21418b77e310b760428eed54ab724 Mon Sep 17 00:00:00 2001 From: Johannes Schmelz Date: Tue, 26 Nov 2024 23:01:55 +0100 Subject: [PATCH 27/31] added correct colors in LobbyMenu --- .../pp/monopoly/client/gui/LobbyMenu.java | 21 ++++++++++++++++--- .../java/pp/monopoly/game/server/Player.java | 10 ++++----- .../pp/monopoly/game/server/PlayerColor.java | 12 +++++------ 3 files changed, 29 insertions(+), 14 deletions(-) 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 720582f..e7c33c2 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 @@ -25,6 +25,7 @@ import com.simsilica.lemur.style.ElementId; import pp.dialog.Dialog; import pp.monopoly.client.MonopolyApp; +import pp.monopoly.game.server.PlayerColor; import pp.monopoly.message.client.PlayerReady; import pp.monopoly.notification.Sound; @@ -171,7 +172,7 @@ public class LobbyMenu extends Dialog { app.getGuiNode().attachChild(lowerRightMenu); // Add a colored circle between the input field and the dropdown menu - circle = createCircle( ColorRGBA.Red); // 50 is the diameter, Red is the color + circle = createCircle(); // 50 is the diameter, Red is the color circle.setLocalTranslation(new Vector3f( (app.getCamera().getWidth()) / 2, // Center horizontally (app.getCamera().getHeight() / 2) - 90, // Adjust Y position @@ -205,19 +206,33 @@ public class LobbyMenu extends Dialog { app.getGuiNode().attachChild(background); } - private Geometry createCircle(ColorRGBA color) { + private Geometry createCircle() { Sphere sphere = new Sphere(90,90,60.0f); Geometry circleGeometry = new Geometry("Circle", sphere); // Create a material with a solid color Material material = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md"); - material.setColor("Color", color); // Set the desired color + material.setColor("Color", idToColor()); // Set the desired color circleGeometry.setMaterial(material); return circleGeometry; } + private ColorRGBA idToColor() { + switch (app.getId()+1) { + case 1: return PlayerColor.CYAN.getColor(); + case 2: return PlayerColor.YELLOW.getColor(); + case 3: return PlayerColor.RED.getColor(); + case 4: return PlayerColor.PINK.getColor(); + case 5: return PlayerColor.GREEN.getColor(); + case 6: return PlayerColor.PURPLE.getColor(); + + default: + return null; + } + } + /** * Schaltet den "Bereit"-Status um. */ 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 4cb0323..a860235 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 @@ -79,12 +79,12 @@ public class Player implements FieldVisitor{ public PlayerColor getColor() { switch ((id%6)+1) { - case 1: return PlayerColor.BLUE; - case 2: return PlayerColor.GREEN_DARK; - case 3: return PlayerColor.GREEN_LIGHT; + case 1: return PlayerColor.CYAN; + case 2: return PlayerColor.YELLOW; + case 3: return PlayerColor.RED; case 4: return PlayerColor.PINK; - case 5: return PlayerColor.RED; - case 6: return PlayerColor.YELLOW; + case 5: return PlayerColor.GREEN; + case 6: return PlayerColor.PURPLE; default: return null; diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/game/server/PlayerColor.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/game/server/PlayerColor.java index 4895b3f..3d38ed6 100644 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/game/server/PlayerColor.java +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/game/server/PlayerColor.java @@ -6,12 +6,12 @@ import com.jme3.math.ColorRGBA; * Enum representing six distinct colors for players in the game. */ public enum PlayerColor { - GREEN_LIGHT(new ColorRGBA(0 / 255f, 204 / 255f, 0 / 255f, 1)), // Hex: 00cc00 - RED(new ColorRGBA(255 / 255f, 0 / 255f, 0 / 255f, 1)), // Hex: ff0000 - BLUE(new ColorRGBA(0 / 255f, 0 / 255f, 204 / 255f, 1)), // Hex: 0000cc - PINK(new ColorRGBA(255 / 255f, 77 / 255f, 166 / 255f, 1)), // Hex: ff4da6 - GREEN_DARK(new ColorRGBA(0 / 255f, 102 / 255f, 0 / 255f, 1)), // Hex: 006600 - YELLOW(new ColorRGBA(255 / 255f, 255 / 255f, 0 / 255f, 1)); // Hex: ffff00 + CYAN(new ColorRGBA(1 / 255f, 190 / 255f, 254 / 255f, 1)), + YELLOW(new ColorRGBA(255 / 255f, 255 / 255f, 0 / 255f, 1)), + RED(new ColorRGBA(255 / 255f, 0 / 255f, 0 / 255f, 1)), + PINK(new ColorRGBA(255 / 255f, 77 / 255f, 166 / 255f, 1)), + GREEN(new ColorRGBA(0 / 255f, 204 / 255f, 0 / 255f, 1)), + PURPLE(new ColorRGBA(143 / 255f, 0 / 255f, 255 / 255f, 1)); private final ColorRGBA color; From 8d087a8e84b43948c638ea6c9e8678bc08c954d4 Mon Sep 17 00:00:00 2001 From: Yvonne Schmidt Date: Tue, 26 Nov 2024 23:15:14 +0100 Subject: [PATCH 28/31] added framework for BuildingAdminMenu --- .../client/gui/BuildingAdminMenu.java | 191 ++++++++++++++++++ .../java/pp/monopoly/client/gui/Toolbar.java | 2 +- 2 files changed, 192 insertions(+), 1 deletion(-) create mode 100644 Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/BuildingAdminMenu.java diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/BuildingAdminMenu.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/BuildingAdminMenu.java new file mode 100644 index 0000000..bade82a --- /dev/null +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/BuildingAdminMenu.java @@ -0,0 +1,191 @@ +package pp.monopoly.client.gui; + +import com.jme3.math.ColorRGBA; +import com.jme3.math.Vector3f; +import com.simsilica.lemur.*; +import com.simsilica.lemur.component.QuadBackgroundComponent; +import com.simsilica.lemur.component.SpringGridLayout; +import com.simsilica.lemur.style.ElementId; +import pp.dialog.Dialog; +import pp.monopoly.client.MonopolyApp; +import pp.monopoly.notification.Sound; + +/** + * Represents a dialog for managing properties in the Monopoly game. + * Allows users to view properties, build, demolish, and manage mortgages. + */ +public class BuildingAdminMenu extends Dialog { + private final MonopolyApp app; + private final Container mainContainer; + + // Buttons + private final Button backButton = new Button("Zurück"); + private final Button buildButton = new Button("Bauen"); + private final Button demolishButton = new Button("Abriss"); + private final Button takeMortgageButton = new Button("Hypothek aufnehmen"); + private final Button payMortgageButton = new Button("Hypothek bezahlen"); + private final Button overviewButton = new Button("Übersicht"); + + /** + * Constructs the BuildingAdminMenu dialog. + * + * @param app The Monopoly application instance. + */ + public BuildingAdminMenu(MonopolyApp app) { + super(app.getDialogManager()); + this.app = app; + + // Configure the main container + mainContainer = new Container(new SpringGridLayout(Axis.Y, Axis.X)); + mainContainer.setPreferredSize(new Vector3f(app.getCamera().getWidth(), app.getCamera().getHeight(), 0)); + mainContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(1, 1, 1, 0.7f))); // Translucent white background + + // Add the header + addHeader("Grundstücke Verwalten"); + + // Add content (Overview, Build, and Mortgage columns) + addContent(); + + // Attach main container to the GUI node + app.getGuiNode().attachChild(mainContainer); + mainContainer.setLocalTranslation(0, app.getCamera().getHeight(), 7); // Full screen + } + + /** + * Adds the header section to the main container. + * + * @param title The title text for the header. + */ + private void addHeader(String title) { + Container headerContainer = new Container(new SpringGridLayout(Axis.X, Axis.Y)); + headerContainer.setPreferredSize(new Vector3f(app.getCamera().getWidth(), 100, 0)); + Label headerLabel = headerContainer.addChild(new Label(title, new ElementId("header"))); + headerLabel.setFontSize(40); + headerLabel.setInsets(new Insets3f(10, 10, 10, 10)); + mainContainer.addChild(headerContainer); + } + + /** + * Adds the main content, organized into columns for Overview, Build, and Mortgage management. + */ + private void addContent() { + Container contentContainer = new Container(new SpringGridLayout(Axis.X, Axis.Y)); + contentContainer.setPreferredSize(new Vector3f(app.getCamera().getWidth(), app.getCamera().getHeight() - 100, 0)); + + // Overview Column + Container overviewColumn = new Container(new SpringGridLayout(Axis.Y, Axis.X)); + overviewColumn.addChild(new Label("Übersicht:")).setFontSize(24); + overviewColumn.addChild(createButtonContainer(overviewButton, "Übersicht", () -> { + app.getGameLogic().playSound(Sound.BUTTON); + handleOverview(); + })); + overviewColumn.addChild(createButtonContainer(backButton, "Zurück", () -> { + app.getGameLogic().playSound(Sound.BUTTON); + handleBack(); + })); + + // Build Column + Container buildColumn = new Container(new SpringGridLayout(Axis.Y, Axis.X)); + buildColumn.addChild(new Label("Bauen:")).setFontSize(24); + buildColumn.addChild(createButtonContainer(buildButton, "Bauen", () -> { + app.getGameLogic().playSound(Sound.BUTTON); + handleBuild(); + })); + buildColumn.addChild(createButtonContainer(demolishButton, "Abriss", () -> { + app.getGameLogic().playSound(Sound.BUTTON); + handleDemolish(); + })); + + // Mortgage Column + Container mortgageColumn = new Container(new SpringGridLayout(Axis.Y, Axis.X)); + mortgageColumn.addChild(new Label("Hypotheken:")).setFontSize(24); + mortgageColumn.addChild(createButtonContainer(takeMortgageButton, "Hypothek aufnehmen", () -> { + app.getGameLogic().playSound(Sound.BUTTON); + handleTakeMortgage(); + })); + mortgageColumn.addChild(createButtonContainer(payMortgageButton, "Hypothek bezahlen", () -> { + app.getGameLogic().playSound(Sound.BUTTON); + handlePayMortgage(); + })); + + + // Add all columns to the content container + contentContainer.addChild(overviewColumn); + contentContainer.addChild(buildColumn); + contentContainer.addChild(mortgageColumn); + + + mainContainer.addChild(contentContainer); + } + + /** + * Creates a button within a dedicated container. + * + * @param button The button to configure. + * @param label The button label. + * @param action The action to perform when the button is clicked. + * @return The container containing the button. + */ + private Container createButtonContainer(Button button, String label, Runnable action) { + Container buttonContainer = new Container(); + button.setText(label); + button.setPreferredSize(new Vector3f(200, 60, 0)); + button.setFontSize(30); // Larger font size for better visibility + button.addClickCommands(source -> ifTopDialog(action)); + buttonContainer.setPreferredSize(new Vector3f(200, 60, 0)); // Ensuring container matches button size + buttonContainer.addChild(button); + return buttonContainer; + } + + /** + * Handles the "Bauen" action. + */ + private void handleBuild() { + // Implement build logic + } + + /** + * Handles the "Abriss" action. + */ + private void handleDemolish() { + // Implement demolish logic + } + + /** + * Handles the "Hypothek aufnehmen" action. + */ + private void handleTakeMortgage() { + // Implement take mortgage logic + } + + /** + * Handles the "Hypothek bezahlen" action. + */ + private void handlePayMortgage() { + // Implement pay mortgage logic + } + + /** + * Handles the "Übersicht" action. + */ + private void handleOverview() { + // Implement overview logic + } + + /** + * Handles the "Zurück" action. + */ + private void handleBack() { + close(); + } + + @Override + public void escape() { + handleBack(); + } + + @Override + public void update(float delta) { + // Periodic updates if necessary + } +} diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/Toolbar.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/Toolbar.java index 81aa4ef..f3af9c3 100644 --- a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/Toolbar.java +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/Toolbar.java @@ -162,7 +162,7 @@ public class Toolbar extends Dialog implements GameEventListener{ propertyMenuButton.setPreferredSize(new Vector3f(150, 50, 0)); // Größe des Buttons propertyMenuButton.addClickCommands(s -> ifTopDialog(() -> { app.getGameLogic().playSound(Sound.BUTTON); - //TODO open property dialog + new BuildingAdminMenu(app).open(); })); return propertyMenuButton; } From 5b0628da157ef96124848188f40eb18ac87a22e6 Mon Sep 17 00:00:00 2001 From: Johannes Schmelz Date: Wed, 27 Nov 2024 00:10:59 +0100 Subject: [PATCH 29/31] dynamically get the fieldid for by popups --- .../monopoly/client/gui/popups/BuyCard.java | 13 ++++------ .../client/gui/popups/FoodFieldCard.java | 23 ++++++++-------- .../client/gui/popups/GateFieldCard.java | 26 +++++++++++-------- .../message/client/BuyPropertyRequest.java | 18 +------------ 4 files changed, 33 insertions(+), 47 deletions(-) diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/BuyCard.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/BuyCard.java index 565e0dc..5d9c46e 100644 --- a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/BuyCard.java +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/BuyCard.java @@ -1,10 +1,6 @@ package pp.monopoly.client.gui.popups; -import com.jme3.material.Material; -import com.jme3.material.RenderState.BlendMode; import com.jme3.math.ColorRGBA; -import com.jme3.scene.Geometry; -import com.jme3.scene.shape.Quad; import com.simsilica.lemur.Button; import com.simsilica.lemur.Container; import com.simsilica.lemur.Label; @@ -13,6 +9,7 @@ import com.simsilica.lemur.style.ElementId; import pp.dialog.Dialog; import pp.monopoly.client.MonopolyApp; import pp.monopoly.client.gui.SettingsMenu; +import pp.monopoly.message.client.BuyPropertyRequest; import pp.monopoly.model.fields.BoardManager; import pp.monopoly.model.fields.BuildingProperty; import pp.monopoly.notification.Sound; @@ -25,13 +22,13 @@ public class BuyCard extends Dialog { private final Container buyCardContainer; private final Container backgroundContainer; - private int index = 37; - + public BuyCard(MonopolyApp app) { super(app.getDialogManager()); this.app = app; - + //Generate the corresponfing field + int index = app.getGameLogic().getPlayerHandler().getPlayers().get(0).getFieldID(); BuildingProperty field = (BuildingProperty) new BoardManager().getFieldAtIndex(index); // Create the background container @@ -75,7 +72,7 @@ public class BuyCard extends Dialog { buyButton.setFontSize(32); buyButton.addClickCommands(s -> ifTopDialog( () -> { app.getGameLogic().playSound(Sound.BUTTON); - //TODO send buy property request + app.getGameLogic().send(new BuyPropertyRequest()); })); float padding = 10; // Padding around the settingsContainer for the background diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/FoodFieldCard.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/FoodFieldCard.java index 2880416..3d6d801 100644 --- a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/FoodFieldCard.java +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/FoodFieldCard.java @@ -5,6 +5,7 @@ import com.jme3.material.RenderState.BlendMode; import com.jme3.math.ColorRGBA; import com.jme3.scene.Geometry; import com.jme3.scene.shape.Quad; +import com.simsilica.lemur.Button; import com.simsilica.lemur.Container; import com.simsilica.lemur.Label; import com.simsilica.lemur.component.QuadBackgroundComponent; @@ -13,7 +14,9 @@ import com.simsilica.lemur.style.ElementId; import pp.dialog.Dialog; import pp.monopoly.client.MonopolyApp; import pp.monopoly.client.gui.SettingsMenu; +import pp.monopoly.message.client.BuyPropertyRequest; import pp.monopoly.model.fields.FoodField; +import pp.monopoly.notification.Sound; /** * FoodFieldCard erstellt die Geböudekarte vom Brandl und der Truppenküche @@ -23,13 +26,13 @@ public class FoodFieldCard extends Dialog { private final Geometry overlayBackground; private final Container foodFieldContainer; private final Container backgroundContainer; - private int index = 12; public FoodFieldCard(MonopolyApp app) { super(app.getDialogManager()); this.app = app; //Generate the corresponfing field + int index = app.getGameLogic().getPlayerHandler().getPlayers().get(0).getFieldID(); FoodField field = (FoodField) app.getGameLogic().getBoardManager().getFieldAtIndex(index); // Halbtransparentes Overlay hinzufügen @@ -68,22 +71,24 @@ public class FoodFieldCard extends Dialog { propertyValuesContainer.addChild(new Label("„Hypothek: " + field.getHypo() + " EUR", new ElementId("label-Text"))); propertyValuesContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.4657f, 0.4735f, 0.4892f, 1.0f))); - - //TODO eventuell diese Stelle löschen, da nur die BuyCard Kaufen und beenden hat - - /* // Beenden-Button Button quitButton = foodFieldContainer.addChild(new Button("Beenden", new ElementId("button"))); quitButton.setFontSize(32); + quitButton.addClickCommands(s -> ifTopDialog(() -> { + app.getGameLogic().playSound(Sound.BUTTON); + close(); + })); // Kaufen-Button Button buyButton = foodFieldContainer.addChild(new Button("Kaufen", new ElementId("button"))); buyButton.setFontSize(32); - */ + buyButton.addClickCommands(s -> ifTopDialog( () -> { + app.getGameLogic().playSound(Sound.BUTTON); + app.getGameLogic().send(new BuyPropertyRequest()); + })); float padding = 10; // Padding around the settingsContainer for the background backgroundContainer.setPreferredSize(foodFieldContainer.getPreferredSize().addLocal(padding, padding, 0)); - // Zentriere das Menü foodFieldContainer.setLocalTranslation( (app.getCamera().getWidth() - foodFieldContainer.getPreferredSize().x) / 2, @@ -127,10 +132,6 @@ public class FoodFieldCard extends Dialog { super.close(); } - public void setIndex(int index) { - this.index = index; - } - @Override public void escape() { new SettingsMenu(app).open(); diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/GateFieldCard.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/GateFieldCard.java index c1d9561..ee4d64c 100644 --- a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/GateFieldCard.java +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/GateFieldCard.java @@ -5,6 +5,7 @@ import com.jme3.material.RenderState.BlendMode; import com.jme3.math.ColorRGBA; import com.jme3.scene.Geometry; import com.jme3.scene.shape.Quad; +import com.simsilica.lemur.Button; import com.simsilica.lemur.Container; import com.simsilica.lemur.Label; import com.simsilica.lemur.component.QuadBackgroundComponent; @@ -12,7 +13,9 @@ import com.simsilica.lemur.style.ElementId; import pp.dialog.Dialog; import pp.monopoly.client.MonopolyApp; import pp.monopoly.client.gui.SettingsMenu; +import pp.monopoly.message.client.BuyPropertyRequest; import pp.monopoly.model.fields.GateField; +import pp.monopoly.notification.Sound; /** * SettingsMenu ist ein Overlay-Menü, das durch ESC aufgerufen werden kann. @@ -22,13 +25,13 @@ public class GateFieldCard extends Dialog { private final Geometry overlayBackground; private final Container gateFieldContainer; private final Container backgroundContainer; - private int index = 5; public GateFieldCard(MonopolyApp app) { super(app.getDialogManager()); this.app = app; //Generate the corresponfing field + int index = app.getGameLogic().getPlayerHandler().getPlayers().get(0).getFieldID(); GateField field = (GateField) app.getGameLogic().getBoardManager().getFieldAtIndex(index); // Halbtransparentes Overlay hinzufügen @@ -63,16 +66,21 @@ public class GateFieldCard extends Dialog { propertyValuesContainer.addChild(new Label("„Hypothek: " + field.getHypo() + " EUR", new ElementId("label-Text"))); propertyValuesContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.4657f, 0.4735f, 0.4892f, 1.0f))); - //TODO eventuell diese Stelle löschen, da nur die BuyCard Kaufen und beenden hat - - /* // Beenden-Button - Button quitButton = foodFieldContainer.addChild(new Button("Beenden", new ElementId("button"))); + Button quitButton = gateFieldContainer.addChild(new Button("Beenden", new ElementId("button"))); quitButton.setFontSize(32); + quitButton.addClickCommands(s -> ifTopDialog(() -> { + app.getGameLogic().playSound(Sound.BUTTON); + close(); + })); // Kaufen-Button - Button buyButton = foodFieldContainer.addChild(new Button("Kaufen", new ElementId("button"))); + Button buyButton = gateFieldContainer.addChild(new Button("Kaufen", new ElementId("button"))); buyButton.setFontSize(32); - */ + buyButton.addClickCommands(s -> ifTopDialog(() -> { + app.getGameLogic().playSound(Sound.BUTTON); + app.getGameLogic().send(new BuyPropertyRequest()); + close(); + })); float padding = 10; // Padding around the settingsContainer for the background backgroundContainer.setPreferredSize(gateFieldContainer.getPreferredSize().addLocal(padding, padding, 0)); @@ -121,10 +129,6 @@ public class GateFieldCard extends Dialog { super.close(); } - public void setIndex(int index) { - this.index = index; - } - @Override public void escape() { new SettingsMenu(app).open(); diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/message/client/BuyPropertyRequest.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/message/client/BuyPropertyRequest.java index 6ecd9b3..44ff29b 100644 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/message/client/BuyPropertyRequest.java +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/message/client/BuyPropertyRequest.java @@ -7,30 +7,14 @@ import com.jme3.network.serializing.Serializable; */ @Serializable public class BuyPropertyRequest extends ClientMessage{ - private int propertyId; - - /** - * Default constructor for serialization purposes. - */ - private BuyPropertyRequest() { /* empty */ } /** * Constructs a BuyPropertyRequest with the specified property ID. * * @param propertyId the ID of the property to buy */ - public BuyPropertyRequest(int propertyId) { - this.propertyId = propertyId; - } + public BuyPropertyRequest() {} - /** - * Gets the ID of the property to buy. - * - * @return the property ID - */ - public int getPropertyId() { - return propertyId; - } @Override public void accept(ClientInterpreter interpreter, int from) { From e92b305a56d876d556271beeff16fb576e3d6d89 Mon Sep 17 00:00:00 2001 From: Johannes Schmelz Date: Wed, 27 Nov 2024 00:11:07 +0100 Subject: [PATCH 30/31] cleanup --- .../main/java/pp/monopoly/client/gui/popups/EventCard.java | 5 ----- 1 file changed, 5 deletions(-) diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/EventCard.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/EventCard.java index 64a8afa..a85eaa5 100644 --- a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/EventCard.java +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/EventCard.java @@ -65,11 +65,6 @@ public class EventCard extends Dialog { quitButton.setFontSize(32); quitButton.addClickCommands(source -> close()); - - // TODO Kaufen-Button wird nicht mehr benötigt, prüfen ob weg kann - //Button buyButton = buyCardContainer.addChild(new Button("Kaufen", new ElementId("button"))); - //buyButton.setFontSize(32); - float padding = 10; // Padding around the settingsContainer for the background backgroundContainer.setPreferredSize(eventCardContainer.getPreferredSize().addLocal(padding, padding, 0)); From cb9888af7ab4209dcaef4b1c64b3ff3ff1f55650 Mon Sep 17 00:00:00 2001 From: Yvonne Schmidt Date: Wed, 27 Nov 2024 00:17:04 +0100 Subject: [PATCH 31/31] completed BuildingAdminMenu --- .../client/gui/BuildingAdminMenu.java | 190 ++++++++---------- .../monopoly/client/gui/CreateGameMenu.java | 2 +- 2 files changed, 85 insertions(+), 107 deletions(-) diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/BuildingAdminMenu.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/BuildingAdminMenu.java index bade82a..bec3e92 100644 --- a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/BuildingAdminMenu.java +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/BuildingAdminMenu.java @@ -1,7 +1,11 @@ package pp.monopoly.client.gui; +import com.jme3.material.Material; import com.jme3.math.ColorRGBA; import com.jme3.math.Vector3f; +import com.jme3.scene.Geometry; +import com.jme3.scene.shape.Quad; +import com.jme3.texture.Texture; import com.simsilica.lemur.*; import com.simsilica.lemur.component.QuadBackgroundComponent; import com.simsilica.lemur.component.SpringGridLayout; @@ -10,15 +14,10 @@ import pp.dialog.Dialog; import pp.monopoly.client.MonopolyApp; import pp.monopoly.notification.Sound; -/** - * Represents a dialog for managing properties in the Monopoly game. - * Allows users to view properties, build, demolish, and manage mortgages. - */ public class BuildingAdminMenu extends Dialog { private final MonopolyApp app; - private final Container mainContainer; - // Buttons + private final Container mainContainer; private final Button backButton = new Button("Zurück"); private final Button buildButton = new Button("Bauen"); private final Button demolishButton = new Button("Abriss"); @@ -26,156 +25,135 @@ public class BuildingAdminMenu extends Dialog { private final Button payMortgageButton = new Button("Hypothek bezahlen"); private final Button overviewButton = new Button("Übersicht"); - /** - * Constructs the BuildingAdminMenu dialog. - * - * @param app The Monopoly application instance. - */ public BuildingAdminMenu(MonopolyApp app) { super(app.getDialogManager()); this.app = app; - // Configure the main container + // Background Image + addBackgroundImage(); + + // Main container for the UI components mainContainer = new Container(new SpringGridLayout(Axis.Y, Axis.X)); - mainContainer.setPreferredSize(new Vector3f(app.getCamera().getWidth(), app.getCamera().getHeight(), 0)); + mainContainer.setPreferredSize(new Vector3f(800, 600, 0)); mainContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(1, 1, 1, 0.7f))); // Translucent white background - // Add the header - addHeader("Grundstücke Verwalten"); - - // Add content (Overview, Build, and Mortgage columns) - addContent(); - - // Attach main container to the GUI node + // Add header + mainContainer.addChild(createHeaderContainer()); + // Add content + mainContainer.addChild(createContent()); + // Attach main container to GUI node app.getGuiNode().attachChild(mainContainer); - mainContainer.setLocalTranslation(0, app.getCamera().getHeight(), 7); // Full screen + mainContainer.setLocalTranslation( + (app.getCamera().getWidth() - mainContainer.getPreferredSize().x) / 2, + (app.getCamera().getHeight() + mainContainer.getPreferredSize().y) / 2, + 7 + ); } /** - * Adds the header section to the main container. + * Creates the header container. * - * @param title The title text for the header. + * @return The header container. */ - private void addHeader(String title) { + private Container createHeaderContainer() { Container headerContainer = new Container(new SpringGridLayout(Axis.X, Axis.Y)); - headerContainer.setPreferredSize(new Vector3f(app.getCamera().getWidth(), 100, 0)); - Label headerLabel = headerContainer.addChild(new Label(title, new ElementId("header"))); - headerLabel.setFontSize(40); + headerContainer.setPreferredSize(new Vector3f(800, 100, 0)); + Label headerLabel = headerContainer.addChild(new Label("Grundstücke Verwalten", new ElementId("header"))); + headerLabel.setFontSize(45); headerLabel.setInsets(new Insets3f(10, 10, 10, 10)); - mainContainer.addChild(headerContainer); + return headerContainer; } /** - * Adds the main content, organized into columns for Overview, Build, and Mortgage management. + * Creates the main content container with columns for Overview, Build, and Mortgage. + * + * @return The content container. */ - private void addContent() { + private Container createContent() { Container contentContainer = new Container(new SpringGridLayout(Axis.X, Axis.Y)); - contentContainer.setPreferredSize(new Vector3f(app.getCamera().getWidth(), app.getCamera().getHeight() - 100, 0)); + contentContainer.setPreferredSize(new Vector3f(800, 500, 0)); // Overview Column Container overviewColumn = new Container(new SpringGridLayout(Axis.Y, Axis.X)); - overviewColumn.addChild(new Label("Übersicht:")).setFontSize(24); - overviewColumn.addChild(createButtonContainer(overviewButton, "Übersicht", () -> { + overviewColumn.addChild(new Label("Übersicht:")).setFontSize(30); + + + overviewButton.setPreferredSize(new Vector3f(200, 50, 0)); + overviewButton.addClickCommands(s -> ifTopDialog(() -> { app.getGameLogic().playSound(Sound.BUTTON); - handleOverview(); })); - overviewColumn.addChild(createButtonContainer(backButton, "Zurück", () -> { + overviewColumn.addChild(overviewButton); + + // Back Button + backButton.setPreferredSize(new Vector3f(200, 50, 0)); + backButton.addClickCommands(s -> ifTopDialog(() -> { app.getGameLogic().playSound(Sound.BUTTON); - handleBack(); + this.close(); })); + overviewColumn.addChild(backButton); + + contentContainer.addChild(overviewColumn); + // Build Column Container buildColumn = new Container(new SpringGridLayout(Axis.Y, Axis.X)); - buildColumn.addChild(new Label("Bauen:")).setFontSize(24); - buildColumn.addChild(createButtonContainer(buildButton, "Bauen", () -> { + buildColumn.addChild(new Label("Bauen:")).setFontSize(30); + + buildButton.setPreferredSize(new Vector3f(200, 50, 0)); + buildButton.addClickCommands(s -> ifTopDialog(() -> { app.getGameLogic().playSound(Sound.BUTTON); - handleBuild(); })); - buildColumn.addChild(createButtonContainer(demolishButton, "Abriss", () -> { + buildColumn.addChild(buildButton); + + demolishButton.setPreferredSize(new Vector3f(200, 50, 0)); + demolishButton.addClickCommands(s -> ifTopDialog(() -> { app.getGameLogic().playSound(Sound.BUTTON); - handleDemolish(); })); + buildColumn.addChild(demolishButton); + + contentContainer.addChild(buildColumn); + // Mortgage Column Container mortgageColumn = new Container(new SpringGridLayout(Axis.Y, Axis.X)); - mortgageColumn.addChild(new Label("Hypotheken:")).setFontSize(24); - mortgageColumn.addChild(createButtonContainer(takeMortgageButton, "Hypothek aufnehmen", () -> { - app.getGameLogic().playSound(Sound.BUTTON); - handleTakeMortgage(); - })); - mortgageColumn.addChild(createButtonContainer(payMortgageButton, "Hypothek bezahlen", () -> { - app.getGameLogic().playSound(Sound.BUTTON); - handlePayMortgage(); - })); + mortgageColumn.addChild(new Label("Hypotheken:")).setFontSize(30); + takeMortgageButton.setPreferredSize(new Vector3f(200, 50, 0)); + takeMortgageButton.addClickCommands(s -> ifTopDialog(() -> { + app.getGameLogic().playSound(Sound.BUTTON); + })); + mortgageColumn.addChild(takeMortgageButton); + + payMortgageButton.setPreferredSize(new Vector3f(200, 50, 0)); + payMortgageButton.addClickCommands(s -> ifTopDialog(() -> { + app.getGameLogic().playSound(Sound.BUTTON); + })); + mortgageColumn.addChild(payMortgageButton); - // Add all columns to the content container - contentContainer.addChild(overviewColumn); - contentContainer.addChild(buildColumn); contentContainer.addChild(mortgageColumn); - - mainContainer.addChild(contentContainer); + return contentContainer; } /** - * Creates a button within a dedicated container. - * - * @param button The button to configure. - * @param label The button label. - * @param action The action to perform when the button is clicked. - * @return The container containing the button. + * Adds a background image to the dialog. */ - private Container createButtonContainer(Button button, String label, Runnable action) { - Container buttonContainer = new Container(); - button.setText(label); - button.setPreferredSize(new Vector3f(200, 60, 0)); - button.setFontSize(30); // Larger font size for better visibility - button.addClickCommands(source -> ifTopDialog(action)); - buttonContainer.setPreferredSize(new Vector3f(200, 60, 0)); // Ensuring container matches button size - buttonContainer.addChild(button); - return buttonContainer; - } - - /** - * Handles the "Bauen" action. - */ - private void handleBuild() { - // Implement build logic - } - - /** - * Handles the "Abriss" action. - */ - private void handleDemolish() { - // Implement demolish logic - } - - /** - * Handles the "Hypothek aufnehmen" action. - */ - private void handleTakeMortgage() { - // Implement take mortgage logic - } - - /** - * Handles the "Hypothek bezahlen" action. - */ - private void handlePayMortgage() { - // Implement pay mortgage logic - } - - /** - * Handles the "Übersicht" action. - */ - private void handleOverview() { - // Implement overview logic + 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); + Material backgroundMaterial = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md"); + backgroundMaterial.setTexture("ColorMap", backgroundImage); + background.setMaterial(backgroundMaterial); + background.setLocalTranslation(0, 0, 6); // Position behind other GUI elements + app.getGuiNode().attachChild(background); } /** * Handles the "Zurück" action. */ private void handleBack() { + app.getGameLogic().playSound(Sound.BUTTON); close(); } @@ -188,4 +166,4 @@ public class BuildingAdminMenu extends Dialog { public void update(float delta) { // Periodic updates if necessary } -} +} \ No newline at end of file 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 82cf38a..1b08622 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 @@ -66,7 +66,7 @@ public class CreateGameMenu extends Dialog { final MonopolyApp app = network.getApp(); - int screenWidth = app.getContext().getSettings().getWidth(); + int screenWidth = app.getContext().getSettings().getWidth(); int screenHeight = app.getContext().getSettings().getHeight(); // Set up the background image