16 #define GETTEXT_DOMAIN "wesnoth-lib"
46 #define ERR_GAMELOADDLG LOG_STREAM(err, log_gameloaddlg)
47 #define WRN_GAMELOADDLG LOG_STREAM(warn, log_gameloaddlg)
48 #define LOG_GAMELOADDLG LOG_STREAM(info, log_gameloaddlg)
49 #define DBG_GAMELOADDLG LOG_STREAM(debug, log_gameloaddlg)
59 bool found_files =
false;
63 auto index = std::make_shared<savegame::save_index_class>(dir.path);
64 found_files = !
index->get_saves_list().empty();
80 , save_index_manager_(
data.manager)
81 , change_difficulty_(register_bool(
"change_difficulty", true,
data.select_difficulty))
82 , show_replay_(register_bool(
"show_replay", true,
data.show_replay))
83 , cancel_orders_(register_bool(
"cancel_orders", true,
data.cancel_orders))
84 , summary_(
data.summary)
86 , cache_config_(cache_config)
96 text_box* filter = find_widget<text_box>(
"txtFilter",
false,
true);
100 listbox& list = find_widget<listbox>(
"savegame_list");
118 menu_button& dir_list = find_widget<menu_button>(
"dirList");
131 if(other_dirs.empty()) {
136 std::vector<config> options;
139 options.emplace_back(
"label",
_(
"game_version^Current Version"),
"path",
"");
141 for(
const auto& known_dir : other_dirs) {
142 options.emplace_back(
144 "path", known_dir.path
153 listbox& list = find_widget<listbox>(
"savegame_list");
163 std::string name =
game.name();
165 item[
"label"] = name;
168 item[
"label"] =
game.format_time_summary();
182 find_widget<minimap>(
"minimap")
183 .set_map_data(
summary_[
"map_data"]);
185 find_widget<label>(
"lblScenario")
188 listbox& leader_list = find_widget<listbox>(
"leader_list");
202 std::string leader_image = leader[
"leader_image"].str();
209 leader_image = indep_path.value() + leader[
"leader_image_tc_modifier"].str();
213 if(leader_image.empty()) {
214 leader_image =
"units/unknown-unit.png" + leader[
"leader_image_tc_modifier"].str();
217 leader_image += sprite_scale_mod +
"~FL(horiz)";
220 item[
"label"] = leader_image;
223 item[
"label"] = leader[
"leader_name"];
226 item[
"label"] = leader[
"gold"];
230 item[
"label"] =
VGETTEXT(
"$active active, $reserve reserve", {{
"active", leader[
"units"]}, {
"reserve", leader[
"recall_units"]}});
231 data.emplace(
"leader_troops",
item);
242 std::stringstream str;
243 str <<
game.format_time_local() <<
"\n";
247 find_widget<styled_widget>(
"slblSummary").set_label(str.str());
259 replay_toggle.
set_active(!is_replay && !is_scenario_start);
262 cancel_orders_toggle.
set_active(!is_replay && !is_scenario_start);
265 change_difficulty_toggle.
set_active(!is_replay && is_scenario_start);
272 bool successfully_displayed_a_game =
false;
275 const int selected_row = find_widget<listbox>(
"savegame_list").get_selected_row();
276 if(selected_row < 0) {
277 find_widget<button>(
"delete").set_active(
false);
281 successfully_displayed_a_game =
true;
285 const std::string preamble =
_(
"The selected file is corrupt: ");
286 const std::string
message =
e.message.empty() ?
"(no details)" :
e.message;
290 if(!successfully_displayed_a_game) {
291 find_widget<minimap>(
"minimap").set_map_data(
"");
292 find_widget<label>(
"lblScenario")
294 find_widget<styled_widget>(
"slblSummary")
297 listbox& leader_list = find_widget<listbox>(
"leader_list");
310 find_widget<button>(
"ok").set_active(successfully_displayed_a_game);
323 listbox& list = find_widget<listbox>(
"savegame_list");
325 const std::vector<std::string> words =
utils::split(text,
' ');
331 boost::dynamic_bitset<> show_items;
337 for(
const auto & word : words)
346 show_items[
i] = found;
355 if(cfg_summary[
"corrupt"].to_bool()) {
356 str <<
"\n<span color='#f00'>" <<
_(
"(Invalid)") <<
"</span>";
364 const std::string&
campaign_type = cfg_summary[
"campaign_type"];
365 const std::string campaign_id = cfg_summary[
"campaign"];
368 if(campaign_type_enum) {
369 switch(*campaign_type_enum) {
370 case campaign_type::type::scenario: {
371 const config* campaign =
nullptr;
372 if(!campaign_id.empty()) {
379 if(campaign !=
nullptr) {
380 symbols[
"campaign_name"] = (*campaign)[
"name"];
383 symbols[
"campaign_name"] =
"(" + campaign_id +
")";
386 str <<
VGETTEXT(
"Campaign: $campaign_name", symbols);
390 str <<
'\n' <<
"(" << campaign_id <<
")";
394 case campaign_type::type::multiplayer:
395 str <<
_(
"Multiplayer");
397 case campaign_type::type::tutorial:
398 str <<
_(
"Tutorial");
400 case campaign_type::type::test:
401 str <<
_(
"Test scenario");
412 }
else if(!cfg_summary[
"turn"].empty()) {
413 str <<
_(
"Turn") <<
" " << cfg_summary[
"turn"];
415 str <<
_(
"Scenario start");
418 if(campaign_type_enum) {
419 switch (*campaign_type_enum) {
420 case campaign_type::type::scenario:
421 case campaign_type::type::multiplayer: {
422 const config* campaign =
nullptr;
423 if (!campaign_id.empty()) {
433 if (campaign !=
nullptr) {
434 str <<
"\n" <<
_(
"Difficulty: ");
437 std::ostringstream ss;
438 ss << difficulty[
"label"] <<
" (" << difficulty[
"description"] <<
")";
449 case campaign_type::type::tutorial:
450 case campaign_type::type::test:
456 if(!cfg_summary[
"version"].empty()) {
457 str <<
"\n" <<
_(
"Version: ") << cfg_summary[
"version"];
460 const std::vector<std::string>& active_mods =
utils::split(cfg_summary[
"active_mods"]);
461 if(!active_mods.empty()) {
462 str <<
"\n" <<
_(
"Modifications: ");
463 for(
const auto& mod_id : active_mods) {
464 std::string mod_name;
469 mod_name =
"(" + mod_id +
")";
483 listbox& list = find_widget<listbox>(
"savegame_list");
490 if(!gui2::dialogs::game_delete::execute()) {
522 if(key == SDLK_DELETE) {
529 menu_button& dir_list = find_widget<menu_button>(
"dirList");
539 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.
std::pair< std::string, unsigned > item
bool exists(const image::locator &i_locator)
Returns true if the given image actually exists, without loading it.
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.