|
OpenTTD Source
14.0-beta1
|
Go to the documentation of this file.
36 #include "table/strings.h"
42 static bool _fios_path_changed;
43 static bool _savegame_sort_dirty;
54 this->map_size_x = this->map_size_y = 256;
55 this->current_date = 0;
84 SetDataTip(STR_LIST_FILTER_OSKTITLE, STR_LIST_FILTER_TOOLTIP),
106 SetDataTip(STR_INTRO_ONLINE_CONTENT, STR_INTRO_TOOLTIP_ONLINE_CONTENT),
142 SetDataTip(STR_LIST_FILTER_OSKTITLE, STR_LIST_FILTER_TOOLTIP),
164 SetDataTip(STR_INTRO_ONLINE_CONTENT, STR_INTRO_TOOLTIP_ONLINE_CONTENT),
166 SetDataTip(STR_SAVELOAD_LOAD_BUTTON, STR_SAVELOAD_LOAD_HEIGHTMAP_TOOLTIP),
189 SetDataTip(STR_LIST_FILTER_OSKTITLE, STR_LIST_FILTER_TOOLTIP),
209 NWidget(
WWT_EDITBOX, COLOUR_GREY,
WID_SL_SAVE_OSK_TITLE),
SetPadding(2, 2, 2, 2),
SetFill(1, 0),
SetResize(1, 0),
210 SetDataTip(STR_SAVELOAD_OSKTITLE, STR_SAVELOAD_EDITBOX_TOOLTIP),
249 size_t sort_start = 0;
256 for (
const auto &item : file_list) {
258 case FIOS_TYPE_DIR: sort_start++;
break;
259 case FIOS_TYPE_PARENT: sort_start++;
break;
260 case FIOS_TYPE_DRIVE: sort_end++;
break;
265 std::sort(file_list.begin() + sort_start, file_list.end() - sort_end);
270 static const uint EDITBOX_MAX_SIZE = 50;
285 static void SaveGameConfirmationCallback(
Window *,
bool confirmed)
291 static void SaveHeightmapConfirmationCallback(
Window *,
bool confirmed)
312 switch (this->abstract_filetype) {
319 this->filename_editbox.text.
Assign(
"UNNAMED");
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;
363 if (_game_mode != GM_MENU && !
_networking && _game_mode != GM_EDITOR) {
373 o_dir.type = FIOS_TYPE_DIRECT;
374 switch (this->abstract_filetype) {
402 void Close([[maybe_unused]]
int data = 0)
override
405 if (!
_networking && _game_mode != GM_EDITOR && _game_mode != GM_MENU) {
411 void DrawWidget(
const Rect &r,
WidgetID widget)
const override
422 static std::string path;
423 static std::optional<uint64_t> free_space = std::nullopt;
425 if (_fios_path_changed) {
427 free_space = FiosGetDiskFreeSpace(path);
428 _fios_path_changed =
false;
433 if (free_space.has_value())
SetDParam(0, free_space.value());
435 DrawString(ir.left, ir.right, ir.top, path, TC_BLACK);
445 for (
auto it = this->display_list.begin() + scroll_pos; it != this->display_list.end() && tr.top < br.bottom; ++it) {
448 if (item == this->selected) {
450 }
else if (item == this->highlighted) {
460 this->DrawDetails(r);
465 void DrawDetails(
const Rect &r)
const
472 tr.top += HEADER_HEIGHT;
478 if (this->selected ==
nullptr)
return;
482 if (tr.top > tr.bottom)
return;
486 DrawString(tr, STR_SAVELOAD_DETAIL_NOT_AVAILABLE);
496 DrawString(tr, STR_NETWORK_SERVER_LIST_MAP_SIZE);
498 if (tr.top > tr.bottom)
return;
502 if (landscape < NUM_LANDSCAPE) {
503 SetDParam(0, STR_CLIMATE_TEMPERATE_LANDSCAPE + landscape);
504 DrawString(tr, STR_NETWORK_SERVER_LIST_LANDSCAPE);
509 if (tr.top > tr.bottom)
return;
514 DrawString(tr, STR_NETWORK_SERVER_LIST_START_DATE);
517 if (tr.top > tr.bottom)
return;
523 DrawString(tr, STR_NETWORK_SERVER_LIST_CURRENT_DATE);
530 if (tr.top > tr.bottom)
return;
535 DrawString(tr, STR_SAVELOAD_DETAIL_GRFSTATUS);
538 if (tr.top > tr.bottom)
return;
543 if (tr.top > tr.bottom)
return;
549 if (!c.
name.empty()) {
556 DrawString(tr, STR_SAVELOAD_DETAIL_COMPANY_INDEX);
558 if (tr.top > tr.bottom)
break;
573 size->height =
resize->height * 10 + padding.height;
579 d.height += padding.height;
588 if (_savegame_sort_dirty) {
589 _savegame_sort_dirty =
false;
597 void OnClick([[maybe_unused]]
Point pt,
WidgetID widget, [[maybe_unused]]
int click_count)
override
601 _savegame_sort_order = (_savegame_sort_order == SORT_BY_NAME) ?
602 SORT_BY_NAME | SORT_DESCENDING : SORT_BY_NAME;
603 _savegame_sort_dirty =
true;
608 _savegame_sort_order = (_savegame_sort_order == SORT_BY_DATE) ?
609 SORT_BY_DATE | SORT_DESCENDING : SORT_BY_DATE;
610 _savegame_sort_dirty =
true;
651 if (it == this->display_list.end())
return;
662 if (click_count == 1) {
663 if (this->selected != file) {
664 this->selected = file;
676 this->filename_editbox.text.
Assign(file->title);
679 }
else if (!_load_check_data.
HasErrors()) {
680 this->selected = file;
701 switch (this->abstract_filetype) {
702 default: NOT_REACHED();
719 void OnMouseOver([[maybe_unused]]
Point pt,
WidgetID widget)
override
723 if (it == this->display_list.end())
return;
728 if (file != this->highlighted) {
729 this->highlighted = file;
732 }
else if (this->highlighted !=
nullptr) {
733 this->highlighted =
nullptr;
738 EventState OnKeyPress([[maybe_unused]] char32_t key, uint16_t keycode)
override
740 if (keycode == WKC_ESC) {
765 ShowQuery(STR_SAVELOAD_OVERWRITE_TITLE, STR_SAVELOAD_OVERWRITE_WARNING,
this, SaveLoadWindow::SaveGameConfirmationCallback);
772 ShowQuery(STR_SAVELOAD_OVERWRITE_TITLE, STR_SAVELOAD_OVERWRITE_WARNING,
this, SaveLoadWindow::SaveHeightmapConfirmationCallback);
788 void BuildDisplayList()
791 this->display_list.clear();
792 this->display_list.reserve(this->fios_items.size());
794 if (this->string_filter.
IsEmpty()) {
796 for (
auto &it : this->fios_items) {
797 this->display_list.push_back(&it);
800 for (
auto &it : this->fios_items) {
802 this->string_filter.
AddLine(it.title);
804 if (this->string_filter.
GetState()) {
805 this->display_list.push_back(&it);
806 }
else if (&it == this->selected) {
808 this->selected =
nullptr;
814 this->vscroll->
SetCount(this->display_list.size());
827 this->selected =
nullptr;
829 if (!gui_scope)
break;
831 _fios_path_changed =
true;
832 this->fios_items.BuildFileList(this->abstract_filetype, this->fop,
true);
833 this->selected =
nullptr;
843 if (!gui_scope)
break;
847 switch (this->abstract_filetype) {
871 this->BuildDisplayList();
876 void OnEditboxChanged(
WidgetID wid)
override
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.
static const uint8_t PC_DARK_BLUE
Dark blue palette colour.
bool checkable
True if the savegame could be checked by SL_LOAD_CHECK. (Old savegames are not checkable....
@ FT_SCENARIO
old or new scenario
std::string error_msg
Data to pass to SetDParamStr when displaying error.
@ 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, ...)
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...
@ SM_LOAD_GAME
Load game, Play Scenario.
Dimensions (a width and height) of a rectangle in 2D.
std::string _personal_dir
custom directory for personal settings, saves, newgrf, etc.
void ShowErrorMessage(StringID summary_msg, int x, int y, CommandCost cc)
Display an error message in a window.
void OnTimeout() override
Called when this window's timeout has been reached.
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.
byte landscape
the landscape we're currently in
void SetFilterTerm(const char *str)
Set the term to filter on.
static WindowDesc _save_dialog_desc(__FILE__, __LINE__, WDP_CENTER, "save_game", 500, 294, WC_SAVELOAD, WC_NONE, 0, std::begin(_nested_save_dialog_widgets), std::end(_nested_save_dialog_widgets))
Save game/scenario.
void SetWidgetDirty(WidgetID widget_index) const
Invalidate a widget, i.e.
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.
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
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 CloseWindowById(WindowClass cls, WindowNumber number, bool force, int data)
Close a window by its class and window number (if it is open).
static const uint8_t PC_VERY_DARK_BLUE
Almost-black blue palette colour.
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.
virtual void Close(int data=0)
Hide the window and all its child windows, and mark them for a later deletion.
@ 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.
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.
constexpr uint Vertical() const
Get total vertical padding of RectPadding.
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.
void Reset()
Resets and frees all memory allocated - used before loading or starting a new game.
@ SM_LOAD_SCENARIO
Load scenario from scenario editor.
void StartupEngines()
Start/initialise all our engines.
const Scrollbar * GetScrollbar(WidgetID widnum) const
Return the Scrollbar to a widget index.
std::string FiosGetCurrentPath()
Get the current path/working directory.
List of file information.
Rect WithHeight(int height, bool end=false) const
Copy Rect and set its height.
const FiosItem * selected
Selected game in fios_items, or nullptr.
Data stored about a string that can be modified in the GUI.
char *const buf
buffer in which text is saved
GameCreationSettings game_creation
settings used during the creation of a game (map)
High level window description.
static constexpr NWidgetPart _nested_load_dialog_widgets[]
Load game/scenario with optional content download.
AbstractFileType
The different abstract types of files that the system knows about.
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.
@ FS_NORMAL
Index of the normal font in the font tables.
Rect Translate(int x, int y) const
Copy and translate Rect by x,y pixels.
bool FiosDelete(const char *name)
Delete a file.
void HandleButtonClick(WidgetID widget)
Do all things to make a button look clicked and mark it to be unclicked in a few ticks.
@ SM_SAVE_HEIGHTMAP
Save heightmap.
@ SLIWD_FILTER_CHANGES
The filename filter has changed (via the editbox)
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
std::vector< FiosItem * > display_list
Filtered display list.
static constexpr NWidgetPart _nested_save_dialog_widgets[]
Save game/scenario.
SaveLoadOperation fop
Type of file to select.
static 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.
static constexpr NWidgetPart _nested_load_heightmap_dialog_widgets[]
Load heightmap with content download.
uint32_t name_2
Parameter of name_1.
static WindowDesc _load_dialog_desc(__FILE__, __LINE__, WDP_CENTER, "load_game", 500, 294, WC_SAVELOAD, WC_NONE, 0, std::begin(_nested_load_dialog_widgets), std::end(_nested_load_dialog_widgets))
Load game/scenario.
std::string GenerateDefaultSaveName()
Get the default name for a savegame or screenshot.
void LowerWidget(WidgetID widget_index)
Marks a widget as lowered.
TimerGameCalendar::Year starting_year
starting date
@ 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.
@ FT_SAVEGAME
old or new savegame
bool SetFocusedWidget(WidgetID widget_index)
Set focus within this window to the given widget.
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.
void ShowHeightmapLoad()
Start with loading a heightmap.
void OnPaint() override
The window must be repainted.
void SetWidgetDisabledState(WidgetID widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
Container for loading in mode SL_LOAD_CHECK.
CompanyPropertiesMap companies
Company information.
bool IsWidgetLowered(WidgetID widget_index) const
Gets the lowered state of a widget.
SwitchMode _switch_mode
The next mainloop command.
std::map< WidgetID, QueryString * > querystrings
QueryString associated to WWT_EDITBOX widgets.
@ SBS_DOWN
Sort ascending.
int cancel_button
Widget button of parent window to simulate when pressing CANCEL in OSK.
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.
void DrawSortButtonState(WidgetID widget, SortButtonState state) const
Draw a sort button's up or down arrow symbol.
void CreateNestedTree()
Perform the first part of the initialization of a nested widget tree.
bool FioCheckFileExists(const std::string &filename, Subdirectory subdir)
Check whether the given file exists.
void Clear()
Reset read data.
void Set(const FiosItem &item)
Set the title of the file.
@ NO_DIRECTORY
A path without any base directory.
void SetDParam(size_t n, uint64_t v)
Set a string parameter v at index n in the global string parameter array.
FileToSaveLoad _file_to_saveload
File to save or load in the openttd loop.
static WindowDesc _load_heightmap_dialog_desc(__FILE__, __LINE__, WDP_CENTER, "load_heightmap", 257, 320, WC_SAVELOAD, WC_NONE, 0, std::begin(_nested_load_heightmap_dialog_widgets), std::end(_nested_load_heightmap_dialog_widgets))
Load heightmap.
void ResetState()
Reset the matching state to process a new item.
EventState
State of handling an event.
static const uint8_t PC_GREY
Grey palette colour.
bool GetState() const
Get the matching state of the current item.
@ FT_HEIGHTMAP
heightmap file
void SetDParamStr(size_t n, const char *str)
This function is used to "bind" a C string to a OpenTTD dparam slot.
@ 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.
GRFListCompatibility grf_compatibility
Summary state of NewGrfs, whether missing files or only compatible found.
static const uint8_t PC_BLACK
Black palette colour.
@ WL_ERROR
Errors (eg. saving/loading failed)
bool FiosBrowseTo(const FiosItem *item)
Browse to a new path based on the passed item, starting at #_fios_path.
static const int ACTION_CLEAR
Clear editbox.
FiosItem o_dir
Original dir (home dir for this browser)
Gamelog gamelog
Gamelog actions.
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
static int SortButtonWidth()
Get width of up/down arrow of sort button state.
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 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.
bool _network_available
is network mode available?
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.
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.
@ 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.
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
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.