From 3a0d966ae408aecc0bdad3325c1cc75927d58e89 Mon Sep 17 00:00:00 2001 From: rubidium <rubidium@openttd.org> Date: Fri, 2 Jan 2009 22:49:43 +0000 Subject: (svn r14790) -Codechange: unify generation of default savegame/screenshot names (PhilSophus) --- src/misc_gui.cpp | 9 +-------- src/openttd.cpp | 4 +--- src/saveload.cpp | 17 +++++++++++++++++ src/saveload.h | 1 + src/screenshot.cpp | 10 ++-------- 5 files changed, 22 insertions(+), 19 deletions(-) diff --git a/src/misc_gui.cpp b/src/misc_gui.cpp index 1e11f9349..b38fcc6d3 100644 --- a/src/misc_gui.cpp +++ b/src/misc_gui.cpp @@ -1426,14 +1426,7 @@ struct SaveLoadWindow : public QueryStringBaseWindow { void GenerateFileName() { - /* Check if we are not a spectator who wants to generate a name.. - * 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); + GenerateDefaultSaveName(this->edit_str_buf, &this->edit_str_buf[this->edit_str_size - 1]); } SaveLoadWindow(const WindowDesc *desc, SaveLoadDialogMode mode) : QueryStringBaseWindow(64, desc) diff --git a/src/openttd.cpp b/src/openttd.cpp index a8f08bb9c..488c969bd 100644 --- a/src/openttd.cpp +++ b/src/openttd.cpp @@ -1110,9 +1110,7 @@ static void DoAutosave() #endif /* PSP */ if (_settings_client.gui.keep_all_autosave && _local_company != COMPANY_SPECTATOR) { - SetDParam(0, _local_company); - SetDParam(1, _date); - GetString(buf, STR_4004, lastof(buf)); + GenerateDefaultSaveName(buf, lastof(buf)); strecat(buf, ".sav", lastof(buf)); } else { /* generate a savegame name and number according to _settings_client.gui.max_num_autosaves */ diff --git a/src/saveload.cpp b/src/saveload.cpp index 968e48911..79c81731c 100644 --- a/src/saveload.cpp +++ b/src/saveload.cpp @@ -29,6 +29,8 @@ #include "functions.h" #include "core/endian_func.hpp" #include "vehicle_base.h" +#include "company_func.h" +#include "date_func.h" #include "autoreplace_base.h" #include "statusbar_gui.h" #include "fileio_func.h" @@ -1817,6 +1819,21 @@ void DoExitSave() 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 /** * Function to get the type of the savegame by looking at the file header. diff --git a/src/saveload.h b/src/saveload.h index 68e55afa7..e52045a83 100644 --- a/src/saveload.h +++ b/src/saveload.h @@ -35,6 +35,7 @@ enum SavegameType { SGT_OTTD ///< OTTD savegame }; +void GenerateDefaultSaveName(char *buf, const char *last); void SetSaveLoadError(uint16 str); const char *GetSaveLoadErrorString(); SaveOrLoadResult SaveOrLoad(const char *filename, int mode, Subdirectory sb); diff --git a/src/screenshot.cpp b/src/screenshot.cpp index f667ecf2f..ced474d91 100644 --- a/src/screenshot.cpp +++ b/src/screenshot.cpp @@ -17,7 +17,7 @@ #include "core/alloc_func.hpp" #include "core/endian_func.hpp" #include "map_func.h" -#include "date_func.h" +#include "saveload.h" #include "company_func.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) { strecpy(_screenshot_name, "screenshot", lastof(_screenshot_name)); } else { - SetDParam(0, _local_company); - SetDParam(1, _date); - GetString(_screenshot_name, STR_4004, lastof(_screenshot_name)); + GenerateDefaultSaveName(_screenshot_name, lastof(_screenshot_name)); } /* Add extension to screenshot file */ - SanitizeFilename(_screenshot_name); len = strlen(_screenshot_name); snprintf(&_screenshot_name[len], lengthof(_screenshot_name) - len, ".%s", ext); @@ -619,6 +616,3 @@ bool MakeScreenshot() default: return false; } } - - - -- cgit v1.2.3-70-g09d2