OpenTTD
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 "date_func.h"
27 #include "core/geometry_func.hpp"
28 #include "gamelog.h"
29 #include "stringfilter_type.h"
30 
31 #include "widgets/fios_widget.h"
32 
33 #include "table/sprites.h"
34 #include "table/strings.h"
35 
36 #include "safeguards.h"
37 
39 
40 static bool _fios_path_changed;
41 static bool _savegame_sort_dirty;
42 
43 
48 {
49  this->checkable = false;
50  this->error = INVALID_STRING_ID;
51  free(this->error_data);
52  this->error_data = nullptr;
53 
54  this->map_size_x = this->map_size_y = 256; // Default for old savegames which do not store mapsize.
55  this->current_date = 0;
56  memset(&this->settings, 0, sizeof(this->settings));
57 
58  for (auto &pair : this->companies) {
59  delete pair.second;
60  }
61  companies.clear();
62 
64  this->gamelog_action = nullptr;
65  this->gamelog_actions = 0;
66 
68 }
69 
73  NWidget(WWT_CLOSEBOX, COLOUR_GREY),
74  NWidget(WWT_CAPTION, COLOUR_GREY, WID_SL_CAPTION),
75  NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
76  EndContainer(),
77  /* Current directory and free space */
78  NWidget(WWT_PANEL, COLOUR_GREY, WID_SL_BACKGROUND), SetFill(1, 0), SetResize(1, 0), EndContainer(),
79 
81  /* Left side : filter box and available files */
82  NWidget(WWT_PANEL, COLOUR_GREY), SetFill(1, 1), SetResize(1, 1),
83  /* Filter box with label */
86  NWidget(WWT_TEXT, COLOUR_GREY), SetFill(0, 1), SetDataTip(STR_SAVELOAD_FILTER_TITLE , STR_NULL),
87  NWidget(WWT_EDITBOX, COLOUR_GREY, WID_SL_FILTER), SetFill(1, 0), SetMinimalSize(50, 12), SetResize(1, 0),
88  SetDataTip(STR_LIST_FILTER_OSKTITLE, STR_LIST_FILTER_TOOLTIP),
89  EndContainer(),
90  /* Sort buttons */
93  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),
94  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),
95  EndContainer(),
96  NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_SL_HOME_BUTTON), SetMinimalSize(12, 12), SetDataTip(SPR_HOUSE_ICON, STR_SAVELOAD_HOME_BUTTON),
97  EndContainer(),
98  /* Files */
101  NWidget(WWT_INSET, COLOUR_GREY, WID_SL_DRIVES_DIRECTORIES_LIST), SetFill(1, 1), SetPadding(2, 1, 2, 2),
102  SetDataTip(0x0, STR_SAVELOAD_LIST_TOOLTIP), SetResize(1, 10), SetScrollbar(WID_SL_SCROLLBAR), EndContainer(),
104  EndContainer(),
107  SetDataTip(STR_INTRO_ONLINE_CONTENT, STR_INTRO_TOOLTIP_ONLINE_CONTENT),
108  EndContainer(),
109  EndContainer(),
110  EndContainer(),
111 
112  /* Right side : game details */
113  NWidget(WWT_PANEL, COLOUR_GREY),
114  NWidget(WWT_EMPTY, INVALID_COLOUR, WID_SL_DETAILS), SetResize(1, 1), SetFill(1, 1),
115  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),
118  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SL_NEWGRF_INFO), SetDataTip(STR_INTRO_NEWGRF_SETTINGS, STR_NULL), SetFill(1, 0), SetResize(1, 0),
119  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SL_LOAD_BUTTON), SetDataTip(STR_SAVELOAD_LOAD_BUTTON, STR_SAVELOAD_LOAD_TOOLTIP), SetFill(1, 0), SetResize(1, 0),
120  EndContainer(),
121  NWidget(WWT_RESIZEBOX, COLOUR_GREY),
122  EndContainer(),
123  EndContainer(),
124  EndContainer(),
125 };
126 
130  NWidget(WWT_CLOSEBOX, COLOUR_GREY),
131  NWidget(WWT_CAPTION, COLOUR_GREY, WID_SL_CAPTION),
132  NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
133  EndContainer(),
134  /* Current directory and free space */
135  NWidget(WWT_PANEL, COLOUR_GREY, WID_SL_BACKGROUND), SetFill(1, 0), SetResize(1, 0), EndContainer(),
136 
137  NWidget(WWT_PANEL, COLOUR_GREY), SetFill(1, 1), SetResize(1, 1),
138  /* Filter box with label */
141  NWidget(WWT_TEXT, COLOUR_GREY), SetFill(0, 1), SetDataTip(STR_SAVELOAD_FILTER_TITLE , STR_NULL),
142  NWidget(WWT_EDITBOX, COLOUR_GREY, WID_SL_FILTER), SetFill(1, 0), SetMinimalSize(50, 12), SetResize(1, 0),
143  SetDataTip(STR_LIST_FILTER_OSKTITLE, STR_LIST_FILTER_TOOLTIP),
144  EndContainer(),
145  /* Sort Buttons */
148  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),
149  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),
150  EndContainer(),
151  NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_SL_HOME_BUTTON), SetMinimalSize(12, 12), SetDataTip(SPR_HOUSE_ICON, STR_SAVELOAD_HOME_BUTTON),
152  EndContainer(),
153  /* Files */
156  NWidget(WWT_INSET, COLOUR_GREY, WID_SL_DRIVES_DIRECTORIES_LIST), SetFill(1, 1), SetPadding(2, 1, 2, 2),
157  SetDataTip(0x0, STR_SAVELOAD_LIST_TOOLTIP), SetResize(1, 10), SetScrollbar(WID_SL_SCROLLBAR), EndContainer(),
159  EndContainer(),
161  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SL_CONTENT_DOWNLOAD), SetResize(1, 0), SetFill(1, 0),
162  SetDataTip(STR_INTRO_ONLINE_CONTENT, STR_INTRO_TOOLTIP_ONLINE_CONTENT),
163  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SL_LOAD_BUTTON), SetResize(1, 0), SetFill(1, 0),
164  SetDataTip(STR_SAVELOAD_LOAD_BUTTON, STR_SAVELOAD_LOAD_HEIGHTMAP_TOOLTIP),
165  NWidget(WWT_RESIZEBOX, COLOUR_GREY),
166  EndContainer(),
167  EndContainer(),
168  EndContainer(),
169 };
170 
174  NWidget(WWT_CLOSEBOX, COLOUR_GREY),
175  NWidget(WWT_CAPTION, COLOUR_GREY, WID_SL_CAPTION),
176  NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
177  EndContainer(),
178  /* Current directory and free space */
179  NWidget(WWT_PANEL, COLOUR_GREY, WID_SL_BACKGROUND), SetFill(1, 0), SetResize(1, 0), EndContainer(),
181  /* Left side : filter box and available files */
182  NWidget(WWT_PANEL, COLOUR_GREY), SetFill(1, 1), SetResize(1, 1),
183  /* Filter box with label */
186  NWidget(WWT_TEXT, COLOUR_GREY), SetFill(0, 1), SetDataTip(STR_SAVELOAD_FILTER_TITLE , STR_NULL),
187  NWidget(WWT_EDITBOX, COLOUR_GREY, WID_SL_FILTER), SetFill(1, 0), SetMinimalSize(50, 12), SetResize(1, 0),
188  SetDataTip(STR_LIST_FILTER_OSKTITLE, STR_LIST_FILTER_TOOLTIP),
189  EndContainer(),
190  /* Sort buttons */
193  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),
194  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),
195  EndContainer(),
196  NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_SL_HOME_BUTTON), SetMinimalSize(12, 12), SetDataTip(SPR_HOUSE_ICON, STR_SAVELOAD_HOME_BUTTON),
197  EndContainer(),
198  /* Files */
201  NWidget(WWT_INSET, COLOUR_GREY, WID_SL_DRIVES_DIRECTORIES_LIST), SetPadding(2, 1, 0, 2),
202  SetDataTip(0x0, STR_SAVELOAD_LIST_TOOLTIP), SetResize(1, 10), SetScrollbar(WID_SL_SCROLLBAR), EndContainer(),
204  EndContainer(),
205  NWidget(WWT_EDITBOX, COLOUR_GREY, WID_SL_SAVE_OSK_TITLE), SetPadding(3, 2, 2, 2), SetFill(1, 0), SetResize(1, 0),
206  SetDataTip(STR_SAVELOAD_OSKTITLE, STR_SAVELOAD_EDITBOX_TOOLTIP),
207  EndContainer(),
208  /* Save/delete buttons */
210  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SL_DELETE_SELECTION), SetDataTip(STR_SAVELOAD_DELETE_BUTTON, STR_SAVELOAD_DELETE_TOOLTIP), SetFill(1, 0), SetResize(1, 0),
211  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SL_SAVE_GAME), SetDataTip(STR_SAVELOAD_SAVE_BUTTON, STR_SAVELOAD_SAVE_TOOLTIP), SetFill(1, 0), SetResize(1, 0),
212  EndContainer(),
213  EndContainer(),
214 
215  /* Right side : game details */
216  NWidget(WWT_PANEL, COLOUR_GREY),
217  NWidget(WWT_EMPTY, INVALID_COLOUR, WID_SL_DETAILS), SetResize(1, 1), SetFill(1, 1),
219  NWidget(NWID_SPACER), SetResize(1, 0), SetFill(1, 1),
220  NWidget(WWT_RESIZEBOX, COLOUR_GREY),
221  EndContainer(),
222  EndContainer(),
223  EndContainer(),
224 };
225 
227 static const TextColour _fios_colours[] = {
228  TC_LIGHT_BROWN, // DFT_OLD_GAME_FILE
229  TC_ORANGE, // DFT_GAME_FILE
230  TC_YELLOW, // DFT_HEIGHTMAP_BMP
231  TC_ORANGE, // DFT_HEIGHTMAP_PNG
232  TC_LIGHT_BLUE, // DFT_FIOS_DRIVE
233  TC_DARK_GREEN, // DFT_FIOS_PARENT
234  TC_DARK_GREEN, // DFT_FIOS_DIR
235  TC_ORANGE, // DFT_FIOS_DIRECT
236 };
237 
238 
243 static void SortSaveGameList(FileList &file_list)
244 {
245  size_t sort_start = 0;
246  size_t sort_end = 0;
247 
248  /* Directories are always above the files (FIOS_TYPE_DIR)
249  * Drives (A:\ (windows only) are always under the files (FIOS_TYPE_DRIVE)
250  * Only sort savegames/scenarios, not directories
251  */
252  for (const FiosItem *item = file_list.Begin(); item != file_list.End(); item++) {
253  switch (item->type) {
254  case FIOS_TYPE_DIR: sort_start++; break;
255  case FIOS_TYPE_PARENT: sort_start++; break;
256  case FIOS_TYPE_DRIVE: sort_end++; break;
257  default: break;
258  }
259  }
260 
261  std::sort(file_list.files.begin() + sort_start, file_list.files.end() - sort_end);
262 }
263 
264 struct SaveLoadWindow : public Window {
265 private:
266  static const uint EDITBOX_MAX_SIZE = 50;
267 
269  AbstractFileType abstract_filetype;
272  FiosItem o_dir;
274  Scrollbar *vscroll;
275 
278  std::vector<bool> fios_items_shown;
279 
280  static void SaveGameConfirmationCallback(Window *w, bool confirmed)
281  {
282  /* File name has already been written to _file_to_saveload */
283  if (confirmed) _switch_mode = SM_SAVE_GAME;
284  }
285 
286  static void SaveHeightmapConfirmationCallback(Window *w, bool confirmed)
287  {
288  /* File name has already been written to _file_to_saveload */
289  if (confirmed) _switch_mode = SM_SAVE_HEIGHTMAP;
290  }
291 
292 public:
293 
296  {
297  GenerateDefaultSaveName(this->filename_editbox.text.buf, &this->filename_editbox.text.buf[this->filename_editbox.text.max_bytes - 1]);
298  this->filename_editbox.text.UpdateSize();
299  }
300 
301  SaveLoadWindow(WindowDesc *desc, AbstractFileType abstract_filetype, SaveLoadOperation fop)
302  : Window(desc), filename_editbox(64), abstract_filetype(abstract_filetype), fop(fop), filter_editbox(EDITBOX_MAX_SIZE)
303  {
304  assert(this->fop == SLO_SAVE || this->fop == SLO_LOAD);
305 
306  /* For saving, construct an initial file name. */
307  if (this->fop == SLO_SAVE) {
308  switch (this->abstract_filetype) {
309  case FT_SAVEGAME:
310  this->GenerateFileName();
311  break;
312 
313  case FT_SCENARIO:
314  case FT_HEIGHTMAP:
315  this->filename_editbox.text.Assign("UNNAMED");
316  break;
317 
318  default:
319  NOT_REACHED();
320  }
321  }
322  this->querystrings[WID_SL_SAVE_OSK_TITLE] = &this->filename_editbox;
323  this->filename_editbox.ok_button = WID_SL_SAVE_GAME;
324 
325  this->CreateNestedTree(true);
326  if (this->fop == SLO_LOAD && this->abstract_filetype == FT_SAVEGAME) {
327  this->GetWidget<NWidgetStacked>(WID_SL_CONTENT_DOWNLOAD_SEL)->SetDisplayedPlane(SZSP_HORIZONTAL);
328  }
329 
330  /* Select caption string of the window. */
331  StringID caption_string;
332  switch (this->abstract_filetype) {
333  case FT_SAVEGAME:
334  caption_string = (this->fop == SLO_SAVE) ? STR_SAVELOAD_SAVE_CAPTION : STR_SAVELOAD_LOAD_CAPTION;
335  break;
336 
337  case FT_SCENARIO:
338  caption_string = (this->fop == SLO_SAVE) ? STR_SAVELOAD_SAVE_SCENARIO : STR_SAVELOAD_LOAD_SCENARIO;
339  break;
340 
341  case FT_HEIGHTMAP:
342  caption_string = (this->fop == SLO_SAVE) ? STR_SAVELOAD_SAVE_HEIGHTMAP : STR_SAVELOAD_LOAD_HEIGHTMAP;
343  break;
344 
345  default:
346  NOT_REACHED();
347  }
348  this->GetWidget<NWidgetCore>(WID_SL_CAPTION)->widget_data = caption_string;
349 
350  this->vscroll = this->GetScrollbar(WID_SL_SCROLLBAR);
351  this->FinishInitNested(0);
352 
353  this->LowerWidget(WID_SL_DRIVES_DIRECTORIES_LIST);
354  this->querystrings[WID_SL_FILTER] = &this->filter_editbox;
355  this->filter_editbox.cancel_button = QueryString::ACTION_CLEAR;
356 
357  /* pause is only used in single-player, non-editor mode, non-menu mode. It
358  * will be unpaused in the WE_DESTROY event handler. */
359  if (_game_mode != GM_MENU && !_networking && _game_mode != GM_EDITOR) {
361  }
362  SetObjectToPlace(SPR_CURSOR_ZZZ, PAL_NONE, HT_NONE, WC_MAIN_WINDOW, 0);
363 
364  this->OnInvalidateData(SLIWD_RESCAN_FILES);
365 
367 
368  /* Select the initial directory. */
369  o_dir.type = FIOS_TYPE_DIRECT;
370  switch (this->abstract_filetype) {
371  case FT_SAVEGAME:
372  FioGetDirectory(o_dir.name, lastof(o_dir.name), SAVE_DIR);
373  break;
374 
375  case FT_SCENARIO:
376  FioGetDirectory(o_dir.name, lastof(o_dir.name), SCENARIO_DIR);
377  break;
378 
379  case FT_HEIGHTMAP:
380  FioGetDirectory(o_dir.name, lastof(o_dir.name), HEIGHTMAP_DIR);
381  break;
382 
383  default:
384  strecpy(o_dir.name, _personal_dir, lastof(o_dir.name));
385  }
386 
387  switch (this->fop) {
388  case SLO_SAVE:
389  /* Focus the edit box by default in the save window */
390  this->SetFocusedWidget(WID_SL_SAVE_OSK_TITLE);
391  break;
392 
393  default:
394  this->SetFocusedWidget(WID_SL_FILTER);
395  }
396  }
397 
398  virtual ~SaveLoadWindow()
399  {
400  /* pause is only used in single-player, non-editor mode, non menu mode */
401  if (!_networking && _game_mode != GM_EDITOR && _game_mode != GM_MENU) {
403  }
404  }
405 
406  void DrawWidget(const Rect &r, int widget) const override
407  {
408  switch (widget) {
409  case WID_SL_SORT_BYNAME:
410  case WID_SL_SORT_BYDATE:
411  if (((_savegame_sort_order & SORT_BY_NAME) != 0) == (widget == WID_SL_SORT_BYNAME)) {
412  this->DrawSortButtonState(widget, _savegame_sort_order & SORT_DESCENDING ? SBS_DOWN : SBS_UP);
413  }
414  break;
415 
416  case WID_SL_BACKGROUND: {
417  static const char *path = nullptr;
418  static StringID str = STR_ERROR_UNABLE_TO_READ_DRIVE;
419  static uint64 tot = 0;
420 
421  if (_fios_path_changed) {
422  str = FiosGetDescText(&path, &tot);
423  _fios_path_changed = false;
424  }
425 
426  if (str != STR_ERROR_UNABLE_TO_READ_DRIVE) SetDParam(0, tot);
428  DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + WD_FRAMERECT_TOP, path, TC_BLACK);
429  break;
430  }
431 
433  GfxFillRect(r.left + 1, r.top + 1, r.right, r.bottom, PC_BLACK);
434 
435  uint y = r.top + WD_FRAMERECT_TOP;
436  uint scroll_pos = this->vscroll->GetPosition();
437  for (uint row = 0; row < this->fios_items.Length(); row++) {
438  if (!this->fios_items_shown[row]) {
439  /* The current item is filtered out : we do not show it */
440  scroll_pos++;
441  continue;
442  }
443  if (row < scroll_pos) continue;
444  const FiosItem *item = this->fios_items.Get(row);
445 
446  if (item == this->selected) {
447  GfxFillRect(r.left + 1, y, r.right, y + this->resize.step_height, PC_DARK_BLUE);
448  }
449  DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, item->title, _fios_colours[GetDetailedFileType(item->type)]);
450  y += this->resize.step_height;
451  if (y >= this->vscroll->GetCapacity() * this->resize.step_height + r.top + WD_FRAMERECT_TOP) break;
452  }
453  break;
454  }
455 
456  case WID_SL_DETAILS: {
459  DrawString(r.left, r.right, r.top + FONT_HEIGHT_NORMAL / 2 + WD_FRAMERECT_TOP, STR_SAVELOAD_DETAIL_CAPTION, TC_FROMSTRING, SA_HOR_CENTER);
460 
461  if (this->selected == nullptr) break;
462 
464  uint y_max = r.bottom - FONT_HEIGHT_NORMAL - WD_FRAMERECT_BOTTOM;
465 
466  if (y > y_max) break;
467  if (!_load_check_data.checkable) {
468  /* Old savegame, no information available */
469  DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_SAVELOAD_DETAIL_NOT_AVAILABLE);
470  y += FONT_HEIGHT_NORMAL;
471  } else if (_load_check_data.error != INVALID_STRING_ID) {
472  /* Incompatible / broken savegame */
473  SetDParamStr(0, _load_check_data.error_data);
475  y, r.bottom - WD_FRAMERECT_BOTTOM, _load_check_data.error, TC_RED);
476  } else {
477  /* Mapsize */
478  SetDParam(0, _load_check_data.map_size_x);
479  SetDParam(1, _load_check_data.map_size_y);
480  DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_NETWORK_SERVER_LIST_MAP_SIZE);
481  y += FONT_HEIGHT_NORMAL;
482  if (y > y_max) break;
483 
484  /* Climate */
485  byte landscape = _load_check_data.settings.game_creation.landscape;
486  if (landscape < NUM_LANDSCAPE) {
487  SetDParam(0, STR_CHEAT_SWITCH_CLIMATE_TEMPERATE_LANDSCAPE + landscape);
488  DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_NETWORK_SERVER_LIST_LANDSCAPE);
489  y += FONT_HEIGHT_NORMAL;
490  }
491 
492  y += WD_PAR_VSEP_NORMAL;
493  if (y > y_max) break;
494 
495  /* Start date (if available) */
496  if (_load_check_data.settings.game_creation.starting_year != 0) {
497  SetDParam(0, ConvertYMDToDate(_load_check_data.settings.game_creation.starting_year, 0, 1));
498  DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_NETWORK_SERVER_LIST_START_DATE);
499  y += FONT_HEIGHT_NORMAL;
500  }
501  if (y > y_max) break;
502 
503  /* Hide current date for scenarios */
504  if (this->abstract_filetype != FT_SCENARIO) {
505  /* Current date */
506  SetDParam(0, _load_check_data.current_date);
507  DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_NETWORK_SERVER_LIST_CURRENT_DATE);
508  y += FONT_HEIGHT_NORMAL;
509  }
510 
511  /* Hide the NewGRF stuff when saving. We also hide the button. */
512  if (this->fop == SLO_LOAD && (this->abstract_filetype == FT_SAVEGAME || this->abstract_filetype == FT_SCENARIO)) {
513  y += WD_PAR_VSEP_NORMAL;
514  if (y > y_max) break;
515 
516  /* NewGrf compatibility */
517  SetDParam(0, _load_check_data.grfconfig == nullptr ? STR_NEWGRF_LIST_NONE :
518  STR_NEWGRF_LIST_ALL_FOUND + _load_check_data.grf_compatibility);
519  DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_SAVELOAD_DETAIL_GRFSTATUS);
520  y += FONT_HEIGHT_NORMAL;
521  }
522  if (y > y_max) break;
523 
524  /* Hide the company stuff for scenarios */
525  if (this->abstract_filetype != FT_SCENARIO) {
526  y += FONT_HEIGHT_NORMAL;
527  if (y > y_max) break;
528 
529  /* Companies / AIs */
530  for (auto &pair : _load_check_data.companies) {
531  SetDParam(0, pair.first + 1);
532  const CompanyProperties &c = *pair.second;
533  if (c.name != nullptr) {
534  SetDParam(1, STR_JUST_RAW_STRING);
535  SetDParamStr(2, c.name);
536  } else {
537  SetDParam(1, c.name_1);
538  SetDParam(2, c.name_2);
539  }
540  DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_SAVELOAD_DETAIL_COMPANY_INDEX);
541  y += FONT_HEIGHT_NORMAL;
542  if (y > y_max) break;
543  }
544  }
545  }
546  break;
547  }
548  }
549  }
550 
551  void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
552  {
553  switch (widget) {
554  case WID_SL_BACKGROUND:
556  break;
557 
559  resize->height = FONT_HEIGHT_NORMAL;
560  size->height = resize->height * 10 + WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM;
561  break;
562  case WID_SL_SORT_BYNAME:
563  case WID_SL_SORT_BYDATE: {
564  Dimension d = GetStringBoundingBox(this->GetWidget<NWidgetCore>(widget)->widget_data);
565  d.width += padding.width + Window::SortButtonWidth() * 2; // Doubled since the string is centred and it also looks better.
566  d.height += padding.height;
567  *size = maxdim(*size, d);
568  break;
569  }
570  }
571  }
572 
573  void OnPaint() override
574  {
575  if (_savegame_sort_dirty) {
576  _savegame_sort_dirty = false;
577  SortSaveGameList(this->fios_items);
578  this->OnInvalidateData(SLIWD_FILTER_CHANGES);
579  }
580 
581  this->DrawWidgets();
582  }
583 
584  void OnClick(Point pt, int widget, int click_count) override
585  {
586  switch (widget) {
587  case WID_SL_SORT_BYNAME: // Sort save names by name
588  _savegame_sort_order = (_savegame_sort_order == SORT_BY_NAME) ?
589  SORT_BY_NAME | SORT_DESCENDING : SORT_BY_NAME;
590  _savegame_sort_dirty = true;
591  this->SetDirty();
592  break;
593 
594  case WID_SL_SORT_BYDATE: // Sort save names by date
595  _savegame_sort_order = (_savegame_sort_order == SORT_BY_DATE) ?
596  SORT_BY_DATE | SORT_DESCENDING : SORT_BY_DATE;
597  _savegame_sort_dirty = true;
598  this->SetDirty();
599  break;
600 
601  case WID_SL_HOME_BUTTON: // OpenTTD 'button', jumps to OpenTTD directory
602  FiosBrowseTo(&o_dir);
603  this->InvalidateData(SLIWD_RESCAN_FILES);
604  break;
605 
606  case WID_SL_LOAD_BUTTON: {
607  if (this->selected == nullptr || _load_check_data.HasErrors()) break;
608 
609  const char *name = FiosBrowseTo(this->selected);
610  _file_to_saveload.SetMode(this->selected->type);
612  _file_to_saveload.SetTitle(this->selected->title);
613 
614  if (this->abstract_filetype == FT_HEIGHTMAP) {
615  delete this;
617  } else if (!_load_check_data.HasNewGrfs() || _load_check_data.grf_compatibility != GLC_NOT_FOUND || _settings_client.gui.UserIsAllowedToChangeNewGRFs()) {
618  _switch_mode = (_game_mode == GM_EDITOR) ? SM_LOAD_SCENARIO : SM_LOAD_GAME;
620  delete this;
621  }
622  break;
623  }
624 
625  case WID_SL_NEWGRF_INFO:
626  if (_load_check_data.HasNewGrfs()) {
627  ShowNewGRFSettings(false, false, false, &_load_check_data.grfconfig);
628  }
629  break;
630 
632  if (!_network_available) {
633  ShowErrorMessage(STR_NETWORK_ERROR_NOTAVAILABLE, INVALID_STRING_ID, WL_ERROR);
634  } else if (_load_check_data.HasNewGrfs()) {
635  ShowMissingContentWindow(_load_check_data.grfconfig);
636  }
637  break;
638 
639  case WID_SL_DRIVES_DIRECTORIES_LIST: { // Click the listbox
640  int y = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_SL_DRIVES_DIRECTORIES_LIST, WD_FRAMERECT_TOP);
641  if (y == INT_MAX) return;
642 
643  /* Get the corresponding non-filtered out item from the list */
644  int i = 0;
645  while (i <= y) {
646  if (!this->fios_items_shown[i]) y++;
647  i++;
648  }
649  const FiosItem *file = this->fios_items.Get(y);
650 
651  const char *name = FiosBrowseTo(file);
652  if (name == nullptr) {
653  /* Changed directory, need refresh. */
654  this->InvalidateData(SLIWD_RESCAN_FILES);
655  break;
656  }
657 
658  if (click_count == 1) {
659  if (this->selected != file) {
660  this->selected = file;
661  _load_check_data.Clear();
662 
663  if (GetDetailedFileType(file->type) == DFT_GAME_FILE) {
664  /* Other detailed file types cannot be checked before. */
666  }
667 
668  this->InvalidateData(SLIWD_SELECTION_CHANGES);
669  }
670  if (this->fop == SLO_SAVE) {
671  /* Copy clicked name to editbox */
672  this->filename_editbox.text.Assign(file->title);
673  this->SetWidgetDirty(WID_SL_SAVE_OSK_TITLE);
674  }
675  } else if (!_load_check_data.HasErrors()) {
676  this->selected = file;
677  if (this->fop == SLO_LOAD) {
678  if (this->abstract_filetype == FT_SAVEGAME || this->abstract_filetype == FT_SCENARIO) {
679  this->OnClick(pt, WID_SL_LOAD_BUTTON, 1);
680  } else {
681  assert(this->abstract_filetype == FT_HEIGHTMAP);
682  _file_to_saveload.SetMode(file->type);
684  _file_to_saveload.SetTitle(file->title);
685 
686  delete this;
688  }
689  }
690  }
691  break;
692  }
693 
695  if (!_network_available) {
696  ShowErrorMessage(STR_NETWORK_ERROR_NOTAVAILABLE, INVALID_STRING_ID, WL_ERROR);
697  } else {
698  assert(this->fop == SLO_LOAD);
699  switch (this->abstract_filetype) {
700  default: NOT_REACHED();
703  }
704  }
705  break;
706 
707  case WID_SL_DELETE_SELECTION: // Delete
708  break;
709 
710  case WID_SL_SAVE_GAME: // Save game
711  /* Note, this is also called via the OSK; and we need to lower the button. */
712  this->HandleButtonClick(WID_SL_SAVE_GAME);
713  break;
714  }
715  }
716 
717  EventState OnKeyPress(WChar key, uint16 keycode) override
718  {
719  if (keycode == WKC_ESC) {
720  delete this;
721  return ES_HANDLED;
722  }
723 
724  return ES_NOT_HANDLED;
725  }
726 
727  void OnTimeout() override
728  {
729  /* Widgets WID_SL_DELETE_SELECTION and WID_SL_SAVE_GAME only exist when saving to a file. */
730  if (this->fop != SLO_SAVE) return;
731 
732  if (this->IsWidgetLowered(WID_SL_DELETE_SELECTION)) { // Delete button clicked
733  if (!FiosDelete(this->filename_editbox.text.buf)) {
734  ShowErrorMessage(STR_ERROR_UNABLE_TO_DELETE_FILE, INVALID_STRING_ID, WL_ERROR);
735  } else {
736  this->InvalidateData(SLIWD_RESCAN_FILES);
737  /* Reset file name to current date on successful delete */
738  if (this->abstract_filetype == FT_SAVEGAME) GenerateFileName();
739  }
740  } else if (this->IsWidgetLowered(WID_SL_SAVE_GAME)) { // Save button clicked
741  if (this->abstract_filetype == FT_SAVEGAME || this->abstract_filetype == FT_SCENARIO) {
742  FiosMakeSavegameName(_file_to_saveload.name, this->filename_editbox.text.buf, lastof(_file_to_saveload.name));
744  ShowQuery(STR_SAVELOAD_OVERWRITE_TITLE, STR_SAVELOAD_OVERWRITE_WARNING, this, SaveLoadWindow::SaveGameConfirmationCallback);
745  } else {
747  }
748  } else {
749  FiosMakeHeightmapName(_file_to_saveload.name, this->filename_editbox.text.buf, lastof(_file_to_saveload.name));
751  ShowQuery(STR_SAVELOAD_OVERWRITE_TITLE, STR_SAVELOAD_OVERWRITE_WARNING, this, SaveLoadWindow::SaveHeightmapConfirmationCallback);
752  } else {
754  }
755  }
756 
757  /* In the editor set up the vehicle engines correctly (date might have changed) */
758  if (_game_mode == GM_EDITOR) StartupEngines();
759  }
760  }
761 
762  void OnResize() override
763  {
765  }
766 
772  void OnInvalidateData(int data = 0, bool gui_scope = true) override
773  {
774  switch (data) {
775  case SLIWD_RESCAN_FILES:
776  /* Rescan files */
777  this->selected = nullptr;
778  _load_check_data.Clear();
779  if (!gui_scope) break;
780 
781  _fios_path_changed = true;
782  this->fios_items.BuildFileList(this->abstract_filetype, this->fop);
783  this->vscroll->SetCount((uint)this->fios_items.Length());
784  this->selected = nullptr;
785  _load_check_data.Clear();
786 
787  /* We reset the files filtered */
788  this->OnInvalidateData(SLIWD_FILTER_CHANGES);
789 
790  FALLTHROUGH;
791 
793  /* Selection changes */
794  if (!gui_scope) break;
795 
796  if (this->fop != SLO_LOAD) break;
797 
798  switch (this->abstract_filetype) {
799  case FT_HEIGHTMAP:
800  this->SetWidgetDisabledState(WID_SL_LOAD_BUTTON, this->selected == nullptr || _load_check_data.HasErrors());
801  break;
802 
803  case FT_SAVEGAME:
804  case FT_SCENARIO: {
805  bool disabled = this->selected == nullptr || _load_check_data.HasErrors();
807  disabled |= _load_check_data.HasNewGrfs() && _load_check_data.grf_compatibility == GLC_NOT_FOUND;
808  }
809  this->SetWidgetDisabledState(WID_SL_LOAD_BUTTON, disabled);
810  this->SetWidgetDisabledState(WID_SL_NEWGRF_INFO, !_load_check_data.HasNewGrfs());
811  this->SetWidgetDisabledState(WID_SL_MISSING_NEWGRFS,
812  !_load_check_data.HasNewGrfs() || _load_check_data.grf_compatibility == GLC_ALL_GOOD);
813  break;
814  }
815 
816  default:
817  NOT_REACHED();
818  }
819  break;
820 
822  /* Filter changes */
823  this->fios_items_shown.resize(this->fios_items.Length());
824  uint items_shown_count = 0;
825  /* We pass through every fios item */
826  for (uint i = 0; i < this->fios_items.Length(); i++) {
827  if (this->string_filter.IsEmpty()) {
828  /* We don't filter anything out if the filter editbox is empty */
829  this->fios_items_shown[i] = true;
830  items_shown_count++;
831  } else {
832  this->string_filter.ResetState();
833  this->string_filter.AddLine(this->fios_items[i].title);
834  /* We set the vector to show this fios element as filtered depending on the result of the filter */
835  this->fios_items_shown[i] = this->string_filter.GetState();
836  if (this->fios_items_shown[i]) items_shown_count++;
837 
838  if (&(this->fios_items[i]) == this->selected && this->fios_items_shown[i] == false) {
839  /* The selected element has been filtered out */
840  this->selected = nullptr;
841  this->OnInvalidateData(SLIWD_SELECTION_CHANGES);
842  }
843  }
844  }
845  this->vscroll->SetCount(items_shown_count);
846  break;
847  }
848  }
849 
850  void OnEditboxChanged(int wid) override
851  {
852  if (wid == WID_SL_FILTER) {
853  this->string_filter.SetFilterTerm(this->filter_editbox.text.buf);
854  this->InvalidateData(SLIWD_FILTER_CHANGES);
855  }
856  }
857 };
858 
861  WDP_CENTER, "load_game", 500, 294,
863  0,
864  _nested_load_dialog_widgets, lengthof(_nested_load_dialog_widgets)
865 );
866 
869  WDP_CENTER, "load_heightmap", 257, 320,
871  0,
872  _nested_load_heightmap_dialog_widgets, lengthof(_nested_load_heightmap_dialog_widgets)
873 );
874 
877  WDP_CENTER, "save_game", 500, 294,
879  0,
880  _nested_save_dialog_widgets, lengthof(_nested_save_dialog_widgets)
881 );
882 
889 {
891 
892  WindowDesc *sld;
893  if (fop == SLO_SAVE) {
894  sld = &_save_dialog_desc;
895  } else {
896  /* Dialogue for loading a file. */
897  sld = (abstract_filetype == FT_HEIGHTMAP) ? &_load_heightmap_dialog_desc : &_load_dialog_desc;
898  }
899 
900  _file_to_saveload.abstract_ftype = abstract_filetype;
901 
902  new SaveLoadWindow(sld, abstract_filetype, fop);
903 }
EventState
State of handling an event.
Definition: window_type.h:711
static const NWidgetPart _nested_load_heightmap_dialog_widgets[]
Load heightmap with content download.
Definition: fios_gui.cpp:128
Functions related to OTTD&#39;s strings.
AbstractFileType
The different abstract types of files that the system knows about.
Definition: fileio_type.h:16
Empty widget, place holder to reserve space in widget array.
Definition: widget_type.h:46
static const TextColour _fios_colours[]
Text colours of DetailedFileType fios entries in the window.
Definition: fios_gui.cpp:227
Normal push-button (no toggle button) with image caption.
Definition: widget_type.h:103
bool _networking
are we in networking mode?
Definition: network.cpp:52
Button to open NewGgrf configuration.
Definition: fios_widget.h:30
Button to load game/scenario.
Definition: fios_widget.h:31
Horizontally center the text.
Definition: gfx_func.h:95
const FiosItem * Get(size_t index) const
Get a pointer to the indicated file information.
Definition: fios.h:157
char * name
Name of the company if the user changed it.
Definition: company_base.h:57
static NWidgetPart SetResize(int16 dx, int16 dy)
Widget part function for setting the resize step.
Definition: widget_type.h:928
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:110
Container for loading in mode SL_LOAD_CHECK.
Definition: fios.h:31
byte landscape
the landscape we&#39;re currently in
High level window description.
Definition: window_gui.h:166
void GenerateDefaultSaveName(char *buf, const char *last)
Fill the buffer with the default name for a savegame or screenshot.
Definition: saveload.cpp:2812
Saveload window; Window numbers:
Definition: window_type.h:137
All GRF needed by game are present.
Definition: newgrf_config.h:52
struct LoggedAction * gamelog_action
Gamelog actions.
Definition: fios.h:46
void SetName(const char *name)
Set the name of the file.
Definition: saveload.cpp:2874
Functions related to dates.
Scrollbar data structure.
Definition: widget_type.h:587
std::vector< FiosItem > files
The list of files.
Definition: fios.h:200
void ClearGRFConfigList(GRFConfig **config)
Clear a GRF Config list, freeing all nodes.
Load game, Play Scenario.
Definition: openttd.h:29
Offset at top to draw the frame rectangular area.
Definition: window_gui.h:62
Normal amount of vertical space between two paragraphs of text.
Definition: window_gui.h:137
Horizontal container.
Definition: widget_type.h:73
void ResetState()
Reset the matching state to process a new item.
The passed event is not handled.
Definition: window_type.h:713
bool GetState() const
Get the matching state of the current item.
Functions to be called to log possibly unsafe game events.
size_t Length() const
Get the number of files in the list.
Definition: fios.h:130
Types related to the fios widgets.
The content consists of a scenario.
Definition: tcp_content.h:27
FileToSaveLoad _file_to_saveload
File to save or load in the openttd loop.
Definition: saveload.cpp:58
void OnEditboxChanged(int wid) override
The text in an editbox has been edited.
Definition: fios_gui.cpp:850
Subdirectory of scenario for heightmaps.
Definition: fileio_type.h:113
void GenerateFileName()
Generate a default save filename.
Definition: fios_gui.cpp:295
a textbox for typing
Definition: widget_type.h:69
Resize box (normally at bottom-right of a window)
Definition: widget_type.h:66
Pressed (inset) panel, most commonly used as combo box text area.
Definition: widget_type.h:49
Title textbox, only available for save operations.
Definition: fios_widget.h:25
static const int ACTION_CLEAR
Clear editbox.
FileList fios_items
Save game list.
Definition: fios_gui.cpp:271
GRFConfig * grfconfig
NewGrf configuration from save.
Definition: fios.h:43
void ShowErrorMessage(StringID summary_msg, StringID detailed_msg, WarningLevel wl, int x=0, int y=0, const GRFFile *textref_stack_grffile=nullptr, uint textref_stack_size=0, const uint32 *textref_stack=nullptr)
Display an error message in a window.
Definition: error_gui.cpp:380
const FiosItem * Begin() const
Get a pointer to the first file information.
Definition: fios.h:139
Close box (at top-left of a window)
Definition: widget_type.h:67
Functions for Standard In/Out file operations.
DetailedFileType GetDetailedFileType(FiosType fios_type)
Extract the detailed file type from a FiosType.
Definition: fileio_type.h:100
String filter and state.
#define lastof(x)
Get the last element of an fixed size array.
Definition: depend.cpp:48
uint32 name_2
Parameter of name_1.
Definition: company_base.h:55
File selection has changed (user click, ...)
Definition: fios.h:22
Panel with game details.
Definition: fios_widget.h:29
Background of file selection.
Definition: fios_widget.h:20
Pure simple text.
Definition: widget_type.h:56
File is being saved.
Definition: fileio_type.h:50
Deals with finding savegames.
Definition: fios.h:103
Save button, only available for save operations.
Definition: fios_widget.h:27
Load file for checking and/or preview.
Definition: fileio_type.h:48
StringID FiosGetDescText(const char **path, uint64 *total_free)
Get descriptive texts.
Definition: fios.cpp:139
void OnTimeout() override
Called when this window&#39;s timeout has been reached.
Definition: fios_gui.cpp:727
bool _network_available
is network mode available?
Definition: network.cpp:54
QueryString filter_editbox
Filter editbox;.
Definition: fios_gui.cpp:277
void SetCount(int num)
Sets the number of elements in the list.
Definition: widget_type.h:668
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:908
Base for the GUIs that have an edit box in them.
Data structure for an opened window.
Definition: window_gui.h:276
Save game or scenario file.
Definition: fileio_type.h:31
bool checkable
True if the savegame could be checked by SL_LOAD_CHECK. (Old savegames are not checkable.)
Definition: fios.h:32
void SetFilterTerm(const char *str)
Set the term to filter on.
old or new savegame
Definition: fileio_type.h:18
old or new scenario
Definition: fileio_type.h:19
static NWidgetPart SetPadding(uint8 top, uint8 right, uint8 bottom, uint8 left)
Widget part function for setting additional space around a widget.
Definition: widget_type.h:1044
static WindowDesc _load_dialog_desc(WDP_CENTER, "load_game", 500, 294, WC_SAVELOAD, WC_NONE, 0, _nested_load_dialog_widgets, lengthof(_nested_load_dialog_widgets))
Load game/scenario.
void SetDParamStr(uint n, const char *str)
This function is used to "bind" a C string to a OpenTTD dparam slot.
Definition: strings.cpp:279
Main window; Window numbers:
Definition: window_type.h:44
void ShowMissingContentWindow(const GRFConfig *list)
Show the content list window with all missing grfs from the given list.
std::vector< bool > fios_items_shown
Map of the filtered out fios items.
Definition: fios_gui.cpp:278
Sort by name button.
Definition: fios_widget.h:16
Base directory for all scenarios.
Definition: fileio_type.h:112
const FiosItem * End() const
Get a pointer behind the last file information.
Definition: fios.h:148
void SetTitle(const char *title)
Set the title of the file.
Definition: saveload.cpp:2883
Functions/types related to saving and loading games.
Invisible widget that takes some space.
Definition: widget_type.h:77
void FiosMakeSavegameName(char *buf, const char *name, const char *last)
Make a save game or scenario filename from a name.
Definition: fios.cpp:226
Functions related to errors.
Default window size box (at top-right of a window, between WWT_SHADEBOX and WWT_STICKYBOX) ...
Definition: widget_type.h:63
Caption of the window.
Definition: fios_widget.h:15
Delete button, only available for save operations.
Definition: fios_widget.h:26
int GetScrolledRowFromWidget(int clickpos, const Window *const w, int widget, int padding=0, int line_height=-1) const
Compute the row of a scrolled widget that a user clicked in.
Definition: widget.cpp:1957
void GamelogFree(LoggedAction *gamelog_action, uint gamelog_actions)
Frees the memory allocated by a gamelog.
Definition: gamelog.cpp:93
Home button.
Definition: fios_widget.h:21
void ShowQuery(StringID caption, StringID message, Window *parent, QueryCallbackProc *callback)
Show a modal confirmation window with standard &#39;yes&#39; and &#39;no&#39; buttons The window is aligned to the ce...
Definition: misc_gui.cpp:1260
Functions related to engines.
int ok_button
Widget button of parent window to simulate when pressing OK in OSK.
Sort descending.
Definition: window_gui.h:225
A game paused for saving/loading.
Definition: openttd.h:58
CompanyPropertiesMap companies
Company information.
Definition: fios.h:41
Statically loadable part of Company pool item.
Definition: company_base.h:54
#define FONT_HEIGHT_NORMAL
Height of characters in the normal (FS_NORMAL) font.
Definition: gfx_func.h:176
static NWidgetPart SetDataTip(uint32 data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1012
Functions related to the gfx engine.
Data stored about a string that can be modified in the GUI.
ClientSettings _settings_client
The current settings for this game.
Definition: settings.cpp:78
Display plane with zero size vertically, and filling and resizing horizontally.
Definition: widget_type.h:387
static NWidgetPart SetMinimalSize(int16 x, int16 y)
Widget part function for setting the minimal size.
Definition: widget_type.h:945
A path without any base directory.
Definition: fileio_type.h:125
Definition of base types and functions in a cross-platform compatible way.
void Clear()
Reset read data.
Definition: fios_gui.cpp:47
void ShowHeightmapLoad()
Start with loading a heightmap.
A number of safeguards to prevent using unsafe methods.
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Definition: gfx_type.h:245
Normal push-button (no toggle button) with text caption.
Definition: widget_type.h:102
Geometry functions.
Simple depressed panel.
Definition: widget_type.h:48
Base directory for all savegames.
Definition: fileio_type.h:110
void BuildFileList(AbstractFileType abstract_filetype, SaveLoadOperation fop)
Construct a file list with the given kind of files, for the stated purpose.
Definition: fios.cpp:74
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:243
const char * _personal_dir
custom directory for personal settings, saves, newgrf, etc.
Definition: fileio.cpp:1117
char * error_data
Data to pass to SetDParamStr when displaying error.
Definition: fios.h:34
Center the window.
Definition: window_gui.h:155
bool HasErrors()
Check whether loading the game resulted in errors.
Definition: fios.h:67
static NWidgetPart NWidget(WidgetType tp, Colours col, int16 idx=-1)
Widget part function for starting a new &#39;real&#39; widget.
Definition: widget_type.h:1112
static WindowDesc _save_dialog_desc(WDP_CENTER, "save_game", 500, 294, WC_SAVELOAD, WC_NONE, 0, _nested_save_dialog_widgets, lengthof(_nested_save_dialog_widgets))
Save game/scenario.
Offset at bottom to draw the frame rectangular area.
Definition: window_gui.h:63
int DrawString(int left, int right, int top, const char *str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
Definition: gfx.cpp:498
EventState OnKeyPress(WChar key, uint16 keycode) override
A key has been pressed.
Definition: fios_gui.cpp:717
Basic functions/variables used all over the place.
Part of the network protocol handling content distribution.
SaveOrLoadResult SaveOrLoad(const char *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:2717
Right offset of the text of the frame.
Definition: window_gui.h:71
bool DoCommandP(const CommandContainer *container, bool my_cmd)
Shortcut for the long DoCommandP when having a container with the data.
Definition: command.cpp:532
The filename filter has changed (via the editbox)
Definition: fios.h:23
#define lengthof(x)
Return the length of an fixed size array.
Definition: depend.cpp:40
File is being loaded.
Definition: fileio_type.h:49
Left offset of the text of the frame.
Definition: window_gui.h:70
int cancel_button
Widget button of parent window to simulate when pressing CANCEL in OSK.
bool FioCheckFileExists(const char *filename, Subdirectory subdir)
Check whether the given file exists.
Definition: fileio.cpp:310
static int SortButtonWidth()
Get width of up/down arrow of sort button state.
Definition: widget.cpp:656
StringID error
Error message from loading. INVALID_STRING_ID if no error.
Definition: fios.h:33
SaveLoadOperation fop
Type of file to select.
Definition: fios_gui.cpp:270
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
static const uint8 PC_BLACK
Black palette colour.
Definition: gfx_func.h:203
SaveLoadOperation
Operation performed on the file.
Definition: fileio_type.h:47
Save game.
Definition: openttd.h:31
void Assign(StringID string)
Render a string into the textbuffer.
Definition: textbuf.cpp:396
Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition: gfx.cpp:700
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
Definition: fios_gui.cpp:406
void AddLine(const char *str)
Pass another text line from the current item to the filter.
bool FiosDelete(const char *name)
Delete a file.
Definition: fios.cpp:253
void StartupEngines()
Start/initialise all our engines.
Definition: engine.cpp:693
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
No window, redirects to WC_MAIN_WINDOW.
Definition: window_type.h:38
void DeleteWindowById(WindowClass cls, WindowNumber number, bool force)
Delete a window by its class and window number (if it is open).
Definition: window.cpp:1162
static const uint8 PC_GREY
Grey palette colour.
Definition: gfx_func.h:205
static const uint8 PC_DARK_BLUE
Dark blue palette colour.
Definition: gfx_func.h:222
Sort by date button.
Definition: fios_widget.h:17
void ShowSaveLoadDialog(AbstractFileType abstract_filetype, SaveLoadOperation fop)
Launch save/load dialog in the given mode.
Definition: fios_gui.cpp:888
void OnResize() override
Called after the window got resized.
Definition: fios_gui.cpp:762
void FiosMakeHeightmapName(char *buf, const char *name, const char *last)
Construct a filename for a height map.
Definition: fios.cpp:239
default
char *const buf
buffer in which text is saved
Definition: textbuf_type.h:32
void ShowNewGRFSettings(bool editable, bool show_params, bool exec_changes, GRFConfig **config)
Setup the NewGRF gui.
Background of window.
Definition: fios_widget.h:19
GUISettings gui
settings related to the GUI
QueryString filename_editbox
Filename editbox.
Definition: fios_gui.cpp:268
Window caption (window title between closebox and stickybox)
Definition: widget_type.h:59
void ClearErrorMessages()
Clear all errors from the queue.
Definition: error_gui.cpp:338
Declarations for savegames operations.
Types related to the landscape.
LoadCheckData _load_check_data
Data loaded from save during SL_LOAD_CHECK.
Definition: fios_gui.cpp:38
The content consists of a heightmap.
Definition: tcp_content.h:28
StringID name_1
Name of the company if the user did not change it.
Definition: company_base.h:56
List of file information.
Definition: fios.h:112
At least one GRF couldn&#39;t be found (higher priority than GLC_COMPATIBLE)
Definition: newgrf_config.h:54
const char * FiosBrowseTo(const FiosItem *item)
Browse to a new path based on the passed item, starting at #_fios_path.
Definition: fios.cpp:150
Searching and filtering using a stringterm.
Sort ascending.
Definition: window_gui.h:224
static const NWidgetPart _nested_load_dialog_widgets[]
Load game/scenario with optional content download.
Definition: fios_gui.cpp:71
static NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME, WWT_INSET, or WWT_PANEL).
Definition: widget_type.h:997
Filter list of files.
Definition: fios_widget.h:18
char * strecpy(char *dst, const char *src, const char *last)
Copies characters from one buffer to another.
Definition: depend.cpp:66
SwitchMode _switch_mode
The next mainloop command.
Definition: gfx.cpp:46
uint gamelog_actions
Number of gamelog actions.
Definition: fios.h:47
Rescan all files (when changed directory, ...)
Definition: fios.h:21
Functions related to commands.
char name[MAX_PATH]
Name of the file.
Definition: saveload.h:320
Coordinates of a point in 2D.
AbstractFileType abstract_ftype
Abstract type of file (scenario, heightmap, etc).
Definition: saveload.h:319
const FiosItem * selected
Selected game in fios_items, or nullptr.
Definition: fios_gui.cpp:273
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:3305
uint16 GetCapacity() const
Gets the number of visible elements of the scrollbar.
Definition: widget_type.h:620
Load scenario from scenario editor.
Definition: openttd.h:34
heightmap file
Definition: fileio_type.h:20
bool UserIsAllowedToChangeNewGRFs() const
Returns true when the user has sufficient privileges to edit newgrfs on a running game...
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
Definition: strings_type.h:17
static WindowDesc _load_heightmap_dialog_desc(WDP_CENTER, "load_heightmap", 257, 320, WC_SAVELOAD, WC_NONE, 0, _nested_load_heightmap_dialog_widgets, lengthof(_nested_load_heightmap_dialog_widgets))
Load heightmap.
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
Definition: depend.cpp:129
Offset at right to draw the frame rectangular area.
Definition: window_gui.h:61
Selection &#39;stack&#39; to &#39;hide&#39; the content download.
Definition: fios_widget.h:28
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition: fios_gui.cpp:584
Button to find missing NewGRFs online.
Definition: fios_widget.h:32
static NWidgetPart SetFill(uint fill_x, uint fill_y)
Widget part function for setting filling.
Definition: widget_type.h:981
StringFilter string_filter
Filter for available games.
Definition: fios_gui.cpp:276
bool HasNewGrfs()
Check whether the game uses any NewGrfs.
Definition: fios.h:76
GameCreationSettings game_creation
settings used during the creation of a game (map)
void SetCapacityFromWidget(Window *w, int widget, int padding=0)
Set capacity of visible elements from the size and resize properties of a widget. ...
Definition: widget.cpp:1971
void ResetObjectToPlace()
Reset the cursor and mouse mode handling back to default (normal cursor, only clicking in windows)...
Definition: viewport.cpp:3353
Specification of a rectangle with absolute coordinates of all edges.
Vertical scrollbar.
Definition: widget_type.h:82
void SetMode(FiosType ft)
Set the mode and file type of the file to save or load based on the type of file entry at the file sy...
Definition: saveload.cpp:2845
The passed event is handled.
Definition: window_type.h:712
Date ConvertYMDToDate(Year year, Month month, Day day)
Converts a tuple of Year, Month and Day to a Date.
Definition: date.cpp:147
Functions related to tile highlights.
Window functions not directly related to making/drawing windows.
void OnPaint() override
The window must be repainted.
Definition: fios_gui.cpp:573
Scrollbar of the file list.
Definition: fios_widget.h:23
Stacked widgets, only one visible at a time (eg in a panel with tabs).
Definition: widget_type.h:78
GUI functions that shouldn&#39;t be here.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition: fios_gui.cpp:772
Errors (eg. saving/loading failed)
Definition: error.h:23
void UpdateWidgetSize(int 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:551
uint32 WChar
Type for wide characters, i.e.
Definition: string_type.h:35
static NWidgetPart SetScrollbar(int index)
Attach a scrollbar to a widget.
Definition: widget_type.h:1093
Dimensions (a width and height) of a rectangle in 2D.
GRFListCompatibility grf_compatibility
Summary state of NewGrfs, whether missing files or only compatible found.
Definition: fios.h:44
Value of the NCB_EQUALSIZE flag.
Definition: widget_type.h:427
bool IsEmpty() const
Check whether any filter words were entered.
Offset at left to draw the frame rectangular area.
Definition: window_gui.h:60
Year starting_year
starting date
This file contains all sprite-related enums and defines.
static const NWidgetPart _nested_save_dialog_widgets[]
Save game/scenario.
Definition: fios_gui.cpp:172
static NWidgetPart SetPIP(uint8 pre, uint8 inter, uint8 post)
Widget part function for setting a pre/inter/post spaces.
Definition: widget_type.h:1074
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.
Save heightmap.
Definition: openttd.h:32
int DrawStringMultiLine(int left, int right, int top, int bottom, const char *str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly over multiple lines.
Definition: gfx.cpp:621
void UpdateSize()
Update Textbuf type with its actual physical character and screenlength Get the count of characters i...
Definition: textbuf.cpp:430
uint16 GetPosition() const
Gets the position of the first visible element in the list.
Definition: widget_type.h:629
Content download button, only available for play scenario/heightmap.
Definition: fios_widget.h:24
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
Definition: strings_func.h:199
pause the game
Definition: command_type.h:254