diff --git a/src/game/GameController.cpp b/src/game/GameController.cpp index 2ca447d25..ca5c8394d 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 baa25ceb2..187d1012d 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 b64af05a2..7d21f028d 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()), @@ -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 43bff6bc1..b6dbe7f07 100644 --- a/src/graphics/OpenGLGraphics.cpp +++ b/src/graphics/OpenGLGraphics.cpp @@ -1,6 +1,7 @@ #include "Graphics.h" #include "font.h" #include +#undef GetUserName //God dammit microsoft! #ifdef OGLI diff --git a/src/preview/PreviewModel.h b/src/preview/PreviewModel.h index 11618a041..77cab3725 100644 --- a/src/preview/PreviewModel.h +++ b/src/preview/PreviewModel.h @@ -11,6 +11,7 @@ #include #include #include + #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 fe750a34b..d367e61b3 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 2a383f3ab..23d7153fc 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 385ff0576..d94ddc5ab 100644 --- a/src/search/SearchModel.h +++ b/src/search/SearchModel.h @@ -4,6 +4,7 @@ #include #include #include +#undef GetUserName //God dammit microsoft! #include #include "client/SaveInfo.h" #include "SearchView.h" diff --git a/src/simulation/Gravity.cpp b/src/simulation/Gravity.cpp index 89f626ea9..ba26cb657 100644 --- a/src/simulation/Gravity.cpp +++ b/src/simulation/Gravity.cpp @@ -1,6 +1,7 @@ #include #include #include +#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 8d81211e4..ec31b6ab9 100644 --- a/src/simulation/Gravity.h +++ b/src/simulation/Gravity.h @@ -2,6 +2,7 @@ #define GRAVITY_H #include +#undef GetUserName //God dammit microsoft! #include "Config.h" #include "Simulation.h" diff --git a/src/tasks/Task.h b/src/tasks/Task.h index 5a89278db..a025ac10b 100644 --- a/src/tasks/Task.h +++ b/src/tasks/Task.h @@ -10,6 +10,7 @@ #include #include +#undef GetUserName //God dammit microsoft! #include "TaskListener.h" class TaskListener;