diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/console_cmds.cpp | 16 | ||||
-rw-r--r-- | src/fileio_type.h | 80 | ||||
-rw-r--r-- | src/fios.h | 2 | ||||
-rw-r--r-- | src/fios_gui.cpp | 20 | ||||
-rw-r--r-- | src/saveload/saveload.cpp | 26 |
5 files changed, 91 insertions, 53 deletions
diff --git a/src/console_cmds.cpp b/src/console_cmds.cpp index 6284287c0..a486ea282 100644 --- a/src/console_cmds.cpp +++ b/src/console_cmds.cpp @@ -360,16 +360,14 @@ DEF_CONSOLE_CMD(ConLoad) _console_file_list.ValidateFileList(); const FiosItem *item = _console_file_list.FindItem(file); if (item != NULL) { - switch (item->type) { - case FIOS_TYPE_FILE: case FIOS_TYPE_OLDFILE: { - _switch_mode = SM_LOAD_GAME; - _file_to_saveload.SetMode(item->type); + 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)); - break; - } - default: IConsolePrintF(CC_ERROR, "%s: Not a savegame.", file); + strecpy(_file_to_saveload.name, FiosBrowseTo(item), lastof(_file_to_saveload.name)); + strecpy(_file_to_saveload.title, item->title, lastof(_file_to_saveload.title)); + } else { + IConsolePrintF(CC_ERROR, "%s: Not a savegame.", file); } } else { IConsolePrintF(CC_ERROR, "%s: No such file or directory.", file); diff --git a/src/fileio_type.h b/src/fileio_type.h index 20df8cd05..4fae7b392 100644 --- a/src/fileio_type.h +++ b/src/fileio_type.h @@ -22,6 +22,27 @@ enum AbstractFileType { FT_HEIGHTMAP, ///< heightmap file FT_INVALID = 7, ///< Invalid or unknown file type. + FT_NUMBITS = 3, ///< Number of bits required for storing a #AbstractFileType value. + FT_MASK = (1 << FT_NUMBITS) - 1, ///< Bitmask for extracting an abstract file type. +}; + +/** Kinds of files in each #AbstractFileType. */ +enum DetailedFileType { + /* Save game and scenario files. */ + DFT_OLD_GAME_FILE, ///< Old save game or scenario file. + DFT_GAME_FILE, ///< Save game or scenario file. + + /* Heightmap files. */ + DFT_HEIGHTMAP_BMP, ///< BMP file. + DFT_HEIGHTMAP_PNG, ///< PNG file. + + /* fios 'files' */ + DFT_FIOS_DRIVE, ///< A drive (letter) entry. + DFT_FIOS_PARENT, ///< A parent directory entry. + DFT_FIOS_DIR, ///< A directory entry. + DFT_FIOS_DIRECT, ///< Direct filename. + + DFT_INVALID = 255, ///< Unknown or invalid file. }; /** Operation performed on the file. */ @@ -30,21 +51,56 @@ enum FileOperation { FOP_SAVE, ///< File is being saved. }; -/** Elements of a file system that are recognized. */ +/** + * Construct an enum value for #FiosType as a combination of an abstract and a detailed file type. + * @param abstract Abstract file type (one of #AbstractFileType). + * @param detailed Detailed file type (one of #DetailedFileType). + */ +#define MAKE_FIOS_TYPE(abstract, detailed) ((abstract) | ((detailed) << FT_NUMBITS)) + +/** + * Elements of a file system that are recognized. + * Values are a combination of #AbstractFileType and #DetailedFileType. + * @see GetAbstractFileType GetDetailedFileType + */ enum FiosType { - FIOS_TYPE_DRIVE, - FIOS_TYPE_PARENT, - FIOS_TYPE_DIR, - FIOS_TYPE_FILE, - FIOS_TYPE_OLDFILE, - FIOS_TYPE_SCENARIO, - FIOS_TYPE_OLD_SCENARIO, - FIOS_TYPE_DIRECT, - FIOS_TYPE_PNG, - FIOS_TYPE_BMP, - FIOS_TYPE_INVALID = 255, + FIOS_TYPE_DRIVE = MAKE_FIOS_TYPE(FT_NONE, DFT_FIOS_DRIVE), + FIOS_TYPE_PARENT = MAKE_FIOS_TYPE(FT_NONE, DFT_FIOS_PARENT), + FIOS_TYPE_DIR = MAKE_FIOS_TYPE(FT_NONE, DFT_FIOS_DIR), + FIOS_TYPE_DIRECT = MAKE_FIOS_TYPE(FT_NONE, DFT_FIOS_DIRECT), + + FIOS_TYPE_FILE = MAKE_FIOS_TYPE(FT_SAVEGAME, DFT_GAME_FILE), + FIOS_TYPE_OLDFILE = MAKE_FIOS_TYPE(FT_SAVEGAME, DFT_OLD_GAME_FILE), + FIOS_TYPE_SCENARIO = MAKE_FIOS_TYPE(FT_SCENARIO, DFT_GAME_FILE), + FIOS_TYPE_OLD_SCENARIO = MAKE_FIOS_TYPE(FT_SCENARIO, DFT_OLD_GAME_FILE), + FIOS_TYPE_PNG = MAKE_FIOS_TYPE(FT_HEIGHTMAP, DFT_HEIGHTMAP_PNG), + FIOS_TYPE_BMP = MAKE_FIOS_TYPE(FT_HEIGHTMAP, DFT_HEIGHTMAP_BMP), + + FIOS_TYPE_INVALID = MAKE_FIOS_TYPE(FT_INVALID, DFT_INVALID), }; +#undef MAKE_FIOS_TYPE + +/** + * Extract the abstract file type from a #FiosType. + * @param fios_type Type to query. + * @return The Abstract file type of the \a fios_type. + */ +inline AbstractFileType GetAbstractFileType(FiosType fios_type) +{ + return static_cast<AbstractFileType>(fios_type & FT_MASK); +} + +/** + * Extract the detailed file type from a #FiosType. + * @param fios_type Type to query. + * @return The Detailed file type of the \a fios_type. + */ +inline DetailedFileType GetDetailedFileType(FiosType fios_type) +{ + return static_cast<DetailedFileType>(fios_type >> FT_NUMBITS); +} + /** * The different kinds of subdirectories OpenTTD uses */ diff --git a/src/fios.h b/src/fios.h index 86bcf3e3a..80654812b 100644 --- a/src/fios.h +++ b/src/fios.h @@ -224,6 +224,4 @@ FiosType FiosGetSavegameListCallback(FileOperation fop, const char *file, const int CDECL CompareFiosItems(const FiosItem *a, const FiosItem *b); -extern const TextColour _fios_colours[]; - #endif /* FIOS_H */ diff --git a/src/fios_gui.cpp b/src/fios_gui.cpp index e902941d6..a4e495b49 100644 --- a/src/fios_gui.cpp +++ b/src/fios_gui.cpp @@ -186,12 +186,19 @@ static const NWidgetPart _nested_save_dialog_widgets[] = { EndContainer(), }; -/** Colours for fios types, indexed by #FiosType. */ -const TextColour _fios_colours[] = { - TC_LIGHT_BLUE, TC_DARK_GREEN, TC_DARK_GREEN, TC_ORANGE, TC_LIGHT_BROWN, - TC_ORANGE, TC_LIGHT_BROWN, TC_ORANGE, TC_ORANGE, TC_YELLOW +/** Text colours of #DetailedFileType fios entries in the window. */ +static const TextColour _fios_colours[] = { + TC_LIGHT_BROWN, // DFT_OLD_GAME_FILE + TC_ORANGE, // DFT_GAME_FILE + TC_YELLOW, // DFT_HEIGHTMAP_BMP + TC_ORANGE, // DFT_HEIGHTMAP_PNG + TC_LIGHT_BLUE, // DFT_FIOS_DRIVE + TC_DARK_GREEN, // DFT_FIOS_PARENT + TC_DARK_GREEN, // DFT_FIOS_DIR + TC_ORANGE, // DFT_FIOS_DIRECT }; + /** * Sort the collected list save games prior to displaying it in the save/load gui. * @param [inout] file_list List of save game files found in the directory. @@ -368,7 +375,7 @@ public: if (item == this->selected) { GfxFillRect(r.left + 1, y, r.right, y + this->resize.step_height, PC_DARK_BLUE); } - DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, item->title, _fios_colours[item->type]); + DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, item->title, _fios_colours[GetDetailedFileType(item->type)]); y += this->resize.step_height; if (y >= this->vscroll->GetCapacity() * this->resize.step_height + r.top + WD_FRAMERECT_TOP) break; } @@ -575,7 +582,8 @@ public: this->selected = file; _load_check_data.Clear(); - if (file->type == FIOS_TYPE_FILE || file->type == FIOS_TYPE_SCENARIO) { + if (GetDetailedFileType(file->type) == DFT_GAME_FILE) { + /* Other detailed file types cannot be checked before. */ SaveOrLoad(name, SL_LOAD_CHECK, NO_DIRECTORY, false); } diff --git a/src/saveload/saveload.cpp b/src/saveload/saveload.cpp index a0d15938a..b5fdda27a 100644 --- a/src/saveload/saveload.cpp +++ b/src/saveload/saveload.cpp @@ -2924,30 +2924,8 @@ void FileToSaveLoad::SetMode(FiosType ft) break; } - switch (ft) { - case FIOS_TYPE_OLDFILE: - case FIOS_TYPE_FILE: - this->filetype = FT_SAVEGAME; - break; - - case FIOS_TYPE_OLD_SCENARIO: - case FIOS_TYPE_SCENARIO: - this->filetype = FT_SCENARIO; - break; - -#ifdef WITH_PNG - case FIOS_TYPE_PNG: - /* FALL THROUGH */ -#endif /* WITH_PNG */ - - case FIOS_TYPE_BMP: - this->filetype = FT_HEIGHTMAP; - break; - - default: - this->filetype = FT_INVALID; - break; - } + this->filetype = GetAbstractFileType(ft); + if (this->filetype == FT_NONE) this->filetype = FT_INVALID; } #if 0 |