Do not allow navigating before the first turn, and do not count an empty turn as a real one when navigating.

The navigation in the history is now more natural.
This commit is contained in:
Olivier Teulière 2008-11-23 17:08:12 +00:00
parent 8e7c61e2d8
commit fa225881c0
3 changed files with 37 additions and 8 deletions

View file

@ -60,12 +60,32 @@ void Navigation::addAndExecute(Command *iCmd)
}
bool Navigation::isFirstTurn() const
{
return m_currTurn == 1 ||
(m_currTurn == 2 && m_turnCommands[1]->isEmpty());
}
bool Navigation::isLastTurn() const
{
return m_currTurn == m_turnCommands.size();
}
void Navigation::prevTurn()
{
if (m_currTurn > 0)
if (m_currTurn > 1)
{
--m_currTurn;
m_turnCommands[m_currTurn]->undo();
// Special case: when the last turn is empty, automatically
// undo the previous turn as well
if (m_currTurn + 1 == m_turnCommands.size() &&
m_turnCommands[m_currTurn]->isEmpty())
{
prevTurn();
}
}
}
@ -76,13 +96,20 @@ void Navigation::nextTurn()
{
m_turnCommands[m_currTurn]->execute();
++m_currTurn;
// Special case: when the last turn is empty, automatically
// execute it
if (m_currTurn + 1 == m_turnCommands.size() &&
m_turnCommands[m_currTurn]->isEmpty())
{
nextTurn();
}
}
}
void Navigation::firstTurn()
{
while (m_currTurn > 0)
while (m_currTurn > 1)
{
prevTurn();
}

View file

@ -39,8 +39,8 @@ class Navigation
void addAndExecute(Command *iCmd);
unsigned int getCurrTurn() const { return m_currTurn; }
bool isFirstTurn() const { return m_currTurn == 0; }
bool isLastTurn() const { return m_currTurn == m_turnCommands.size(); }
bool isFirstTurn() const;
bool isLastTurn() const;
void firstTurn();
void prevTurn();

View file

@ -136,10 +136,12 @@ void Training::recordPlayerMove(const Move &iMove, Player &ioPlayer)
void Training::start()
{
if (getNPlayers() != 0)
return;
m_currPlayer = 0;
firstPlayer();
// Dummy new turn, because the navigation prevents undoing the first turn.
// Since in this mode the player can set the rack, we cannot do like in the
// duplicate and free game modes, where we change turn just before a move
// is played...
accessNavigation().newTurn();
}