From e2622657f076ef943d051593d0969306daf15f32 Mon Sep 17 00:00:00 2001 From: jacob1 Date: Fri, 19 Oct 2012 15:06:07 -0400 Subject: [PATCH] ability to reload and resave local saves without retyping name --- src/game/GameController.cpp | 24 ++++++++++++++++++++++-- src/game/GameModel.cpp | 24 +++++++++++++++++++++++- src/game/GameModel.h | 2 ++ src/game/GameView.cpp | 12 ++++++++++++ src/save/LocalSaveActivity.cpp | 6 ++++-- src/save/LocalSaveActivity.h | 11 ++++++++++- 6 files changed, 73 insertions(+), 6 deletions(-) diff --git a/src/game/GameController.cpp b/src/game/GameController.cpp index 99315b078..96f966cb7 100644 --- a/src/game/GameController.cpp +++ b/src/game/GameController.cpp @@ -925,9 +925,25 @@ void GameController::OpenLocalSaveWindow() } else { - SaveFile tempSave(""); + std::string filename = ""; + if (gameModel->GetFile()) + filename = gameModel->GetFile()->GetDisplayName(); + SaveFile tempSave(filename); tempSave.SetGameSave(gameSave); - new LocalSaveActivity(tempSave); + + class LocalSaveCallback: public FileSavedCallback + { + GameController * c; + public: + LocalSaveCallback(GameController * _c): c(_c) {} + virtual ~LocalSaveCallback() {}; + virtual void FileSaved(SaveFile* file) + { + c->gameModel->SetSaveFile(file); + } + }; + + new LocalSaveActivity(tempSave, new LocalSaveCallback(this)); } } @@ -1193,6 +1209,10 @@ void GameController::ReloadSim() { gameModel->SetSave(gameModel->GetSave()); } + else if(gameModel->GetFile() && gameModel->GetFile()->GetGameSave()) + { + gameModel->SetSaveFile(gameModel->GetFile()); + } } std::string GameController::ElementResolve(int type) diff --git a/src/game/GameModel.cpp b/src/game/GameModel.cpp index 49e031f4d..f905a1ccd 100644 --- a/src/game/GameModel.cpp +++ b/src/game/GameModel.cpp @@ -22,6 +22,7 @@ GameModel::GameModel(): currentBrush(0), currentUser(0, ""), currentSave(NULL), + currentFile(NULL), colourSelector(false), clipboard(NULL), stamp(NULL), @@ -159,6 +160,8 @@ GameModel::~GameModel() delete stamp; if(currentSave) delete currentSave; + if(currentFile) + delete currentFile; //if(activeTools) // delete[] activeTools; } @@ -536,6 +539,9 @@ void GameModel::SetSave(SaveInfo * newSave) else currentSave = new SaveInfo(*newSave); } + if(currentFile) + delete currentFile; + currentFile = NULL; if(currentSave && currentSave->GetGameSave()) { @@ -558,9 +564,25 @@ void GameModel::SetSave(SaveInfo * newSave) UpdateQuickOptions(); } +SaveFile * GameModel::GetFile() +{ + return currentFile; +} + void GameModel::SetSaveFile(SaveFile * newSave) { - SetSave(NULL); + if(currentFile != newSave) + { + if(currentFile) + delete currentFile; + if(newSave == NULL) + currentFile = NULL; + else + currentFile = new SaveFile(*newSave); + } + if (currentSave) + delete currentSave; + currentSave = NULL; if(newSave && newSave->GetGameSave()) { diff --git a/src/game/GameModel.h b/src/game/GameModel.h index 311f89c1e..b4c0bd3d6 100644 --- a/src/game/GameModel.h +++ b/src/game/GameModel.h @@ -57,6 +57,7 @@ private: int currentBrush; vector brushList; SaveInfo * currentSave; + SaveFile * currentFile; Simulation * sim; Renderer * ren; Tool * lastTool; @@ -143,6 +144,7 @@ public: void SetVote(int direction); SaveInfo * GetSave(); + SaveFile * GetFile(); Brush * GetBrush(); void SetSave(SaveInfo * newSave); void SetSaveFile(SaveFile * newSave); diff --git a/src/game/GameView.cpp b/src/game/GameView.cpp index 7ba1fe728..9a2f77260 100644 --- a/src/game/GameView.cpp +++ b/src/game/GameView.cpp @@ -847,6 +847,18 @@ void GameView::NotifySaveChanged(GameModel * sender) tagSimulationButton->SetText("[no tags set]"); } } + else if (sender->GetFile()) + { + ((SplitButton*)saveSimulationButton)->SetShowSplit(false); + saveSimulationButton->SetText(sender->GetFile()->GetDisplayName()); + reloadButton->Enabled = true; + upVoteButton->Enabled = false; + upVoteButton->Appearance.BackgroundInactive = (ui::Colour(0, 0, 0)); + downVoteButton->Enabled = false; + upVoteButton->Appearance.BackgroundInactive = (ui::Colour(0, 0, 0)); + tagSimulationButton->Enabled = false; + tagSimulationButton->SetText("[no tags set]"); + } else { ((SplitButton*)saveSimulationButton)->SetShowSplit(false); diff --git a/src/save/LocalSaveActivity.cpp b/src/save/LocalSaveActivity.cpp index 740fabee2..d2c4a2f5b 100644 --- a/src/save/LocalSaveActivity.cpp +++ b/src/save/LocalSaveActivity.cpp @@ -37,10 +37,11 @@ public: } }; -LocalSaveActivity::LocalSaveActivity(SaveFile save) : +LocalSaveActivity::LocalSaveActivity(SaveFile save, FileSavedCallback * callback) : WindowActivity(ui::Point(-1, -1), ui::Point(220, 200)), thumbnail(NULL), - save(save) + save(save), + callback(callback) { ui::Label * titleLabel = new ui::Label(ui::Point(4, 5), ui::Point(Size.X-8, 16), "Save to computer:"); titleLabel->SetTextColour(style::Colour::InformationTitle); @@ -117,6 +118,7 @@ void LocalSaveActivity::saveWrite(std::string finalFilename) mkdir(LOCAL_SAVE_DIR, 0755); #endif Client::Ref().WriteFile(save.GetGameSave()->Serialise(), finalFilename); + callback->FileSaved(&save); } void LocalSaveActivity::OnDraw() diff --git a/src/save/LocalSaveActivity.h b/src/save/LocalSaveActivity.h index b5d19f3d2..aacbc0b67 100644 --- a/src/save/LocalSaveActivity.h +++ b/src/save/LocalSaveActivity.h @@ -11,6 +11,14 @@ namespace ui class Thumbnail; +class FileSavedCallback +{ +public: + FileSavedCallback() {} + virtual ~FileSavedCallback() {} + virtual void FileSaved(SaveFile * file) {} +}; + class LocalSaveActivity: public WindowActivity, public ThumbnailListener { SaveFile save; @@ -20,8 +28,9 @@ class LocalSaveActivity: public WindowActivity, public ThumbnailListener class SaveAction; friend class CancelAction; friend class SaveAction; + FileSavedCallback * callback; public: - LocalSaveActivity(SaveFile save); + LocalSaveActivity(SaveFile save, FileSavedCallback * callback); void saveWrite(std::string finalFilename); virtual void Save(); virtual void OnDraw();