(svn r14790) -Codechange: unify generation of default savegame/screenshot names (PhilSophus)

This commit is contained in:
rubidium 2009-01-02 22:49:43 +00:00
parent 1357b0a4c2
commit 3a0d966ae4
5 changed files with 22 additions and 19 deletions

View File

@ -1426,14 +1426,7 @@ struct SaveLoadWindow : public QueryStringBaseWindow {
void GenerateFileName() void GenerateFileName()
{ {
/* Check if we are not a spectator who wants to generate a name.. GenerateDefaultSaveName(this->edit_str_buf, &this->edit_str_buf[this->edit_str_size - 1]);
* Let's use the name of company #0 for now. */
const Company *c = GetCompany(IsValidCompanyID(_local_company) ? _local_company : COMPANY_FIRST);
SetDParam(0, c->index);
SetDParam(1, _date);
GetString(this->edit_str_buf, STR_4004, &this->edit_str_buf[this->edit_str_size - 1]);
SanitizeFilename(this->edit_str_buf);
} }
SaveLoadWindow(const WindowDesc *desc, SaveLoadDialogMode mode) : QueryStringBaseWindow(64, desc) SaveLoadWindow(const WindowDesc *desc, SaveLoadDialogMode mode) : QueryStringBaseWindow(64, desc)

View File

@ -1110,9 +1110,7 @@ static void DoAutosave()
#endif /* PSP */ #endif /* PSP */
if (_settings_client.gui.keep_all_autosave && _local_company != COMPANY_SPECTATOR) { if (_settings_client.gui.keep_all_autosave && _local_company != COMPANY_SPECTATOR) {
SetDParam(0, _local_company); GenerateDefaultSaveName(buf, lastof(buf));
SetDParam(1, _date);
GetString(buf, STR_4004, lastof(buf));
strecat(buf, ".sav", lastof(buf)); strecat(buf, ".sav", lastof(buf));
} else { } else {
/* generate a savegame name and number according to _settings_client.gui.max_num_autosaves */ /* generate a savegame name and number according to _settings_client.gui.max_num_autosaves */

View File

@ -29,6 +29,8 @@
#include "functions.h" #include "functions.h"
#include "core/endian_func.hpp" #include "core/endian_func.hpp"
#include "vehicle_base.h" #include "vehicle_base.h"
#include "company_func.h"
#include "date_func.h"
#include "autoreplace_base.h" #include "autoreplace_base.h"
#include "statusbar_gui.h" #include "statusbar_gui.h"
#include "fileio_func.h" #include "fileio_func.h"
@ -1817,6 +1819,21 @@ void DoExitSave()
SaveOrLoad("exit.sav", SL_SAVE, AUTOSAVE_DIR); SaveOrLoad("exit.sav", SL_SAVE, AUTOSAVE_DIR);
} }
/**
* Fill the buffer with the default name for a savegame *or* screenshot.
* @param buf the buffer to write to.
* @param last the last element in the buffer.
*/
void GenerateDefaultSaveName(char *buf, const char *last)
{
/* Check if we are not a spectator who wants to generate a name..
* Let's use the name of company #0 for now. */
SetDParam(0, IsValidCompanyID(_local_company) ? _local_company : COMPANY_FIRST);
SetDParam(1, _date);
GetString(buf, STR_4004, last);
SanitizeFilename(buf);
}
#if 0 #if 0
/** /**
* Function to get the type of the savegame by looking at the file header. * Function to get the type of the savegame by looking at the file header.

View File

@ -35,6 +35,7 @@ enum SavegameType {
SGT_OTTD ///< OTTD savegame SGT_OTTD ///< OTTD savegame
}; };
void GenerateDefaultSaveName(char *buf, const char *last);
void SetSaveLoadError(uint16 str); void SetSaveLoadError(uint16 str);
const char *GetSaveLoadErrorString(); const char *GetSaveLoadErrorString();
SaveOrLoadResult SaveOrLoad(const char *filename, int mode, Subdirectory sb); SaveOrLoadResult SaveOrLoad(const char *filename, int mode, Subdirectory sb);

View File

@ -17,7 +17,7 @@
#include "core/alloc_func.hpp" #include "core/alloc_func.hpp"
#include "core/endian_func.hpp" #include "core/endian_func.hpp"
#include "map_func.h" #include "map_func.h"
#include "date_func.h" #include "saveload.h"
#include "company_func.h" #include "company_func.h"
#include "table/strings.h" #include "table/strings.h"
@ -550,13 +550,10 @@ static char *MakeScreenshotName(const char *ext)
if (_game_mode == GM_EDITOR || _game_mode == GM_MENU || _local_company == COMPANY_SPECTATOR) { if (_game_mode == GM_EDITOR || _game_mode == GM_MENU || _local_company == COMPANY_SPECTATOR) {
strecpy(_screenshot_name, "screenshot", lastof(_screenshot_name)); strecpy(_screenshot_name, "screenshot", lastof(_screenshot_name));
} else { } else {
SetDParam(0, _local_company); GenerateDefaultSaveName(_screenshot_name, lastof(_screenshot_name));
SetDParam(1, _date);
GetString(_screenshot_name, STR_4004, lastof(_screenshot_name));
} }
/* Add extension to screenshot file */ /* Add extension to screenshot file */
SanitizeFilename(_screenshot_name);
len = strlen(_screenshot_name); len = strlen(_screenshot_name);
snprintf(&_screenshot_name[len], lengthof(_screenshot_name) - len, ".%s", ext); snprintf(&_screenshot_name[len], lengthof(_screenshot_name) - len, ".%s", ext);
@ -619,6 +616,3 @@ bool MakeScreenshot()
default: return false; default: return false;
} }
} }