From c46a2171f22f17bbf10d2c0412787930c70645d6 Mon Sep 17 00:00:00 2001 From: Steve Cotton Date: Sat, 13 Feb 2021 11:41:07 +0100 Subject: [PATCH] Improve the Load dialog's UX when there are no save files or corrupted files Re-add the popup that appears when "Load" is pressed on the title screen if there are no files, but now check for files from previous versions too. Improve handling of switching from a version with files to a version without files, disabling buttons on the load dialog when there are no files in the current directory. Versions with no files will still be shown in the drop-down. This adds a todo about the error path at the start of evaluate_summary_string, this path is reached by creating empty files in the save dir. The dialog's state is reasonable, so it seemed a low priority and I don't want to introduce new bugs by refactoring this path now. Deleting all files now doesn't automatically close the dialog. --- changelog.md | 2 + src/gui/dialogs/game_load.cpp | 83 +++++++++++++++++++++-------------- src/gui/dialogs/game_load.hpp | 8 ++-- 3 files changed, 56 insertions(+), 37 deletions(-) diff --git a/changelog.md b/changelog.md index 5f8f6e1d9616..420d65b9bb99 100644 --- a/changelog.md +++ b/changelog.md @@ -11,6 +11,8 @@ ### Translations ### Units ### User interface + * Improved the Load dialog when there are no saved games for the current version, and also when there are corrupted files. + * Re-added the pop-up when there are no saved games at all (issue #5517). ### WML Engine * Standard Location Filters now support gives_income=yes|no to make it simpler to match villages regardless of owner ### Miscellaneous and Bug Fixes diff --git a/src/gui/dialogs/game_load.cpp b/src/gui/dialogs/game_load.cpp index 76d0e2682fe2..36d3e62b9111 100644 --- a/src/gui/dialogs/game_load.cpp +++ b/src/gui/dialogs/game_load.cpp @@ -58,6 +58,27 @@ namespace gui2::dialogs REGISTER_DIALOG(game_load) +bool game_load::execute(const game_config_view& cache_config, savegame::load_game_metadata& data) +{ + if(savegame::save_index_class::default_saves_dir()->get_saves_list().empty()) { + bool found_files = false; + for(const auto& dir : filesystem::find_other_version_saves_dirs()) { + if(!found_files) { + // this needs to be a shared_ptr because get_saves_list() uses shared_from_this + auto index = std::make_shared(dir.path); + found_files = !index->get_saves_list().empty(); + } + } + + if(!found_files) { + gui2::show_transient_message(_("No Saved Games"), _("There are no saved games to load.")); + return false; + } + } + + return game_load(cache_config, data).show(); +} + game_load::game_load(const game_config_view& cache_config, savegame::load_game_metadata& data) : filename_(data.filename) , save_index_manager_(data.manager) @@ -122,12 +143,10 @@ void game_load::set_save_dir_list(menu_button& dir_list) options.emplace_back("label", _("game_version^Current Version"), "path", ""); for(const auto& known_dir : other_dirs) { - if(!known_dir.path.empty()) { - options.emplace_back( - "label", VGETTEXT("game_version^Wesnoth $version", utils::string_map{{"version", known_dir.version}}), - "path", known_dir.path - ); - } + options.emplace_back( + "label", VGETTEXT("game_version^Wesnoth $version", utils::string_map{{"version", known_dir.version}}), + "path", known_dir.path + ); } dir_list.set_values(options); @@ -159,16 +178,8 @@ void game_load::populate_game_list() find_widget