2010-06-03 11:05:20 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is part of OpenTTD.
|
|
|
|
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
|
|
|
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** @file fios_gui.cpp GUIs for loading/saving games, scenarios, heightmaps, ... */
|
|
|
|
|
|
|
|
#include "stdafx.h"
|
|
|
|
#include "saveload/saveload.h"
|
2011-12-10 13:54:10 +00:00
|
|
|
#include "error.h"
|
2010-06-03 11:05:20 +00:00
|
|
|
#include "gui.h"
|
|
|
|
#include "gfx_func.h"
|
|
|
|
#include "command_func.h"
|
|
|
|
#include "network/network.h"
|
|
|
|
#include "network/network_content.h"
|
|
|
|
#include "strings_func.h"
|
|
|
|
#include "fileio_func.h"
|
|
|
|
#include "fios.h"
|
|
|
|
#include "window_func.h"
|
|
|
|
#include "tilehighlight_func.h"
|
|
|
|
#include "querystring_gui.h"
|
2010-06-05 19:02:29 +00:00
|
|
|
#include "engine_func.h"
|
2010-06-13 14:17:26 +00:00
|
|
|
#include "landscape_type.h"
|
|
|
|
#include "date_func.h"
|
2010-11-12 16:29:09 +00:00
|
|
|
#include "core/geometry_func.hpp"
|
2012-02-05 15:51:13 +00:00
|
|
|
#include "gamelog.h"
|
2010-06-03 11:05:20 +00:00
|
|
|
|
2011-12-15 22:22:55 +00:00
|
|
|
#include "widgets/fios_widget.h"
|
|
|
|
|
2010-06-03 11:05:20 +00:00
|
|
|
#include "table/sprites.h"
|
|
|
|
#include "table/strings.h"
|
|
|
|
|
2014-04-23 20:13:33 +00:00
|
|
|
#include "safeguards.h"
|
|
|
|
|
2010-06-03 11:05:20 +00:00
|
|
|
SaveLoadDialogMode _saveload_mode;
|
2010-06-13 14:13:23 +00:00
|
|
|
LoadCheckData _load_check_data; ///< Data loaded from save during SL_LOAD_CHECK.
|
2010-06-03 11:05:20 +00:00
|
|
|
|
|
|
|
static bool _fios_path_changed;
|
|
|
|
static bool _savegame_sort_dirty;
|
|
|
|
|
|
|
|
|
2010-06-13 14:13:23 +00:00
|
|
|
/**
|
|
|
|
* Reset read data.
|
|
|
|
*/
|
|
|
|
void LoadCheckData::Clear()
|
|
|
|
{
|
|
|
|
this->checkable = false;
|
|
|
|
this->error = INVALID_STRING_ID;
|
|
|
|
free(this->error_data);
|
|
|
|
this->error_data = NULL;
|
2010-06-13 14:13:49 +00:00
|
|
|
|
|
|
|
this->map_size_x = this->map_size_y = 256; // Default for old savegames which do not store mapsize.
|
2010-06-13 14:14:20 +00:00
|
|
|
this->current_date = 0;
|
2010-06-13 14:14:37 +00:00
|
|
|
memset(&this->settings, 0, sizeof(this->settings));
|
2010-06-13 14:15:36 +00:00
|
|
|
|
|
|
|
const CompanyPropertiesMap::iterator end = this->companies.End();
|
|
|
|
for (CompanyPropertiesMap::iterator it = this->companies.Begin(); it != end; it++) {
|
|
|
|
delete it->second;
|
|
|
|
}
|
|
|
|
companies.Clear();
|
2010-06-13 14:15:58 +00:00
|
|
|
|
2012-02-05 15:51:13 +00:00
|
|
|
GamelogFree(this->gamelog_action, this->gamelog_actions);
|
2011-10-30 13:47:45 +00:00
|
|
|
this->gamelog_action = NULL;
|
|
|
|
this->gamelog_actions = 0;
|
|
|
|
|
2010-06-13 14:15:58 +00:00
|
|
|
ClearGRFConfigList(&this->grfconfig);
|
2010-06-13 14:13:23 +00:00
|
|
|
}
|
|
|
|
|
2010-06-13 14:17:02 +00:00
|
|
|
/** Load game/scenario with optional content download */
|
2010-06-03 11:05:20 +00:00
|
|
|
static const NWidgetPart _nested_load_dialog_widgets[] = {
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
|
|
|
NWidget(WWT_CLOSEBOX, COLOUR_GREY),
|
2011-12-16 16:27:45 +00:00
|
|
|
NWidget(WWT_CAPTION, COLOUR_GREY, WID_SL_CAPTION),
|
2013-05-26 19:30:07 +00:00
|
|
|
NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
|
2010-06-03 11:05:20 +00:00
|
|
|
EndContainer(),
|
2011-12-16 16:27:45 +00:00
|
|
|
NWidget(WWT_PANEL, COLOUR_GREY, WID_SL_BACKGROUND), SetFill(1, 0), SetResize(1, 0), EndContainer(),
|
2010-06-13 14:17:26 +00:00
|
|
|
NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
|
|
|
|
NWidget(NWID_VERTICAL),
|
2010-06-13 14:16:27 +00:00
|
|
|
NWidget(NWID_HORIZONTAL),
|
2010-06-13 14:17:26 +00:00
|
|
|
NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
|
2011-12-16 16:27:45 +00:00
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SL_SORT_BYNAME), SetDataTip(STR_SORT_BY_CAPTION_NAME, STR_TOOLTIP_SORT_ORDER), SetFill(1, 0), SetResize(1, 0),
|
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SL_SORT_BYDATE), SetDataTip(STR_SORT_BY_CAPTION_DATE, STR_TOOLTIP_SORT_ORDER), SetFill(1, 0), SetResize(1, 0),
|
2010-06-13 14:17:26 +00:00
|
|
|
EndContainer(),
|
2011-12-16 16:27:45 +00:00
|
|
|
NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_SL_HOME_BUTTON), SetMinimalSize(12, 12), SetDataTip(SPR_HOUSE_ICON, STR_SAVELOAD_HOME_BUTTON),
|
2010-06-13 14:17:26 +00:00
|
|
|
EndContainer(),
|
2011-12-16 16:27:45 +00:00
|
|
|
NWidget(WWT_PANEL, COLOUR_GREY, WID_SL_FILE_BACKGROUND),
|
2010-06-13 14:17:26 +00:00
|
|
|
NWidget(NWID_HORIZONTAL),
|
2011-12-16 16:27:45 +00:00
|
|
|
NWidget(WWT_INSET, COLOUR_GREY, WID_SL_DRIVES_DIRECTORIES_LIST), SetFill(1, 1), SetPadding(2, 1, 2, 2),
|
|
|
|
SetDataTip(0x0, STR_SAVELOAD_LIST_TOOLTIP), SetResize(1, 10), SetScrollbar(WID_SL_SCROLLBAR), EndContainer(),
|
|
|
|
NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_SL_SCROLLBAR),
|
2010-06-13 14:16:27 +00:00
|
|
|
EndContainer(),
|
2011-12-16 16:27:45 +00:00
|
|
|
NWidget(NWID_SELECTION, INVALID_COLOUR, WID_SL_CONTENT_DOWNLOAD_SEL),
|
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SL_CONTENT_DOWNLOAD), SetResize(1, 0),
|
2010-06-13 14:17:26 +00:00
|
|
|
SetDataTip(STR_INTRO_ONLINE_CONTENT, STR_INTRO_TOOLTIP_ONLINE_CONTENT),
|
|
|
|
EndContainer(),
|
|
|
|
EndContainer(),
|
|
|
|
EndContainer(),
|
|
|
|
NWidget(WWT_PANEL, COLOUR_GREY),
|
2011-12-16 16:27:45 +00:00
|
|
|
NWidget(WWT_EMPTY, INVALID_COLOUR, WID_SL_DETAILS), SetResize(1, 1), SetFill(1, 1),
|
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SL_MISSING_NEWGRFS), SetDataTip(STR_NEWGRF_SETTINGS_FIND_MISSING_CONTENT_BUTTON, STR_NEWGRF_SETTINGS_FIND_MISSING_CONTENT_TOOLTIP), SetFill(1, 0), SetResize(1, 0),
|
2010-06-13 14:17:26 +00:00
|
|
|
NWidget(NWID_HORIZONTAL),
|
|
|
|
NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
|
2011-12-16 16:27:45 +00:00
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SL_NEWGRF_INFO), SetDataTip(STR_INTRO_NEWGRF_SETTINGS, STR_NULL), SetFill(1, 0), SetResize(1, 0),
|
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SL_LOAD_BUTTON), SetDataTip(STR_SAVELOAD_LOAD_BUTTON, STR_SAVELOAD_LOAD_TOOLTIP), SetFill(1, 0), SetResize(1, 0),
|
2010-06-13 14:17:26 +00:00
|
|
|
EndContainer(),
|
|
|
|
NWidget(WWT_RESIZEBOX, COLOUR_GREY),
|
2010-06-03 11:05:20 +00:00
|
|
|
EndContainer(),
|
|
|
|
EndContainer(),
|
|
|
|
EndContainer(),
|
|
|
|
};
|
|
|
|
|
2010-06-13 14:17:02 +00:00
|
|
|
/** Load heightmap with content download */
|
|
|
|
static const NWidgetPart _nested_load_heightmap_dialog_widgets[] = {
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
|
|
|
NWidget(WWT_CLOSEBOX, COLOUR_GREY),
|
2011-12-16 16:27:45 +00:00
|
|
|
NWidget(WWT_CAPTION, COLOUR_GREY, WID_SL_CAPTION),
|
2013-05-26 19:30:07 +00:00
|
|
|
NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
|
2010-06-13 14:17:02 +00:00
|
|
|
EndContainer(),
|
2011-12-16 16:27:45 +00:00
|
|
|
NWidget(WWT_PANEL, COLOUR_GREY, WID_SL_BACKGROUND), SetFill(1, 0), SetResize(1, 0), EndContainer(),
|
2010-06-13 14:17:02 +00:00
|
|
|
NWidget(NWID_VERTICAL),
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
|
|
|
NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
|
2011-12-16 16:27:45 +00:00
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SL_SORT_BYNAME), SetDataTip(STR_SORT_BY_CAPTION_NAME, STR_TOOLTIP_SORT_ORDER), SetFill(1, 0), SetResize(1, 0),
|
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SL_SORT_BYDATE), SetDataTip(STR_SORT_BY_CAPTION_DATE, STR_TOOLTIP_SORT_ORDER), SetFill(1, 0), SetResize(1, 0),
|
2010-06-13 14:17:02 +00:00
|
|
|
EndContainer(),
|
2011-12-16 16:27:45 +00:00
|
|
|
NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_SL_HOME_BUTTON), SetMinimalSize(12, 12), SetDataTip(SPR_HOUSE_ICON, STR_SAVELOAD_HOME_BUTTON),
|
2010-06-13 14:17:02 +00:00
|
|
|
EndContainer(),
|
2011-12-16 16:27:45 +00:00
|
|
|
NWidget(WWT_PANEL, COLOUR_GREY, WID_SL_FILE_BACKGROUND),
|
2010-06-13 14:17:02 +00:00
|
|
|
NWidget(NWID_HORIZONTAL),
|
2011-12-16 16:27:45 +00:00
|
|
|
NWidget(WWT_INSET, COLOUR_GREY, WID_SL_DRIVES_DIRECTORIES_LIST), SetFill(1, 1), SetPadding(2, 1, 2, 2),
|
|
|
|
SetDataTip(0x0, STR_SAVELOAD_LIST_TOOLTIP), SetResize(1, 10), SetScrollbar(WID_SL_SCROLLBAR), EndContainer(),
|
|
|
|
NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_SL_SCROLLBAR),
|
2010-06-13 14:17:02 +00:00
|
|
|
EndContainer(),
|
2014-03-25 21:47:07 +00:00
|
|
|
NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
|
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SL_CONTENT_DOWNLOAD), SetResize(1, 0), SetFill(1, 0),
|
2010-06-13 14:17:02 +00:00
|
|
|
SetDataTip(STR_INTRO_ONLINE_CONTENT, STR_INTRO_TOOLTIP_ONLINE_CONTENT),
|
2014-03-25 21:47:07 +00:00
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SL_LOAD_BUTTON), SetResize(1, 0), SetFill(1, 0),
|
|
|
|
SetDataTip(STR_SAVELOAD_LOAD_BUTTON, STR_SAVELOAD_LOAD_HEIGHTMAP_TOOLTIP),
|
2010-06-13 14:17:02 +00:00
|
|
|
NWidget(WWT_RESIZEBOX, COLOUR_GREY),
|
|
|
|
EndContainer(),
|
|
|
|
EndContainer(),
|
|
|
|
EndContainer(),
|
|
|
|
};
|
|
|
|
|
|
|
|
/** Save game/scenario */
|
2010-06-03 11:05:20 +00:00
|
|
|
static const NWidgetPart _nested_save_dialog_widgets[] = {
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
|
|
|
NWidget(WWT_CLOSEBOX, COLOUR_GREY),
|
2011-12-16 16:27:45 +00:00
|
|
|
NWidget(WWT_CAPTION, COLOUR_GREY, WID_SL_CAPTION),
|
2013-05-26 19:30:07 +00:00
|
|
|
NWidget(WWT_DEFSIZEBOX, COLOUR_GREY),
|
2010-06-03 11:05:20 +00:00
|
|
|
EndContainer(),
|
2011-12-16 16:27:45 +00:00
|
|
|
NWidget(WWT_PANEL, COLOUR_GREY, WID_SL_BACKGROUND), SetFill(1, 0), SetResize(1, 0), EndContainer(),
|
2010-06-13 14:17:26 +00:00
|
|
|
NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
|
|
|
|
NWidget(NWID_VERTICAL),
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
|
|
|
NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
|
2011-12-16 16:27:45 +00:00
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SL_SORT_BYNAME), SetDataTip(STR_SORT_BY_CAPTION_NAME, STR_TOOLTIP_SORT_ORDER), SetFill(1, 0), SetResize(1, 0),
|
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SL_SORT_BYDATE), SetDataTip(STR_SORT_BY_CAPTION_DATE, STR_TOOLTIP_SORT_ORDER), SetFill(1, 0), SetResize(1, 0),
|
2010-06-13 14:17:26 +00:00
|
|
|
EndContainer(),
|
2011-12-16 16:27:45 +00:00
|
|
|
NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_SL_HOME_BUTTON), SetMinimalSize(12, 12), SetDataTip(SPR_HOUSE_ICON, STR_SAVELOAD_HOME_BUTTON),
|
2010-06-13 14:17:26 +00:00
|
|
|
EndContainer(),
|
2011-12-16 16:27:45 +00:00
|
|
|
NWidget(WWT_PANEL, COLOUR_GREY, WID_SL_FILE_BACKGROUND),
|
2010-06-13 14:17:26 +00:00
|
|
|
NWidget(NWID_HORIZONTAL),
|
2011-12-16 16:27:45 +00:00
|
|
|
NWidget(WWT_INSET, COLOUR_GREY, WID_SL_DRIVES_DIRECTORIES_LIST), SetPadding(2, 1, 0, 2),
|
|
|
|
SetDataTip(0x0, STR_SAVELOAD_LIST_TOOLTIP), SetResize(1, 10), SetScrollbar(WID_SL_SCROLLBAR), EndContainer(),
|
|
|
|
NWidget(NWID_VSCROLLBAR, COLOUR_GREY, WID_SL_SCROLLBAR),
|
2010-06-13 14:17:26 +00:00
|
|
|
EndContainer(),
|
2011-12-16 16:27:45 +00:00
|
|
|
NWidget(WWT_EDITBOX, COLOUR_GREY, WID_SL_SAVE_OSK_TITLE), SetPadding(3, 2, 2, 2), SetFill(1, 0), SetResize(1, 0),
|
2010-06-13 14:17:26 +00:00
|
|
|
SetDataTip(STR_SAVELOAD_OSKTITLE, STR_SAVELOAD_EDITBOX_TOOLTIP),
|
2010-06-13 14:16:27 +00:00
|
|
|
EndContainer(),
|
|
|
|
NWidget(NWID_HORIZONTAL),
|
2011-12-16 16:27:45 +00:00
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SL_DELETE_SELECTION), SetDataTip(STR_SAVELOAD_DELETE_BUTTON, STR_SAVELOAD_DELETE_TOOLTIP), SetFill(1, 0), SetResize(1, 0),
|
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SL_SAVE_GAME), SetDataTip(STR_SAVELOAD_SAVE_BUTTON, STR_SAVELOAD_SAVE_TOOLTIP), SetFill(1, 0), SetResize(1, 0),
|
2010-06-03 11:05:20 +00:00
|
|
|
EndContainer(),
|
2010-06-13 14:16:27 +00:00
|
|
|
EndContainer(),
|
2010-06-13 14:17:26 +00:00
|
|
|
NWidget(WWT_PANEL, COLOUR_GREY),
|
2011-12-16 16:27:45 +00:00
|
|
|
NWidget(WWT_EMPTY, INVALID_COLOUR, WID_SL_DETAILS), SetResize(1, 1), SetFill(1, 1),
|
2010-06-13 14:17:26 +00:00
|
|
|
NWidget(NWID_HORIZONTAL),
|
|
|
|
NWidget(NWID_SPACER), SetResize(1, 0), SetFill(1, 1),
|
|
|
|
NWidget(WWT_RESIZEBOX, COLOUR_GREY),
|
|
|
|
EndContainer(),
|
2010-06-03 11:05:20 +00:00
|
|
|
EndContainer(),
|
|
|
|
EndContainer(),
|
|
|
|
};
|
|
|
|
|
2011-05-27 21:20:07 +00:00
|
|
|
/** Colours for fios types, indexed by #FiosType. */
|
2010-06-03 11:05:20 +00:00
|
|
|
const TextColour _fios_colours[] = {
|
|
|
|
TC_LIGHT_BLUE, TC_DARK_GREEN, TC_DARK_GREEN, TC_ORANGE, TC_LIGHT_BROWN,
|
|
|
|
TC_ORANGE, TC_LIGHT_BROWN, TC_ORANGE, TC_ORANGE, TC_YELLOW
|
|
|
|
};
|
|
|
|
|
|
|
|
void BuildFileList()
|
|
|
|
{
|
|
|
|
_fios_path_changed = true;
|
|
|
|
FiosFreeSavegameList();
|
|
|
|
|
|
|
|
switch (_saveload_mode) {
|
|
|
|
case SLD_LOAD_SCENARIO:
|
|
|
|
case SLD_SAVE_SCENARIO:
|
|
|
|
FiosGetScenarioList(_saveload_mode); break;
|
2011-05-28 13:55:59 +00:00
|
|
|
case SLD_SAVE_HEIGHTMAP:
|
2010-06-03 11:05:20 +00:00
|
|
|
case SLD_LOAD_HEIGHTMAP:
|
|
|
|
FiosGetHeightmapList(_saveload_mode); break;
|
|
|
|
|
|
|
|
default: FiosGetSavegameList(_saveload_mode); break;
|
|
|
|
}
|
2011-05-15 12:30:14 +00:00
|
|
|
|
|
|
|
/* Invalidate saveload window */
|
|
|
|
InvalidateWindowData(WC_SAVELOAD, 0, 2, true);
|
2010-06-03 11:05:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void MakeSortedSaveGameList()
|
|
|
|
{
|
|
|
|
uint sort_start = 0;
|
|
|
|
uint sort_end = 0;
|
|
|
|
|
|
|
|
/* Directories are always above the files (FIOS_TYPE_DIR)
|
|
|
|
* Drives (A:\ (windows only) are always under the files (FIOS_TYPE_DRIVE)
|
|
|
|
* Only sort savegames/scenarios, not directories
|
|
|
|
*/
|
|
|
|
for (const FiosItem *item = _fios_items.Begin(); item != _fios_items.End(); item++) {
|
|
|
|
switch (item->type) {
|
|
|
|
case FIOS_TYPE_DIR: sort_start++; break;
|
|
|
|
case FIOS_TYPE_PARENT: sort_start++; break;
|
|
|
|
case FIOS_TYPE_DRIVE: sort_end++; break;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
uint s_amount = _fios_items.Length() - sort_start - sort_end;
|
|
|
|
QSortT(_fios_items.Get(sort_start), s_amount, CompareFiosItems);
|
|
|
|
}
|
|
|
|
|
2012-11-14 22:50:35 +00:00
|
|
|
struct SaveLoadWindow : public Window {
|
2010-06-03 11:05:20 +00:00
|
|
|
private:
|
2012-11-14 22:50:35 +00:00
|
|
|
QueryString filename_editbox; ///< Filename editbox.
|
2010-06-03 11:05:20 +00:00
|
|
|
FiosItem o_dir;
|
2010-06-13 14:17:26 +00:00
|
|
|
const FiosItem *selected;
|
2010-08-12 08:37:01 +00:00
|
|
|
Scrollbar *vscroll;
|
2010-06-03 11:05:20 +00:00
|
|
|
public:
|
|
|
|
|
2011-05-28 13:55:59 +00:00
|
|
|
/** Generate a default save filename. */
|
2010-06-03 11:05:20 +00:00
|
|
|
void GenerateFileName()
|
|
|
|
{
|
2012-11-14 22:50:35 +00:00
|
|
|
GenerateDefaultSaveName(this->filename_editbox.text.buf, &this->filename_editbox.text.buf[this->filename_editbox.text.max_bytes - 1]);
|
|
|
|
this->filename_editbox.text.UpdateSize();
|
2010-06-03 11:05:20 +00:00
|
|
|
}
|
|
|
|
|
2013-05-26 19:23:42 +00:00
|
|
|
SaveLoadWindow(WindowDesc *desc, SaveLoadDialogMode mode) : Window(desc), filename_editbox(64)
|
2010-06-03 11:05:20 +00:00
|
|
|
{
|
|
|
|
static const StringID saveload_captions[] = {
|
|
|
|
STR_SAVELOAD_LOAD_CAPTION,
|
|
|
|
STR_SAVELOAD_LOAD_SCENARIO,
|
|
|
|
STR_SAVELOAD_SAVE_CAPTION,
|
|
|
|
STR_SAVELOAD_SAVE_SCENARIO,
|
|
|
|
STR_SAVELOAD_LOAD_HEIGHTMAP,
|
2011-05-28 13:55:59 +00:00
|
|
|
STR_SAVELOAD_SAVE_HEIGHTMAP,
|
2010-06-03 11:05:20 +00:00
|
|
|
};
|
|
|
|
assert((uint)mode < lengthof(saveload_captions));
|
|
|
|
|
|
|
|
/* Use an array to define what will be the current file type being handled
|
|
|
|
* by current file mode */
|
|
|
|
switch (mode) {
|
|
|
|
case SLD_SAVE_GAME: this->GenerateFileName(); break;
|
2011-05-28 13:55:59 +00:00
|
|
|
case SLD_SAVE_HEIGHTMAP:
|
2012-11-14 22:50:35 +00:00
|
|
|
case SLD_SAVE_SCENARIO: this->filename_editbox.text.Assign("UNNAMED"); break;
|
2010-06-03 11:05:20 +00:00
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
|
2012-11-14 22:50:35 +00:00
|
|
|
this->querystrings[WID_SL_SAVE_OSK_TITLE] = &this->filename_editbox;
|
|
|
|
this->filename_editbox.ok_button = WID_SL_SAVE_GAME;
|
2010-06-03 11:05:20 +00:00
|
|
|
|
2013-05-26 19:23:42 +00:00
|
|
|
this->CreateNestedTree(true);
|
2011-12-16 16:27:45 +00:00
|
|
|
if (mode == SLD_LOAD_GAME) this->GetWidget<NWidgetStacked>(WID_SL_CONTENT_DOWNLOAD_SEL)->SetDisplayedPlane(SZSP_HORIZONTAL);
|
|
|
|
this->GetWidget<NWidgetCore>(WID_SL_CAPTION)->widget_data = saveload_captions[mode];
|
|
|
|
this->vscroll = this->GetScrollbar(WID_SL_SCROLLBAR);
|
2010-06-03 11:05:20 +00:00
|
|
|
|
2013-05-26 19:23:42 +00:00
|
|
|
this->FinishInitNested(0);
|
2010-06-03 11:05:20 +00:00
|
|
|
|
2011-12-16 16:27:45 +00:00
|
|
|
this->LowerWidget(WID_SL_DRIVES_DIRECTORIES_LIST);
|
2010-06-03 11:05:20 +00:00
|
|
|
|
|
|
|
/* pause is only used in single-player, non-editor mode, non-menu mode. It
|
|
|
|
* will be unpaused in the WE_DESTROY event handler. */
|
|
|
|
if (_game_mode != GM_MENU && !_networking && _game_mode != GM_EDITOR) {
|
|
|
|
DoCommandP(0, PM_PAUSED_SAVELOAD, 1, CMD_PAUSE);
|
|
|
|
}
|
|
|
|
SetObjectToPlace(SPR_CURSOR_ZZZ, PAL_NONE, HT_NONE, WC_MAIN_WINDOW, 0);
|
|
|
|
|
2010-06-12 14:52:42 +00:00
|
|
|
this->OnInvalidateData(0);
|
2010-06-03 11:05:20 +00:00
|
|
|
|
|
|
|
ResetObjectToPlace();
|
|
|
|
|
|
|
|
o_dir.type = FIOS_TYPE_DIRECT;
|
|
|
|
switch (_saveload_mode) {
|
|
|
|
case SLD_SAVE_GAME:
|
|
|
|
case SLD_LOAD_GAME:
|
2014-04-23 21:23:21 +00:00
|
|
|
FioGetDirectory(o_dir.name, lastof(o_dir.name), SAVE_DIR);
|
2010-06-03 11:05:20 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SLD_SAVE_SCENARIO:
|
|
|
|
case SLD_LOAD_SCENARIO:
|
2014-04-23 21:23:21 +00:00
|
|
|
FioGetDirectory(o_dir.name, lastof(o_dir.name), SCENARIO_DIR);
|
2010-06-03 11:05:20 +00:00
|
|
|
break;
|
|
|
|
|
2011-05-28 13:55:59 +00:00
|
|
|
case SLD_SAVE_HEIGHTMAP:
|
2010-06-03 11:05:20 +00:00
|
|
|
case SLD_LOAD_HEIGHTMAP:
|
2014-04-23 21:23:21 +00:00
|
|
|
FioGetDirectory(o_dir.name, lastof(o_dir.name), HEIGHTMAP_DIR);
|
2010-06-03 11:05:20 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
strecpy(o_dir.name, _personal_dir, lastof(o_dir.name));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Focus the edit box by default in the save windows */
|
2011-05-28 13:55:59 +00:00
|
|
|
if (_saveload_mode == SLD_SAVE_GAME || _saveload_mode == SLD_SAVE_SCENARIO || _saveload_mode == SLD_SAVE_HEIGHTMAP) {
|
2011-12-16 16:27:45 +00:00
|
|
|
this->SetFocusedWidget(WID_SL_SAVE_OSK_TITLE);
|
2010-06-03 11:05:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~SaveLoadWindow()
|
|
|
|
{
|
|
|
|
/* pause is only used in single-player, non-editor mode, non menu mode */
|
|
|
|
if (!_networking && _game_mode != GM_EDITOR && _game_mode != GM_MENU) {
|
|
|
|
DoCommandP(0, PM_PAUSED_SAVELOAD, 0, CMD_PAUSE);
|
|
|
|
}
|
|
|
|
FiosFreeSavegameList();
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void DrawWidget(const Rect &r, int widget) const
|
|
|
|
{
|
|
|
|
switch (widget) {
|
2011-12-16 16:27:45 +00:00
|
|
|
case WID_SL_SORT_BYNAME:
|
|
|
|
case WID_SL_SORT_BYDATE:
|
|
|
|
if (((_savegame_sort_order & SORT_BY_NAME) != 0) == (widget == WID_SL_SORT_BYNAME)) {
|
2010-06-03 11:05:20 +00:00
|
|
|
this->DrawSortButtonState(widget, _savegame_sort_order & SORT_DESCENDING ? SBS_DOWN : SBS_UP);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2011-12-16 16:27:45 +00:00
|
|
|
case WID_SL_BACKGROUND: {
|
2010-06-03 11:05:20 +00:00
|
|
|
static const char *path = NULL;
|
|
|
|
static StringID str = STR_ERROR_UNABLE_TO_READ_DRIVE;
|
|
|
|
static uint64 tot = 0;
|
|
|
|
|
|
|
|
if (_fios_path_changed) {
|
|
|
|
str = FiosGetDescText(&path, &tot);
|
|
|
|
_fios_path_changed = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (str != STR_ERROR_UNABLE_TO_READ_DRIVE) SetDParam(0, tot);
|
|
|
|
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + FONT_HEIGHT_NORMAL + WD_FRAMERECT_TOP, str);
|
|
|
|
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + WD_FRAMERECT_TOP, path, TC_BLACK);
|
2010-08-01 18:53:30 +00:00
|
|
|
break;
|
|
|
|
}
|
2010-06-03 11:05:20 +00:00
|
|
|
|
2011-12-16 16:27:45 +00:00
|
|
|
case WID_SL_DRIVES_DIRECTORIES_LIST: {
|
2011-05-06 21:13:29 +00:00
|
|
|
GfxFillRect(r.left + 1, r.top + 1, r.right, r.bottom, PC_BLACK);
|
2010-06-03 11:05:20 +00:00
|
|
|
|
|
|
|
uint y = r.top + WD_FRAMERECT_TOP;
|
2010-08-12 08:37:01 +00:00
|
|
|
for (uint pos = this->vscroll->GetPosition(); pos < _fios_items.Length(); pos++) {
|
2010-06-03 11:05:20 +00:00
|
|
|
const FiosItem *item = _fios_items.Get(pos);
|
|
|
|
|
2010-06-13 14:17:26 +00:00
|
|
|
if (item == this->selected) {
|
2011-05-06 21:13:29 +00:00
|
|
|
GfxFillRect(r.left + 1, y, r.right, y + this->resize.step_height, PC_DARK_BLUE);
|
2010-06-13 14:17:26 +00:00
|
|
|
}
|
2010-06-03 11:05:20 +00:00
|
|
|
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, item->title, _fios_colours[item->type]);
|
|
|
|
y += this->resize.step_height;
|
2010-08-12 08:37:01 +00:00
|
|
|
if (y >= this->vscroll->GetCapacity() * this->resize.step_height + r.top + WD_FRAMERECT_TOP) break;
|
2010-06-03 11:05:20 +00:00
|
|
|
}
|
2010-08-01 18:53:30 +00:00
|
|
|
break;
|
|
|
|
}
|
2010-06-13 14:17:26 +00:00
|
|
|
|
2011-12-16 16:27:45 +00:00
|
|
|
case WID_SL_DETAILS: {
|
2010-06-13 14:17:26 +00:00
|
|
|
GfxFillRect(r.left + WD_FRAMERECT_LEFT, r.top + WD_FRAMERECT_TOP,
|
2011-05-06 21:13:29 +00:00
|
|
|
r.right - WD_FRAMERECT_RIGHT, r.top + FONT_HEIGHT_NORMAL * 2 + WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM, PC_GREY);
|
2010-07-02 13:53:05 +00:00
|
|
|
DrawString(r.left, r.right, r.top + FONT_HEIGHT_NORMAL / 2 + WD_FRAMERECT_TOP, STR_SAVELOAD_DETAIL_CAPTION, TC_FROMSTRING, SA_HOR_CENTER);
|
2010-06-13 14:17:26 +00:00
|
|
|
|
|
|
|
if (this->selected == NULL) break;
|
|
|
|
|
|
|
|
uint y = r.top + FONT_HEIGHT_NORMAL * 2 + WD_PAR_VSEP_NORMAL + WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM;
|
|
|
|
uint y_max = r.bottom - FONT_HEIGHT_NORMAL - WD_FRAMERECT_BOTTOM;
|
|
|
|
|
|
|
|
if (y > y_max) break;
|
|
|
|
if (!_load_check_data.checkable) {
|
|
|
|
/* Old savegame, no information available */
|
|
|
|
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_SAVELOAD_DETAIL_NOT_AVAILABLE);
|
|
|
|
y += FONT_HEIGHT_NORMAL;
|
|
|
|
} else if (_load_check_data.error != INVALID_STRING_ID) {
|
|
|
|
/* Incompatible / broken savegame */
|
|
|
|
SetDParamStr(0, _load_check_data.error_data);
|
|
|
|
y = DrawStringMultiLine(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT,
|
|
|
|
y, r.bottom - WD_FRAMERECT_BOTTOM, _load_check_data.error, TC_RED);
|
|
|
|
} else {
|
|
|
|
/* Mapsize */
|
|
|
|
SetDParam(0, _load_check_data.map_size_x);
|
|
|
|
SetDParam(1, _load_check_data.map_size_y);
|
|
|
|
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_NETWORK_SERVER_LIST_MAP_SIZE);
|
|
|
|
y += FONT_HEIGHT_NORMAL;
|
|
|
|
if (y > y_max) break;
|
|
|
|
|
|
|
|
/* Climate */
|
|
|
|
byte landscape = _load_check_data.settings.game_creation.landscape;
|
|
|
|
if (landscape < NUM_LANDSCAPE) {
|
|
|
|
SetDParam(0, STR_CHEAT_SWITCH_CLIMATE_TEMPERATE_LANDSCAPE + landscape);
|
|
|
|
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_NETWORK_SERVER_LIST_LANDSCAPE);
|
|
|
|
y += FONT_HEIGHT_NORMAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
y += WD_PAR_VSEP_NORMAL;
|
|
|
|
if (y > y_max) break;
|
|
|
|
|
|
|
|
/* Start date (if available) */
|
|
|
|
if (_load_check_data.settings.game_creation.starting_year != 0) {
|
|
|
|
SetDParam(0, ConvertYMDToDate(_load_check_data.settings.game_creation.starting_year, 0, 1));
|
|
|
|
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_NETWORK_SERVER_LIST_START_DATE);
|
|
|
|
y += FONT_HEIGHT_NORMAL;
|
|
|
|
}
|
|
|
|
if (y > y_max) break;
|
|
|
|
|
|
|
|
/* Hide current date for scenarios */
|
|
|
|
if (_saveload_mode != SLD_LOAD_SCENARIO && _saveload_mode != SLD_SAVE_SCENARIO) {
|
|
|
|
/* Current date */
|
|
|
|
SetDParam(0, _load_check_data.current_date);
|
|
|
|
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_NETWORK_SERVER_LIST_CURRENT_DATE);
|
|
|
|
y += FONT_HEIGHT_NORMAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Hide the NewGRF stuff when saving. We also hide the button. */
|
|
|
|
if (_saveload_mode == SLD_LOAD_GAME || _saveload_mode == SLD_LOAD_SCENARIO) {
|
|
|
|
y += WD_PAR_VSEP_NORMAL;
|
|
|
|
if (y > y_max) break;
|
|
|
|
|
|
|
|
/* NewGrf compatibility */
|
|
|
|
SetDParam(0, _load_check_data.grfconfig == NULL ? STR_NEWGRF_LIST_NONE :
|
|
|
|
STR_NEWGRF_LIST_ALL_FOUND + _load_check_data.grf_compatibility);
|
|
|
|
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_SAVELOAD_DETAIL_GRFSTATUS);
|
|
|
|
y += FONT_HEIGHT_NORMAL;
|
|
|
|
}
|
|
|
|
if (y > y_max) break;
|
|
|
|
|
|
|
|
/* Hide the company stuff for scenarios */
|
|
|
|
if (_saveload_mode != SLD_LOAD_SCENARIO && _saveload_mode != SLD_SAVE_SCENARIO) {
|
|
|
|
y += FONT_HEIGHT_NORMAL;
|
|
|
|
if (y > y_max) break;
|
|
|
|
|
|
|
|
/* Companies / AIs */
|
|
|
|
CompanyPropertiesMap::const_iterator end = _load_check_data.companies.End();
|
|
|
|
for (CompanyPropertiesMap::const_iterator it = _load_check_data.companies.Begin(); it != end; it++) {
|
|
|
|
SetDParam(0, it->first + 1);
|
|
|
|
const CompanyProperties &c = *it->second;
|
|
|
|
if (c.name != NULL) {
|
|
|
|
SetDParam(1, STR_JUST_RAW_STRING);
|
|
|
|
SetDParamStr(2, c.name);
|
|
|
|
} else {
|
|
|
|
SetDParam(1, c.name_1);
|
|
|
|
SetDParam(2, c.name_2);
|
|
|
|
}
|
|
|
|
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_SAVELOAD_DETAIL_COMPANY_INDEX);
|
|
|
|
y += FONT_HEIGHT_NORMAL;
|
|
|
|
if (y > y_max) break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-08-01 18:53:30 +00:00
|
|
|
break;
|
|
|
|
}
|
2010-06-03 11:05:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
|
|
|
|
{
|
|
|
|
switch (widget) {
|
2011-12-16 16:27:45 +00:00
|
|
|
case WID_SL_BACKGROUND:
|
2010-06-03 11:05:20 +00:00
|
|
|
size->height = 2 * FONT_HEIGHT_NORMAL + WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM;
|
|
|
|
break;
|
|
|
|
|
2011-12-16 16:27:45 +00:00
|
|
|
case WID_SL_DRIVES_DIRECTORIES_LIST:
|
2010-06-03 11:05:20 +00:00
|
|
|
resize->height = FONT_HEIGHT_NORMAL;
|
|
|
|
size->height = resize->height * 10 + WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM;
|
|
|
|
break;
|
2011-12-16 16:27:45 +00:00
|
|
|
case WID_SL_SORT_BYNAME:
|
|
|
|
case WID_SL_SORT_BYDATE: {
|
2010-11-12 16:29:09 +00:00
|
|
|
Dimension d = GetStringBoundingBox(this->GetWidget<NWidgetCore>(widget)->widget_data);
|
|
|
|
d.width += padding.width + WD_SORTBUTTON_ARROW_WIDTH * 2; // Doubled since the string is centred and it also looks better.
|
|
|
|
d.height += padding.height;
|
|
|
|
*size = maxdim(*size, d);
|
|
|
|
break;
|
|
|
|
}
|
2010-06-03 11:05:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void OnPaint()
|
|
|
|
{
|
|
|
|
if (_savegame_sort_dirty) {
|
|
|
|
_savegame_sort_dirty = false;
|
|
|
|
MakeSortedSaveGameList();
|
|
|
|
}
|
|
|
|
|
2010-08-12 08:37:01 +00:00
|
|
|
this->vscroll->SetCount(_fios_items.Length());
|
2010-06-03 11:05:20 +00:00
|
|
|
this->DrawWidgets();
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void OnClick(Point pt, int widget, int click_count)
|
|
|
|
{
|
|
|
|
switch (widget) {
|
2011-12-16 16:27:45 +00:00
|
|
|
case WID_SL_SORT_BYNAME: // Sort save names by name
|
2010-06-03 11:05:20 +00:00
|
|
|
_savegame_sort_order = (_savegame_sort_order == SORT_BY_NAME) ?
|
|
|
|
SORT_BY_NAME | SORT_DESCENDING : SORT_BY_NAME;
|
|
|
|
_savegame_sort_dirty = true;
|
|
|
|
this->SetDirty();
|
|
|
|
break;
|
|
|
|
|
2011-12-16 16:27:45 +00:00
|
|
|
case WID_SL_SORT_BYDATE: // Sort save names by date
|
2010-06-03 11:05:20 +00:00
|
|
|
_savegame_sort_order = (_savegame_sort_order == SORT_BY_DATE) ?
|
|
|
|
SORT_BY_DATE | SORT_DESCENDING : SORT_BY_DATE;
|
|
|
|
_savegame_sort_dirty = true;
|
|
|
|
this->SetDirty();
|
|
|
|
break;
|
|
|
|
|
2011-12-16 16:27:45 +00:00
|
|
|
case WID_SL_HOME_BUTTON: // OpenTTD 'button', jumps to OpenTTD directory
|
2010-06-03 11:05:20 +00:00
|
|
|
FiosBrowseTo(&o_dir);
|
2010-06-12 14:52:42 +00:00
|
|
|
this->InvalidateData();
|
2010-06-03 11:05:20 +00:00
|
|
|
break;
|
|
|
|
|
2011-12-16 16:27:45 +00:00
|
|
|
case WID_SL_LOAD_BUTTON:
|
2014-03-25 21:47:07 +00:00
|
|
|
if (this->selected != NULL && !_load_check_data.HasErrors()) {
|
2010-06-13 14:17:26 +00:00
|
|
|
const char *name = FiosBrowseTo(this->selected);
|
|
|
|
SetFiosType(this->selected->type);
|
|
|
|
|
|
|
|
strecpy(_file_to_saveload.name, name, lastof(_file_to_saveload.name));
|
|
|
|
strecpy(_file_to_saveload.title, this->selected->title, lastof(_file_to_saveload.title));
|
2014-03-25 21:47:07 +00:00
|
|
|
|
|
|
|
if (_saveload_mode == SLD_LOAD_HEIGHTMAP) {
|
|
|
|
delete this;
|
|
|
|
ShowHeightmapLoad();
|
|
|
|
} else if (_load_check_data.grf_compatibility != GLC_NOT_FOUND || _settings_client.gui.UserIsAllowedToChangeNewGRFs()) {
|
|
|
|
_switch_mode = (_game_mode == GM_EDITOR) ? SM_LOAD_SCENARIO : SM_LOAD_GAME;
|
|
|
|
ClearErrorMessages();
|
|
|
|
delete this;
|
|
|
|
}
|
2010-06-13 14:17:26 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2011-12-16 16:27:45 +00:00
|
|
|
case WID_SL_NEWGRF_INFO:
|
2010-06-13 14:17:26 +00:00
|
|
|
if (_load_check_data.HasNewGrfs()) {
|
|
|
|
ShowNewGRFSettings(false, false, false, &_load_check_data.grfconfig);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2011-12-16 16:27:45 +00:00
|
|
|
case WID_SL_MISSING_NEWGRFS:
|
2011-12-09 21:49:52 +00:00
|
|
|
if (!_network_available) {
|
|
|
|
ShowErrorMessage(STR_NETWORK_ERROR_NOTAVAILABLE, INVALID_STRING_ID, WL_ERROR);
|
|
|
|
} else {
|
|
|
|
#if defined(ENABLE_NETWORK)
|
|
|
|
ShowMissingContentWindow(_load_check_data.grfconfig);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2011-12-16 16:27:45 +00:00
|
|
|
case WID_SL_DRIVES_DIRECTORIES_LIST: { // Click the listbox
|
|
|
|
int y = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_SL_DRIVES_DIRECTORIES_LIST, WD_FRAMERECT_TOP);
|
2010-07-26 13:08:48 +00:00
|
|
|
if (y == INT_MAX) return;
|
2010-06-03 11:05:20 +00:00
|
|
|
|
|
|
|
const FiosItem *file = _fios_items.Get(y);
|
|
|
|
|
|
|
|
const char *name = FiosBrowseTo(file);
|
|
|
|
if (name != NULL) {
|
2010-06-13 14:17:26 +00:00
|
|
|
if (click_count == 1) {
|
|
|
|
if (this->selected != file) {
|
|
|
|
this->selected = file;
|
|
|
|
_load_check_data.Clear();
|
|
|
|
|
|
|
|
if (file->type == FIOS_TYPE_FILE || file->type == FIOS_TYPE_SCENARIO) {
|
|
|
|
SaveOrLoad(name, SL_LOAD_CHECK, NO_DIRECTORY, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
this->InvalidateData(1);
|
|
|
|
}
|
2011-05-28 13:55:59 +00:00
|
|
|
if (_saveload_mode == SLD_SAVE_GAME || _saveload_mode == SLD_SAVE_SCENARIO || _saveload_mode == SLD_SAVE_HEIGHTMAP) {
|
2010-06-13 14:17:26 +00:00
|
|
|
/* Copy clicked name to editbox */
|
2012-11-14 22:50:35 +00:00
|
|
|
this->filename_editbox.text.Assign(file->title);
|
2011-12-16 16:27:45 +00:00
|
|
|
this->SetWidgetDirty(WID_SL_SAVE_OSK_TITLE);
|
2010-06-13 14:17:26 +00:00
|
|
|
}
|
|
|
|
} else if (!_load_check_data.HasErrors()) {
|
|
|
|
this->selected = file;
|
|
|
|
if (_saveload_mode == SLD_LOAD_GAME || _saveload_mode == SLD_LOAD_SCENARIO) {
|
2011-12-16 16:27:45 +00:00
|
|
|
this->OnClick(pt, WID_SL_LOAD_BUTTON, 1);
|
2010-06-13 14:17:26 +00:00
|
|
|
} else if (_saveload_mode == SLD_LOAD_HEIGHTMAP) {
|
|
|
|
SetFiosType(file->type);
|
|
|
|
strecpy(_file_to_saveload.name, name, lastof(_file_to_saveload.name));
|
|
|
|
strecpy(_file_to_saveload.title, file->title, lastof(_file_to_saveload.title));
|
|
|
|
|
|
|
|
delete this;
|
|
|
|
ShowHeightmapLoad();
|
|
|
|
}
|
2010-06-03 11:05:20 +00:00
|
|
|
}
|
|
|
|
} else {
|
2010-06-12 14:52:42 +00:00
|
|
|
/* Changed directory, need refresh. */
|
|
|
|
this->InvalidateData();
|
2010-06-03 11:05:20 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-12-16 16:27:45 +00:00
|
|
|
case WID_SL_CONTENT_DOWNLOAD:
|
2010-06-03 11:05:20 +00:00
|
|
|
if (!_network_available) {
|
|
|
|
ShowErrorMessage(STR_NETWORK_ERROR_NOTAVAILABLE, INVALID_STRING_ID, WL_ERROR);
|
|
|
|
} else {
|
|
|
|
#if defined(ENABLE_NETWORK)
|
|
|
|
switch (_saveload_mode) {
|
|
|
|
default: NOT_REACHED();
|
|
|
|
case SLD_LOAD_SCENARIO: ShowNetworkContentListWindow(NULL, CONTENT_TYPE_SCENARIO); break;
|
|
|
|
case SLD_LOAD_HEIGHTMAP: ShowNetworkContentListWindow(NULL, CONTENT_TYPE_HEIGHTMAP); break;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2012-11-13 21:46:58 +00:00
|
|
|
case WID_SL_DELETE_SELECTION: // Delete
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WID_SL_SAVE_GAME: // Save game
|
|
|
|
/* Note, this is also called via the OSK; and we need to lower the button. */
|
|
|
|
this->HandleButtonClick(WID_SL_SAVE_GAME);
|
2010-06-03 11:05:20 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-05 20:36:24 +00:00
|
|
|
virtual EventState OnKeyPress(WChar key, uint16 keycode)
|
2010-06-03 11:05:20 +00:00
|
|
|
{
|
|
|
|
if (keycode == WKC_ESC) {
|
|
|
|
delete this;
|
|
|
|
return ES_HANDLED;
|
|
|
|
}
|
|
|
|
|
2012-11-13 21:47:02 +00:00
|
|
|
return ES_NOT_HANDLED;
|
2010-06-03 11:05:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void OnTimeout()
|
|
|
|
{
|
|
|
|
/* This test protects against using widgets 11 and 12 which are only available
|
2011-05-28 13:55:59 +00:00
|
|
|
* in those saveload modes. */
|
|
|
|
if (!(_saveload_mode == SLD_SAVE_GAME || _saveload_mode == SLD_SAVE_SCENARIO || _saveload_mode == SLD_SAVE_HEIGHTMAP)) return;
|
2010-06-03 11:05:20 +00:00
|
|
|
|
2011-12-16 16:27:45 +00:00
|
|
|
if (this->IsWidgetLowered(WID_SL_DELETE_SELECTION)) { // Delete button clicked
|
2012-11-14 22:50:35 +00:00
|
|
|
if (!FiosDelete(this->filename_editbox.text.buf)) {
|
2010-06-03 11:05:20 +00:00
|
|
|
ShowErrorMessage(STR_ERROR_UNABLE_TO_DELETE_FILE, INVALID_STRING_ID, WL_ERROR);
|
|
|
|
} else {
|
2010-06-12 14:52:42 +00:00
|
|
|
this->InvalidateData();
|
2010-06-03 11:05:20 +00:00
|
|
|
/* Reset file name to current date on successful delete */
|
|
|
|
if (_saveload_mode == SLD_SAVE_GAME) GenerateFileName();
|
|
|
|
}
|
2011-12-16 16:27:45 +00:00
|
|
|
} else if (this->IsWidgetLowered(WID_SL_SAVE_GAME)) { // Save button clicked
|
2011-05-28 13:55:59 +00:00
|
|
|
if (_saveload_mode == SLD_SAVE_GAME || _saveload_mode == SLD_SAVE_SCENARIO) {
|
|
|
|
_switch_mode = SM_SAVE_GAME;
|
2014-04-23 21:23:21 +00:00
|
|
|
FiosMakeSavegameName(_file_to_saveload.name, this->filename_editbox.text.buf, lastof(_file_to_saveload.name));
|
2011-05-28 13:55:59 +00:00
|
|
|
} else {
|
|
|
|
_switch_mode = SM_SAVE_HEIGHTMAP;
|
2014-04-23 21:23:21 +00:00
|
|
|
FiosMakeHeightmapName(_file_to_saveload.name, this->filename_editbox.text.buf, lastof(_file_to_saveload.name));
|
2011-05-28 13:55:59 +00:00
|
|
|
}
|
2010-06-03 11:05:20 +00:00
|
|
|
|
|
|
|
/* In the editor set up the vehicle engines correctly (date might have changed) */
|
|
|
|
if (_game_mode == GM_EDITOR) StartupEngines();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void OnResize()
|
|
|
|
{
|
2011-12-16 16:27:45 +00:00
|
|
|
this->vscroll->SetCapacityFromWidget(this, WID_SL_DRIVES_DIRECTORIES_LIST);
|
2010-06-03 11:05:20 +00:00
|
|
|
}
|
|
|
|
|
2011-03-13 21:31:29 +00:00
|
|
|
/**
|
|
|
|
* Some data on this window has become invalid.
|
|
|
|
* @param data Information about the changed data.
|
|
|
|
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
|
|
|
|
*/
|
|
|
|
virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
|
2010-06-03 11:05:20 +00:00
|
|
|
{
|
2010-06-13 14:17:26 +00:00
|
|
|
switch (data) {
|
|
|
|
case 0:
|
|
|
|
/* Rescan files */
|
|
|
|
this->selected = NULL;
|
|
|
|
_load_check_data.Clear();
|
2011-03-13 21:35:50 +00:00
|
|
|
if (!gui_scope) break;
|
2010-06-13 14:17:26 +00:00
|
|
|
BuildFileList();
|
2010-08-01 20:52:11 +00:00
|
|
|
/* FALL THROUGH */
|
2010-06-13 14:17:26 +00:00
|
|
|
case 1:
|
|
|
|
/* Selection changes */
|
2011-03-13 21:35:50 +00:00
|
|
|
if (!gui_scope) break;
|
2014-03-25 21:47:07 +00:00
|
|
|
if (_saveload_mode == SLD_LOAD_HEIGHTMAP) {
|
|
|
|
this->SetWidgetDisabledState(WID_SL_LOAD_BUTTON, this->selected == NULL || _load_check_data.HasErrors());
|
|
|
|
}
|
2010-06-13 14:17:26 +00:00
|
|
|
if (_saveload_mode == SLD_LOAD_GAME || _saveload_mode == SLD_LOAD_SCENARIO) {
|
2011-12-16 16:27:45 +00:00
|
|
|
this->SetWidgetDisabledState(WID_SL_LOAD_BUTTON,
|
2010-11-07 21:46:41 +00:00
|
|
|
this->selected == NULL || _load_check_data.HasErrors() || !(_load_check_data.grf_compatibility != GLC_NOT_FOUND || _settings_client.gui.UserIsAllowedToChangeNewGRFs()));
|
2011-12-16 16:27:45 +00:00
|
|
|
this->SetWidgetDisabledState(WID_SL_NEWGRF_INFO,
|
2010-06-13 14:17:26 +00:00
|
|
|
!_load_check_data.HasNewGrfs());
|
2011-12-16 16:27:45 +00:00
|
|
|
this->SetWidgetDisabledState(WID_SL_MISSING_NEWGRFS,
|
2011-12-09 21:49:52 +00:00
|
|
|
!_load_check_data.HasNewGrfs() || _load_check_data.grf_compatibility == GLC_ALL_GOOD);
|
2010-06-13 14:17:26 +00:00
|
|
|
}
|
|
|
|
break;
|
2011-05-15 12:30:14 +00:00
|
|
|
case 2:
|
|
|
|
/* _fios_items changed */
|
|
|
|
this->vscroll->SetCount(_fios_items.Length());
|
|
|
|
this->selected = NULL;
|
|
|
|
_load_check_data.Clear();
|
|
|
|
break;
|
2010-06-13 14:17:26 +00:00
|
|
|
}
|
2010-06-03 11:05:20 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-06-13 14:17:02 +00:00
|
|
|
/** Load game/scenario */
|
2013-05-26 19:23:42 +00:00
|
|
|
static WindowDesc _load_dialog_desc(
|
2013-05-26 19:25:01 +00:00
|
|
|
WDP_CENTER, "load_game", 500, 294,
|
2010-06-03 11:05:20 +00:00
|
|
|
WC_SAVELOAD, WC_NONE,
|
2012-11-11 16:10:43 +00:00
|
|
|
0,
|
2010-06-03 11:05:20 +00:00
|
|
|
_nested_load_dialog_widgets, lengthof(_nested_load_dialog_widgets)
|
|
|
|
);
|
|
|
|
|
2010-06-13 14:17:02 +00:00
|
|
|
/** Load heightmap */
|
2013-05-26 19:23:42 +00:00
|
|
|
static WindowDesc _load_heightmap_dialog_desc(
|
2013-05-26 19:25:01 +00:00
|
|
|
WDP_CENTER, "load_heightmap", 257, 320,
|
2010-06-13 14:17:02 +00:00
|
|
|
WC_SAVELOAD, WC_NONE,
|
2012-11-11 16:10:43 +00:00
|
|
|
0,
|
2010-06-13 14:17:02 +00:00
|
|
|
_nested_load_heightmap_dialog_widgets, lengthof(_nested_load_heightmap_dialog_widgets)
|
|
|
|
);
|
|
|
|
|
|
|
|
/** Save game/scenario */
|
2013-05-26 19:23:42 +00:00
|
|
|
static WindowDesc _save_dialog_desc(
|
2013-05-26 19:25:01 +00:00
|
|
|
WDP_CENTER, "save_game", 500, 294,
|
2010-06-03 11:05:20 +00:00
|
|
|
WC_SAVELOAD, WC_NONE,
|
2012-11-11 16:10:43 +00:00
|
|
|
0,
|
2010-06-03 11:05:20 +00:00
|
|
|
_nested_save_dialog_widgets, lengthof(_nested_save_dialog_widgets)
|
|
|
|
);
|
|
|
|
|
2010-08-01 19:22:34 +00:00
|
|
|
/**
|
|
|
|
* These values are used to convert the file/operations mode into a corresponding file type.
|
2010-08-01 19:44:49 +00:00
|
|
|
* So each entry, as expressed by the related comment, is based on the enum
|
|
|
|
*/
|
2010-06-03 11:05:20 +00:00
|
|
|
static const FileType _file_modetotype[] = {
|
2011-05-28 13:55:59 +00:00
|
|
|
FT_SAVEGAME, // used for SLD_LOAD_GAME
|
|
|
|
FT_SCENARIO, // used for SLD_LOAD_SCENARIO
|
|
|
|
FT_SAVEGAME, // used for SLD_SAVE_GAME
|
|
|
|
FT_SCENARIO, // used for SLD_SAVE_SCENARIO
|
|
|
|
FT_HEIGHTMAP, // used for SLD_LOAD_HEIGHTMAP
|
|
|
|
FT_HEIGHTMAP, // used for SLD_SAVE_HEIGHTMAP
|
2010-06-03 11:05:20 +00:00
|
|
|
};
|
|
|
|
|
2011-05-27 21:20:07 +00:00
|
|
|
/**
|
|
|
|
* Launch save/load dialog in the given mode.
|
|
|
|
* @param mode Save/load mode.
|
|
|
|
*/
|
2010-06-03 11:05:20 +00:00
|
|
|
void ShowSaveLoadDialog(SaveLoadDialogMode mode)
|
|
|
|
{
|
|
|
|
DeleteWindowById(WC_SAVELOAD, 0);
|
|
|
|
|
2013-05-26 19:23:42 +00:00
|
|
|
WindowDesc *sld;
|
2010-06-03 11:05:20 +00:00
|
|
|
switch (mode) {
|
|
|
|
case SLD_SAVE_GAME:
|
|
|
|
case SLD_SAVE_SCENARIO:
|
2011-05-28 13:55:59 +00:00
|
|
|
case SLD_SAVE_HEIGHTMAP:
|
2010-06-03 11:05:20 +00:00
|
|
|
sld = &_save_dialog_desc; break;
|
2010-06-13 14:17:02 +00:00
|
|
|
case SLD_LOAD_HEIGHTMAP:
|
|
|
|
sld = &_load_heightmap_dialog_desc; break;
|
2010-06-03 11:05:20 +00:00
|
|
|
default:
|
|
|
|
sld = &_load_dialog_desc; break;
|
|
|
|
}
|
|
|
|
|
|
|
|
_saveload_mode = mode;
|
|
|
|
_file_to_saveload.filetype = _file_modetotype[mode];
|
|
|
|
|
|
|
|
new SaveLoadWindow(sld, mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetFiosType(const byte fiostype)
|
|
|
|
{
|
|
|
|
switch (fiostype) {
|
|
|
|
case FIOS_TYPE_FILE:
|
|
|
|
case FIOS_TYPE_SCENARIO:
|
|
|
|
_file_to_saveload.mode = SL_LOAD;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FIOS_TYPE_OLDFILE:
|
|
|
|
case FIOS_TYPE_OLD_SCENARIO:
|
|
|
|
_file_to_saveload.mode = SL_OLD_LOAD;
|
|
|
|
break;
|
|
|
|
|
|
|
|
#ifdef WITH_PNG
|
|
|
|
case FIOS_TYPE_PNG:
|
|
|
|
_file_to_saveload.mode = SL_PNG;
|
|
|
|
break;
|
|
|
|
#endif /* WITH_PNG */
|
|
|
|
|
|
|
|
case FIOS_TYPE_BMP:
|
|
|
|
_file_to_saveload.mode = SL_BMP;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
_file_to_saveload.mode = SL_INVALID;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|