From a79b71f02893cd00f785f71b0b874fc8dd1a658f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Teuli=C3=A8re?= Date: Sun, 30 Nov 2008 20:51:05 +0000 Subject: [PATCH] When navigating in the history, display the current turn in the status bar --- game/navigation.cpp | 18 ++++++++++++++++++ game/navigation.h | 3 ++- qt/main_window.cpp | 12 ++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/game/navigation.cpp b/game/navigation.cpp index a6b951c..c487d37 100644 --- a/game/navigation.cpp +++ b/game/navigation.cpp @@ -60,6 +60,24 @@ void Navigation::addAndExecute(Command *iCmd) } +unsigned int Navigation::getCurrTurn() const +{ + unsigned int currTurn = m_currTurn; + if (isLastTurn() && m_turnCommands.back()->isEmpty()) + --currTurn; + return currTurn; +} + + +unsigned int Navigation::getNbTurns() const +{ + unsigned int count = m_turnCommands.size(); + if (m_turnCommands.back()->isEmpty()) + --count; + return count; +} + + bool Navigation::isFirstTurn() const { return m_currTurn == 1 || diff --git a/game/navigation.h b/game/navigation.h index 984a50b..cdc0e1b 100644 --- a/game/navigation.h +++ b/game/navigation.h @@ -38,7 +38,8 @@ class Navigation void newTurn(); void addAndExecute(Command *iCmd); - unsigned int getCurrTurn() const { return m_currTurn; } + unsigned int getCurrTurn() const; + unsigned int getNbTurns() const; bool isFirstTurn() const; bool isLastTurn() const; diff --git a/qt/main_window.cpp b/qt/main_window.cpp index 1edc4e3..1d2f5f1 100644 --- a/qt/main_window.cpp +++ b/qt/main_window.cpp @@ -789,6 +789,9 @@ void MainWindow::onHistoryFirstTurn() m_game->accessNavigation().firstTurn(); emit gameUpdated(); + unsigned int currTurn = m_game->getNavigation().getCurrTurn(); + unsigned int nbTurns = m_game->getNavigation().getNbTurns(); + displayInfoMsg(_q("Turn %1/%2").arg(currTurn).arg(nbTurns)); } @@ -799,6 +802,9 @@ void MainWindow::onHistoryPrevTurn() m_game->accessNavigation().prevTurn(); emit gameUpdated(); + unsigned int currTurn = m_game->getNavigation().getCurrTurn(); + unsigned int nbTurns = m_game->getNavigation().getNbTurns(); + displayInfoMsg(_q("Turn %1/%2").arg(currTurn).arg(nbTurns)); } @@ -809,6 +815,9 @@ void MainWindow::onHistoryNextTurn() m_game->accessNavigation().nextTurn(); emit gameUpdated(); + unsigned int currTurn = m_game->getNavigation().getCurrTurn(); + unsigned int nbTurns = m_game->getNavigation().getNbTurns(); + displayInfoMsg(_q("Turn %1/%2").arg(currTurn).arg(nbTurns)); } @@ -819,6 +828,9 @@ void MainWindow::onHistoryLastTurn() m_game->accessNavigation().lastTurn(); emit gameUpdated(); + unsigned int currTurn = m_game->getNavigation().getCurrTurn(); + unsigned int nbTurns = m_game->getNavigation().getNbTurns(); + displayInfoMsg(_q("Turn %1/%2").arg(currTurn).arg(nbTurns)); }