Go to the documentation of this file.
35 #include "table/strings.h"
41 static bool _fios_path_changed;
42 static bool _savegame_sort_dirty;
55 this->map_size_x = this->map_size_y = 256;
56 this->current_date = 0;
90 SetDataTip(STR_LIST_FILTER_OSKTITLE, STR_LIST_FILTER_TOOLTIP),
112 SetDataTip(STR_INTRO_ONLINE_CONTENT, STR_INTRO_TOOLTIP_ONLINE_CONTENT),
148 SetDataTip(STR_LIST_FILTER_OSKTITLE, STR_LIST_FILTER_TOOLTIP),
170 SetDataTip(STR_INTRO_ONLINE_CONTENT, STR_INTRO_TOOLTIP_ONLINE_CONTENT),
172 SetDataTip(STR_SAVELOAD_LOAD_BUTTON, STR_SAVELOAD_LOAD_HEIGHTMAP_TOOLTIP),
195 SetDataTip(STR_LIST_FILTER_OSKTITLE, STR_LIST_FILTER_TOOLTIP),
215 NWidget(
WWT_EDITBOX, COLOUR_GREY,
WID_SL_SAVE_OSK_TITLE),
SetPadding(2, 2, 2, 2),
SetFill(1, 0),
SetResize(1, 0),
216 SetDataTip(STR_SAVELOAD_OSKTITLE, STR_SAVELOAD_EDITBOX_TOOLTIP),
255 size_t sort_start = 0;
262 for (
const auto &item : file_list) {
264 case FIOS_TYPE_DIR: sort_start++;
break;
265 case FIOS_TYPE_PARENT: sort_start++;
break;
266 case FIOS_TYPE_DRIVE: sort_end++;
break;
271 std::sort(file_list.begin() + sort_start, file_list.end() - sort_end);
276 static const uint EDITBOX_MAX_SIZE = 50;
291 static void SaveGameConfirmationCallback(
Window *w,
bool confirmed)
297 static void SaveHeightmapConfirmationCallback(
Window *w,
bool confirmed)
308 GenerateDefaultSaveName(this->filename_editbox.text.
buf, &this->filename_editbox.text.buf[this->filename_editbox.text.max_bytes - 1]);
319 switch (this->abstract_filetype) {
326 this->filename_editbox.text.
Assign(
"UNNAMED");
343 switch (this->abstract_filetype) {
345 caption_string = (this->fop ==
SLO_SAVE) ? STR_SAVELOAD_SAVE_CAPTION : STR_SAVELOAD_LOAD_CAPTION;
349 caption_string = (this->fop ==
SLO_SAVE) ? STR_SAVELOAD_SAVE_SCENARIO : STR_SAVELOAD_LOAD_SCENARIO;
353 caption_string = (this->fop ==
SLO_SAVE) ? STR_SAVELOAD_SAVE_HEIGHTMAP : STR_SAVELOAD_LOAD_HEIGHTMAP;
359 this->GetWidget<NWidgetCore>(
WID_SL_CAPTION)->widget_data = caption_string;
370 if (_game_mode != GM_MENU && !
_networking && _game_mode != GM_EDITOR) {
380 o_dir.type = FIOS_TYPE_DIRECT;
382 switch (this->abstract_filetype) {
414 if (!
_networking && _game_mode != GM_EDITOR && _game_mode != GM_MENU) {
431 static const char *path =
nullptr;
432 static StringID str = STR_ERROR_UNABLE_TO_READ_DRIVE;
433 static uint64 tot = 0;
435 if (_fios_path_changed) {
437 _fios_path_changed =
false;
442 if (str != STR_ERROR_UNABLE_TO_READ_DRIVE)
SetDParam(0, tot);
444 DrawString(ir.left, ir.right, ir.top, path, TC_BLACK);
454 for (uint row = 0; row < this->fios_items.size() && tr.top < br.bottom; row++) {
455 if (!this->fios_items_shown[row]) {
460 if (row < scroll_pos)
continue;
461 const FiosItem *item = &this->fios_items[row];
463 if (item == this->selected) {
465 }
else if (item == this->highlighted) {
475 this->DrawDetails(r);
480 void DrawDetails(
const Rect &r)
const
487 tr.top += HEADER_HEIGHT;
493 if (this->selected ==
nullptr)
return;
497 if (tr.top > tr.bottom)
return;
501 DrawString(tr, STR_SAVELOAD_DETAIL_NOT_AVAILABLE);
511 DrawString(tr, STR_NETWORK_SERVER_LIST_MAP_SIZE);
513 if (tr.top > tr.bottom)
return;
517 if (landscape < NUM_LANDSCAPE) {
518 SetDParam(0, STR_CLIMATE_TEMPERATE_LANDSCAPE + landscape);
519 DrawString(tr, STR_NETWORK_SERVER_LIST_LANDSCAPE);
524 if (tr.top > tr.bottom)
return;
529 DrawString(tr, STR_NETWORK_SERVER_LIST_START_DATE);
532 if (tr.top > tr.bottom)
return;
538 DrawString(tr, STR_NETWORK_SERVER_LIST_CURRENT_DATE);
545 if (tr.top > tr.bottom)
return;
550 DrawString(tr, STR_SAVELOAD_DETAIL_GRFSTATUS);
553 if (tr.top > tr.bottom)
return;
558 if (tr.top > tr.bottom)
return;
564 if (!c.
name.empty()) {
571 DrawString(tr, STR_SAVELOAD_DETAIL_COMPANY_INDEX);
573 if (tr.top > tr.bottom)
break;
588 size->height =
resize->height * 10 + padding.height;
594 d.height += padding.height;
603 if (_savegame_sort_dirty) {
604 _savegame_sort_dirty =
false;
616 _savegame_sort_order = (_savegame_sort_order == SORT_BY_NAME) ?
617 SORT_BY_NAME | SORT_DESCENDING : SORT_BY_NAME;
618 _savegame_sort_dirty =
true;
623 _savegame_sort_order = (_savegame_sort_order == SORT_BY_DATE) ?
624 SORT_BY_DATE | SORT_DESCENDING : SORT_BY_DATE;
625 _savegame_sort_dirty =
true;
669 if (y == INT_MAX)
return;
674 if (!this->fios_items_shown[i]) y++;
677 const FiosItem *file = &this->fios_items[y];
680 if (name ==
nullptr) {
686 if (click_count == 1) {
687 if (this->selected != file) {
688 this->selected = file;
700 this->filename_editbox.text.
Assign(file->title);
703 }
else if (!_load_check_data.
HasErrors()) {
704 this->selected = file;
727 switch (this->abstract_filetype) {
728 default: NOT_REACHED();
749 if (y == INT_MAX)
return;
754 if (!this->fios_items_shown[i]) y++;
757 const FiosItem *file = &this->fios_items[y];
759 if (file != this->highlighted) {
760 this->highlighted = file;
763 }
else if (this->highlighted !=
nullptr) {
764 this->highlighted =
nullptr;
771 if (keycode == WKC_ESC) {
796 ShowQuery(STR_SAVELOAD_OVERWRITE_TITLE, STR_SAVELOAD_OVERWRITE_WARNING,
this, SaveLoadWindow::SaveGameConfirmationCallback);
803 ShowQuery(STR_SAVELOAD_OVERWRITE_TITLE, STR_SAVELOAD_OVERWRITE_WARNING,
this, SaveLoadWindow::SaveHeightmapConfirmationCallback);
829 this->selected =
nullptr;
831 if (!gui_scope)
break;
833 _fios_path_changed =
true;
834 this->fios_items.
BuildFileList(this->abstract_filetype, this->fop);
835 this->vscroll->
SetCount((uint)this->fios_items.size());
836 this->selected =
nullptr;
846 if (!gui_scope)
break;
850 switch (this->abstract_filetype) {
875 this->fios_items_shown.resize(this->fios_items.size());
876 uint items_shown_count = 0;
878 for (uint i = 0; i < this->fios_items.size(); i++) {
879 if (this->string_filter.
IsEmpty()) {
881 this->fios_items_shown[i] =
true;
885 this->string_filter.
AddLine(this->fios_items[i].title);
887 this->fios_items_shown[i] = this->string_filter.
GetState();
888 if (this->fios_items_shown[i]) items_shown_count++;
890 if (&(this->fios_items[i]) == this->selected && !this->fios_items_shown[i]) {
892 this->selected =
nullptr;
897 this->vscroll->
SetCount(items_shown_count);
void ShowNewGRFSettings(bool editable, bool show_params, bool exec_changes, GRFConfig **config)
Setup the NewGRF gui.
@ ES_HANDLED
The passed event is handled.
@ WC_SAVELOAD
Saveload window; Window numbers:
void ShowSaveLoadDialog(AbstractFileType abstract_filetype, SaveLoadOperation fop)
Launch save/load dialog in the given mode.
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.
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.
bool checkable
True if the savegame could be checked by SL_LOAD_CHECK. (Old savegames are not checkable....
@ FT_SCENARIO
old or new scenario
StringID FiosGetDescText(const char **path, uint64 *total_free)
Get descriptive texts.
@ SAVE_DIR
Base directory for all savegames.
int ok_button
Widget button of parent window to simulate when pressing OK in OSK.
QueryString filename_editbox
Filename editbox.
@ SLIWD_RESCAN_FILES
Rescan all files (when changed directory, ...)
static const NWidgetPart _nested_load_dialog_widgets[]
Load game/scenario with optional content download.
char32_t WChar
Type for wide characters, i.e.
@ SM_LOAD_GAME
Load game, Play Scenario.
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
Dimensions (a width and height) of a rectangle in 2D.
void DrawSortButtonState(int widget, SortButtonState state) const
Draw a sort button's up or down arrow symbol.
std::string _personal_dir
custom directory for personal settings, saves, newgrf, etc.
void OnTimeout() override
Called when this window's timeout has been reached.
const Scrollbar * GetScrollbar(uint widnum) const
Return the Scrollbar to a widget index.
QueryString filter_editbox
Filter editbox;.
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
void ClearGRFConfigList(GRFConfig **config)
Clear a GRF Config list, freeing all nodes.
bool IsEmpty() const
Check whether any filter words were entered.
struct LoggedAction * gamelog_action
Gamelog actions.
byte landscape
the landscape we're currently in
void SetTitle(const char *title)
Set the title of the file.
void SetFilterTerm(const char *str)
Set the term to filter on.
SaveOrLoadResult SaveOrLoad(const std::string &filename, SaveLoadOperation fop, DetailedFileType dft, Subdirectory sb, bool threaded)
Main Save or Load function where the high-level saveload functions are handled.
void Assign(StringID string)
Render a string into the textbuffer.
SaveLoadOperation
Operation performed on the file.
void OnResize() override
Called after the window got resized.
std::string name
Name of the file.
void CreateNestedTree(bool fill_nested=true)
Perform the first part of the initialization of a nested widget tree.
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
void GamelogFree(LoggedAction *gamelog_action, uint gamelog_actions)
Frees the memory allocated by a gamelog.
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.
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
@ SLO_CHECK
Load file for checking and/or preview.
void ShowMissingContentWindow(const GRFConfig *list)
Show the content list window with all missing grfs from the given list.
@ DFT_GAME_FILE
Save game or scenario file.
@ HEIGHTMAP_DIR
Subdirectory of scenario for heightmaps.
GRFConfig * grfconfig
NewGrf configuration from save.
void SetName(const char *name)
Set the name of the file.
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
std::string name
Name of the company if the user changed it.
ClientSettings _settings_client
The current settings for this game.
DetailedFileType GetDetailedFileType(FiosType fios_type)
Extract the detailed file type from a FiosType.
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.
static const NWidgetPart _nested_load_heightmap_dialog_widgets[]
Load heightmap with content download.
void AddLine(const char *str)
Pass another text line from the current item to the filter.
bool HasErrors()
Check whether loading the game resulted in errors.
@ SM_LOAD_SCENARIO
Load scenario from scenario editor.
void HandleButtonClick(byte widget)
Do all things to make a button look clicked and mark it to be unclicked in a few ticks.
void StartupEngines()
Start/initialise all our engines.
List of file information.
Rect WithHeight(int height, bool end=false) const
Copy Rect and set its height.
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
const FiosItem * selected
Selected game in fios_items, or nullptr.
Data stored about a string that can be modified in the GUI.
std::vector< bool > fios_items_shown
Map of the filtered out fios items.
Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize)
Return the string dimension in pixels.
uint32 name_2
Parameter of name_1.
char *const buf
buffer in which text is saved
SmallMap< int, QueryString * > querystrings
QueryString associated to WWT_EDITBOX widgets.
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.
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.
GameCreationSettings game_creation
settings used during the creation of a game (map)
High level window description.
AbstractFileType
The different abstract types of files that the system knows about.
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 ClearErrorMessages()
Clear all errors from the queue.
@ SLO_LOAD
File is being loaded.
ResizeInfo resize
Resize information.
@ SLO_SAVE
File is being saved.
std::string FiosMakeHeightmapName(const char *name)
Construct a filename for a height map.
@ PM_PAUSED_SAVELOAD
A game paused for saving/loading.
Rect Translate(int x, int y) const
Copy and translate Rect by x,y pixels.
bool FiosDelete(const char *name)
Delete a file.
@ SM_SAVE_HEIGHTMAP
Save heightmap.
@ SLIWD_FILTER_CHANGES
The filename filter has changed (via the editbox)
char * error_data
Data to pass to SetDParamStr when displaying error.
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
uint gamelog_actions
Number of gamelog actions.
SaveLoadOperation fop
Type of file to select.
void BuildFileList(AbstractFileType abstract_filetype, SaveLoadOperation fop)
Construct a file list with the given kind of files, for the stated purpose.
Date ConvertYMDToDate(Year year, Month month, Day day)
Converts a tuple of Year, Month and Day to a Date.
@ ES_NOT_HANDLED
The passed event is not handled.
Deals with finding savegames.
void SetWidgetDisabledState(byte widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
const char * FiosBrowseTo(const FiosItem *item)
Browse to a new path based on the passed item, starting at #_fios_path.
@ SCENARIO_DIR
Base directory for all scenarios.
@ SLIWD_SELECTION_CHANGES
File selection has changed (user click, ...)
bool _networking
are we in networking mode?
const FiosItem * highlighted
Item in fios_items highlighted by mouse pointer, or nullptr.
StringFilter string_filter
Filter for available games.
void GenerateFileName()
Generate a default save filename.
Coordinates of a point in 2D.
FileList fios_items
Save game list.
LoadCheckData _load_check_data
Data loaded from save during SL_LOAD_CHECK.
bool SetFocusedWidget(int widget_index)
Set focus within this window to the given widget.
@ FT_SAVEGAME
old or new savegame
static const uint8 PC_BLACK
Black palette colour.
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.
uint step_height
Step-size of height resize changes.
uint Vertical() const
Get total vertical padding of RectPadding.
void InvalidateData(int data=0, bool gui_scope=true)
Mark this window's data as invalid (in need of re-computing)
static const TextColour _fios_colours[]
Text colours of DetailedFileType fios entries in the window.
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
@ SA_HOR_CENTER
Horizontally center the text.
StringID error
Error message from loading. INVALID_STRING_ID if no error.
static const uint8 PC_GREY
Grey palette colour.
void ShowHeightmapLoad()
Start with loading a heightmap.
void GenerateDefaultSaveName(char *buf, const char *last)
Fill the buffer with the default name for a savegame or screenshot.
void OnPaint() override
The window must be repainted.
Container for loading in mode SL_LOAD_CHECK.
CompanyPropertiesMap companies
Company information.
SwitchMode _switch_mode
The next mainloop command.
uint32 StringID
Numeric value that represents a string, independent of the selected language.
void OnEditboxChanged(int wid) override
The text in an editbox has been edited.
void ShowQuery(StringID caption, StringID message, Window *parent, QueryCallbackProc *callback)
Show a modal confirmation window with standard 'yes' and 'no' buttons The window is aligned to the ce...
@ SBS_DOWN
Sort ascending.
int cancel_button
Widget button of parent window to simulate when pressing CANCEL in OSK.
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.
bool FioCheckFileExists(const std::string &filename, Subdirectory subdir)
Check whether the given file exists.
void Clear()
Reset read data.
#define FONT_HEIGHT_NORMAL
Height of characters in the normal (FS_NORMAL) font.
@ NO_DIRECTORY
A path without any base directory.
static const uint8 PC_DARK_BLUE
Dark blue palette colour.
void OnMouseOver(Point pt, int widget) override
The mouse is currently moving over the window or has just moved outside of the window.
FileToSaveLoad _file_to_saveload
File to save or load in the openttd loop.
void ResetState()
Reset the matching state to process a new item.
void UpdateSize()
Update Textbuf type with its actual physical character and screenlength Get the count of characters i...
bool IsWidgetLowered(byte widget_index) const
Gets the lowered state of a widget.
void Close() override
Hide the window and all its child windows, and mark them for a later deletion.
EventState
State of handling an event.
bool GetState() const
Get the matching state of the current item.
@ FT_HEIGHTMAP
heightmap file
static const uint8 PC_VERY_DARK_BLUE
Almost-black blue palette colour.
@ WC_MAIN_WINDOW
Main window; Window numbers:
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Year starting_year
starting date
GRFListCompatibility grf_compatibility
Summary state of NewGrfs, whether missing files or only compatible found.
@ WL_ERROR
Errors (eg. saving/loading failed)
static const int ACTION_CLEAR
Clear editbox.
FiosItem o_dir
Original dir (home dir for this browser)
#define lengthof(x)
Return the length of an fixed size array.
static int SortButtonWidth()
Get width of up/down arrow of sort button state.
void CloseWindowById(WindowClass cls, WindowNumber number, bool force)
Close a window by its class and window number (if it is open).
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
@ CONTENT_TYPE_SCENARIO
The content consists of a scenario.
bool HasNewGrfs()
Check whether the game uses any NewGrfs.
Data structure for an opened window.
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...
void DrawWidgets() const
Paint all widgets of a window.
std::string FiosMakeSavegameName(const char *name)
Make a save game or scenario filename from a name.
@ GLC_ALL_GOOD
All GRF needed by game are present.
static const NWidgetPart _nested_save_dialog_widgets[]
Save game/scenario.
EventState OnKeyPress(WChar key, uint16 keycode) override
A key has been pressed.
bool _network_available
is network mode available?
char * strecpy(char *dst, const char *src, const char *last)
Copies characters from one buffer to another.
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
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...
void SetWidgetDirty(byte widget_index) const
Invalidate a widget, i.e.
bool UserIsAllowedToChangeNewGRFs() const
Returns true when the user has sufficient privileges to edit newgrfs on a running game.
Specification of a rectangle with absolute coordinates of all edges.
void LowerWidget(byte widget_index)
Marks a widget as lowered.
static void SortSaveGameList(FileList &file_list)
Sort the collected list save games prior to displaying it in the save/load gui.
@ CONTENT_TYPE_HEIGHTMAP
The content consists of a heightmap.
#define lastof(x)
Get the last element of an fixed size array.
@ GLC_NOT_FOUND
At least one GRF couldn't be found (higher priority than GLC_COMPATIBLE)
void ResetObjectToPlace()
Reset the cursor and mouse mode handling back to default (normal cursor, only clicking in windows).
@ WDP_CENTER
Center the window.
Statically loadable part of Company pool item.
void SetDParamStr(uint n, const char *str)
This function is used to "bind" a C string to a OpenTTD dparam slot.
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
GUISettings gui
settings related to the GUI
StringID name_1
Name of the company if the user did not change it.
virtual void Close()
Hide the window and all its child windows, and mark them for a later deletion.