From 98209da0a561614033a727b55c4313ab67dea91c Mon Sep 17 00:00:00 2001 From: Simon Robertshaw Date: Fri, 10 Aug 2012 20:50:36 +0100 Subject: [PATCH] Save Open signs working --- src/game/GameController.cpp | 75 ++++++++++++++++++++++++++++++- src/game/GameController.h | 5 +++ src/preview/PreviewController.cpp | 2 +- 3 files changed, 80 insertions(+), 2 deletions(-) diff --git a/src/game/GameController.cpp b/src/game/GameController.cpp index 02dd4df53..c3281b65c 100644 --- a/src/game/GameController.cpp +++ b/src/game/GameController.cpp @@ -2,6 +2,7 @@ #include #include #include "Config.h" +#include "Format.h" #include "GameController.h" #include "GameModel.h" #include "client/SaveInfo.h" @@ -57,6 +58,27 @@ public: } }; +class GameController::SaveOpenCallback: public ControllerCallback +{ + GameController * cc; +public: + SaveOpenCallback(GameController * cc_) { cc = cc_; } + virtual void ControllerExit() + { + if(cc->activePreview->GetDoOpen() && cc->activePreview->GetSave()) + { + try + { + cc->LoadSave(cc->activePreview->GetSave()); + } + catch(GameModelException & ex) + { + new ErrorMessage("Cannot open save", ex.what()); + } + } + } +}; + class GameController::RenderCallback: public ControllerCallback { @@ -114,6 +136,7 @@ GameController::GameController(): console(NULL), tagsWindow(NULL), options(NULL), + activePreview(NULL), HasDone(false) { gameView = new GameView(); @@ -151,6 +174,10 @@ GameController::~GameController() { delete console; } + if(activePreview) + { + delete activePreview; + } if(ui::Engine::Ref().GetWindow() == gameView) { ui::Engine::Ref().CloseWindow(); @@ -420,7 +447,41 @@ bool GameController::MouseDown(int x, int y, unsigned button) bool GameController::MouseUp(int x, int y, unsigned button) { - return commandInterface->OnMouseUp(x, y, button); + bool ret = commandInterface->OnMouseUp(x, y, button); + if(ret && yGetSimulation(); + for (std::vector::iterator iter = sim->signs.begin(), end = sim->signs.end(); iter != end; ++iter) + { + int signx, signy, signw, signh; + (*iter).pos(signx, signy, signw, signh); + if (x>=signx && x<=signx+signw && y>=signy && y<=signy+signh) + { + if (sregexp((*iter).text.c_str(), "^{c:[0-9]*|.*}$")==0) + { + const char * signText = (*iter).text.c_str(); + char buff[256]; + int sldr; + + memset(buff, 0, sizeof(buff)); + + for (sldr=3; signText[sldr] != '|'; sldr++) + buff[sldr-3] = signText[sldr]; + + buff[sldr-3] = '\0'; + + int tempSaveID = format::StringToNumber(std::string(buff)); + if(tempSaveID) + OpenSavePreview(tempSaveID, 0); + break; + } + } + } + } + } + return ret; } bool GameController::MouseWheel(int x, int y, int d) @@ -622,6 +683,12 @@ void GameController::Update() search = NULL; } + if(activePreview && activePreview->HasExited) + { + delete activePreview; + activePreview = NULL; + } + if(loginWindow && loginWindow->HasExited) { delete loginWindow; @@ -755,6 +822,12 @@ void GameController::LoadSave(SaveInfo * save) gameModel->SetSave(save); } +void GameController::OpenSavePreview(int saveID, int saveDate) +{ + activePreview = new PreviewController(saveID, new SaveOpenCallback(this)); + ui::Engine::Ref().ShowWindow(activePreview->GetView()); +} + void GameController::OpenLocalBrowse() { class LocalSaveOpenCallback: public FileSelectedCallback diff --git a/src/game/GameController.h b/src/game/GameController.h index b301032cc..963b50617 100644 --- a/src/game/GameController.h +++ b/src/game/GameController.h @@ -8,6 +8,7 @@ #include "simulation/Simulation.h" #include "search/SearchController.h" #include "render/RenderController.h" +#include "preview/PreviewController.h" #include "login/LoginController.h" #include "tags/TagsController.h" #include "console/ConsoleController.h" @@ -30,6 +31,7 @@ class GameController: public ClientListener { private: //Simulation * sim; + PreviewController * activePreview; GameView * gameView; GameModel * gameModel; SearchController * search; @@ -49,6 +51,8 @@ public: class TagsCallback; class StampsCallback; class OptionsCallback; + class SaveOpenCallback; + friend class SaveOpenCallback; GameController(); ~GameController(); GameView * GetView(); @@ -91,6 +95,7 @@ public: void OpenSearch(); void OpenLogin(); void OpenTags(); + void OpenSavePreview(int saveID, int saveDate); void OpenLocalSaveWindow(); void OpenLocalBrowse(); void OpenOptions(); diff --git a/src/preview/PreviewController.cpp b/src/preview/PreviewController.cpp index a922bc631..b81ccdab2 100644 --- a/src/preview/PreviewController.cpp +++ b/src/preview/PreviewController.cpp @@ -150,9 +150,9 @@ void PreviewController::Exit() { ui::Engine::Ref().CloseWindow(); } + HasExited = true; if(callback) callback->ControllerExit(); - HasExited = true; } PreviewController::~PreviewController() {