Update to 1.10.0-beta1
This commit is contained in:
176
src/fios_gui.cpp
176
src/fios_gui.cpp
@@ -51,20 +51,19 @@ void LoadCheckData::Clear()
|
||||
this->checkable = false;
|
||||
this->error = INVALID_STRING_ID;
|
||||
free(this->error_data);
|
||||
this->error_data = NULL;
|
||||
this->error_data = nullptr;
|
||||
|
||||
this->map_size_x = this->map_size_y = 256; // Default for old savegames which do not store mapsize.
|
||||
this->current_date = 0;
|
||||
memset(&this->settings, 0, sizeof(this->settings));
|
||||
|
||||
const CompanyPropertiesMap::iterator end = this->companies.End();
|
||||
for (CompanyPropertiesMap::iterator it = this->companies.Begin(); it != end; it++) {
|
||||
delete it->second;
|
||||
for (auto &pair : this->companies) {
|
||||
delete pair.second;
|
||||
}
|
||||
companies.Clear();
|
||||
companies.clear();
|
||||
|
||||
GamelogFree(this->gamelog_action, this->gamelog_actions);
|
||||
this->gamelog_action = NULL;
|
||||
this->gamelog_action = nullptr;
|
||||
this->gamelog_actions = 0;
|
||||
|
||||
ClearGRFConfigList(&this->grfconfig);
|
||||
@@ -245,8 +244,8 @@ static const TextColour _fios_colours[] = {
|
||||
*/
|
||||
static void SortSaveGameList(FileList &file_list)
|
||||
{
|
||||
uint sort_start = 0;
|
||||
uint sort_end = 0;
|
||||
size_t sort_start = 0;
|
||||
size_t sort_end = 0;
|
||||
|
||||
/* Directories are always above the files (FIOS_TYPE_DIR)
|
||||
* Drives (A:\ (windows only) are always under the files (FIOS_TYPE_DRIVE)
|
||||
@@ -261,8 +260,7 @@ static void SortSaveGameList(FileList &file_list)
|
||||
}
|
||||
}
|
||||
|
||||
uint s_amount = file_list.Length() - sort_start - sort_end;
|
||||
QSortT(file_list.Get(sort_start), s_amount, CompareFiosItems);
|
||||
std::sort(file_list.files.begin() + sort_start, file_list.files.end() - sort_end);
|
||||
}
|
||||
|
||||
struct SaveLoadWindow : public Window {
|
||||
@@ -274,12 +272,12 @@ private:
|
||||
SaveLoadOperation fop; ///< File operation to perform.
|
||||
FileList fios_items; ///< Save game list.
|
||||
FiosItem o_dir;
|
||||
const FiosItem *selected; ///< Selected game in #fios_items, or \c NULL.
|
||||
const FiosItem *selected; ///< Selected game in #fios_items, or \c nullptr.
|
||||
Scrollbar *vscroll;
|
||||
|
||||
StringFilter string_filter; ///< Filter for available games.
|
||||
QueryString filter_editbox; ///< Filter editbox;
|
||||
SmallVector<bool, 32> fios_items_shown; ///< Map of the filtered out fios items
|
||||
std::vector<bool> fios_items_shown; ///< Map of the filtered out fios items
|
||||
|
||||
static void SaveGameConfirmationCallback(Window *w, bool confirmed)
|
||||
{
|
||||
@@ -407,7 +405,7 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
virtual void DrawWidget(const Rect &r, int widget) const
|
||||
void DrawWidget(const Rect &r, int widget) const override
|
||||
{
|
||||
switch (widget) {
|
||||
case WID_SL_SORT_BYNAME:
|
||||
@@ -418,7 +416,7 @@ public:
|
||||
break;
|
||||
|
||||
case WID_SL_BACKGROUND: {
|
||||
static const char *path = NULL;
|
||||
static const char *path = nullptr;
|
||||
static StringID str = STR_ERROR_UNABLE_TO_READ_DRIVE;
|
||||
static uint64 tot = 0;
|
||||
|
||||
@@ -462,7 +460,7 @@ public:
|
||||
r.right - WD_FRAMERECT_RIGHT, r.top + FONT_HEIGHT_NORMAL * 2 + WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM, PC_GREY);
|
||||
DrawString(r.left, r.right, r.top + FONT_HEIGHT_NORMAL / 2 + WD_FRAMERECT_TOP, STR_SAVELOAD_DETAIL_CAPTION, TC_FROMSTRING, SA_HOR_CENTER);
|
||||
|
||||
if (this->selected == NULL) break;
|
||||
if (this->selected == nullptr) 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;
|
||||
@@ -518,7 +516,7 @@ public:
|
||||
if (y > y_max) break;
|
||||
|
||||
/* NewGrf compatibility */
|
||||
SetDParam(0, _load_check_data.grfconfig == NULL ? STR_NEWGRF_LIST_NONE :
|
||||
SetDParam(0, _load_check_data.grfconfig == nullptr ? 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;
|
||||
@@ -531,11 +529,10 @@ public:
|
||||
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) {
|
||||
for (auto &pair : _load_check_data.companies) {
|
||||
SetDParam(0, pair.first + 1);
|
||||
const CompanyProperties &c = *pair.second;
|
||||
if (c.name != nullptr) {
|
||||
SetDParam(1, STR_JUST_RAW_STRING);
|
||||
SetDParamStr(2, c.name);
|
||||
} else {
|
||||
@@ -553,7 +550,7 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
|
||||
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
|
||||
{
|
||||
switch (widget) {
|
||||
case WID_SL_BACKGROUND:
|
||||
@@ -575,7 +572,7 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
virtual void OnPaint()
|
||||
void OnPaint() override
|
||||
{
|
||||
if (_savegame_sort_dirty) {
|
||||
_savegame_sort_dirty = false;
|
||||
@@ -586,7 +583,7 @@ public:
|
||||
this->DrawWidgets();
|
||||
}
|
||||
|
||||
virtual void OnClick(Point pt, int widget, int click_count)
|
||||
void OnClick(Point pt, int widget, int click_count) override
|
||||
{
|
||||
switch (widget) {
|
||||
case WID_SL_SORT_BYNAME: // Sort save names by name
|
||||
@@ -608,24 +605,24 @@ public:
|
||||
this->InvalidateData(SLIWD_RESCAN_FILES);
|
||||
break;
|
||||
|
||||
case WID_SL_LOAD_BUTTON:
|
||||
if (this->selected != NULL && !_load_check_data.HasErrors()) {
|
||||
const char *name = FiosBrowseTo(this->selected);
|
||||
_file_to_saveload.SetMode(this->selected->type);
|
||||
_file_to_saveload.SetName(name);
|
||||
_file_to_saveload.SetTitle(this->selected->title);
|
||||
case WID_SL_LOAD_BUTTON: {
|
||||
if (this->selected == nullptr || _load_check_data.HasErrors()) break;
|
||||
|
||||
if (this->abstract_filetype == FT_HEIGHTMAP) {
|
||||
delete this;
|
||||
ShowHeightmapLoad();
|
||||
const char *name = FiosBrowseTo(this->selected);
|
||||
_file_to_saveload.SetMode(this->selected->type);
|
||||
_file_to_saveload.SetName(name);
|
||||
_file_to_saveload.SetTitle(this->selected->title);
|
||||
|
||||
} else if (!_load_check_data.HasNewGrfs() || _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;
|
||||
}
|
||||
if (this->abstract_filetype == FT_HEIGHTMAP) {
|
||||
delete this;
|
||||
ShowHeightmapLoad();
|
||||
} else if (!_load_check_data.HasNewGrfs() || _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;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case WID_SL_NEWGRF_INFO:
|
||||
if (_load_check_data.HasNewGrfs()) {
|
||||
@@ -637,9 +634,7 @@ public:
|
||||
if (!_network_available) {
|
||||
ShowErrorMessage(STR_NETWORK_ERROR_NOTAVAILABLE, INVALID_STRING_ID, WL_ERROR);
|
||||
} else if (_load_check_data.HasNewGrfs()) {
|
||||
#if defined(ENABLE_NETWORK)
|
||||
ShowMissingContentWindow(_load_check_data.grfconfig);
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -656,43 +651,44 @@ public:
|
||||
const FiosItem *file = this->fios_items.Get(y);
|
||||
|
||||
const char *name = FiosBrowseTo(file);
|
||||
if (name != NULL) {
|
||||
if (click_count == 1) {
|
||||
if (this->selected != file) {
|
||||
this->selected = file;
|
||||
_load_check_data.Clear();
|
||||
|
||||
if (GetDetailedFileType(file->type) == DFT_GAME_FILE) {
|
||||
/* Other detailed file types cannot be checked before. */
|
||||
SaveOrLoad(name, SLO_CHECK, DFT_GAME_FILE, NO_DIRECTORY, false);
|
||||
}
|
||||
|
||||
this->InvalidateData(SLIWD_SELECTION_CHANGES);
|
||||
}
|
||||
if (this->fop == SLO_SAVE) {
|
||||
/* Copy clicked name to editbox */
|
||||
this->filename_editbox.text.Assign(file->title);
|
||||
this->SetWidgetDirty(WID_SL_SAVE_OSK_TITLE);
|
||||
}
|
||||
} else if (!_load_check_data.HasErrors()) {
|
||||
this->selected = file;
|
||||
if (this->fop == SLO_LOAD) {
|
||||
if (this->abstract_filetype == FT_SAVEGAME || this->abstract_filetype == FT_SCENARIO) {
|
||||
this->OnClick(pt, WID_SL_LOAD_BUTTON, 1);
|
||||
} else {
|
||||
assert(this->abstract_filetype == FT_HEIGHTMAP);
|
||||
_file_to_saveload.SetMode(file->type);
|
||||
_file_to_saveload.SetName(name);
|
||||
_file_to_saveload.SetTitle(file->title);
|
||||
|
||||
delete this;
|
||||
ShowHeightmapLoad();
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (name == nullptr) {
|
||||
/* Changed directory, need refresh. */
|
||||
this->InvalidateData(SLIWD_RESCAN_FILES);
|
||||
break;
|
||||
}
|
||||
|
||||
if (click_count == 1) {
|
||||
if (this->selected != file) {
|
||||
this->selected = file;
|
||||
_load_check_data.Clear();
|
||||
|
||||
if (GetDetailedFileType(file->type) == DFT_GAME_FILE) {
|
||||
/* Other detailed file types cannot be checked before. */
|
||||
SaveOrLoad(name, SLO_CHECK, DFT_GAME_FILE, NO_DIRECTORY, false);
|
||||
}
|
||||
|
||||
this->InvalidateData(SLIWD_SELECTION_CHANGES);
|
||||
}
|
||||
if (this->fop == SLO_SAVE) {
|
||||
/* Copy clicked name to editbox */
|
||||
this->filename_editbox.text.Assign(file->title);
|
||||
this->SetWidgetDirty(WID_SL_SAVE_OSK_TITLE);
|
||||
}
|
||||
} else if (!_load_check_data.HasErrors()) {
|
||||
this->selected = file;
|
||||
if (this->fop == SLO_LOAD) {
|
||||
if (this->abstract_filetype == FT_SAVEGAME || this->abstract_filetype == FT_SCENARIO) {
|
||||
this->OnClick(pt, WID_SL_LOAD_BUTTON, 1);
|
||||
} else {
|
||||
assert(this->abstract_filetype == FT_HEIGHTMAP);
|
||||
_file_to_saveload.SetMode(file->type);
|
||||
_file_to_saveload.SetName(name);
|
||||
_file_to_saveload.SetTitle(file->title);
|
||||
|
||||
delete this;
|
||||
ShowHeightmapLoad();
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -701,14 +697,12 @@ public:
|
||||
if (!_network_available) {
|
||||
ShowErrorMessage(STR_NETWORK_ERROR_NOTAVAILABLE, INVALID_STRING_ID, WL_ERROR);
|
||||
} else {
|
||||
#if defined(ENABLE_NETWORK)
|
||||
assert(this->fop == SLO_LOAD);
|
||||
switch (this->abstract_filetype) {
|
||||
default: NOT_REACHED();
|
||||
case FT_SCENARIO: ShowNetworkContentListWindow(NULL, CONTENT_TYPE_SCENARIO); break;
|
||||
case FT_HEIGHTMAP: ShowNetworkContentListWindow(NULL, CONTENT_TYPE_HEIGHTMAP); break;
|
||||
case FT_SCENARIO: ShowNetworkContentListWindow(nullptr, CONTENT_TYPE_SCENARIO); break;
|
||||
case FT_HEIGHTMAP: ShowNetworkContentListWindow(nullptr, CONTENT_TYPE_HEIGHTMAP); break;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -722,7 +716,7 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
virtual EventState OnKeyPress(WChar key, uint16 keycode)
|
||||
EventState OnKeyPress(WChar key, uint16 keycode) override
|
||||
{
|
||||
if (keycode == WKC_ESC) {
|
||||
delete this;
|
||||
@@ -732,7 +726,7 @@ public:
|
||||
return ES_NOT_HANDLED;
|
||||
}
|
||||
|
||||
virtual void OnTimeout()
|
||||
void OnTimeout() override
|
||||
{
|
||||
/* Widgets WID_SL_DELETE_SELECTION and WID_SL_SAVE_GAME only exist when saving to a file. */
|
||||
if (this->fop != SLO_SAVE) return;
|
||||
@@ -767,7 +761,7 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
virtual void OnResize()
|
||||
void OnResize() override
|
||||
{
|
||||
this->vscroll->SetCapacityFromWidget(this, WID_SL_DRIVES_DIRECTORIES_LIST);
|
||||
}
|
||||
@@ -777,19 +771,19 @@ public:
|
||||
* @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)
|
||||
void OnInvalidateData(int data = 0, bool gui_scope = true) override
|
||||
{
|
||||
switch (data) {
|
||||
case SLIWD_RESCAN_FILES:
|
||||
/* Rescan files */
|
||||
this->selected = NULL;
|
||||
this->selected = nullptr;
|
||||
_load_check_data.Clear();
|
||||
if (!gui_scope) break;
|
||||
|
||||
_fios_path_changed = true;
|
||||
this->fios_items.BuildFileList(this->abstract_filetype, this->fop);
|
||||
this->vscroll->SetCount(this->fios_items.Length());
|
||||
this->selected = NULL;
|
||||
this->vscroll->SetCount((uint)this->fios_items.Length());
|
||||
this->selected = nullptr;
|
||||
_load_check_data.Clear();
|
||||
|
||||
/* We reset the files filtered */
|
||||
@@ -805,12 +799,12 @@ public:
|
||||
|
||||
switch (this->abstract_filetype) {
|
||||
case FT_HEIGHTMAP:
|
||||
this->SetWidgetDisabledState(WID_SL_LOAD_BUTTON, this->selected == NULL || _load_check_data.HasErrors());
|
||||
this->SetWidgetDisabledState(WID_SL_LOAD_BUTTON, this->selected == nullptr || _load_check_data.HasErrors());
|
||||
break;
|
||||
|
||||
case FT_SAVEGAME:
|
||||
case FT_SCENARIO: {
|
||||
bool disabled = this->selected == NULL || _load_check_data.HasErrors();
|
||||
bool disabled = this->selected == nullptr || _load_check_data.HasErrors();
|
||||
if (!_settings_client.gui.UserIsAllowedToChangeNewGRFs()) {
|
||||
disabled |= _load_check_data.HasNewGrfs() && _load_check_data.grf_compatibility == GLC_NOT_FOUND;
|
||||
}
|
||||
@@ -828,7 +822,7 @@ public:
|
||||
|
||||
case SLIWD_FILTER_CHANGES:
|
||||
/* Filter changes */
|
||||
this->fios_items_shown.Resize(this->fios_items.Length());
|
||||
this->fios_items_shown.resize(this->fios_items.Length());
|
||||
uint items_shown_count = 0; ///< The number of items shown in the list
|
||||
/* We pass through every fios item */
|
||||
for (uint i = 0; i < this->fios_items.Length(); i++) {
|
||||
@@ -845,7 +839,7 @@ public:
|
||||
|
||||
if (&(this->fios_items[i]) == this->selected && this->fios_items_shown[i] == false) {
|
||||
/* The selected element has been filtered out */
|
||||
this->selected = NULL;
|
||||
this->selected = nullptr;
|
||||
this->OnInvalidateData(SLIWD_SELECTION_CHANGES);
|
||||
}
|
||||
}
|
||||
@@ -855,7 +849,7 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
virtual void OnEditboxChanged(int wid)
|
||||
void OnEditboxChanged(int wid) override
|
||||
{
|
||||
if (wid == WID_SL_FILTER) {
|
||||
this->string_filter.SetFilterTerm(this->filter_editbox.text.buf);
|
||||
|
||||
Reference in New Issue
Block a user