Reset the timer automatically when a new turn starts

This commit is contained in:
Olivier Teulière 2012-11-06 23:55:17 +01:00
parent c89e91010c
commit e355acc4fb
2 changed files with 16 additions and 3 deletions

View file

@ -81,7 +81,7 @@ MainWindow::MainWindow(QWidget *iParent)
m_bagWindow(NULL), m_boardWindow(NULL), m_bagWindow(NULL), m_boardWindow(NULL),
m_historyWindow(NULL), m_statsWindow(NULL), m_timerWindow(NULL), m_historyWindow(NULL), m_statsWindow(NULL), m_timerWindow(NULL),
m_dicToolsWindow(NULL), m_dicNameLabel(NULL), m_timerModel(NULL), m_dicToolsWindow(NULL), m_dicNameLabel(NULL), m_timerModel(NULL),
m_currentTurn(0) m_currentTurn(0), m_lastTurn(0)
{ {
#ifdef DEBUG #ifdef DEBUG
// Check that the string conversion routines are not buggy // Check that the string conversion routines are not buggy
@ -116,6 +116,8 @@ MainWindow::MainWindow(QWidget *iParent)
this, SLOT(beep())); this, SLOT(beep()));
QObject::connect(m_timerModel, SIGNAL(expired()), QObject::connect(m_timerModel, SIGNAL(expired()),
this, SLOT(beep())); this, SLOT(beep()));
QObject::connect(this, SIGNAL(newTurn(int)),
m_timerModel, SLOT(resetTimer()));
QObject::connect(this, SIGNAL(gameChangedNonConst(PublicGame*)), QObject::connect(this, SIGNAL(gameChangedNonConst(PublicGame*)),
this, SLOT(updateForGame(PublicGame*))); this, SLOT(updateForGame(PublicGame*)));
@ -262,12 +264,18 @@ void MainWindow::refresh()
m_actionHistoryReplayTurn->setEnabled(!isLastTurn); m_actionHistoryReplayTurn->setEnabled(!isLastTurn);
if (m_game->isFinished()) if (m_game->isFinished())
displayInfoMsg(_q("End of the game")); displayInfoMsg(_q("End of the game"));
// Emit the turnChanged() sign if needed. // Emit the turnChanged() signal if needed
if (currTurn != m_currentTurn) if (currTurn != m_currentTurn)
{ {
m_currentTurn = currTurn; m_currentTurn = currTurn;
emit turnChanged(currTurn, isLastTurn); emit turnChanged(currTurn, isLastTurn);
} }
// Emit the newTurn() signal if needed
if (currTurn > m_lastTurn)
{
m_lastTurn = currTurn;
emit newTurn(currTurn);
}
// Update the auto-saved game // Update the auto-saved game
try try

View file

@ -62,6 +62,8 @@ signals:
void gameChangedNonConst(PublicGame *iGame); void gameChangedNonConst(PublicGame *iGame);
void gameUpdated(); void gameUpdated();
void turnChanged(int iCurrTurn, bool isLastTurn); void turnChanged(int iCurrTurn, bool isLastTurn);
/// Like turnChanged(), but only emitted when a new turn is created
void newTurn(int iCurrTurn);
public slots: public slots:
/// Display an error message to the user /// Display an error message to the user
@ -195,9 +197,12 @@ private:
/// Model for the timer widgets /// Model for the timer widgets
TimerModel *m_timerModel; TimerModel *m_timerModel;
/// Last known turn number. Used to emit turnChanged(). /// Current turn number. Used to emit turnChanged().
unsigned m_currentTurn; unsigned m_currentTurn;
/// Last known turn number. Used to emit newTurn().
unsigned m_lastTurn;
/// Save window state /// Save window state
void writeSettings() const; void writeSettings() const;
/// Restore window state /// Restore window state