From 0b51af888c01834370df171f13d817157af4372b Mon Sep 17 00:00:00 2001 From: Max-Wilhelm Bruker Date: Mon, 26 Mar 2012 19:32:27 +0200 Subject: [PATCH] Don't close the game tab immediately when kicked out of a game. Fixes bug #25 --- cockatrice/src/messagelogwidget.cpp | 5 +++++ cockatrice/src/messagelogwidget.h | 1 + cockatrice/src/tab_game.cpp | 31 ++++++++++++++++++++--------- cockatrice/src/tab_game.h | 2 ++ 4 files changed, 30 insertions(+), 9 deletions(-) diff --git a/cockatrice/src/messagelogwidget.cpp b/cockatrice/src/messagelogwidget.cpp index 7c531bb4..2196aeb7 100644 --- a/cockatrice/src/messagelogwidget.cpp +++ b/cockatrice/src/messagelogwidget.cpp @@ -59,6 +59,11 @@ void MessageLogWidget::logGameClosed() appendHtml(tr("The game has been closed.")); } +void MessageLogWidget::logKicked() +{ + appendHtml(tr("You have been kicked out of the game.")); +} + void MessageLogWidget::logJoinSpectator(QString name) { appendHtml(tr("%1 is now watching the game.").arg(sanitizeHtml(name))); diff --git a/cockatrice/src/messagelogwidget.h b/cockatrice/src/messagelogwidget.h index aeb928ad..a41813c7 100644 --- a/cockatrice/src/messagelogwidget.h +++ b/cockatrice/src/messagelogwidget.h @@ -44,6 +44,7 @@ public slots: void logJoin(Player *player); void logLeave(Player *player); void logGameClosed(); + void logKicked(); void logJoinSpectator(QString name); void logLeaveSpectator(QString name); void logDeckSelect(Player *player, QString deckHash); diff --git a/cockatrice/src/tab_game.cpp b/cockatrice/src/tab_game.cpp index 471a1eb2..95e0c5ad 100644 --- a/cockatrice/src/tab_game.cpp +++ b/cockatrice/src/tab_game.cpp @@ -209,6 +209,7 @@ TabGame::TabGame(GameReplay *_replay) resuming(false), currentPhase(-1), activeCard(0), + gameClosed(false), replay(_replay), currentReplayStep(0) { @@ -353,6 +354,7 @@ TabGame::TabGame(TabSupervisor *_tabSupervisor, QList &_client resuming(event.resuming()), currentPhase(-1), activeCard(0), + gameClosed(false), replay(0) { gameInfo.set_started(false); @@ -631,12 +633,14 @@ void TabGame::actConcede() void TabGame::actLeaveGame() { - if (!spectator) - if (QMessageBox::question(this, tr("Leave game"), tr("Are you sure you want to leave this game?"), QMessageBox::Yes | QMessageBox::No, QMessageBox::No) != QMessageBox::Yes) - return; - - if (!replay) - sendGameCommand(Command_LeaveGame()); + if (!gameClosed) { + if (!spectator) + if (QMessageBox::question(this, tr("Leave game"), tr("Are you sure you want to leave this game?"), QMessageBox::Yes | QMessageBox::No, QMessageBox::No) != QMessageBox::Yes) + return; + + if (!replay) + sendGameCommand(Command_LeaveGame()); + } deleteLater(); } @@ -853,6 +857,15 @@ void TabGame::stopGame() phasesToolbar->hide(); } +void TabGame::closeGame() +{ + gameInfo.set_started(false); + gameClosed = true; + + tabMenu->clear(); + tabMenu->addAction(aLeaveGame); +} + void TabGame::eventSpectatorSay(const Event_GameSay &event, int eventPlayerId, const GameEventContext & /*context*/) { messageLog->logSpectatorSay(spectators.value(eventPlayerId), QString::fromStdString(event.message())); @@ -1001,9 +1014,9 @@ void TabGame::eventLeave(const Event_Leave & /*event*/, int eventPlayerId, const void TabGame::eventKicked(const Event_Kicked & /*event*/, int /*eventPlayerId*/, const GameEventContext & /*context*/) { + closeGame(); + messageLog->logKicked(); emit userEvent(); - QMessageBox::critical(this, tr("Kicked"), tr("You have been kicked out of the game.")); - deleteLater(); } void TabGame::eventGameHostChanged(const Event_GameHostChanged & /*event*/, int eventPlayerId, const GameEventContext & /*context*/) @@ -1013,7 +1026,7 @@ void TabGame::eventGameHostChanged(const Event_GameHostChanged & /*event*/, int void TabGame::eventGameClosed(const Event_GameClosed & /*event*/, int /*eventPlayerId*/, const GameEventContext & /*context*/) { - gameInfo.set_started(false); + closeGame(); messageLog->logGameClosed(); emit userEvent(); } diff --git a/cockatrice/src/tab_game.h b/cockatrice/src/tab_game.h index a0b58588..7863e24b 100644 --- a/cockatrice/src/tab_game.h +++ b/cockatrice/src/tab_game.h @@ -109,6 +109,7 @@ private: int currentPhase; int activePlayer; CardItem *activeCard; + bool gameClosed; // Replay related members GameReplay *replay; @@ -140,6 +141,7 @@ private: void startGame(bool resuming); void stopGame(); + void closeGame(); void eventSpectatorSay(const Event_GameSay &event, int eventPlayerId, const GameEventContext &context); void eventSpectatorLeave(const Event_Leave &event, int eventPlayerId, const GameEventContext &context);