summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSimon Robertshaw <simon@hardwired.org.uk>2012-08-06 21:24:10 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2012-08-06 21:24:10 (GMT)
commita8dcc7a07016dde7299e1ce44ad5f4ea0d28149e (patch)
tree96e2d1d17f1a0a0a28427f3490532627c2e68bdc /src
parent9c1c4119d3b8700ea642dba24977ecf15608f383 (diff)
downloadpowder-a8dcc7a07016dde7299e1ce44ad5f4ea0d28149e.zip
powder-a8dcc7a07016dde7299e1ce44ad5f4ea0d28149e.tar.gz
Started work on save as current name
Diffstat (limited to 'src')
-rw-r--r--src/game/GameController.cpp55
-rw-r--r--src/game/GameController.h1
-rw-r--r--src/game/GameView.cpp147
-rw-r--r--src/graphics/OpenGLGraphics.cpp1
-rw-r--r--src/preview/PreviewModel.h1
-rw-r--r--src/save/ServerSaveActivity.cpp17
-rw-r--r--src/save/ServerSaveActivity.h1
-rw-r--r--src/search/SearchModel.h1
-rw-r--r--src/simulation/Gravity.cpp1
-rw-r--r--src/simulation/Gravity.h1
-rw-r--r--src/tasks/Task.h1
11 files changed, 222 insertions, 5 deletions
diff --git a/src/game/GameController.cpp b/src/game/GameController.cpp
index 2ca447d..ca5c839 100644
--- a/src/game/GameController.cpp
+++ b/src/game/GameController.cpp
@@ -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);
diff --git a/src/game/GameController.h b/src/game/GameController.h
index baa25ce..187d101 100644
--- a/src/game/GameController.h
+++ b/src/game/GameController.h
@@ -94,6 +94,7 @@ public:
void OpenOptions();
void OpenRenderOptions();
void OpenSaveWindow();
+ void SaveAsCurrent();
void OpenStamps();
void OpenElementSearch();
void PlaceSave(ui::Point position);
diff --git a/src/game/GameView.cpp b/src/game/GameView.cpp
index b64af05..7d21f02 100644
--- a/src/game/GameView.cpp
+++ b/src/game/GameView.cpp
@@ -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;
diff --git a/src/graphics/OpenGLGraphics.cpp b/src/graphics/OpenGLGraphics.cpp
index 43bff6b..b6dbe7f 100644
--- a/src/graphics/OpenGLGraphics.cpp
+++ b/src/graphics/OpenGLGraphics.cpp
@@ -1,6 +1,7 @@
#include "Graphics.h"
#include "font.h"
#include <pthread.h>
+#undef GetUserName //God dammit microsoft!
#ifdef OGLI
diff --git a/src/preview/PreviewModel.h b/src/preview/PreviewModel.h
index 11618a0..77cab37 100644
--- a/src/preview/PreviewModel.h
+++ b/src/preview/PreviewModel.h
@@ -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"
diff --git a/src/save/ServerSaveActivity.cpp b/src/save/ServerSaveActivity.cpp
index fe750a3..d367e61 100644
--- a/src/save/ServerSaveActivity.cpp
+++ b/src/save/ServerSaveActivity.cpp
@@ -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)
{
diff --git a/src/save/ServerSaveActivity.h b/src/save/ServerSaveActivity.h
index 2a383f3..23d7153 100644
--- a/src/save/ServerSaveActivity.h
+++ b/src/save/ServerSaveActivity.h
@@ -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();
diff --git a/src/search/SearchModel.h b/src/search/SearchModel.h
index 385ff05..d94ddc5 100644
--- a/src/search/SearchModel.h
+++ b/src/search/SearchModel.h
@@ -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"
diff --git a/src/simulation/Gravity.cpp b/src/simulation/Gravity.cpp
index 89f626e..ba26cb6 100644
--- a/src/simulation/Gravity.cpp
+++ b/src/simulation/Gravity.cpp
@@ -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"
diff --git a/src/simulation/Gravity.h b/src/simulation/Gravity.h
index 8d81211..ec31b6a 100644
--- a/src/simulation/Gravity.h
+++ b/src/simulation/Gravity.h
@@ -2,6 +2,7 @@
#define GRAVITY_H
#include <pthread.h>
+#undef GetUserName //God dammit microsoft!
#include "Config.h"
#include "Simulation.h"
diff --git a/src/tasks/Task.h b/src/tasks/Task.h
index 5a89278..a025ac1 100644
--- a/src/tasks/Task.h
+++ b/src/tasks/Task.h
@@ -10,6 +10,7 @@
#include <string>
#include <pthread.h>
+#undef GetUserName //God dammit microsoft!
#include "TaskListener.h"
class TaskListener;