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>(&
window,
"txtFilter",
false,
true);
100 listbox& list = find_widget<listbox>(&
window,
"savegame_list",
false);
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
163 std::string name =
game.name();
165 item[
"label"] = name;
168 item[
"label"] =
game.format_time_summary();
182 find_widget<minimap>(
get_window(),
"minimap",
false)
183 .set_map_data(
summary_[
"map_data"]);
185 find_widget<label>(
get_window(),
"lblScenario",
false)
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>(
get_window(),
"slblSummary",
false).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>(
get_window(),
"savegame_list",
false).get_selected_row();
276 if(selected_row < 0) {
277 find_widget<button>(
get_window(),
"delete",
false).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>(
get_window(),
"minimap",
false).set_map_data(
"");
292 find_widget<label>(
get_window(),
"lblScenario",
false)
294 find_widget<styled_widget>(
get_window(),
"slblSummary",
false)
310 find_widget<button>(
get_window(),
"ok",
false).set_active(successfully_displayed_a_game);
325 const std::vector<std::string> words =
utils::split(text,
' ');
331 boost::dynamic_bitset<> show_items;
337 for(
const auto & word : words)
352 show_items[
i] = found;
361 if(cfg_summary[
"corrupt"].to_bool()) {
362 str <<
"\n<span color='#f00'>" <<
_(
"(Invalid)") <<
"</span>";
370 const std::string&
campaign_type = cfg_summary[
"campaign_type"];
371 const std::string campaign_id = cfg_summary[
"campaign"];
374 if(campaign_type_enum) {
375 switch(*campaign_type_enum) {
376 case campaign_type::type::scenario: {
377 const config* campaign =
nullptr;
378 if(!campaign_id.empty()) {
385 if(campaign !=
nullptr) {
386 symbols[
"campaign_name"] = (*campaign)[
"name"];
389 symbols[
"campaign_name"] =
"(" + campaign_id +
")";
392 str <<
VGETTEXT(
"Campaign: $campaign_name", symbols);
396 str <<
'\n' <<
"(" << campaign_id <<
")";
400 case campaign_type::type::multiplayer:
401 str <<
_(
"Multiplayer");
403 case campaign_type::type::tutorial:
404 str <<
_(
"Tutorial");
406 case campaign_type::type::test:
407 str <<
_(
"Test scenario");
418 }
else if(!cfg_summary[
"turn"].empty()) {
419 str <<
_(
"Turn") <<
" " << cfg_summary[
"turn"];
421 str <<
_(
"Scenario start");
424 if(campaign_type_enum) {
425 switch (*campaign_type_enum) {
426 case campaign_type::type::scenario:
427 case campaign_type::type::multiplayer: {
428 const config* campaign =
nullptr;
429 if (!campaign_id.empty()) {
439 if (campaign !=
nullptr) {
440 str <<
"\n" <<
_(
"Difficulty: ");
443 std::ostringstream ss;
444 ss << difficulty[
"label"] <<
" (" << difficulty[
"description"] <<
")";
455 case campaign_type::type::tutorial:
456 case campaign_type::type::test:
462 if(!cfg_summary[
"version"].empty()) {
463 str <<
"\n" <<
_(
"Version: ") << cfg_summary[
"version"];
466 const std::vector<std::string>& active_mods =
utils::split(cfg_summary[
"active_mods"]);
467 if(!active_mods.empty()) {
468 str <<
"\n" <<
_(
"Modifications: ");
469 for(
const auto& mod_id : active_mods) {
470 std::string mod_name;
475 mod_name =
"(" + mod_id +
")";
496 if(!gui2::dialogs::game_delete::execute()) {
528 if(key == SDLK_DELETE) {
545 if(
auto* filter = find_widget<text_box>(
get_window(),
"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_
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_
virtual void pre_show(window &window) override
Actions to be taken before showing the window.
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.
window * get_window()
Returns a pointer to the dialog's 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.
base class of top level items, the only item which needs to store the final canvases to draw on.
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.
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.
bool chars_equal_insensitive(char a, char b)
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.
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.