From 01dd8c33ba4ac4893830814f18d67c1899653d68 Mon Sep 17 00:00:00 2001 From: Oleg Agafonov Date: Tue, 28 Nov 2023 21:47:48 +0400 Subject: [PATCH] gui: fixed possible game error with player timer on client side --- .../java/mage/client/game/PlayerPanelExt.java | 27 ++++++++++++------- .../src/main/java/mage/view/GameView.java | 4 +-- .../java/mage/server/game/GameController.java | 1 + 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/Mage.Client/src/main/java/mage/client/game/PlayerPanelExt.java b/Mage.Client/src/main/java/mage/client/game/PlayerPanelExt.java index b46a112c03b..5e52a38d539 100644 --- a/Mage.Client/src/main/java/mage/client/game/PlayerPanelExt.java +++ b/Mage.Client/src/main/java/mage/client/game/PlayerPanelExt.java @@ -104,20 +104,26 @@ public class PlayerPanelExt extends javax.swing.JPanel { int priorityTimeValue = pt.getCount() + pt.getBufferCount(); String text = getPriorityTimeLeftString(priorityTimeValue); // Set timer text colors (note, if you change it here, change it in update() as well) - Color textColor = null; // use default in HoverButton - Color foregroundColor = Color.BLACK; + final Color textColor; // use default in HoverButton + final Color foregroundColor; if (pt.getBufferCount() > 0) { textColor = Color.GREEN; foregroundColor = Color.GREEN.darker().darker(); } else if (pt.getCount() < 300) { // visual indication for under 5 minutes textColor = Color.RED; foregroundColor = Color.RED.darker().darker(); + } else { + textColor = null; + foregroundColor = Color.BLACK; } - PlayerPanelExt.this.avatar.setTopText(text); - PlayerPanelExt.this.avatar.setTopTextColor(textColor); - PlayerPanelExt.this.timerLabel.setText(text); - PlayerPanelExt.this.timerLabel.setForeground(foregroundColor); - PlayerPanelExt.this.avatar.repaint(); + + SwingUtilities.invokeLater(() -> { + PlayerPanelExt.this.avatar.setTopText(text); + PlayerPanelExt.this.avatar.setTopTextColor(textColor); + PlayerPanelExt.this.timerLabel.setText(text); + PlayerPanelExt.this.timerLabel.setForeground(foregroundColor); + PlayerPanelExt.this.avatar.repaint(); + }); }); timer.init(gameId); } @@ -318,14 +324,17 @@ public class PlayerPanelExt extends javax.swing.JPanel { this.avatar.setTopText(priorityTimeValue); this.timerLabel.setText(priorityTimeValue); // Set timer text colors (note, if you change it here, change it in init()::timer.setTaskOnTick() as well) - Color textColor = null; // use default in HoverButton - Color foregroundColor = Color.BLACK; + final Color textColor; // use default in HoverButton + final Color foregroundColor; if (player.getBufferTimeLeft() > 0) { textColor = Color.GREEN; foregroundColor = Color.GREEN.darker().darker(); } else if (player.getPriorityTimeLeft() < 300) { // visual indication for under 5 minutes textColor = Color.RED; foregroundColor = Color.RED.darker().darker(); + } else { + textColor = null; + foregroundColor = Color.BLACK; } this.avatar.setTopTextColor(textColor); this.timerLabel.setForeground(foregroundColor); diff --git a/Mage.Common/src/main/java/mage/view/GameView.java b/Mage.Common/src/main/java/mage/view/GameView.java index f9c9ff50117..5e70adb8708 100644 --- a/Mage.Common/src/main/java/mage/view/GameView.java +++ b/Mage.Common/src/main/java/mage/view/GameView.java @@ -43,8 +43,8 @@ public class GameView implements Serializable { private UUID myPlayerId = null; // null for watcher private final CardsView myHand = new CardsView(); private PlayableObjectsList canPlayObjects; - private Map opponentHands = new HashMap<>(); - private Map watchedHands = new HashMap<>(); + private final Map opponentHands = new HashMap<>(); + private final Map watchedHands = new HashMap<>(); private final CardsView stack = new CardsView(); private final List exiles = new ArrayList<>(); private final List revealed = new ArrayList<>(); diff --git a/Mage.Server/src/main/java/mage/server/game/GameController.java b/Mage.Server/src/main/java/mage/server/game/GameController.java index c61bfc85942..a0a563d694c 100644 --- a/Mage.Server/src/main/java/mage/server/game/GameController.java +++ b/Mage.Server/src/main/java/mage/server/game/GameController.java @@ -267,6 +267,7 @@ public class GameController implements GameCallback { long delayMs = 250L; // run each 250 ms Action executeOnNoTimeLeft = () -> { + // TODO: buggy, must run in game thread, not in timer thread game.timerTimeout(initPlayerId); logger.debug("Player has no time left to end the match: " + initPlayerId + ". Conceding."); };