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
 
@@ -429,15 +429,13 @@ DEF_CONSOLE_CMD(ConLoad)
 
	const char *file = argv[1];
 
	_console_file_list.ValidateFileList();
 
	const FiosItem *item = _console_file_list.FindItem(file);
 
	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);
 
		}
 
	} else {
 
		IConsolePrint(CC_ERROR, "'{}' cannot be found.", file);
 
	}
src/fios_gui.cpp
Show inline comments
 
@@ -631,15 +631,13 @@ public:
 
				this->InvalidateData(SLIWD_RESCAN_FILES);
 
				break;
 

	
 
			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();
 
					ShowHeightmapLoad();
 
				} else if (!_load_check_data.HasNewGrfs() || _load_check_data.grf_compatibility != GLC_NOT_FOUND || _settings_client.gui.UserIsAllowedToChangeNewGRFs()) {
 
					_switch_mode = (_game_mode == GM_EDITOR) ? SM_LOAD_SCENARIO : SM_LOAD_GAME;
 
@@ -685,13 +683,13 @@ public:
 
					if (this->selected != file) {
 
						this->selected = file;
 
						_load_check_data.Clear();
 

	
 
						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);
 
					}
 
					if (this->fop == SLO_SAVE) {
 
						/* Copy clicked name to editbox */
 
@@ -702,15 +700,13 @@ public:
 
					this->selected = file;
 
					if (this->fop == SLO_LOAD) {
 
						if (this->abstract_filetype == FT_SAVEGAME || this->abstract_filetype == FT_SCENARIO) {
 
							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
 
@@ -403,13 +403,13 @@ static const StringID _variety[]     = {
 
static_assert(lengthof(_num_inds) == ID_END + 1);
 

	
 
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)
 
	{
 
		this->InitNested(number);
 

	
 
@@ -1054,13 +1054,13 @@ static void _ShowGenerateLandscape(Gener
 
	WindowDesc *desc = (mode == GLWM_HEIGHTMAP) ? &_heightmap_load_desc : &_generate_landscape_desc;
 
	GenerateLandscapeWindow *w = AllocateWindowDescFront<GenerateLandscapeWindow>(desc, mode, true);
 

	
 
	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);
 
}
 

	
 
/** Start with a normal game. */
src/openttd.cpp
Show inline comments
 
@@ -581,13 +581,13 @@ int openttd_main(int argc, char *argv[])
 
				if (mgo.opt != nullptr) SetDebugString(mgo.opt, ShowInfoI);
 
				break;
 
			}
 
		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);
 

	
 
				/* if the file doesn't exist or it is not a valid savegame, let the saveload code show an error */
 
				auto t = _file_to_saveload.name.find_last_of('.');
src/saveload/saveload.cpp
Show inline comments
 
@@ -3393,27 +3393,20 @@ void FileToSaveLoad::SetMode(SaveLoadOpe
 
	this->file_op = fop;
 
	this->detail_ftype = dft;
 
	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
 
{
 
	assert(this->load_description.has_value());
 
	return *this->load_description;
src/saveload/saveload.h
Show inline comments
 
@@ -362,22 +362,21 @@ enum SaveOrLoadResult {
 
	SL_ERROR  = 1, ///< error that was caught before internal structures were modified
 
	SL_REINIT = 2, ///< error that was caught in the middle of updating game state, need to clear it. (can only happen during load)
 
};
 

	
 
/** 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. */
 
enum SavegameType {
 
	SGT_TTD,    ///< TTD  savegame (can be detected incorrectly)
 
	SGT_TTDP1,  ///< TTDP savegame ( -//- ) (data at NW border)
0 comments (0 inline, 0 general)