16 #define GETTEXT_DOMAIN "wesnoth-lib"
49 #define ERR_GAMELOADDLG LOG_STREAM(err, log_gameloaddlg)
50 #define WRN_GAMELOADDLG LOG_STREAM(warn, log_gameloaddlg)
51 #define LOG_GAMELOADDLG LOG_STREAM(info, log_gameloaddlg)
52 #define DBG_GAMELOADDLG LOG_STREAM(debug, log_gameloaddlg)
62 bool found_files =
false;
66 auto index = std::make_shared<savegame::save_index_class>(dir.path);
67 found_files = !
index->get_saves_list().empty();
83 , save_index_manager_(
data.manager)
84 , change_difficulty_(register_bool(
"change_difficulty", true,
data.select_difficulty))
85 , show_replay_(register_bool(
"show_replay", true,
data.show_replay))
86 , cancel_orders_(register_bool(
"cancel_orders", true,
data.cancel_orders))
87 , summary_(
data.summary)
89 , cache_config_(cache_config)
98 text_box*
filter = find_widget<text_box>(
"txtFilter",
false,
true);
102 listbox& list = find_widget<listbox>(
"savegame_list");
110 [
this](
const std::size_t
i) {
return games_[
i].name(); },
111 [
this](
const std::size_t
i) {
return games_[
i].modified(); }
122 menu_button& dir_list = find_widget<menu_button>(
"dirList");
135 if(other_dirs.empty()) {
140 std::vector<config> options;
143 options.emplace_back(
"label",
_(
"game_version^Current Version"),
"path",
"");
145 for(
const auto& known_dir : other_dirs) {
146 options.emplace_back(
148 "path", known_dir.path
157 listbox& list = find_widget<listbox>(
"savegame_list");
167 std::string name =
game.name();
169 item[
"label"] = name;
170 data.emplace(
"filename", item);
172 item[
"label"] =
game.format_time_summary();
173 data.emplace(
"date", item);
186 find_widget<minimap>(
"minimap")
187 .set_map_data(
summary_[
"map_data"]);
189 find_widget<label>(
"lblScenario")
192 listbox& leader_list = find_widget<listbox>(
"leader_list");
206 std::string leader_image = leader[
"leader_image"].str();
213 leader_image = indep_path.value() + leader[
"leader_image_tc_modifier"].str();
217 if(leader_image.empty()) {
218 leader_image =
"units/unknown-unit.png" + leader[
"leader_image_tc_modifier"].str();
221 leader_image += sprite_scale_mod +
"~FL(horiz)";
224 item[
"label"] = leader_image;
225 data.emplace(
"imgLeader", item);
227 item[
"label"] = leader[
"leader_name"];
228 data.emplace(
"leader_name", item);
230 item[
"label"] = leader[
"gold"];
231 data.emplace(
"leader_gold", item);
234 item[
"label"] =
VGETTEXT(
"$active active, $reserve reserve", {{
"active", leader[
"units"]}, {
"reserve", leader[
"recall_units"]}});
235 data.emplace(
"leader_troops", item);
246 std::stringstream str;
247 str <<
game.format_time_local() <<
"\n";
251 find_widget<styled_widget>(
"slblSummary").set_label(str.str());
263 replay_toggle.
set_active(!is_replay && !is_scenario_start);
266 cancel_orders_toggle.
set_active(!is_replay && !is_scenario_start);
269 change_difficulty_toggle.
set_active(!is_replay && is_scenario_start);
276 bool successfully_displayed_a_game =
false;
279 const int selected_row = find_widget<listbox>(
"savegame_list").get_selected_row();
280 if(selected_row < 0) {
281 find_widget<button>(
"delete").set_active(
false);
285 successfully_displayed_a_game =
true;
289 const std::string preamble =
_(
"The selected file is corrupt: ");
290 const std::string
message =
e.message.empty() ?
"(no details)" :
e.message;
294 if(!successfully_displayed_a_game) {
295 find_widget<minimap>(
"minimap").set_map_data(
"");
296 find_widget<label>(
"lblScenario")
298 find_widget<styled_widget>(
"slblSummary")
301 listbox& leader_list = find_widget<listbox>(
"leader_list");
314 find_widget<button>(
"ok").set_active(successfully_displayed_a_game);
322 find_widget<listbox>(
"savegame_list").filter_rows_by(
328 if(cfg_summary[
"corrupt"].to_bool()) {
337 const std::string&
campaign_type = cfg_summary[
"campaign_type"];
338 const std::string campaign_id = cfg_summary[
"campaign"];
341 if(campaign_type_enum) {
342 switch(*campaign_type_enum) {
343 case campaign_type::type::scenario: {
344 const config* campaign =
nullptr;
345 if(!campaign_id.empty()) {
352 if(campaign !=
nullptr) {
353 symbols[
"campaign_name"] = (*campaign)[
"name"];
356 symbols[
"campaign_name"] =
"(" + campaign_id +
")";
359 str <<
VGETTEXT(
"Campaign: $campaign_name", symbols);
363 str <<
'\n' <<
"(" << campaign_id <<
")";
367 case campaign_type::type::multiplayer:
368 str <<
_(
"Multiplayer");
370 case campaign_type::type::tutorial:
371 str <<
_(
"Tutorial");
373 case campaign_type::type::test:
374 str <<
_(
"Test scenario");
385 }
else if(!cfg_summary[
"turn"].empty()) {
386 str <<
_(
"Turn") <<
" " << cfg_summary[
"turn"];
388 str <<
_(
"Scenario start");
391 if(campaign_type_enum) {
392 switch (*campaign_type_enum) {
393 case campaign_type::type::scenario:
394 case campaign_type::type::multiplayer: {
395 const config* campaign =
nullptr;
396 if (!campaign_id.empty()) {
406 if (campaign !=
nullptr) {
407 str <<
"\n" <<
_(
"Difficulty: ");
410 std::ostringstream ss;
411 ss << difficulty[
"label"] <<
" (" << difficulty[
"description"] <<
")";
422 case campaign_type::type::tutorial:
423 case campaign_type::type::test:
429 if(!cfg_summary[
"version"].empty()) {
430 str <<
"\n" <<
_(
"Version: ") << cfg_summary[
"version"];
433 const std::vector<std::string>& active_mods =
utils::split(cfg_summary[
"active_mods"]);
434 if(!active_mods.empty()) {
435 str <<
"\n" <<
_(
"Modifications: ");
436 for(
const auto& mod_id : active_mods) {
437 std::string mod_name;
442 mod_name =
"(" + mod_id +
")";
456 listbox& list = find_widget<listbox>(
"savegame_list");
463 if(!gui2::dialogs::game_delete::execute()) {
495 if(key == SDLK_DELETE) {
502 menu_button& dir_list = find_widget<menu_button>(
"dirList");
512 if(
auto*
filter = find_widget<text_box>(
"txtFilter",
false,
true)) {
string_enums::enum_base< campaign_type_defines > campaign_type
A config object defines a single node in a WML file, with access to child nodes.
config & find_mandatory_child(config_key_type key, const std::string &name, const std::string &value)
child_itors child_range(config_key_type key)
A class grating read only view to a vector of config objects, viewed as one config with all children ...
optional_const_config find_child(config_key_type key, const std::string &name, const std::string &value) const
const config & find_mandatory_child(config_key_type key, const std::string &name, const std::string &value) const
void browse_button_callback()
void display_savegame_internal(const savegame::save_info &game)
Part of display_savegame that might throw a config::error if the savegame data is corrupt.
void apply_filter_text(const std::string &text)
Hides saves not matching the given filter.
field_bool * show_replay_
virtual void pre_show() override
Actions to be taken before showing the window.
game_load(const game_config_view &cache_config, savegame::load_game_metadata &data)
void key_press_callback(const SDL_Keycode key)
void evaluate_summary_string(std::stringstream &str, const config &cfg_summary)
void set_save_dir_list(menu_button &dir_list)
void delete_button_callback()
field_bool * cancel_orders_
const game_config_view & cache_config_
std::shared_ptr< savegame::save_index_class > & save_index_manager_
std::vector< savegame::save_info > games_
void populate_game_list()
Update (both internally and visually) the list of games.
field_bool * change_difficulty_
Main class to show messages to the user.
Abstract base class for all modal dialogs.
bool show(const unsigned auto_close_time=0)
Shows the window.
styled_widget * get_widget()
void set_active(const bool active)
Activates all children.
grid & add_row(const widget_item &item, const int index=-1)
When an item in the list is selected by the user we need to update the state.
void set_sorters(Args &&... functors)
Registers sorting controls using magic index IDs.
bool select_row(const unsigned row, const bool select=true)
Selects a row.
void remove_row(const unsigned row, unsigned count=1)
Removes a row in the listbox.
void clear()
Removes all the rows in the listbox, clearing it.
int get_selected_row() const
Returns the first selected row.
virtual unsigned get_state() const override
See styled_widget::get_state.
A widget that allows the user to input text in single line.
void set_enter_disabled(const bool enter_disabled)
Disable the enter key.
void keyboard_capture(widget *widget)
void add_to_keyboard_chain(widget *widget)
Adds the widget to the keyboard chain.
static bool is_replay_save(const config &cfg)
static std::shared_ptr< save_index_class > default_saves_dir()
Returns an instance for managing saves in filesystem::get_saves_dir()
Filename and modification date for a file list.
Implements some helper classes to ease adding fields to a dialog and hide the synchronization needed.
Declarations for File-IO.
static lg::log_domain log_gameloaddlg
static std::string _(const char *str)
symbol_table string_table
bool open_object([[maybe_unused]] const std::string &path_or_url)
utils::optional< std::string > get_independent_binary_file_path(const std::string &type, const std::string &filename)
Returns an asset path to filename for binary path-independent use in saved games.
std::vector< other_version_dir > find_other_version_saves_dirs()
Searches for directories containing saves created by other versions of Wesnoth.
const std::string unicode_bullet
REGISTER_DIALOG(editor_edit_unit)
void connect_signal_pre_key_press(dispatcher &dispatcher, const signal_keyboard &signal)
Connects the signal for 'snooping' on the keypress.
void connect_signal_notify_modified(dispatcher &dispatcher, const signal_notification &signal)
Connects a signal handler for getting a notification upon modification.
void connect_signal_mouse_left_click(dispatcher &dispatcher, const signal &signal)
Connects a signal handler for a left mouse button click.
std::map< std::string, widget_item > widget_data
std::map< std::string, t_string > widget_item
void show_transient_message(const std::string &title, const std::string &message, const std::string &image, const bool message_use_markup, const bool title_use_markup)
Shows a transient message to the user.
bool exists(const image::locator &i_locator)
Returns true if the given image actually exists, without loading it.
std::string span_color(const color_t &color, Args &&... data)
auto make_ci_matcher(std::string_view filter_text)
Returns a function which performs locale-aware case-insensitive search.
std::size_t index(std::string_view str, const std::size_t index)
Codepoint index corresponding to the nth character in a UTF-8 string.
void ellipsis_truncate(std::string &str, const std::size_t size)
Truncates a string to a given utf-8 character count and then appends an ellipsis.
std::map< std::string, t_string > string_map
std::vector< std::string > split(const config_attribute_value &val)
Desktop environment interaction functions.
std::string filename
Filename.
The base template for associating string values with enum values.
static constexpr utils::optional< enum_type > get_enum(const std::string_view value)
Converts a string into its enum equivalent.