mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-15 03:28:49 -07:00
[Game] Fix game timer starting twice, not stopping and not resetting correctly. (#6177)
* Fix timer starting twice, not stopping and not resetting correctly. Took 39 minutes * Don't stop/start, just start. Took 29 minutes * Fix build. Took 2 minutes --------- Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
This commit is contained in:
parent
6187c7268f
commit
fad1280185
3 changed files with 5 additions and 12 deletions
|
|
@ -15,6 +15,10 @@ GameState::GameState(AbstractGame *parent,
|
||||||
clients(_clients), gameStateKnown(_gameStateKnown), resuming(_resuming), currentPhase(_currentPhase),
|
clients(_clients), gameStateKnown(_gameStateKnown), resuming(_resuming), currentPhase(_currentPhase),
|
||||||
activePlayer(-1), gameClosed(_gameClosed)
|
activePlayer(-1), gameClosed(_gameClosed)
|
||||||
{
|
{
|
||||||
|
gameTimer = new QTimer(this);
|
||||||
|
gameTimer->setInterval(1000);
|
||||||
|
connect(gameTimer, &QTimer::timeout, this, &GameState::incrementGameTime);
|
||||||
|
gameTimer->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameState::incrementGameTime()
|
void GameState::incrementGameTime()
|
||||||
|
|
@ -24,6 +28,7 @@ void GameState::incrementGameTime()
|
||||||
|
|
||||||
void GameState::setGameTime(int _secondsElapsed)
|
void GameState::setGameTime(int _secondsElapsed)
|
||||||
{
|
{
|
||||||
|
secondsElapsed = _secondsElapsed;
|
||||||
int seconds = _secondsElapsed;
|
int seconds = _secondsElapsed;
|
||||||
int minutes = seconds / 60;
|
int minutes = seconds / 60;
|
||||||
seconds -= minutes * 60;
|
seconds -= minutes * 60;
|
||||||
|
|
@ -33,12 +38,4 @@ void GameState::setGameTime(int _secondsElapsed)
|
||||||
emit updateTimeElapsedLabel(QString::number(hours).rightJustified(2, '0') + ":" +
|
emit updateTimeElapsedLabel(QString::number(hours).rightJustified(2, '0') + ":" +
|
||||||
QString::number(minutes).rightJustified(2, '0') + ":" +
|
QString::number(minutes).rightJustified(2, '0') + ":" +
|
||||||
QString::number(seconds).rightJustified(2, '0'));
|
QString::number(seconds).rightJustified(2, '0'));
|
||||||
}
|
|
||||||
|
|
||||||
void GameState::startGameTimer()
|
|
||||||
{
|
|
||||||
gameTimer = new QTimer(this);
|
|
||||||
gameTimer->setInterval(1000);
|
|
||||||
connect(gameTimer, &QTimer::timeout, this, &GameState::incrementGameTime);
|
|
||||||
gameTimer->start();
|
|
||||||
}
|
}
|
||||||
|
|
@ -91,15 +91,12 @@ public:
|
||||||
void onStartedChanged(bool _started)
|
void onStartedChanged(bool _started)
|
||||||
{
|
{
|
||||||
if (_started) {
|
if (_started) {
|
||||||
startGameTimer();
|
|
||||||
emit gameStarted(_started);
|
emit gameStarted(_started);
|
||||||
} else {
|
} else {
|
||||||
emit gameStopped();
|
emit gameStopped();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void startGameTimer();
|
|
||||||
|
|
||||||
void setGameStateKnown(bool known)
|
void setGameStateKnown(bool known)
|
||||||
{
|
{
|
||||||
gameStateKnown = known;
|
gameStateKnown = known;
|
||||||
|
|
|
||||||
|
|
@ -1277,7 +1277,6 @@ void TabGame::createMessageDock(bool bReplay)
|
||||||
timeElapsedLabel = new QLabel;
|
timeElapsedLabel = new QLabel;
|
||||||
timeElapsedLabel->setAlignment(Qt::AlignCenter);
|
timeElapsedLabel->setAlignment(Qt::AlignCenter);
|
||||||
connect(game->getGameState(), &GameState::updateTimeElapsedLabel, this, &TabGame::updateTimeElapsedLabel);
|
connect(game->getGameState(), &GameState::updateTimeElapsedLabel, this, &TabGame::updateTimeElapsedLabel);
|
||||||
game->getGameState()->startGameTimer();
|
|
||||||
|
|
||||||
messageLogLayout->addWidget(timeElapsedLabel);
|
messageLogLayout->addWidget(timeElapsedLabel);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue