OpenTTD Source: src/fios_gui.cpp Source File

OpenTTD Source 15.0-RC2

fios_gui.cpp
Go to the documentation of this file.
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 <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
10#include "stdafx.h"
11#include "saveload/saveload.h"
12#include "error.h"
13#include "gui.h"
14#include "gfx_func.h"
15#include "command_func.h"
16#include "network/network.h"
17#include "network/network_content.h"
18#include "strings_func.h"
19#include "fileio_func.h"
20#include "fios.h"
21#include "window_func.h"
22#include "tilehighlight_func.h"
23#include "querystring_gui.h"
24#include "engine_func.h"
25#include "landscape_type.h"
26#include "genworld.h"
27#include "timer/timer_game_calendar.h"
28#include "core/geometry_func.hpp"
29#include "gamelog.h"
30#include "stringfilter_type.h"
31#include "misc_cmd.h"
32#include "gamelog_internal.h"
33
34#include "widgets/fios_widget.h"
35
36#include "table/sprites.h"
37#include "table/strings.h"
38
39#include "safeguards.h"
40
41 LoadCheckData _load_check_data;
42
43static bool _fios_path_changed;
44static bool _savegame_sort_dirty;
45
49 void LoadCheckData::Clear()
50{
51 this->checkable = false;
52 this->error = INVALID_STRING_ID;
53 this->error_msg.clear();
54
55 this->map_size_x = this->map_size_y = 256; // Default for old savegames which do not store mapsize.
56 this->current_date = CalendarTime::MIN_DATE;
57 this->landscape = {};
58 this->starting_year = {};
59
60 companies.clear();
61
62 this->gamelog.Reset();
63
64 ClearGRFConfigList(this->grfconfig);
65}
66
68 static constexpr std::initializer_list<NWidgetPart> _nested_load_dialog_widgets = {
69 NWidget(NWID_HORIZONTAL),
70 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
71 NWidget(WWT_CAPTION, COLOUR_GREY, WID_SL_CAPTION),
72 NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
73 EndContainer(),
74 /* Current directory and free space */
75 NWidget(WWT_PANEL, COLOUR_GREY, WID_SL_BACKGROUND), SetFill(1, 0), SetResize(1, 0),
76 EndContainer(),
77
78 NWidget(NWID_HORIZONTAL, NWidContainerFlag::EqualSize),
79 /* Left side : filter box and available files */
80 NWidget(NWID_VERTICAL),
81 /* Filter box with label */
82 NWidget(WWT_PANEL, COLOUR_GREY), SetFill(1, 1), SetResize(1, 1),
83 NWidget(NWID_HORIZONTAL), SetPadding(WidgetDimensions::unscaled.framerect.top, 0, WidgetDimensions::unscaled.framerect.bottom, 0),
84 SetPIP(WidgetDimensions::unscaled.frametext.left, WidgetDimensions::unscaled.frametext.right, 0),
85 NWidget(WWT_TEXT, INVALID_COLOUR), SetFill(0, 1), SetStringTip(STR_SAVELOAD_FILTER_TITLE),
86 NWidget(WWT_EDITBOX, COLOUR_GREY, WID_SL_FILTER), SetFill(1, 0), SetResize(1, 0),
87 SetStringTip(STR_LIST_FILTER_OSKTITLE, STR_LIST_FILTER_TOOLTIP),
88 EndContainer(),
89 EndContainer(),
90 /* Sort buttons */
91 NWidget(NWID_HORIZONTAL),
92 NWidget(NWID_HORIZONTAL, NWidContainerFlag::EqualSize),
93 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SL_SORT_BYNAME), SetStringTip(STR_SORT_BY_CAPTION_NAME, STR_TOOLTIP_SORT_ORDER), SetFill(1, 0), SetResize(1, 0),
94 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SL_SORT_BYDATE), SetStringTip(STR_SORT_BY_CAPTION_DATE, STR_TOOLTIP_SORT_ORDER), SetFill(1, 0), SetResize(1, 0),
95 EndContainer(),
96 NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_SL_HOME_BUTTON), SetAspect(1), SetSpriteTip(SPR_HOUSE_ICON, STR_SAVELOAD_HOME_BUTTON_TOOLTIP),
97 EndContainer(),
98 /* Files */
99 NWidget(NWID_HORIZONTAL),
100 NWidget(WWT_PANEL, COLOUR_GREY, WID_SL_FILE_BACKGROUND),
101 NWidget(WWT_INSET, COLOUR_GREY, WID_SL_DRIVES_DIRECTORIES_LIST), SetFill(1, 1), SetPadding(2, 2, 2, 2),
102 SetToolTip(STR_SAVELOAD_LIST_TOOLTIP), SetResize(1, 10), SetScrollbar(WID_SL_SCROLLBAR),
103 EndContainer(),
104 EndContainer(),
105 NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_SL_SCROLLBAR),
106 EndContainer(),
107 /* Online Content button */
108 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_SL_CONTENT_DOWNLOAD_SEL),
109 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SL_CONTENT_DOWNLOAD), SetResize(1, 0),
110 SetStringTip(STR_INTRO_ONLINE_CONTENT, STR_INTRO_TOOLTIP_ONLINE_CONTENT),
111 EndContainer(),
112 EndContainer(),
113
114 /* Right side : game details */
115 NWidget(NWID_VERTICAL),
116 NWidget(WWT_PANEL, COLOUR_GREY, WID_SL_DETAILS), SetResize(1, 1), SetFill(1, 1),
117 EndContainer(),
118 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SL_MISSING_NEWGRFS), SetStringTip(STR_NEWGRF_SETTINGS_FIND_MISSING_CONTENT_BUTTON, STR_NEWGRF_SETTINGS_FIND_MISSING_CONTENT_TOOLTIP), SetFill(1, 0), SetResize(1, 0),
119 NWidget(NWID_HORIZONTAL),
120 NWidget(NWID_HORIZONTAL, NWidContainerFlag::EqualSize),
121 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SL_NEWGRF_INFO), SetStringTip(STR_MAPGEN_NEWGRF_SETTINGS, STR_MAPGEN_NEWGRF_SETTINGS_TOOLTIP), SetFill(1, 0), SetResize(1, 0),
122 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SL_LOAD_BUTTON), SetStringTip(STR_SAVELOAD_LOAD_BUTTON, STR_SAVELOAD_LOAD_TOOLTIP), SetFill(1, 0), SetResize(1, 0),
123 EndContainer(),
124 NWidget(WWT_RESIZEBOX, COLOUR_GREY),
125 EndContainer(),
126 EndContainer(),
127 EndContainer(),
128};
129
131 static constexpr std::initializer_list<NWidgetPart> _nested_load_heightmap_dialog_widgets = {
132 NWidget(NWID_HORIZONTAL),
133 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
134 NWidget(WWT_CAPTION, COLOUR_GREY, WID_SL_CAPTION),
135 NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
136 EndContainer(),
137 /* Current directory and free space */
138 NWidget(WWT_PANEL, COLOUR_GREY, WID_SL_BACKGROUND), SetFill(1, 0), SetResize(1, 0),
139 EndContainer(),
140
141 /* Filter box with label */
142 NWidget(WWT_PANEL, COLOUR_GREY), SetFill(1, 1), SetResize(1, 1),
143 NWidget(NWID_HORIZONTAL), SetPadding(WidgetDimensions::unscaled.framerect.top, 0, WidgetDimensions::unscaled.framerect.bottom, 0),
144 SetPIP(WidgetDimensions::unscaled.frametext.left, WidgetDimensions::unscaled.frametext.right, 0),
145 NWidget(WWT_TEXT, INVALID_COLOUR), SetFill(0, 1), SetStringTip(STR_SAVELOAD_FILTER_TITLE),
146 NWidget(WWT_EDITBOX, COLOUR_GREY, WID_SL_FILTER), SetFill(1, 0), SetResize(1, 0),
147 SetStringTip(STR_LIST_FILTER_OSKTITLE, STR_LIST_FILTER_TOOLTIP),
148 EndContainer(),
149 EndContainer(),
150 /* Sort Buttons */
151 NWidget(NWID_HORIZONTAL),
152 NWidget(NWID_HORIZONTAL, NWidContainerFlag::EqualSize),
153 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SL_SORT_BYNAME), SetStringTip(STR_SORT_BY_CAPTION_NAME, STR_TOOLTIP_SORT_ORDER), SetFill(1, 0), SetResize(1, 0),
154 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SL_SORT_BYDATE), SetStringTip(STR_SORT_BY_CAPTION_DATE, STR_TOOLTIP_SORT_ORDER), SetFill(1, 0), SetResize(1, 0),
155 EndContainer(),
156 NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_SL_HOME_BUTTON), SetAspect(1), SetSpriteTip(SPR_HOUSE_ICON, STR_SAVELOAD_HOME_BUTTON_TOOLTIP),
157 EndContainer(),
158 /* Files */
159 NWidget(NWID_HORIZONTAL),
160 NWidget(WWT_PANEL, COLOUR_GREY, WID_SL_FILE_BACKGROUND),
161 NWidget(WWT_INSET, COLOUR_GREY, WID_SL_DRIVES_DIRECTORIES_LIST), SetFill(1, 1), SetPadding(2, 2, 2, 2),
162 SetToolTip(STR_SAVELOAD_LIST_TOOLTIP), SetResize(1, 10), SetScrollbar(WID_SL_SCROLLBAR),
163 EndContainer(),
164 EndContainer(),
165 NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_SL_SCROLLBAR),
166 EndContainer(),
167 /* Online Content and Load button */
168 NWidget(NWID_HORIZONTAL, NWidContainerFlag::EqualSize),
169 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SL_CONTENT_DOWNLOAD), SetResize(1, 0), SetFill(1, 0),
170 SetStringTip(STR_INTRO_ONLINE_CONTENT, STR_INTRO_TOOLTIP_ONLINE_CONTENT),
171 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SL_LOAD_BUTTON), SetResize(1, 0), SetFill(1, 0),
172 SetStringTip(STR_SAVELOAD_LOAD_BUTTON, STR_SAVELOAD_LOAD_HEIGHTMAP_TOOLTIP),
173 NWidget(WWT_RESIZEBOX, COLOUR_GREY),
174 EndContainer(),
175};
176
178 static constexpr std::initializer_list<NWidgetPart> _nested_load_town_data_dialog_widgets = {
179 NWidget(NWID_HORIZONTAL),
180 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
181 NWidget(WWT_CAPTION, COLOUR_GREY, WID_SL_CAPTION),
182 NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
183 EndContainer(),
184 /* Current directory and free space */
185 NWidget(WWT_PANEL, COLOUR_GREY, WID_SL_BACKGROUND), SetFill(1, 0), SetResize(1, 0), EndContainer(),
186
187 /* Filter box with label */
188 NWidget(WWT_PANEL, COLOUR_GREY), SetFill(1, 1), SetResize(1, 1),
189 NWidget(NWID_HORIZONTAL), SetPadding(WidgetDimensions::unscaled.framerect.top, 0, WidgetDimensions::unscaled.framerect.bottom, 0),
190 SetPIP(WidgetDimensions::unscaled.frametext.left, WidgetDimensions::unscaled.frametext.right, 0),
191 NWidget(WWT_TEXT, INVALID_COLOUR), SetFill(0, 1), SetStringTip(STR_SAVELOAD_FILTER_TITLE),
192 NWidget(WWT_EDITBOX, COLOUR_GREY, WID_SL_FILTER), SetFill(1, 0), SetResize(1, 0), SetStringTip(STR_LIST_FILTER_OSKTITLE, STR_LIST_FILTER_TOOLTIP),
193 EndContainer(),
194 EndContainer(),
195 /* Sort Buttons */
196 NWidget(NWID_HORIZONTAL),
197 NWidget(NWID_HORIZONTAL, NWidContainerFlag::EqualSize),
198 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SL_SORT_BYNAME), SetStringTip(STR_SORT_BY_CAPTION_NAME, STR_TOOLTIP_SORT_ORDER), SetFill(1, 0), SetResize(1, 0),
199 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SL_SORT_BYDATE), SetStringTip(STR_SORT_BY_CAPTION_DATE, STR_TOOLTIP_SORT_ORDER), SetFill(1, 0), SetResize(1, 0),
200 EndContainer(),
201 NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_SL_HOME_BUTTON), SetAspect(1), SetSpriteTip(SPR_HOUSE_ICON, STR_SAVELOAD_HOME_BUTTON_TOOLTIP),
202 EndContainer(),
203 /* Files */
204 NWidget(NWID_HORIZONTAL),
205 NWidget(WWT_PANEL, COLOUR_GREY, WID_SL_FILE_BACKGROUND),
206 NWidget(WWT_INSET, COLOUR_GREY, WID_SL_DRIVES_DIRECTORIES_LIST), SetFill(1, 1), SetPadding(2, 2, 2, 2),
207 SetToolTip(STR_SAVELOAD_LIST_TOOLTIP), SetResize(1, 10), SetScrollbar(WID_SL_SCROLLBAR), EndContainer(),
208 EndContainer(),
209 NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_SL_SCROLLBAR),
210 EndContainer(),
211 /* Load button */
212 NWidget(NWID_HORIZONTAL, NWidContainerFlag::EqualSize),
213 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SL_LOAD_BUTTON), SetResize(1, 0), SetFill(1, 0),
214 SetStringTip(STR_SAVELOAD_LOAD_BUTTON, STR_SAVELOAD_LOAD_TOWN_DATA_TOOLTIP),
215 NWidget(WWT_RESIZEBOX, COLOUR_GREY),
216 EndContainer(),
217};
218
220 static constexpr std::initializer_list<NWidgetPart> _nested_save_dialog_widgets = {
221 NWidget(NWID_HORIZONTAL),
222 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
223 NWidget(WWT_CAPTION, COLOUR_GREY, WID_SL_CAPTION),
224 NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
225 EndContainer(),
226 /* Current directory and free space */
227 NWidget(WWT_PANEL, COLOUR_GREY, WID_SL_BACKGROUND), SetFill(1, 0), SetResize(1, 0),
228 EndContainer(),
229
230 NWidget(NWID_HORIZONTAL, NWidContainerFlag::EqualSize),
231 /* Left side : filter box and available files */
232 NWidget(NWID_VERTICAL),
233 /* Filter box with label */
234 NWidget(WWT_PANEL, COLOUR_GREY), SetFill(1, 1), SetResize(1, 1),
235 NWidget(NWID_HORIZONTAL), SetPadding(WidgetDimensions::unscaled.framerect.top, 0, WidgetDimensions::unscaled.framerect.bottom, 0),
236 SetPIP(WidgetDimensions::unscaled.frametext.left, WidgetDimensions::unscaled.frametext.right, 0),
237 NWidget(WWT_TEXT, INVALID_COLOUR), SetFill(0, 1), SetStringTip(STR_SAVELOAD_FILTER_TITLE),
238 NWidget(WWT_EDITBOX, COLOUR_GREY, WID_SL_FILTER), SetFill(1, 0), SetResize(1, 0),
239 SetStringTip(STR_LIST_FILTER_OSKTITLE, STR_LIST_FILTER_TOOLTIP),
240 EndContainer(),
241 EndContainer(),
242 /* Sort buttons */
243 NWidget(NWID_HORIZONTAL),
244 NWidget(NWID_HORIZONTAL, NWidContainerFlag::EqualSize),
245 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SL_SORT_BYNAME), SetStringTip(STR_SORT_BY_CAPTION_NAME, STR_TOOLTIP_SORT_ORDER), SetFill(1, 0), SetResize(1, 0),
246 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SL_SORT_BYDATE), SetStringTip(STR_SORT_BY_CAPTION_DATE, STR_TOOLTIP_SORT_ORDER), SetFill(1, 0), SetResize(1, 0),
247 EndContainer(),
248 NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_SL_HOME_BUTTON), SetAspect(1), SetSpriteTip(SPR_HOUSE_ICON, STR_SAVELOAD_HOME_BUTTON_TOOLTIP),
249 EndContainer(),
250 /* Files */
251 NWidget(NWID_HORIZONTAL),
252 NWidget(WWT_PANEL, COLOUR_GREY, WID_SL_FILE_BACKGROUND),
253 NWidget(WWT_INSET, COLOUR_GREY, WID_SL_DRIVES_DIRECTORIES_LIST), SetPadding(2, 2, 2, 2),
254 SetToolTip(STR_SAVELOAD_LIST_TOOLTIP), SetResize(1, 10), SetScrollbar(WID_SL_SCROLLBAR),
255 EndContainer(),
256 EndContainer(),
257 NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_SL_SCROLLBAR),
258 EndContainer(),
259 NWidget(WWT_PANEL, COLOUR_GREY),
260 NWidget(WWT_EDITBOX, COLOUR_GREY, WID_SL_SAVE_OSK_TITLE), SetPadding(2, 2, 2, 2), SetFill(1, 0), SetResize(1, 0),
261 SetStringTip(STR_SAVELOAD_OSKTITLE, STR_SAVELOAD_EDITBOX_TOOLTIP),
262 EndContainer(),
263 /* Save/delete buttons */
264 NWidget(NWID_HORIZONTAL),
265 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SL_DELETE_SELECTION), SetStringTip(STR_SAVELOAD_DELETE_BUTTON, STR_SAVELOAD_DELETE_TOOLTIP), SetFill(1, 0), SetResize(1, 0),
266 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SL_SAVE_GAME), SetStringTip(STR_SAVELOAD_SAVE_BUTTON, STR_SAVELOAD_SAVE_TOOLTIP), SetFill(1, 0), SetResize(1, 0),
267 EndContainer(),
268 EndContainer(),
269
270 /* Right side : game details */
271 NWidget(NWID_VERTICAL),
272 NWidget(WWT_PANEL, COLOUR_GREY, WID_SL_DETAILS), SetResize(1, 1), SetFill(1, 1),
273 EndContainer(),
274 NWidget(NWID_HORIZONTAL),
275 NWidget(WWT_PANEL, COLOUR_GREY), SetResize(1, 0), SetFill(1, 1),
276 EndContainer(),
277 NWidget(WWT_RESIZEBOX, COLOUR_GREY),
278 EndContainer(),
279 EndContainer(),
280 EndContainer(),
281};
282
284 static const TextColour _fios_colours[] = {
285 TC_LIGHT_BROWN, // DFT_OLD_GAME_FILE
286 TC_ORANGE, // DFT_GAME_FILE
287 TC_YELLOW, // DFT_HEIGHTMAP_BMP
288 TC_ORANGE, // DFT_HEIGHTMAP_PNG
289 TC_LIGHT_BROWN, // DFT_TOWN_DATA_JSON
290 TC_LIGHT_BLUE, // DFT_FIOS_DRIVE
291 TC_DARK_GREEN, // DFT_FIOS_PARENT
292 TC_DARK_GREEN, // DFT_FIOS_DIR
293 TC_ORANGE, // DFT_FIOS_DIRECT
294};
295/* This should align with the DetailedFileType enum defined in fileio_type.h */
296static_assert(std::size(_fios_colours) == DFT_END);
297
302 static void SortSaveGameList(FileList &file_list)
303{
304 size_t sort_start = 0;
305 size_t sort_end = 0;
306
307 /* Directories are always above the files (FIOS_TYPE_DIR)
308 * Drives (A:\ (windows only) are always under the files (FIOS_TYPE_DRIVE)
309 * Only sort savegames/scenarios, not directories
310 */
311 for (const auto &item : file_list) {
312 switch (item.type.detailed) {
313 case DFT_FIOS_DIR: sort_start++; break;
314 case DFT_FIOS_PARENT: sort_start++; break;
315 case DFT_FIOS_DRIVE: sort_end++; break;
316 default: break;
317 }
318 }
319
320 std::sort(file_list.begin() + sort_start, file_list.end() - sort_end);
321}
322
323 struct SaveLoadWindow : public Window {
324private:
325 static const uint EDITBOX_MAX_SIZE = 50;
326
327 QueryString filename_editbox;
328 AbstractFileType abstract_filetype{};
329 SaveLoadOperation fop{};
330 FileList fios_items{};
331 FiosItem o_dir{};
332 const FiosItem *selected = nullptr;
333 const FiosItem *highlighted = nullptr;
334 Scrollbar *vscroll = nullptr;
335
336 StringFilter string_filter{};
337 QueryString filter_editbox;
338 std::vector<FiosItem *> display_list{};
339
340 static void SaveGameConfirmationCallback(Window *, bool confirmed)
341 {
342 /* File name has already been written to _file_to_saveload */
343 if (confirmed) _switch_mode = SM_SAVE_GAME;
344 }
345
346 static void SaveHeightmapConfirmationCallback(Window *, bool confirmed)
347 {
348 /* File name has already been written to _file_to_saveload */
349 if (confirmed) _switch_mode = SM_SAVE_HEIGHTMAP;
350 }
351
352 static void DeleteFileConfirmationCallback(Window *window, bool confirmed)
353 {
354 auto *save_load_window = static_cast<SaveLoadWindow*>(window);
355
356 assert(save_load_window->selected != nullptr);
357
358 if (confirmed) {
359 if (!FioRemove(save_load_window->selected->name)) {
360 ShowErrorMessage(GetEncodedString(STR_ERROR_UNABLE_TO_DELETE_FILE), {}, WL_ERROR);
361 } else {
362 save_load_window->InvalidateData(SLIWD_RESCAN_FILES);
363 /* Reset file name to current date on successful delete */
364 if (save_load_window->abstract_filetype == FT_SAVEGAME) save_load_window->GenerateFileName();
365 }
366 }
367 }
368
369public:
370
372 void GenerateFileName()
373 {
374 this->filename_editbox.text.Assign(GenerateDefaultSaveName());
375 }
376
377 SaveLoadWindow(WindowDesc &desc, AbstractFileType abstract_filetype, SaveLoadOperation fop)
378 : Window(desc), filename_editbox(64), abstract_filetype(abstract_filetype), fop(fop), filter_editbox(EDITBOX_MAX_SIZE)
379 {
380 assert(this->fop == SLO_SAVE || this->fop == SLO_LOAD);
381
382 /* For saving, construct an initial file name. */
383 if (this->fop == SLO_SAVE) {
384 switch (this->abstract_filetype) {
385 case FT_SAVEGAME:
386 this->GenerateFileName();
387 break;
388
389 case FT_SCENARIO:
390 case FT_HEIGHTMAP:
391 this->filename_editbox.text.Assign("UNNAMED");
392 break;
393
394 default:
395 /* It's not currently possible to save town data. */
396 NOT_REACHED();
397 }
398 }
399 this->querystrings[WID_SL_SAVE_OSK_TITLE] = &this->filename_editbox;
400 this->filename_editbox.ok_button = WID_SL_SAVE_GAME;
401
402 this->CreateNestedTree();
403 if (this->fop == SLO_LOAD && this->abstract_filetype == FT_SAVEGAME) {
404 this->GetWidget<NWidgetStacked>(WID_SL_CONTENT_DOWNLOAD_SEL)->SetDisplayedPlane(SZSP_HORIZONTAL);
405 }
406
407 /* Select caption string of the window. */
408 StringID caption_string;
409 switch (this->abstract_filetype) {
410 case FT_SAVEGAME:
411 caption_string = (this->fop == SLO_SAVE) ? STR_SAVELOAD_SAVE_CAPTION : STR_SAVELOAD_LOAD_CAPTION;
412 break;
413
414 case FT_SCENARIO:
415 caption_string = (this->fop == SLO_SAVE) ? STR_SAVELOAD_SAVE_SCENARIO : STR_SAVELOAD_LOAD_SCENARIO;
416 break;
417
418 case FT_HEIGHTMAP:
419 caption_string = (this->fop == SLO_SAVE) ? STR_SAVELOAD_SAVE_HEIGHTMAP : STR_SAVELOAD_LOAD_HEIGHTMAP;
420 break;
421
422 case FT_TOWN_DATA:
423 caption_string = STR_SAVELOAD_LOAD_TOWN_DATA; // It's not currently possible to save town data.
424 break;
425
426 default:
427 NOT_REACHED();
428 }
429 this->GetWidget<NWidgetCore>(WID_SL_CAPTION)->SetString(caption_string);
430
431 this->vscroll = this->GetScrollbar(WID_SL_SCROLLBAR);
432 this->FinishInitNested(0);
433
434 this->LowerWidget(WID_SL_DRIVES_DIRECTORIES_LIST);
435 this->querystrings[WID_SL_FILTER] = &this->filter_editbox;
436 this->filter_editbox.cancel_button = QueryString::ACTION_CLEAR;
437
438 /* pause is only used in single-player, non-editor mode, non-menu mode. It
439 * will be unpaused in the WE_DESTROY event handler. */
440 if (_game_mode != GM_MENU && !_networking && _game_mode != GM_EDITOR) {
441 Command<CMD_PAUSE>::Post(PauseMode::SaveLoad, true);
442 }
443 SetObjectToPlace(SPR_CURSOR_ZZZ, PAL_NONE, HT_NONE, WC_MAIN_WINDOW, 0);
444
445 this->OnInvalidateData(SLIWD_RESCAN_FILES);
446
447 ResetObjectToPlace();
448
449 /* Select the initial directory. */
450 o_dir.type = FIOS_TYPE_DIRECT;
451 switch (this->abstract_filetype) {
452 case FT_SAVEGAME:
453 o_dir.name = FioFindDirectory(SAVE_DIR);
454 break;
455
456 case FT_SCENARIO:
457 o_dir.name = FioFindDirectory(SCENARIO_DIR);
458 break;
459
460 case FT_HEIGHTMAP:
461 case FT_TOWN_DATA:
462 o_dir.name = FioFindDirectory(HEIGHTMAP_DIR);
463 break;
464
465 default:
466 o_dir.name = _personal_dir;
467 }
468
469 switch (this->fop) {
470 case SLO_SAVE:
471 /* Focus the edit box by default in the save window */
472 this->SetFocusedWidget(WID_SL_SAVE_OSK_TITLE);
473 break;
474
475 default:
476 this->SetFocusedWidget(WID_SL_FILTER);
477 }
478 }
479
480 void Close([[maybe_unused]] int data = 0) override
481 {
482 /* pause is only used in single-player, non-editor mode, non menu mode */
483 if (!_networking && _game_mode != GM_EDITOR && _game_mode != GM_MENU) {
484 Command<CMD_PAUSE>::Post(PauseMode::SaveLoad, false);
485 }
486 this->Window::Close();
487 }
488
489 void DrawWidget(const Rect &r, WidgetID widget) const override
490 {
491 switch (widget) {
492 case WID_SL_SORT_BYNAME:
493 case WID_SL_SORT_BYDATE:
494 if (((_savegame_sort_order & SORT_BY_NAME) != 0) == (widget == WID_SL_SORT_BYNAME)) {
495 this->DrawSortButtonState(widget, _savegame_sort_order & SORT_DESCENDING ? SBS_DOWN : SBS_UP);
496 }
497 break;
498
499 case WID_SL_BACKGROUND: {
500 static std::string path;
501 static std::optional<uint64_t> free_space = std::nullopt;
502
503 if (_fios_path_changed) {
504 path = FiosGetCurrentPath();
505 free_space = FiosGetDiskFreeSpace(path);
506 _fios_path_changed = false;
507 }
508
509 Rect ir = r.Shrink(WidgetDimensions::scaled.framerect);
510
511 if (free_space.has_value()) {
512 DrawString(ir.left, ir.right, ir.top + GetCharacterHeight(FS_NORMAL), GetString(STR_SAVELOAD_BYTES_FREE, free_space.value()));
513 } else {
514 DrawString(ir.left, ir.right, ir.top + GetCharacterHeight(FS_NORMAL), STR_ERROR_UNABLE_TO_READ_DRIVE);
515 }
516 DrawString(ir.left, ir.right, ir.top, path, TC_BLACK);
517 break;
518 }
519
520 case WID_SL_DRIVES_DIRECTORIES_LIST: {
521 const Rect br = r.Shrink(WidgetDimensions::scaled.bevel);
522 GfxFillRect(br, PC_BLACK);
523
524 Rect tr = r.Shrink(WidgetDimensions::scaled.inset).WithHeight(this->resize.step_height);
525 auto [first, last] = this->vscroll->GetVisibleRangeIterators(this->display_list);
526 for (auto it = first; it != last; ++it) {
527 const FiosItem *item = *it;
528
529 if (item == this->selected) {
530 GfxFillRect(br.WithY(tr), PC_DARK_BLUE);
531 } else if (item == this->highlighted) {
532 GfxFillRect(br.WithY(tr), PC_VERY_DARK_BLUE);
533 }
534 DrawString(tr, item->title.GetDecodedString(), _fios_colours[item->type.detailed]);
535 tr = tr.Translate(0, this->resize.step_height);
536 }
537 break;
538 }
539
540 case WID_SL_DETAILS:
541 this->DrawDetails(r);
542 break;
543 }
544 }
545
546 void DrawDetails(const Rect &r) const
547 {
548 /* Header panel */
549 int HEADER_HEIGHT = GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.frametext.Vertical();
550
551 Rect hr = r.WithHeight(HEADER_HEIGHT).Shrink(WidgetDimensions::scaled.frametext);
552 Rect tr = r.Shrink(WidgetDimensions::scaled.frametext);
553 tr.top += HEADER_HEIGHT;
554
555 /* Create the nice lighter rectangle at the details top */
556 GfxFillRect(r.WithHeight(HEADER_HEIGHT).Shrink(WidgetDimensions::scaled.bevel.left, WidgetDimensions::scaled.bevel.top, WidgetDimensions::scaled.bevel.right, 0), GetColourGradient(COLOUR_GREY, SHADE_LIGHTEST));
557 DrawString(hr.left, hr.right, hr.top, STR_SAVELOAD_DETAIL_CAPTION, TC_FROMSTRING, SA_HOR_CENTER);
558
559 if (this->selected == nullptr) return;
560
561 /* Details panel */
562 tr.bottom -= GetCharacterHeight(FS_NORMAL) - 1;
563 if (tr.top > tr.bottom) return;
564
565 if (!_load_check_data.checkable) {
566 /* Old savegame, no information available */
567 DrawString(tr, STR_SAVELOAD_DETAIL_NOT_AVAILABLE);
568 tr.top += GetCharacterHeight(FS_NORMAL);
569 } else if (_load_check_data.error != INVALID_STRING_ID) {
570 /* Incompatible / broken savegame */
571 tr.top = DrawStringMultiLine(tr, GetString(_load_check_data.error, _load_check_data.error_msg), TC_RED);
572 } else {
573 /* Mapsize */
574 DrawString(tr, GetString(STR_NETWORK_SERVER_LIST_MAP_SIZE, _load_check_data.map_size_x, _load_check_data.map_size_y));
575 tr.top += GetCharacterHeight(FS_NORMAL);
576 if (tr.top > tr.bottom) return;
577
578 /* Climate */
579 if (to_underlying(_load_check_data.landscape) < NUM_LANDSCAPE) {
580 DrawString(tr, GetString(STR_NETWORK_SERVER_LIST_LANDSCAPE, STR_CLIMATE_TEMPERATE_LANDSCAPE + to_underlying(_load_check_data.landscape)));
581 tr.top += GetCharacterHeight(FS_NORMAL);
582 }
583
584 tr.top += WidgetDimensions::scaled.vsep_normal;
585 if (tr.top > tr.bottom) return;
586
587 /* Start date (if available) */
588 if (_load_check_data.starting_year != 0) {
589 DrawString(tr, GetString(STR_NETWORK_SERVER_LIST_START_DATE, TimerGameCalendar::ConvertYMDToDate(_load_check_data.starting_year, 0, 1)));
590 tr.top += GetCharacterHeight(FS_NORMAL);
591 }
592 if (tr.top > tr.bottom) return;
593
594 /* Hide current date for scenarios */
595 if (this->abstract_filetype != FT_SCENARIO) {
596 /* Current date */
597 DrawString(tr, GetString(STR_NETWORK_SERVER_LIST_CURRENT_DATE, _load_check_data.current_date));
598 tr.top += GetCharacterHeight(FS_NORMAL);
599 }
600
601 /* Hide the NewGRF stuff when saving. We also hide the button. */
602 if (this->fop == SLO_LOAD && (this->abstract_filetype == FT_SAVEGAME || this->abstract_filetype == FT_SCENARIO)) {
603 tr.top += WidgetDimensions::scaled.vsep_normal;
604 if (tr.top > tr.bottom) return;
605
606 /* NewGrf compatibility */
607 DrawString(tr, GetString(STR_SAVELOAD_DETAIL_GRFSTATUS, _load_check_data.grfconfig.empty() ? STR_NEWGRF_LIST_NONE : STR_NEWGRF_LIST_ALL_FOUND + _load_check_data.grf_compatibility));
608 tr.top += GetCharacterHeight(FS_NORMAL);
609 }
610 if (tr.top > tr.bottom) return;
611
612 /* Hide the company stuff for scenarios */
613 if (this->abstract_filetype != FT_SCENARIO) {
614 tr.top += WidgetDimensions::scaled.vsep_wide;
615 if (tr.top > tr.bottom) return;
616
617 /* Companies / AIs */
618 for (auto &pair : _load_check_data.companies) {
619 const CompanyProperties &c = *pair.second;
620 if (c.name.empty()) {
621 DrawString(tr, GetString(STR_SAVELOAD_DETAIL_COMPANY_INDEX, pair.first + 1, c.name_1, c.name_2));
622 } else {
623 DrawString(tr, GetString(STR_SAVELOAD_DETAIL_COMPANY_INDEX, pair.first + 1, STR_JUST_RAW_STRING, c.name));
624 }
625
626 tr.top += GetCharacterHeight(FS_NORMAL);
627 if (tr.top > tr.bottom) break;
628 }
629 }
630 }
631 }
632
633 void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
634 {
635 switch (widget) {
636 case WID_SL_BACKGROUND:
637 size.height = 2 * GetCharacterHeight(FS_NORMAL) + padding.height;
638 break;
639
640 case WID_SL_DRIVES_DIRECTORIES_LIST:
641 fill.height = resize.height = GetCharacterHeight(FS_NORMAL);
642 size.height = resize.height * 10 + padding.height;
643 break;
644 case WID_SL_SORT_BYNAME:
645 case WID_SL_SORT_BYDATE: {
646 Dimension d = GetStringBoundingBox(this->GetWidget<NWidgetCore>(widget)->GetString());
647 d.width += padding.width + Window::SortButtonWidth() * 2; // Doubled since the string is centred and it also looks better.
648 d.height += padding.height;
649 size = maxdim(size, d);
650 break;
651 }
652 }
653 }
654
655 void OnPaint() override
656 {
657 if (_savegame_sort_dirty) {
658 _savegame_sort_dirty = false;
659 SortSaveGameList(this->fios_items);
660 this->OnInvalidateData(SLIWD_FILTER_CHANGES);
661 }
662
663 this->DrawWidgets();
664 }
665
666 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
667 {
668 switch (widget) {
669 case WID_SL_SORT_BYNAME: // Sort save names by name
670 _savegame_sort_order = (_savegame_sort_order == SORT_BY_NAME) ?
671 SORT_BY_NAME | SORT_DESCENDING : SORT_BY_NAME;
672 _savegame_sort_dirty = true;
673 this->SetDirty();
674 break;
675
676 case WID_SL_SORT_BYDATE: // Sort save names by date
677 _savegame_sort_order = (_savegame_sort_order == SORT_BY_DATE) ?
678 SORT_BY_DATE | SORT_DESCENDING : SORT_BY_DATE;
679 _savegame_sort_dirty = true;
680 this->SetDirty();
681 break;
682
683 case WID_SL_HOME_BUTTON: // OpenTTD 'button', jumps to OpenTTD directory
684 FiosBrowseTo(&o_dir);
685 this->InvalidateData(SLIWD_RESCAN_FILES);
686 break;
687
688 case WID_SL_LOAD_BUTTON: {
689 if (this->selected == nullptr || _load_check_data.HasErrors()) break;
690
691 _file_to_saveload.Set(*this->selected);
692
693 if (this->abstract_filetype == FT_HEIGHTMAP) {
694 this->Close();
695 ShowHeightmapLoad();
696 } else if (this->abstract_filetype == FT_TOWN_DATA) {
697 this->Close();
698 LoadTownData();
699 } else if (!_load_check_data.HasNewGrfs() || _load_check_data.grf_compatibility != GLC_NOT_FOUND || _settings_client.gui.UserIsAllowedToChangeNewGRFs()) {
700 _switch_mode = (_game_mode == GM_EDITOR) ? SM_LOAD_SCENARIO : SM_LOAD_GAME;
701 ClearErrorMessages();
702 this->Close();
703 }
704 break;
705 }
706
707 case WID_SL_NEWGRF_INFO:
708 if (_load_check_data.HasNewGrfs()) {
709 ShowNewGRFSettings(false, false, false, _load_check_data.grfconfig);
710 }
711 break;
712
713 case WID_SL_MISSING_NEWGRFS:
714 if (!_network_available) {
715 ShowErrorMessage(GetEncodedString(STR_NETWORK_ERROR_NOTAVAILABLE), {}, WL_ERROR);
716 } else if (_load_check_data.HasNewGrfs()) {
717 ShowMissingContentWindow(_load_check_data.grfconfig);
718 }
719 break;
720
721 case WID_SL_DRIVES_DIRECTORIES_LIST: { // Click the listbox
722 auto it = this->vscroll->GetScrolledItemFromWidget(this->display_list, pt.y, this, WID_SL_DRIVES_DIRECTORIES_LIST, WidgetDimensions::scaled.inset.top);
723 if (it == this->display_list.end()) return;
724
725 /* Get the corresponding non-filtered out item from the list */
726 const FiosItem *file = *it;
727
728 if (FiosBrowseTo(file)) {
729 /* Changed directory, need refresh. */
730 this->InvalidateData(SLIWD_RESCAN_FILES);
731 break;
732 }
733
734 if (click_count == 1) {
735 if (this->selected != file) {
736 this->selected = file;
737 _load_check_data.Clear();
738
739 if (file->type.detailed == DFT_GAME_FILE) {
740 /* Other detailed file types cannot be checked before. */
741 SaveOrLoad(file->name, SLO_CHECK, DFT_GAME_FILE, NO_DIRECTORY, false);
742 }
743
744 this->InvalidateData(SLIWD_SELECTION_CHANGES);
745 }
746 if (this->fop == SLO_SAVE) {
747 /* Copy clicked name to editbox */
748 this->filename_editbox.text.Assign(file->title.GetDecodedString());
749 this->SetWidgetDirty(WID_SL_SAVE_OSK_TITLE);
750 }
751 } else if (!_load_check_data.HasErrors()) {
752 this->selected = file;
753 if (this->fop == SLO_LOAD) {
754 if (this->abstract_filetype == FT_SAVEGAME || this->abstract_filetype == FT_SCENARIO || this->abstract_filetype == FT_TOWN_DATA) {
755 this->OnClick(pt, WID_SL_LOAD_BUTTON, 1);
756 } else {
757 assert(this->abstract_filetype == FT_HEIGHTMAP);
758 _file_to_saveload.Set(*file);
759
760 this->Close();
761 ShowHeightmapLoad();
762 }
763 }
764 }
765 break;
766 }
767
768 case WID_SL_CONTENT_DOWNLOAD:
769 if (!_network_available) {
770 ShowErrorMessage(GetEncodedString(STR_NETWORK_ERROR_NOTAVAILABLE), {}, WL_ERROR);
771 } else {
772 assert(this->fop == SLO_LOAD);
773 switch (this->abstract_filetype) {
774 default: NOT_REACHED();
775 case FT_SCENARIO: ShowNetworkContentListWindow(nullptr, CONTENT_TYPE_SCENARIO); break;
776 case FT_HEIGHTMAP: ShowNetworkContentListWindow(nullptr, CONTENT_TYPE_HEIGHTMAP); break;
777 }
778 }
779 break;
780
781 case WID_SL_DELETE_SELECTION: // Delete
782 break;
783
784 case WID_SL_SAVE_GAME: // Save game
785 /* Note, this is also called via the OSK; and we need to lower the button. */
786 this->HandleButtonClick(WID_SL_SAVE_GAME);
787 break;
788 }
789 }
790
791 void OnMouseOver([[maybe_unused]] Point pt, WidgetID widget) override
792 {
793 if (widget == WID_SL_DRIVES_DIRECTORIES_LIST) {
794 auto it = this->vscroll->GetScrolledItemFromWidget(this->display_list, pt.y, this, WID_SL_DRIVES_DIRECTORIES_LIST, WidgetDimensions::scaled.inset.top);
795 if (it == this->display_list.end()) return;
796
797 /* Get the corresponding non-filtered out item from the list */
798 const FiosItem *file = *it;
799
800 if (file != this->highlighted) {
801 this->highlighted = file;
802 this->SetWidgetDirty(WID_SL_DRIVES_DIRECTORIES_LIST);
803 }
804 } else if (this->highlighted != nullptr) {
805 this->highlighted = nullptr;
806 this->SetWidgetDirty(WID_SL_DRIVES_DIRECTORIES_LIST);
807 }
808 }
809
810 EventState OnKeyPress([[maybe_unused]] char32_t key, uint16_t keycode) override
811 {
812 if (keycode == WKC_ESC) {
813 this->Close();
814 return ES_HANDLED;
815 }
816
817 return ES_NOT_HANDLED;
818 }
819
820 void OnTimeout() override
821 {
822 /* Widgets WID_SL_DELETE_SELECTION and WID_SL_SAVE_GAME only exist when saving to a file. */
823 if (this->fop != SLO_SAVE) return;
824
825 if (this->IsWidgetLowered(WID_SL_DELETE_SELECTION)) { // Delete button clicked
826 ShowQuery(GetEncodedString(STR_SAVELOAD_DELETE_TITLE), GetEncodedString(STR_SAVELOAD_DELETE_WARNING),
827 this, SaveLoadWindow::DeleteFileConfirmationCallback);
828 } else if (this->IsWidgetLowered(WID_SL_SAVE_GAME)) { // Save button clicked
829 if (this->abstract_filetype == FT_SAVEGAME || this->abstract_filetype == FT_SCENARIO) {
830 _file_to_saveload.name = FiosMakeSavegameName(this->filename_editbox.text.GetText());
831 if (FioCheckFileExists(_file_to_saveload.name, Subdirectory::SAVE_DIR)) {
832 ShowQuery(GetEncodedString(STR_SAVELOAD_OVERWRITE_TITLE), GetEncodedString(STR_SAVELOAD_OVERWRITE_WARNING),
833 this, SaveLoadWindow::SaveGameConfirmationCallback);
834 } else {
835 _switch_mode = SM_SAVE_GAME;
836 }
837 } else {
838 _file_to_saveload.name = FiosMakeHeightmapName(this->filename_editbox.text.GetText());
839 if (FioCheckFileExists(_file_to_saveload.name, Subdirectory::SAVE_DIR)) {
840 ShowQuery(GetEncodedString(STR_SAVELOAD_OVERWRITE_TITLE), GetEncodedString(STR_SAVELOAD_OVERWRITE_WARNING),
841 this, SaveLoadWindow::SaveHeightmapConfirmationCallback);
842 } else {
843 _switch_mode = SM_SAVE_HEIGHTMAP;
844 }
845 }
846
847 /* In the editor set up the vehicle engines correctly (date might have changed) */
848 if (_game_mode == GM_EDITOR) StartupEngines();
849 }
850 }
851
852 void OnResize() override
853 {
854 this->vscroll->SetCapacityFromWidget(this, WID_SL_DRIVES_DIRECTORIES_LIST);
855 }
856
857 void BuildDisplayList()
858 {
859 /* Filter changes */
860 this->display_list.clear();
861 this->display_list.reserve(this->fios_items.size());
862
863 if (this->string_filter.IsEmpty()) {
864 /* We don't filter anything out if the filter editbox is empty */
865 for (auto &it : this->fios_items) {
866 this->display_list.push_back(&it);
867 }
868 } else {
869 for (auto &it : this->fios_items) {
870 this->string_filter.ResetState();
871 this->string_filter.AddLine(it.title.GetDecodedString());
872 /* We set the vector to show this fios element as filtered depending on the result of the filter */
873 if (this->string_filter.GetState()) {
874 this->display_list.push_back(&it);
875 } else if (&it == this->selected) {
876 /* The selected element has been filtered out */
877 this->selected = nullptr;
878 this->OnInvalidateData(SLIWD_SELECTION_CHANGES);
879 }
880 }
881 }
882
883 this->vscroll->SetCount(this->display_list.size());
884 }
885
891 void OnInvalidateData(int data = 0, bool gui_scope = true) override
892 {
893 switch (data) {
894 case SLIWD_RESCAN_FILES:
895 /* Rescan files */
896 this->selected = nullptr;
897 _load_check_data.Clear();
898 if (!gui_scope) break;
899
900 _fios_path_changed = true;
901 this->fios_items.BuildFileList(this->abstract_filetype, this->fop, true);
902 this->selected = nullptr;
903 _load_check_data.Clear();
904
905 /* We reset the files filtered */
906 this->OnInvalidateData(SLIWD_FILTER_CHANGES);
907
908 [[fallthrough]];
909
910 case SLIWD_SELECTION_CHANGES:
911 /* Selection changes */
912 if (!gui_scope) break;
913
914 if (this->fop == SLO_SAVE) this->SetWidgetDisabledState(WID_SL_DELETE_SELECTION, this->selected == nullptr);
915
916 if (this->fop != SLO_LOAD) break;
917
918 switch (this->abstract_filetype) {
919 case FT_HEIGHTMAP:
920 case FT_TOWN_DATA:
921 this->SetWidgetDisabledState(WID_SL_LOAD_BUTTON, this->selected == nullptr || _load_check_data.HasErrors());
922 break;
923
924 case FT_SAVEGAME:
925 case FT_SCENARIO: {
926 bool disabled = this->selected == nullptr || _load_check_data.HasErrors();
927 if (!_settings_client.gui.UserIsAllowedToChangeNewGRFs()) {
928 disabled |= _load_check_data.HasNewGrfs() && _load_check_data.grf_compatibility == GLC_NOT_FOUND;
929 }
930 this->SetWidgetDisabledState(WID_SL_LOAD_BUTTON, disabled);
931 this->SetWidgetDisabledState(WID_SL_NEWGRF_INFO, !_load_check_data.HasNewGrfs());
932 this->SetWidgetDisabledState(WID_SL_MISSING_NEWGRFS,
933 !_load_check_data.HasNewGrfs() || _load_check_data.grf_compatibility == GLC_ALL_GOOD);
934 break;
935 }
936
937 default:
938 NOT_REACHED();
939 }
940 break;
941
942 case SLIWD_FILTER_CHANGES:
943 this->BuildDisplayList();
944 break;
945 }
946 }
947
948 void OnEditboxChanged(WidgetID wid) override
949 {
950 if (wid == WID_SL_FILTER) {
951 this->string_filter.SetFilterTerm(this->filter_editbox.text.GetText());
952 this->InvalidateData(SLIWD_FILTER_CHANGES);
953 }
954
955 if (wid == WID_SL_SAVE_OSK_TITLE) {
956 this->selected = nullptr;
957 this->InvalidateData(SLIWD_SELECTION_CHANGES);
958 }
959 }
960};
961
963 static WindowDesc _load_dialog_desc(
964 WDP_CENTER, "load_game", 500, 294,
965 WC_SAVELOAD, WC_NONE,
966 {},
967 _nested_load_dialog_widgets
968);
969
971 static WindowDesc _load_heightmap_dialog_desc(
972 WDP_CENTER, "load_heightmap", 257, 320,
973 WC_SAVELOAD, WC_NONE,
974 {},
975 _nested_load_heightmap_dialog_widgets
976);
977
979 static WindowDesc _load_town_data_dialog_desc(
980 WDP_CENTER, "load_town_data", 257, 320,
981 WC_SAVELOAD, WC_NONE,
982 {},
983 _nested_load_town_data_dialog_widgets
984);
985
987 static WindowDesc _save_dialog_desc(
988 WDP_CENTER, "save_game", 500, 294,
989 WC_SAVELOAD, WC_NONE,
990 {},
991 _nested_save_dialog_widgets
992);
993
999 void ShowSaveLoadDialog(AbstractFileType abstract_filetype, SaveLoadOperation fop)
1000{
1001 CloseWindowById(WC_SAVELOAD, 0);
1002
1003 if (fop == SLO_SAVE) {
1004 new SaveLoadWindow(_save_dialog_desc, abstract_filetype, fop);
1005 } else {
1006 /* Dialogue for loading a file. */
1007 switch (abstract_filetype) {
1008 case FT_HEIGHTMAP:
1009 new SaveLoadWindow(_load_heightmap_dialog_desc, abstract_filetype, fop);
1010 break;
1011
1012 case FT_TOWN_DATA:
1013 new SaveLoadWindow(_load_town_data_dialog_desc, abstract_filetype, fop);
1014 break;
1015
1016 default:
1017 new SaveLoadWindow(_load_dialog_desc, abstract_filetype, fop);
1018 }
1019 }
1020}
EncodedString::GetDecodedString
std::string GetDecodedString() const
Decode the encoded string.
Definition strings.cpp:207
FileList
List of file information.
Definition fios.h:87
FileList::BuildFileList
void BuildFileList(AbstractFileType abstract_filetype, SaveLoadOperation fop, bool show_dirs)
Construct a file list with the given kind of files, for the stated purpose.
Definition fios.cpp:67
Gamelog::Reset
void Reset()
Resets and frees all memory allocated - used before loading or starting a new game.
Definition gamelog.cpp:94
Scrollbar
Scrollbar data structure.
Definition widget_type.h:708
Scrollbar::SetCount
void SetCount(size_t num)
Sets the number of elements in the list.
Definition widget_type.h:792
Scrollbar::GetScrolledItemFromWidget
auto GetScrolledItemFromWidget(Tcontainer &container, int clickpos, const Window *const w, WidgetID widget, int padding=0, int line_height=-1) const
Return an iterator pointing to the element of a scrolled widget that a user clicked in.
Definition widget_type.h:891
Scrollbar::SetCapacityFromWidget
void SetCapacityFromWidget(Window *w, WidgetID widget, int padding=0)
Set capacity of visible elements from the size and resize properties of a widget.
Definition widget.cpp:2499
Scrollbar::GetVisibleRangeIterators
auto GetVisibleRangeIterators(Tcontainer &container) const
Get a pair of iterators for the range of visible elements in a container.
Definition widget_type.h:872
TimerGameCalendar::ConvertYMDToDate
static Date ConvertYMDToDate(Year year, Month month, Day day)
Converts a tuple of Year, Month and Day to a Date.
Definition timer_game_calendar.cpp:55
TimerGameConst< struct Calendar >::MIN_DATE
static constexpr TimerGame< struct Calendar >::Date MIN_DATE
The date on January 1, year 0.
Definition timer_game_common.h:190
WidgetDimensions::framerect
RectPadding framerect
Standard padding inside many panels.
Definition window_gui.h:40
WidgetDimensions::frametext
RectPadding frametext
Padding inside frame with text.
Definition window_gui.h:41
WidgetDimensions::scaled
static WidgetDimensions scaled
Widget dimensions scaled for current zoom level.
Definition window_gui.h:30
WidgetDimensions::vsep_normal
int vsep_normal
Normal vertical spacing.
Definition window_gui.h:58
WidgetDimensions::vsep_wide
int vsep_wide
Wide vertical spacing.
Definition window_gui.h:60
WidgetDimensions::inset
RectPadding inset
Padding inside inset container.
Definition window_gui.h:35
WidgetDimensions::unscaled
static const WidgetDimensions unscaled
Unscaled widget dimensions.
Definition window_gui.h:93
WidgetDimensions::bevel
RectPadding bevel
Bevel thickness, affected by "scaled bevels" game option.
Definition window_gui.h:38
command_func.h
Functions related to commands.
StartupEngines
void StartupEngines()
Start/initialise all our engines.
Definition engine.cpp:798
engine_func.h
Functions related to engines.
to_underlying
constexpr std::underlying_type_t< enum_type > to_underlying(enum_type e)
Implementation of std::to_underlying (from C++23)
Definition enum_type.hpp:17
error.h
Functions related to errors.
ClearErrorMessages
void ClearErrorMessages()
Clear all errors from the queue.
Definition error_gui.cpp:251
WL_ERROR
@ WL_ERROR
Errors (eg. saving/loading failed)
Definition error.h:26
ShowErrorMessage
void ShowErrorMessage(EncodedString &&summary_msg, int x, int y, CommandCost &cc)
Display an error message in a window.
Definition error_gui.cpp:290
FioRemove
bool FioRemove(const std::string &filename)
Remove a file.
Definition fileio.cpp:327
_personal_dir
std::string _personal_dir
custom directory for personal settings, saves, newgrf, etc.
Definition fileio.cpp:871
FioCheckFileExists
bool FioCheckFileExists(std::string_view filename, Subdirectory subdir)
Check whether the given file exists.
Definition fileio.cpp:121
fileio_func.h
Functions for Standard In/Out file operations.
SaveLoadOperation
SaveLoadOperation
Operation performed on the file.
Definition fileio_type.h:52
SLO_CHECK
@ SLO_CHECK
Load file for checking and/or preview.
Definition fileio_type.h:53
SLO_SAVE
@ SLO_SAVE
File is being saved.
Definition fileio_type.h:55
SLO_LOAD
@ SLO_LOAD
File is being loaded.
Definition fileio_type.h:54
DFT_FIOS_DRIVE
@ DFT_FIOS_DRIVE
A drive (letter) entry.
Definition fileio_type.h:41
DFT_GAME_FILE
@ DFT_GAME_FILE
Save game or scenario file.
Definition fileio_type.h:31
DFT_FIOS_DIR
@ DFT_FIOS_DIR
A directory entry.
Definition fileio_type.h:43
DFT_FIOS_PARENT
@ DFT_FIOS_PARENT
A parent directory entry.
Definition fileio_type.h:42
DFT_END
@ DFT_END
End of this enum. Supports a compile time size check against _fios_colours in fios_gui....
Definition fileio_type.h:46
NO_DIRECTORY
@ NO_DIRECTORY
A path without any base directory.
Definition fileio_type.h:107
SCENARIO_DIR
@ SCENARIO_DIR
Base directory for all scenarios.
Definition fileio_type.h:92
SAVE_DIR
@ SAVE_DIR
Base directory for all savegames.
Definition fileio_type.h:90
HEIGHTMAP_DIR
@ HEIGHTMAP_DIR
Subdirectory of scenario for heightmaps.
Definition fileio_type.h:93
AbstractFileType
AbstractFileType
The different abstract types of files that the system knows about.
Definition fileio_type.h:17
FT_SCENARIO
@ FT_SCENARIO
old or new scenario
Definition fileio_type.h:20
FT_HEIGHTMAP
@ FT_HEIGHTMAP
heightmap file
Definition fileio_type.h:21
FT_SAVEGAME
@ FT_SAVEGAME
old or new savegame
Definition fileio_type.h:19
FT_TOWN_DATA
@ FT_TOWN_DATA
town data file
Definition fileio_type.h:22
FiosMakeSavegameName
std::string FiosMakeSavegameName(std::string_view name)
Make a save game or scenario filename from a name.
Definition fios.cpp:216
FiosGetCurrentPath
std::string FiosGetCurrentPath()
Get the current path/working directory.
Definition fios.cpp:132
FiosMakeHeightmapName
std::string FiosMakeHeightmapName(std::string_view name)
Construct a filename for a height map.
Definition fios.cpp:228
FiosBrowseTo
bool FiosBrowseTo(const FiosItem *item)
Browse to a new path based on the passed item, starting at _fios_path.
Definition fios.cpp:142
fios.h
Declarations for savegames operations.
SLIWD_FILTER_CHANGES
@ SLIWD_FILTER_CHANGES
The filename filter has changed (via the editbox)
Definition fios.h:25
SLIWD_SELECTION_CHANGES
@ SLIWD_SELECTION_CHANGES
File selection has changed (user click, ...)
Definition fios.h:24
SLIWD_RESCAN_FILES
@ SLIWD_RESCAN_FILES
Rescan all files (when changed directory, ...)
Definition fios.h:23
ShowSaveLoadDialog
void ShowSaveLoadDialog(AbstractFileType abstract_filetype, SaveLoadOperation fop)
Launch save/load dialog in the given mode.
Definition fios_gui.cpp:999
_load_town_data_dialog_desc
static WindowDesc _load_town_data_dialog_desc(WDP_CENTER, "load_town_data", 257, 320, WC_SAVELOAD, WC_NONE, {}, _nested_load_town_data_dialog_widgets)
Load town data.
_nested_save_dialog_widgets
static constexpr std::initializer_list< NWidgetPart > _nested_save_dialog_widgets
Save game/scenario.
Definition fios_gui.cpp:220
_nested_load_heightmap_dialog_widgets
static constexpr std::initializer_list< NWidgetPart > _nested_load_heightmap_dialog_widgets
Load heightmap with content download.
Definition fios_gui.cpp:131
_nested_load_dialog_widgets
static constexpr std::initializer_list< NWidgetPart > _nested_load_dialog_widgets
Load game/scenario with optional content download.
Definition fios_gui.cpp:68
_load_heightmap_dialog_desc
static WindowDesc _load_heightmap_dialog_desc(WDP_CENTER, "load_heightmap", 257, 320, WC_SAVELOAD, WC_NONE, {}, _nested_load_heightmap_dialog_widgets)
Load heightmap.
_load_dialog_desc
static WindowDesc _load_dialog_desc(WDP_CENTER, "load_game", 500, 294, WC_SAVELOAD, WC_NONE, {}, _nested_load_dialog_widgets)
Load game/scenario.
_save_dialog_desc
static WindowDesc _save_dialog_desc(WDP_CENTER, "save_game", 500, 294, WC_SAVELOAD, WC_NONE, {}, _nested_save_dialog_widgets)
Save game/scenario.
_nested_load_town_data_dialog_widgets
static constexpr std::initializer_list< NWidgetPart > _nested_load_town_data_dialog_widgets
Load town data.
Definition fios_gui.cpp:178
_load_check_data
LoadCheckData _load_check_data
Data loaded from save during SL_LOAD_CHECK.
Definition fios_gui.cpp:41
_fios_colours
static const TextColour _fios_colours[]
Text colours of DetailedFileType fios entries in the window.
Definition fios_gui.cpp:284
SortSaveGameList
static void SortSaveGameList(FileList &file_list)
Sort the collected list save games prior to displaying it in the save/load gui.
Definition fios_gui.cpp:302
fios_widget.h
Types related to the fios widgets.
WID_SL_SORT_BYDATE
@ WID_SL_SORT_BYDATE
Sort by date button.
Definition fios_widget.h:17
WID_SL_SAVE_GAME
@ WID_SL_SAVE_GAME
Save button, only available for save operations.
Definition fios_widget.h:27
WID_SL_BACKGROUND
@ WID_SL_BACKGROUND
Background of window.
Definition fios_widget.h:19
WID_SL_SAVE_OSK_TITLE
@ WID_SL_SAVE_OSK_TITLE
Title textbox, only available for save operations.
Definition fios_widget.h:25
WID_SL_DELETE_SELECTION
@ WID_SL_DELETE_SELECTION
Delete button, only available for save operations.
Definition fios_widget.h:26
WID_SL_DETAILS
@ WID_SL_DETAILS
Panel with game details.
Definition fios_widget.h:29
WID_SL_FILE_BACKGROUND
@ WID_SL_FILE_BACKGROUND
Background of file selection.
Definition fios_widget.h:20
WID_SL_NEWGRF_INFO
@ WID_SL_NEWGRF_INFO
Button to open NewGgrf configuration.
Definition fios_widget.h:30
WID_SL_DRIVES_DIRECTORIES_LIST
@ WID_SL_DRIVES_DIRECTORIES_LIST
Drives list.
Definition fios_widget.h:22
WID_SL_LOAD_BUTTON
@ WID_SL_LOAD_BUTTON
Button to load game/scenario.
Definition fios_widget.h:31
WID_SL_FILTER
@ WID_SL_FILTER
Filter list of files.
Definition fios_widget.h:18
WID_SL_SCROLLBAR
@ WID_SL_SCROLLBAR
Scrollbar of the file list.
Definition fios_widget.h:23
WID_SL_CAPTION
@ WID_SL_CAPTION
Caption of the window.
Definition fios_widget.h:15
WID_SL_HOME_BUTTON
@ WID_SL_HOME_BUTTON
Home button.
Definition fios_widget.h:21
WID_SL_SORT_BYNAME
@ WID_SL_SORT_BYNAME
Sort by name button.
Definition fios_widget.h:16
WID_SL_MISSING_NEWGRFS
@ WID_SL_MISSING_NEWGRFS
Button to find missing NewGRFs online.
Definition fios_widget.h:32
WID_SL_CONTENT_DOWNLOAD_SEL
@ WID_SL_CONTENT_DOWNLOAD_SEL
Selection 'stack' to 'hide' the content download.
Definition fios_widget.h:28
WID_SL_CONTENT_DOWNLOAD
@ WID_SL_CONTENT_DOWNLOAD
Content download button, only available for play scenario/heightmap.
Definition fios_widget.h:24
GetCharacterHeight
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
Definition fontcache.cpp:87
gamelog.h
Functions to be called to log fundamental changes to the game.
gamelog_internal.h
Declaration shared among gamelog.cpp and saveload/gamelog_sl.cpp.
LoadTownData
void LoadTownData()
Load town data from _file_to_saveload, place towns at the appropriate locations, and expand them to t...
Definition genworld.cpp:359
genworld.h
Functions related to world/map generation.
ShowHeightmapLoad
void ShowHeightmapLoad()
Start with loading a heightmap.
Definition genworld_gui.cpp:1047
maxdim
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
Definition geometry_func.cpp:22
geometry_func.hpp
Geometry functions.
GetStringBoundingBox
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition gfx.cpp:894
DrawString
int DrawString(int left, int right, int top, std::string_view str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
Definition gfx.cpp:665
DrawStringMultiLine
int DrawStringMultiLine(int left, int right, int top, int bottom, std::string_view str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly over multiple lines.
Definition gfx.cpp:782
GfxFillRect
void GfxFillRect(int left, int top, int right, int bottom, const std::variant< PixelColour, PaletteID > &colour, FillRectMode mode)
Applies a certain FillRectMode-operation to a rectangle [left, right] x [top, bottom] on the screen.
Definition gfx.cpp:115
_switch_mode
SwitchMode _switch_mode
The next mainloop command.
Definition gfx.cpp:49
gfx_func.h
Functions related to the gfx engine.
FS_NORMAL
@ FS_NORMAL
Index of the normal font in the font tables.
Definition gfx_type.h:249
SA_HOR_CENTER
@ SA_HOR_CENTER
Horizontally center the text.
Definition gfx_type.h:389
TextColour
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Definition gfx_type.h:307
SetFill
constexpr NWidgetPart SetFill(uint16_t fill_x, uint16_t fill_y)
Widget part function for setting filling.
Definition widget_type.h:1219
SetSpriteTip
constexpr NWidgetPart SetSpriteTip(SpriteID sprite, StringID tip={})
Widget part function for setting the sprite and tooltip.
Definition widget_type.h:1251
SetPIP
constexpr NWidgetPart SetPIP(uint8_t pre, uint8_t inter, uint8_t post)
Widget part function for setting a pre/inter/post spaces.
Definition widget_type.h:1375
SetScrollbar
constexpr NWidgetPart SetScrollbar(WidgetID index)
Attach a scrollbar to a widget.
Definition widget_type.h:1399
SetPadding
constexpr NWidgetPart SetPadding(uint8_t top, uint8_t right, uint8_t bottom, uint8_t left)
Widget part function for setting additional space around a widget.
Definition widget_type.h:1332
SetStringTip
constexpr NWidgetPart SetStringTip(StringID string, StringID tip={})
Widget part function for setting the string and tooltip.
Definition widget_type.h:1240
SetAspect
constexpr NWidgetPart SetAspect(float ratio, AspectFlags flags=AspectFlag::ResizeX)
Widget part function for setting the aspect ratio.
Definition widget_type.h:1410
SetToolTip
constexpr NWidgetPart SetToolTip(StringID tip)
Widget part function for setting tooltip and clearing the widget data.
Definition widget_type.h:1318
EndContainer
constexpr NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition widget_type.h:1229
NWidget
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=INVALID_WIDGET)
Widget part function for starting a new 'real' widget.
Definition widget_type.h:1424
SetResize
constexpr NWidgetPart SetResize(int16_t dx, int16_t dy)
Widget part function for setting the resize step.
Definition widget_type.h:1145
Window::SetDirty
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition window.cpp:966
gui.h
GUI functions that shouldn't be here.
landscape_type.h
Types related to the landscape.
misc_cmd.h
Miscellaneous command definitions.
ShowQuery
void ShowQuery(EncodedString &&caption, EncodedString &&message, Window *parent, QueryCallbackProc *callback, bool focus)
Show a confirmation window with standard 'yes' and 'no' buttons The window is aligned to the centre o...
Definition misc_gui.cpp:1202
_network_available
bool _network_available
is network mode available?
Definition network.cpp:68
_networking
bool _networking
are we in networking mode?
Definition network.cpp:66
network.h
Basic functions/variables used all over the place.
network_content.h
Part of the network protocol handling content distribution.
ShowNetworkContentListWindow
void ShowNetworkContentListWindow(ContentVector *cv=nullptr, ContentType type1=CONTENT_TYPE_END, ContentType type2=CONTENT_TYPE_END)
Show the content list window with a given set of content.
Definition network_content_gui.cpp:1117
ShowMissingContentWindow
void ShowMissingContentWindow(const GRFConfigList &list)
Show the content list window with all missing grfs from the given list.
Definition newgrf_gui.cpp:1503
ClearGRFConfigList
void ClearGRFConfigList(GRFConfigList &config)
Clear a GRF Config list, freeing all nodes.
Definition newgrf_config.cpp:324
GLC_ALL_GOOD
@ GLC_ALL_GOOD
All GRF needed by game are present.
Definition newgrf_config.h:53
GLC_NOT_FOUND
@ GLC_NOT_FOUND
At least one GRF couldn't be found (higher priority than GLC_COMPATIBLE)
Definition newgrf_config.h:55
ShowNewGRFSettings
void ShowNewGRFSettings(bool editable, bool show_params, bool exec_changes, GRFConfigList &config)
Setup the NewGRF gui.
Definition newgrf_gui.cpp:1966
PauseMode::SaveLoad
@ SaveLoad
A game paused for saving/loading.
SM_LOAD_SCENARIO
@ SM_LOAD_SCENARIO
Load scenario from scenario editor.
Definition openttd.h:37
SM_SAVE_HEIGHTMAP
@ SM_SAVE_HEIGHTMAP
Save heightmap.
Definition openttd.h:35
SM_SAVE_GAME
@ SM_SAVE_GAME
Save game.
Definition openttd.h:34
SM_LOAD_GAME
@ SM_LOAD_GAME
Load game, Play Scenario.
Definition openttd.h:32
GetColourGradient
PixelColour GetColourGradient(Colours colour, ColourShade shade)
Get colour gradient palette index.
Definition palette.cpp:388
PC_DARK_BLUE
static constexpr PixelColour PC_DARK_BLUE
Dark blue palette colour.
Definition palette_func.h:116
PC_BLACK
static constexpr PixelColour PC_BLACK
Black palette colour.
Definition palette_func.h:96
PC_VERY_DARK_BLUE
static constexpr PixelColour PC_VERY_DARK_BLUE
Almost-black blue palette colour.
Definition palette_func.h:115
querystring_gui.h
Base for the GUIs that have an edit box in them.
safeguards.h
A number of safeguards to prevent using unsafe methods.
SaveOrLoad
SaveOrLoadResult SaveOrLoad(std::string_view filename, SaveLoadOperation fop, DetailedFileType dft, Subdirectory sb, bool threaded)
Main Save or Load function where the high-level saveload functions are handled.
Definition saveload.cpp:3258
_file_to_saveload
FileToSaveLoad _file_to_saveload
File to save or load in the openttd loop.
Definition saveload.cpp:78
GenerateDefaultSaveName
std::string GenerateDefaultSaveName()
Get the default name for a savegame or screenshot.
Definition saveload.cpp:3375
saveload.h
Functions/types related to saving and loading games.
_settings_client
ClientSettings _settings_client
The current settings for this game.
Definition settings.cpp:60
sprites.h
This file contains all sprite-related enums and defines.
stdafx.h
Definition of base types and functions in a cross-platform compatible way.
stringfilter_type.h
Searching and filtering using a stringterm.
GetEncodedString
EncodedString GetEncodedString(StringID str)
Encode a string with no parameters into an encoded string.
Definition strings.cpp:90
GetString
std::string GetString(StringID string)
Resolve the given StringID into a std::string with formatting but no parameters.
Definition strings.cpp:424
strings_func.h
Functions related to OTTD's strings.
StringID
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Definition strings_type.h:19
INVALID_STRING_ID
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
Definition strings_type.h:20
ClientSettings::gui
GUISettings gui
settings related to the GUI
Definition settings_type.h:650
CommandHelper
Definition command_func.h:83
CompanyProperties
Statically loadable part of Company pool item.
Definition company_base.h:71
CompanyProperties::name_2
uint32_t name_2
Parameter of name_1.
Definition company_base.h:72
CompanyProperties::name_1
StringID name_1
Name of the company if the user did not change it.
Definition company_base.h:73
CompanyProperties::name
std::string name
Name of the company if the user changed it.
Definition company_base.h:74
Coord2D< int >
Dimension
Dimensions (a width and height) of a rectangle in 2D.
Definition geometry_type.hpp:56
FileToSaveLoad::name
std::string name
Name of the file.
Definition saveload.h:430
FileToSaveLoad::Set
void Set(const FiosItem &item)
Set the title of the file.
Definition saveload.cpp:3437
FiosItem
Deals with finding savegames.
Definition fios.h:78
FiosType::detailed
DetailedFileType detailed
Detailed file type.
Definition fileio_type.h:65
GUISettings::UserIsAllowedToChangeNewGRFs
bool UserIsAllowedToChangeNewGRFs() const
Returns true when the user has sufficient privileges to edit newgrfs on a running game.
Definition settings_type.h:264
LoadCheckData
Container for loading in mode SL_LOAD_CHECK.
Definition fios.h:33
LoadCheckData::checkable
bool checkable
True if the savegame could be checked by SL_LOAD_CHECK. (Old savegames are not checkable....
Definition fios.h:34
LoadCheckData::HasNewGrfs
bool HasNewGrfs()
Check whether the game uses any NewGrfs.
Definition fios.h:67
LoadCheckData::error_msg
std::string error_msg
Data to pass to string parameters when displaying error.
Definition fios.h:36
LoadCheckData::starting_year
TimerGameCalendar::Year starting_year
Starting date.
Definition fios.h:43
LoadCheckData::companies
CompanyPropertiesMap companies
Company information.
Definition fios.h:45
LoadCheckData::error
StringID error
Error message from loading. INVALID_STRING_ID if no error.
Definition fios.h:35
LoadCheckData::gamelog
Gamelog gamelog
Gamelog actions.
Definition fios.h:50
LoadCheckData::HasErrors
bool HasErrors()
Check whether loading the game resulted in errors.
Definition fios.h:58
LoadCheckData::Clear
void Clear()
Reset read data.
Definition fios_gui.cpp:49
LoadCheckData::grf_compatibility
GRFListCompatibility grf_compatibility
Summary state of NewGrfs, whether missing files or only compatible found.
Definition fios.h:48
LoadCheckData::landscape
LandscapeType landscape
Landscape type.
Definition fios.h:42
LoadCheckData::grfconfig
GRFConfigList grfconfig
NewGrf configuration from save.
Definition fios.h:47
QueryString
Data stored about a string that can be modified in the GUI.
Definition querystring_gui.h:20
QueryString::ok_button
int ok_button
Widget button of parent window to simulate when pressing OK in OSK.
Definition querystring_gui.h:27
QueryString::cancel_button
int cancel_button
Widget button of parent window to simulate when pressing CANCEL in OSK.
Definition querystring_gui.h:28
QueryString::ACTION_CLEAR
static const int ACTION_CLEAR
Clear editbox.
Definition querystring_gui.h:24
RectPadding::Vertical
constexpr uint Vertical() const
Get total vertical padding of RectPadding.
Definition geometry_type.hpp:95
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition geometry_type.hpp:101
Rect::Shrink
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
Definition geometry_type.hpp:124
Rect::WithHeight
Rect WithHeight(int height, bool end=false) const
Copy Rect and set its height.
Definition geometry_type.hpp:237
Rect::WithY
Rect WithY(int new_top, int new_bottom) const
Create a new Rect, replacing the top and bottom coordiates.
Definition geometry_type.hpp:280
Rect::Translate
Rect Translate(int x, int y) const
Copy and translate Rect by x,y pixels.
Definition geometry_type.hpp:200
ResizeInfo::step_height
uint step_height
Step-size of height resize changes.
Definition window_gui.h:213
SaveLoadWindow
Definition fios_gui.cpp:323
SaveLoadWindow::OnTimeout
void OnTimeout() override
Called when this window's timeout has been reached.
Definition fios_gui.cpp:820
SaveLoadWindow::OnClick
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition fios_gui.cpp:666
SaveLoadWindow::highlighted
const FiosItem * highlighted
Item in fios_items highlighted by mouse pointer, or nullptr.
Definition fios_gui.cpp:333
SaveLoadWindow::filter_editbox
QueryString filter_editbox
Filter editbox;.
Definition fios_gui.cpp:337
SaveLoadWindow::GenerateFileName
void GenerateFileName()
Generate a default save filename.
Definition fios_gui.cpp:372
SaveLoadWindow::string_filter
StringFilter string_filter
Filter for available items.
Definition fios_gui.cpp:336
SaveLoadWindow::OnInvalidateData
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition fios_gui.cpp:891
SaveLoadWindow::display_list
std::vector< FiosItem * > display_list
Filtered display list.
Definition fios_gui.cpp:338
SaveLoadWindow::OnMouseOver
void OnMouseOver(Point pt, WidgetID widget) override
The mouse is currently moving over the window or has just moved outside of the window.
Definition fios_gui.cpp:791
SaveLoadWindow::Close
void Close(int data=0) override
Hide the window and all its child windows, and mark them for a later deletion.
Definition fios_gui.cpp:480
SaveLoadWindow::UpdateWidgetSize
void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override
Update size and resize step of a widget in the window.
Definition fios_gui.cpp:633
SaveLoadWindow::OnResize
void OnResize() override
Called after the window got resized.
Definition fios_gui.cpp:852
SaveLoadWindow::fop
SaveLoadOperation fop
Type of file to select.
Definition fios_gui.cpp:329
SaveLoadWindow::fios_items
FileList fios_items
Item list.
Definition fios_gui.cpp:330
SaveLoadWindow::filename_editbox
QueryString filename_editbox
Filename editbox.
Definition fios_gui.cpp:327
SaveLoadWindow::OnPaint
void OnPaint() override
The window must be repainted.
Definition fios_gui.cpp:655
SaveLoadWindow::DrawWidget
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
Definition fios_gui.cpp:489
SaveLoadWindow::selected
const FiosItem * selected
Selected item in fios_items, or nullptr.
Definition fios_gui.cpp:332
SaveLoadWindow::o_dir
FiosItem o_dir
Original dir (home dir for this browser)
Definition fios_gui.cpp:331
SaveLoadWindow::OnKeyPress
EventState OnKeyPress(char32_t key, uint16_t keycode) override
A key has been pressed.
Definition fios_gui.cpp:810
SaveLoadWindow::OnEditboxChanged
void OnEditboxChanged(WidgetID wid) override
The text in an editbox has been edited.
Definition fios_gui.cpp:948
StringFilter
String filter and state.
Definition stringfilter_type.h:30
StringFilter::IsEmpty
bool IsEmpty() const
Check whether any filter words were entered.
Definition stringfilter_type.h:57
StringFilter::SetFilterTerm
void SetFilterTerm(std::string_view str)
Set the term to filter on.
Definition stringfilter.cpp:29
StringFilter::ResetState
void ResetState()
Reset the matching state to process a new item.
Definition stringfilter.cpp:80
StringFilter::GetState
bool GetState() const
Get the matching state of the current item.
Definition stringfilter_type.h:67
Textbuf::GetText
std::string_view GetText() const
Get the current text.
Definition textbuf.cpp:284
Textbuf::Assign
void Assign(std::string_view text)
Copy a string into the textbuffer.
Definition textbuf.cpp:420
WindowDesc
High level window description.
Definition window_gui.h:168
Window
Data structure for an opened window.
Definition window_gui.h:274
Window::Close
virtual void Close(int data=0)
Hide the window and all its child windows, and mark them for a later deletion.
Definition window.cpp:1102
Window::SortButtonWidth
static int SortButtonWidth()
Get width of up/down arrow of sort button state.
Definition widget.cpp:815
Window::FinishInitNested
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Definition window.cpp:1807
Window::querystrings
std::map< WidgetID, QueryString * > querystrings
QueryString associated to WWT_EDITBOX widgets.
Definition window_gui.h:321
Window::DrawWidgets
void DrawWidgets() const
Paint all widgets of a window.
Definition widget.cpp:766
Window::InvalidateData
void InvalidateData(int data=0, bool gui_scope=true)
Mark this window's data as invalid (in need of re-computing)
Definition window.cpp:3234
Window::SetWidgetDirty
void SetWidgetDirty(WidgetID widget_index) const
Invalidate a widget, i.e.
Definition window.cpp:556
Window::DrawSortButtonState
void DrawSortButtonState(WidgetID widget, SortButtonState state) const
Draw a sort button's up or down arrow symbol.
Definition widget.cpp:798
Window::resize
ResizeInfo resize
Resize information.
Definition window_gui.h:315
Window::CreateNestedTree
void CreateNestedTree()
Perform the first part of the initialization of a nested widget tree.
Definition window.cpp:1797
Window::SetFocusedWidget
bool SetFocusedWidget(WidgetID widget_index)
Set focus within this window to the given widget.
Definition window.cpp:485
Window::IsWidgetLowered
bool IsWidgetLowered(WidgetID widget_index) const
Gets the lowered state of a widget.
Definition window_gui.h:492
Window::LowerWidget
void LowerWidget(WidgetID widget_index)
Marks a widget as lowered.
Definition window_gui.h:461
Window::HandleButtonClick
void HandleButtonClick(WidgetID widget)
Do all things to make a button look clicked and mark it to be unclicked in a few ticks.
Definition window.cpp:595
Window::GetScrollbar
const Scrollbar * GetScrollbar(WidgetID widnum) const
Return the Scrollbar to a widget index.
Definition window.cpp:313
Window::SetWidgetDisabledState
void SetWidgetDisabledState(WidgetID widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
Definition window_gui.h:382
CONTENT_TYPE_SCENARIO
@ CONTENT_TYPE_SCENARIO
The content consists of a scenario.
Definition tcp_content_type.h:27
CONTENT_TYPE_HEIGHTMAP
@ CONTENT_TYPE_HEIGHTMAP
The content consists of a heightmap.
Definition tcp_content_type.h:28
tilehighlight_func.h
Functions related to tile highlights.
ResetObjectToPlace
void ResetObjectToPlace()
Reset the cursor and mouse mode handling back to default (normal cursor, only clicking in windows).
Definition viewport.cpp:3573
SetObjectToPlace
void SetObjectToPlace(CursorID icon, PaletteID pal, HighLightStyle mode, WindowClass window_class, WindowNumber window_num)
Change the cursor and mouse click/drag handling to a mode for performing special operations like tile...
Definition viewport.cpp:3525
HT_NONE
@ HT_NONE
default
Definition tilehighlight_type.h:20
timer_game_calendar.h
Definition of the game-calendar-timer.
WWT_PUSHTXTBTN
@ WWT_PUSHTXTBTN
Normal push-button (no toggle button) with text caption.
Definition widget_type.h:104
WWT_INSET
@ WWT_INSET
Pressed (inset) panel, most commonly used as combo box text area.
Definition widget_type.h:40
WWT_PUSHIMGBTN
@ WWT_PUSHIMGBTN
Normal push-button (no toggle button) with image caption.
Definition widget_type.h:105
WWT_EDITBOX
@ WWT_EDITBOX
a textbox for typing
Definition widget_type.h:62
NWID_HORIZONTAL
@ NWID_HORIZONTAL
Horizontal container.
Definition widget_type.h:66
WWT_PANEL
@ WWT_PANEL
Simple depressed panel.
Definition widget_type.h:39
WWT_CAPTION
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition widget_type.h:52
NWID_VSCROLLBAR
@ NWID_VSCROLLBAR
Vertical scrollbar.
Definition widget_type.h:76
NWID_VERTICAL
@ NWID_VERTICAL
Vertical container.
Definition widget_type.h:68
WWT_CLOSEBOX
@ WWT_CLOSEBOX
Close box (at top-left of a window)
Definition widget_type.h:60
WWT_RESIZEBOX
@ WWT_RESIZEBOX
Resize box (normally at bottom-right of a window)
Definition widget_type.h:59
WWT_DEFSIZEBOX
@ WWT_DEFSIZEBOX
Default window size box (at top-right of a window, between WWT_SHADEBOX and WWT_STICKYBOX)
Definition widget_type.h:56
WWT_TEXT
@ WWT_TEXT
Pure simple text.
Definition widget_type.h:49
NWID_SELECTION
@ NWID_SELECTION
Stacked widgets, only one visible at a time (eg in a panel with tabs).
Definition widget_type.h:71
SZSP_HORIZONTAL
@ SZSP_HORIZONTAL
Display plane with zero size vertically, and filling and resizing horizontally.
Definition widget_type.h:505
EqualSize
@ EqualSize
Containers should keep all their (resizing) children equally large.
Definition widget_type.h:541
CloseWindowById
void CloseWindowById(WindowClass cls, WindowNumber number, bool force, int data)
Close a window by its class and window number (if it is open).
Definition window.cpp:1193
window_func.h
Window functions not directly related to making/drawing windows.
SBS_DOWN
@ SBS_DOWN
Sort ascending.
Definition window_gui.h:219
SBS_UP
@ SBS_UP
Sort descending.
Definition window_gui.h:220
WDP_CENTER
@ WDP_CENTER
Center the window.
Definition window_gui.h:145
WidgetID
int WidgetID
Widget ID.
Definition window_type.h:20
EventState
EventState
State of handling an event.
Definition window_type.h:780
ES_HANDLED
@ ES_HANDLED
The passed event is handled.
Definition window_type.h:781
ES_NOT_HANDLED
@ ES_NOT_HANDLED
The passed event is not handled.
Definition window_type.h:782
WC_NONE
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition window_type.h:50
WC_MAIN_WINDOW
@ WC_MAIN_WINDOW
Main window; Window numbers:
Definition window_type.h:56
WC_SAVELOAD
@ WC_SAVELOAD
Saveload window; Window numbers:
Definition window_type.h:149