summaryrefslogtreecommitdiff
path: root/src/game/GameController.cpp
diff options
context:
space:
mode:
authorSimon Robertshaw <simon@hardwired.org.uk>2012-08-10 19:50:36 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2012-08-10 19:50:36 (GMT)
commit98209da0a561614033a727b55c4313ab67dea91c (patch)
tree3dc092c8765a67a1b8ebdd617c4403a45dd74b75 /src/game/GameController.cpp
parent150114c11fa65aa1c6c29abab8332bf6749da372 (diff)
downloadpowder-98209da0a561614033a727b55c4313ab67dea91c.zip
powder-98209da0a561614033a727b55c4313ab67dea91c.tar.gz
Save Open signs working
Diffstat (limited to 'src/game/GameController.cpp')
-rw-r--r--src/game/GameController.cpp75
1 files changed, 74 insertions, 1 deletions
diff --git a/src/game/GameController.cpp b/src/game/GameController.cpp
index 02dd4df..c3281b6 100644
--- a/src/game/GameController.cpp
+++ b/src/game/GameController.cpp
@@ -2,6 +2,7 @@
#include <iostream>
#include <queue>
#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 && 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)
@@ -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