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