summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjacob1 <jfu614@gmail.com>2012-10-19 23:17:15 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2012-10-26 14:15:38 (GMT)
commit3a29fc0268dbda68e80f7de586c6692ba7a11565 (patch)
treefa2ae1ded7149c2b56c4dcecac032e991b30d00e
parente2622657f076ef943d051593d0969306daf15f32 (diff)
downloadpowder-3a29fc0268dbda68e80f7de586c6692ba7a11565.zip
powder-3a29fc0268dbda68e80f7de586c6692ba7a11565.tar.gz
Save local saves as current name option (overwrites them automatically). Fix filename not showing when first saving a local save
-rw-r--r--src/cat/LegacyLuaAPI.cpp11
-rw-r--r--src/cat/LuaScriptInterface.cpp8
-rw-r--r--src/client/Client.cpp22
-rw-r--r--src/client/Client.h1
-rw-r--r--src/client/SaveFile.cpp5
-rw-r--r--src/client/SaveFile.h1
-rw-r--r--src/game/GameController.cpp38
-rw-r--r--src/game/GameController.h2
-rw-r--r--src/game/GameModel.cpp2
-rw-r--r--src/game/GameModel.h2
-rw-r--r--src/game/GameView.cpp23
-rw-r--r--src/game/GameView.h1
-rw-r--r--src/save/LocalSaveActivity.cpp13
13 files changed, 68 insertions, 61 deletions
diff --git a/src/cat/LegacyLuaAPI.cpp b/src/cat/LegacyLuaAPI.cpp
index dfebf01..d6e6ce6 100644
--- a/src/cat/LegacyLuaAPI.cpp
+++ b/src/cat/LegacyLuaAPI.cpp
@@ -16,11 +16,6 @@
#include "simulation/Simulation.h"
#include "game/GameModel.h"
-#ifdef WIN
-#include <direct.h>
-#else
-#include <sys/stat.h>
-#endif
#include <time.h>
#ifndef FFI
@@ -1747,11 +1742,7 @@ int luatpt_getscript(lua_State* l)
filename = new char[fileauthor.length()+fileid.length()+strlen(PATH_SEP)+strlen(LOCAL_LUA_DIR)+6];
sprintf(filename, LOCAL_LUA_DIR PATH_SEP "%s_%s.lua", fileauthor.c_str(), fileid.c_str());
-#ifdef WIN
- _mkdir(LOCAL_LUA_DIR);
-#else
- mkdir(LOCAL_LUA_DIR, 0755);
-#endif
+ Client::Ref().MakeDirectory(LOCAL_LUA_DIR);
outputfile = fopen(filename, "r");
if(outputfile)
diff --git a/src/cat/LuaScriptInterface.cpp b/src/cat/LuaScriptInterface.cpp
index b9124c5..56da7e0 100644
--- a/src/cat/LuaScriptInterface.cpp
+++ b/src/cat/LuaScriptInterface.cpp
@@ -1520,14 +1520,10 @@ int LuaScriptInterface::fileSystem_isDirectory(lua_State * l)
int LuaScriptInterface::fileSystem_makeDirectory(lua_State * l)
{
- const char * filename = lua_tostring(l, 1);
+ const char * dirname = lua_tostring(l, 1);
int ret = 0;
-#ifdef WIN
- ret = _mkdir(filename);
-#else
- ret = mkdir(filename, 0755);
-#endif
+ ret = Client::Ref().MakeDirectory(dirname);
lua_pushboolean(l, ret == 0);
return 1;
}
diff --git a/src/client/Client.cpp b/src/client/Client.cpp
index b35c292..763814a 100644
--- a/src/client/Client.cpp
+++ b/src/client/Client.cpp
@@ -430,6 +430,15 @@ std::vector<std::string> Client::DirectorySearch(std::string directory, std::str
return searchResults;
}
+int Client::MakeDirectory(const char * dirName)
+{
+#ifdef WIN
+ return _mkdir(dirName);
+#else
+ return mkdir(dirName, 0755);
+#endif
+}
+
void Client::WriteFile(std::vector<unsigned char> fileData, std::string filename)
{
try
@@ -870,11 +879,7 @@ std::string Client::AddStamp(GameSave * saveData)
<< std::setw(8) << std::setfill('0') << std::hex << lastStampTime
<< std::setw(2) << std::setfill('0') << std::hex << lastStampName;
-#ifdef WIN
- _mkdir(STAMPS_DIR);
-#else
- mkdir(STAMPS_DIR, 0755);
-#endif
+ MakeDirectory(STAMPS_DIR);
int gameDataLength;
char * gameData = saveData->Serialise(gameDataLength);
@@ -895,12 +900,7 @@ std::string Client::AddStamp(GameSave * saveData)
void Client::updateStamps()
{
-
-#ifdef WIN
- _mkdir(STAMPS_DIR);
-#else
- mkdir(STAMPS_DIR, 0755);
-#endif
+ MakeDirectory(STAMPS_DIR);
std::ofstream stampsStream;
stampsStream.open(std::string(STAMPS_DIR PATH_SEP "stamps.def").c_str(), std::ios::binary);
diff --git a/src/client/Client.h b/src/client/Client.h
index 4f65788..642fd63 100644
--- a/src/client/Client.h
+++ b/src/client/Client.h
@@ -98,6 +98,7 @@ public:
void Initialise(std::string proxyString);
void SetProxy(std::string proxy);
+ int MakeDirectory(const char * dirname);
void WriteFile(std::vector<unsigned char> fileData, std::string filename);
void WriteFile(std::vector<char> fileData, std::string filename);
bool FileExists(std::string filename);
diff --git a/src/client/SaveFile.cpp b/src/client/SaveFile.cpp
index 368d89d..fe7ad4f 100644
--- a/src/client/SaveFile.cpp
+++ b/src/client/SaveFile.cpp
@@ -56,6 +56,11 @@ std::string SaveFile::GetName()
return filename;
}
+void SaveFile::SetFileName(std::string fileName)
+{
+ this->filename = fileName;
+}
+
std::string SaveFile::GetDisplayName()
{
return displayName;
diff --git a/src/client/SaveFile.h b/src/client/SaveFile.h
index 9a9310f..b63d181 100644
--- a/src/client/SaveFile.h
+++ b/src/client/SaveFile.h
@@ -25,6 +25,7 @@ public:
std::string GetDisplayName();
void SetDisplayName(std::string displayName);
std::string GetName();
+ void SetFileName(std::string fileName);
virtual ~SaveFile();
private:
diff --git a/src/game/GameController.cpp b/src/game/GameController.cpp
index 96f966c..dfe3a94 100644
--- a/src/game/GameController.cpp
+++ b/src/game/GameController.cpp
@@ -909,7 +909,7 @@ void GameController::OpenSearch()
ui::Engine::Ref().ShowWindow(search->GetView());
}
-void GameController::OpenLocalSaveWindow()
+void GameController::OpenLocalSaveWindow(bool asCurrent)
{
Simulation * sim = gameModel->GetSimulation();
GameSave * gameSave = sim->Save();
@@ -926,24 +926,32 @@ void GameController::OpenLocalSaveWindow()
else
{
std::string filename = "";
- if (gameModel->GetFile())
- filename = gameModel->GetFile()->GetDisplayName();
+ if (gameModel->GetSaveFile())
+ filename = gameModel->GetSaveFile()->GetDisplayName();
SaveFile tempSave(filename);
tempSave.SetGameSave(gameSave);
- class LocalSaveCallback: public FileSavedCallback
+ if (!asCurrent || !gameModel->GetSaveFile())
{
- GameController * c;
- public:
- LocalSaveCallback(GameController * _c): c(_c) {}
- virtual ~LocalSaveCallback() {};
- virtual void FileSaved(SaveFile* file)
+ class LocalSaveCallback: public FileSavedCallback
{
- c->gameModel->SetSaveFile(file);
- }
- };
+ GameController * c;
+ public:
+ LocalSaveCallback(GameController * _c): c(_c) {}
+ virtual ~LocalSaveCallback() {};
+ virtual void FileSaved(SaveFile* file)
+ {
+ c->gameModel->SetSaveFile(file);
+ }
+ };
- new LocalSaveActivity(tempSave, new LocalSaveCallback(this));
+ new LocalSaveActivity(tempSave, new LocalSaveCallback(this));
+ }
+ else if (gameModel->GetSaveFile())
+ {
+ Client::Ref().MakeDirectory(LOCAL_SAVE_DIR);
+ Client::Ref().WriteFile(gameSave->Serialise(), gameModel->GetSaveFile()->GetName());
+ }
}
}
@@ -1209,9 +1217,9 @@ void GameController::ReloadSim()
{
gameModel->SetSave(gameModel->GetSave());
}
- else if(gameModel->GetFile() && gameModel->GetFile()->GetGameSave())
+ else if(gameModel->GetSaveFile() && gameModel->GetSaveFile()->GetGameSave())
{
- gameModel->SetSaveFile(gameModel->GetFile());
+ gameModel->SetSaveFile(gameModel->GetSaveFile());
}
}
diff --git a/src/game/GameController.h b/src/game/GameController.h
index 14dbccb..2ac8bea 100644
--- a/src/game/GameController.h
+++ b/src/game/GameController.h
@@ -105,7 +105,7 @@ public:
void OpenLogin();
void OpenTags();
void OpenSavePreview(int saveID, int saveDate);
- void OpenLocalSaveWindow();
+ void OpenLocalSaveWindow(bool asCurrent);
void OpenLocalBrowse();
void OpenOptions();
void OpenRenderOptions();
diff --git a/src/game/GameModel.cpp b/src/game/GameModel.cpp
index f905a1c..0a3c577 100644
--- a/src/game/GameModel.cpp
+++ b/src/game/GameModel.cpp
@@ -564,7 +564,7 @@ void GameModel::SetSave(SaveInfo * newSave)
UpdateQuickOptions();
}
-SaveFile * GameModel::GetFile()
+SaveFile * GameModel::GetSaveFile()
{
return currentFile;
}
diff --git a/src/game/GameModel.h b/src/game/GameModel.h
index b4c0bd3..7288c32 100644
--- a/src/game/GameModel.h
+++ b/src/game/GameModel.h
@@ -144,7 +144,7 @@ public:
void SetVote(int direction);
SaveInfo * GetSave();
- SaveFile * GetFile();
+ SaveFile * GetSaveFile();
Brush * GetBrush();
void SetSave(SaveInfo * newSave);
void SetSaveFile(SaveFile * newSave);
diff --git a/src/game/GameView.cpp b/src/game/GameView.cpp
index 9a2f772..73b3833 100644
--- a/src/game/GameView.cpp
+++ b/src/game/GameView.cpp
@@ -181,7 +181,8 @@ GameView::GameView():
recording(false),
screenshotIndex(0),
recordingIndex(0),
- toolTipPresence(0)
+ toolTipPresence(0),
+ currentSaveType(0)
{
int currentX = 1;
@@ -238,14 +239,14 @@ GameView::GameView():
void ActionCallbackRight(ui::Button * sender)
{
if(v->CtrlBehaviour())
- v->c->OpenLocalSaveWindow();
+ v->c->OpenLocalSaveWindow(false);
else
v->c->OpenSaveWindow();
}
void ActionCallbackLeft(ui::Button * sender)
{
if(v->CtrlBehaviour())
- v->c->OpenLocalSaveWindow();
+ v->c->OpenLocalSaveWindow(true);
else
v->c->SaveAsCurrent();
}
@@ -846,11 +847,15 @@ void GameView::NotifySaveChanged(GameModel * sender)
{
tagSimulationButton->SetText("[no tags set]");
}
+ currentSaveType = 1;
}
- else if (sender->GetFile())
+ else if (sender->GetSaveFile())
{
- ((SplitButton*)saveSimulationButton)->SetShowSplit(false);
- saveSimulationButton->SetText(sender->GetFile()->GetDisplayName());
+ if (ctrlBehaviour)
+ ((SplitButton*)saveSimulationButton)->SetShowSplit(true);
+ else
+ ((SplitButton*)saveSimulationButton)->SetShowSplit(false);
+ saveSimulationButton->SetText(sender->GetSaveFile()->GetDisplayName());
reloadButton->Enabled = true;
upVoteButton->Enabled = false;
upVoteButton->Appearance.BackgroundInactive = (ui::Colour(0, 0, 0));
@@ -858,6 +863,7 @@ void GameView::NotifySaveChanged(GameModel * sender)
upVoteButton->Appearance.BackgroundInactive = (ui::Colour(0, 0, 0));
tagSimulationButton->Enabled = false;
tagSimulationButton->SetText("[no tags set]");
+ currentSaveType = 2;
}
else
{
@@ -870,6 +876,7 @@ void GameView::NotifySaveChanged(GameModel * sender)
upVoteButton->Appearance.BackgroundInactive = (ui::Colour(0, 0, 0));
tagSimulationButton->Enabled = false;
tagSimulationButton->SetText("[no tags set]");
+ currentSaveType = 0;
}
}
@@ -1685,6 +1692,8 @@ void GameView::enableCtrlBehaviour()
saveSimulationButton->Appearance.TextInactive = saveSimulationButton->Appearance.TextHover = ui::Colour(0, 0, 0);
searchButton->Appearance.BackgroundInactive = searchButton->Appearance.BackgroundHover = ui::Colour(255, 255, 255);
searchButton->Appearance.TextInactive = searchButton->Appearance.TextHover = ui::Colour(0, 0, 0);
+ if (currentSaveType == 2)
+ ((SplitButton*)saveSimulationButton)->SetShowSplit(true);
if(isMouseDown)
{
if(!shiftBehaviour)
@@ -1708,6 +1717,8 @@ void GameView::disableCtrlBehaviour()
searchButton->Appearance.BackgroundInactive = ui::Colour(0, 0, 0);
searchButton->Appearance.BackgroundHover = ui::Colour(20, 20, 20);
searchButton->Appearance.TextInactive = searchButton->Appearance.TextHover = ui::Colour(255, 255, 255);
+ if (currentSaveType == 2)
+ ((SplitButton*)saveSimulationButton)->SetShowSplit(false);
if(!shiftBehaviour)
c->SetToolStrength(1.0f);
else
diff --git a/src/game/GameView.h b/src/game/GameView.h
index f36aef3..e17279f 100644
--- a/src/game/GameView.h
+++ b/src/game/GameView.h
@@ -55,6 +55,7 @@ private:
std::string buttonTip;
std::string introTextMessage;
int toolIndex;
+ int currentSaveType;
int infoTipPresence;
std::string toolTip;
diff --git a/src/save/LocalSaveActivity.cpp b/src/save/LocalSaveActivity.cpp
index d2c4a2f..b57a993 100644
--- a/src/save/LocalSaveActivity.cpp
+++ b/src/save/LocalSaveActivity.cpp
@@ -1,8 +1,3 @@
-#ifdef WIN
-#include <direct.h>
-#else
-#include <sys/stat.h>
-#endif
#include "LocalSaveActivity.h"
#include "interface/Label.h"
#include "interface/Textbox.h"
@@ -94,6 +89,8 @@ void LocalSaveActivity::Save()
if(filenameField->GetText().length())
{
std::string finalFilename = std::string(LOCAL_SAVE_DIR) + std::string(PATH_SEP) + filenameField->GetText() + ".cps";
+ save.SetDisplayName(filenameField->GetText());
+ save.SetFileName(finalFilename);
if(Client::Ref().FileExists(finalFilename))
{
new ConfirmPrompt("Overwrite file", "Are you sure you wish to overwrite\n"+finalFilename, new FileOverwriteConfirmation(this, finalFilename));
@@ -112,11 +109,7 @@ void LocalSaveActivity::Save()
void LocalSaveActivity::saveWrite(std::string finalFilename)
{
-#ifdef WIN
- _mkdir(LOCAL_SAVE_DIR);
-#else
- mkdir(LOCAL_SAVE_DIR, 0755);
-#endif
+ Client::Ref().MakeDirectory(LOCAL_SAVE_DIR);
Client::Ref().WriteFile(save.GetGameSave()->Serialise(), finalFilename);
callback->FileSaved(&save);
}