gui: fixed possible game error with player timer on client side

This commit is contained in:
Oleg Agafonov 2023-11-28 21:47:48 +04:00
parent 30269243bb
commit 01dd8c33ba
3 changed files with 21 additions and 11 deletions

View file

@ -104,21 +104,27 @@ public class PlayerPanelExt extends javax.swing.JPanel {
int priorityTimeValue = pt.getCount() + pt.getBufferCount(); int priorityTimeValue = pt.getCount() + pt.getBufferCount();
String text = getPriorityTimeLeftString(priorityTimeValue); String text = getPriorityTimeLeftString(priorityTimeValue);
// Set timer text colors (note, if you change it here, change it in update() as well) // Set timer text colors (note, if you change it here, change it in update() as well)
Color textColor = null; // use default in HoverButton final Color textColor; // use default in HoverButton
Color foregroundColor = Color.BLACK; final Color foregroundColor;
if (pt.getBufferCount() > 0) { if (pt.getBufferCount() > 0) {
textColor = Color.GREEN; textColor = Color.GREEN;
foregroundColor = Color.GREEN.darker().darker(); foregroundColor = Color.GREEN.darker().darker();
} else if (pt.getCount() < 300) { // visual indication for under 5 minutes } else if (pt.getCount() < 300) { // visual indication for under 5 minutes
textColor = Color.RED; textColor = Color.RED;
foregroundColor = Color.RED.darker().darker(); foregroundColor = Color.RED.darker().darker();
} else {
textColor = null;
foregroundColor = Color.BLACK;
} }
SwingUtilities.invokeLater(() -> {
PlayerPanelExt.this.avatar.setTopText(text); PlayerPanelExt.this.avatar.setTopText(text);
PlayerPanelExt.this.avatar.setTopTextColor(textColor); PlayerPanelExt.this.avatar.setTopTextColor(textColor);
PlayerPanelExt.this.timerLabel.setText(text); PlayerPanelExt.this.timerLabel.setText(text);
PlayerPanelExt.this.timerLabel.setForeground(foregroundColor); PlayerPanelExt.this.timerLabel.setForeground(foregroundColor);
PlayerPanelExt.this.avatar.repaint(); PlayerPanelExt.this.avatar.repaint();
}); });
});
timer.init(gameId); timer.init(gameId);
} }
} }
@ -318,14 +324,17 @@ public class PlayerPanelExt extends javax.swing.JPanel {
this.avatar.setTopText(priorityTimeValue); this.avatar.setTopText(priorityTimeValue);
this.timerLabel.setText(priorityTimeValue); this.timerLabel.setText(priorityTimeValue);
// Set timer text colors (note, if you change it here, change it in init()::timer.setTaskOnTick() as well) // 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 final Color textColor; // use default in HoverButton
Color foregroundColor = Color.BLACK; final Color foregroundColor;
if (player.getBufferTimeLeft() > 0) { if (player.getBufferTimeLeft() > 0) {
textColor = Color.GREEN; textColor = Color.GREEN;
foregroundColor = Color.GREEN.darker().darker(); foregroundColor = Color.GREEN.darker().darker();
} else if (player.getPriorityTimeLeft() < 300) { // visual indication for under 5 minutes } else if (player.getPriorityTimeLeft() < 300) { // visual indication for under 5 minutes
textColor = Color.RED; textColor = Color.RED;
foregroundColor = Color.RED.darker().darker(); foregroundColor = Color.RED.darker().darker();
} else {
textColor = null;
foregroundColor = Color.BLACK;
} }
this.avatar.setTopTextColor(textColor); this.avatar.setTopTextColor(textColor);
this.timerLabel.setForeground(foregroundColor); this.timerLabel.setForeground(foregroundColor);

View file

@ -43,8 +43,8 @@ public class GameView implements Serializable {
private UUID myPlayerId = null; // null for watcher private UUID myPlayerId = null; // null for watcher
private final CardsView myHand = new CardsView(); private final CardsView myHand = new CardsView();
private PlayableObjectsList canPlayObjects; private PlayableObjectsList canPlayObjects;
private Map<String, SimpleCardsView> opponentHands = new HashMap<>(); private final Map<String, SimpleCardsView> opponentHands = new HashMap<>();
private Map<String, SimpleCardsView> watchedHands = new HashMap<>(); private final Map<String, SimpleCardsView> watchedHands = new HashMap<>();
private final CardsView stack = new CardsView(); private final CardsView stack = new CardsView();
private final List<ExileView> exiles = new ArrayList<>(); private final List<ExileView> exiles = new ArrayList<>();
private final List<RevealedView> revealed = new ArrayList<>(); private final List<RevealedView> revealed = new ArrayList<>();

View file

@ -267,6 +267,7 @@ public class GameController implements GameCallback {
long delayMs = 250L; // run each 250 ms long delayMs = 250L; // run each 250 ms
Action executeOnNoTimeLeft = () -> { Action executeOnNoTimeLeft = () -> {
// TODO: buggy, must run in game thread, not in timer thread
game.timerTimeout(initPlayerId); game.timerTimeout(initPlayerId);
logger.debug("Player has no time left to end the match: " + initPlayerId + ". Conceding."); logger.debug("Player has no time left to end the match: " + initPlayerId + ". Conceding.");
}; };