35 #include "table/strings.h" 41 static bool _fios_path_changed;
42 static bool _savegame_sort_dirty;
55 this->map_size_x = this->map_size_y = 256;
56 this->current_date = 0;
57 memset(&this->settings, 0,
sizeof(this->settings));
97 SetDataTip(STR_INTRO_ONLINE_CONTENT, STR_INTRO_TOOLTIP_ONLINE_CONTENT),
139 SetDataTip(STR_INTRO_ONLINE_CONTENT, STR_INTRO_TOOLTIP_ONLINE_CONTENT),
141 SetDataTip(STR_SAVELOAD_LOAD_BUTTON, STR_SAVELOAD_LOAD_HEIGHTMAP_TOOLTIP),
171 NWidget(
WWT_EDITBOX, COLOUR_GREY,
WID_SL_SAVE_OSK_TITLE),
SetPadding(3, 2, 2, 2),
SetFill(1, 0),
SetResize(1, 0),
172 SetDataTip(STR_SAVELOAD_OSKTITLE, STR_SAVELOAD_EDITBOX_TOOLTIP),
215 for (
const FiosItem *item = file_list.
Begin(); item != file_list.
End(); item++) {
216 switch (item->type) {
217 case FIOS_TYPE_DIR: sort_start++;
break;
218 case FIOS_TYPE_PARENT: sort_start++;
break;
219 case FIOS_TYPE_DRIVE: sort_end++;
break;
224 uint s_amount = file_list.
Length() - sort_start - sort_end;
242 GenerateDefaultSaveName(this->filename_editbox.text.
buf, &this->filename_editbox.text.buf[this->filename_editbox.text.max_bytes - 1]);
247 :
Window(desc), filename_editbox(64), abstract_filetype(abstract_filetype), fop(fop)
253 switch (this->abstract_filetype) {
255 this->GenerateFileName();
260 this->filename_editbox.text.
Assign(
"UNNAMED");
270 this->CreateNestedTree(
true);
277 switch (this->abstract_filetype) {
279 caption_string = (this->fop ==
SLO_SAVE) ? STR_SAVELOAD_SAVE_CAPTION : STR_SAVELOAD_LOAD_CAPTION;
283 caption_string = (this->fop ==
SLO_SAVE) ? STR_SAVELOAD_SAVE_SCENARIO : STR_SAVELOAD_LOAD_SCENARIO;
287 caption_string = (this->fop ==
SLO_SAVE) ? STR_SAVELOAD_SAVE_HEIGHTMAP : STR_SAVELOAD_LOAD_HEIGHTMAP;
293 this->GetWidget<NWidgetCore>(
WID_SL_CAPTION)->widget_data = caption_string;
296 this->FinishInitNested(0);
302 if (_game_mode != GM_MENU && !
_networking && _game_mode != GM_EDITOR) {
307 this->OnInvalidateData(0);
312 o_dir.type = FIOS_TYPE_DIRECT;
313 switch (this->abstract_filetype) {
337 if (!
_networking && _game_mode != GM_EDITOR && _game_mode != GM_MENU) {
348 this->DrawSortButtonState(widget, _savegame_sort_order & SORT_DESCENDING ?
SBS_DOWN :
SBS_UP);
353 static const char *path = NULL;
354 static StringID str = STR_ERROR_UNABLE_TO_READ_DRIVE;
355 static uint64 tot = 0;
357 if (_fios_path_changed) {
359 _fios_path_changed =
false;
362 if (str != STR_ERROR_UNABLE_TO_READ_DRIVE)
SetDParam(0, tot);
372 for (uint pos = this->vscroll->
GetPosition(); pos < this->fios_items.
Length(); pos++) {
375 if (item == this->selected) {
379 y += this->resize.step_height;
390 if (this->selected == NULL)
break;
395 if (y > y_max)
break;
404 y, r.bottom - WD_FRAMERECT_BOTTOM, _load_check_data.
error, TC_RED);
407 SetDParam(0, _load_check_data.map_size_x);
408 SetDParam(1, _load_check_data.map_size_y);
411 if (y > y_max)
break;
415 if (landscape < NUM_LANDSCAPE) {
416 SetDParam(0, STR_CHEAT_SWITCH_CLIMATE_TEMPERATE_LANDSCAPE + landscape);
422 if (y > y_max)
break;
430 if (y > y_max)
break;
435 SetDParam(0, _load_check_data.current_date);
443 if (y > y_max)
break;
451 if (y > y_max)
break;
456 if (y > y_max)
break;
463 if (c.
name != NULL) {
472 if (y > y_max)
break;
496 d.height += padding.height;
505 if (_savegame_sort_dirty) {
506 _savegame_sort_dirty =
false;
518 _savegame_sort_order = (_savegame_sort_order == SORT_BY_NAME) ?
519 SORT_BY_NAME | SORT_DESCENDING : SORT_BY_NAME;
520 _savegame_sort_dirty =
true;
525 _savegame_sort_order = (_savegame_sort_order == SORT_BY_DATE) ?
526 SORT_BY_DATE | SORT_DESCENDING : SORT_BY_DATE;
527 _savegame_sort_dirty =
true;
533 this->InvalidateData();
537 if (this->selected != NULL && !_load_check_data.
HasErrors()) {
565 #if defined(ENABLE_NETWORK) 573 if (y == INT_MAX)
return;
579 if (click_count == 1) {
580 if (this->selected != file) {
581 this->selected = file;
582 _load_check_data.
Clear();
589 this->InvalidateData(1);
593 this->filename_editbox.text.
Assign(file->title);
596 }
else if (!_load_check_data.
HasErrors()) {
597 this->selected = file;
614 this->InvalidateData();
623 #if defined(ENABLE_NETWORK) 625 switch (this->abstract_filetype) {
626 default: NOT_REACHED();
646 if (keycode == WKC_ESC) {
663 this->InvalidateData();
665 if (this->abstract_filetype ==
FT_SAVEGAME) GenerateFileName();
696 this->selected = NULL;
697 _load_check_data.
Clear();
698 if (!gui_scope)
break;
700 _fios_path_changed =
true;
701 this->fios_items.
BuildFileList(this->abstract_filetype, this->fop);
703 this->selected = NULL;
704 _load_check_data.
Clear();
709 if (!gui_scope)
break;
713 switch (this->abstract_filetype) {
720 bool disabled = this->selected == NULL || _load_check_data.
HasErrors();
744 _nested_load_dialog_widgets,
lengthof(_nested_load_dialog_widgets)
752 _nested_load_heightmap_dialog_widgets,
lengthof(_nested_load_heightmap_dialog_widgets)
760 _nested_save_dialog_widgets,
lengthof(_nested_save_dialog_widgets)
777 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
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.
The passed event is not handled.
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.
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.
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?
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.)
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.
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.
bool DoCommandP(const CommandContainer *container, bool my_cmd)
Shortcut for the long DoCommandP when having a container with the data.
#define lengthof(x)
Return the length of an fixed size array.
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.
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 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.
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.
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.
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.
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.