Rename Save class to SaveInfo, introduce SaveFile for hanlding of local data (stamps and local saves). Rename Stamps browser to LocalBrowser, ready for sharing code with the local save browser
This commit is contained in:
parent
2e48fc6115
commit
61ed6e0276
@ -22,7 +22,7 @@
|
||||
|
||||
#include "interface/Point.h"
|
||||
|
||||
#include "search/Save.h"
|
||||
#include "client/SaveInfo.h"
|
||||
|
||||
Client::Client():
|
||||
authUser(0, "")
|
||||
@ -153,9 +153,11 @@ User Client::GetAuthUser()
|
||||
return authUser;
|
||||
}
|
||||
|
||||
RequestStatus Client::UploadSave(Save * save)
|
||||
RequestStatus Client::UploadSave(SaveInfo * save)
|
||||
{
|
||||
lastError = "";
|
||||
int gameDataLength;
|
||||
char * gameData = NULL;
|
||||
int dataStatus;
|
||||
char * data;
|
||||
int dataLength = 0;
|
||||
@ -163,9 +165,23 @@ RequestStatus Client::UploadSave(Save * save)
|
||||
userIDStream << authUser.ID;
|
||||
if(authUser.ID)
|
||||
{
|
||||
if(!save->GetGameSave())
|
||||
{
|
||||
lastError = "Empty game save";
|
||||
return RequestFailure;
|
||||
}
|
||||
|
||||
gameData = save->GetGameSave()->Serialise(gameDataLength);
|
||||
|
||||
if(!gameData)
|
||||
{
|
||||
lastError = "Cannot upload game save";
|
||||
return RequestFailure;
|
||||
}
|
||||
|
||||
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 };
|
||||
char * postDatas[] = { (char *)(save->name.c_str()), (char *)(save->Description.c_str()), gameData, (char *)(save->Published?"Public":"Private") };
|
||||
int postLengths[] = { save->name.length(), save->Description.length(), gameDataLength, 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);
|
||||
}
|
||||
@ -178,6 +194,7 @@ RequestStatus Client::UploadSave(Save * save)
|
||||
{
|
||||
if(strncmp((const char *)data, "OK", 2)!=0)
|
||||
{
|
||||
if(gameData) free(gameData);
|
||||
free(data);
|
||||
lastError = std::string((const char *)data);
|
||||
return RequestFailure;
|
||||
@ -198,16 +215,18 @@ RequestStatus Client::UploadSave(Save * save)
|
||||
}
|
||||
}
|
||||
free(data);
|
||||
if(gameData) free(gameData);
|
||||
return RequestOkay;
|
||||
}
|
||||
else if(data)
|
||||
{
|
||||
free(data);
|
||||
}
|
||||
if(gameData) free(gameData);
|
||||
return RequestFailure;
|
||||
}
|
||||
|
||||
Save * Client::GetStamp(string stampID)
|
||||
SaveFile * Client::GetStamp(string stampID)
|
||||
{
|
||||
std::ifstream stampFile;
|
||||
stampFile.open(string(STAMPS_DIR PATH_SEP + stampID + ".stm").c_str(), ios::binary);
|
||||
@ -221,10 +240,10 @@ Save * Client::GetStamp(string stampID)
|
||||
stampFile.read((char *)tempData, fileSize);
|
||||
stampFile.close();
|
||||
|
||||
|
||||
Save * tempSave = new Save(0, 0, 0, 0, "", stampID);
|
||||
tempSave->SetData(tempData, fileSize);
|
||||
return tempSave;
|
||||
SaveFile * file = new SaveFile(string(STAMPS_DIR PATH_SEP + stampID + ".stm").c_str());
|
||||
GameSave * tempSave = new GameSave((char *)tempData, fileSize);
|
||||
file->SetGameSave(tempSave);
|
||||
return file;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -245,7 +264,7 @@ void Client::DeleteStamp(string stampID)
|
||||
}
|
||||
}
|
||||
|
||||
string Client::AddStamp(Save * saveData)
|
||||
string Client::AddStamp(GameSave * saveData)
|
||||
{
|
||||
unsigned t=(unsigned)time(NULL);
|
||||
if (lastStampTime!=t)
|
||||
@ -267,9 +286,12 @@ string Client::AddStamp(Save * saveData)
|
||||
mkdir(STAMPS_DIR, 0755);
|
||||
#endif
|
||||
|
||||
int gameDataLength;
|
||||
char * gameData = saveData->Serialise(gameDataLength);
|
||||
|
||||
std::ofstream stampStream;
|
||||
stampStream.open(string(STAMPS_DIR PATH_SEP + saveID.str()+".stm").c_str(), ios::binary);
|
||||
stampStream.write((const char *)saveData->data, saveData->dataLength);
|
||||
stampStream.write((const char *)gameData, gameDataLength);
|
||||
stampStream.close();
|
||||
|
||||
stampIDs.push_back(saveID.str());
|
||||
@ -683,7 +705,7 @@ failure:
|
||||
return RequestFailure;
|
||||
}
|
||||
|
||||
Save * Client::GetSave(int saveID, int saveDate)
|
||||
SaveInfo * Client::GetSave(int saveID, int saveDate)
|
||||
{
|
||||
lastError = "";
|
||||
std::stringstream urlStream;
|
||||
@ -733,7 +755,7 @@ Save * Client::GetSave(int saveID, int saveDate)
|
||||
tempTags.push_back(tempTag.Value());
|
||||
}
|
||||
|
||||
Save * tempSave = new Save(
|
||||
SaveInfo * tempSave = new SaveInfo(
|
||||
tempID.Value(),
|
||||
tempDate.Value(),
|
||||
tempScoreUp.Value(),
|
||||
@ -849,11 +871,11 @@ std::vector<SaveComment*> * Client::GetComments(int saveID, int start, int count
|
||||
return commentArray;
|
||||
}
|
||||
|
||||
std::vector<Save*> * Client::SearchSaves(int start, int count, string query, string sort, std::string category, int & resultCount)
|
||||
std::vector<SaveInfo*> * Client::SearchSaves(int start, int count, string query, string sort, std::string category, int & resultCount)
|
||||
{
|
||||
lastError = "";
|
||||
resultCount = 0;
|
||||
std::vector<Save*> * saveArray = new std::vector<Save*>();
|
||||
std::vector<SaveInfo*> * saveArray = new std::vector<SaveInfo*>();
|
||||
std::stringstream urlStream;
|
||||
char * data;
|
||||
int dataStatus, dataLength;
|
||||
@ -904,7 +926,7 @@ std::vector<Save*> * Client::SearchSaves(int start, int count, string query, str
|
||||
json::String tempUsername = savesArray[j]["Username"];
|
||||
json::String tempName = savesArray[j]["Name"];
|
||||
saveArray->push_back(
|
||||
new Save(
|
||||
new SaveInfo(
|
||||
tempID.Value(),
|
||||
tempDate.Value(),
|
||||
tempScoreUp.Value(),
|
||||
|
@ -9,7 +9,8 @@
|
||||
#include "HTTP.h"
|
||||
#include "preview/Comment.h"
|
||||
#include "search/Thumbnail.h"
|
||||
#include "search/Save.h"
|
||||
#include "client/SaveInfo.h"
|
||||
#include "client/SaveFile.h"
|
||||
#include "Singleton.h"
|
||||
#include "User.h"
|
||||
|
||||
@ -52,21 +53,21 @@ public:
|
||||
~Client();
|
||||
|
||||
RequestStatus ExecVote(int saveID, int direction);
|
||||
RequestStatus UploadSave(Save * save);
|
||||
RequestStatus UploadSave(SaveInfo * save);
|
||||
|
||||
Save * GetStamp(string stampID);
|
||||
SaveFile * GetStamp(string stampID);
|
||||
void DeleteStamp(string stampID);
|
||||
string AddStamp(Save * saveData);
|
||||
string AddStamp(GameSave * saveData);
|
||||
vector<string> GetStamps();
|
||||
|
||||
unsigned char * GetSaveData(int saveID, int saveDate, int & dataLength);
|
||||
LoginStatus Login(string username, string password, User & user);
|
||||
void ClearThumbnailRequests();
|
||||
std::vector<Save*> * SearchSaves(int start, int count, string query, string sort, string category, int & resultCount);
|
||||
std::vector<SaveInfo*> * SearchSaves(int start, int count, string query, string sort, string category, int & resultCount);
|
||||
std::vector<SaveComment*> * GetComments(int saveID, int start, int count);
|
||||
Thumbnail * GetPreview(int saveID, int saveDate);
|
||||
Thumbnail * GetThumbnail(int saveID, int saveDate);
|
||||
Save * GetSave(int saveID, int saveDate);
|
||||
SaveInfo * GetSave(int saveID, int saveDate);
|
||||
RequestStatus DeleteSave(int saveID);
|
||||
RequestStatus ReportSave(int saveID, std::string message);
|
||||
RequestStatus UnpublishSave(int saveID);
|
||||
|
@ -11,7 +11,7 @@
|
||||
#include "Config.h"
|
||||
#include "bson/BSON.h"
|
||||
#include "GameSave.h"
|
||||
#include "SimulationData.h"
|
||||
#include "simulation/SimulationData.h"
|
||||
|
||||
GameSave::GameSave(GameSave & save) :
|
||||
waterEEnabled(save.waterEEnabled),
|
||||
@ -23,7 +23,8 @@ airMode(save.airMode),
|
||||
signs(save.signs)
|
||||
{
|
||||
setSize(save.width, save.height);
|
||||
|
||||
|
||||
particlesCount = save.particlesCount;
|
||||
copy(save.particles, save.particles+NPART, particles);
|
||||
copy(save.blockMapPtr, save.blockMapPtr+((height/CELL)*(width/CELL)), blockMapPtr);
|
||||
copy(save.fanVelXPtr, save.fanVelXPtr+((height/CELL)*(width/CELL)), fanVelXPtr);
|
||||
@ -52,6 +53,7 @@ void GameSave::setSize(int newWidth, int newHeight)
|
||||
this->width = (newWidth/CELL)*CELL;
|
||||
this->height = (newHeight/CELL)*CELL;
|
||||
|
||||
particlesCount = 0;
|
||||
particles = new Particle[NPART];
|
||||
blockMap = new unsigned char*[height/CELL];
|
||||
blockMapPtr = new unsigned char[(height/CELL)*(width/CELL)];
|
||||
@ -1458,4 +1460,4 @@ GameSave::~GameSave()
|
||||
delete[] fanVelY;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,8 +9,13 @@
|
||||
#define The_Powder_Toy_GameSave_h
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include "Config.h"
|
||||
#include "Misc.h"
|
||||
#include "simulation/StorageClasses.h"
|
||||
#include "simulation/Sign.h"
|
||||
#include "simulation/Particle.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
struct ParseException: public exception {
|
||||
enum ParseResult { OK = 0, Corrupt, WrongVersion, InvalidDimensions, InternalError, MissingElement };
|
||||
|
43
src/client/SaveFile.cpp
Normal file
43
src/client/SaveFile.cpp
Normal file
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* SaveFile.cpp
|
||||
*
|
||||
* Created on: Jun 6, 2012
|
||||
* Author: Simon
|
||||
*/
|
||||
|
||||
#include "SaveFile.h"
|
||||
|
||||
SaveFile::SaveFile(SaveFile & save):
|
||||
gameSave(NULL)
|
||||
{
|
||||
if(save.gameSave)
|
||||
gameSave = new GameSave(*save.gameSave);
|
||||
}
|
||||
|
||||
SaveFile::SaveFile(string filename):
|
||||
filename(filename),
|
||||
gameSave(NULL)
|
||||
{
|
||||
//Load file
|
||||
}
|
||||
|
||||
GameSave * SaveFile::GetGameSave()
|
||||
{
|
||||
return gameSave;
|
||||
}
|
||||
|
||||
void SaveFile::SetGameSave(GameSave * save)
|
||||
{
|
||||
gameSave = save;
|
||||
}
|
||||
|
||||
string SaveFile::GetName()
|
||||
{
|
||||
return filename;
|
||||
}
|
||||
|
||||
SaveFile::~SaveFile() {
|
||||
if(gameSave)
|
||||
delete gameSave;
|
||||
}
|
||||
|
31
src/client/SaveFile.h
Normal file
31
src/client/SaveFile.h
Normal file
@ -0,0 +1,31 @@
|
||||
/*
|
||||
* SaveFile.h
|
||||
*
|
||||
* Created on: Jun 6, 2012
|
||||
* Author: Simon
|
||||
*/
|
||||
|
||||
#ifndef SAVEFILE_H_
|
||||
#define SAVEFILE_H_
|
||||
|
||||
#include <string>
|
||||
#include "GameSave.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
class SaveFile {
|
||||
public:
|
||||
SaveFile(SaveFile & save);
|
||||
SaveFile(string filename);
|
||||
|
||||
GameSave * GetGameSave();
|
||||
void SetGameSave(GameSave * save);
|
||||
string GetName();
|
||||
|
||||
virtual ~SaveFile();
|
||||
private:
|
||||
GameSave * gameSave;
|
||||
string filename;
|
||||
};
|
||||
|
||||
#endif /* SAVEFILE_H_ */
|
103
src/client/SaveInfo.cpp
Normal file
103
src/client/SaveInfo.cpp
Normal file
@ -0,0 +1,103 @@
|
||||
/*
|
||||
* Save.cpp
|
||||
*
|
||||
* Created on: Jan 26, 2012
|
||||
* Author: Simon
|
||||
*/
|
||||
|
||||
#include "client/SaveInfo.h"
|
||||
#include "client/Client.h"
|
||||
|
||||
SaveInfo::SaveInfo(SaveInfo & save) :
|
||||
userName(save.userName), name(save.name), Description(save.Description), date(
|
||||
save.date), Published(save.Published), id(save.id), votesUp(
|
||||
save.votesUp), votesDown(save.votesDown), gameSave(NULL), vote(save.vote), tags(save.tags) {
|
||||
if(save.gameSave)
|
||||
gameSave = new GameSave(*save.gameSave);
|
||||
}
|
||||
|
||||
SaveInfo::SaveInfo(int _id, int _date, int _votesUp, int _votesDown, string _userName,
|
||||
string _name) :
|
||||
id(_id), votesUp(_votesUp), votesDown(_votesDown), userName(_userName), name(
|
||||
_name), Description("No description provided"), date(_date), Published(
|
||||
true), gameSave(NULL), vote(0), tags() {
|
||||
}
|
||||
|
||||
SaveInfo::SaveInfo(int _id, int date_, int _votesUp, int _votesDown, int _vote, string _userName,
|
||||
string _name, string description_, bool published_, vector<string> tags_) :
|
||||
id(_id), votesUp(_votesUp), votesDown(_votesDown), userName(_userName), name(
|
||||
_name), Description(description_), date(date_), Published(
|
||||
published_), gameSave(NULL), vote(_vote), tags(tags_) {
|
||||
}
|
||||
|
||||
SaveInfo::~SaveInfo()
|
||||
{
|
||||
if(gameSave)
|
||||
{
|
||||
delete gameSave;
|
||||
}
|
||||
}
|
||||
|
||||
void SaveInfo::SetName(string name) {
|
||||
this->name = name;
|
||||
}
|
||||
string SaveInfo::GetName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
void SaveInfo::SetVote(int vote)
|
||||
{
|
||||
this->vote = vote;
|
||||
}
|
||||
int SaveInfo::GetVote()
|
||||
{
|
||||
return vote;
|
||||
}
|
||||
|
||||
void SaveInfo::SetUserName(string userName) {
|
||||
this->userName = userName;
|
||||
}
|
||||
|
||||
string SaveInfo::GetUserName() {
|
||||
return userName;
|
||||
}
|
||||
|
||||
void SaveInfo::SetID(int id) {
|
||||
this->id = id;
|
||||
}
|
||||
int SaveInfo::GetID() {
|
||||
return id;
|
||||
}
|
||||
|
||||
void SaveInfo::SetVotesUp(int votesUp) {
|
||||
this->votesUp = votesUp;
|
||||
}
|
||||
int SaveInfo::GetVotesUp() {
|
||||
return votesUp;
|
||||
}
|
||||
|
||||
void SaveInfo::SetVotesDown(int votesDown) {
|
||||
this->votesDown = votesDown;
|
||||
}
|
||||
int SaveInfo::GetVotesDown() {
|
||||
return votesDown;
|
||||
}
|
||||
|
||||
void SaveInfo::SetTags(vector<string> tags)
|
||||
{
|
||||
this->tags = tags;
|
||||
}
|
||||
vector<string> SaveInfo::GetTags()
|
||||
{
|
||||
return tags;
|
||||
}
|
||||
|
||||
GameSave * SaveInfo::GetGameSave()
|
||||
{
|
||||
return gameSave;
|
||||
}
|
||||
|
||||
void SaveInfo::SetGameSave(GameSave * saveGame)
|
||||
{
|
||||
gameSave = saveGame;
|
||||
}
|
68
src/client/SaveInfo.h
Normal file
68
src/client/SaveInfo.h
Normal file
@ -0,0 +1,68 @@
|
||||
#ifndef SAVE_H
|
||||
#define SAVE_H
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <stdlib.h>
|
||||
#include <iostream>
|
||||
#include <string.h>
|
||||
#include "GameSave.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
class SaveInfo
|
||||
{
|
||||
private:
|
||||
public:
|
||||
int id;
|
||||
int date;
|
||||
int votesUp, votesDown;
|
||||
bool Favourite;
|
||||
|
||||
GameSave * gameSave;
|
||||
|
||||
SaveInfo(SaveInfo & save);
|
||||
|
||||
SaveInfo(int _id, int _date, int _votesUp, int _votesDown, string _userName, string _name);
|
||||
|
||||
SaveInfo(int _id, int date_, int _votesUp, int _votesDown, int _vote, string _userName, string _name, string description_, bool published_, vector<string> tags);
|
||||
|
||||
~SaveInfo();
|
||||
|
||||
string userName;
|
||||
string name;
|
||||
|
||||
string Description;
|
||||
|
||||
vector<string> tags;
|
||||
|
||||
int vote;
|
||||
|
||||
bool Published;
|
||||
|
||||
void SetName(string name);
|
||||
string GetName();
|
||||
|
||||
void SetUserName(string userName);
|
||||
string GetUserName();
|
||||
|
||||
void SetID(int id);
|
||||
int GetID();
|
||||
|
||||
void SetVote(int vote);
|
||||
int GetVote();
|
||||
|
||||
void SetVotesUp(int votesUp);
|
||||
int GetVotesUp();
|
||||
|
||||
void SetVotesDown(int votesDown);
|
||||
int GetVotesDown();
|
||||
|
||||
void SetTags(vector<string> tags);
|
||||
vector<string> GetTags();
|
||||
|
||||
GameSave * GetGameSave();
|
||||
void SetGameSave(GameSave * gameSave);
|
||||
};
|
||||
|
||||
#endif // SAVE_H
|
@ -4,7 +4,7 @@
|
||||
#include "Config.h"
|
||||
#include "GameController.h"
|
||||
#include "GameModel.h"
|
||||
#include "search/Save.h"
|
||||
#include "client/SaveInfo.h"
|
||||
#include "search/SearchController.h"
|
||||
#include "render/RenderController.h"
|
||||
#include "login/LoginController.h"
|
||||
@ -37,7 +37,7 @@ public:
|
||||
{
|
||||
try
|
||||
{
|
||||
cc->gameModel->SetSave(new Save(*(cc->search->GetLoadedSave())));
|
||||
cc->gameModel->SetSave(new SaveInfo(*(cc->search->GetLoadedSave())));
|
||||
}
|
||||
catch(GameModelException & ex)
|
||||
{
|
||||
@ -79,7 +79,7 @@ public:
|
||||
{
|
||||
if(cc->ssave->GetSaveUploaded())
|
||||
{
|
||||
cc->gameModel->SetSave(new Save(*(cc->ssave->GetSave())));
|
||||
cc->gameModel->SetSave(new SaveInfo(*(cc->ssave->GetSave())));
|
||||
|
||||
}
|
||||
//cc->gameModel->SetUser(cc->loginWindow->GetUser());
|
||||
@ -93,7 +93,7 @@ public:
|
||||
TagsCallback(GameController * cc_) { cc = cc_; }
|
||||
virtual void ControllerExit()
|
||||
{
|
||||
cc->gameModel->SetSave(new Save(*(cc->tagsWindow->GetSave())));
|
||||
cc->gameModel->SetSave(new SaveInfo(*(cc->tagsWindow->GetSave())));
|
||||
}
|
||||
};
|
||||
|
||||
@ -104,9 +104,9 @@ public:
|
||||
StampsCallback(GameController * cc_) { cc = cc_; }
|
||||
virtual void ControllerExit()
|
||||
{
|
||||
if(cc->stamps->GetStamp())
|
||||
if(cc->localBrowser->GetSave())
|
||||
{
|
||||
cc->gameModel->SetStamp(cc->stamps->GetStamp());
|
||||
cc->gameModel->SetStamp(cc->localBrowser->GetSave()->GetGameSave());
|
||||
}
|
||||
else
|
||||
cc->gameModel->SetStamp(NULL);
|
||||
@ -501,8 +501,8 @@ void GameController::OpenTags()
|
||||
|
||||
void GameController::OpenStamps()
|
||||
{
|
||||
stamps = new StampsController(new StampsCallback(this));
|
||||
ui::Engine::Ref().ShowWindow(stamps->GetView());
|
||||
localBrowser = new LocalBrowserController(new StampsCallback(this));
|
||||
ui::Engine::Ref().ShowWindow(localBrowser->GetView());
|
||||
}
|
||||
|
||||
void GameController::OpenOptions()
|
||||
@ -529,25 +529,23 @@ void GameController::OpenSaveWindow()
|
||||
{
|
||||
if(gameModel->GetUser().ID)
|
||||
{
|
||||
GameSave * tempSave = gameModel->GetSimulation()->Save();
|
||||
if(!tempSave)
|
||||
GameSave * gameSave = gameModel->GetSimulation()->Save();
|
||||
if(!gameSave)
|
||||
{
|
||||
new ErrorMessage("Error", "Unable to build save.");
|
||||
}
|
||||
else
|
||||
{
|
||||
int dataSize;
|
||||
unsigned char * tempData = (unsigned char*)tempSave->Serialise(dataSize);
|
||||
if(gameModel->GetSave())
|
||||
{
|
||||
Save tempSave(*gameModel->GetSave());
|
||||
tempSave.SetData(tempData, dataSize);
|
||||
SaveInfo tempSave(*gameModel->GetSave());
|
||||
tempSave.SetGameSave(gameSave);
|
||||
ssave = new SSaveController(new SSaveCallback(this), tempSave);
|
||||
}
|
||||
else
|
||||
{
|
||||
Save tempSave(0, 0, 0, 0, gameModel->GetUser().Username, "");
|
||||
tempSave.SetData(tempData, dataSize);
|
||||
SaveInfo tempSave(0, 0, 0, 0, gameModel->GetUser().Username, "");
|
||||
tempSave.SetGameSave(gameSave);
|
||||
ssave = new SSaveController(new SSaveCallback(this), tempSave);
|
||||
}
|
||||
ui::Engine::Ref().ShowWindow(ssave->GetView());
|
||||
@ -584,10 +582,9 @@ void GameController::ClearSim()
|
||||
|
||||
void GameController::ReloadSim()
|
||||
{
|
||||
if(gameModel->GetSave() && gameModel->GetSave()->GetData())
|
||||
if(gameModel->GetSave() && gameModel->GetSave()->GetGameSave())
|
||||
{
|
||||
GameSave * newSave = new GameSave((char*)gameModel->GetSave()->GetData(), gameModel->GetSave()->GetDataLength());
|
||||
gameModel->GetSimulation()->Load(newSave);
|
||||
gameModel->GetSimulation()->Load(gameModel->GetSave()->GetGameSave());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -12,7 +12,7 @@
|
||||
#include "ssave/SSaveController.h"
|
||||
#include "tags/TagsController.h"
|
||||
#include "console/ConsoleController.h"
|
||||
#include "stamps/StampsController.h"
|
||||
#include "localbrowser/LocalBrowserController.h"
|
||||
//#include "cat/TPTScriptInterface.h"
|
||||
#include "cat/LuaScriptInterface.h"
|
||||
#include "options/OptionsController.h"
|
||||
@ -36,7 +36,7 @@ private:
|
||||
SSaveController * ssave;
|
||||
ConsoleController * console;
|
||||
TagsController * tagsWindow;
|
||||
StampsController * stamps;
|
||||
LocalBrowserController * localBrowser;
|
||||
OptionsController * options;
|
||||
CommandInterface * commandInterface;
|
||||
public:
|
||||
|
@ -263,20 +263,19 @@ vector<Menu*> GameModel::GetMenuList()
|
||||
return menuList;
|
||||
}
|
||||
|
||||
Save * GameModel::GetSave()
|
||||
SaveInfo * GameModel::GetSave()
|
||||
{
|
||||
return currentSave;
|
||||
}
|
||||
|
||||
void GameModel::SetSave(Save * newSave)
|
||||
void GameModel::SetSave(SaveInfo * newSave)
|
||||
{
|
||||
if(currentSave)
|
||||
delete currentSave;
|
||||
currentSave = newSave;
|
||||
if(currentSave)
|
||||
{
|
||||
GameSave * newSave = new GameSave((char*)currentSave->GetData(), currentSave->GetDataLength());
|
||||
int returnVal = sim->Load(newSave);
|
||||
int returnVal = sim->Load(currentSave->GetGameSave());
|
||||
if(returnVal){
|
||||
delete currentSave;
|
||||
currentSave = NULL;
|
||||
@ -430,15 +429,11 @@ void GameModel::ClearSimulation()
|
||||
sim->clear_sim();
|
||||
}
|
||||
|
||||
void GameModel::SetStamp(Save * save)
|
||||
void GameModel::SetStamp(GameSave * save)
|
||||
{
|
||||
if(stamp)
|
||||
delete stamp;
|
||||
try {
|
||||
stamp = new GameSave((char*)save->GetData(), save->GetDataLength());
|
||||
} catch (ParseException& e) {
|
||||
stamp = NULL;
|
||||
}
|
||||
stamp = new GameSave(*save);
|
||||
notifyStampChanged();
|
||||
}
|
||||
|
||||
@ -446,16 +441,8 @@ void GameModel::AddStamp(GameSave * save)
|
||||
{
|
||||
if(stamp)
|
||||
delete stamp;
|
||||
stamp = save;
|
||||
|
||||
char * saveData;
|
||||
int saveSize;
|
||||
saveData = save->Serialise(saveSize);
|
||||
Save * tempSave = new Save(0, 0, 0, 0, "", "");
|
||||
tempSave->SetData((unsigned char*)saveData, saveSize);
|
||||
Client::Ref().AddStamp(tempSave);
|
||||
delete tempSave;
|
||||
|
||||
stamp = new GameSave(*save);
|
||||
Client::Ref().AddStamp(save);
|
||||
notifyClipboardChanged();
|
||||
}
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
#include <vector>
|
||||
#include <deque>
|
||||
#include "search/Save.h"
|
||||
#include "client/SaveInfo.h"
|
||||
#include "simulation/Simulation.h"
|
||||
#include "interface/Colour.h"
|
||||
#include "Renderer.h"
|
||||
@ -43,7 +43,7 @@ private:
|
||||
Menu * activeMenu;
|
||||
int currentBrush;
|
||||
vector<Brush *> brushList;
|
||||
Save * currentSave;
|
||||
SaveInfo * currentSave;
|
||||
Simulation * sim;
|
||||
Renderer * ren;
|
||||
Tool * activeTools[3];
|
||||
@ -78,9 +78,9 @@ public:
|
||||
ui::Colour GetColourSelectorColour();
|
||||
|
||||
void SetVote(int direction);
|
||||
Save * GetSave();
|
||||
SaveInfo * GetSave();
|
||||
Brush * GetBrush();
|
||||
void SetSave(Save * newSave);
|
||||
void SetSave(SaveInfo * newSave);
|
||||
void AddObserver(GameView * observer);
|
||||
Tool * GetActiveTool(int selection);
|
||||
void SetActiveTool(int selection, Tool * tool);
|
||||
@ -110,7 +110,7 @@ public:
|
||||
ui::Point GetZoomPosition();
|
||||
void SetZoomWindowPosition(ui::Point position);
|
||||
ui::Point GetZoomWindowPosition();
|
||||
void SetStamp(Save * newStamp);
|
||||
void SetStamp(GameSave * newStamp);
|
||||
void AddStamp(GameSave * save);
|
||||
void SetClipboard(GameSave * save);
|
||||
void Log(string message);
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include <iostream>
|
||||
|
||||
#include "SaveButton.h"
|
||||
#include "search/Save.h"
|
||||
#include "client/SaveInfo.h"
|
||||
#include "Graphics.h"
|
||||
#include "Engine.h"
|
||||
#include "client/Client.h"
|
||||
@ -9,8 +9,9 @@
|
||||
|
||||
namespace ui {
|
||||
|
||||
SaveButton::SaveButton(Point position, Point size, Save * save):
|
||||
SaveButton::SaveButton(Point position, Point size, SaveInfo * save):
|
||||
Component(position, size),
|
||||
file(NULL),
|
||||
save(save),
|
||||
thumbnail(NULL),
|
||||
isMouseInside(false),
|
||||
@ -50,6 +51,30 @@ SaveButton::SaveButton(Point position, Point size, Save * save):
|
||||
}
|
||||
}
|
||||
|
||||
SaveButton::SaveButton(Point position, Point size, SaveFile * file):
|
||||
Component(position, size),
|
||||
save(NULL),
|
||||
file(file),
|
||||
thumbnail(NULL),
|
||||
isMouseInside(false),
|
||||
isButtonDown(false),
|
||||
actionCallback(NULL),
|
||||
voteColour(255, 0, 0),
|
||||
selectable(false),
|
||||
selected(false)
|
||||
{
|
||||
if(file)
|
||||
{
|
||||
name = file->GetName();
|
||||
if(Graphics::textwidth((char *)name.c_str()) > Size.X)
|
||||
{
|
||||
int position = Graphics::textwidthx((char *)name.c_str(), Size.X - 22);
|
||||
name = name.erase(position, name.length()-position);
|
||||
name += "...";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SaveButton::~SaveButton()
|
||||
{
|
||||
if(thumbnail)
|
||||
@ -58,25 +83,45 @@ SaveButton::~SaveButton()
|
||||
delete actionCallback;
|
||||
if(save)
|
||||
delete save;
|
||||
if(file)
|
||||
delete file;
|
||||
}
|
||||
|
||||
void SaveButton::Tick(float dt)
|
||||
{
|
||||
Thumbnail * tempThumb;
|
||||
float scaleFactorY = 1.0f, scaleFactorX = 1.0f;
|
||||
if(!thumbnail && save)
|
||||
if(!thumbnail)
|
||||
{
|
||||
if(save->GetID())
|
||||
if(save)
|
||||
{
|
||||
tempThumb = Client::Ref().GetThumbnail(save->GetID(), 0);
|
||||
if(tempThumb)
|
||||
if(!save->GetGameSave() && save->GetID())
|
||||
{
|
||||
thumbnail = new Thumbnail(*tempThumb); //Store a local copy of the thumbnail
|
||||
tempThumb = Client::Ref().GetThumbnail(save->GetID(), 0);
|
||||
if(tempThumb)
|
||||
{
|
||||
thumbnail = new Thumbnail(*tempThumb); //Store a local copy of the thumbnail
|
||||
}
|
||||
}
|
||||
else if(save->GetGameSave())
|
||||
{
|
||||
thumbnail = SaveRenderer::Ref().Render(save->GetGameSave());
|
||||
}
|
||||
else
|
||||
{
|
||||
thumbnail = NULL;
|
||||
}
|
||||
}
|
||||
else
|
||||
if(file)
|
||||
{
|
||||
thumbnail = SaveRenderer::Ref().Render(save->GetData(), save->GetDataLength());
|
||||
if(file->GetGameSave())
|
||||
{
|
||||
thumbnail = SaveRenderer::Ref().Render(file->GetGameSave());
|
||||
}
|
||||
else
|
||||
{
|
||||
thumbnail = NULL;
|
||||
}
|
||||
}
|
||||
if(thumbnail && thumbnail->Data)
|
||||
{
|
||||
@ -115,7 +160,7 @@ void SaveButton::Draw(const Point& screenPos)
|
||||
if(thumbnail)
|
||||
{
|
||||
thumbBoxSize = ui::Point(thumbnail->Size.X, thumbnail->Size.Y);
|
||||
if(save->id)
|
||||
if(save && save->id)
|
||||
g->draw_image(thumbnail->Data, screenPos.X-3+(Size.X-thumbBoxSize.X)/2, screenPos.Y+(Size.Y-21-thumbBoxSize.Y)/2, thumbnail->Size.X, thumbnail->Size.Y, 255);
|
||||
else
|
||||
g->draw_image(thumbnail->Data, screenPos.X+(Size.X-thumbBoxSize.X)/2, screenPos.Y+(Size.Y-21-thumbBoxSize.Y)/2, thumbnail->Size.X, thumbnail->Size.Y, 255);
|
||||
@ -158,6 +203,22 @@ void SaveButton::Draw(const Point& screenPos)
|
||||
g->drawtext(screenPos.X+(Size.X-Graphics::textwidth((char *)save->userName.c_str()))/2, screenPos.Y+Size.Y - 10, save->userName, 100, 130, 160, 255);
|
||||
}
|
||||
}
|
||||
if(file)
|
||||
{
|
||||
if(isMouseInside)
|
||||
g->drawrect(screenPos.X+(Size.X-thumbBoxSize.X)/2, screenPos.Y+(Size.Y-21-thumbBoxSize.Y)/2, thumbBoxSize.X, thumbBoxSize.Y, 210, 230, 255, 255);
|
||||
else
|
||||
g->drawrect(screenPos.X+(Size.X-thumbBoxSize.X)/2, screenPos.Y+(Size.Y-21-thumbBoxSize.Y)/2, thumbBoxSize.X, thumbBoxSize.Y, 180, 180, 180, 255);
|
||||
|
||||
if(isMouseInside)
|
||||
{
|
||||
g->drawtext(screenPos.X+(Size.X-Graphics::textwidth((char *)name.c_str()))/2, screenPos.Y+Size.Y - 21, name, 255, 255, 255, 255);
|
||||
}
|
||||
else
|
||||
{
|
||||
g->drawtext(screenPos.X+(Size.X-Graphics::textwidth((char *)name.c_str()))/2, screenPos.Y+Size.Y - 21, name, 180, 180, 180, 255);
|
||||
}
|
||||
}
|
||||
|
||||
if(isMouseInside && selectable)
|
||||
{
|
||||
|
@ -4,7 +4,8 @@
|
||||
#include <string>
|
||||
|
||||
#include "Component.h"
|
||||
#include "search/Save.h"
|
||||
#include "client/SaveFile.h"
|
||||
#include "client/SaveInfo.h"
|
||||
#include "Graphics.h"
|
||||
#include "search/Thumbnail.h"
|
||||
#include "interface/Colour.h"
|
||||
@ -22,11 +23,13 @@ public:
|
||||
|
||||
class SaveButton : public Component
|
||||
{
|
||||
Save * save;
|
||||
SaveFile * file;
|
||||
SaveInfo * save;
|
||||
Thumbnail * thumbnail;
|
||||
std::string name;
|
||||
public:
|
||||
SaveButton(Point position, Point size, Save * save);
|
||||
SaveButton(Point position, Point size, SaveInfo * save);
|
||||
SaveButton(Point position, Point size, SaveFile * file);
|
||||
virtual ~SaveButton();
|
||||
|
||||
virtual void OnMouseClick(int x, int y, unsigned int button);
|
||||
@ -43,7 +46,8 @@ public:
|
||||
void SetSelectable(bool selectable_) { selectable = selectable_; }
|
||||
bool GetSelectable() { return selectable; }
|
||||
|
||||
Save * GetSave() { return save; }
|
||||
SaveInfo * GetSave() { return save; }
|
||||
SaveFile * GetSaveFile() { return file; }
|
||||
inline bool GetState() { return state; }
|
||||
virtual void DoAction();
|
||||
virtual void DoSelection();
|
||||
|
135
src/localbrowser/LocalBrowserController.cpp
Normal file
135
src/localbrowser/LocalBrowserController.cpp
Normal file
@ -0,0 +1,135 @@
|
||||
/*
|
||||
* StampsController.cpp
|
||||
*
|
||||
* Created on: Mar 29, 2012
|
||||
* Author: Simon
|
||||
*/
|
||||
#include <sstream>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "client/Client.h"
|
||||
#include "LocalBrowserController.h"
|
||||
#include "interface/Engine.h"
|
||||
#include "dialogues/ConfirmPrompt.h"
|
||||
#include "tasks/TaskWindow.h"
|
||||
#include "tasks/Task.h"
|
||||
|
||||
#include "LocalBrowserModel.h"
|
||||
#include "LocalBrowserView.h"
|
||||
|
||||
LocalBrowserController::LocalBrowserController(ControllerCallback * callback):
|
||||
HasDone(false)
|
||||
{
|
||||
browserModel = new LocalBrowserModel();
|
||||
browserView = new LocalBrowserView();
|
||||
browserView->AttachController(this);
|
||||
browserModel->AddObserver(browserView);
|
||||
|
||||
this->callback = callback;
|
||||
|
||||
browserModel->UpdateSavesList(1);
|
||||
}
|
||||
|
||||
void LocalBrowserController::OpenSave(SaveFile * save)
|
||||
{
|
||||
browserModel->SetSave(save);
|
||||
}
|
||||
|
||||
SaveFile * LocalBrowserController::GetSave()
|
||||
{
|
||||
return browserModel->GetSave();
|
||||
}
|
||||
|
||||
void LocalBrowserController::RemoveSelected()
|
||||
{
|
||||
class RemoveSelectedConfirmation: public ConfirmDialogueCallback {
|
||||
public:
|
||||
LocalBrowserController * c;
|
||||
RemoveSelectedConfirmation(LocalBrowserController * c_) { c = c_; }
|
||||
virtual void ConfirmCallback(ConfirmPrompt::DialogueResult result) {
|
||||
if (result == ConfirmPrompt::ResultOkay)
|
||||
c->removeSelectedC();
|
||||
}
|
||||
virtual ~RemoveSelectedConfirmation() { }
|
||||
};
|
||||
|
||||
std::stringstream desc;
|
||||
desc << "Are you sure you want to delete " << browserModel->GetSelected().size() << " saves";
|
||||
if(browserModel->GetSelected().size()>1)
|
||||
desc << "s";
|
||||
new ConfirmPrompt("Delete saves", desc.str(), new RemoveSelectedConfirmation(this));
|
||||
}
|
||||
|
||||
void LocalBrowserController::removeSelectedC()
|
||||
{
|
||||
class RemoveSavesTask : public Task
|
||||
{
|
||||
std::vector<std::string> saves;
|
||||
public:
|
||||
RemoveSavesTask(std::vector<std::string> saves_) { saves = saves_; }
|
||||
virtual void doWork()
|
||||
{
|
||||
for(int i = 0; i < saves.size(); i++)
|
||||
{
|
||||
std::stringstream saveName;
|
||||
saveName << "Deleting save [" << saves[i] << "] ...";
|
||||
notifyStatus(saveName.str());
|
||||
Client::Ref().DeleteStamp(saves[i]);
|
||||
usleep(100*1000);
|
||||
notifyProgress((float(i+1)/float(saves.size())*100));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
std::vector<std::string> selected = browserModel->GetSelected();
|
||||
new TaskWindow("Removing saves", new RemoveSavesTask(selected));
|
||||
ClearSelection();
|
||||
browserModel->UpdateSavesList(browserModel->GetPageNum());
|
||||
}
|
||||
|
||||
void LocalBrowserController::ClearSelection()
|
||||
{
|
||||
browserModel->ClearSelected();
|
||||
}
|
||||
|
||||
void LocalBrowserController::NextPage()
|
||||
{
|
||||
if(browserModel->GetPageNum()>1)
|
||||
browserModel->UpdateSavesList(browserModel->GetPageNum()-1);
|
||||
}
|
||||
|
||||
void LocalBrowserController::PrevPage()
|
||||
{
|
||||
if(browserModel->GetPageNum() <= browserModel->GetPageCount())
|
||||
browserModel->UpdateSavesList(browserModel->GetPageNum()+1);
|
||||
}
|
||||
|
||||
void LocalBrowserController::Update()
|
||||
{
|
||||
if(browserModel->GetSave())
|
||||
{
|
||||
Exit();
|
||||
}
|
||||
}
|
||||
|
||||
void LocalBrowserController::Selected(std::string saveName, bool selected)
|
||||
{
|
||||
if(selected)
|
||||
browserModel->SelectSave(saveName);
|
||||
else
|
||||
browserModel->DeselectSave(saveName);
|
||||
}
|
||||
|
||||
void LocalBrowserController::Exit()
|
||||
{
|
||||
if(ui::Engine::Ref().GetWindow() == browserView)
|
||||
ui::Engine::Ref().CloseWindow();
|
||||
if(callback)
|
||||
callback->ControllerExit();
|
||||
HasDone = true;
|
||||
}
|
||||
|
||||
LocalBrowserController::~LocalBrowserController() {
|
||||
// TODO Auto-generated destructor stub
|
||||
}
|
||||
|
39
src/localbrowser/LocalBrowserController.h
Normal file
39
src/localbrowser/LocalBrowserController.h
Normal file
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* StampsController.h
|
||||
*
|
||||
* Created on: Mar 29, 2012
|
||||
* Author: Simon
|
||||
*/
|
||||
|
||||
#ifndef STAMPSCONTROLLER_H_
|
||||
#define STAMPSCONTROLLER_H_
|
||||
|
||||
#include "Controller.h"
|
||||
#include "LocalBrowserView.h"
|
||||
#include "client/SaveInfo.h"
|
||||
|
||||
class LocalBrowserView;
|
||||
class LocalBrowserModel;
|
||||
class LocalBrowserController {
|
||||
ControllerCallback * callback;
|
||||
LocalBrowserView * browserView;
|
||||
LocalBrowserModel * browserModel;
|
||||
public:
|
||||
bool HasDone;
|
||||
LocalBrowserController(ControllerCallback * callback);
|
||||
LocalBrowserView * GetView() {return browserView;}
|
||||
SaveFile * GetSave();
|
||||
void RemoveSelected();
|
||||
void removeSelectedC();
|
||||
void ClearSelection();
|
||||
void Selected(std::string stampID, bool selected);
|
||||
void OpenSave(SaveFile * stamp);
|
||||
void SetStamp();
|
||||
void NextPage();
|
||||
void PrevPage();
|
||||
void Update();
|
||||
void Exit();
|
||||
virtual ~LocalBrowserController();
|
||||
};
|
||||
|
||||
#endif /* STAMPSCONTROLLER_H_ */
|
131
src/localbrowser/LocalBrowserModel.cpp
Normal file
131
src/localbrowser/LocalBrowserModel.cpp
Normal file
@ -0,0 +1,131 @@
|
||||
/*
|
||||
* StampsModel.cpp
|
||||
*
|
||||
* Created on: Mar 29, 2012
|
||||
* Author: Simon
|
||||
*/
|
||||
|
||||
#include "LocalBrowserModel.h"
|
||||
#include "LocalBrowserView.h"
|
||||
#include "client/Client.h"
|
||||
#include "LocalBrowserModelException.h"
|
||||
|
||||
LocalBrowserModel::LocalBrowserModel():
|
||||
stamp(NULL),
|
||||
currentPage(1)
|
||||
{
|
||||
// TODO Auto-generated constructor stub
|
||||
stampIDs = Client::Ref().GetStamps();
|
||||
}
|
||||
|
||||
|
||||
std::vector<SaveFile*> LocalBrowserModel::GetSavesList()
|
||||
{
|
||||
return savesList;
|
||||
}
|
||||
|
||||
void LocalBrowserModel::AddObserver(LocalBrowserView * observer)
|
||||
{
|
||||
observers.push_back(observer);
|
||||
observer->NotifySavesListChanged(this);
|
||||
observer->NotifyPageChanged(this);
|
||||
}
|
||||
|
||||
void LocalBrowserModel::notifySavesListChanged()
|
||||
{
|
||||
for(int i = 0; i < observers.size(); i++)
|
||||
{
|
||||
observers[i]->NotifySavesListChanged(this);
|
||||
}
|
||||
}
|
||||
|
||||
void LocalBrowserModel::notifyPageChanged()
|
||||
{
|
||||
for(int i = 0; i < observers.size(); i++)
|
||||
{
|
||||
observers[i]->NotifyPageChanged(this);
|
||||
}
|
||||
}
|
||||
|
||||
SaveFile * LocalBrowserModel::GetSave()
|
||||
{
|
||||
return stamp;
|
||||
}
|
||||
|
||||
void LocalBrowserModel::SetSave(SaveFile * newStamp)
|
||||
{
|
||||
if(stamp)
|
||||
delete stamp;
|
||||
stamp = new SaveFile(*newStamp);
|
||||
}
|
||||
|
||||
void LocalBrowserModel::UpdateSavesList(int pageNumber)
|
||||
{
|
||||
std::vector<SaveFile*> tempSavesList = savesList;
|
||||
savesList.clear();
|
||||
currentPage = pageNumber;
|
||||
notifyPageChanged();
|
||||
notifySavesListChanged();
|
||||
/*notifyStampsListChanged();
|
||||
for(int i = 0; i < tempStampsList.size(); i++)
|
||||
{
|
||||
delete tempStampsList[i];
|
||||
}*/
|
||||
|
||||
int stampsEnd = pageNumber*20;
|
||||
|
||||
for(int i = stampsEnd-20; i<stampIDs.size() && i<stampsEnd; i++)
|
||||
{
|
||||
SaveFile * tempSave = Client::Ref().GetStamp(stampIDs[i]);
|
||||
if(tempSave)
|
||||
{
|
||||
savesList.push_back(tempSave);
|
||||
}
|
||||
}
|
||||
notifySavesListChanged();
|
||||
}
|
||||
|
||||
void LocalBrowserModel::SelectSave(std::string stampID)
|
||||
{
|
||||
for(int i = 0; i < selected.size(); i++)
|
||||
{
|
||||
if(selected[i]==stampID)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
selected.push_back(stampID);
|
||||
notifySelectedChanged();
|
||||
}
|
||||
|
||||
void LocalBrowserModel::DeselectSave(std::string stampID)
|
||||
{
|
||||
bool changed = false;
|
||||
restart:
|
||||
for(int i = 0; i < selected.size(); i++)
|
||||
{
|
||||
if(selected[i]==stampID)
|
||||
{
|
||||
selected.erase(selected.begin()+i);
|
||||
changed = true;
|
||||
goto restart; //Just ensure all cases are removed.
|
||||
}
|
||||
}
|
||||
if(changed)
|
||||
notifySelectedChanged();
|
||||
}
|
||||
|
||||
void LocalBrowserModel::notifySelectedChanged()
|
||||
{
|
||||
for(int i = 0; i < observers.size(); i++)
|
||||
{
|
||||
LocalBrowserView* cObserver = observers[i];
|
||||
cObserver->NotifySelectedChanged(this);
|
||||
}
|
||||
}
|
||||
|
||||
LocalBrowserModel::~LocalBrowserModel() {
|
||||
if(stamp)
|
||||
delete stamp;
|
||||
}
|
||||
|
43
src/localbrowser/LocalBrowserModel.h
Normal file
43
src/localbrowser/LocalBrowserModel.h
Normal file
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* StampsModel.h
|
||||
*
|
||||
* Created on: Mar 29, 2012
|
||||
* Author: Simon
|
||||
*/
|
||||
|
||||
#ifndef STAMPSMODEL_H_
|
||||
#define STAMPSMODEL_H_
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <cmath>
|
||||
#include "client/SaveFile.h"
|
||||
|
||||
class LocalBrowserView;
|
||||
class LocalBrowserModel {
|
||||
vector<std::string> selected;
|
||||
SaveFile * stamp;
|
||||
std::vector<std::string> stampIDs;
|
||||
std::vector<SaveFile*> savesList;
|
||||
std::vector<LocalBrowserView*> observers;
|
||||
int currentPage;
|
||||
void notifySavesListChanged();
|
||||
void notifyPageChanged();
|
||||
void notifySelectedChanged();
|
||||
public:
|
||||
LocalBrowserModel();
|
||||
int GetPageCount() { return max(1, (int)(ceil(stampIDs.size()/16))); }
|
||||
int GetPageNum() { return currentPage; }
|
||||
void AddObserver(LocalBrowserView * observer);
|
||||
std::vector<SaveFile *> GetSavesList();
|
||||
void UpdateSavesList(int pageNumber);
|
||||
SaveFile * GetSave();
|
||||
void SetSave(SaveFile * newStamp);
|
||||
vector<std::string> GetSelected() { return selected; }
|
||||
void ClearSelected() { selected.clear(); notifySelectedChanged(); }
|
||||
void SelectSave(std::string stampID);
|
||||
void DeselectSave(std::string stampID);
|
||||
virtual ~LocalBrowserModel();
|
||||
};
|
||||
|
||||
#endif /* STAMPSMODEL_H_ */
|
23
src/localbrowser/LocalBrowserModelException.h
Normal file
23
src/localbrowser/LocalBrowserModelException.h
Normal file
@ -0,0 +1,23 @@
|
||||
/*
|
||||
* StampsModelException.h
|
||||
*
|
||||
* Created on: Mar 29, 2012
|
||||
* Author: Simon
|
||||
*/
|
||||
|
||||
#ifndef STAMPSMODELEXCEPTION_H_
|
||||
#define STAMPSMODELEXCEPTION_H_
|
||||
|
||||
#include <string>
|
||||
#include <exception>
|
||||
using namespace std;
|
||||
|
||||
class LocalBrowserModelException {
|
||||
string message;
|
||||
public:
|
||||
LocalBrowserModelException(string message_): message(message_) {};
|
||||
const char * what() const throw() { return message.c_str(); };
|
||||
~LocalBrowserModelException() throw() {};
|
||||
};
|
||||
|
||||
#endif /* STAMPSMODELEXCEPTION_H_ */
|
197
src/localbrowser/LocalBrowserView.cpp
Normal file
197
src/localbrowser/LocalBrowserView.cpp
Normal file
@ -0,0 +1,197 @@
|
||||
/*
|
||||
* StampsView.cpp
|
||||
*
|
||||
* Created on: Mar 29, 2012
|
||||
* Author: Simon
|
||||
*/
|
||||
|
||||
#include <sstream>
|
||||
#include "client/Client.h"
|
||||
#include "LocalBrowserView.h"
|
||||
|
||||
#include "dialogues/ErrorMessage.h"
|
||||
#include "LocalBrowserController.h"
|
||||
#include "LocalBrowserModel.h"
|
||||
#include "LocalBrowserModelException.h"
|
||||
|
||||
LocalBrowserView::LocalBrowserView():
|
||||
ui::Window(ui::Point(0, 0), ui::Point(XRES+BARSIZE, YRES+MENUSIZE))
|
||||
{
|
||||
nextButton = new ui::Button(ui::Point(XRES+BARSIZE-52, YRES+MENUSIZE-18), ui::Point(50, 16), "Next \x95");
|
||||
previousButton = new ui::Button(ui::Point(1, YRES+MENUSIZE-18), ui::Point(50, 16), "\x96 Prev");
|
||||
infoLabel = new ui::Label(ui::Point(51, YRES+MENUSIZE-18), ui::Point(XRES+BARSIZE-102, 16), "Loading...");
|
||||
AddComponent(infoLabel);
|
||||
AddComponent(nextButton);
|
||||
AddComponent(previousButton);
|
||||
|
||||
class NextPageAction : public ui::ButtonAction
|
||||
{
|
||||
LocalBrowserView * v;
|
||||
public:
|
||||
NextPageAction(LocalBrowserView * _v) { v = _v; }
|
||||
void ActionCallback(ui::Button * sender)
|
||||
{
|
||||
v->c->NextPage();
|
||||
}
|
||||
};
|
||||
nextButton->SetActionCallback(new NextPageAction(this));
|
||||
nextButton->Appearance.HorizontalAlign = ui::Appearance::AlignRight; nextButton->Appearance.VerticalAlign = ui::Appearance::AlignBottom;
|
||||
|
||||
class PrevPageAction : public ui::ButtonAction
|
||||
{
|
||||
LocalBrowserView * v;
|
||||
public:
|
||||
PrevPageAction(LocalBrowserView * _v) { v = _v; }
|
||||
void ActionCallback(ui::Button * sender)
|
||||
{
|
||||
v->c->PrevPage();
|
||||
}
|
||||
};
|
||||
previousButton->SetActionCallback(new PrevPageAction(this));
|
||||
previousButton->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; previousButton->Appearance.VerticalAlign = ui::Appearance::AlignBottom;
|
||||
|
||||
class RemoveSelectedAction : public ui::ButtonAction
|
||||
{
|
||||
LocalBrowserView * v;
|
||||
public:
|
||||
RemoveSelectedAction(LocalBrowserView * _v) { v = _v; }
|
||||
void ActionCallback(ui::Button * sender)
|
||||
{
|
||||
v->c->RemoveSelected();
|
||||
}
|
||||
};
|
||||
|
||||
removeSelected = new ui::Button(ui::Point((((XRES+BARSIZE)-100)/2), YRES+MENUSIZE-18), ui::Point(100, 16), "Delete");
|
||||
removeSelected->Visible = false;
|
||||
removeSelected->SetActionCallback(new RemoveSelectedAction(this));
|
||||
AddComponent(removeSelected);
|
||||
}
|
||||
|
||||
void LocalBrowserView::OnTick(float dt)
|
||||
{
|
||||
c->Update();
|
||||
}
|
||||
|
||||
void LocalBrowserView::NotifyPageChanged(LocalBrowserModel * sender)
|
||||
{
|
||||
std::stringstream pageInfo;
|
||||
pageInfo << "Page " << sender->GetPageNum() << " of " << sender->GetPageCount();
|
||||
infoLabel->SetText(pageInfo.str());
|
||||
if(sender->GetPageNum() == 1)
|
||||
{
|
||||
previousButton->Visible = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
previousButton->Visible = true;
|
||||
}
|
||||
if(sender->GetPageNum() == sender->GetPageCount())
|
||||
{
|
||||
nextButton->Visible = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
nextButton->Visible = true;
|
||||
}
|
||||
}
|
||||
|
||||
void LocalBrowserView::NotifySavesListChanged(LocalBrowserModel * sender)
|
||||
{
|
||||
int i = 0;
|
||||
int buttonWidth, buttonHeight, saveX = 0, saveY = 0, savesX = 5, savesY = 4, buttonPadding = 2;
|
||||
int buttonAreaWidth, buttonAreaHeight, buttonXOffset, buttonYOffset;
|
||||
|
||||
vector<SaveFile*> saves = sender->GetSavesList();
|
||||
for(i = 0; i < stampButtons.size(); i++)
|
||||
{
|
||||
RemoveComponent(stampButtons[i]);
|
||||
delete stampButtons[i];
|
||||
}
|
||||
stampButtons.clear();
|
||||
buttonXOffset = 0;
|
||||
buttonYOffset = 50;
|
||||
buttonAreaWidth = Size.X;
|
||||
buttonAreaHeight = Size.Y - buttonYOffset - 18;
|
||||
buttonWidth = (buttonAreaWidth/savesX) - buttonPadding*2;
|
||||
buttonHeight = (buttonAreaHeight/savesY) - buttonPadding*2;
|
||||
class SaveOpenAction: public ui::SaveButtonAction
|
||||
{
|
||||
LocalBrowserView * v;
|
||||
public:
|
||||
SaveOpenAction(LocalBrowserView * _v) { v = _v; }
|
||||
virtual void ActionCallback(ui::SaveButton * sender)
|
||||
{
|
||||
if(sender->GetSaveFile())
|
||||
v->c->OpenSave(sender->GetSaveFile());
|
||||
}
|
||||
virtual void SelectedCallback(ui::SaveButton * sender)
|
||||
{
|
||||
if(sender->GetSaveFile())
|
||||
v->c->Selected(sender->GetSaveFile()->GetName(), sender->GetSelected());
|
||||
}
|
||||
};
|
||||
for(i = 0; i < saves.size(); i++)
|
||||
{
|
||||
if(saveX == savesX)
|
||||
{
|
||||
if(saveY == savesY-1)
|
||||
break;
|
||||
saveX = 0;
|
||||
saveY++;
|
||||
}
|
||||
ui::SaveButton * saveButton;
|
||||
saveButton = new ui::SaveButton(
|
||||
ui::Point(
|
||||
buttonXOffset + buttonPadding + saveX*(buttonWidth+buttonPadding*2),
|
||||
buttonYOffset + buttonPadding + saveY*(buttonHeight+buttonPadding*2)
|
||||
),
|
||||
ui::Point(buttonWidth, buttonHeight),
|
||||
saves[i]);
|
||||
saveButton->SetSelectable(true);
|
||||
saveButton->SetActionCallback(new SaveOpenAction(this));
|
||||
stampButtons.push_back(saveButton);
|
||||
AddComponent(saveButton);
|
||||
saveX++;
|
||||
}
|
||||
}
|
||||
|
||||
void LocalBrowserView::NotifySelectedChanged(LocalBrowserModel * sender)
|
||||
{
|
||||
vector<std::string> selected = sender->GetSelected();
|
||||
for(int j = 0; j < stampButtons.size(); j++)
|
||||
{
|
||||
stampButtons[j]->SetSelected(false);
|
||||
for(int i = 0; i < selected.size(); i++)
|
||||
{
|
||||
if(stampButtons[j]->GetSaveFile()->GetName()==selected[i])
|
||||
stampButtons[j]->SetSelected(true);
|
||||
}
|
||||
}
|
||||
|
||||
if(selected.size())
|
||||
{
|
||||
removeSelected->Visible = true;
|
||||
}
|
||||
else
|
||||
removeSelected->Visible = false;
|
||||
}
|
||||
|
||||
void LocalBrowserView::OnMouseWheel(int x, int y, int d)
|
||||
{
|
||||
if(!d)
|
||||
return;
|
||||
if(d<0)
|
||||
c->NextPage();
|
||||
else
|
||||
c->PrevPage();
|
||||
}
|
||||
void LocalBrowserView::OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt)
|
||||
{
|
||||
if(key==KEY_ESCAPE)
|
||||
c->Exit();
|
||||
}
|
||||
|
||||
LocalBrowserView::~LocalBrowserView() {
|
||||
// TODO Auto-generated destructor stub
|
||||
}
|
||||
|
40
src/localbrowser/LocalBrowserView.h
Normal file
40
src/localbrowser/LocalBrowserView.h
Normal file
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* StampsView.h
|
||||
*
|
||||
* Created on: Mar 29, 2012
|
||||
* Author: Simon
|
||||
*/
|
||||
|
||||
#ifndef STAMPSVIEW_H_
|
||||
#define STAMPSVIEW_H_
|
||||
|
||||
#include <vector>
|
||||
#include "interface/Window.h"
|
||||
#include "interface/Button.h"
|
||||
#include "interface/Textbox.h"
|
||||
#include "interface/Label.h"
|
||||
#include "interface/SaveButton.h"
|
||||
|
||||
class LocalBrowserController;
|
||||
class LocalBrowserModel;
|
||||
class LocalBrowserView: public ui::Window {
|
||||
LocalBrowserController * c;
|
||||
std::vector<ui::SaveButton*> stampButtons;
|
||||
ui::Button * previousButton;
|
||||
ui::Button * nextButton;
|
||||
ui::Label * infoLabel;
|
||||
ui::Button * removeSelected;
|
||||
public:
|
||||
LocalBrowserView();
|
||||
//virtual void OnDraw();
|
||||
virtual void OnTick(float dt);
|
||||
void AttachController(LocalBrowserController * c_) { c = c_; };
|
||||
void NotifyPageChanged(LocalBrowserModel * sender);
|
||||
void NotifySavesListChanged(LocalBrowserModel * sender);
|
||||
void NotifySelectedChanged(LocalBrowserModel * sender);
|
||||
virtual void OnMouseWheel(int x, int y, int d);
|
||||
virtual void OnKeyPress(int key, Uint16 character, bool shift, bool ctrl, bool alt);
|
||||
virtual ~LocalBrowserView();
|
||||
};
|
||||
|
||||
#endif /* STAMPSVIEW_H_ */
|
@ -40,7 +40,7 @@ void PreviewController::Update()
|
||||
}
|
||||
}
|
||||
|
||||
Save * PreviewController::GetSave()
|
||||
SaveInfo * PreviewController::GetSave()
|
||||
{
|
||||
return previewModel->GetSave();
|
||||
}
|
||||
|
@ -11,7 +11,7 @@
|
||||
#include "preview/PreviewModel.h"
|
||||
#include "preview/PreviewView.h"
|
||||
#include "Controller.h"
|
||||
#include "search/Save.h"
|
||||
#include "client/SaveInfo.h"
|
||||
|
||||
class PreviewModel;
|
||||
class PreviewView;
|
||||
@ -28,7 +28,7 @@ public:
|
||||
void OpenInBrowser();
|
||||
void Report(std::string message);
|
||||
bool GetDoOpen();
|
||||
Save * GetSave();
|
||||
SaveInfo * GetSave();
|
||||
PreviewView * GetView() { return previewView; }
|
||||
void Update();
|
||||
void FavouriteSave();
|
||||
|
@ -42,7 +42,7 @@ void * PreviewModel::updateSaveCommentsTHelper(void * obj)
|
||||
|
||||
void * PreviewModel::updateSaveInfoT()
|
||||
{
|
||||
Save * tempSave = Client::Ref().GetSave(tSaveID, tSaveDate);
|
||||
SaveInfo * tempSave = Client::Ref().GetSave(tSaveID, tSaveDate);
|
||||
updateSaveInfoFinished = true;
|
||||
return tempSave;
|
||||
}
|
||||
@ -134,7 +134,7 @@ Thumbnail * PreviewModel::GetPreview()
|
||||
return savePreview;
|
||||
}
|
||||
|
||||
Save * PreviewModel::GetSave()
|
||||
SaveInfo * PreviewModel::GetSave()
|
||||
{
|
||||
return save;
|
||||
}
|
||||
|
@ -11,7 +11,7 @@
|
||||
#include <vector>
|
||||
#include <pthread.h>
|
||||
#include "PreviewView.h"
|
||||
#include "search/Save.h"
|
||||
#include "client/SaveInfo.h"
|
||||
#include "preview/Comment.h"
|
||||
#include "search/Thumbnail.h"
|
||||
|
||||
@ -21,7 +21,7 @@ class PreviewView;
|
||||
class PreviewModel {
|
||||
bool doOpen;
|
||||
vector<PreviewView*> observers;
|
||||
Save * save;
|
||||
SaveInfo * save;
|
||||
Thumbnail * savePreview;
|
||||
std::vector<SaveComment*> * saveComments;
|
||||
void notifyPreviewChanged();
|
||||
@ -52,7 +52,7 @@ class PreviewModel {
|
||||
public:
|
||||
PreviewModel();
|
||||
Thumbnail * GetPreview();
|
||||
Save * GetSave();
|
||||
SaveInfo * GetSave();
|
||||
std::vector<SaveComment*> * GetComments();
|
||||
void AddObserver(PreviewView * observer);
|
||||
void UpdateSave(int saveID, int saveDate);
|
||||
|
@ -162,7 +162,7 @@ void PreviewView::OnMouseDown(int x, int y, unsigned button)
|
||||
|
||||
void PreviewView::NotifySaveChanged(PreviewModel * sender)
|
||||
{
|
||||
Save * save = sender->GetSave();
|
||||
SaveInfo * save = sender->GetSave();
|
||||
if(save)
|
||||
{
|
||||
votesUp = save->votesUp;
|
||||
|
@ -21,7 +21,7 @@ public:
|
||||
{
|
||||
if(cc->activePreview->GetDoOpen() && cc->activePreview->GetSave())
|
||||
{
|
||||
cc->searchModel->SetLoadedSave(new Save(*(cc->activePreview->GetSave())));
|
||||
cc->searchModel->SetLoadedSave(new SaveInfo(*(cc->activePreview->GetSave())));
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -45,7 +45,7 @@ SearchController::SearchController(ControllerCallback * callback):
|
||||
//windowPanel.AddChild();
|
||||
}
|
||||
|
||||
Save * SearchController::GetLoadedSave()
|
||||
SaveInfo * SearchController::GetLoadedSave()
|
||||
{
|
||||
return searchModel->GetLoadedSave();
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
#include "SearchView.h"
|
||||
#include "preview/PreviewController.h"
|
||||
#include "Controller.h"
|
||||
#include "Save.h"
|
||||
#include "client/SaveInfo.h"
|
||||
|
||||
class SearchView;
|
||||
class SearchModel;
|
||||
@ -43,7 +43,7 @@ public:
|
||||
void RemoveSelected();
|
||||
void UnpublishSelected();
|
||||
void FavouriteSelected();
|
||||
Save * GetLoadedSave();
|
||||
SaveInfo * GetLoadedSave();
|
||||
};
|
||||
|
||||
#endif // SEARCHCONTROLLER_H
|
||||
|
@ -1,5 +1,5 @@
|
||||
#include "SearchModel.h"
|
||||
#include "Save.h"
|
||||
#include "client/SaveInfo.h"
|
||||
|
||||
#include "client/Client.h"
|
||||
|
||||
@ -28,7 +28,7 @@ void * SearchModel::updateSaveListT()
|
||||
category = "Favourites";
|
||||
if(showOwn && Client::Ref().GetAuthUser().ID)
|
||||
category = "by:"+Client::Ref().GetAuthUser().Username;
|
||||
vector<Save*> * tempSaveList = Client::Ref().SearchSaves((currentPage-1)*20, 20, lastQuery, currentSort=="new"?"date":"votes", category, resultCount);
|
||||
vector<SaveInfo*> * tempSaveList = Client::Ref().SearchSaves((currentPage-1)*20, 20, lastQuery, currentSort=="new"?"date":"votes", category, resultCount);
|
||||
updateSaveListFinished = true;
|
||||
return tempSaveList;
|
||||
}
|
||||
@ -55,16 +55,16 @@ void SearchModel::UpdateSaveList(int pageNumber, std::string query)
|
||||
}
|
||||
}
|
||||
|
||||
void SearchModel::SetLoadedSave(Save * save)
|
||||
void SearchModel::SetLoadedSave(SaveInfo * save)
|
||||
{
|
||||
loadedSave = save;
|
||||
}
|
||||
|
||||
Save * SearchModel::GetLoadedSave(){
|
||||
SaveInfo * SearchModel::GetLoadedSave(){
|
||||
return loadedSave;
|
||||
}
|
||||
|
||||
vector<Save*> SearchModel::GetSaveList()
|
||||
vector<SaveInfo*> SearchModel::GetSaveList()
|
||||
{
|
||||
return saveList;
|
||||
}
|
||||
@ -78,7 +78,7 @@ void SearchModel::Update()
|
||||
updateSaveListWorking = false;
|
||||
lastError = "";
|
||||
saveListLoaded = true;
|
||||
vector<Save*> * tempSaveList;
|
||||
vector<SaveInfo*> * tempSaveList;
|
||||
pthread_join(updateSaveListThread, (void**)(&tempSaveList));
|
||||
saveList = *tempSaveList;
|
||||
delete tempSaveList;
|
||||
|
@ -5,7 +5,7 @@
|
||||
#include <string>
|
||||
#include <pthread.h>
|
||||
#include <cmath>
|
||||
#include "Save.h"
|
||||
#include "client/SaveInfo.h"
|
||||
#include "SearchView.h"
|
||||
|
||||
using namespace std;
|
||||
@ -14,13 +14,13 @@ class SearchView;
|
||||
class SearchModel
|
||||
{
|
||||
private:
|
||||
Save * loadedSave;
|
||||
SaveInfo * loadedSave;
|
||||
string currentSort;
|
||||
string lastQuery;
|
||||
string lastError;
|
||||
vector<int> selected;
|
||||
vector<SearchView*> observers;
|
||||
vector<Save*> saveList;
|
||||
vector<SaveInfo*> saveList;
|
||||
int currentPage;
|
||||
int resultCount;
|
||||
bool showOwn;
|
||||
@ -45,7 +45,7 @@ public:
|
||||
|
||||
void AddObserver(SearchView * observer);
|
||||
void UpdateSaveList(int pageNumber, std::string query);
|
||||
vector<Save*> GetSaveList();
|
||||
vector<SaveInfo*> GetSaveList();
|
||||
string GetLastError() { return lastError; }
|
||||
int GetPageCount() { return max(1, (int)(ceil(resultCount/16))); }
|
||||
int GetPageNum() { return currentPage; }
|
||||
@ -56,8 +56,8 @@ public:
|
||||
bool GetShowOwn() { return showOwn; }
|
||||
void SetShowFavourite(bool show) { if(show!=showFavourite) { showFavourite = show; } notifyShowFavouriteChanged(); }
|
||||
bool GetShowFavourite() { return showFavourite; }
|
||||
void SetLoadedSave(Save * save);
|
||||
Save * GetLoadedSave();
|
||||
void SetLoadedSave(SaveInfo * save);
|
||||
SaveInfo * GetLoadedSave();
|
||||
bool GetSavesLoaded() { return saveListLoaded; }
|
||||
vector<int> GetSelected() { return selected; }
|
||||
void ClearSelected() { selected.clear(); notifySelectedChanged(); }
|
||||
|
@ -286,7 +286,7 @@ void SearchView::NotifySaveListChanged(SearchModel * sender)
|
||||
int buttonWidth, buttonHeight, saveX = 0, saveY = 0, savesX = 5, savesY = 4, buttonPadding = 2;
|
||||
int buttonAreaWidth, buttonAreaHeight, buttonXOffset, buttonYOffset;
|
||||
|
||||
vector<Save*> saves = sender->GetSaveList();
|
||||
vector<SaveInfo*> saves = sender->GetSaveList();
|
||||
Client::Ref().ClearThumbnailRequests();
|
||||
for(i = 0; i < saveButtons.size(); i++)
|
||||
{
|
||||
|
27
src/simulation/Particle.cpp
Normal file
27
src/simulation/Particle.cpp
Normal file
@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Particle.cpp
|
||||
*
|
||||
* Created on: Jun 6, 2012
|
||||
* Author: Simon
|
||||
*/
|
||||
|
||||
#include <cstddef>
|
||||
#include "Particle.h"
|
||||
|
||||
std::vector<StructProperty> Particle::GetProperties()
|
||||
{
|
||||
std::vector<StructProperty> properties;
|
||||
properties.push_back(StructProperty("type", StructProperty::ParticleType, offsetof(Particle, type)));
|
||||
properties.push_back(StructProperty("life", StructProperty::ParticleType, offsetof(Particle, life)));
|
||||
properties.push_back(StructProperty("ctype", StructProperty::ParticleType, offsetof(Particle, ctype)));
|
||||
properties.push_back(StructProperty("x", StructProperty::Float, offsetof(Particle, x)));
|
||||
properties.push_back(StructProperty("y", StructProperty::Float, offsetof(Particle, y)));
|
||||
properties.push_back(StructProperty("vx", StructProperty::Float, offsetof(Particle, vx)));
|
||||
properties.push_back(StructProperty("vy", StructProperty::Float, offsetof(Particle, vy)));
|
||||
properties.push_back(StructProperty("temp", StructProperty::Float, offsetof(Particle, temp)));
|
||||
properties.push_back(StructProperty("flags", StructProperty::UInteger, offsetof(Particle, flags)));
|
||||
properties.push_back(StructProperty("tmp", StructProperty::Integer, offsetof(Particle, tmp)));
|
||||
properties.push_back(StructProperty("tmp2", StructProperty::Integer, offsetof(Particle, tmp2)));
|
||||
properties.push_back(StructProperty("dcolour", StructProperty::UInteger, offsetof(Particle, dcolour)));
|
||||
return properties;
|
||||
}
|
@ -9,6 +9,7 @@
|
||||
#ifndef The_Powder_Toy_Particle_h
|
||||
#define The_Powder_Toy_Particle_h
|
||||
|
||||
#include <vector>
|
||||
#include "StructProperty.h"
|
||||
|
||||
struct Particle
|
||||
@ -24,23 +25,7 @@ struct Particle
|
||||
unsigned int dcolour;
|
||||
/** Returns a list of properties, their type and offset within the structure that can be changed
|
||||
by higher-level processes refering to them by name such as Lua or the property tool **/
|
||||
static std::vector<StructProperty> GetProperties()
|
||||
{
|
||||
std::vector<StructProperty> properties;
|
||||
properties.push_back(StructProperty("type", StructProperty::ParticleType, offsetof(Particle, type)));
|
||||
properties.push_back(StructProperty("life", StructProperty::ParticleType, offsetof(Particle, life)));
|
||||
properties.push_back(StructProperty("ctype", StructProperty::ParticleType, offsetof(Particle, ctype)));
|
||||
properties.push_back(StructProperty("x", StructProperty::Float, offsetof(Particle, x)));
|
||||
properties.push_back(StructProperty("y", StructProperty::Float, offsetof(Particle, y)));
|
||||
properties.push_back(StructProperty("vx", StructProperty::Float, offsetof(Particle, vx)));
|
||||
properties.push_back(StructProperty("vy", StructProperty::Float, offsetof(Particle, vy)));
|
||||
properties.push_back(StructProperty("temp", StructProperty::Float, offsetof(Particle, temp)));
|
||||
properties.push_back(StructProperty("flags", StructProperty::UInteger, offsetof(Particle, flags)));
|
||||
properties.push_back(StructProperty("tmp", StructProperty::Integer, offsetof(Particle, tmp)));
|
||||
properties.push_back(StructProperty("tmp2", StructProperty::Integer, offsetof(Particle, tmp2)));
|
||||
properties.push_back(StructProperty("dcolour", StructProperty::UInteger, offsetof(Particle, dcolour)));
|
||||
return properties;
|
||||
}
|
||||
static std::vector<StructProperty> GetProperties();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -9,6 +9,8 @@
|
||||
#ifndef The_Powder_Toy_StructProperty_h
|
||||
#define The_Powder_Toy_StructProperty_h
|
||||
|
||||
#include <string>
|
||||
|
||||
struct StructProperty
|
||||
{
|
||||
enum PropertyType { ParticleType, Colour, Integer, UInteger, Float, String };
|
||||
|
@ -7,14 +7,14 @@
|
||||
|
||||
#include "SSaveController.h"
|
||||
|
||||
SSaveController::SSaveController(ControllerCallback * callback, Save save):
|
||||
SSaveController::SSaveController(ControllerCallback * callback, SaveInfo save):
|
||||
HasExited(false)
|
||||
{
|
||||
ssaveView = new SSaveView();
|
||||
ssaveView->AttachController(this);
|
||||
ssaveModel = new SSaveModel();
|
||||
ssaveModel->AddObserver(ssaveView);
|
||||
ssaveModel->SetSave(new Save(save));
|
||||
ssaveModel->SetSave(new SaveInfo(save));
|
||||
|
||||
this->callback = callback;
|
||||
}
|
||||
@ -24,7 +24,7 @@ void SSaveController::UploadSave(std::string saveName, std::string saveDescripti
|
||||
ssaveModel->UploadSave(saveName, saveDescription, publish);
|
||||
}
|
||||
|
||||
Save * SSaveController::GetSave()
|
||||
SaveInfo * SSaveController::GetSave()
|
||||
{
|
||||
return ssaveModel->GetSave();
|
||||
}
|
||||
|
@ -11,7 +11,7 @@
|
||||
#include "SSaveModel.h"
|
||||
#include "SSaveView.h"
|
||||
#include "Controller.h"
|
||||
#include "search/Save.h"
|
||||
#include "client/SaveInfo.h"
|
||||
|
||||
class SSaveView;
|
||||
class SSaveModel;
|
||||
@ -21,8 +21,8 @@ class SSaveController {
|
||||
ControllerCallback * callback;
|
||||
public:
|
||||
bool HasExited;
|
||||
SSaveController(ControllerCallback * callback, Save save);
|
||||
Save * GetSave();
|
||||
SSaveController(ControllerCallback * callback, SaveInfo save);
|
||||
SaveInfo * GetSave();
|
||||
bool GetSaveUploaded();
|
||||
void Exit();
|
||||
void Update();
|
||||
|
@ -51,13 +51,13 @@ void SSaveModel::UploadSave(std::string saveName, std::string saveDescription, b
|
||||
notifySaveUploadChanged();
|
||||
}
|
||||
|
||||
void SSaveModel::SetSave(Save * save)
|
||||
void SSaveModel::SetSave(SaveInfo * save)
|
||||
{
|
||||
this->save = save;
|
||||
notifySaveChanged();
|
||||
}
|
||||
|
||||
Save * SSaveModel::GetSave()
|
||||
SaveInfo * SSaveModel::GetSave()
|
||||
{
|
||||
return this->save;
|
||||
}
|
||||
|
@ -11,14 +11,14 @@
|
||||
#include <vector>
|
||||
|
||||
#include "SSaveView.h"
|
||||
#include "search/Save.h"
|
||||
#include "client/SaveInfo.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
class SSaveView;
|
||||
class SSaveModel {
|
||||
vector<SSaveView*> observers;
|
||||
Save * save;
|
||||
SaveInfo * save;
|
||||
void notifySaveChanged();
|
||||
void notifySaveUploadChanged();
|
||||
bool saveUploaded;
|
||||
@ -26,8 +26,8 @@ public:
|
||||
SSaveModel();
|
||||
void AddObserver(SSaveView * observer);
|
||||
void Update();
|
||||
Save * GetSave();
|
||||
void SetSave(Save * save);
|
||||
SaveInfo * GetSave();
|
||||
void SetSave(SaveInfo * save);
|
||||
void UploadSave(std::string saveName, std::string saveDescription, bool publish);
|
||||
bool GetSaveUploaded();
|
||||
virtual ~SSaveModel();
|
||||
|
@ -11,7 +11,7 @@
|
||||
#include "TagsModel.h"
|
||||
#include "TagsView.h"
|
||||
|
||||
TagsController::TagsController(ControllerCallback * callback, Save * save):
|
||||
TagsController::TagsController(ControllerCallback * callback, SaveInfo * save):
|
||||
HasDone(false)
|
||||
{
|
||||
tagsModel = new TagsModel();
|
||||
@ -24,7 +24,7 @@ TagsController::TagsController(ControllerCallback * callback, Save * save):
|
||||
this->callback = callback;
|
||||
}
|
||||
|
||||
Save * TagsController::GetSave()
|
||||
SaveInfo * TagsController::GetSave()
|
||||
{
|
||||
return tagsModel->GetSave();
|
||||
}
|
||||
|
@ -10,7 +10,7 @@
|
||||
|
||||
#include "Controller.h"
|
||||
#include "TagsView.h"
|
||||
#include "search/Save.h"
|
||||
#include "client/SaveInfo.h"
|
||||
|
||||
class TagsView;
|
||||
class TagsModel;
|
||||
@ -20,9 +20,9 @@ class TagsController {
|
||||
TagsModel * tagsModel;
|
||||
public:
|
||||
bool HasDone;
|
||||
TagsController(ControllerCallback * callback, Save * save);
|
||||
TagsController(ControllerCallback * callback, SaveInfo * save);
|
||||
TagsView * GetView() {return tagsView;}
|
||||
Save * GetSave();
|
||||
SaveInfo * GetSave();
|
||||
void RemoveTag(string tag);
|
||||
void AddTag(string tag);
|
||||
void Exit();
|
||||
|
@ -17,13 +17,13 @@ TagsModel::TagsModel():
|
||||
|
||||
}
|
||||
|
||||
void TagsModel::SetSave(Save * save)
|
||||
void TagsModel::SetSave(SaveInfo * save)
|
||||
{
|
||||
this->save = save;
|
||||
notifyTagsChanged();
|
||||
}
|
||||
|
||||
Save * TagsModel::GetSave()
|
||||
SaveInfo * TagsModel::GetSave()
|
||||
{
|
||||
return save;
|
||||
}
|
||||
|
@ -9,20 +9,20 @@
|
||||
#define TAGSMODEL_H_
|
||||
|
||||
#include <vector>
|
||||
#include "search/Save.h"
|
||||
#include "client/SaveInfo.h"
|
||||
|
||||
class TagsView;
|
||||
class TagsModel {
|
||||
Save * save;
|
||||
SaveInfo * save;
|
||||
std::vector<TagsView*> observers;
|
||||
void notifyTagsChanged();
|
||||
public:
|
||||
TagsModel();
|
||||
void AddObserver(TagsView * observer);
|
||||
void SetSave(Save * save);
|
||||
void SetSave(SaveInfo * save);
|
||||
void RemoveTag(string tag);
|
||||
void AddTag(string tag);
|
||||
Save * GetSave();
|
||||
SaveInfo * GetSave();
|
||||
virtual ~TagsModel();
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user