16 #define GETTEXT_DOMAIN "wesnoth-lib"
48 #define ERR_GAMELOADDLG LOG_STREAM(err, log_gameloaddlg)
49 #define WRN_GAMELOADDLG LOG_STREAM(warn, log_gameloaddlg)
50 #define LOG_GAMELOADDLG LOG_STREAM(info, log_gameloaddlg)
51 #define DBG_GAMELOADDLG LOG_STREAM(debug, log_gameloaddlg)
61 bool found_files =
false;
65 auto index = std::make_shared<savegame::save_index_class>(dir.path);
66 found_files = !
index->get_saves_list().empty();
82 , save_index_manager_(
data.manager)
83 , change_difficulty_(register_bool(
"change_difficulty", true,
data.select_difficulty))
84 , show_replay_(register_bool(
"show_replay", true,
data.show_replay))
85 , cancel_orders_(register_bool(
"cancel_orders", true,
data.cancel_orders))
86 , summary_(
data.summary)
88 , cache_config_(cache_config)
98 text_box* filter = find_widget<text_box>(
"txtFilter",
false,
true);
102 listbox& list = find_widget<listbox>(
"savegame_list");
120 menu_button& dir_list = find_widget<menu_button>(
"dirList");
133 if(other_dirs.empty()) {
138 std::vector<config> options;
141 options.emplace_back(
"label",
_(
"game_version^Current Version"),
"path",
"");
143 for(
const auto& known_dir : other_dirs) {
144 options.emplace_back(
146 "path", known_dir.path
155 listbox& list = find_widget<listbox>(
"savegame_list");
165 std::string name =
game.name();
167 item[
"label"] = name;
168 data.emplace(
"filename", item);
170 item[
"label"] =
game.format_time_summary();
171 data.emplace(
"date", item);
184 find_widget<minimap>(
"minimap")
185 .set_map_data(
summary_[
"map_data"]);
187 find_widget<label>(
"lblScenario")
190 listbox& leader_list = find_widget<listbox>(
"leader_list");
204 std::string leader_image = leader[
"leader_image"].str();
211 leader_image = indep_path.value() + leader[
"leader_image_tc_modifier"].str();
215 if(leader_image.empty()) {
216 leader_image =
"units/unknown-unit.png" + leader[
"leader_image_tc_modifier"].str();
219 leader_image += sprite_scale_mod +
"~FL(horiz)";
222 item[
"label"] = leader_image;
223 data.emplace(
"imgLeader", item);
225 item[
"label"] = leader[
"leader_name"];
226 data.emplace(
"leader_name", item);
228 item[
"label"] = leader[
"gold"];
229 data.emplace(
"leader_gold", item);
232 item[
"label"] =
VGETTEXT(
"$active active, $reserve reserve", {{
"active", leader[
"units"]}, {
"reserve", leader[
"recall_units"]}});
233 data.emplace(
"leader_troops", item);
244 std::stringstream str;
245 str <<
game.format_time_local() <<
"\n";
249 find_widget<styled_widget>(
"slblSummary").set_label(str.str());
261 replay_toggle.
set_active(!is_replay && !is_scenario_start);
264 cancel_orders_toggle.
set_active(!is_replay && !is_scenario_start);
267 change_difficulty_toggle.
set_active(!is_replay && is_scenario_start);
274 bool successfully_displayed_a_game =
false;
277 const int selected_row = find_widget<listbox>(
"savegame_list").get_selected_row();
278 if(selected_row < 0) {
279 find_widget<button>(
"delete").set_active(
false);
283 successfully_displayed_a_game =
true;
287 const std::string preamble =
_(
"The selected file is corrupt: ");
288 const std::string
message =
e.message.empty() ?
"(no details)" :
e.message;
292 if(!successfully_displayed_a_game) {
293 find_widget<minimap>(
"minimap").set_map_data(
"");
294 find_widget<label>(
"lblScenario")
296 find_widget<styled_widget>(
"slblSummary")
299 listbox& leader_list = find_widget<listbox>(
"leader_list");
312 find_widget<button>(
"ok").set_active(successfully_displayed_a_game);
325 listbox& list = find_widget<listbox>(
"savegame_list");
327 const std::vector<std::string> words =
utils::split(text,
' ');
333 boost::dynamic_bitset<> show_items;
339 for(
const auto & word : words)
348 show_items[
i] = found;
357 if(cfg_summary[
"corrupt"].to_bool()) {
366 const std::string&
campaign_type = cfg_summary[
"campaign_type"];
367 const std::string campaign_id = cfg_summary[
"campaign"];
370 if(campaign_type_enum) {
371 switch(*campaign_type_enum) {
372 case campaign_type::type::scenario: {
373 const config* campaign =
nullptr;
374 if(!campaign_id.empty()) {
381 if(campaign !=
nullptr) {
382 symbols[
"campaign_name"] = (*campaign)[
"name"];
385 symbols[
"campaign_name"] =
"(" + campaign_id +
")";
388 str <<
VGETTEXT(
"Campaign: $campaign_name", symbols);
392 str <<
'\n' <<
"(" << campaign_id <<
")";
396 case campaign_type::type::multiplayer:
397 str <<
_(
"Multiplayer");
399 case campaign_type::type::tutorial:
400 str <<
_(
"Tutorial");
402 case campaign_type::type::test:
403 str <<
_(
"Test scenario");
414 }
else if(!cfg_summary[
"turn"].empty()) {
415 str <<
_(
"Turn") <<
" " << cfg_summary[
"turn"];
417 str <<
_(
"Scenario start");
420 if(campaign_type_enum) {
421 switch (*campaign_type_enum) {
422 case campaign_type::type::scenario:
423 case campaign_type::type::multiplayer: {
424 const config* campaign =
nullptr;
425 if (!campaign_id.empty()) {
435 if (campaign !=
nullptr) {
436 str <<
"\n" <<
_(
"Difficulty: ");
439 std::ostringstream ss;
440 ss << difficulty[
"label"] <<
" (" << difficulty[
"description"] <<
")";
451 case campaign_type::type::tutorial:
452 case campaign_type::type::test:
458 if(!cfg_summary[
"version"].empty()) {
459 str <<
"\n" <<
_(
"Version: ") << cfg_summary[
"version"];
462 const std::vector<std::string>& active_mods =
utils::split(cfg_summary[
"active_mods"]);
463 if(!active_mods.empty()) {
464 str <<
"\n" <<
_(
"Modifications: ");
465 for(
const auto& mod_id : active_mods) {
466 std::string mod_name;
471 mod_name =
"(" + mod_id +
")";
485 listbox& list = find_widget<listbox>(
"savegame_list");
492 if(!gui2::dialogs::game_delete::execute()) {
524 if(key == SDLK_DELETE) {
531 menu_button& dir_list = find_widget<menu_button>(
"dirList");
541 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 apply_filter_text(const std::string &text, bool force)
Implementation detail of filter_text_changed and handle_dir_select.
std::vector< std::string > last_words_
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.
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.
void filter_text_changed(const std::string &text)
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.
void set_row_shown(const unsigned row, const bool shown)
Makes a row visible or invisible.
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.
bool select_row(const unsigned row, const bool select=true)
Selects a row.
void register_sorting_option(const int col, const Func &f)
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.
unsigned get_item_count() const
Returns the number of items in the listbox.
virtual unsigned get_state() const override
See styled_widget::get_state.
void set_text_changed_callback(std::function< void(text_box_base *textbox, const std::string text)> cb)
Set the text_changed callback.
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)
bool ci_search(const std::string &s1, const std::string &s2)
std::size_t index(const std::string &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.