mirror of https://github.com/OpenTTD/OpenTTD.git
Codechange: Make FileToSaveLoad's title std::string and simplify assignments
This commit is contained in:
parent
f0a1ddd81c
commit
ee723f26ba
|
@ -432,9 +432,7 @@ DEF_CONSOLE_CMD(ConLoad)
|
|||
if (item != nullptr) {
|
||||
if (GetAbstractFileType(item->type) == FT_SAVEGAME) {
|
||||
_switch_mode = SM_LOAD_GAME;
|
||||
_file_to_saveload.SetMode(item->type);
|
||||
_file_to_saveload.SetName(item->name);
|
||||
_file_to_saveload.SetTitle(item->title);
|
||||
_file_to_saveload.Set(*item);
|
||||
} else {
|
||||
IConsolePrint(CC_ERROR, "'{}' is not a savegame.", file);
|
||||
}
|
||||
|
|
|
@ -634,9 +634,7 @@ public:
|
|||
case WID_SL_LOAD_BUTTON: {
|
||||
if (this->selected == nullptr || _load_check_data.HasErrors()) break;
|
||||
|
||||
_file_to_saveload.SetMode(this->selected->type);
|
||||
_file_to_saveload.SetName(this->selected->name);
|
||||
_file_to_saveload.SetTitle(this->selected->title);
|
||||
_file_to_saveload.Set(*this->selected);
|
||||
|
||||
if (this->abstract_filetype == FT_HEIGHTMAP) {
|
||||
this->Close();
|
||||
|
@ -688,7 +686,7 @@ public:
|
|||
|
||||
if (GetDetailedFileType(file->type) == DFT_GAME_FILE) {
|
||||
/* Other detailed file types cannot be checked before. */
|
||||
SaveOrLoad(name, SLO_CHECK, DFT_GAME_FILE, NO_DIRECTORY, false);
|
||||
SaveOrLoad(file->name, SLO_CHECK, DFT_GAME_FILE, NO_DIRECTORY, false);
|
||||
}
|
||||
|
||||
this->InvalidateData(SLIWD_SELECTION_CHANGES);
|
||||
|
@ -705,9 +703,7 @@ public:
|
|||
this->OnClick(pt, WID_SL_LOAD_BUTTON, 1);
|
||||
} else {
|
||||
assert(this->abstract_filetype == FT_HEIGHTMAP);
|
||||
_file_to_saveload.SetMode(file->type);
|
||||
_file_to_saveload.SetName(file->name);
|
||||
_file_to_saveload.SetTitle(file->title);
|
||||
_file_to_saveload.Set(*file);
|
||||
|
||||
this->Close();
|
||||
ShowHeightmapLoad();
|
||||
|
|
|
@ -406,7 +406,7 @@ struct GenerateLandscapeWindow : public Window {
|
|||
uint widget_id;
|
||||
uint x;
|
||||
uint y;
|
||||
char name[64];
|
||||
std::string name;
|
||||
GenerateLandscapeWindowMode mode;
|
||||
|
||||
GenerateLandscapeWindow(WindowDesc *desc, WindowNumber number = 0) : Window(desc)
|
||||
|
@ -1057,7 +1057,7 @@ static void _ShowGenerateLandscape(GenerateLandscapeWindowMode mode)
|
|||
if (mode == GLWM_HEIGHTMAP) {
|
||||
w->x = x;
|
||||
w->y = y;
|
||||
strecpy(w->name, _file_to_saveload.title, lastof(w->name));
|
||||
w->name = _file_to_saveload.title;
|
||||
}
|
||||
|
||||
SetWindowDirty(WC_GENERATE_LANDSCAPE, mode);
|
||||
|
|
|
@ -584,7 +584,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 != nullptr) {
|
||||
_file_to_saveload.SetName(mgo.opt);
|
||||
_file_to_saveload.name = 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(SLO_LOAD, is_scenario ? FT_SCENARIO : FT_SAVEGAME, DFT_GAME_FILE);
|
||||
|
|
|
@ -3395,22 +3395,15 @@ void FileToSaveLoad::SetMode(SaveLoadOperation fop, AbstractFileType aft, Detail
|
|||
this->abstract_ftype = aft;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the name of the file.
|
||||
* @param name Name of the file.
|
||||
*/
|
||||
void FileToSaveLoad::SetName(const char *name)
|
||||
{
|
||||
this->name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the title of the file.
|
||||
* @param title Title of the file.
|
||||
*/
|
||||
void FileToSaveLoad::SetTitle(const char *title)
|
||||
void FileToSaveLoad::Set(const FiosItem &item)
|
||||
{
|
||||
strecpy(this->title, title, lastof(this->title));
|
||||
this->SetMode(item.type);
|
||||
this->name = item.name;
|
||||
this->title = item.title;
|
||||
}
|
||||
|
||||
SaveLoadTable SaveLoadHandler::GetLoadDescription() const
|
||||
|
|
|
@ -365,16 +365,15 @@ enum SaveOrLoadResult {
|
|||
|
||||
/** Deals with the type of the savegame, independent of extension */
|
||||
struct FileToSaveLoad {
|
||||
SaveLoadOperation file_op; ///< File operation to perform.
|
||||
SaveLoadOperation file_op; ///< File operation to perform.
|
||||
DetailedFileType detail_ftype; ///< Concrete file type (PNG, BMP, old save, etc).
|
||||
AbstractFileType abstract_ftype; ///< Abstract type of file (scenario, heightmap, etc).
|
||||
std::string name; ///< Name of the file.
|
||||
char title[255]; ///< Internal name of the game.
|
||||
std::string title; ///< Internal name of the game.
|
||||
|
||||
void SetMode(FiosType ft);
|
||||
void SetMode(SaveLoadOperation fop, AbstractFileType aft, DetailedFileType dft);
|
||||
void SetName(const char *name);
|
||||
void SetTitle(const char *title);
|
||||
void Set(const FiosItem &item);
|
||||
};
|
||||
|
||||
/** Types of save games. */
|
||||
|
|
Loading…
Reference in New Issue