allow redo with Ctrl-Y

This commit is contained in:
krawthekrow 2016-09-12 15:22:23 +08:00 committed by jacob1
parent 63b2227802
commit 95d2014724
5 changed files with 57 additions and 8 deletions

View File

@ -232,34 +232,60 @@ GameController::~GameController()
void GameController::HistoryRestore()
{
std::deque<Snapshot*> history = gameModel->GetHistory();
if(history.size())
unsigned int historyPosition = gameModel->GetHistoryPosition();
if(historyPosition > 0 && historyPosition <= history.size())
{
Snapshot * snap = history.back();
gameModel->GetSimulation()->Restore(*snap);
if(history.size()>1)
if (historyPosition == history.size())
{
history.pop_back();
delete snap;
gameModel->SetHistory(history);
Snapshot * newSnap = gameModel->GetSimulation()->CreateSnapshot();
history.push_back(newSnap);
}
Snapshot * snap = history[historyPosition - 1];
gameModel->GetSimulation()->Restore(*snap);
gameModel->SetHistory(history);
gameModel->SetHistoryPosition(historyPosition - 1);
}
}
void GameController::HistorySnapshot()
{
std::deque<Snapshot*> history = gameModel->GetHistory();
unsigned int historyPosition = gameModel->GetHistoryPosition();
Snapshot * newSnap = gameModel->GetSimulation()->CreateSnapshot();
if(newSnap)
{
while (historyPosition < history.size())
{
Snapshot * snap = history.back();
history.pop_back();
delete snap;
}
if(history.size() >= 1) //History limit is current 1
{
Snapshot * snap = history.front();
history.pop_front();
//snap->Particles.clear();
delete snap;
if (historyPosition > history.size())
{
historyPosition--;
}
}
history.push_back(newSnap);
gameModel->SetHistory(history);
gameModel->SetHistoryPosition(historyPosition + 1);
}
}
void GameController::HistoryForward()
{
std::deque<Snapshot*> history = gameModel->GetHistory();
unsigned int historyPosition = gameModel->GetHistoryPosition();
if(historyPosition < history.size() - 1)
{
Snapshot * snap = history[historyPosition + 1];
gameModel->GetSimulation()->Restore(*snap);
gameModel->SetHistoryPosition(historyPosition + 1);
}
}

View File

@ -73,6 +73,7 @@ public:
void HistoryRestore();
void HistorySnapshot();
void HistoryForward();
void AdjustGridSize(int direction);
void InvertAirSim();

View File

@ -28,6 +28,7 @@ GameModel::GameModel():
currentFile(NULL),
currentUser(0, ""),
toolStrength(1.0f),
historyPosition(0),
activeColourPreset(0),
colourSelector(false),
colour(255, 0, 0, 255),
@ -423,11 +424,22 @@ std::deque<Snapshot*> GameModel::GetHistory()
{
return history;
}
unsigned int GameModel::GetHistoryPosition()
{
return historyPosition;
}
void GameModel::SetHistory(std::deque<Snapshot*> newHistory)
{
history = newHistory;
}
void GameModel::SetHistoryPosition(unsigned int newHistoryPosition)
{
historyPosition = newHistoryPosition;
}
void GameModel::SetVote(int direction)
{
if(currentSave)

View File

@ -65,6 +65,7 @@ private:
User currentUser;
float toolStrength;
std::deque<Snapshot*> history;
unsigned int historyPosition;
size_t activeColourPreset;
std::vector<ui::Colour> colourPresets;
@ -129,7 +130,9 @@ public:
void BuildQuickOptionMenu(GameController * controller);
std::deque<Snapshot*> GetHistory();
unsigned int GetHistoryPosition();
void SetHistory(std::deque<Snapshot*> newHistory);
void SetHistoryPosition(unsigned int newHistoryPosition);
void UpdateQuickOptions();

View File

@ -1545,7 +1545,14 @@ void GameView::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool
}
break;
case 'y':
c->SwitchAir();
if (ctrl)
{
c->HistoryForward();
}
else
{
c->SwitchAir();
}
break;
case SDLK_ESCAPE:
case 'q':