Fix #8316: Make sort industries by production and transported with a cargo filter...
[openttd-github.git] / src / fios.h
blobc0e51629756fd6b28ec0e15e24230ff40d47fdf8
1 /*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6 */
8 /** @file fios.h Declarations for savegames operations */
10 #ifndef FIOS_H
11 #define FIOS_H
13 #include "gfx_type.h"
14 #include "company_base.h"
15 #include "newgrf_config.h"
16 #include "network/core/tcp_content_type.h"
19 /** Special values for save-load window for the data parameter of #InvalidateWindowData. */
20 enum SaveLoadInvalidateWindowData {
21 SLIWD_RESCAN_FILES, ///< Rescan all files (when changed directory, ...)
22 SLIWD_SELECTION_CHANGES, ///< File selection has changed (user click, ...)
23 SLIWD_FILTER_CHANGES, ///< The filename filter has changed (via the editbox)
26 typedef SmallMap<uint, CompanyProperties *> CompanyPropertiesMap;
28 /**
29 * Container for loading in mode SL_LOAD_CHECK.
31 struct LoadCheckData {
32 bool checkable; ///< True if the savegame could be checked by SL_LOAD_CHECK. (Old savegames are not checkable.)
33 StringID error; ///< Error message from loading. INVALID_STRING_ID if no error.
34 char *error_data; ///< Data to pass to SetDParamStr when displaying #error.
36 uint32 map_size_x, map_size_y;
37 Date current_date;
39 GameSettings settings;
41 CompanyPropertiesMap companies; ///< Company information.
43 GRFConfig *grfconfig; ///< NewGrf configuration from save.
44 GRFListCompatibility grf_compatibility; ///< Summary state of NewGrfs, whether missing files or only compatible found.
46 struct LoggedAction *gamelog_action; ///< Gamelog actions
47 uint gamelog_actions; ///< Number of gamelog actions
49 LoadCheckData() : error_data(nullptr), grfconfig(nullptr),
50 grf_compatibility(GLC_NOT_FOUND), gamelog_action(nullptr), gamelog_actions(0)
52 this->Clear();
55 /**
56 * Don't leak memory at program exit
58 ~LoadCheckData()
60 this->Clear();
63 /**
64 * Check whether loading the game resulted in errors.
65 * @return true if errors were encountered.
67 bool HasErrors()
69 return this->checkable && this->error != INVALID_STRING_ID;
72 /**
73 * Check whether the game uses any NewGrfs.
74 * @return true if NewGrfs are used.
76 bool HasNewGrfs()
78 return this->checkable && this->error == INVALID_STRING_ID && this->grfconfig != nullptr;
81 void Clear();
84 extern LoadCheckData _load_check_data;
86 /** Deals with finding savegames */
87 struct FiosItem {
88 FiosType type;
89 uint64 mtime;
90 char title[64];
91 char name[MAX_PATH];
92 bool operator< (const FiosItem &other) const;
95 /** List of file information. */
96 class FileList : public std::vector<FiosItem> {
97 public:
98 void BuildFileList(AbstractFileType abstract_filetype, SaveLoadOperation fop);
99 const FiosItem *FindItem(const char *file);
102 enum SortingBits {
103 SORT_ASCENDING = 0,
104 SORT_DESCENDING = 1,
105 SORT_BY_DATE = 0,
106 SORT_BY_NAME = 2
108 DECLARE_ENUM_AS_BIT_SET(SortingBits)
110 /* Variables to display file lists */
111 extern SortingBits _savegame_sort_order;
113 void ShowSaveLoadDialog(AbstractFileType abstract_filetype, SaveLoadOperation fop);
115 void FiosGetSavegameList(SaveLoadOperation fop, FileList &file_list);
116 void FiosGetScenarioList(SaveLoadOperation fop, FileList &file_list);
117 void FiosGetHeightmapList(SaveLoadOperation fop, FileList &file_list);
119 const char *FiosBrowseTo(const FiosItem *item);
121 StringID FiosGetDescText(const char **path, uint64 *total_free);
122 bool FiosDelete(const char *name);
123 std::string FiosMakeHeightmapName(const char *name);
124 std::string FiosMakeSavegameName(const char *name);
126 FiosType FiosGetSavegameListCallback(SaveLoadOperation fop, const std::string &file, const char *ext, char *title, const char *last);
129 * A savegame name automatically numbered.
131 struct FiosNumberedSaveName {
132 FiosNumberedSaveName(const std::string &prefix);
133 std::string Filename();
134 std::string Extension();
135 private:
136 std::string prefix;
137 int number;
140 #endif /* FIOS_H */