Changeset - r27195:f643bbb4f8df
[Not reviewed]
master
0 6 0
Rubidium - 14 months ago 2023-04-16 19:44:53
rubidium@openttd.org
Codechange: Make FileToSaveLoad's title std::string and simplify assignments
6 files changed with 14 insertions and 28 deletions:
0 comments (0 inline, 0 general)
src/console_cmds.cpp
Show inline comments
 
@@ -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);
 
		}
src/fios_gui.cpp
Show inline comments
 
@@ -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();
src/genworld_gui.cpp
Show inline comments
 
@@ -406,7 +406,7 @@ struct GenerateLandscapeWindow : public 
 
	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(Gener
 
	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);
src/openttd.cpp
Show inline comments
 
@@ -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);
src/saveload/saveload.cpp
Show inline comments
 
@@ -3396,21 +3396,14 @@ void FileToSaveLoad::SetMode(SaveLoadOpe
 
}
 

	
 
/**
 
 * 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
src/saveload/saveload.h
Show inline comments
 
@@ -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. */
0 comments (0 inline, 0 general)