37 #include "table/strings.h"
43 static bool _fios_path_changed;
44 static bool _savegame_sort_dirty;
55 this->map_size_x = this->map_size_y = 256;
56 this->current_date = 0;
86 SetDataTip(STR_LIST_FILTER_OSKTITLE, STR_LIST_FILTER_TOOLTIP),
109 SetDataTip(STR_INTRO_ONLINE_CONTENT, STR_INTRO_TOOLTIP_ONLINE_CONTENT),
146 SetDataTip(STR_LIST_FILTER_OSKTITLE, STR_LIST_FILTER_TOOLTIP),
169 SetDataTip(STR_INTRO_ONLINE_CONTENT, STR_INTRO_TOOLTIP_ONLINE_CONTENT),
171 SetDataTip(STR_SAVELOAD_LOAD_BUTTON, STR_SAVELOAD_LOAD_HEIGHTMAP_TOOLTIP),
213 SetDataTip(STR_SAVELOAD_LOAD_BUTTON, STR_SAVELOAD_LOAD_TOWN_DATA_TOOLTIP),
238 SetDataTip(STR_LIST_FILTER_OSKTITLE, STR_LIST_FILTER_TOOLTIP),
259 NWidget(
WWT_EDITBOX, COLOUR_GREY,
WID_SL_SAVE_OSK_TITLE),
SetPadding(2, 2, 2, 2),
SetFill(1, 0),
SetResize(1, 0),
260 SetDataTip(STR_SAVELOAD_OSKTITLE, STR_SAVELOAD_EDITBOX_TOOLTIP),
303 size_t sort_start = 0;
310 for (
const auto &item : file_list) {
312 case FIOS_TYPE_DIR: sort_start++;
break;
313 case FIOS_TYPE_PARENT: sort_start++;
break;
314 case FIOS_TYPE_DRIVE: sort_end++;
break;
319 std::sort(file_list.begin() + sort_start, file_list.end() - sort_end);
324 static const uint EDITBOX_MAX_SIZE = 50;
339 static void SaveGameConfirmationCallback(
Window *,
bool confirmed)
345 static void SaveHeightmapConfirmationCallback(
Window *,
bool confirmed)
366 switch (this->abstract_filetype) {
373 this->filename_editbox.text.
Assign(
"UNNAMED");
391 switch (this->abstract_filetype) {
393 caption_string = (this->fop ==
SLO_SAVE) ? STR_SAVELOAD_SAVE_CAPTION : STR_SAVELOAD_LOAD_CAPTION;
397 caption_string = (this->fop ==
SLO_SAVE) ? STR_SAVELOAD_SAVE_SCENARIO : STR_SAVELOAD_LOAD_SCENARIO;
401 caption_string = (this->fop ==
SLO_SAVE) ? STR_SAVELOAD_SAVE_HEIGHTMAP : STR_SAVELOAD_LOAD_HEIGHTMAP;
405 caption_string = STR_SAVELOAD_LOAD_TOWN_DATA;
411 this->GetWidget<NWidgetCore>(
WID_SL_CAPTION)->widget_data = caption_string;
422 if (_game_mode != GM_MENU && !
_networking && _game_mode != GM_EDITOR) {
432 o_dir.type = FIOS_TYPE_DIRECT;
433 switch (this->abstract_filetype) {
462 void Close([[maybe_unused]]
int data = 0)
override
465 if (!
_networking && _game_mode != GM_EDITOR && _game_mode != GM_MENU) {
471 void DrawWidget(
const Rect &r,
WidgetID widget)
const override
482 static std::string path;
483 static std::optional<uint64_t> free_space = std::nullopt;
485 if (_fios_path_changed) {
487 free_space = FiosGetDiskFreeSpace(path);
488 _fios_path_changed =
false;
493 if (free_space.has_value())
SetDParam(0, free_space.value());
495 DrawString(ir.left, ir.right, ir.top, path, TC_BLACK);
505 for (
auto it = first; it != last; ++it) {
508 if (item == this->selected) {
510 }
else if (item == this->highlighted) {
520 this->DrawDetails(r);
525 void DrawDetails(
const Rect &r)
const
532 tr.top += HEADER_HEIGHT;
538 if (this->selected ==
nullptr)
return;
542 if (tr.top > tr.bottom)
return;
546 DrawString(tr, STR_SAVELOAD_DETAIL_NOT_AVAILABLE);
556 DrawString(tr, STR_NETWORK_SERVER_LIST_MAP_SIZE);
558 if (tr.top > tr.bottom)
return;
562 if (landscape < NUM_LANDSCAPE) {
563 SetDParam(0, STR_CLIMATE_TEMPERATE_LANDSCAPE + landscape);
564 DrawString(tr, STR_NETWORK_SERVER_LIST_LANDSCAPE);
569 if (tr.top > tr.bottom)
return;
574 DrawString(tr, STR_NETWORK_SERVER_LIST_START_DATE);
577 if (tr.top > tr.bottom)
return;
583 DrawString(tr, STR_NETWORK_SERVER_LIST_CURRENT_DATE);
590 if (tr.top > tr.bottom)
return;
595 DrawString(tr, STR_SAVELOAD_DETAIL_GRFSTATUS);
598 if (tr.top > tr.bottom)
return;
603 if (tr.top > tr.bottom)
return;
609 if (!c.
name.empty()) {
616 DrawString(tr, STR_SAVELOAD_DETAIL_COMPANY_INDEX);
618 if (tr.top > tr.bottom)
break;
633 size.height =
resize.height * 10 + padding.height;
639 d.height += padding.height;
648 if (_savegame_sort_dirty) {
649 _savegame_sort_dirty =
false;
657 void OnClick([[maybe_unused]]
Point pt,
WidgetID widget, [[maybe_unused]]
int click_count)
override
661 _savegame_sort_order = (_savegame_sort_order == SORT_BY_NAME) ?
662 SORT_BY_NAME | SORT_DESCENDING : SORT_BY_NAME;
663 _savegame_sort_dirty =
true;
668 _savegame_sort_order = (_savegame_sort_order == SORT_BY_DATE) ?
669 SORT_BY_DATE | SORT_DESCENDING : SORT_BY_DATE;
670 _savegame_sort_dirty =
true;
714 if (it == this->display_list.end())
return;
725 if (click_count == 1) {
726 if (this->selected != file) {
727 this->selected = file;
739 this->filename_editbox.text.
Assign(file->title);
742 }
else if (!_load_check_data.
HasErrors()) {
743 this->selected = file;
764 switch (this->abstract_filetype) {
765 default: NOT_REACHED();
782 void OnMouseOver([[maybe_unused]]
Point pt,
WidgetID widget)
override
786 if (it == this->display_list.end())
return;
791 if (file != this->highlighted) {
792 this->highlighted = file;
795 }
else if (this->highlighted !=
nullptr) {
796 this->highlighted =
nullptr;
801 EventState OnKeyPress([[maybe_unused]] char32_t key, uint16_t keycode)
override
803 if (keycode == WKC_ESC) {
828 ShowQuery(STR_SAVELOAD_OVERWRITE_TITLE, STR_SAVELOAD_OVERWRITE_WARNING,
this, SaveLoadWindow::SaveGameConfirmationCallback);
835 ShowQuery(STR_SAVELOAD_OVERWRITE_TITLE, STR_SAVELOAD_OVERWRITE_WARNING,
this, SaveLoadWindow::SaveHeightmapConfirmationCallback);
851 void BuildDisplayList()
854 this->display_list.clear();
855 this->display_list.reserve(this->fios_items.size());
857 if (this->string_filter.
IsEmpty()) {
859 for (
auto &it : this->fios_items) {
860 this->display_list.push_back(&it);
863 for (
auto &it : this->fios_items) {
865 this->string_filter.
AddLine(it.title);
867 if (this->string_filter.
GetState()) {
868 this->display_list.push_back(&it);
869 }
else if (&it == this->selected) {
871 this->selected =
nullptr;
877 this->vscroll->
SetCount(this->display_list.size());
890 this->selected =
nullptr;
892 if (!gui_scope)
break;
894 _fios_path_changed =
true;
895 this->fios_items.BuildFileList(this->abstract_filetype, this->fop,
true);
896 this->selected =
nullptr;
906 if (!gui_scope)
break;
910 switch (this->abstract_filetype) {
935 this->BuildDisplayList();
940 void OnEditboxChanged(
WidgetID wid)
override
994 switch (abstract_filetype) {
List of file information.
void Reset()
Resets and frees all memory allocated - used before loading or starting a new game.
static Date ConvertYMDToDate(Year year, Month month, Day day)
Converts a tuple of Year, Month and Day to a Date.
Functions related to commands.
void StartupEngines()
Start/initialise all our engines.
Functions related to engines.
Functions related to errors.
void ClearErrorMessages()
Clear all errors from the queue.
void ShowErrorMessage(StringID summary_msg, int x, int y, CommandCost cc)
Display an error message in a window.
@ WL_ERROR
Errors (eg. saving/loading failed)
std::string _personal_dir
custom directory for personal settings, saves, newgrf, etc.
bool FioCheckFileExists(const std::string &filename, Subdirectory subdir)
Check whether the given file exists.
Functions for Standard In/Out file operations.
DetailedFileType GetDetailedFileType(FiosType fios_type)
Extract the detailed file type from a FiosType.
AbstractFileType
The different abstract types of files that the system knows about.
@ FT_SCENARIO
old or new scenario
@ FT_HEIGHTMAP
heightmap file
@ FT_SAVEGAME
old or new savegame
@ FT_TOWN_DATA
town data file
SaveLoadOperation
Operation performed on the file.
@ SLO_CHECK
Load file for checking and/or preview.
@ SLO_SAVE
File is being saved.
@ SLO_LOAD
File is being loaded.
@ DFT_GAME_FILE
Save game or scenario file.
@ DFT_END
End of this enum. Supports a compile time size check against _fios_colours in fios_gui....
@ NO_DIRECTORY
A path without any base directory.
@ SCENARIO_DIR
Base directory for all scenarios.
@ SAVE_DIR
Base directory for all savegames.
@ HEIGHTMAP_DIR
Subdirectory of scenario for heightmaps.
std::string FiosGetCurrentPath()
Get the current path/working directory.
std::string FiosMakeSavegameName(const char *name)
Make a save game or scenario filename from a name.
std::string FiosMakeHeightmapName(const char *name)
Construct a filename for a height map.
bool FiosDelete(const char *name)
Delete a file.
bool FiosBrowseTo(const FiosItem *item)
Browse to a new path based on the passed item, starting at #_fios_path.
Declarations for savegames operations.
@ SLIWD_FILTER_CHANGES
The filename filter has changed (via the editbox)
@ SLIWD_SELECTION_CHANGES
File selection has changed (user click, ...)
@ SLIWD_RESCAN_FILES
Rescan all files (when changed directory, ...)
void ShowSaveLoadDialog(AbstractFileType abstract_filetype, SaveLoadOperation fop)
Launch save/load dialog in the given mode.
static constexpr NWidgetPart _nested_load_heightmap_dialog_widgets[]
Load heightmap with content download.
static WindowDesc _load_heightmap_dialog_desc(WDP_CENTER, "load_heightmap", 257, 320, WC_SAVELOAD, WC_NONE, 0, _nested_load_heightmap_dialog_widgets)
Load heightmap.
static constexpr NWidgetPart _nested_load_dialog_widgets[]
Load game/scenario with optional content download.
static constexpr NWidgetPart _nested_save_dialog_widgets[]
Save game/scenario.
static WindowDesc _load_dialog_desc(WDP_CENTER, "load_game", 500, 294, WC_SAVELOAD, WC_NONE, 0, _nested_load_dialog_widgets)
Load game/scenario.
static WindowDesc _load_town_data_dialog_desc(WDP_CENTER, "load_town_data", 257, 320, WC_SAVELOAD, WC_NONE, 0, _nested_load_town_data_dialog_widgets)
Load town data.
LoadCheckData _load_check_data
Data loaded from save during SL_LOAD_CHECK.
static const TextColour _fios_colours[]
Text colours of DetailedFileType fios entries in the window.
static constexpr NWidgetPart _nested_load_town_data_dialog_widgets[]
Load town data.
static WindowDesc _save_dialog_desc(WDP_CENTER, "save_game", 500, 294, WC_SAVELOAD, WC_NONE, 0, _nested_save_dialog_widgets)
Save game/scenario.
static void SortSaveGameList(FileList &file_list)
Sort the collected list save games prior to displaying it in the save/load gui.
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
Functions to be called to log fundamental changes to the game.
Declaration shared among gamelog.cpp and saveload/gamelog_sl.cpp.
void LoadTownData()
Load town data from _file_to_saveload, place towns at the appropriate locations, and expand them to t...
Functions related to world/map generation.
void ShowHeightmapLoad()
Start with loading a heightmap.
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
int DrawString(int left, int right, int top, std::string_view str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
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.
int DrawStringMultiLine(int left, int right, int top, int bottom, std::string_view str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly over multiple lines.
SwitchMode _switch_mode
The next mainloop command.
Functions related to the gfx engine.
@ SA_HOR_CENTER
Horizontally center the text.
@ FS_NORMAL
Index of the normal font in the font tables.
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
GUI functions that shouldn't be here.
Types related to the landscape.
Miscellaneous command definitions.
void ShowQuery(StringID caption, StringID message, Window *parent, QueryCallbackProc *callback, bool focus)
Show a confirmation window with standard 'yes' and 'no' buttons The window is aligned to the centre o...
bool _network_available
is network mode available?
bool _networking
are we in networking mode?
Basic functions/variables used all over the place.
Part of the network protocol handling content distribution.
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.
void ClearGRFConfigList(GRFConfig **config)
Clear a GRF Config list, freeing all nodes.
@ GLC_ALL_GOOD
All GRF needed by game are present.
@ GLC_NOT_FOUND
At least one GRF couldn't be found (higher priority than GLC_COMPATIBLE)
void ShowNewGRFSettings(bool editable, bool show_params, bool exec_changes, GRFConfig **config)
Setup the NewGRF gui.
void ShowMissingContentWindow(const GRFConfig *list)
Show the content list window with all missing grfs from the given list.
@ SM_LOAD_SCENARIO
Load scenario from scenario editor.
@ SM_SAVE_HEIGHTMAP
Save heightmap.
@ SM_LOAD_GAME
Load game, Play Scenario.
@ PM_PAUSED_SAVELOAD
A game paused for saving/loading.
static const uint8_t PC_GREY
Grey palette colour.
static const uint8_t PC_DARK_BLUE
Dark blue palette colour.
static const uint8_t PC_BLACK
Black palette colour.
static const uint8_t PC_VERY_DARK_BLUE
Almost-black blue palette colour.
Base for the GUIs that have an edit box in them.
A number of safeguards to prevent using unsafe methods.
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.
FileToSaveLoad _file_to_saveload
File to save or load in the openttd loop.
std::string GenerateDefaultSaveName()
Get the default name for a savegame or screenshot.
Functions/types related to saving and loading games.
ClientSettings _settings_client
The current settings for this game.
This file contains all sprite-related enums and defines.
Definition of base types and functions in a cross-platform compatible way.
Searching and filtering using a stringterm.
void SetDParam(size_t n, uint64_t v)
Set a string parameter v at index n in the global string parameter array.
void SetDParamStr(size_t n, const char *str)
This function is used to "bind" a C string to a OpenTTD dparam slot.
Functions related to OTTD's strings.
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
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
Statically loadable part of Company pool item.
uint32_t name_2
Parameter of name_1.
StringID name_1
Name of the company if the user did not change it.
std::string name
Name of the company if the user changed it.
Dimensions (a width and height) of a rectangle in 2D.
std::string name
Name of the file.
void Set(const FiosItem &item)
Set the title of the file.
Deals with finding savegames.
bool UserIsAllowedToChangeNewGRFs() const
Returns true when the user has sufficient privileges to edit newgrfs on a running game.
uint8_t landscape
the landscape we're currently in
TimerGameCalendar::Year starting_year
starting date
GameCreationSettings game_creation
settings used during the creation of a game (map)
Container for loading in mode SL_LOAD_CHECK.
bool checkable
True if the savegame could be checked by SL_LOAD_CHECK. (Old savegames are not checkable....
bool HasNewGrfs()
Check whether the game uses any NewGrfs.
std::string error_msg
Data to pass to SetDParamStr when displaying error.
CompanyPropertiesMap companies
Company information.
StringID error
Error message from loading. INVALID_STRING_ID if no error.
GRFConfig * grfconfig
NewGrf configuration from save.
Gamelog gamelog
Gamelog actions.
bool HasErrors()
Check whether loading the game resulted in errors.
void Clear()
Reset read data.
GRFListCompatibility grf_compatibility
Summary state of NewGrfs, whether missing files or only compatible found.
Coordinates of a point in 2D.
Data stored about a string that can be modified in the GUI.
int ok_button
Widget button of parent window to simulate when pressing OK in OSK.
int cancel_button
Widget button of parent window to simulate when pressing CANCEL in OSK.
static const int ACTION_CLEAR
Clear editbox.
constexpr uint Vertical() const
Get total vertical padding of RectPadding.
Specification of a rectangle with absolute coordinates of all edges.
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
Rect WithHeight(int height, bool end=false) const
Copy Rect and set its height.
Rect Translate(int x, int y) const
Copy and translate Rect by x,y pixels.
uint step_height
Step-size of height resize changes.
void OnTimeout() override
Called when this window's timeout has been reached.
const FiosItem * highlighted
Item in fios_items highlighted by mouse pointer, or nullptr.
QueryString filter_editbox
Filter editbox;.
void GenerateFileName()
Generate a default save filename.
StringFilter string_filter
Filter for available games.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
std::vector< FiosItem * > display_list
Filtered display list.
void OnResize() override
Called after the window got resized.
SaveLoadOperation fop
Type of file to select.
FileList fios_items
Save game list.
QueryString filename_editbox
Filename editbox.
void OnPaint() override
The window must be repainted.
const FiosItem * selected
Selected game in fios_items, or nullptr.
FiosItem o_dir
Original dir (home dir for this browser)
bool IsEmpty() const
Check whether any filter words were entered.
void SetFilterTerm(const char *str)
Set the term to filter on.
void ResetState()
Reset the matching state to process a new item.
void AddLine(const char *str)
Pass another text line from the current item to the filter.
bool GetState() const
Get the matching state of the current item.
void Assign(StringID string)
Render a string into the textbuffer.
char *const buf
buffer in which text is saved
High level window description.
Data structure for an opened window.
virtual void Close(int data=0)
Hide the window and all its child windows, and mark them for a later deletion.
static int SortButtonWidth()
Get width of up/down arrow of sort button state.
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
std::map< WidgetID, QueryString * > querystrings
QueryString associated to WWT_EDITBOX widgets.
void DrawWidgets() const
Paint all widgets of a window.
void InvalidateData(int data=0, bool gui_scope=true)
Mark this window's data as invalid (in need of re-computing)
void SetWidgetDirty(WidgetID widget_index) const
Invalidate a widget, i.e.
void DrawSortButtonState(WidgetID widget, SortButtonState state) const
Draw a sort button's up or down arrow symbol.
ResizeInfo resize
Resize information.
void CreateNestedTree()
Perform the first part of the initialization of a nested widget tree.
bool SetFocusedWidget(WidgetID widget_index)
Set focus within this window to the given widget.
bool IsWidgetLowered(WidgetID widget_index) const
Gets the lowered state of a widget.
void LowerWidget(WidgetID widget_index)
Marks a widget as lowered.
void HandleButtonClick(WidgetID widget)
Do all things to make a button look clicked and mark it to be unclicked in a few ticks.
const Scrollbar * GetScrollbar(WidgetID widnum) const
Return the Scrollbar to a widget index.
void SetWidgetDisabledState(WidgetID widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
@ CONTENT_TYPE_SCENARIO
The content consists of a scenario.
@ CONTENT_TYPE_HEIGHTMAP
The content consists of a heightmap.
Functions related to tile highlights.
void ResetObjectToPlace()
Reset the cursor and mouse mode handling back to default (normal cursor, only clicking in windows).
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 of the game-calendar-timer.
void CloseWindowById(WindowClass cls, WindowNumber number, bool force, int data)
Close a window by its class and window number (if it is open).
Window functions not directly related to making/drawing windows.
@ SBS_DOWN
Sort ascending.
@ WDP_CENTER
Center the window.
EventState
State of handling an event.
@ ES_HANDLED
The passed event is handled.
@ ES_NOT_HANDLED
The passed event is not handled.
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
@ WC_MAIN_WINDOW
Main window; Window numbers:
@ WC_SAVELOAD
Saveload window; Window numbers: