From 5b0628da157ef96124848188f40eb18ac87a22e6 Mon Sep 17 00:00:00 2001 From: Johannes Schmelz Date: Wed, 27 Nov 2024 00:10:59 +0100 Subject: [PATCH] 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) {