36 #include "table/strings.h" 42 static bool _fios_path_changed;
43 static bool _savegame_sort_dirty;
56 this->map_size_x = this->map_size_y = 256;
57 this->current_date = 0;
58 memset(&this->settings, 0,
sizeof(this->settings));
91 SetDataTip(STR_LIST_FILTER_OSKTITLE, STR_LIST_FILTER_TOOLTIP),
110 SetDataTip(STR_INTRO_ONLINE_CONTENT, STR_INTRO_TOOLTIP_ONLINE_CONTENT),
146 SetDataTip(STR_LIST_FILTER_OSKTITLE, STR_LIST_FILTER_TOOLTIP),
165 SetDataTip(STR_INTRO_ONLINE_CONTENT, STR_INTRO_TOOLTIP_ONLINE_CONTENT),
167 SetDataTip(STR_SAVELOAD_LOAD_BUTTON, STR_SAVELOAD_LOAD_HEIGHTMAP_TOOLTIP),
191 SetDataTip(STR_LIST_FILTER_OSKTITLE, STR_LIST_FILTER_TOOLTIP),
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),
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;
264 uint s_amount = file_list.
Length() - sort_start - sort_end;
270 static const uint EDITBOX_MAX_SIZE = 50;
284 static void SaveGameConfirmationCallback(
Window *w,
bool confirmed)
290 static void SaveHeightmapConfirmationCallback(
Window *w,
bool confirmed)
301 GenerateDefaultSaveName(this->filename_editbox.text.
buf, &this->filename_editbox.text.buf[this->filename_editbox.text.max_bytes - 1]);
306 :
Window(desc), filename_editbox(64), abstract_filetype(abstract_filetype), fop(fop), filter_editbox(EDITBOX_MAX_SIZE)
312 switch (this->abstract_filetype) {
314 this->GenerateFileName();
319 this->filename_editbox.text.
Assign(
"UNNAMED");
329 this->CreateNestedTree(
true);
336 switch (this->abstract_filetype) {
338 caption_string = (this->fop ==
SLO_SAVE) ? STR_SAVELOAD_SAVE_CAPTION : STR_SAVELOAD_LOAD_CAPTION;
342 caption_string = (this->fop ==
SLO_SAVE) ? STR_SAVELOAD_SAVE_SCENARIO : STR_SAVELOAD_LOAD_SCENARIO;
346 caption_string = (this->fop ==
SLO_SAVE) ? STR_SAVELOAD_SAVE_HEIGHTMAP : STR_SAVELOAD_LOAD_HEIGHTMAP;
352 this->GetWidget<NWidgetCore>(
WID_SL_CAPTION)->widget_data = caption_string;
355 this->FinishInitNested(0);
363 if (_game_mode != GM_MENU && !
_networking && _game_mode != GM_EDITOR) {
373 o_dir.type = FIOS_TYPE_DIRECT;
374 switch (this->abstract_filetype) {
405 if (!
_networking && _game_mode != GM_EDITOR && _game_mode != GM_MENU) {
416 this->DrawSortButtonState(widget, _savegame_sort_order & SORT_DESCENDING ?
SBS_DOWN :
SBS_UP);
421 static const char *path = NULL;
422 static StringID str = STR_ERROR_UNABLE_TO_READ_DRIVE;
423 static uint64 tot = 0;
425 if (_fios_path_changed) {
427 _fios_path_changed =
false;
430 if (str != STR_ERROR_UNABLE_TO_READ_DRIVE)
SetDParam(0, tot);
441 for (uint row = 0; row < this->fios_items.
Length(); row++) {
442 if (!this->fios_items_shown[row]) {
447 if (row < scroll_pos)
continue;
450 if (item == this->selected) {
454 y += this->resize.step_height;
465 if (this->selected == NULL)
break;
470 if (y > y_max)
break;
479 y, r.bottom - WD_FRAMERECT_BOTTOM, _load_check_data.
error, TC_RED);
482 SetDParam(0, _load_check_data.map_size_x);
483 SetDParam(1, _load_check_data.map_size_y);
486 if (y > y_max)
break;
490 if (landscape < NUM_LANDSCAPE) {
491 SetDParam(0, STR_CHEAT_SWITCH_CLIMATE_TEMPERATE_LANDSCAPE + landscape);
497 if (y > y_max)
break;
505 if (y > y_max)
break;
510 SetDParam(0, _load_check_data.current_date);
518 if (y > y_max)
break;
526 if (y > y_max)
break;
531 if (y > y_max)
break;
538 if (c.
name != NULL) {
547 if (y > y_max)
break;
571 d.height += padding.height;
580 if (_savegame_sort_dirty) {
581 _savegame_sort_dirty =
false;
593 _savegame_sort_order = (_savegame_sort_order == SORT_BY_NAME) ?
594 SORT_BY_NAME | SORT_DESCENDING : SORT_BY_NAME;
595 _savegame_sort_dirty =
true;
600 _savegame_sort_order = (_savegame_sort_order == SORT_BY_DATE) ?
601 SORT_BY_DATE | SORT_DESCENDING : SORT_BY_DATE;
602 _savegame_sort_dirty =
true;
612 if (this->selected != NULL && !_load_check_data.
HasErrors()) {
640 #if defined(ENABLE_NETWORK) 648 if (y == INT_MAX)
return;
653 if (!this->fios_items_shown[i]) y++;
660 if (click_count == 1) {
661 if (this->selected != file) {
662 this->selected = file;
663 _load_check_data.
Clear();
674 this->filename_editbox.text.
Assign(file->title);
677 }
else if (!_load_check_data.
HasErrors()) {
678 this->selected = file;
704 #if defined(ENABLE_NETWORK) 706 switch (this->abstract_filetype) {
707 default: NOT_REACHED();
727 if (keycode == WKC_ESC) {
746 if (this->abstract_filetype ==
FT_SAVEGAME) GenerateFileName();
752 ShowQuery(STR_SAVELOAD_OVERWRITE_TITLE, STR_SAVELOAD_OVERWRITE_WARNING,
this, SaveLoadWindow::SaveGameConfirmationCallback);
759 ShowQuery(STR_SAVELOAD_OVERWRITE_TITLE, STR_SAVELOAD_OVERWRITE_WARNING,
this, SaveLoadWindow::SaveHeightmapConfirmationCallback);
785 this->selected = NULL;
786 _load_check_data.
Clear();
787 if (!gui_scope)
break;
789 _fios_path_changed =
true;
790 this->fios_items.
BuildFileList(this->abstract_filetype, this->fop);
792 this->selected = NULL;
793 _load_check_data.
Clear();
802 if (!gui_scope)
break;
806 switch (this->abstract_filetype) {
813 bool disabled = this->selected == NULL || _load_check_data.
HasErrors();
831 this->fios_items_shown.
Resize(this->fios_items.
Length());
832 uint items_shown_count = 0;
834 for (uint i = 0; i < this->fios_items.
Length(); i++) {
835 if (this->string_filter.
IsEmpty()) {
837 this->fios_items_shown[i] =
true;
841 this->string_filter.
AddLine(this->fios_items[i].title);
843 this->fios_items_shown[i] = this->string_filter.
GetState();
844 if (this->fios_items_shown[i]) items_shown_count++;
846 if (&(this->fios_items[i]) == this->selected && this->fios_items_shown[i] ==
false) {
848 this->selected = NULL;
853 this->vscroll->
SetCount(items_shown_count);
872 _nested_load_dialog_widgets,
lengthof(_nested_load_dialog_widgets)
880 _nested_load_heightmap_dialog_widgets,
lengthof(_nested_load_heightmap_dialog_widgets)
888 _nested_save_dialog_widgets,
lengthof(_nested_save_dialog_widgets)
905 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.
virtual void OnPaint()
The window must be repainted.
bool _networking
are we in networking mode?
Horizontally center the text.
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
SmallVector< bool, 32 > fios_items_shown
Map of the filtered out fios items.
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.
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.
The content consists of a scenario.
FileToSaveLoad _file_to_saveload
File to save or load in the openttd loop.
Subdirectory of scenario for heightmaps.
void GenerateFileName()
Generate a default save filename.
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.
void Clear()
Remove all items from the list.
GRFConfig * grfconfig
NewGrf configuration from save.
const T * Begin() const
Get the pointer to the first item (const)
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, ...)
const T * End() const
Get the pointer behind the last valid item (const)
Deals with finding savegames.
Load file for checking and/or preview.
StringID FiosGetDescText(const char **path, uint64 *total_free)
Get descriptive texts.
bool _network_available
is network mode available?
QueryString filter_editbox
Filter editbox;.
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.
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 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.
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.
uint Length() const
Get the number of files in the list.
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.
virtual EventState OnKeyPress(WChar key, uint16 keycode)
A key has been pressed.
virtual void DrawWidget(const Rect &r, int widget) const
Draw the contents of a nested widget.
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.
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.
virtual void OnInvalidateData(int data=0, bool gui_scope=true)
Some data on this window has become invalid.
virtual void OnTimeout()
Called when this window's timeout has been reached.
const FiosItem * Get(uint index) const
Get a pointer to the indicated file information.
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.
virtual void OnResize()
Called after the window got resized.
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.
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.
int CDECL CompareFiosItems(const FiosItem *da, const FiosItem *db)
Compare two FiosItem's.
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 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.
virtual void OnEditboxChanged(int wid)
The text in an editbox has been edited.
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 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.
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.
AbstractFileType abstract_ftype
Abstract type of file (scenario, heightmap, etc).
const FiosItem * selected
Selected game in fios_items, or NULL.
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.
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.
A game paused for saving/loading.
Functions related to tile highlights.
Window functions not directly related to making/drawing windows.
GUI functions that shouldn't be here.
Errors (eg. saving/loading failed)
static void QSortT(T *base, uint num, int(CDECL *comparator)(const T *, const T *), bool desc=false)
Type safe qsort()
uint32 WChar
Type for wide characters, i.e.
virtual void OnClick(Point pt, int widget, int click_count)
A click with the left mouse button has been made on the window.
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.
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.