Save Open signs working

This commit is contained in:
Simon Robertshaw 2012-08-10 20:50:36 +01:00
parent 150114c11f
commit 98209da0a5
3 changed files with 80 additions and 2 deletions

View File

@ -2,6 +2,7 @@
#include <iostream> #include <iostream>
#include <queue> #include <queue>
#include "Config.h" #include "Config.h"
#include "Format.h"
#include "GameController.h" #include "GameController.h"
#include "GameModel.h" #include "GameModel.h"
#include "client/SaveInfo.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 class GameController::RenderCallback: public ControllerCallback
{ {
@ -114,6 +136,7 @@ GameController::GameController():
console(NULL), console(NULL),
tagsWindow(NULL), tagsWindow(NULL),
options(NULL), options(NULL),
activePreview(NULL),
HasDone(false) HasDone(false)
{ {
gameView = new GameView(); gameView = new GameView();
@ -151,6 +174,10 @@ GameController::~GameController()
{ {
delete console; delete console;
} }
if(activePreview)
{
delete activePreview;
}
if(ui::Engine::Ref().GetWindow() == gameView) if(ui::Engine::Ref().GetWindow() == gameView)
{ {
ui::Engine::Ref().CloseWindow(); 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) bool GameController::MouseUp(int x, int y, unsigned button)
{ {
return commandInterface->OnMouseUp(x, y, button); bool ret = commandInterface->OnMouseUp(x, y, button);
if(ret && y<YRES && x<XRES)
{
if (true)//If it's not a sign tool
{
Simulation * sim = gameModel->GetSimulation();
for (std::vector<sign>::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<int>(std::string(buff));
if(tempSaveID)
OpenSavePreview(tempSaveID, 0);
break;
}
}
}
}
}
return ret;
} }
bool GameController::MouseWheel(int x, int y, int d) bool GameController::MouseWheel(int x, int y, int d)
@ -622,6 +683,12 @@ void GameController::Update()
search = NULL; search = NULL;
} }
if(activePreview && activePreview->HasExited)
{
delete activePreview;
activePreview = NULL;
}
if(loginWindow && loginWindow->HasExited) if(loginWindow && loginWindow->HasExited)
{ {
delete loginWindow; delete loginWindow;
@ -755,6 +822,12 @@ void GameController::LoadSave(SaveInfo * save)
gameModel->SetSave(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() void GameController::OpenLocalBrowse()
{ {
class LocalSaveOpenCallback: public FileSelectedCallback class LocalSaveOpenCallback: public FileSelectedCallback

View File

@ -8,6 +8,7 @@
#include "simulation/Simulation.h" #include "simulation/Simulation.h"
#include "search/SearchController.h" #include "search/SearchController.h"
#include "render/RenderController.h" #include "render/RenderController.h"
#include "preview/PreviewController.h"
#include "login/LoginController.h" #include "login/LoginController.h"
#include "tags/TagsController.h" #include "tags/TagsController.h"
#include "console/ConsoleController.h" #include "console/ConsoleController.h"
@ -30,6 +31,7 @@ class GameController: public ClientListener
{ {
private: private:
//Simulation * sim; //Simulation * sim;
PreviewController * activePreview;
GameView * gameView; GameView * gameView;
GameModel * gameModel; GameModel * gameModel;
SearchController * search; SearchController * search;
@ -49,6 +51,8 @@ public:
class TagsCallback; class TagsCallback;
class StampsCallback; class StampsCallback;
class OptionsCallback; class OptionsCallback;
class SaveOpenCallback;
friend class SaveOpenCallback;
GameController(); GameController();
~GameController(); ~GameController();
GameView * GetView(); GameView * GetView();
@ -91,6 +95,7 @@ public:
void OpenSearch(); void OpenSearch();
void OpenLogin(); void OpenLogin();
void OpenTags(); void OpenTags();
void OpenSavePreview(int saveID, int saveDate);
void OpenLocalSaveWindow(); void OpenLocalSaveWindow();
void OpenLocalBrowse(); void OpenLocalBrowse();
void OpenOptions(); void OpenOptions();

View File

@ -150,9 +150,9 @@ void PreviewController::Exit()
{ {
ui::Engine::Ref().CloseWindow(); ui::Engine::Ref().CloseWindow();
} }
HasExited = true;
if(callback) if(callback)
callback->ControllerExit(); callback->ControllerExit();
HasExited = true;
} }
PreviewController::~PreviewController() { PreviewController::~PreviewController() {