summaryrefslogtreecommitdiff
path: root/src/game
diff options
context:
space:
mode:
authorSimon Robertshaw <simon@hardwired.org.uk>2012-01-30 00:40:28 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2012-01-30 00:40:28 (GMT)
commit259fc2bcf75d754af043a5d3fa39b6ee0c0b1dec (patch)
treef0fe2c14499345121371bba0ecc3fe21d17e0953 /src/game
parentfe329e9127ebcb8c89c505c4c120e175810d280c (diff)
downloadpowder-259fc2bcf75d754af043a5d3fa39b6ee0c0b1dec.zip
powder-259fc2bcf75d754af043a5d3fa39b6ee0c0b1dec.tar.gz
ASCII for key events, save and Textarea (no caret, yet)
Diffstat (limited to 'src/game')
-rw-r--r--src/game/GameController.cpp42
-rw-r--r--src/game/GameController.h3
-rw-r--r--src/game/GameView.cpp6
-rw-r--r--src/game/GameView.h8
4 files changed, 51 insertions, 8 deletions
diff --git a/src/game/GameController.cpp b/src/game/GameController.cpp
index 65556db..fd3572f 100644
--- a/src/game/GameController.cpp
+++ b/src/game/GameController.cpp
@@ -9,6 +9,7 @@
#include "render/RenderController.h"
#include "login/LoginController.h"
#include "interface/Point.h"
+#include "dialogues/ErrorMessage.h"
using namespace std;
@@ -50,10 +51,26 @@ public:
}
};
+class GameController::SSaveCallback: public ControllerCallback
+{
+ GameController * cc;
+public:
+ SSaveCallback(GameController * cc_) { cc = cc_; }
+ virtual void ControllerExit()
+ {
+ if(cc->ssave->GetSaveUploaded())
+ {
+ cc->gameModel->SetSave(new Save(*(cc->ssave->GetSave())));
+ }
+ //cc->gameModel->SetUser(cc->loginWindow->GetUser());
+ }
+};
+
GameController::GameController():
search(NULL),
renderOptions(NULL),
- loginWindow(NULL)
+ loginWindow(NULL),
+ ssave(NULL)
{
gameView = new GameView();
gameModel = new GameModel();
@@ -267,7 +284,28 @@ void GameController::OpenRenderOptions()
void GameController::OpenSaveWindow()
{
- //TODO: Implement
+ if(gameModel->GetUser().ID)
+ {
+ if(gameModel->GetSave())
+ {
+ Save tempSave(*gameModel->GetSave());
+ int tempSaveLength;
+ tempSave.SetData(gameModel->GetSimulation()->Save(tempSaveLength));
+ ssave = new SSaveController(new SSaveCallback(this), tempSave);
+ }
+ else
+ {
+ Save tempSave(0, 0, 0, 0, gameModel->GetUser().Username, "");
+ int tempSaveLength;
+ tempSave.SetData(gameModel->GetSimulation()->Save(tempSaveLength));
+ ssave = new SSaveController(new SSaveCallback(this), tempSave);
+ }
+ ui::Engine::Ref().ShowWindow(ssave->GetView());
+ }
+ else
+ {
+ new ErrorMessage("Error", "You need to login to upload saves.");
+ }
}
void GameController::Vote(int direction)
diff --git a/src/game/GameController.h b/src/game/GameController.h
index 7498e47..43c9bb2 100644
--- a/src/game/GameController.h
+++ b/src/game/GameController.h
@@ -9,6 +9,7 @@
#include "search/SearchController.h"
#include "render/RenderController.h"
#include "login/LoginController.h"
+#include "ssave/SSaveController.h"
#include "Menu.h"
using namespace std;
@@ -24,10 +25,12 @@ private:
SearchController * search;
RenderController * renderOptions;
LoginController * loginWindow;
+ SSaveController * ssave;
public:
class LoginCallback;
class SearchCallback;
class RenderCallback;
+ class SSaveCallback;
GameController();
~GameController();
GameView * GetView();
diff --git a/src/game/GameView.cpp b/src/game/GameView.cpp
index 9a2eb2d..560b1d5 100644
--- a/src/game/GameView.cpp
+++ b/src/game/GameView.cpp
@@ -340,6 +340,7 @@ void GameView::NotifySaveChanged(GameModel * sender)
{
if(sender->GetSave())
{
+ saveSimulationButton->SetText(sender->GetSave()->GetName());
reloadButton->Enabled = true;
upVoteButton->Enabled = (sender->GetSave()->GetID() && sender->GetUser().ID && sender->GetSave()->GetVote()==0);
if(sender->GetSave()->GetID() && sender->GetUser().ID && sender->GetSave()->GetVote()==1)
@@ -355,6 +356,7 @@ void GameView::NotifySaveChanged(GameModel * sender)
}
else
{
+ saveSimulationButton->SetText("");
reloadButton->Enabled = false;
upVoteButton->Enabled = false;
upVoteButton->SetBackgroundColour(ui::Colour(0, 0, 0));
@@ -420,7 +422,7 @@ void GameView::OnMouseWheel(int x, int y, int d)
}
}
-void GameView::OnKeyPress(int key, bool shift, bool ctrl, bool alt)
+void GameView::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt)
{
switch(key)
{
@@ -438,7 +440,7 @@ void GameView::OnKeyPress(int key, bool shift, bool ctrl, bool alt)
}
}
-void GameView::OnKeyRelease(int key, bool shift, bool ctrl, bool alt)
+void GameView::OnKeyRelease(int key, Uint16 character, bool shift, bool ctrl, bool alt)
{
//switch(key)
//{
diff --git a/src/game/GameView.h b/src/game/GameView.h
index 610b953..1cd69c0 100644
--- a/src/game/GameView.h
+++ b/src/game/GameView.h
@@ -56,10 +56,10 @@ public:
virtual void OnMouseDown(int x, int y, unsigned button);
virtual void OnMouseUp(int x, int y, unsigned button);
virtual void OnMouseWheel(int x, int y, int d);
- virtual void OnKeyPress(int key, bool shift, bool ctrl, bool alt);
- virtual void OnKeyRelease(int key, bool shift, bool ctrl, bool alt);
- //virtual void OnKeyPress(int key, bool shift, bool ctrl, bool alt) {}
- //virtual void OnKeyRelease(int key, bool shift, bool ctrl, bool alt) {}
+ virtual void OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt);
+ virtual void OnKeyRelease(int key, Uint16 character, bool shift, bool ctrl, bool alt);
+ //virtual void OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt) {}
+ //virtual void OnKeyRelease(int key, Uint16 character, bool shift, bool ctrl, bool alt) {}
virtual void OnTick(float dt);
virtual void OnDraw();
class MenuAction;