Save local saves as current name option (overwrites them automatically). Fix filename not showing when first saving a local save

This commit is contained in:
jacob1 2012-10-19 19:17:15 -04:00 committed by Simon Robertshaw
parent e2622657f0
commit 3a29fc0268
13 changed files with 68 additions and 61 deletions

View File

@ -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)

View File

@ -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;
}

View File

@ -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);

View File

@ -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);

View File

@ -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;

View File

@ -25,6 +25,7 @@ public:
std::string GetDisplayName();
void SetDisplayName(std::string displayName);
std::string GetName();
void SetFileName(std::string fileName);
virtual ~SaveFile();
private:

View File

@ -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());
}
}

View File

@ -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();

View File

@ -564,7 +564,7 @@ void GameModel::SetSave(SaveInfo * newSave)
UpdateQuickOptions();
}
SaveFile * GameModel::GetFile()
SaveFile * GameModel::GetSaveFile()
{
return currentFile;
}

View File

@ -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);

View File

@ -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

View File

@ -55,6 +55,7 @@ private:
std::string buttonTip;
std::string introTextMessage;
int toolIndex;
int currentSaveType;
int infoTipPresence;
std::string toolTip;

View File

@ -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);
}