From f96da2c46cc7851f4bebd8dd82ec8f3b7276e644 Mon Sep 17 00:00:00 2001 From: Felix Koppe Date: Sat, 7 Dec 2024 14:37:19 +0100 Subject: [PATCH] Add notification delay --- .../mdga/client/NotificationSynchronizer.java | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/Projekte/mdga/client/src/main/java/pp/mdga/client/NotificationSynchronizer.java b/Projekte/mdga/client/src/main/java/pp/mdga/client/NotificationSynchronizer.java index b43d1649..ab93560c 100644 --- a/Projekte/mdga/client/src/main/java/pp/mdga/client/NotificationSynchronizer.java +++ b/Projekte/mdga/client/src/main/java/pp/mdga/client/NotificationSynchronizer.java @@ -1,5 +1,6 @@ package pp.mdga.client; +import com.jme3.system.NanoTimer; import pp.mdga.client.acoustic.MdgaSound; import pp.mdga.client.board.BoardHandler; import pp.mdga.client.gui.GuiHandler; @@ -16,13 +17,26 @@ public class NotificationSynchronizer { private ArrayList notifications = new ArrayList<>(); + private NanoTimer timer = new NanoTimer(); + private float delay = 0; + + private static final float STANDARD_DELAY = 2.5f; + NotificationSynchronizer(MdgaApp app) { this.app = app; } public void update() { - Notification n = app.getGameLogic().getNotification(); - while (n != null) { + while (timer.getTimeInSeconds() >= delay) { + Notification n = app.getGameLogic().getNotification(); + + if(n == null) { + return; + } + + timer.reset(); + delay = 0; + if(n instanceof InfoNotification infoNotification) { app.getView().showInfo(infoNotification.getMessage(), infoNotification.isError()); return; @@ -46,8 +60,6 @@ public void update() { throw new RuntimeException("no notification expected: " + n.getClass().getName()); } } - - n = app.getGameLogic().getNotification(); } } @@ -90,10 +102,12 @@ private void handleGame(Notification notification) { if (notification instanceof AcquireCardNotification n) { guiHandler.addCardOwn(n.getBonusCard()); app.getAcousticHandler().playSound(MdgaSound.BONUS); + delay = STANDARD_DELAY; } else if (notification instanceof ActivePlayerNotification n) { gameView.getGuiHandler().setActivePlayer(n.getColor()); boardHandler.showDice(n.getColor()); app.getAcousticHandler().playSound(MdgaSound.UI90); + delay = STANDARD_DELAY; } else if (notification instanceof CeremonyNotification ceremonyNotification) { app.enter(MdgaState.CEREMONY); CeremonyView ceremonyView = (CeremonyView) app.getView(); @@ -162,6 +176,7 @@ private void handleGame(Notification notification) { if (n.isTurbo()) guiHandler.showRolledDiceMult(n.getEyes(), n.getMultiplier(), n.getColor()); else guiHandler.showRolledDice(n.getEyes(), n.getColor()); } + delay = 7; } else if (notification instanceof SelectableCardsNotification n) { guiHandler.setSelectableCards(n.getCards()); gameView.showNoPower();