diff options
author | alberth <alberth@openttd.org> | 2016-09-04 12:58:04 +0000 |
---|---|---|
committer | alberth <alberth@openttd.org> | 2016-09-04 12:58:04 +0000 |
commit | 6f201ce4a8db0143ba0664aabdd04dc733adc243 (patch) | |
tree | a368495e00682bf58a0270ab1fe63d79e934a530 | |
parent | 597380e099688652e31fd1f406b53dee6b65da90 (diff) | |
download | openttd-6f201ce4a8db0143ba0664aabdd04dc733adc243.tar.xz |
(svn r27651) -Codechange: Introduce methods for setting the name and title of _file_to_saveload.
-rw-r--r-- | src/console_cmds.cpp | 5 | ||||
-rw-r--r-- | src/fios_gui.cpp | 9 | ||||
-rw-r--r-- | src/openttd.cpp | 2 | ||||
-rw-r--r-- | src/saveload/saveload.cpp | 18 | ||||
-rw-r--r-- | src/saveload/saveload.h | 2 |
5 files changed, 27 insertions, 9 deletions
diff --git a/src/console_cmds.cpp b/src/console_cmds.cpp index c26f17f29..863929b94 100644 --- a/src/console_cmds.cpp +++ b/src/console_cmds.cpp @@ -363,9 +363,8 @@ DEF_CONSOLE_CMD(ConLoad) if (GetAbstractFileType(item->type) == FT_SAVEGAME) { _switch_mode = SM_LOAD_GAME; _file_to_saveload.SetMode(item->type); - - strecpy(_file_to_saveload.name, FiosBrowseTo(item), lastof(_file_to_saveload.name)); - strecpy(_file_to_saveload.title, item->title, lastof(_file_to_saveload.title)); + _file_to_saveload.SetName(FiosBrowseTo(item)); + _file_to_saveload.SetTitle(item->title); } else { IConsolePrintF(CC_ERROR, "%s: Not a savegame.", file); } diff --git a/src/fios_gui.cpp b/src/fios_gui.cpp index 0c09f96ab..a0f0f1b29 100644 --- a/src/fios_gui.cpp +++ b/src/fios_gui.cpp @@ -537,9 +537,8 @@ public: if (this->selected != NULL && !_load_check_data.HasErrors()) { const char *name = FiosBrowseTo(this->selected); _file_to_saveload.SetMode(this->selected->type); - - strecpy(_file_to_saveload.name, name, lastof(_file_to_saveload.name)); - strecpy(_file_to_saveload.title, this->selected->title, lastof(_file_to_saveload.title)); + _file_to_saveload.SetName(name); + _file_to_saveload.SetTitle(this->selected->title); if (this->abstract_filetype == FT_HEIGHTMAP) { delete this; @@ -602,8 +601,8 @@ public: } else { assert(this->abstract_filetype == FT_HEIGHTMAP); _file_to_saveload.SetMode(file->type); - strecpy(_file_to_saveload.name, name, lastof(_file_to_saveload.name)); - strecpy(_file_to_saveload.title, file->title, lastof(_file_to_saveload.title)); + _file_to_saveload.SetName(name); + _file_to_saveload.SetTitle(file->title); delete this; ShowHeightmapLoad(); diff --git a/src/openttd.cpp b/src/openttd.cpp index 4464e8016..f00ce74c3 100644 --- a/src/openttd.cpp +++ b/src/openttd.cpp @@ -618,7 +618,7 @@ int openttd_main(int argc, char *argv[]) case 'e': _switch_mode = (_switch_mode == SM_LOAD_GAME || _switch_mode == SM_LOAD_SCENARIO ? SM_LOAD_SCENARIO : SM_EDITOR); break; case 'g': if (mgo.opt != NULL) { - strecpy(_file_to_saveload.name, mgo.opt, lastof(_file_to_saveload.name)); + _file_to_saveload.SetName(mgo.opt); bool is_scenario = _switch_mode == SM_EDITOR || _switch_mode == SM_LOAD_SCENARIO; _switch_mode = is_scenario ? SM_LOAD_SCENARIO : SM_LOAD_GAME; _file_to_saveload.SetMode(FOP_LOAD, is_scenario ? FT_SCENARIO : FT_SAVEGAME, DFT_GAME_FILE); diff --git a/src/saveload/saveload.cpp b/src/saveload/saveload.cpp index 4dd8a4c7b..b78171e60 100644 --- a/src/saveload/saveload.cpp +++ b/src/saveload/saveload.cpp @@ -2932,6 +2932,24 @@ void FileToSaveLoad::SetMode(FileOperation fop, AbstractFileType aft, DetailedFi this->abstract_ftype = aft; } +/** + * Set the name of the file. + * @param name Name of the file. + */ +void FileToSaveLoad::SetName(const char *name) +{ + strecpy(this->name, name, lastof(this->name)); +} + +/** + * Set the title of the file. + * @param title Title of the file. + */ +void FileToSaveLoad::SetTitle(const char *title) +{ + strecpy(this->title, title, lastof(this->title)); +} + #if 0 /** * Function to get the type of the savegame by looking at the file header. diff --git a/src/saveload/saveload.h b/src/saveload/saveload.h index 7b0ae8f48..b25e91e2c 100644 --- a/src/saveload/saveload.h +++ b/src/saveload/saveload.h @@ -32,6 +32,8 @@ struct FileToSaveLoad { void SetMode(FiosType ft); void SetMode(FileOperation fop, AbstractFileType aft, DetailedFileType dft); + void SetName(const char *name); + void SetTitle(const char *title); }; /** Types of save games. */ |