mirror of
https://athene2.informatik.unibw-muenchen.de/progproj/gruppen-ht24/Gruppe-02.git
synced 2025-01-18 22:56:15 +01:00
trigger rent popup
This commit is contained in:
parent
f6137b8b68
commit
b87b3f054b
@ -11,10 +11,12 @@ import pp.monopoly.client.gui.popups.EventCardPopup;
|
||||
import pp.monopoly.client.gui.popups.FoodFieldCard;
|
||||
import pp.monopoly.client.gui.popups.GateFieldCard;
|
||||
import pp.monopoly.client.gui.popups.LooserPopUp;
|
||||
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.model.fields.BuildingProperty;
|
||||
import pp.monopoly.model.fields.FoodField;
|
||||
import pp.monopoly.model.fields.GateField;
|
||||
@ -153,6 +155,8 @@ public class TestWorld implements GameEventListener{
|
||||
new TimeOut(app).open();
|
||||
} else if (event.msg().equals("tradeRequest")) {
|
||||
new ConfirmTrade(app).open();
|
||||
} else if(event.msg().equals("rent")) {
|
||||
new Rent(app, ( (NotificationMessage) event.message()).getRentOwner(), ( (NotificationMessage) event.message()).getRentAmount() ).open();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -13,7 +13,7 @@ import com.simsilica.lemur.component.QuadBackgroundComponent;
|
||||
import com.simsilica.lemur.style.ElementId;
|
||||
import pp.dialog.Dialog;
|
||||
import pp.monopoly.client.MonopolyApp;
|
||||
import pp.monopoly.model.fields.BuildingProperty;
|
||||
import pp.monopoly.notification.Sound;
|
||||
|
||||
/**
|
||||
* Rent is a popup that is triggered when a player enters a field that does not belong himself and is owned by another player
|
||||
@ -24,17 +24,10 @@ public class Rent extends Dialog {
|
||||
private final Container rentContainer;
|
||||
private final Container backgroundContainer;
|
||||
|
||||
|
||||
private int index = 21; // TODO fixed for testing
|
||||
|
||||
|
||||
|
||||
public Rent(MonopolyApp app) {
|
||||
public Rent(MonopolyApp app, String playerName, int amount) {
|
||||
super(app.getDialogManager());
|
||||
this.app = app;
|
||||
|
||||
BuildingProperty field = (BuildingProperty) app.getGameLogic().getBoardManager().getFieldAtIndex(index);
|
||||
|
||||
// Halbtransparentes Overlay hinzufügen
|
||||
overlayBackground = createOverlayBackground();
|
||||
app.getGuiNode().attachChild(overlayBackground);
|
||||
@ -48,26 +41,29 @@ public class Rent extends Dialog {
|
||||
|
||||
// Hauptcontainer für die Warnung
|
||||
rentContainer = new Container();
|
||||
rentContainer.setBackground(new QuadBackgroundComponent(field.getColor().getColor()));
|
||||
rentContainer.setBackground(new QuadBackgroundComponent(ColorRGBA.Gray));
|
||||
rentContainer.setPreferredSize(new Vector3f(550,250,10));
|
||||
|
||||
float padding = 10; // Passt den backgroundContainer an die Größe des bankruptContainers an
|
||||
backgroundContainer.setPreferredSize(rentContainer.getPreferredSize().addLocal(padding, padding, 0));
|
||||
|
||||
// Titel
|
||||
Label gateFieldTitle = rentContainer.addChild(new Label( "Miete fürs "+field.getName()+" !", new ElementId("label-Bold")));
|
||||
Label gateFieldTitle = rentContainer.addChild(new Label( "Miete !", new ElementId("label-Bold")));
|
||||
gateFieldTitle.setFontSize(48);
|
||||
gateFieldTitle.setColor(ColorRGBA.Black);
|
||||
|
||||
// Text, der auf der Karte steht
|
||||
Container textContainer = rentContainer.addChild(new Container());
|
||||
textContainer.addChild(new Label("Du bist auf das " + field.getName()+ " gekommen!", new ElementId("label-Text")));
|
||||
textContainer.addChild(new Label("Du must Spieler XXX XXX EUR Miete zahlen", new ElementId("label-Text")));
|
||||
textContainer.addChild(new Label("Du must Spieler "+ playerName + " "+ amount+" EUR Miete zahlen", new ElementId("label-Text")));
|
||||
textContainer.setBackground(new QuadBackgroundComponent(new ColorRGBA(0.4657f, 0.4735f, 0.4892f, 1.0f)));
|
||||
textContainer.setPreferredSize(rentContainer.getPreferredSize().addLocal(-250,-200,0));
|
||||
|
||||
// Beenden-Button
|
||||
Button quitButton = rentContainer.addChild(new Button("Überweisen", new ElementId("button")));
|
||||
quitButton.addClickCommands(s -> ifTopDialog(() -> {
|
||||
app.getGameLogic().playSound(Sound.BUTTON);
|
||||
close();
|
||||
}));
|
||||
quitButton.setFontSize(32);
|
||||
quitButton.addClickCommands(source -> close());
|
||||
|
||||
@ -76,14 +72,14 @@ public class Rent extends Dialog {
|
||||
rentContainer.setLocalTranslation(
|
||||
(app.getCamera().getWidth() - rentContainer.getPreferredSize().x) / 2,
|
||||
(app.getCamera().getHeight() + rentContainer.getPreferredSize().y) / 2,
|
||||
8
|
||||
10
|
||||
);
|
||||
|
||||
// Zentriere das Popup
|
||||
backgroundContainer.setLocalTranslation(
|
||||
(app.getCamera().getWidth() - rentContainer.getPreferredSize().x - padding) / 2,
|
||||
(app.getCamera().getHeight() + rentContainer.getPreferredSize().y+ padding) / 2,
|
||||
7
|
||||
10
|
||||
);
|
||||
|
||||
app.getGuiNode().attachChild(rentContainer);
|
||||
@ -101,7 +97,7 @@ public class Rent extends Dialog {
|
||||
material.setColor("Color", new ColorRGBA(0, 0, 0, 0.5f)); // Halbtransparent
|
||||
material.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
|
||||
overlay.setMaterial(material);
|
||||
overlay.setLocalTranslation(0, 0, 0);
|
||||
overlay.setLocalTranslation(0, 0, 10);
|
||||
return overlay;
|
||||
}
|
||||
|
||||
@ -110,10 +106,10 @@ public class Rent extends Dialog {
|
||||
*/
|
||||
@Override
|
||||
public void close() {
|
||||
super.close();
|
||||
app.getGuiNode().detachChild(rentContainer); // Entferne das Menü
|
||||
app.getGuiNode().detachChild(backgroundContainer); //Entfernt Rand
|
||||
app.getGuiNode().detachChild(overlayBackground); // Entferne das Overlay
|
||||
super.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -14,6 +14,7 @@ import pp.monopoly.message.server.GameOver;
|
||||
import pp.monopoly.message.server.GameStart;
|
||||
import pp.monopoly.message.server.JailEvent;
|
||||
import pp.monopoly.message.server.NextPlayerTurn;
|
||||
import pp.monopoly.message.server.NotificationMessage;
|
||||
import pp.monopoly.message.server.PlayerStatusUpdate;
|
||||
import pp.monopoly.message.server.ServerInterpreter;
|
||||
import pp.monopoly.message.server.TimeOutWarning;
|
||||
@ -233,10 +234,10 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker {
|
||||
@Override
|
||||
public void received(GameOver msg) {
|
||||
if (msg.isWinner()) {
|
||||
notifyListeners(new PopUpEvent("Winner"));
|
||||
notifyListeners(new PopUpEvent("Winner", msg));
|
||||
playSound(Sound.WINNER);
|
||||
} else {
|
||||
notifyListeners(new PopUpEvent("Looser"));
|
||||
notifyListeners(new PopUpEvent("Looser", msg));
|
||||
playSound(Sound.LOSER);
|
||||
}
|
||||
}
|
||||
@ -287,7 +288,7 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker {
|
||||
*/
|
||||
@Override
|
||||
public void received(TimeOutWarning msg) {
|
||||
notifyListeners(new PopUpEvent("timeout"));
|
||||
notifyListeners(new PopUpEvent("timeout", msg));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -322,7 +323,7 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker {
|
||||
@Override
|
||||
public void received(TradeRequest msg) {
|
||||
tradeHandler = msg.getTradeHandler();
|
||||
notifyListeners(new PopUpEvent("tradeRequest"));
|
||||
notifyListeners(new PopUpEvent("tradeRequest", msg));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -338,6 +339,13 @@ public class ClientGameLogic implements ServerInterpreter, GameEventBroker {
|
||||
|
||||
@Override
|
||||
public void received(BuyPropertyRequest msg) {
|
||||
notifyListeners(new PopUpEvent("Buy"));
|
||||
notifyListeners(new PopUpEvent("Buy", msg));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void received(NotificationMessage msg) {
|
||||
if (msg.getKeyWord().equals("rent")) {
|
||||
notifyListeners(new PopUpEvent("rent", msg));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,7 @@ import pp.monopoly.message.server.BuyPropertyRequest;
|
||||
import pp.monopoly.message.server.DiceResult;
|
||||
import pp.monopoly.message.server.EventDrawCard;
|
||||
import pp.monopoly.message.server.NextPlayerTurn;
|
||||
import pp.monopoly.message.server.NotificationMessage;
|
||||
import pp.monopoly.message.server.PlayerStatusUpdate;
|
||||
import pp.monopoly.model.FieldVisitor;
|
||||
import pp.monopoly.model.Figure;
|
||||
@ -304,6 +305,10 @@ public class Player implements FieldVisitor<Void>{
|
||||
int rent = field.calcRent();
|
||||
field.getOwner().earnMoney(rent);
|
||||
pay(rent);
|
||||
NotificationMessage msg = new NotificationMessage("rent");
|
||||
msg.setRentAmount(rent);
|
||||
msg.setRentOwnerId(field.getOwner().getName());
|
||||
getHandler().getLogic().send(this, msg);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@ -317,8 +322,13 @@ public class Player implements FieldVisitor<Void>{
|
||||
if (field.getOwner().getNumProp(field) == 2) {
|
||||
factor = 10;
|
||||
}
|
||||
field.getOwner().earnMoney(rollResult.calcTotal()*factor);
|
||||
pay(rollResult.calcTotal()*factor);
|
||||
int rent = rollResult.calcTotal()*factor;
|
||||
field.getOwner().earnMoney(rent);
|
||||
pay(rent);
|
||||
NotificationMessage msg = new NotificationMessage("rent");
|
||||
msg.setRentAmount(rent);
|
||||
msg.setRentOwnerId(field.getOwner().getName());
|
||||
getHandler().getLogic().send(this, msg);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@ -332,6 +342,10 @@ public class Player implements FieldVisitor<Void>{
|
||||
|
||||
field.getOwner().earnMoney(rent);
|
||||
pay(rent);
|
||||
NotificationMessage msg = new NotificationMessage("rent");
|
||||
msg.setRentAmount(rent);
|
||||
msg.setRentOwnerId(field.getOwner().getName());
|
||||
getHandler().getLogic().send(this, msg);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -0,0 +1,50 @@
|
||||
package pp.monopoly.message.server;
|
||||
|
||||
import com.jme3.network.serializing.Serializable;
|
||||
|
||||
@Serializable
|
||||
public class NotificationMessage extends ServerMessage{
|
||||
|
||||
private final String keyWord;
|
||||
|
||||
private int rentAmount;
|
||||
private String rentOwner;
|
||||
|
||||
private NotificationMessage(){ keyWord = null;}
|
||||
|
||||
public NotificationMessage(String keyWord) {
|
||||
this.keyWord = keyWord;
|
||||
}
|
||||
|
||||
public int getRentAmount() {
|
||||
return rentAmount;
|
||||
}
|
||||
|
||||
public void setRentAmount(int rentAmount) {
|
||||
this.rentAmount = rentAmount;
|
||||
}
|
||||
|
||||
public void setRentOwnerId(String rentOwnerId) {
|
||||
this.rentOwner = rentOwnerId;
|
||||
}
|
||||
|
||||
public String getRentOwner() {
|
||||
return rentOwner;
|
||||
}
|
||||
|
||||
public String getKeyWord() {
|
||||
return keyWord;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(ServerInterpreter interpreter) {
|
||||
interpreter.received(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInfoTextKey() {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'getInfoTextKey'");
|
||||
}
|
||||
|
||||
}
|
@ -96,4 +96,11 @@ public interface ServerInterpreter {
|
||||
* @param msg the NextPlayerTurn message received
|
||||
*/
|
||||
void received(BuyPropertyRequest msg);
|
||||
|
||||
/**
|
||||
* Handles a NextPlayerTurn message received from the server.
|
||||
*
|
||||
* @param msg the NextPlayerTurn message received
|
||||
*/
|
||||
void received(NotificationMessage msg);
|
||||
}
|
||||
|
@ -1,6 +1,8 @@
|
||||
package pp.monopoly.notification;
|
||||
|
||||
public record PopUpEvent(String msg) implements GameEvent{
|
||||
import pp.monopoly.message.server.ServerMessage;
|
||||
|
||||
public record PopUpEvent(String msg, ServerMessage message) implements GameEvent{
|
||||
|
||||
@Override
|
||||
public void notifyListener(GameEventListener listener) {
|
||||
|
@ -42,6 +42,7 @@ import pp.monopoly.message.server.DiceResult;
|
||||
import pp.monopoly.message.server.EventDrawCard;
|
||||
import pp.monopoly.message.server.GameStart;
|
||||
import pp.monopoly.message.server.NextPlayerTurn;
|
||||
import pp.monopoly.message.server.NotificationMessage;
|
||||
import pp.monopoly.message.server.PlayerStatusUpdate;
|
||||
import pp.monopoly.message.server.ServerMessage;
|
||||
import pp.monopoly.message.server.TradeReply;
|
||||
@ -170,6 +171,7 @@ public class MonopolyServer implements MessageListener<HostedConnection>, Connec
|
||||
Serializer.registerClass(TradeRequest.class);
|
||||
Serializer.registerClass(TradeReply.class);
|
||||
Serializer.registerClass(TradeHandler.class);
|
||||
Serializer.registerClass(NotificationMessage.class);
|
||||
}
|
||||
|
||||
private void registerListeners() {
|
||||
|
Loading…
Reference in New Issue
Block a user