OpenTTD Source
12.0-beta2
|
Go to the documentation of this file.
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;
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 auto &item : file_list) {
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.begin() + sort_start, file_list.end() - sort_end);
266 static const uint EDITBOX_MAX_SIZE = 50;
281 static void SaveGameConfirmationCallback(
Window *w,
bool confirmed)
287 static void SaveHeightmapConfirmationCallback(
Window *w,
bool confirmed)
298 GenerateDefaultSaveName(this->filename_editbox.text.
buf, &this->filename_editbox.text.buf[this->filename_editbox.text.max_bytes - 1]);
309 switch (this->abstract_filetype) {
316 this->filename_editbox.text.
Assign(
"UNNAMED");
333 switch (this->abstract_filetype) {
335 caption_string = (this->fop ==
SLO_SAVE) ? STR_SAVELOAD_SAVE_CAPTION : STR_SAVELOAD_LOAD_CAPTION;
339 caption_string = (this->fop ==
SLO_SAVE) ? STR_SAVELOAD_SAVE_SCENARIO : STR_SAVELOAD_LOAD_SCENARIO;
343 caption_string = (this->fop ==
SLO_SAVE) ? STR_SAVELOAD_SAVE_HEIGHTMAP : STR_SAVELOAD_LOAD_HEIGHTMAP;
349 this->GetWidget<NWidgetCore>(
WID_SL_CAPTION)->widget_data = caption_string;
360 if (_game_mode != GM_MENU && !
_networking && _game_mode != GM_EDITOR) {
370 o_dir.type = FIOS_TYPE_DIRECT;
372 switch (this->abstract_filetype) {
404 if (!
_networking && _game_mode != GM_EDITOR && _game_mode != GM_MENU) {
421 static const char *path =
nullptr;
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.size(); row++) {
442 if (!this->fios_items_shown[row]) {
447 if (row < scroll_pos)
continue;
448 const FiosItem *item = &this->fios_items[row];
450 if (item == this->selected) {
452 }
else if (item == this->highlighted) {
467 if (this->selected ==
nullptr)
break;
472 if (y > y_max)
break;
488 if (y > y_max)
break;
492 if (landscape < NUM_LANDSCAPE) {
493 SetDParam(0, STR_CHEAT_SWITCH_CLIMATE_TEMPERATE_LANDSCAPE + landscape);
499 if (y > y_max)
break;
507 if (y > y_max)
break;
520 if (y > y_max)
break;
528 if (y > y_max)
break;
533 if (y > y_max)
break;
539 if (!c.
name.empty()) {
548 if (y > y_max)
break;
572 d.height += padding.height;
581 if (_savegame_sort_dirty) {
582 _savegame_sort_dirty =
false;
594 _savegame_sort_order = (_savegame_sort_order == SORT_BY_NAME) ?
595 SORT_BY_NAME | SORT_DESCENDING : SORT_BY_NAME;
596 _savegame_sort_dirty =
true;
601 _savegame_sort_order = (_savegame_sort_order == SORT_BY_DATE) ?
602 SORT_BY_DATE | SORT_DESCENDING : SORT_BY_DATE;
603 _savegame_sort_dirty =
true;
647 if (y == INT_MAX)
return;
652 if (!this->fios_items_shown[i]) y++;
655 const FiosItem *file = &this->fios_items[y];
658 if (name ==
nullptr) {
664 if (click_count == 1) {
665 if (this->selected != file) {
666 this->selected = file;
678 this->filename_editbox.text.
Assign(file->title);
681 }
else if (!_load_check_data.
HasErrors()) {
682 this->selected = file;
705 switch (this->abstract_filetype) {
706 default: NOT_REACHED();
730 if (y == INT_MAX)
return;
735 if (!this->fios_items_shown[i]) y++;
738 const FiosItem *file = &this->fios_items[y];
740 if (file != this->highlighted) {
741 this->highlighted = file;
744 }
else if (this->highlighted !=
nullptr) {
745 this->highlighted =
nullptr;
752 if (keycode == WKC_ESC) {
777 ShowQuery(STR_SAVELOAD_OVERWRITE_TITLE, STR_SAVELOAD_OVERWRITE_WARNING,
this, SaveLoadWindow::SaveGameConfirmationCallback);
784 ShowQuery(STR_SAVELOAD_OVERWRITE_TITLE, STR_SAVELOAD_OVERWRITE_WARNING,
this, SaveLoadWindow::SaveHeightmapConfirmationCallback);
810 this->selected =
nullptr;
812 if (!gui_scope)
break;
814 _fios_path_changed =
true;
815 this->fios_items.
BuildFileList(this->abstract_filetype, this->fop);
816 this->vscroll->
SetCount((uint)this->fios_items.size());
817 this->selected =
nullptr;
827 if (!gui_scope)
break;
831 switch (this->abstract_filetype) {
856 this->fios_items_shown.resize(this->fios_items.size());
857 uint items_shown_count = 0;
859 for (uint i = 0; i < this->fios_items.size(); i++) {
860 if (this->string_filter.
IsEmpty()) {
862 this->fios_items_shown[i] =
true;
866 this->string_filter.
AddLine(this->fios_items[i].title);
868 this->fios_items_shown[i] = this->string_filter.
GetState();
869 if (this->fios_items_shown[i]) items_shown_count++;
871 if (&(this->fios_items[i]) == this->selected && !this->fios_items_shown[i]) {
873 this->selected =
nullptr;
878 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.
@ WD_FRAMERECT_TOP
Offset at top to draw the frame rectangular area.
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;.
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.
@ WD_FRAMETEXT_LEFT
Left offset of the text of the frame.
List of file information.
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.
bool DoCommandP(const CommandContainer *container, bool my_cmd)
Shortcut for the long DoCommandP when having a container with the data.
bool FiosDelete(const char *name)
Delete a file.
@ CMD_PAUSE
pause the game
@ 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.
@ WD_FRAMERECT_LEFT
Offset at left to draw the frame rectangular area.
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.
@ WD_PAR_VSEP_NORMAL
Normal amount of vertical space between two paragraphs of text.
@ WD_FRAMERECT_RIGHT
Offset at right to draw the frame rectangular area.
@ ES_NOT_HANDLED
The passed event is not handled.
@ WD_FRAMERECT_BOTTOM
Offset at bottom to draw the frame rectangular area.
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.
int left
x position of left edge of the window
@ 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.
@ WD_FRAMETEXT_RIGHT
Right offset of the text of the frame.
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.
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.
void OnMouseLoop() override
Called for every mouse loop run, which is at least once per (game) tick.
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.
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.
int top
y position of top edge of the window
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.
Point pos
logical mouse position
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.