34 #include "table/strings.h" 40 static bool _fios_path_changed;
41 static bool _savegame_sort_dirty;
54 this->map_size_x = this->map_size_y = 256;
55 this->current_date = 0;
56 memset(&this->settings, 0,
sizeof(this->settings));
88 SetDataTip(STR_LIST_FILTER_OSKTITLE, STR_LIST_FILTER_TOOLTIP),
107 SetDataTip(STR_INTRO_ONLINE_CONTENT, STR_INTRO_TOOLTIP_ONLINE_CONTENT),
143 SetDataTip(STR_LIST_FILTER_OSKTITLE, STR_LIST_FILTER_TOOLTIP),
162 SetDataTip(STR_INTRO_ONLINE_CONTENT, STR_INTRO_TOOLTIP_ONLINE_CONTENT),
164 SetDataTip(STR_SAVELOAD_LOAD_BUTTON, STR_SAVELOAD_LOAD_HEIGHTMAP_TOOLTIP),
188 SetDataTip(STR_LIST_FILTER_OSKTITLE, STR_LIST_FILTER_TOOLTIP),
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),
245 size_t sort_start = 0;
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;
261 std::sort(file_list.
files.begin() + sort_start, file_list.
files.end() - sort_end);
266 static const uint EDITBOX_MAX_SIZE = 50;
280 static void SaveGameConfirmationCallback(
Window *w,
bool confirmed)
286 static void SaveHeightmapConfirmationCallback(
Window *w,
bool confirmed)
297 GenerateDefaultSaveName(this->filename_editbox.text.
buf, &this->filename_editbox.text.buf[this->filename_editbox.text.max_bytes - 1]);
302 :
Window(desc), filename_editbox(64), abstract_filetype(abstract_filetype), fop(fop), filter_editbox(EDITBOX_MAX_SIZE)
308 switch (this->abstract_filetype) {
310 this->GenerateFileName();
315 this->filename_editbox.text.
Assign(
"UNNAMED");
325 this->CreateNestedTree(
true);
332 switch (this->abstract_filetype) {
334 caption_string = (this->fop ==
SLO_SAVE) ? STR_SAVELOAD_SAVE_CAPTION : STR_SAVELOAD_LOAD_CAPTION;
338 caption_string = (this->fop ==
SLO_SAVE) ? STR_SAVELOAD_SAVE_SCENARIO : STR_SAVELOAD_LOAD_SCENARIO;
342 caption_string = (this->fop ==
SLO_SAVE) ? STR_SAVELOAD_SAVE_HEIGHTMAP : STR_SAVELOAD_LOAD_HEIGHTMAP;
348 this->GetWidget<NWidgetCore>(
WID_SL_CAPTION)->widget_data = caption_string;
351 this->FinishInitNested(0);
359 if (_game_mode != GM_MENU && !
_networking && _game_mode != GM_EDITOR) {
369 o_dir.type = FIOS_TYPE_DIRECT;
370 switch (this->abstract_filetype) {
401 if (!
_networking && _game_mode != GM_EDITOR && _game_mode != GM_MENU) {
412 this->DrawSortButtonState(widget, _savegame_sort_order & SORT_DESCENDING ?
SBS_DOWN :
SBS_UP);
417 static const char *path =
nullptr;
418 static StringID str = STR_ERROR_UNABLE_TO_READ_DRIVE;
419 static uint64 tot = 0;
421 if (_fios_path_changed) {
423 _fios_path_changed =
false;
426 if (str != STR_ERROR_UNABLE_TO_READ_DRIVE)
SetDParam(0, tot);
437 for (uint row = 0; row < this->fios_items.
Length(); row++) {
438 if (!this->fios_items_shown[row]) {
443 if (row < scroll_pos)
continue;
446 if (item == this->selected) {
450 y += this->resize.step_height;
461 if (this->selected ==
nullptr)
break;
466 if (y > y_max)
break;
475 y, r.bottom - WD_FRAMERECT_BOTTOM, _load_check_data.
error, TC_RED);
478 SetDParam(0, _load_check_data.map_size_x);
479 SetDParam(1, _load_check_data.map_size_y);
482 if (y > y_max)
break;
486 if (landscape < NUM_LANDSCAPE) {
487 SetDParam(0, STR_CHEAT_SWITCH_CLIMATE_TEMPERATE_LANDSCAPE + landscape);
493 if (y > y_max)
break;
501 if (y > y_max)
break;
506 SetDParam(0, _load_check_data.current_date);
514 if (y > y_max)
break;
522 if (y > y_max)
break;
527 if (y > y_max)
break;
530 for (
auto &pair : _load_check_data.
companies) {
533 if (c.
name !=
nullptr) {
542 if (y > y_max)
break;
566 d.height += padding.height;
575 if (_savegame_sort_dirty) {
576 _savegame_sort_dirty =
false;
588 _savegame_sort_order = (_savegame_sort_order == SORT_BY_NAME) ?
589 SORT_BY_NAME | SORT_DESCENDING : SORT_BY_NAME;
590 _savegame_sort_dirty =
true;
595 _savegame_sort_order = (_savegame_sort_order == SORT_BY_DATE) ?
596 SORT_BY_DATE | SORT_DESCENDING : SORT_BY_DATE;
597 _savegame_sort_dirty =
true;
607 if (this->selected ==
nullptr || _load_check_data.
HasErrors())
break;
641 if (y == INT_MAX)
return;
646 if (!this->fios_items_shown[i]) y++;
652 if (name ==
nullptr) {
658 if (click_count == 1) {
659 if (this->selected != file) {
660 this->selected = file;
661 _load_check_data.
Clear();
672 this->filename_editbox.text.
Assign(file->title);
675 }
else if (!_load_check_data.
HasErrors()) {
676 this->selected = file;
699 switch (this->abstract_filetype) {
700 default: NOT_REACHED();
719 if (keycode == WKC_ESC) {
738 if (this->abstract_filetype ==
FT_SAVEGAME) GenerateFileName();
744 ShowQuery(STR_SAVELOAD_OVERWRITE_TITLE, STR_SAVELOAD_OVERWRITE_WARNING,
this, SaveLoadWindow::SaveGameConfirmationCallback);
751 ShowQuery(STR_SAVELOAD_OVERWRITE_TITLE, STR_SAVELOAD_OVERWRITE_WARNING,
this, SaveLoadWindow::SaveHeightmapConfirmationCallback);
777 this->selected =
nullptr;
778 _load_check_data.
Clear();
779 if (!gui_scope)
break;
781 _fios_path_changed =
true;
782 this->fios_items.
BuildFileList(this->abstract_filetype, this->fop);
784 this->selected =
nullptr;
785 _load_check_data.
Clear();
794 if (!gui_scope)
break;
798 switch (this->abstract_filetype) {
805 bool disabled = this->selected ==
nullptr || _load_check_data.
HasErrors();
823 this->fios_items_shown.resize(this->fios_items.
Length());
824 uint items_shown_count = 0;
826 for (uint i = 0; i < this->fios_items.
Length(); i++) {
827 if (this->string_filter.
IsEmpty()) {
829 this->fios_items_shown[i] =
true;
833 this->string_filter.
AddLine(this->fios_items[i].title);
835 this->fios_items_shown[i] = this->string_filter.
GetState();
836 if (this->fios_items_shown[i]) items_shown_count++;
838 if (&(this->fios_items[i]) == this->selected && this->fios_items_shown[i] ==
false) {
840 this->selected =
nullptr;
845 this->vscroll->
SetCount(items_shown_count);
864 _nested_load_dialog_widgets,
lengthof(_nested_load_dialog_widgets)
872 _nested_load_heightmap_dialog_widgets,
lengthof(_nested_load_heightmap_dialog_widgets)
880 _nested_save_dialog_widgets,
lengthof(_nested_save_dialog_widgets)
897 sld = (abstract_filetype ==
FT_HEIGHTMAP) ? &_load_heightmap_dialog_desc : &_load_dialog_desc;
EventState
State of handling an event.
static const NWidgetPart _nested_load_heightmap_dialog_widgets[]
Load heightmap with content download.
Functions related to OTTD's strings.
AbstractFileType
The different abstract types of files that the system knows about.
static const TextColour _fios_colours[]
Text colours of DetailedFileType fios entries in the window.
bool _networking
are we in networking mode?
Horizontally center the text.
const FiosItem * Get(size_t index) const
Get a pointer to the indicated file information.
char * name
Name of the company if the user changed it.
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...
Container for loading in mode SL_LOAD_CHECK.
byte landscape
the landscape we're currently in
High level window description.
void GenerateDefaultSaveName(char *buf, const char *last)
Fill the buffer with the default name for a savegame or screenshot.
Saveload window; Window numbers:
All GRF needed by game are present.
struct LoggedAction * gamelog_action
Gamelog actions.
void SetName(const char *name)
Set the name of the file.
Functions related to dates.
std::vector< FiosItem > files
The list of files.
void ClearGRFConfigList(GRFConfig **config)
Clear a GRF Config list, freeing all nodes.
Load game, Play Scenario.
Offset at top to draw the frame rectangular area.
Normal amount of vertical space between two paragraphs of text.
void ResetState()
Reset the matching state to process a new item.
The passed event is not handled.
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.
The content consists of a scenario.
FileToSaveLoad _file_to_saveload
File to save or load in the openttd loop.
void OnEditboxChanged(int wid) override
The text in an editbox has been edited.
Subdirectory of scenario for heightmaps.
void GenerateFileName()
Generate a default save filename.
static const int ACTION_CLEAR
Clear editbox.
FileList fios_items
Save game list.
GRFConfig * grfconfig
NewGrf configuration from save.
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.
const FiosItem * Begin() const
Get a pointer to the first file information.
Functions for Standard In/Out file operations.
DetailedFileType GetDetailedFileType(FiosType fios_type)
Extract the detailed file type from a FiosType.
#define lastof(x)
Get the last element of an fixed size array.
uint32 name_2
Parameter of name_1.
File selection has changed (user click, ...)
Deals with finding savegames.
Load file for checking and/or preview.
StringID FiosGetDescText(const char **path, uint64 *total_free)
Get descriptive texts.
void OnTimeout() override
Called when this window's timeout has been reached.
bool _network_available
is network mode available?
QueryString filter_editbox
Filter editbox;.
Base for the GUIs that have an edit box in them.
Data structure for an opened window.
Save game or scenario file.
bool checkable
True if the savegame could be checked by SL_LOAD_CHECK. (Old savegames are not checkable.)
void SetFilterTerm(const char *str)
Set the term to filter on.
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.
Main window; Window numbers:
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.
Base directory for all scenarios.
const FiosItem * End() const
Get a pointer behind the last file information.
void SetTitle(const char *title)
Set the title of the file.
Functions/types related to saving and loading games.
void FiosMakeSavegameName(char *buf, const char *name, const char *last)
Make a save game or scenario filename from a name.
Functions related to errors.
void GamelogFree(LoggedAction *gamelog_action, uint gamelog_actions)
Frees the memory allocated by a gamelog.
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...
Functions related to engines.
int ok_button
Widget button of parent window to simulate when pressing OK in OSK.
A game paused for saving/loading.
CompanyPropertiesMap companies
Company information.
Statically loadable part of Company pool item.
#define FONT_HEIGHT_NORMAL
Height of characters in the normal (FS_NORMAL) font.
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.
A path without any base directory.
Definition of base types and functions in a cross-platform compatible way.
void Clear()
Reset read data.
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...
Base directory for all savegames.
void BuildFileList(AbstractFileType abstract_filetype, SaveLoadOperation fop)
Construct a file list with the given kind of files, for the stated purpose.
static void SortSaveGameList(FileList &file_list)
Sort the collected list save games prior to displaying it in the save/load gui.
const char * _personal_dir
custom directory for personal settings, saves, newgrf, etc.
char * error_data
Data to pass to SetDParamStr when displaying error.
bool HasErrors()
Check whether loading the game resulted in errors.
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.
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.
EventState OnKeyPress(WChar key, uint16 keycode) override
A key has been pressed.
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.
Right offset of the text of the frame.
bool DoCommandP(const CommandContainer *container, bool my_cmd)
Shortcut for the long DoCommandP when having a container with the data.
The filename filter has changed (via the editbox)
#define lengthof(x)
Return the length of an fixed size array.
Left offset of the text of the frame.
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.
static int SortButtonWidth()
Get width of up/down arrow of sort button state.
StringID error
Error message from loading. INVALID_STRING_ID if no error.
SaveLoadOperation fop
Type of file to select.
uint32 StringID
Numeric value that represents a string, independent of the selected language.
static const uint8 PC_BLACK
Black palette colour.
SaveLoadOperation
Operation performed on the file.
void Assign(StringID string)
Render a string into the textbuffer.
Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize)
Return the string dimension in pixels.
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
void AddLine(const char *str)
Pass another text line from the current item to the filter.
bool FiosDelete(const char *name)
Delete a file.
void StartupEngines()
Start/initialise all our engines.
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
No window, redirects to WC_MAIN_WINDOW.
void DeleteWindowById(WindowClass cls, WindowNumber number, bool force)
Delete a window by its class and window number (if it is open).
static const uint8 PC_GREY
Grey palette colour.
static const uint8 PC_DARK_BLUE
Dark blue palette colour.
void ShowSaveLoadDialog(AbstractFileType abstract_filetype, SaveLoadOperation fop)
Launch save/load dialog in the given mode.
void OnResize() override
Called after the window got resized.
void FiosMakeHeightmapName(char *buf, const char *name, const char *last)
Construct a filename for a height map.
char *const buf
buffer in which text is saved
void ShowNewGRFSettings(bool editable, bool show_params, bool exec_changes, GRFConfig **config)
Setup the NewGRF gui.
GUISettings gui
settings related to the GUI
QueryString filename_editbox
Filename editbox.
void ClearErrorMessages()
Clear all errors from the queue.
Declarations for savegames operations.
Types related to the landscape.
LoadCheckData _load_check_data
Data loaded from save during SL_LOAD_CHECK.
The content consists of a heightmap.
StringID name_1
Name of the company if the user did not change it.
List of file information.
At least one GRF couldn't be found (higher priority than GLC_COMPATIBLE)
const char * FiosBrowseTo(const FiosItem *item)
Browse to a new path based on the passed item, starting at #_fios_path.
Searching and filtering using a stringterm.
static const NWidgetPart _nested_load_dialog_widgets[]
Load game/scenario with optional content download.
char * strecpy(char *dst, const char *src, const char *last)
Copies characters from one buffer to another.
SwitchMode _switch_mode
The next mainloop command.
uint gamelog_actions
Number of gamelog actions.
Rescan all files (when changed directory, ...)
Functions related to commands.
char name[MAX_PATH]
Name of the file.
Coordinates of a point in 2D.
AbstractFileType abstract_ftype
Abstract type of file (scenario, heightmap, etc).
const FiosItem * selected
Selected game in fios_items, or nullptr.
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...
Load scenario from scenario editor.
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)
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.
Offset at right to draw the frame rectangular area.
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
StringFilter string_filter
Filter for available games.
bool HasNewGrfs()
Check whether the game uses any NewGrfs.
GameCreationSettings game_creation
settings used during the creation of a game (map)
void ResetObjectToPlace()
Reset the cursor and mouse mode handling back to default (normal cursor, only clicking in windows)...
Specification of a rectangle with absolute coordinates of all edges.
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...
The passed event is handled.
Date ConvertYMDToDate(Year year, Month month, Day day)
Converts a tuple of Year, Month and Day to a Date.
Functions related to tile highlights.
Window functions not directly related to making/drawing windows.
void OnPaint() override
The window must be repainted.
GUI functions that shouldn't be here.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Errors (eg. saving/loading failed)
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.
uint32 WChar
Type for wide characters, i.e.
Dimensions (a width and height) of a rectangle in 2D.
GRFListCompatibility grf_compatibility
Summary state of NewGrfs, whether missing files or only compatible found.
bool IsEmpty() const
Check whether any filter words were entered.
Offset at left to draw the frame rectangular area.
Year starting_year
starting date
This file contains all sprite-related enums and defines.
static const NWidgetPart _nested_save_dialog_widgets[]
Save game/scenario.
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.
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.
void UpdateSize()
Update Textbuf type with its actual physical character and screenlength Get the count of characters i...
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.