From 8614faf9406563840f61486315da184f40a7b6b0 Mon Sep 17 00:00:00 2001 From: Johannes Schmelz Date: Sat, 7 Dec 2024 22:11:31 +0100 Subject: [PATCH] show popups --- .../pp/monopoly/client/BoardAppState.java | 6 ++ .../java/pp/monopoly/client/PopUpManager.java | 97 +++++++++++++++++++ 2 files changed, 103 insertions(+) create mode 100644 Projekte/monopoly/client/src/main/java/pp/monopoly/client/PopUpManager.java diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/BoardAppState.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/BoardAppState.java index 96e4809..819fa68 100644 --- a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/BoardAppState.java +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/BoardAppState.java @@ -61,6 +61,11 @@ public class BoardAppState extends MonopolyAppState { */ private BobTheBuilder bobTheBuilder; + /** + * The pop-up manager for displaying messages and notifications. + */ + private PopUpManager popUpManager;; + /** * Initializes the state by setting up the sky, lights, and other visual components. * This method is called when the state is first attached to the state manager. @@ -71,6 +76,7 @@ public class BoardAppState extends MonopolyAppState { @Override public void initialize(AppStateManager stateManager, Application application) { super.initialize(stateManager, application); + popUpManager = new PopUpManager(getApp()); viewNode.attachChild(sceneNode); setupLights(); setupSky(); diff --git a/Projekte/monopoly/client/src/main/java/pp/monopoly/client/PopUpManager.java b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/PopUpManager.java new file mode 100644 index 0000000..53e6dfa --- /dev/null +++ b/Projekte/monopoly/client/src/main/java/pp/monopoly/client/PopUpManager.java @@ -0,0 +1,97 @@ +package pp.monopoly.client; + +import java.util.Timer; +import java.util.TimerTask; + +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; +import pp.monopoly.client.gui.popups.FoodFieldCard; +import pp.monopoly.client.gui.popups.GateFieldCard; +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.ReceivedRent; +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.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; +import pp.monopoly.notification.EventCardEvent; +import pp.monopoly.notification.GameEventListener; +import pp.monopoly.notification.PopUpEvent; + +public class PopUpManager implements GameEventListener { + + private final MonopolyApp app; + + public PopUpManager(MonopolyApp app) { + this.app = app; + app.getGameLogic().addListener(this); + } + + @Override + public void receivedEvent(PopUpEvent event) { + if (event.msg().equals("Buy")) { + Timer timer = new Timer(); + timer.schedule(new TimerTask() { + @Override + public void run() { + app.enqueue(() -> { + int field = app.getGameLogic().getPlayerHandler().getPlayerById(app.getId()).getFieldID(); + Object fieldObject = app.getGameLogic().getBoardManager().getFieldAtIndex(field); + + if (fieldObject instanceof BuildingProperty) { + new BuildingPropertyCard(app).open(); + } else if (fieldObject instanceof GateField) { + new GateFieldCard(app).open(); + } else if (fieldObject instanceof FoodField) { + new FoodFieldCard(app).open(); + } + }); + } + }, 2500); + } else if (event.msg().equals("Winner")) { + new WinnerPopUp(app).open(); + } else if (event.msg().equals("Looser")) { + new LooserPopUp(app).open(); + } else if (event.msg().equals("timeout")) { + new TimeOut(app).open(); + } else if (event.msg().equals("tradeRequest")) { + new ConfirmTrade(app).open(); + } else if (event.msg().equals("goingToJail")) { + new Gulag(app).open(); + } else if (event.msg().equals("NoMoneyWarning")) { + new NoMoneyWarning(app).open(); + } else if(event.msg().equals("rent")) { + new Rent(app, ( (NotificationMessage) event.message()).getRentOwner(), ( (NotificationMessage) event.message()).getRentAmount() ).open(); + } else if (event.msg().equals("jailtryagain")) { + 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(); + } else if (event.msg().equals("ReceivedRent")) { + new ReceivedRent(app, ( (NotificationMessage) event.message()).getRentOwner(), ( (NotificationMessage) event.message()).getRentAmount() ).open(); + } + } + + @Override + public void receivedEvent(EventCardEvent event) { + Timer timer = new Timer(); + timer.schedule(new TimerTask() { + @Override + public void run() { + app.enqueue(() -> new EventCardPopup(app, event.description()).open()); + } + }, 2500); + } +}