From 7ace959f1f95b862adf24340dea71c6c3fc0554e Mon Sep 17 00:00:00 2001 From: Johannes Schmelz Date: Mon, 2 Dec 2024 02:48:06 +0100 Subject: [PATCH 1/5] sellHouse --- .../monopoly/client/gui/popups/BuyHouse.java | 5 ++++ .../monopoly/client/gui/popups/SellHouse.java | 23 +++++++++++++++---- .../monopoly/game/server/ServerGameLogic.java | 13 +++++++---- 3 files changed, 32 insertions(+), 9 deletions(-) diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/BuyHouse.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/BuyHouse.java index d2b3c4e..81c1c73 100644 --- a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/BuyHouse.java +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/BuyHouse.java @@ -147,6 +147,11 @@ public class BuyHouse extends Dialog { selectionDisplay.setPreferredSize(new Vector3f(300, 30, 0)); dropdownContainer.addChild(selectionDisplay); // Add it to the dropdown container + // Set initial selection + if (!propertyOptions.isEmpty()) { + onDropdownSelectionChanged(propertySelector); + } + return dropdownContainer; } /** diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/SellHouse.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/SellHouse.java index 08d78c5..3b1fcf1 100644 --- a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/SellHouse.java +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/SellHouse.java @@ -21,7 +21,7 @@ import pp.dialog.Dialog; import pp.monopoly.client.MonopolyApp; import pp.monopoly.client.gui.SettingsMenu; import pp.monopoly.game.server.Player; -import pp.monopoly.message.client.BuyPropertyResponse; +import pp.monopoly.message.client.AlterProperty; import pp.monopoly.model.fields.BoardManager; import pp.monopoly.model.fields.BuildingProperty; import pp.monopoly.notification.Sound; @@ -73,7 +73,7 @@ public class SellHouse extends Dialog { Container downContainer = sellhouseContainer.addChild(new Container()); // Text, der auf der Karte steht - upContainer.addChild(new Label("„Grundstück wählen:", new ElementId("label-Text"))); //TODO hier überall die entsprechenden Variablen einfügen + upContainer.addChild(new Label("„Grundstück wählen:", new ElementId("label-Text"))); upContainer.addChild(new Label("", new ElementId("label-Text")));// Leerzeile upContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.4657f, 0.4735f, 0.4892f, 1.0f))); @@ -99,9 +99,16 @@ public class SellHouse extends Dialog { confirmButton.setFontSize(32); confirmButton.addClickCommands(s -> ifTopDialog( () -> { app.getGameLogic().playSound(Sound.BUTTON); - // Send the "alter building" message to the server - //app.getGameLogic().sendMessage(new AlterBuildingMessage(selected.getId(), false)); TODO Message an Server - + AlterProperty msg = new AlterProperty("SellHouse"); + for (String string : selectedProperties) { + System.out.println(string); + } + msg.setProperties(selectedProperties.stream().map(p -> app.getGameLogic().getBoardManager().getFieldByName(p).getId()).map(p -> (Integer) p).collect(Collectors.toSet())); + for (Integer integer : msg.getProperties()) { + System.out.println("ID des verkaufs: "+integer); + } + app.getGameLogic().send(msg); + close(); })); // Zentriere das Popup @@ -149,6 +156,11 @@ public class SellHouse extends Dialog { selectionDisplay = new TextField(""); // Create TextField for displaying selections selectionDisplay.setPreferredSize(new Vector3f(300, 30, 0)); dropdownContainer.addChild(selectionDisplay); // Add it to the dropdown container + + // Set initial selection + if (!propertyOptions.isEmpty()) { + onDropdownSelectionChanged(propertySelector); + } return dropdownContainer; } @@ -164,6 +176,7 @@ public class SellHouse extends Dialog { return boardManager.getPropertyFields(self.getProperties()).stream() .filter(property -> property instanceof BuildingProperty) .map(property -> (BuildingProperty) property) + .filter(p -> app.getGameLogic().getBoardManager().canSell(p)) .collect(Collectors.toList()); } 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 87b69af..a4fcf31 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 @@ -382,27 +382,32 @@ public class ServerGameLogic implements ClientInterpreter { public void received(AlterProperty msg, int from) { Player sender = playerHandler.getPlayerById(from); + Set properties = new HashSet<>(); + for (Integer integer : msg.getProperties()) { + properties.add( (PropertyField)boardManager.getFieldAtIndex(integer)); + } + if (msg.getKeyword().equals("TakeMortage")) { - for (PropertyField field : sender.getPropertyFields()) { + for (PropertyField field : properties) { field.setMortgaged(true); sender.earnMoney(field.getHypo()); } } else if (msg.getKeyword().equals("RepayMortage")) { - for (PropertyField field : sender.getPropertyFields()) { + for (PropertyField field : properties) { if(sender.getAccountBalance() >= field.getHypo()) { field.setMortgaged(false); sender.pay(field.getHypo()); } } } else if(msg.getKeyword().equals("BuyHouse")) { - for (BuildingProperty field : sender.getPropertyFields().stream().filter(p -> p instanceof BuildingProperty).map(p -> (BuildingProperty) p).collect(Collectors.toList())) { + for (BuildingProperty field : properties.stream().map(p -> (BuildingProperty) p).collect(Collectors.toList())) { if (boardManager.canBuild(field) && sender.getAccountBalance() >= field.getHousePrice()) { field.build(); sender.pay(field.getHousePrice()); } } } else if(msg.getKeyword().equals("SellHouse")) { - for (BuildingProperty field : sender.getPropertyFields().stream().filter(p -> p instanceof BuildingProperty).map(p -> (BuildingProperty) p).collect(Collectors.toList())) { + for (BuildingProperty field : properties.stream().map(p -> (BuildingProperty) p).collect(Collectors.toList())) { if (boardManager.canSell(field)) { field.sell(); sender.earnMoney(field.getHousePrice()); From 560bedc80b052d4e7c43f859e46a084514e88581 Mon Sep 17 00:00:00 2001 From: Johannes Schmelz Date: Mon, 2 Dec 2024 03:00:22 +0100 Subject: [PATCH 2/5] mortage --- .../client/gui/popups/RepayMortage.java | 33 +++++++++++-------- .../client/gui/popups/TakeMortage.java | 33 ++++++++++++------- .../model/fields/BuildingProperty.java | 2 +- 3 files changed, 42 insertions(+), 26 deletions(-) diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/RepayMortage.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/RepayMortage.java index bc03f00..ada03c0 100644 --- a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/RepayMortage.java +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/RepayMortage.java @@ -6,7 +6,6 @@ import com.simsilica.lemur.Axis; import com.simsilica.lemur.Button; import com.simsilica.lemur.Container; import com.simsilica.lemur.Label; -import com.simsilica.lemur.ListBox; import com.simsilica.lemur.Selector; import com.simsilica.lemur.TextField; import com.simsilica.lemur.component.QuadBackgroundComponent; @@ -18,8 +17,9 @@ import pp.dialog.Dialog; import pp.monopoly.client.MonopolyApp; import pp.monopoly.client.gui.SettingsMenu; import pp.monopoly.game.server.Player; +import pp.monopoly.message.client.AlterProperty; import pp.monopoly.model.fields.BoardManager; -import pp.monopoly.model.fields.BuildingProperty; +import pp.monopoly.model.fields.PropertyField; import pp.monopoly.notification.Sound; import java.util.HashSet; @@ -69,7 +69,7 @@ public class RepayMortage extends Dialog { Container downContainer = repayMortageContainer.addChild(new Container()); // Text, der auf der Karte steht - upContainer.addChild(new Label("„Grundstück wählen:", new ElementId("label-Text"))); //TODO hier überall die entsprechenden Variablen einfügen + upContainer.addChild(new Label("„Grundstück wählen:", new ElementId("label-Text"))); upContainer.addChild(new Label("", new ElementId("label-Text")));// Leerzeile upContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.4657f, 0.4735f, 0.4892f, 1.0f))); @@ -95,9 +95,10 @@ public class RepayMortage extends Dialog { confirmButton.setFontSize(32); confirmButton.addClickCommands(s -> ifTopDialog( () -> { app.getGameLogic().playSound(Sound.BUTTON); - // Send the "alter building" message to the server - //app.getGameLogic().sendMessage(new AlterBuildingMessage(selected.getId(), false)); TODO Message an Server - + AlterProperty msg = new AlterProperty("RepayMortage"); + msg.setProperties(selectedProperties.stream().map(p -> app.getGameLogic().getBoardManager().getFieldByName(p).getId()).map(p -> (Integer) p).collect(Collectors.toSet())); + app.getGameLogic().send(msg); + close(); })); // Zentriere das Popup @@ -128,10 +129,10 @@ public class RepayMortage extends Dialog { dropdownContainer.setBackground(new QuadBackgroundComponent(ColorRGBA.Orange)); VersionedList propertyOptions = new VersionedList<>(); - List playerProperties = getPlayerProperties(); + List playerProperties = getPlayerProperties(); // Populate the dropdown with property names - for (BuildingProperty property : playerProperties) { + for (PropertyField property : playerProperties) { propertyOptions.add(property.getName()); } @@ -146,20 +147,26 @@ public class RepayMortage extends Dialog { selectionDisplay.setPreferredSize(new Vector3f(300, 30, 0)); dropdownContainer.addChild(selectionDisplay); // Add it to the dropdown container + // Set initial selection + if (!propertyOptions.isEmpty()) { + onDropdownSelectionChanged(propertySelector); + } + return dropdownContainer; } /** * Retrieves the list of properties owned by the current player. * - * @return List of BuildingProperty objects owned by the player. + * @return List of PropertyField objects owned by the player. */ - private List getPlayerProperties() { + private List getPlayerProperties() { Player self = app.getGameLogic().getPlayerHandler().getPlayerById(app.getId()); BoardManager boardManager = app.getGameLogic().getBoardManager(); return boardManager.getPropertyFields(self.getProperties()).stream() - .filter(property -> property instanceof BuildingProperty) - .map(property -> (BuildingProperty) property) + .filter(property -> property instanceof PropertyField) + .map(property -> (PropertyField) property) + .filter(p -> p.isMortgaged()) .collect(Collectors.toList()); } @@ -184,7 +191,7 @@ public class RepayMortage extends Dialog { int cost = 0; for (String s : selectedProperties) { - cost += ((BuildingProperty) app.getGameLogic().getBoardManager().getFieldByName(s)).getHousePrice(); + cost += ((PropertyField) app.getGameLogic().getBoardManager().getFieldByName(s)).getHypo(); } String display = String.join(" | ", selectedProperties); diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/TakeMortage.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/TakeMortage.java index 3211df9..c53999b 100644 --- a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/TakeMortage.java +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/TakeMortage.java @@ -6,7 +6,6 @@ import com.simsilica.lemur.Axis; import com.simsilica.lemur.Button; import com.simsilica.lemur.Container; import com.simsilica.lemur.Label; -import com.simsilica.lemur.ListBox; import com.simsilica.lemur.Selector; import com.simsilica.lemur.TextField; import com.simsilica.lemur.component.QuadBackgroundComponent; @@ -18,8 +17,10 @@ import pp.dialog.Dialog; import pp.monopoly.client.MonopolyApp; import pp.monopoly.client.gui.SettingsMenu; import pp.monopoly.game.server.Player; +import pp.monopoly.message.client.AlterProperty; import pp.monopoly.model.fields.BoardManager; -import pp.monopoly.model.fields.BuildingProperty; +import pp.monopoly.model.fields.PropertyField; +import pp.monopoly.model.fields.PropertyField; import pp.monopoly.notification.Sound; import java.util.HashSet; @@ -69,7 +70,7 @@ public class TakeMortage extends Dialog { Container downContainer = takeMortageContainer.addChild(new Container()); // Text, der auf der Karte steht - upContainer.addChild(new Label("„Grundstück wählen:", new ElementId("label-Text"))); //TODO hier überall die entsprechenden Variablen einfügen + upContainer.addChild(new Label("„Grundstück wählen:", new ElementId("label-Text"))); upContainer.addChild(new Label("", new ElementId("label-Text")));// Leerzeile upContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.4657f, 0.4735f, 0.4892f, 1.0f))); @@ -95,8 +96,10 @@ public class TakeMortage extends Dialog { confirmButton.setFontSize(32); confirmButton.addClickCommands(s -> ifTopDialog( () -> { app.getGameLogic().playSound(Sound.BUTTON); - // Send the "alter building" message to the server - //app.getGameLogic().sendMessage(new AlterBuildingMessage(selected.getId(), false)); TODO Message an Server + AlterProperty msg = new AlterProperty("TakeMortage"); + msg.setProperties(selectedProperties.stream().map(p -> app.getGameLogic().getBoardManager().getFieldByName(p).getId()).map(p -> (Integer) p).collect(Collectors.toSet())); + app.getGameLogic().send(msg); + close(); })); // Zentriere das Popup @@ -127,10 +130,10 @@ public class TakeMortage extends Dialog { dropdownContainer.setBackground(new QuadBackgroundComponent(ColorRGBA.Orange)); VersionedList propertyOptions = new VersionedList<>(); - List playerProperties = getPlayerProperties(); + List playerProperties = getPlayerProperties(); // Populate the dropdown with property names - for (BuildingProperty property : playerProperties) { + for (PropertyField property : playerProperties) { propertyOptions.add(property.getName()); } @@ -145,20 +148,26 @@ public class TakeMortage extends Dialog { selectionDisplay.setPreferredSize(new Vector3f(300, 30, 0)); dropdownContainer.addChild(selectionDisplay); // Add it to the dropdown container + // Set initial selection + if (!propertyOptions.isEmpty()) { + onDropdownSelectionChanged(propertySelector); + } + return dropdownContainer; } /** * Retrieves the list of properties owned by the current player. * - * @return List of BuildingProperty objects owned by the player. + * @return List of PropertyField objects owned by the player. */ - private List getPlayerProperties() { + private List getPlayerProperties() { Player self = app.getGameLogic().getPlayerHandler().getPlayerById(app.getId()); BoardManager boardManager = app.getGameLogic().getBoardManager(); return boardManager.getPropertyFields(self.getProperties()).stream() - .filter(property -> property instanceof BuildingProperty) - .map(property -> (BuildingProperty) property) + .filter(property -> property instanceof PropertyField) + .map(property -> (PropertyField) property) + .filter(p -> !p.isMortgaged()) .collect(Collectors.toList()); } @@ -183,7 +192,7 @@ public class TakeMortage extends Dialog { int cost = 0; for (String s : selectedProperties) { - cost += ((BuildingProperty) app.getGameLogic().getBoardManager().getFieldByName(s)).getHousePrice(); + cost += ((PropertyField) app.getGameLogic().getBoardManager().getFieldByName(s)).getHypo(); } String display = String.join(" | ", selectedProperties); diff --git a/Projekte/monopoly/model/src/main/java/pp/monopoly/model/fields/BuildingProperty.java b/Projekte/monopoly/model/src/main/java/pp/monopoly/model/fields/BuildingProperty.java index 3fc9839..f289e14 100644 --- a/Projekte/monopoly/model/src/main/java/pp/monopoly/model/fields/BuildingProperty.java +++ b/Projekte/monopoly/model/src/main/java/pp/monopoly/model/fields/BuildingProperty.java @@ -10,7 +10,7 @@ import pp.monopoly.game.server.Player; @Serializable public class BuildingProperty extends PropertyField { - private int houses; + private int houses = 2; private final int housePrice; private final FieldColor color; private final int rentFactor1 = 5; From 4743a6882c62537f65ae35407258ba871d0f3750 Mon Sep 17 00:00:00 2001 From: Johannes Schmelz Date: Mon, 2 Dec 2024 03:02:05 +0100 Subject: [PATCH 3/5] fixed testing env --- .../src/main/java/pp/monopoly/client/gui/SettingsMenu.java | 2 ++ .../src/main/java/pp/monopoly/game/server/ServerGameLogic.java | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/SettingsMenu.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/SettingsMenu.java index f0faeb5..5b080aa 100644 --- a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/SettingsMenu.java +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/SettingsMenu.java @@ -18,6 +18,7 @@ import static pp.monopoly.Resources.lookup; import pp.monopoly.client.GameMusic; import pp.monopoly.client.GameSound; import pp.monopoly.client.MonopolyApp; +import pp.monopoly.message.client.NotificationAnswer; import pp.dialog.Dialog; import pp.dialog.StateCheckboxModel; import pp.monopoly.notification.Sound; @@ -60,6 +61,7 @@ public class SettingsMenu extends Dialog { addChild(new Button("Zurück zum Spiel", new ElementId("button"))).addClickCommands(s -> ifTopDialog(() -> { this.close(); // Close the StartMenu dialog + app.getGameLogic().send(new NotificationAnswer("hack")); app.getGameLogic().playSound(Sound.BUTTON); })); addChild(new Button("Beenden", new ElementId("button"))).addClickCommands(s -> ifTopDialog(() -> { 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 a4fcf31..aa95bee 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 @@ -425,11 +425,11 @@ public class ServerGameLogic implements ClientInterpreter { } else if (msg.getA().equals("PayJail")) { playerHandler.getPlayerById(from).payBail(); } else if(msg.getA().equals("hack")) { - System.out.println("HAck ausgeführt"); for (BuildingProperty bp : boardManager.getPropertyFields( List.of(1,3)).stream().filter(p -> p instanceof BuildingProperty).map(p -> (BuildingProperty) p).collect(Collectors.toList())) { bp.setOwner(playerHandler.getPlayerById(0)); playerHandler.getPlayerById(0).addProperty(bp.getId()); } + playerHandler.getPlayerAtIndex(0).earnMoney(20000); } updateAllPlayers(); From 13754c843a5864927ac1e6fec6f7b1fd74fc4e38 Mon Sep 17 00:00:00 2001 From: Johannes Schmelz Date: Mon, 2 Dec 2024 03:03:42 +0100 Subject: [PATCH 4/5] clean up --- .../src/main/java/pp/monopoly/client/gui/SettingsMenu.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/SettingsMenu.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/SettingsMenu.java index 5b080aa..9d7f710 100644 --- a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/SettingsMenu.java +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/SettingsMenu.java @@ -14,11 +14,9 @@ import com.simsilica.lemur.Checkbox; import com.simsilica.lemur.Label; import com.simsilica.lemur.style.ElementId; -import static pp.monopoly.Resources.lookup; import pp.monopoly.client.GameMusic; import pp.monopoly.client.GameSound; import pp.monopoly.client.MonopolyApp; -import pp.monopoly.message.client.NotificationAnswer; import pp.dialog.Dialog; import pp.dialog.StateCheckboxModel; import pp.monopoly.notification.Sound; @@ -61,7 +59,6 @@ public class SettingsMenu extends Dialog { addChild(new Button("Zurück zum Spiel", new ElementId("button"))).addClickCommands(s -> ifTopDialog(() -> { this.close(); // Close the StartMenu dialog - app.getGameLogic().send(new NotificationAnswer("hack")); app.getGameLogic().playSound(Sound.BUTTON); })); addChild(new Button("Beenden", new ElementId("button"))).addClickCommands(s -> ifTopDialog(() -> { From bcf4956d2df746b5b28055ad7c984d28e4a778e6 Mon Sep 17 00:00:00 2001 From: Johannes Schmelz Date: Mon, 2 Dec 2024 03:16:50 +0100 Subject: [PATCH 5/5] TradeReplay popup --- .../main/java/pp/monopoly/client/gui/TestWorld.java | 9 ++++++++- .../pp/monopoly/client/gui/popups/AcceptTrade.java | 11 ++++++++--- .../pp/monopoly/client/gui/popups/RejectTrade.java | 11 ++++++++--- .../java/pp/monopoly/game/client/ClientGameLogic.java | 2 ++ 4 files changed, 26 insertions(+), 7 deletions(-) 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 f754eeb..8aff687 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 @@ -12,6 +12,7 @@ import com.jme3.renderer.ViewPort; import com.jme3.scene.control.AbstractControl; import pp.monopoly.client.MonopolyApp; +import pp.monopoly.client.gui.popups.AcceptTrade; import pp.monopoly.client.gui.popups.BuildingPropertyCard; import pp.monopoly.client.gui.popups.ConfirmTrade; import pp.monopoly.client.gui.popups.EventCardPopup; @@ -21,12 +22,14 @@ import pp.monopoly.client.gui.popups.Gulag; import pp.monopoly.client.gui.popups.GulagInfo; import pp.monopoly.client.gui.popups.LooserPopUp; import pp.monopoly.client.gui.popups.NoMoneyWarning; +import pp.monopoly.client.gui.popups.RejectTrade; import pp.monopoly.client.gui.popups.Rent; import pp.monopoly.client.gui.popups.TimeOut; import pp.monopoly.client.gui.popups.WinnerPopUp; import pp.monopoly.game.server.Player; import pp.monopoly.game.server.PlayerHandler; import pp.monopoly.message.server.NotificationMessage; +import pp.monopoly.message.server.TradeReply; import pp.monopoly.model.fields.BuildingProperty; import pp.monopoly.model.fields.FoodField; import pp.monopoly.model.fields.GateField; @@ -385,7 +388,11 @@ public class TestWorld implements GameEventListener { new GulagInfo(app, 1).open(); } else if (event.msg().equals("jailpay")) { new GulagInfo(app, 3).open(); - } + } else if (event.msg().equals("tradepos")) { + new AcceptTrade(app, (TradeReply) event.message()).open(); + } else if (event.msg().equals("tradeneg")) { + new RejectTrade(app, (TradeReply) event.message()).open(); + } } @Override diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/AcceptTrade.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/AcceptTrade.java index fdbd22d..f2fb28f 100644 --- a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/AcceptTrade.java +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/AcceptTrade.java @@ -13,6 +13,8 @@ import com.simsilica.lemur.component.QuadBackgroundComponent; import com.simsilica.lemur.style.ElementId; import pp.dialog.Dialog; import pp.monopoly.client.MonopolyApp; +import pp.monopoly.message.server.TradeReply; +import pp.monopoly.notification.Sound; /** * Bankrupt is a Warning-Popup which appears when the balance is negative at the end of a player´s turn @@ -25,7 +27,7 @@ public class AcceptTrade extends Dialog { - public AcceptTrade(MonopolyApp app) { + public AcceptTrade(MonopolyApp app, TradeReply msg) { super(app.getDialogManager()); this.app = app; @@ -55,7 +57,7 @@ public class AcceptTrade extends Dialog { // Text, der im Popup steht Container textContainer = noMoneyWarningContainer.addChild(new Container()); - textContainer.addChild(new Label("Du hast Spieler XXX einen Handel vorgeschlagen", new ElementId("label-Text"))); + textContainer.addChild(new Label("Du hast Spieler"+ msg.getTradeHandler().getReceiver().getName() + "einen Handel vorgeschlagen", new ElementId("label-Text"))); textContainer.addChild(new Label("", new ElementId("label-Text"))); textContainer.addChild(new Label("Der Handel wurde angenommen", new ElementId("label-Text"))); textContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.4657f, 0.4735f, 0.4892f, 1.0f))); @@ -66,7 +68,10 @@ public class AcceptTrade extends Dialog { // Beenden-Button Button quitButton = noMoneyWarningContainer.addChild(new Button("Bestätigen", new ElementId("button"))); quitButton.setFontSize(32); - quitButton.addClickCommands(source -> close()); + quitButton.addClickCommands(source -> ifTopDialog(() -> { + app.getGameLogic().playSound(Sound.BUTTON); + close(); + })); // Zentriere das Popup diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/RejectTrade.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/RejectTrade.java index 2caa095..4cd9c23 100644 --- a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/RejectTrade.java +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/gui/popups/RejectTrade.java @@ -13,6 +13,8 @@ import com.simsilica.lemur.component.QuadBackgroundComponent; import com.simsilica.lemur.style.ElementId; import pp.dialog.Dialog; import pp.monopoly.client.MonopolyApp; +import pp.monopoly.message.server.TradeReply; +import pp.monopoly.notification.Sound; /** * Bankrupt is a Warning-Popup which appears when the balance is negative at the end of a player´s turn @@ -25,7 +27,7 @@ public class RejectTrade extends Dialog { - public RejectTrade(MonopolyApp app) { + public RejectTrade(MonopolyApp app, TradeReply msg) { super(app.getDialogManager()); this.app = app; @@ -55,7 +57,7 @@ public class RejectTrade extends Dialog { // Text, der im Popup steht Container textContainer = noMoneyWarningContainer.addChild(new Container()); - textContainer.addChild(new Label("Du hast Spieler XXX einen Handel vorgeschlagen", new ElementId("label-Text"))); + textContainer.addChild(new Label("Du hast Spieler"+ msg.getTradeHandler().getReceiver().getName() + "einen Handel vorgeschlagen", new ElementId("label-Text"))); textContainer.addChild(new Label("", new ElementId("label-Text"))); textContainer.addChild(new Label("Der Handel wurde abgelehnt", new ElementId("label-Text"))); textContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.4657f, 0.4735f, 0.4892f, 1.0f))); @@ -66,7 +68,10 @@ public class RejectTrade extends Dialog { // Beenden-Button Button quitButton = noMoneyWarningContainer.addChild(new Button("Bestätigen", new ElementId("button"))); quitButton.setFontSize(32); - quitButton.addClickCommands(source -> close()); + quitButton.addClickCommands(source -> ifTopDialog(() -> { + app.getGameLogic().playSound(Sound.BUTTON); + close(); + })); // Zentriere das Popup 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 fb99bca..32725de 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 @@ -307,8 +307,10 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker { public void received(TradeReply msg) { if (msg.isAccepted()) { playSound(Sound.TRADE_ACCEPTED); + notifyListeners(new PopUpEvent("tradepos", msg)); } else { playSound(Sound.TRADE_REJECTED); + notifyListeners(new PopUpEvent("tradeneg", msg)); } }