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