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 (item != nullptr) {
|
||||||
if (GetAbstractFileType(item->type) == FT_SAVEGAME) {
|
if (GetAbstractFileType(item->type) == FT_SAVEGAME) {
|
||||||
_switch_mode = SM_LOAD_GAME;
|
_switch_mode = SM_LOAD_GAME;
|
||||||
_file_to_saveload.SetMode(item->type);
|
_file_to_saveload.Set(*item);
|
||||||
_file_to_saveload.SetName(item->name);
|
|
||||||
_file_to_saveload.SetTitle(item->title);
|
|
||||||
} else {
|
} else {
|
||||||
IConsolePrint(CC_ERROR, "'{}' is not a savegame.", file);
|
IConsolePrint(CC_ERROR, "'{}' is not a savegame.", file);
|
||||||
}
|
}
|
||||||
|
|
|
@ -634,9 +634,7 @@ public:
|
||||||
case WID_SL_LOAD_BUTTON: {
|
case WID_SL_LOAD_BUTTON: {
|
||||||
if (this->selected == nullptr || _load_check_data.HasErrors()) break;
|
if (this->selected == nullptr || _load_check_data.HasErrors()) break;
|
||||||
|
|
||||||
_file_to_saveload.SetMode(this->selected->type);
|
_file_to_saveload.Set(*this->selected);
|
||||||
_file_to_saveload.SetName(this->selected->name);
|
|
||||||
_file_to_saveload.SetTitle(this->selected->title);
|
|
||||||
|
|
||||||
if (this->abstract_filetype == FT_HEIGHTMAP) {
|
if (this->abstract_filetype == FT_HEIGHTMAP) {
|
||||||
this->Close();
|
this->Close();
|
||||||
|
@ -688,7 +686,7 @@ public:
|
||||||
|
|
||||||
if (GetDetailedFileType(file->type) == DFT_GAME_FILE) {
|
if (GetDetailedFileType(file->type) == DFT_GAME_FILE) {
|
||||||
/* Other detailed file types cannot be checked before. */
|
/* 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);
|
this->InvalidateData(SLIWD_SELECTION_CHANGES);
|
||||||
|
@ -705,9 +703,7 @@ public:
|
||||||
this->OnClick(pt, WID_SL_LOAD_BUTTON, 1);
|
this->OnClick(pt, WID_SL_LOAD_BUTTON, 1);
|
||||||
} else {
|
} else {
|
||||||
assert(this->abstract_filetype == FT_HEIGHTMAP);
|
assert(this->abstract_filetype == FT_HEIGHTMAP);
|
||||||
_file_to_saveload.SetMode(file->type);
|
_file_to_saveload.Set(*file);
|
||||||
_file_to_saveload.SetName(file->name);
|
|
||||||
_file_to_saveload.SetTitle(file->title);
|
|
||||||
|
|
||||||
this->Close();
|
this->Close();
|
||||||
ShowHeightmapLoad();
|
ShowHeightmapLoad();
|
||||||
|
|
|
@ -406,7 +406,7 @@ struct GenerateLandscapeWindow : public Window {
|
||||||
uint widget_id;
|
uint widget_id;
|
||||||
uint x;
|
uint x;
|
||||||
uint y;
|
uint y;
|
||||||
char name[64];
|
std::string name;
|
||||||
GenerateLandscapeWindowMode mode;
|
GenerateLandscapeWindowMode mode;
|
||||||
|
|
||||||
GenerateLandscapeWindow(WindowDesc *desc, WindowNumber number = 0) : Window(desc)
|
GenerateLandscapeWindow(WindowDesc *desc, WindowNumber number = 0) : Window(desc)
|
||||||
|
@ -1057,7 +1057,7 @@ static void _ShowGenerateLandscape(GenerateLandscapeWindowMode mode)
|
||||||
if (mode == GLWM_HEIGHTMAP) {
|
if (mode == GLWM_HEIGHTMAP) {
|
||||||
w->x = x;
|
w->x = x;
|
||||||
w->y = y;
|
w->y = y;
|
||||||
strecpy(w->name, _file_to_saveload.title, lastof(w->name));
|
w->name = _file_to_saveload.title;
|
||||||
}
|
}
|
||||||
|
|
||||||
SetWindowDirty(WC_GENERATE_LANDSCAPE, mode);
|
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 'e': _switch_mode = (_switch_mode == SM_LOAD_GAME || _switch_mode == SM_LOAD_SCENARIO ? SM_LOAD_SCENARIO : SM_EDITOR); break;
|
||||||
case 'g':
|
case 'g':
|
||||||
if (mgo.opt != nullptr) {
|
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;
|
bool is_scenario = _switch_mode == SM_EDITOR || _switch_mode == SM_LOAD_SCENARIO;
|
||||||
_switch_mode = is_scenario ? SM_LOAD_SCENARIO : SM_LOAD_GAME;
|
_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);
|
_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;
|
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.
|
* Set the title of the file.
|
||||||
* @param title 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
|
SaveLoadTable SaveLoadHandler::GetLoadDescription() const
|
||||||
|
|
|
@ -365,16 +365,15 @@ enum SaveOrLoadResult {
|
||||||
|
|
||||||
/** Deals with the type of the savegame, independent of extension */
|
/** Deals with the type of the savegame, independent of extension */
|
||||||
struct FileToSaveLoad {
|
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).
|
DetailedFileType detail_ftype; ///< Concrete file type (PNG, BMP, old save, etc).
|
||||||
AbstractFileType abstract_ftype; ///< Abstract type of file (scenario, heightmap, etc).
|
AbstractFileType abstract_ftype; ///< Abstract type of file (scenario, heightmap, etc).
|
||||||
std::string name; ///< Name of the file.
|
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(FiosType ft);
|
||||||
void SetMode(SaveLoadOperation fop, AbstractFileType aft, DetailedFileType dft);
|
void SetMode(SaveLoadOperation fop, AbstractFileType aft, DetailedFileType dft);
|
||||||
void SetName(const char *name);
|
void Set(const FiosItem &item);
|
||||||
void SetTitle(const char *title);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Types of save games. */
|
/** Types of save games. */
|
||||||
|
|
Loading…
Reference in New Issue