15 #define GETTEXT_DOMAIN "wesnoth-lib" 51 #define ERR_GAMELOADDLG LOG_STREAM(err, log_gameloaddlg) 52 #define WRN_GAMELOADDLG LOG_STREAM(warn, log_gameloaddlg) 53 #define LOG_GAMELOADDLG LOG_STREAM(info, log_gameloaddlg) 54 #define DBG_GAMELOADDLG LOG_STREAM(debug, log_gameloaddlg) 65 , save_index_manager_(data.
manager)
66 , change_difficulty_(register_bool("change_difficulty", true, data.select_difficulty))
67 , show_replay_(register_bool("show_replay", true, data.show_replay))
68 , cancel_orders_(register_bool("cancel_orders", true, data.cancel_orders))
69 , summary_(data.summary)
71 , cache_config_(cache_config)
81 text_box* filter = find_widget<text_box>(&window,
"txtFilter",
false,
true);
85 listbox& list = find_widget<listbox>(&window,
"savegame_list",
false);
89 window.keyboard_capture(filter);
90 window.add_to_keyboard_chain(&list);
103 menu_button& dir_list = find_widget<menu_button>(&window,
"dirList",
false);
116 if(other_dirs.empty()) {
124 options.emplace_back(
"label",
_(
"game_version^Current Version"),
"path",
"");
126 for(
const auto& known_dir : other_dirs) {
127 if(!known_dir.path.empty()) {
128 options.emplace_back(
130 "path", known_dir.path
147 std::map<std::string, string_map> data;
152 item[
"label"] =
name;
153 data.emplace(
"filename", item);
155 item[
"label"] =
game.format_time_summary();
156 data.emplace(
"date", item);
166 const int selected_row =
167 find_widget<listbox>(
get_window(),
"savegame_list",
false).get_selected_row();
169 if(selected_row == -1) {
177 find_widget<minimap>(
get_window(),
"minimap",
false)
178 .set_map_data(
summary_[
"map_data"]);
180 find_widget<label>(
get_window(),
"lblScenario",
false)
190 std::map<std::string, string_map> data;
196 std::string leader_image = leader[
"leader_image"].str();
202 if(!leader_image.empty()) {
203 leader_image += leader[
"leader_image_tc_modifier"].str();
207 if(leader_image.empty()) {
208 leader_image =
"units/unknown-unit.png" + leader[
"leader_image_tc_modifier"].str();
211 leader_image += sprite_scale_mod;
214 item[
"label"] = leader_image;
215 data.emplace(
"imgLeader", item);
217 item[
"label"] = leader[
"leader_name"];
218 data.emplace(
"leader_name", item);
220 item[
"label"] = leader[
"gold"];
221 data.emplace(
"leader_gold", item);
223 item[
"label"] = leader[
"units"];
224 data.emplace(
"leader_troops", item);
226 item[
"label"] = leader[
"recall_units"];
227 data.emplace(
"leader_reserves", item);
232 std::stringstream str;
237 find_widget<scroll_label>(
get_window(),
"slblSummary",
false).set_label(str.str());
249 replay_toggle.
set_active(!is_replay && !is_scenario_start);
252 cancel_orders_toggle.
set_active(!is_replay && !is_scenario_start);
255 change_difficulty_toggle.
set_active(!is_replay && is_scenario_start);
266 const std::string preamble =
_(
"The selected file is corrupt: ");
269 find_widget<minimap>(
get_window(),
"minimap",
false).set_map_data(
"");
270 find_widget<label>(
get_window(),
"lblScenario",
false)
271 .set_label(preamble);
272 find_widget<scroll_label>(
get_window(),
"slblSummary",
false)
292 const std::vector<std::string> words =
utils::split(text,
' ');
298 boost::dynamic_bitset<> show_items;
304 for(
const auto & word : words)
319 show_items[
i] = found;
328 find_widget<button>(
get_window(),
"ok",
false).set_active(any_shown);
336 std::string difficulty_human_str =
string_table[cfg_summary[
"difficulty"]];
337 if(cfg_summary[
"corrupt"].to_bool()) {
338 str <<
"\n<span color='#f00'>" <<
_(
"(Invalid)") <<
"</span>";
343 const std::string& campaign_type = cfg_summary[
"campaign_type"];
346 switch(game_classification::CAMPAIGN_TYPE::string_to_enum(campaign_type).v) {
348 const std::string campaign_id = cfg_summary[
"campaign"];
350 const config* campaign =
nullptr;
351 if(!campaign_id.empty()) {
357 if (campaign !=
nullptr) {
359 const config &difficulty = campaign->
find_child(
"difficulty",
"define", cfg_summary[
"difficulty"]);
360 std::ostringstream ss;
361 ss << difficulty[
"label"] <<
" (" << difficulty[
"description"] <<
")";
362 difficulty_human_str = ss.str();
368 if(campaign !=
nullptr) {
369 symbols[
"campaign_name"] = (*campaign)[
"name"];
372 symbols[
"campaign_name"] =
"(" + campaign_id +
")";
375 str <<
VGETTEXT(
"Campaign: $campaign_name", symbols);
379 str <<
'\n' <<
"(" << campaign_id <<
")";
383 case game_classification::CAMPAIGN_TYPE::MULTIPLAYER:
384 str <<
_(
"Multiplayer");
386 case game_classification::CAMPAIGN_TYPE::TUTORIAL:
387 str <<
_(
"Tutorial");
389 case game_classification::CAMPAIGN_TYPE::TEST:
390 str <<
_(
"Test scenario");
394 str << campaign_type;
401 }
else if(!cfg_summary[
"turn"].empty()) {
402 str <<
_(
"Turn") <<
" " << cfg_summary[
"turn"];
404 str <<
_(
"Scenario start");
407 str <<
"\n" <<
_(
"Difficulty: ")
408 << difficulty_human_str;
410 if(!cfg_summary[
"version"].empty()) {
411 str <<
"\n" <<
_(
"Version: ") << cfg_summary[
"version"];
414 const std::vector<std::string>& active_mods =
utils::split(cfg_summary[
"active_mods"]);
415 if(!active_mods.empty()) {
416 str <<
"\n" <<
_(
"Modifications: ");
417 for(
const auto& mod_id : active_mods) {
418 std::string mod_name;
423 mod_name =
"(" + mod_id +
")";
440 if(index <
games_.size()) {
444 if(!gui2::dialogs::game_delete::execute()) {
481 if(key == SDLK_DELETE) {
Define the common log macros for the gui toolkit.
Dialog was closed with the CANCEL button.
#define REGISTER_DIALOG(window_id)
Wrapper for REGISTER_DIALOG2.
void set_text_changed_callback(std::function< void(text_box_base *textbox, const std::string text)> cb)
Set the text_changed callback.
std::map< std::string, t_string > string_map
field_bool * change_difficulty_
config & find_child(config_key_type key, const std::string &name, const std::string &value)
Returns the first child of tag key with a name attribute containing value.
Main class to show messages to the user.
This shows the dialog to select and load a savegame file.
static std::shared_ptr< save_index_class > default_saves_dir()
Returns an instance for managing saves in filesystem::get_saves_dir()
std::shared_ptr< savegame::save_index_class > & save_index_manager_
void populate_game_list()
Update (both internally and visually) the list of games.
const game_config_view & cache_config_
child_itors child_range(config_key_type key)
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. ...
void key_press_callback(const SDL_Keycode key)
bool chars_equal_insensitive(char a, char b)
void set_save_dir_list(menu_button &dir_list)
window * get_window() const
Returns a pointer to the dialog's window.
int get_selected_row() const
Returns the first selected row.
Implements some helper classes to ease adding fields to a dialog and hide the synchronization needed...
static std::string _(const char *str)
std::vector< std::string > last_words_
const config & summary() const
Class for a single line text area.
void delete_button_callback()
bool exists(const image::locator &i_locator)
Returns true if the given image actually exists, without loading it.
std::string format_time_local() const
Desktop environment interaction functions.
void connect_signal_notify_modified(dispatcher &dispatcher, const signal_notification_function &signal)
Connects a signal handler for getting a notification upon modification.
This file contains the settings handling of the widget library.
void browse_button_callback()
void clear()
Removes all the rows in the listbox, clearing it.
void connect_signal_mouse_left_click(dispatcher &dispatcher, const signal_function &signal)
Connects a signal handler for a left mouse button click.
static bool is_replay_save(const config &cfg)
unsigned get_item_count() const
Returns the number of items in the listbox.
std::string get_independent_image_path(const std::string &filename)
Returns an image path to filename for binary path-independent use in saved games. ...
bool any_rows_shown() const
std::vector< savegame::save_info > games_
const std::string & name() const
Various uncategorised dialogs.
styled_widget * get_widget()
bool open_object(const std::string &path_or_url)
Opens the specified object with the default application configured for its type.
virtual void pre_show(window &window) override
Inherited from modal_dialog.
void filter_text_changed(const std::string &text)
grid & add_row(const string_map &item, const int index=-1)
When an item in the list is selected by the user we need to update the state.
field_bool * show_replay_
Declarations for File-IO.
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.
const std::string unicode_bullet
void display_savegame_internal()
const config & find_child(config_key_type key, const std::string &name, const std::string &value) const
field_bool * cancel_orders_
Filename and modification date for a file list.
void connect_signal_pre_key_press(dispatcher &dispatcher, const signal_keyboard_function &signal)
Connects the signal for 'snooping' on the keypress.
std::vector< std::string > split(const config_attribute_value &val)
symbol_table string_table
void remove_row(const unsigned row, unsigned count=1)
Removes a row in the listbox.
void invalidate_layout()
Updates the size of the window.
static lg::log_domain log_gameloaddlg
std::vector< other_version_dir > find_other_version_saves_dirs()
Searches for directories containing saves created by other versions of Wesnoth.
void register_sorting_option(const int col, const Func &f)
A config object defines a single node in a WML file, with access to child nodes.
void set_retval(int retval)
Convenience wrapper to set the window's exit code.
base class of top level items, the only item which needs to store the final canvases to draw on...
void set_row_shown(const unsigned row, const bool shown)
Makes a row visible or invisible.
void evaluate_summary_string(std::stringstream &str, const config &cfg_summary)
std::pair< std::string, unsigned > item
void set_enter_disabled(const bool enter_disabled)
Disable the enter key.