mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-08-19 06:31:26 +02:00
Save as current name complete, resolves #5
This commit is contained in:
@@ -19,6 +19,7 @@
|
|||||||
#include "filebrowser/FileBrowserActivity.h"
|
#include "filebrowser/FileBrowserActivity.h"
|
||||||
#include "save/LocalSaveActivity.h"
|
#include "save/LocalSaveActivity.h"
|
||||||
#include "save/ServerSaveActivity.h"
|
#include "save/ServerSaveActivity.h"
|
||||||
|
#include "interface/Keys.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
@@ -433,26 +434,26 @@ bool GameController::KeyRelease(int key, Uint16 character, bool shift, bool ctrl
|
|||||||
if(ret)
|
if(ret)
|
||||||
{
|
{
|
||||||
Simulation * sim = gameModel->GetSimulation();
|
Simulation * sim = gameModel->GetSimulation();
|
||||||
if (key == SDLK_RIGHT || key == SDLK_LEFT)
|
if (key == KEY_RIGHT || key == KEY_LEFT)
|
||||||
{
|
{
|
||||||
sim->player.pcomm = sim->player.comm; //Saving last movement
|
sim->player.pcomm = sim->player.comm; //Saving last movement
|
||||||
sim->player.comm = (int)(sim->player.comm)&12; //Stop command
|
sim->player.comm = (int)(sim->player.comm)&12; //Stop command
|
||||||
}
|
}
|
||||||
if (key == SDLK_UP)
|
if (key == KEY_UP)
|
||||||
{
|
{
|
||||||
sim->player.comm = (int)(sim->player.comm)&11;
|
sim->player.comm = (int)(sim->player.comm)&11;
|
||||||
}
|
}
|
||||||
if (key == SDLK_DOWN)
|
if (key == KEY_DOWN)
|
||||||
{
|
{
|
||||||
sim->player.comm = (int)(sim->player.comm)&7;
|
sim->player.comm = (int)(sim->player.comm)&7;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (key == SDLK_d || key == SDLK_a)
|
if (key == KEY_d || key == KEY_a)
|
||||||
{
|
{
|
||||||
sim->player2.pcomm = sim->player2.comm; //Saving last movement
|
sim->player2.pcomm = sim->player2.comm; //Saving last movement
|
||||||
sim->player2.comm = (int)(sim->player2.comm)&12; //Stop command
|
sim->player2.comm = (int)(sim->player2.comm)&12; //Stop command
|
||||||
}
|
}
|
||||||
if (key == SDLK_w)
|
if (key == KEY_w)
|
||||||
{
|
{
|
||||||
sim->player2.comm = (int)(sim->player2.comm)&11;
|
sim->player2.comm = (int)(sim->player2.comm)&11;
|
||||||
}
|
}
|
||||||
@@ -852,11 +853,8 @@ void GameController::SaveAsCurrent()
|
|||||||
//c->LoadSave(&save);
|
//c->LoadSave(&save);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if(!gameModel->GetSave() || gameModel->GetUser().Username != gameModel->GetSave()->GetUserName())
|
|
||||||
{
|
if(gameModel->GetSave() && gameModel->GetUser().ID && gameModel->GetUser().Username == gameModel->GetSave()->GetUserName())
|
||||||
OpenSaveWindow();
|
|
||||||
}
|
|
||||||
if(gameModel->GetUser().ID)
|
|
||||||
{
|
{
|
||||||
Simulation * sim = gameModel->GetSimulation();
|
Simulation * sim = gameModel->GetSimulation();
|
||||||
GameSave * gameSave = sim->Save();
|
GameSave * gameSave = sim->Save();
|
||||||
@@ -886,6 +884,10 @@ void GameController::SaveAsCurrent()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if(gameModel->GetUser().ID)
|
||||||
|
{
|
||||||
|
OpenSaveWindow();
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
new ErrorMessage("Error", "You need to login to upload saves.");
|
new ErrorMessage("Error", "You need to login to upload saves.");
|
||||||
|
@@ -54,7 +54,7 @@ public:
|
|||||||
{
|
{
|
||||||
if(leftDown)
|
if(leftDown)
|
||||||
DoLeftAction();
|
DoLeftAction();
|
||||||
if(rightDown)
|
else if(rightDown)
|
||||||
DoRightAction();
|
DoRightAction();
|
||||||
}
|
}
|
||||||
ui::Button::OnMouseUp(x, y, button);
|
ui::Button::OnMouseUp(x, y, button);
|
||||||
|
@@ -8,6 +8,7 @@
|
|||||||
#include "dialogues/ErrorMessage.h"
|
#include "dialogues/ErrorMessage.h"
|
||||||
#include "dialogues/ConfirmPrompt.h"
|
#include "dialogues/ConfirmPrompt.h"
|
||||||
#include "client/Client.h"
|
#include "client/Client.h"
|
||||||
|
#include "tasks/Task.h"
|
||||||
#include "Style.h"
|
#include "Style.h"
|
||||||
|
|
||||||
class ServerSaveActivity::CancelAction: public ui::ButtonAction
|
class ServerSaveActivity::CancelAction: public ui::ButtonAction
|
||||||
@@ -32,11 +33,46 @@ public:
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//Currently, reading is done on another thread, we can't render outside the main thread due to some bullshit with OpenGL
|
||||||
|
class SaveUploadTask: public Task
|
||||||
|
{
|
||||||
|
SaveInfo save;
|
||||||
|
|
||||||
|
virtual void before()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void after()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual bool doWork()
|
||||||
|
{
|
||||||
|
notifyProgress(-1);
|
||||||
|
return Client::Ref().UploadSave(save) == RequestOkay;
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
SaveInfo GetSave()
|
||||||
|
{
|
||||||
|
return save;
|
||||||
|
}
|
||||||
|
|
||||||
|
SaveUploadTask(SaveInfo save):
|
||||||
|
save(save)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
ServerSaveActivity::ServerSaveActivity(SaveInfo save, ServerSaveActivity::SaveUploadedCallback * callback) :
|
ServerSaveActivity::ServerSaveActivity(SaveInfo save, ServerSaveActivity::SaveUploadedCallback * callback) :
|
||||||
WindowActivity(ui::Point(-1, -1), ui::Point(440, 200)),
|
WindowActivity(ui::Point(-1, -1), ui::Point(440, 200)),
|
||||||
thumbnail(NULL),
|
thumbnail(NULL),
|
||||||
save(save),
|
save(save),
|
||||||
callback(callback)
|
callback(callback),
|
||||||
|
saveUploadTask(NULL)
|
||||||
{
|
{
|
||||||
ui::Label * titleLabel = new ui::Label(ui::Point(4, 5), ui::Point((Size.X/2)-8, 16), "Save to server:");
|
ui::Label * titleLabel = new ui::Label(ui::Point(4, 5), ui::Point((Size.X/2)-8, 16), "Save to server:");
|
||||||
titleLabel->SetTextColour(style::Colour::InformationTitle);
|
titleLabel->SetTextColour(style::Colour::InformationTitle);
|
||||||
@@ -98,13 +134,27 @@ ServerSaveActivity::ServerSaveActivity(SaveInfo save, bool saveNow, ServerSaveAc
|
|||||||
WindowActivity(ui::Point(-1, -1), ui::Point(200, 50)),
|
WindowActivity(ui::Point(-1, -1), ui::Point(200, 50)),
|
||||||
thumbnail(NULL),
|
thumbnail(NULL),
|
||||||
save(save),
|
save(save),
|
||||||
callback(callback)
|
callback(callback),
|
||||||
|
saveUploadTask(NULL)
|
||||||
{
|
{
|
||||||
ui::Label * titleLabel = new ui::Label(ui::Point(0, 0), Size, "Saving to server...");
|
ui::Label * titleLabel = new ui::Label(ui::Point(0, 0), Size, "Saving to server...");
|
||||||
titleLabel->SetTextColour(style::Colour::InformationTitle);
|
titleLabel->SetTextColour(style::Colour::InformationTitle);
|
||||||
titleLabel->Appearance.HorizontalAlign = ui::Appearance::AlignCentre;
|
titleLabel->Appearance.HorizontalAlign = ui::Appearance::AlignCentre;
|
||||||
titleLabel->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
|
titleLabel->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
|
||||||
AddComponent(titleLabel);
|
AddComponent(titleLabel);
|
||||||
|
|
||||||
|
saveUploadTask = new SaveUploadTask(save);
|
||||||
|
saveUploadTask->AddTaskListener(this);
|
||||||
|
saveUploadTask->Start();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ServerSaveActivity::NotifyDone(Task * task)
|
||||||
|
{
|
||||||
|
Exit();
|
||||||
|
if(!task->GetSuccess())
|
||||||
|
{
|
||||||
|
new ErrorMessage("Error", "Error while saving");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ServerSaveActivity::Save()
|
void ServerSaveActivity::Save()
|
||||||
@@ -169,6 +219,12 @@ void ServerSaveActivity::Exit()
|
|||||||
WindowActivity::Exit();
|
WindowActivity::Exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ServerSaveActivity::OnTick(float dt)
|
||||||
|
{
|
||||||
|
if(saveUploadTask)
|
||||||
|
saveUploadTask->Poll();
|
||||||
|
}
|
||||||
|
|
||||||
void ServerSaveActivity::OnDraw()
|
void ServerSaveActivity::OnDraw()
|
||||||
{
|
{
|
||||||
Graphics * g = ui::Engine::Ref().g;
|
Graphics * g = ui::Engine::Ref().g;
|
||||||
@@ -192,5 +248,6 @@ void ServerSaveActivity::OnThumbnailReady(Thumbnail * thumbnail)
|
|||||||
|
|
||||||
ServerSaveActivity::~ServerSaveActivity()
|
ServerSaveActivity::~ServerSaveActivity()
|
||||||
{
|
{
|
||||||
|
if(saveUploadTask)
|
||||||
|
delete saveUploadTask;
|
||||||
}
|
}
|
@@ -3,6 +3,7 @@
|
|||||||
#include "Activity.h"
|
#include "Activity.h"
|
||||||
#include "client/SaveInfo.h"
|
#include "client/SaveInfo.h"
|
||||||
#include "client/ThumbnailListener.h"
|
#include "client/ThumbnailListener.h"
|
||||||
|
#include "tasks/TaskListener.h"
|
||||||
|
|
||||||
namespace ui
|
namespace ui
|
||||||
{
|
{
|
||||||
@@ -10,8 +11,9 @@ namespace ui
|
|||||||
class Checkbox;
|
class Checkbox;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class Task;
|
||||||
class Thumbnail;
|
class Thumbnail;
|
||||||
class ServerSaveActivity: public WindowActivity, public ThumbnailListener
|
class ServerSaveActivity: public WindowActivity, public ThumbnailListener, public TaskListener
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
class SaveUploadedCallback
|
class SaveUploadedCallback
|
||||||
@@ -28,8 +30,11 @@ public:
|
|||||||
virtual void Exit();
|
virtual void Exit();
|
||||||
virtual void OnDraw();
|
virtual void OnDraw();
|
||||||
virtual void OnThumbnailReady(Thumbnail * thumbnail);
|
virtual void OnThumbnailReady(Thumbnail * thumbnail);
|
||||||
|
virtual void OnTick(float dt);
|
||||||
virtual ~ServerSaveActivity();
|
virtual ~ServerSaveActivity();
|
||||||
protected:
|
protected:
|
||||||
|
virtual void NotifyDone(Task * task);
|
||||||
|
Task * saveUploadTask;
|
||||||
SaveUploadedCallback * callback;
|
SaveUploadedCallback * callback;
|
||||||
SaveInfo save;
|
SaveInfo save;
|
||||||
Thumbnail * thumbnail;
|
Thumbnail * thumbnail;
|
||||||
|
@@ -102,7 +102,11 @@ void Task::Poll()
|
|||||||
|
|
||||||
Task::~Task()
|
Task::~Task()
|
||||||
{
|
{
|
||||||
|
if(!done)
|
||||||
|
{
|
||||||
|
pthread_join(doWorkThread, NULL);
|
||||||
|
pthread_mutex_destroy(&taskMutex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Task::before()
|
void Task::before()
|
||||||
|
Reference in New Issue
Block a user