mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-08-18 14:11:16 +02:00
ASCII for key events, save and Textarea (no caret, yet)
This commit is contained in:
@@ -148,4 +148,5 @@ extern unsigned char ZSIZE;
|
|||||||
#define DEBUG_PERFORMANCE_CALC 0x0008
|
#define DEBUG_PERFORMANCE_CALC 0x0008
|
||||||
#define DEBUG_PERFORMANCE_FRAME 0x0010
|
#define DEBUG_PERFORMANCE_FRAME 0x0010
|
||||||
|
|
||||||
|
#include "interface/Keys.h"
|
||||||
//#endif /* CONFIG_H_ */
|
//#endif /* CONFIG_H_ */
|
||||||
|
@@ -118,10 +118,10 @@ int main(int argc, char * argv[])
|
|||||||
engine->Exit();
|
engine->Exit();
|
||||||
break;
|
break;
|
||||||
case SDL_KEYDOWN:
|
case SDL_KEYDOWN:
|
||||||
engine->onKeyPress(event.key.keysym.unicode, false, false, false);
|
engine->onKeyPress(event.key.keysym.sym, event.key.keysym.unicode, event.key.keysym.mod&KEY_MOD_SHIFT, event.key.keysym.mod&KEY_MOD_CONTROL, event.key.keysym.mod&KEY_MOD_ALT);
|
||||||
break;
|
break;
|
||||||
case SDL_KEYUP:
|
case SDL_KEYUP:
|
||||||
engine->onKeyRelease(event.key.keysym.unicode, false, false, false);
|
engine->onKeyRelease(event.key.keysym.sym, event.key.keysym.unicode, event.key.keysym.mod&KEY_MOD_SHIFT, event.key.keysym.mod&KEY_MOD_CONTROL, event.key.keysym.mod&KEY_MOD_ALT);
|
||||||
break;
|
break;
|
||||||
case SDL_MOUSEMOTION:
|
case SDL_MOUSEMOTION:
|
||||||
engine->onMouseMove(event.motion.x, event.motion.y);
|
engine->onMouseMove(event.motion.x, event.motion.y);
|
||||||
|
@@ -51,6 +51,60 @@ User Client::GetAuthUser()
|
|||||||
return authUser;
|
return authUser;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RequestStatus Client::UploadSave(Save * save)
|
||||||
|
{
|
||||||
|
lastError = "";
|
||||||
|
int dataStatus;
|
||||||
|
char * data;
|
||||||
|
int dataLength = 0;
|
||||||
|
std::stringstream userIDStream;
|
||||||
|
userIDStream << authUser.ID;
|
||||||
|
if(authUser.ID)
|
||||||
|
{
|
||||||
|
char * postNames[] = { "Name", "Description", "Data:save.bin", "Publish", NULL };
|
||||||
|
char * postDatas[] = { (char *)(save->name.c_str()), (char *)(save->Description.c_str()), (char *)(save->GetData()), (char *)(save->Published?"Public":"Private") };
|
||||||
|
int postLengths[] = { save->name.length(), save->Description.length(), save->GetDataLength(), save->Published?6:7 };
|
||||||
|
//std::cout << postNames[0] << " " << postDatas[0] << " " << postLengths[0] << std::endl;
|
||||||
|
data = http_multipart_post("http://" SERVER "/Save.api", postNames, postDatas, postLengths, (char *)(userIDStream.str().c_str()), NULL, (char *)(authUser.SessionID.c_str()), &dataStatus, &dataLength);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
lastError = "Not authenticated";
|
||||||
|
return RequestFailure;
|
||||||
|
}
|
||||||
|
if(data && dataStatus == 200)
|
||||||
|
{
|
||||||
|
if(strncmp((const char *)data, "OK", 2)!=0)
|
||||||
|
{
|
||||||
|
free(data);
|
||||||
|
lastError = std::string((const char *)data);
|
||||||
|
return RequestFailure;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
int tempID;
|
||||||
|
std::stringstream saveIDStream((char *)(data+3));
|
||||||
|
saveIDStream >> tempID;
|
||||||
|
if(!tempID)
|
||||||
|
{
|
||||||
|
lastError = "Server did not return Save ID";
|
||||||
|
return RequestFailure;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
save->id = tempID;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
free(data);
|
||||||
|
return RequestOkay;
|
||||||
|
}
|
||||||
|
else if(data)
|
||||||
|
{
|
||||||
|
free(data);
|
||||||
|
}
|
||||||
|
return RequestFailure;
|
||||||
|
}
|
||||||
|
|
||||||
RequestStatus Client::ExecVote(int saveID, int direction)
|
RequestStatus Client::ExecVote(int saveID, int direction)
|
||||||
{
|
{
|
||||||
lastError = "";
|
lastError = "";
|
||||||
@@ -83,7 +137,6 @@ RequestStatus Client::ExecVote(int saveID, int direction)
|
|||||||
lastError = "Not authenticated";
|
lastError = "Not authenticated";
|
||||||
return RequestFailure;
|
return RequestFailure;
|
||||||
}
|
}
|
||||||
std::cout << data << std::endl;
|
|
||||||
if(data && dataStatus == 200)
|
if(data && dataStatus == 200)
|
||||||
{
|
{
|
||||||
if(strncmp((const char *)data, "OK", 2)!=0)
|
if(strncmp((const char *)data, "OK", 2)!=0)
|
||||||
|
@@ -38,6 +38,7 @@ public:
|
|||||||
~Client();
|
~Client();
|
||||||
|
|
||||||
RequestStatus ExecVote(int saveID, int direction);
|
RequestStatus ExecVote(int saveID, int direction);
|
||||||
|
RequestStatus UploadSave(Save * save);
|
||||||
|
|
||||||
unsigned char * GetSaveData(int saveID, int saveDate, int & dataLength);
|
unsigned char * GetSaveData(int saveID, int saveDate, int & dataLength);
|
||||||
LoginStatus Login(string username, string password, User & user);
|
LoginStatus Login(string username, string password, User & user);
|
||||||
|
@@ -9,6 +9,7 @@
|
|||||||
#include "render/RenderController.h"
|
#include "render/RenderController.h"
|
||||||
#include "login/LoginController.h"
|
#include "login/LoginController.h"
|
||||||
#include "interface/Point.h"
|
#include "interface/Point.h"
|
||||||
|
#include "dialogues/ErrorMessage.h"
|
||||||
|
|
||||||
using namespace std;
|
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():
|
GameController::GameController():
|
||||||
search(NULL),
|
search(NULL),
|
||||||
renderOptions(NULL),
|
renderOptions(NULL),
|
||||||
loginWindow(NULL)
|
loginWindow(NULL),
|
||||||
|
ssave(NULL)
|
||||||
{
|
{
|
||||||
gameView = new GameView();
|
gameView = new GameView();
|
||||||
gameModel = new GameModel();
|
gameModel = new GameModel();
|
||||||
@@ -267,7 +284,28 @@ void GameController::OpenRenderOptions()
|
|||||||
|
|
||||||
void GameController::OpenSaveWindow()
|
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)
|
void GameController::Vote(int direction)
|
||||||
|
@@ -9,6 +9,7 @@
|
|||||||
#include "search/SearchController.h"
|
#include "search/SearchController.h"
|
||||||
#include "render/RenderController.h"
|
#include "render/RenderController.h"
|
||||||
#include "login/LoginController.h"
|
#include "login/LoginController.h"
|
||||||
|
#include "ssave/SSaveController.h"
|
||||||
#include "Menu.h"
|
#include "Menu.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
@@ -24,10 +25,12 @@ private:
|
|||||||
SearchController * search;
|
SearchController * search;
|
||||||
RenderController * renderOptions;
|
RenderController * renderOptions;
|
||||||
LoginController * loginWindow;
|
LoginController * loginWindow;
|
||||||
|
SSaveController * ssave;
|
||||||
public:
|
public:
|
||||||
class LoginCallback;
|
class LoginCallback;
|
||||||
class SearchCallback;
|
class SearchCallback;
|
||||||
class RenderCallback;
|
class RenderCallback;
|
||||||
|
class SSaveCallback;
|
||||||
GameController();
|
GameController();
|
||||||
~GameController();
|
~GameController();
|
||||||
GameView * GetView();
|
GameView * GetView();
|
||||||
|
@@ -340,6 +340,7 @@ void GameView::NotifySaveChanged(GameModel * sender)
|
|||||||
{
|
{
|
||||||
if(sender->GetSave())
|
if(sender->GetSave())
|
||||||
{
|
{
|
||||||
|
saveSimulationButton->SetText(sender->GetSave()->GetName());
|
||||||
reloadButton->Enabled = true;
|
reloadButton->Enabled = true;
|
||||||
upVoteButton->Enabled = (sender->GetSave()->GetID() && sender->GetUser().ID && sender->GetSave()->GetVote()==0);
|
upVoteButton->Enabled = (sender->GetSave()->GetID() && sender->GetUser().ID && sender->GetSave()->GetVote()==0);
|
||||||
if(sender->GetSave()->GetID() && sender->GetUser().ID && sender->GetSave()->GetVote()==1)
|
if(sender->GetSave()->GetID() && sender->GetUser().ID && sender->GetSave()->GetVote()==1)
|
||||||
@@ -355,6 +356,7 @@ void GameView::NotifySaveChanged(GameModel * sender)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
saveSimulationButton->SetText("");
|
||||||
reloadButton->Enabled = false;
|
reloadButton->Enabled = false;
|
||||||
upVoteButton->Enabled = false;
|
upVoteButton->Enabled = false;
|
||||||
upVoteButton->SetBackgroundColour(ui::Colour(0, 0, 0));
|
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)
|
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)
|
//switch(key)
|
||||||
//{
|
//{
|
||||||
|
@@ -56,10 +56,10 @@ public:
|
|||||||
virtual void OnMouseDown(int x, int y, unsigned button);
|
virtual void OnMouseDown(int x, int y, unsigned button);
|
||||||
virtual void OnMouseUp(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 OnMouseWheel(int x, int y, int d);
|
||||||
virtual void OnKeyPress(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, bool shift, bool ctrl, bool alt);
|
virtual void OnKeyRelease(int key, Uint16 character, bool shift, bool ctrl, bool alt);
|
||||||
//virtual void OnKeyPress(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, 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 OnTick(float dt);
|
||||||
virtual void OnDraw();
|
virtual void OnDraw();
|
||||||
class MenuAction;
|
class MenuAction;
|
||||||
|
@@ -94,11 +94,11 @@ void Component::Tick(float dt)
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void Component::OnKeyPress(int key, bool shift, bool ctrl, bool alt)
|
void Component::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void Component::OnKeyRelease(int key, bool shift, bool ctrl, bool alt)
|
void Component::OnKeyRelease(int key, Uint16 character, bool shift, bool ctrl, bool alt)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -56,8 +56,8 @@ namespace ui
|
|||||||
void OnMouseUnclick(int localx, int localy, unsigned int button);
|
void OnMouseUnclick(int localx, int localy, unsigned int button);
|
||||||
void OnMouseWheel(int localx, int localy, int d);
|
void OnMouseWheel(int localx, int localy, int d);
|
||||||
void OnMouseWheelInside(int localx, int localy, int d);
|
void OnMouseWheelInside(int localx, int localy, int d);
|
||||||
void OnKeyPress(int key, bool shift, bool ctrl, bool alt);
|
void OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt);
|
||||||
void OnKeyRelease(int key, bool shift, bool ctrl, bool alt);
|
void OnKeyRelease(int key, Uint16 character, bool shift, bool ctrl, bool alt);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
///
|
///
|
||||||
@@ -185,7 +185,7 @@ namespace ui
|
|||||||
// ctrl: Control key is down.
|
// ctrl: Control key is down.
|
||||||
// alt: Alternate key is down.
|
// alt: Alternate key is down.
|
||||||
///
|
///
|
||||||
virtual void OnKeyPress(int key, bool shift, bool ctrl, bool alt);
|
virtual void OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt);
|
||||||
|
|
||||||
///
|
///
|
||||||
// Called: When a key is released.
|
// Called: When a key is released.
|
||||||
@@ -195,7 +195,7 @@ namespace ui
|
|||||||
// ctrl: Control key is released.
|
// ctrl: Control key is released.
|
||||||
// alt: Alternate key is released.
|
// alt: Alternate key is released.
|
||||||
///
|
///
|
||||||
virtual void OnKeyRelease(int key, bool shift, bool ctrl, bool alt);
|
virtual void OnKeyRelease(int key, Uint16 character, bool shift, bool ctrl, bool alt);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Window* parentstate_;
|
Window* parentstate_;
|
||||||
|
@@ -178,16 +178,16 @@ void Engine::Draw()
|
|||||||
g->Blit();
|
g->Blit();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Engine::onKeyPress(int key, bool shift, bool ctrl, bool alt)
|
void Engine::onKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt)
|
||||||
{
|
{
|
||||||
if(state_)
|
if(state_)
|
||||||
state_->DoKeyPress(key, shift, ctrl, alt);
|
state_->DoKeyPress(key, character, shift, ctrl, alt);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Engine::onKeyRelease(int key, bool shift, bool ctrl, bool alt)
|
void Engine::onKeyRelease(int key, Uint16 character, bool shift, bool ctrl, bool alt)
|
||||||
{
|
{
|
||||||
if(state_)
|
if(state_)
|
||||||
state_->DoKeyRelease(key, shift, ctrl, alt);
|
state_->DoKeyRelease(key, character, shift, ctrl, alt);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Engine::onMouseClick(int x, int y, unsigned button)
|
void Engine::onMouseClick(int x, int y, unsigned button)
|
||||||
|
@@ -29,8 +29,8 @@ namespace ui
|
|||||||
void onMouseClick(int x, int y, unsigned button);
|
void onMouseClick(int x, int y, unsigned button);
|
||||||
void onMouseUnclick(int x, int y, unsigned button);
|
void onMouseUnclick(int x, int y, unsigned button);
|
||||||
void onMouseWheel(int x, int y, int delta);
|
void onMouseWheel(int x, int y, int delta);
|
||||||
void onKeyPress(int key, bool shift, bool ctrl, bool alt);
|
void onKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt);
|
||||||
void onKeyRelease(int key, bool shift, bool ctrl, bool alt);
|
void onKeyRelease(int key, Uint16 character, bool shift, bool ctrl, bool alt);
|
||||||
void onResize(int newWidth, int newHeight);
|
void onResize(int newWidth, int newHeight);
|
||||||
void onClose();
|
void onClose();
|
||||||
|
|
||||||
|
@@ -7,3 +7,8 @@
|
|||||||
#define KEY_BACKSPACE SDLK_BACKSPACE
|
#define KEY_BACKSPACE SDLK_BACKSPACE
|
||||||
#define KEY_DELETE SDLK_DELETE
|
#define KEY_DELETE SDLK_DELETE
|
||||||
#define KEY_TAB SDLK_TAB
|
#define KEY_TAB SDLK_TAB
|
||||||
|
|
||||||
|
#define KEY_MOD_CONTROL KMOD_CTRL
|
||||||
|
#define KEY_MOD_ALT KMOD_ALT
|
||||||
|
#define KEY_MOD_SHIFT KMOD_SHIFT
|
||||||
|
|
||||||
|
@@ -116,14 +116,14 @@ void Panel::Tick(float dt)
|
|||||||
children[i]->Tick(dt);
|
children[i]->Tick(dt);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Panel::OnKeyPress(int key, bool shift, bool ctrl, bool alt)
|
void Panel::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt)
|
||||||
{
|
{
|
||||||
XOnKeyPress(key, shift, ctrl, alt);
|
XOnKeyPress(key, character, shift, ctrl, alt);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Panel::OnKeyRelease(int key, bool shift, bool ctrl, bool alt)
|
void Panel::OnKeyRelease(int key, Uint16 character, bool shift, bool ctrl, bool alt)
|
||||||
{
|
{
|
||||||
XOnKeyRelease(key, shift, ctrl, alt);
|
XOnKeyRelease(key, character, shift, ctrl, alt);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Panel::OnMouseClick(int localx, int localy, unsigned button)
|
void Panel::OnMouseClick(int localx, int localy, unsigned button)
|
||||||
@@ -339,11 +339,11 @@ void Panel::XTick(float dt)
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void Panel::XOnKeyPress(int key, bool shift, bool ctrl, bool alt)
|
void Panel::XOnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void Panel::XOnKeyRelease(int key, bool shift, bool ctrl, bool alt)
|
void Panel::XOnKeyRelease(int key, Uint16 character, bool shift, bool ctrl, bool alt)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -59,8 +59,8 @@ class Component;
|
|||||||
void OnMouseUnclick(int localx, int localy, unsigned button);
|
void OnMouseUnclick(int localx, int localy, unsigned button);
|
||||||
void OnMouseWheel(int localx, int localy, int d);
|
void OnMouseWheel(int localx, int localy, int d);
|
||||||
void OnMouseWheelInside(int localx, int localy, int d);
|
void OnMouseWheelInside(int localx, int localy, int d);
|
||||||
void OnKeyPress(int key, bool shift, bool ctrl, bool alt);
|
void OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt);
|
||||||
void OnKeyRelease(int key, bool shift, bool ctrl, bool alt);
|
void OnKeyRelease(int key, Uint16 character, bool shift, bool ctrl, bool alt);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// child components
|
// child components
|
||||||
@@ -82,8 +82,8 @@ class Component;
|
|||||||
void XOnMouseUnclick(int localx, int localy, unsigned int button);
|
void XOnMouseUnclick(int localx, int localy, unsigned int button);
|
||||||
void XOnMouseWheel(int localx, int localy, int d);
|
void XOnMouseWheel(int localx, int localy, int d);
|
||||||
void XOnMouseWheelInside(int localx, int localy, int d);
|
void XOnMouseWheelInside(int localx, int localy, int d);
|
||||||
void XOnKeyPress(int key, bool shift, bool ctrl, bool alt);
|
void XOnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt);
|
||||||
void XOnKeyRelease(int key, bool shift, bool ctrl, bool alt);
|
void XOnKeyRelease(int key, Uint16 character, bool shift, bool ctrl, bool alt);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Overridable. Called by XComponent::Tick()
|
// Overridable. Called by XComponent::Tick()
|
||||||
@@ -127,10 +127,10 @@ class Component;
|
|||||||
virtual void XOnMouseWheelInside(int localx, int localy, int d);
|
virtual void XOnMouseWheelInside(int localx, int localy, int d);
|
||||||
|
|
||||||
// Overridable. Called by XComponent::OnKeyPress()
|
// Overridable. Called by XComponent::OnKeyPress()
|
||||||
virtual void XOnKeyPress(int key, bool shift, bool ctrl, bool alt);
|
virtual void XOnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt);
|
||||||
|
|
||||||
// Overridable. Called by XComponent::OnKeyRelease()
|
// Overridable. Called by XComponent::OnKeyRelease()
|
||||||
virtual void XOnKeyRelease(int key, bool shift, bool ctrl, bool alt);
|
virtual void XOnKeyRelease(int key, Uint16 character, bool shift, bool ctrl, bool alt);
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
80
src/interface/Textarea.cpp
Normal file
80
src/interface/Textarea.cpp
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
/*
|
||||||
|
* Textarea.cpp
|
||||||
|
*
|
||||||
|
* Created on: Jan 29, 2012
|
||||||
|
* Author: Simon
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include "Textarea.h"
|
||||||
|
|
||||||
|
using namespace ui;
|
||||||
|
|
||||||
|
Textarea::Textarea(Point position, Point size, std::string textboxText):
|
||||||
|
Textbox(position, size, textboxText)
|
||||||
|
{
|
||||||
|
updateMultiline();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Textarea::SetText(std::string text)
|
||||||
|
{
|
||||||
|
this->text = text;
|
||||||
|
updateMultiline();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Textarea::updateMultiline()
|
||||||
|
{
|
||||||
|
char * rawText = (char*)malloc(text.length()+1);
|
||||||
|
memcpy(rawText, text.c_str(), text.length());
|
||||||
|
rawText[text.length()] = 0;
|
||||||
|
|
||||||
|
int currentWidth = 0;
|
||||||
|
char * lastSpace = NULL;
|
||||||
|
char * currentWord = rawText;
|
||||||
|
char * nextSpace;
|
||||||
|
while(true)
|
||||||
|
{
|
||||||
|
nextSpace = strchr(currentWord+1, ' ');
|
||||||
|
if(nextSpace)
|
||||||
|
nextSpace[0] = 0;
|
||||||
|
int width = Graphics::textwidth(currentWord);
|
||||||
|
if(width+currentWidth > Size.X-6)
|
||||||
|
{
|
||||||
|
currentWidth = width;
|
||||||
|
currentWord[0] = '\n';
|
||||||
|
}
|
||||||
|
else
|
||||||
|
currentWidth += width;
|
||||||
|
if(nextSpace)
|
||||||
|
nextSpace[0] = ' ';
|
||||||
|
if(!(currentWord = strchr(currentWord+1, ' ')))
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
textLines = rawText;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Textarea::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt)
|
||||||
|
{
|
||||||
|
Textbox::OnKeyPress(key, character, shift, ctrl, alt);
|
||||||
|
updateMultiline();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Textarea::Draw(const Point &screenPos)
|
||||||
|
{
|
||||||
|
Graphics * g = ui::Engine::Ref().g;
|
||||||
|
if(IsFocused())
|
||||||
|
{
|
||||||
|
g->drawrect(screenPos.X, screenPos.Y, Size.X, Size.Y, 255, 255, 255, 255);
|
||||||
|
g->drawtext(screenPos.X+3, screenPos.Y+3, textLines, 255, 255, 255, 255);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
g->drawrect(screenPos.X, screenPos.Y, Size.X, Size.Y, 160, 160, 160, 255);
|
||||||
|
g->drawtext(screenPos.X+3, screenPos.Y+3, textLines, 160, 160, 160, 255);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Textarea::~Textarea() {
|
||||||
|
// TODO Auto-generated destructor stub
|
||||||
|
}
|
||||||
|
|
33
src/interface/Textarea.h
Normal file
33
src/interface/Textarea.h
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* Textarea.h
|
||||||
|
*
|
||||||
|
* Created on: Jan 29, 2012
|
||||||
|
* Author: Simon
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef TEXTAREA_H_
|
||||||
|
#define TEXTAREA_H_
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
#include <sstream>
|
||||||
|
#include "Textbox.h"
|
||||||
|
|
||||||
|
namespace ui
|
||||||
|
{
|
||||||
|
|
||||||
|
class Textarea: public ui::Textbox
|
||||||
|
{
|
||||||
|
void updateMultiline();
|
||||||
|
std::string textLines;
|
||||||
|
public:
|
||||||
|
Textarea(Point position, Point size, std::string textboxText);
|
||||||
|
virtual void TextPosition() {}
|
||||||
|
virtual void SetText(std::string text);
|
||||||
|
virtual void OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt);
|
||||||
|
virtual void Draw(const Point& screenPos);
|
||||||
|
virtual ~Textarea();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* TEXTAREA_H_ */
|
@@ -9,19 +9,6 @@
|
|||||||
|
|
||||||
using namespace ui;
|
using namespace ui;
|
||||||
|
|
||||||
Textbox::Textbox(Window* parent_state, std::string textboxText):
|
|
||||||
Component(parent_state),
|
|
||||||
text(textboxText),
|
|
||||||
textPosition(ui::Point(0, 0)),
|
|
||||||
textVAlign(AlignMiddle),
|
|
||||||
textHAlign(AlignCentre),
|
|
||||||
actionCallback(NULL),
|
|
||||||
masked(false)
|
|
||||||
{
|
|
||||||
TextPosition();
|
|
||||||
cursor = text.length();
|
|
||||||
}
|
|
||||||
|
|
||||||
Textbox::Textbox(Point position, Point size, std::string textboxText):
|
Textbox::Textbox(Point position, Point size, std::string textboxText):
|
||||||
Component(position, size),
|
Component(position, size),
|
||||||
text(textboxText),
|
text(textboxText),
|
||||||
@@ -35,19 +22,6 @@ Textbox::Textbox(Point position, Point size, std::string textboxText):
|
|||||||
cursor = text.length();
|
cursor = text.length();
|
||||||
}
|
}
|
||||||
|
|
||||||
Textbox::Textbox(std::string textboxText):
|
|
||||||
Component(),
|
|
||||||
text(textboxText),
|
|
||||||
textPosition(ui::Point(0, 0)),
|
|
||||||
textVAlign(AlignMiddle),
|
|
||||||
textHAlign(AlignCentre),
|
|
||||||
actionCallback(NULL),
|
|
||||||
masked(false)
|
|
||||||
{
|
|
||||||
TextPosition();
|
|
||||||
cursor = text.length();
|
|
||||||
}
|
|
||||||
|
|
||||||
Textbox::~Textbox()
|
Textbox::~Textbox()
|
||||||
{
|
{
|
||||||
if(actionCallback)
|
if(actionCallback)
|
||||||
@@ -105,7 +79,7 @@ std::string Textbox::GetText()
|
|||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Textbox::OnKeyPress(int key, bool shift, bool ctrl, bool alt)
|
void Textbox::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt)
|
||||||
{
|
{
|
||||||
bool changed = false;
|
bool changed = false;
|
||||||
try
|
try
|
||||||
@@ -152,22 +126,20 @@ void Textbox::OnKeyPress(int key, bool shift, bool ctrl, bool alt)
|
|||||||
changed = true;
|
changed = true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
}
|
||||||
if(key >= ' ' && key < 127)
|
if(character >= ' ' && character < 127)
|
||||||
|
{
|
||||||
|
if(cursor == text.length())
|
||||||
{
|
{
|
||||||
if(cursor == text.length())
|
text += character;
|
||||||
{
|
//std::cout << key << std::endl;
|
||||||
text += key;
|
|
||||||
//std::cout << key << std::endl;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
text.insert(cursor, 1, (char)key);
|
|
||||||
}
|
|
||||||
cursor++;
|
|
||||||
changed = true;
|
|
||||||
}
|
}
|
||||||
break;
|
else
|
||||||
|
{
|
||||||
|
text.insert(cursor, 1, (char)character);
|
||||||
|
}
|
||||||
|
cursor++;
|
||||||
|
changed = true;
|
||||||
}
|
}
|
||||||
if(changed && actionCallback)
|
if(changed && actionCallback)
|
||||||
{
|
{
|
||||||
|
@@ -17,6 +17,7 @@ public:
|
|||||||
};
|
};
|
||||||
class Textbox : public Component
|
class Textbox : public Component
|
||||||
{
|
{
|
||||||
|
protected:
|
||||||
std::string text;
|
std::string text;
|
||||||
ui::Point textPosition;
|
ui::Point textPosition;
|
||||||
HorizontalAlignment textHAlign;
|
HorizontalAlignment textHAlign;
|
||||||
@@ -25,19 +26,17 @@ class Textbox : public Component
|
|||||||
TextboxAction *actionCallback;
|
TextboxAction *actionCallback;
|
||||||
bool masked;
|
bool masked;
|
||||||
public:
|
public:
|
||||||
Textbox(Window* parent_state, std::string textboxText);
|
|
||||||
Textbox(Point position, Point size, std::string textboxText);
|
Textbox(Point position, Point size, std::string textboxText);
|
||||||
Textbox(std::string textboxText);
|
|
||||||
virtual ~Textbox();
|
virtual ~Textbox();
|
||||||
|
|
||||||
void TextPosition();
|
virtual void TextPosition();
|
||||||
void SetText(std::string text);
|
virtual void SetText(std::string text);
|
||||||
std::string GetText();
|
std::string GetText();
|
||||||
HorizontalAlignment GetHAlignment() { return textHAlign; }
|
HorizontalAlignment GetHAlignment() { return textHAlign; }
|
||||||
VerticalAlignment GetVAlignment() { return textVAlign; }
|
VerticalAlignment GetVAlignment() { return textVAlign; }
|
||||||
void SetAlignment(HorizontalAlignment hAlign, VerticalAlignment vAlign) { textHAlign = hAlign; textVAlign = vAlign; TextPosition(); }
|
void SetAlignment(HorizontalAlignment hAlign, VerticalAlignment vAlign) { textHAlign = hAlign; textVAlign = vAlign; TextPosition(); }
|
||||||
void SetActionCallback(TextboxAction * action) { actionCallback = action; }
|
void SetActionCallback(TextboxAction * action) { actionCallback = action; }
|
||||||
virtual void OnKeyPress(int key, bool shift, bool ctrl, bool alt);
|
virtual void OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt);
|
||||||
|
|
||||||
void SetHidden(bool hidden) { masked = hidden; }
|
void SetHidden(bool hidden) { masked = hidden; }
|
||||||
bool GetHidden() { return masked; }
|
bool GetHidden() { return masked; }
|
||||||
|
@@ -140,28 +140,28 @@ void Window::DoTick(float dt)
|
|||||||
OnTick(dt);
|
OnTick(dt);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::DoKeyPress(int key, bool shift, bool ctrl, bool alt)
|
void Window::DoKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt)
|
||||||
{
|
{
|
||||||
//on key press
|
//on key press
|
||||||
if(focusedComponent_ != NULL)
|
if(focusedComponent_ != NULL)
|
||||||
{
|
{
|
||||||
if(!focusedComponent_->Locked)
|
if(!focusedComponent_->Locked)
|
||||||
focusedComponent_->OnKeyPress(key, shift, ctrl, alt);
|
focusedComponent_->OnKeyPress(key, character, shift, ctrl, alt);
|
||||||
}
|
}
|
||||||
|
|
||||||
OnKeyPress(key, shift, ctrl, alt);
|
OnKeyPress(key, character, shift, ctrl, alt);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::DoKeyRelease(int key, bool shift, bool ctrl, bool alt)
|
void Window::DoKeyRelease(int key, Uint16 character, bool shift, bool ctrl, bool alt)
|
||||||
{
|
{
|
||||||
//on key unpress
|
//on key unpress
|
||||||
if(focusedComponent_ != NULL)
|
if(focusedComponent_ != NULL)
|
||||||
{
|
{
|
||||||
if(!focusedComponent_->Locked)
|
if(!focusedComponent_->Locked)
|
||||||
focusedComponent_->OnKeyRelease(key, shift, ctrl, alt);
|
focusedComponent_->OnKeyRelease(key, character, shift, ctrl, alt);
|
||||||
}
|
}
|
||||||
|
|
||||||
OnKeyRelease(key, shift, ctrl, alt);
|
OnKeyRelease(key, character, shift, ctrl, alt);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::DoMouseDown(int x_, int y_, unsigned button)
|
void Window::DoMouseDown(int x_, int y_, unsigned button)
|
||||||
|
@@ -55,8 +55,8 @@ enum ChromeStyle
|
|||||||
virtual void DoMouseDown(int x, int y, unsigned button);
|
virtual void DoMouseDown(int x, int y, unsigned button);
|
||||||
virtual void DoMouseUp(int x, int y, unsigned button);
|
virtual void DoMouseUp(int x, int y, unsigned button);
|
||||||
virtual void DoMouseWheel(int x, int y, int d);
|
virtual void DoMouseWheel(int x, int y, int d);
|
||||||
virtual void DoKeyPress(int key, bool shift, bool ctrl, bool alt);
|
virtual void DoKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt);
|
||||||
virtual void DoKeyRelease(int key, bool shift, bool ctrl, bool alt);
|
virtual void DoKeyRelease(int key, Uint16 character, bool shift, bool ctrl, bool alt);
|
||||||
|
|
||||||
bool IsFocused(const Component* c) const;
|
bool IsFocused(const Component* c) const;
|
||||||
void FocusComponent(Component* c);
|
void FocusComponent(Component* c);
|
||||||
@@ -73,8 +73,8 @@ enum ChromeStyle
|
|||||||
virtual void OnMouseDown(int x, int y, unsigned button) {}
|
virtual void OnMouseDown(int x, int y, unsigned button) {}
|
||||||
virtual void OnMouseUp(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 OnMouseWheel(int x, int y, int d) {}
|
||||||
virtual void OnKeyPress(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, bool shift, bool ctrl, bool alt) {}
|
virtual void OnKeyRelease(int key, Uint16 character, bool shift, bool ctrl, bool alt) {}
|
||||||
std::vector<Component*> Components;
|
std::vector<Component*> Components;
|
||||||
Component* focusedComponent_;
|
Component* focusedComponent_;
|
||||||
ChromeStyle chrome;
|
ChromeStyle chrome;
|
||||||
|
@@ -21,7 +21,9 @@ public:
|
|||||||
|
|
||||||
SearchController::SearchController(ControllerCallback * callback):
|
SearchController::SearchController(ControllerCallback * callback):
|
||||||
activePreview(NULL),
|
activePreview(NULL),
|
||||||
HasExited(false)
|
HasExited(false),
|
||||||
|
nextQueryTime(0.0f),
|
||||||
|
nextQueryDone(true)
|
||||||
{
|
{
|
||||||
searchModel = new SearchModel();
|
searchModel = new SearchModel();
|
||||||
searchView = new SearchView();
|
searchView = new SearchView();
|
||||||
@@ -43,6 +45,11 @@ Save * SearchController::GetLoadedSave()
|
|||||||
|
|
||||||
void SearchController::Update()
|
void SearchController::Update()
|
||||||
{
|
{
|
||||||
|
if(!nextQueryDone && nextQueryTime < clock())
|
||||||
|
{
|
||||||
|
nextQueryDone = true;
|
||||||
|
searchModel->UpdateSaveList(1, nextQuery);
|
||||||
|
}
|
||||||
searchModel->Update();
|
searchModel->Update();
|
||||||
if(activePreview && activePreview->HasExited)
|
if(activePreview && activePreview->HasExited)
|
||||||
{
|
{
|
||||||
@@ -79,7 +86,10 @@ SearchController::~SearchController()
|
|||||||
|
|
||||||
void SearchController::DoSearch(std::string query)
|
void SearchController::DoSearch(std::string query)
|
||||||
{
|
{
|
||||||
searchModel->UpdateSaveList(1, query);
|
nextQuery = query;
|
||||||
|
nextQueryTime = clock()+(0.6 * CLOCKS_PER_SEC);
|
||||||
|
nextQueryDone = false;
|
||||||
|
//searchModel->UpdateSaveList(1, query);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SearchController::PrevPage()
|
void SearchController::PrevPage()
|
||||||
|
@@ -17,6 +17,10 @@ private:
|
|||||||
SearchView * searchView;
|
SearchView * searchView;
|
||||||
PreviewController * activePreview;
|
PreviewController * activePreview;
|
||||||
ControllerCallback * callback;
|
ControllerCallback * callback;
|
||||||
|
|
||||||
|
double nextQueryTime;
|
||||||
|
std::string nextQuery;
|
||||||
|
bool nextQueryDone;
|
||||||
public:
|
public:
|
||||||
class OpenCallback;
|
class OpenCallback;
|
||||||
bool HasExited;
|
bool HasExited;
|
||||||
|
@@ -124,6 +124,7 @@ void Gravity::gravity_update_async()
|
|||||||
void *Gravity::update_grav_async_helper(void * context)
|
void *Gravity::update_grav_async_helper(void * context)
|
||||||
{
|
{
|
||||||
((Gravity *)context)->update_grav_async();
|
((Gravity *)context)->update_grav_async();
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Gravity::update_grav_async()
|
void Gravity::update_grav_async()
|
||||||
|
55
src/ssave/SSaveController.cpp
Normal file
55
src/ssave/SSaveController.cpp
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
/*
|
||||||
|
* SSaveController.cpp
|
||||||
|
*
|
||||||
|
* Created on: Jan 29, 2012
|
||||||
|
* Author: Simon
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "SSaveController.h"
|
||||||
|
|
||||||
|
SSaveController::SSaveController(ControllerCallback * callback, Save save):
|
||||||
|
HasExited(false)
|
||||||
|
{
|
||||||
|
ssaveView = new SSaveView();
|
||||||
|
ssaveView->AttachController(this);
|
||||||
|
ssaveModel = new SSaveModel();
|
||||||
|
ssaveModel->AddObserver(ssaveView);
|
||||||
|
ssaveModel->SetSave(new Save(save));
|
||||||
|
|
||||||
|
this->callback = callback;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SSaveController::UploadSave(std::string saveName, std::string saveDescription, bool publish)
|
||||||
|
{
|
||||||
|
ssaveModel->UploadSave(saveName, saveDescription, publish);
|
||||||
|
}
|
||||||
|
|
||||||
|
Save * SSaveController::GetSave()
|
||||||
|
{
|
||||||
|
return ssaveModel->GetSave();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SSaveController::GetSaveUploaded()
|
||||||
|
{
|
||||||
|
return ssaveModel->GetSaveUploaded();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SSaveController::Update()
|
||||||
|
{
|
||||||
|
ssaveModel->Update();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SSaveController::Exit()
|
||||||
|
{
|
||||||
|
if(ui::Engine::Ref().GetWindow() == ssaveView)
|
||||||
|
ui::Engine::Ref().CloseWindow();
|
||||||
|
if(callback)
|
||||||
|
callback->ControllerExit();
|
||||||
|
HasExited = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
SSaveController::~SSaveController() {
|
||||||
|
if(ui::Engine::Ref().GetWindow() == ssaveView)
|
||||||
|
ui::Engine::Ref().CloseWindow();
|
||||||
|
}
|
||||||
|
|
34
src/ssave/SSaveController.h
Normal file
34
src/ssave/SSaveController.h
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
/*
|
||||||
|
* SSaveController.h
|
||||||
|
*
|
||||||
|
* Created on: Jan 29, 2012
|
||||||
|
* Author: Simon
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef SSAVECONTROLLER_H_
|
||||||
|
#define SSAVECONTROLLER_H_
|
||||||
|
|
||||||
|
#include "SSaveModel.h"
|
||||||
|
#include "SSaveView.h"
|
||||||
|
#include "Controller.h"
|
||||||
|
#include "search/Save.h"
|
||||||
|
|
||||||
|
class SSaveView;
|
||||||
|
class SSaveModel;
|
||||||
|
class SSaveController {
|
||||||
|
SSaveView * ssaveView;
|
||||||
|
SSaveModel * ssaveModel;
|
||||||
|
ControllerCallback * callback;
|
||||||
|
public:
|
||||||
|
bool HasExited;
|
||||||
|
SSaveController(ControllerCallback * callback, Save save);
|
||||||
|
Save * GetSave();
|
||||||
|
bool GetSaveUploaded();
|
||||||
|
void Exit();
|
||||||
|
void Update();
|
||||||
|
void UploadSave(std::string saveName, std::string saveDescription, bool publish);
|
||||||
|
SSaveView * GetView() { return ssaveView; }
|
||||||
|
virtual ~SSaveController();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* SSAVECONTROLLER_H_ */
|
85
src/ssave/SSaveModel.cpp
Normal file
85
src/ssave/SSaveModel.cpp
Normal file
@@ -0,0 +1,85 @@
|
|||||||
|
/*
|
||||||
|
* SSaveModel.cpp
|
||||||
|
*
|
||||||
|
* Created on: Jan 29, 2012
|
||||||
|
* Author: Simon
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "SSaveModel.h"
|
||||||
|
#include "client/Client.h"
|
||||||
|
|
||||||
|
SSaveModel::SSaveModel():
|
||||||
|
save(NULL),
|
||||||
|
saveUploaded(false)
|
||||||
|
{
|
||||||
|
// TODO Auto-generated constructor stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void SSaveModel::notifySaveChanged()
|
||||||
|
{
|
||||||
|
for(int i = 0; i < observers.size(); i++)
|
||||||
|
{
|
||||||
|
observers[i]->NotifySaveChanged(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SSaveModel::notifySaveUploadChanged()
|
||||||
|
{
|
||||||
|
for(int i = 0; i < observers.size(); i++)
|
||||||
|
{
|
||||||
|
observers[i]->NotifySaveUploadChanged(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SSaveModel::UploadSave(std::string saveName, std::string saveDescription, bool publish)
|
||||||
|
{
|
||||||
|
save->name = saveName;
|
||||||
|
save->Description = saveDescription;
|
||||||
|
save->Published = publish;
|
||||||
|
saveUploaded = false;
|
||||||
|
notifySaveUploadChanged();
|
||||||
|
|
||||||
|
if(Client::Ref().UploadSave(save) == RequestOkay)
|
||||||
|
{
|
||||||
|
saveUploaded = true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
saveUploaded = false;
|
||||||
|
}
|
||||||
|
notifySaveUploadChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SSaveModel::SetSave(Save * save)
|
||||||
|
{
|
||||||
|
this->save = save;
|
||||||
|
notifySaveChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
Save * SSaveModel::GetSave()
|
||||||
|
{
|
||||||
|
return this->save;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SSaveModel::GetSaveUploaded()
|
||||||
|
{
|
||||||
|
return saveUploaded;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SSaveModel::AddObserver(SSaveView * observer)
|
||||||
|
{
|
||||||
|
observers.push_back(observer);
|
||||||
|
observer->NotifySaveChanged(this);
|
||||||
|
observer->NotifySaveUploadChanged(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SSaveModel::Update()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
SSaveModel::~SSaveModel() {
|
||||||
|
delete save;
|
||||||
|
}
|
||||||
|
|
36
src/ssave/SSaveModel.h
Normal file
36
src/ssave/SSaveModel.h
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
/*
|
||||||
|
* SSaveModel.h
|
||||||
|
*
|
||||||
|
* Created on: Jan 29, 2012
|
||||||
|
* Author: Simon
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef SSAVEMODEL_H_
|
||||||
|
#define SSAVEMODEL_H_
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "SSaveView.h"
|
||||||
|
#include "search/Save.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
class SSaveView;
|
||||||
|
class SSaveModel {
|
||||||
|
vector<SSaveView*> observers;
|
||||||
|
Save * save;
|
||||||
|
void notifySaveChanged();
|
||||||
|
void notifySaveUploadChanged();
|
||||||
|
bool saveUploaded;
|
||||||
|
public:
|
||||||
|
SSaveModel();
|
||||||
|
void AddObserver(SSaveView * observer);
|
||||||
|
void Update();
|
||||||
|
Save * GetSave();
|
||||||
|
void SetSave(Save * save);
|
||||||
|
void UploadSave(std::string saveName, std::string saveDescription, bool publish);
|
||||||
|
bool GetSaveUploaded();
|
||||||
|
virtual ~SSaveModel();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* SSAVEMODEL_H_ */
|
92
src/ssave/SSaveView.cpp
Normal file
92
src/ssave/SSaveView.cpp
Normal file
@@ -0,0 +1,92 @@
|
|||||||
|
/*
|
||||||
|
* SSaveView.cpp
|
||||||
|
*
|
||||||
|
* Created on: Jan 29, 2012
|
||||||
|
* Author: Simon
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "SSaveView.h"
|
||||||
|
|
||||||
|
SSaveView::SSaveView():
|
||||||
|
ui::Window(ui::Point(-1, -1), ui::Point(200, 200)),
|
||||||
|
publishCheckbox(NULL),
|
||||||
|
saveButton(NULL),
|
||||||
|
closeButton(NULL),
|
||||||
|
nameField(NULL),
|
||||||
|
titleLabel(NULL),
|
||||||
|
descriptionField(NULL)
|
||||||
|
{
|
||||||
|
titleLabel = new ui::Label(ui::Point(2, 1), ui::Point(Size.X-4, 16), "Save to Server");
|
||||||
|
titleLabel->SetAlignment(AlignLeft, AlignBottom);
|
||||||
|
AddComponent(titleLabel);
|
||||||
|
|
||||||
|
nameField = new ui::Textbox(ui::Point(4, 18), ui::Point(Size.X-8, 16), "");
|
||||||
|
nameField->SetAlignment(AlignLeft, AlignBottom);
|
||||||
|
AddComponent(nameField);
|
||||||
|
|
||||||
|
descriptionField = new ui::Textarea(ui::Point(4, 54), ui::Point(Size.X-8, Size.Y-26-54), "");
|
||||||
|
AddComponent(descriptionField);
|
||||||
|
|
||||||
|
publishCheckbox = new ui::Checkbox(ui::Point(4, 36), ui::Point(Size.X-8, 16), "Publish");
|
||||||
|
AddComponent(publishCheckbox);
|
||||||
|
|
||||||
|
class CloseAction: public ui::ButtonAction
|
||||||
|
{
|
||||||
|
SSaveView * v;
|
||||||
|
public:
|
||||||
|
CloseAction(SSaveView * v_) { v = v_; };
|
||||||
|
void ActionCallback(ui::Button * sender)
|
||||||
|
{
|
||||||
|
v->c->Exit();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
closeButton = new ui::Button(ui::Point(0, Size.Y-16), ui::Point(50, 16), "Cancel");
|
||||||
|
closeButton->SetActionCallback(new CloseAction(this));
|
||||||
|
AddComponent(closeButton);
|
||||||
|
|
||||||
|
class SaveAction: public ui::ButtonAction
|
||||||
|
{
|
||||||
|
SSaveView * v;
|
||||||
|
public:
|
||||||
|
SaveAction(SSaveView * v_) { v = v_; };
|
||||||
|
void ActionCallback(ui::Button * sender)
|
||||||
|
{
|
||||||
|
v->c->UploadSave(v->nameField->GetText(), "", v->publishCheckbox->GetChecked());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
saveButton = new ui::Button(ui::Point(Size.X-50, Size.Y-16), ui::Point(50, 16), "Save");
|
||||||
|
saveButton->SetActionCallback(new SaveAction(this));
|
||||||
|
AddComponent(saveButton);
|
||||||
|
}
|
||||||
|
|
||||||
|
void SSaveView::NotifySaveChanged(SSaveModel * sender)
|
||||||
|
{
|
||||||
|
if(sender->GetSave())
|
||||||
|
{
|
||||||
|
nameField->SetText(sender->GetSave()->GetName());
|
||||||
|
publishCheckbox->SetChecked(sender->GetSave()->Published);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
nameField->SetText("");
|
||||||
|
//publishCheckbox->SetChecked(sender->GetSave()->GetPublished());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SSaveView::NotifySaveUploadChanged(SSaveModel * sender)
|
||||||
|
{
|
||||||
|
if(sender->GetSaveUploaded())
|
||||||
|
c->Exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SSaveView::OnDraw()
|
||||||
|
{
|
||||||
|
Graphics * g = ui::Engine::Ref().g;
|
||||||
|
|
||||||
|
g->clearrect(Position.X, Position.Y, Size.X, Size.Y);
|
||||||
|
g->drawrect(Position.X, Position.Y, Size.X, Size.Y, 200, 200, 200, 255);
|
||||||
|
}
|
||||||
|
|
||||||
|
SSaveView::~SSaveView() {
|
||||||
|
}
|
||||||
|
|
39
src/ssave/SSaveView.h
Normal file
39
src/ssave/SSaveView.h
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
/*
|
||||||
|
* SSaveView.h
|
||||||
|
*
|
||||||
|
* Created on: Jan 29, 2012
|
||||||
|
* Author: Simon
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef SSAVEVIEW_H_
|
||||||
|
#define SSAVEVIEW_H_
|
||||||
|
|
||||||
|
#include "interface/Window.h"
|
||||||
|
#include "interface/Label.h"
|
||||||
|
#include "interface/Button.h"
|
||||||
|
#include "interface/Textbox.h"
|
||||||
|
#include "interface/Textarea.h"
|
||||||
|
#include "interface/Checkbox.h"
|
||||||
|
#include "SSaveModel.h"
|
||||||
|
#include "SSaveController.h"
|
||||||
|
|
||||||
|
class SSaveController;
|
||||||
|
class SSaveModel;
|
||||||
|
class SSaveView: public ui::Window {
|
||||||
|
SSaveController * c;
|
||||||
|
ui::Checkbox * publishCheckbox;
|
||||||
|
ui::Button * saveButton;
|
||||||
|
ui::Button * closeButton;
|
||||||
|
ui::Textbox * nameField;
|
||||||
|
ui::Label * titleLabel;
|
||||||
|
ui::Textarea * descriptionField;
|
||||||
|
public:
|
||||||
|
SSaveView();
|
||||||
|
void AttachController(SSaveController * c_) { c = c_; };
|
||||||
|
void NotifySaveChanged(SSaveModel * sender);
|
||||||
|
void NotifySaveUploadChanged(SSaveModel * sender);
|
||||||
|
virtual void OnDraw();
|
||||||
|
virtual ~SSaveView();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* SSAVEVIEW_H_ */
|
Reference in New Issue
Block a user