Started work on save as current name
This commit is contained in:
parent
9c1c4119d3
commit
a8dcc7a070
@ -837,6 +837,61 @@ void GameController::OpenSaveWindow()
|
||||
}
|
||||
}
|
||||
|
||||
void GameController::SaveAsCurrent()
|
||||
{
|
||||
|
||||
class SaveUploadedCallback: public ServerSaveActivity::SaveUploadedCallback
|
||||
{
|
||||
GameController * c;
|
||||
public:
|
||||
SaveUploadedCallback(GameController * _c): c(_c) {}
|
||||
virtual ~SaveUploadedCallback() {};
|
||||
virtual void SaveUploaded(SaveInfo save)
|
||||
{
|
||||
//Don't do anything
|
||||
//c->LoadSave(&save);
|
||||
}
|
||||
};
|
||||
if(gameModel->GetSave() && gameModel->GetUser().Username != gameModel->GetSave()->GetUserName())
|
||||
{
|
||||
OpenSaveWindow();
|
||||
}
|
||||
if(gameModel->GetUser().ID)
|
||||
{
|
||||
Simulation * sim = gameModel->GetSimulation();
|
||||
GameSave * gameSave = sim->Save();
|
||||
gameSave->paused = gameModel->GetPaused();
|
||||
gameSave->gravityMode = sim->gravityMode;
|
||||
gameSave->airMode = sim->air->airMode;
|
||||
gameSave->legacyEnable = sim->legacy_enable;
|
||||
gameSave->waterEEnabled = sim->water_equal_test;
|
||||
gameSave->gravityEnable = sim->grav->ngrav_enable;
|
||||
if(!gameSave)
|
||||
{
|
||||
new ErrorMessage("Error", "Unable to build save.");
|
||||
}
|
||||
else
|
||||
{
|
||||
if(gameModel->GetSave())
|
||||
{
|
||||
SaveInfo tempSave(*gameModel->GetSave());
|
||||
tempSave.SetGameSave(gameSave);
|
||||
new ServerSaveActivity(tempSave, true, new SaveUploadedCallback(this));
|
||||
}
|
||||
else
|
||||
{
|
||||
SaveInfo tempSave(0, 0, 0, 0, gameModel->GetUser().Username, "");
|
||||
tempSave.SetGameSave(gameSave);
|
||||
new ServerSaveActivity(tempSave, true, new SaveUploadedCallback(this));
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
new ErrorMessage("Error", "You need to login to upload saves.");
|
||||
}
|
||||
}
|
||||
|
||||
void GameController::FrameStep()
|
||||
{
|
||||
gameModel->FrameStep(1);
|
||||
|
@ -94,6 +94,7 @@ public:
|
||||
void OpenOptions();
|
||||
void OpenRenderOptions();
|
||||
void OpenSaveWindow();
|
||||
void SaveAsCurrent();
|
||||
void OpenStamps();
|
||||
void OpenElementSearch();
|
||||
void PlaceSave(ui::Point position);
|
||||
|
@ -16,6 +16,133 @@
|
||||
#include "Format.h"
|
||||
#include "QuickOption.h"
|
||||
|
||||
|
||||
class SplitButton;
|
||||
class SplitButtonAction
|
||||
{
|
||||
public:
|
||||
virtual void ActionCallbackLeft(ui::Button * sender) {}
|
||||
virtual void ActionCallbackRight(ui::Button * sender) {}
|
||||
virtual ~SplitButtonAction() {}
|
||||
};
|
||||
class SplitButton : public ui::Button
|
||||
{
|
||||
private:
|
||||
bool rightDown;
|
||||
bool leftDown;
|
||||
bool showSplit;
|
||||
int splitPosition;
|
||||
std::string toolTip2;
|
||||
SplitButtonAction * splitActionCallback;
|
||||
public:
|
||||
SplitButton(ui::Point position, ui::Point size, std::string buttonText, std::string toolTip, std::string toolTip2, int split) :
|
||||
Button(position, size, buttonText, toolTip),
|
||||
toolTip2(toolTip2),
|
||||
splitPosition(split),
|
||||
splitActionCallback(NULL),
|
||||
showSplit(true)
|
||||
{
|
||||
|
||||
}
|
||||
bool GetShowSplit() { return showSplit; }
|
||||
void SetShowSplit(bool split) { showSplit = split; }
|
||||
SplitButtonAction * GetSplitActionCallback() { return splitActionCallback; }
|
||||
void SetSplitActionCallback(SplitButtonAction * newAction) { splitActionCallback = newAction; }
|
||||
virtual void OnMouseUp(int x, int y, unsigned int button)
|
||||
{
|
||||
if(isButtonDown)
|
||||
{
|
||||
if(leftDown)
|
||||
DoLeftAction();
|
||||
if(rightDown)
|
||||
DoRightAction();
|
||||
}
|
||||
ui::Button::OnMouseUp(x, y, button);
|
||||
|
||||
}
|
||||
virtual void OnMouseMovedInside(int x, int y, int dx, int dy)
|
||||
{
|
||||
if(x >= splitPosition)
|
||||
{
|
||||
if(toolTip.length()>0 && GetParentWindow())
|
||||
{
|
||||
GetParentWindow()->ToolTip(this, ui::Point(x, y), toolTip);
|
||||
}
|
||||
}
|
||||
else if(x < splitPosition)
|
||||
{
|
||||
if(toolTip2.length()>0 && GetParentWindow())
|
||||
{
|
||||
GetParentWindow()->ToolTip(this, ui::Point(x, y), toolTip2);
|
||||
}
|
||||
}
|
||||
}
|
||||
virtual void OnMouseEnter(int x, int y)
|
||||
{
|
||||
isMouseInside = true;
|
||||
if(!Enabled)
|
||||
return;
|
||||
if(x >= splitPosition)
|
||||
{
|
||||
if(toolTip.length()>0 && GetParentWindow())
|
||||
{
|
||||
GetParentWindow()->ToolTip(this, ui::Point(x, y), toolTip);
|
||||
}
|
||||
}
|
||||
else if(x < splitPosition)
|
||||
{
|
||||
if(toolTip2.length()>0 && GetParentWindow())
|
||||
{
|
||||
GetParentWindow()->ToolTip(this, ui::Point(x, y), toolTip2);
|
||||
}
|
||||
}
|
||||
}
|
||||
virtual void TextPosition()
|
||||
{
|
||||
ui::Button::TextPosition();
|
||||
textPosition.X += 3;
|
||||
}
|
||||
virtual void OnMouseClick(int x, int y, unsigned int button)
|
||||
{
|
||||
ui::Button::OnMouseClick(x, y, button);
|
||||
rightDown = false;
|
||||
leftDown = false;
|
||||
if(x >= splitPosition)
|
||||
rightDown = true;
|
||||
else if(x < splitPosition)
|
||||
leftDown = true;
|
||||
}
|
||||
void DoRightAction()
|
||||
{
|
||||
if(!Enabled)
|
||||
return;
|
||||
if(splitActionCallback)
|
||||
splitActionCallback->ActionCallbackRight(this);
|
||||
}
|
||||
void DoLeftAction()
|
||||
{
|
||||
if(!Enabled)
|
||||
return;
|
||||
if(splitActionCallback)
|
||||
splitActionCallback->ActionCallbackLeft(this);
|
||||
}
|
||||
void Draw(const ui::Point& screenPos)
|
||||
{
|
||||
ui::Button::Draw(screenPos);
|
||||
Graphics * g = ui::Engine::Ref().g;
|
||||
drawn = true;
|
||||
|
||||
if(showSplit)
|
||||
g->draw_line(splitPosition+screenPos.X, screenPos.Y+1, splitPosition+screenPos.X, screenPos.Y+Size.Y-2, 180, 180, 180, 255);
|
||||
}
|
||||
virtual ~SplitButton()
|
||||
{
|
||||
if(splitActionCallback)
|
||||
delete splitActionCallback;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
GameView::GameView():
|
||||
ui::Window(ui::Point(0, 0), ui::Point(XRES+BARSIZE, YRES+MENUSIZE)),
|
||||
pointQueue(queue<ui::Point*>()),
|
||||
@ -92,24 +219,31 @@ GameView::GameView():
|
||||
reloadButton->SetActionCallback(new ReloadAction(this));
|
||||
AddComponent(reloadButton);
|
||||
|
||||
class SaveSimulationAction : public ui::ButtonAction
|
||||
class SaveSimulationAction : public SplitButtonAction
|
||||
{
|
||||
GameView * v;
|
||||
public:
|
||||
SaveSimulationAction(GameView * _v) { v = _v; }
|
||||
void ActionCallback(ui::Button * sender)
|
||||
void ActionCallbackRight(ui::Button * sender)
|
||||
{
|
||||
if(v->CtrlBehaviour())
|
||||
v->c->OpenLocalSaveWindow();
|
||||
else
|
||||
v->c->OpenSaveWindow();
|
||||
}
|
||||
void ActionCallbackLeft(ui::Button * sender)
|
||||
{
|
||||
if(v->CtrlBehaviour())
|
||||
v->c->OpenLocalSaveWindow();
|
||||
else
|
||||
v->c->SaveAsCurrent();
|
||||
}
|
||||
};
|
||||
saveSimulationButton = new ui::Button(ui::Point(currentX, Size.Y-16), ui::Point(150, 15), "[untitled simulation]");
|
||||
saveSimulationButton = new SplitButton(ui::Point(currentX, Size.Y-16), ui::Point(150, 15), "[untitled simulation]", "Save game as current name", "Save game as new name", 19);
|
||||
saveSimulationButton->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
|
||||
saveSimulationButton->SetIcon(IconSave);
|
||||
currentX+=151;
|
||||
saveSimulationButton->SetActionCallback(new SaveSimulationAction(this));
|
||||
((SplitButton*)saveSimulationButton)->SetSplitActionCallback(new SaveSimulationAction(this));
|
||||
AddComponent(saveSimulationButton);
|
||||
|
||||
class UpVoteAction : public ui::ButtonAction
|
||||
@ -683,6 +817,10 @@ void GameView::NotifySaveChanged(GameModel * sender)
|
||||
if(sender->GetSave())
|
||||
{
|
||||
saveSimulationButton->SetText(sender->GetSave()->GetName());
|
||||
if(sender->GetSave()->GetUserName() == sender->GetUser().Username)
|
||||
((SplitButton*)saveSimulationButton)->SetShowSplit(true);
|
||||
else
|
||||
((SplitButton*)saveSimulationButton)->SetShowSplit(false);
|
||||
reloadButton->Enabled = true;
|
||||
upVoteButton->Enabled = (sender->GetSave()->GetID() && sender->GetUser().ID && sender->GetSave()->GetVote()==0);
|
||||
if(sender->GetSave()->GetID() && sender->GetUser().ID && sender->GetSave()->GetVote()==1)
|
||||
@ -721,6 +859,7 @@ void GameView::NotifySaveChanged(GameModel * sender)
|
||||
}
|
||||
else
|
||||
{
|
||||
((SplitButton*)saveSimulationButton)->SetShowSplit(false);
|
||||
saveSimulationButton->SetText("[untitled simulation]");
|
||||
reloadButton->Enabled = false;
|
||||
upVoteButton->Enabled = false;
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include "Graphics.h"
|
||||
#include "font.h"
|
||||
#include <pthread.h>
|
||||
#undef GetUserName //God dammit microsoft!
|
||||
|
||||
#ifdef OGLI
|
||||
|
||||
|
@ -11,6 +11,7 @@
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include <pthread.h>
|
||||
#undef GetUserName //God dammit microsoft!
|
||||
#include "PreviewView.h"
|
||||
#include "client/SaveInfo.h"
|
||||
#include "preview/Comment.h"
|
||||
|
@ -94,6 +94,19 @@ ServerSaveActivity::ServerSaveActivity(SaveInfo save, ServerSaveActivity::SaveUp
|
||||
ThumbnailBroker::Ref().RenderThumbnail(save.GetGameSave(), (Size.X/2)-16, -1, this);
|
||||
}
|
||||
|
||||
ServerSaveActivity::ServerSaveActivity(SaveInfo save, bool saveNow, ServerSaveActivity::SaveUploadedCallback * callback) :
|
||||
WindowActivity(ui::Point(-1, -1), ui::Point(200, 50)),
|
||||
thumbnail(NULL),
|
||||
save(save),
|
||||
callback(callback)
|
||||
{
|
||||
ui::Label * titleLabel = new ui::Label(ui::Point(0, 0), Size, "Saving to server...");
|
||||
titleLabel->SetTextColour(style::Colour::InformationTitle);
|
||||
titleLabel->Appearance.HorizontalAlign = ui::Appearance::AlignCentre;
|
||||
titleLabel->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
|
||||
AddComponent(titleLabel);
|
||||
}
|
||||
|
||||
void ServerSaveActivity::Save()
|
||||
{
|
||||
class PublishConfirmation: public ConfirmDialogueCallback {
|
||||
@ -161,7 +174,9 @@ void ServerSaveActivity::OnDraw()
|
||||
Graphics * g = ui::Engine::Ref().g;
|
||||
g->clearrect(Position.X-2, Position.Y-2, Size.X+3, Size.Y+3);
|
||||
g->drawrect(Position.X, Position.Y, Size.X, Size.Y, 255, 255, 255, 255);
|
||||
g->draw_line(Position.X+(Size.X/2)-1, Position.Y, Position.X+(Size.X/2)-1, Position.Y+Size.Y-1, 255, 255, 255, 255);
|
||||
|
||||
if(Size.X>220)
|
||||
g->draw_line(Position.X+(Size.X/2)-1, Position.Y, Position.X+(Size.X/2)-1, Position.Y+Size.Y-1, 255, 255, 255, 255);
|
||||
|
||||
if(thumbnail)
|
||||
{
|
||||
|
@ -22,6 +22,7 @@ public:
|
||||
virtual void SaveUploaded(SaveInfo save) {}
|
||||
};
|
||||
ServerSaveActivity(SaveInfo save, SaveUploadedCallback * callback);
|
||||
ServerSaveActivity(SaveInfo save, bool saveNow, SaveUploadedCallback * callback);
|
||||
void saveUpload();
|
||||
virtual void Save();
|
||||
virtual void Exit();
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <pthread.h>
|
||||
#undef GetUserName //God dammit microsoft!
|
||||
#include <cmath>
|
||||
#include "client/SaveInfo.h"
|
||||
#include "SearchView.h"
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include <cmath>
|
||||
#include <sys/types.h>
|
||||
#include <pthread.h>
|
||||
#undef GetUserName //God dammit microsoft!
|
||||
#include "Config.h"
|
||||
#include "Gravity.h"
|
||||
//#include "powder.h"
|
||||
|
@ -2,6 +2,7 @@
|
||||
#define GRAVITY_H
|
||||
|
||||
#include <pthread.h>
|
||||
#undef GetUserName //God dammit microsoft!
|
||||
#include "Config.h"
|
||||
#include "Simulation.h"
|
||||
|
||||
|
@ -10,6 +10,7 @@
|
||||
|
||||
#include <string>
|
||||
#include <pthread.h>
|
||||
#undef GetUserName //God dammit microsoft!
|
||||
#include "TaskListener.h"
|
||||
|
||||
class TaskListener;
|
||||
|
Reference in New Issue
Block a user