mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-03-22 15:19:52 +01:00
allow redo with Ctrl-Y
This commit is contained in:
parent
63b2227802
commit
95d2014724
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -73,6 +73,7 @@ public:
|
||||
|
||||
void HistoryRestore();
|
||||
void HistorySnapshot();
|
||||
void HistoryForward();
|
||||
|
||||
void AdjustGridSize(int direction);
|
||||
void InvertAirSim();
|
||||
|
@ -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)
|
||||
|
@ -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();
|
||||
|
||||
|
@ -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':
|
||||
|
Loading…
x
Reference in New Issue
Block a user