mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r14790) -Codechange: unify generation of default savegame/screenshot names (PhilSophus)
This commit is contained in:
parent
1357b0a4c2
commit
3a0d966ae4
|
@ -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)
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue