15 #define GETTEXT_DOMAIN "wesnoth-lib" 50 #define ERR_GAMELOADDLG LOG_STREAM(err, log_gameloaddlg) 51 #define WRN_GAMELOADDLG LOG_STREAM(warn, log_gameloaddlg) 52 #define LOG_GAMELOADDLG LOG_STREAM(info, log_gameloaddlg) 53 #define DBG_GAMELOADDLG LOG_STREAM(debug, log_gameloaddlg) 107 , save_index_manager_(data.
manager)
108 , change_difficulty_(register_bool("change_difficulty", true, data.select_difficulty))
109 , show_replay_(register_bool("show_replay", true, data.show_replay))
110 , cancel_orders_(register_bool("cancel_orders", true, data.cancel_orders))
111 , summary_(data.summary)
113 , cache_config_(cache_config)
123 find_widget<minimap>(&window,
"minimap",
false).set_config(&
cache_config_);
125 text_box* filter = find_widget<text_box>(&window,
"txtFilter",
false,
true);
129 listbox& list = find_widget<listbox>(&window,
"savegame_list",
false);
133 window.keyboard_capture(filter);
134 window.add_to_keyboard_chain(&list);
147 menu_button& dir_list = find_widget<menu_button>(&window,
"dirList",
false);
160 if(other_dirs.empty()) {
168 options.emplace_back(
"label",
_(
"game_version^Current Version"),
"path",
"");
170 for(
const auto& known_dir : other_dirs) {
171 if(!known_dir.path.empty()) {
172 options.emplace_back(
174 "path", known_dir.path
184 listbox& list = find_widget<listbox>(&window,
"savegame_list",
false);
191 std::map<std::string, string_map> data;
194 std::string name =
game.name();
196 item[
"label"] = name;
197 data.emplace(
"filename", item);
199 item[
"label"] =
game.format_time_summary();
200 data.emplace(
"date", item);
205 find_widget<button>(&window,
"delete",
false).set_active(!
save_index_manager_->read_only());
210 const int selected_row =
211 find_widget<listbox>(&window,
"savegame_list",
false).get_selected_row();
213 if(selected_row == -1) {
221 find_widget<minimap>(&window,
"minimap",
false)
222 .set_map_data(
summary_[
"map_data"]);
224 find_widget<label>(&window,
"lblScenario",
false)
227 listbox& leader_list = find_widget<listbox>(&window,
"leader_list",
false);
234 std::map<std::string, string_map> data;
240 std::string leader_image = leader[
"leader_image"].str();
246 if(!leader_image.empty()) {
247 leader_image += leader[
"leader_image_tc_modifier"].str();
251 if(leader_image.empty()) {
252 leader_image =
"units/unknown-unit.png" + leader[
"leader_image_tc_modifier"].str();
255 leader_image += sprite_scale_mod;
258 item[
"label"] = leader_image;
259 data.emplace(
"imgLeader", item);
261 item[
"label"] = leader[
"leader_name"];
262 data.emplace(
"leader_name", item);
264 item[
"label"] = leader[
"gold"];
265 data.emplace(
"leader_gold", item);
267 item[
"label"] = leader[
"units"];
268 data.emplace(
"leader_troops", item);
270 item[
"label"] = leader[
"recall_units"];
271 data.emplace(
"leader_reserves", item);
276 std::stringstream str;
281 find_widget<scroll_label>(&window,
"slblSummary",
false).set_label(str.str());
282 window.invalidate_layout();
293 replay_toggle.
set_active(!is_replay && !is_scenario_start);
296 cancel_orders_toggle.
set_active(!is_replay && !is_scenario_start);
299 change_difficulty_toggle.
set_active(!is_replay && is_scenario_start);
310 const std::string preamble =
_(
"The selected file is corrupt: ");
313 find_widget<minimap>(&window,
"minimap",
false).set_map_data(
"");
314 find_widget<label>(&window,
"lblScenario",
false)
315 .set_label(preamble);
316 find_widget<scroll_label>(&window,
"slblSummary",
false)
319 listbox& leader_list = find_widget<listbox>(&window,
"leader_list",
false);
336 listbox& list = find_widget<listbox>(&window,
"savegame_list",
false);
338 const std::vector<std::string> words =
utils::split(text,
' ');
344 boost::dynamic_bitset<> show_items;
352 label& filename_label = find_widget<label>(*it,
"filename",
false);
355 for(
const auto & word : words)
357 found = std::search(filename_label.
get_label().
str().begin(),
370 show_items[
i] = found;
379 find_widget<button>(&window,
"ok",
false).set_active(any_shown);
382 window.set_enter_disabled(!any_shown);
387 std::string difficulty_human_str =
string_table[cfg_summary[
"difficulty"]];
388 if(cfg_summary[
"corrupt"].to_bool()) {
389 str <<
"\n<span color='#f00'>" <<
_(
"(Invalid)") <<
"</span>";
394 const std::string& campaign_type = cfg_summary[
"campaign_type"];
397 switch(game_classification::CAMPAIGN_TYPE::string_to_enum(campaign_type).v) {
399 const std::string campaign_id = cfg_summary[
"campaign"];
401 const config* campaign =
nullptr;
402 if(!campaign_id.empty()) {
408 if (campaign !=
nullptr) {
410 const config &difficulty = campaign->
find_child(
"difficulty",
"define", cfg_summary[
"difficulty"]);
411 std::ostringstream ss;
412 ss << difficulty[
"label"] <<
" (" << difficulty[
"description"] <<
")";
413 difficulty_human_str = ss.str();
419 if(campaign !=
nullptr) {
420 symbols[
"campaign_name"] = (*campaign)[
"name"];
423 symbols[
"campaign_name"] =
"(" + campaign_id +
")";
426 str <<
VGETTEXT(
"Campaign: $campaign_name", symbols);
430 str <<
'\n' <<
"(" << campaign_id <<
")";
434 case game_classification::CAMPAIGN_TYPE::MULTIPLAYER:
435 str <<
_(
"Multiplayer");
437 case game_classification::CAMPAIGN_TYPE::TUTORIAL:
438 str <<
_(
"Tutorial");
440 case game_classification::CAMPAIGN_TYPE::TEST:
441 str <<
_(
"Test scenario");
445 str << campaign_type;
452 }
else if(!cfg_summary[
"turn"].empty()) {
453 str <<
_(
"Turn") <<
" " << cfg_summary[
"turn"];
455 str <<
_(
"Scenario start");
458 str <<
"\n" <<
_(
"Difficulty: ")
459 << difficulty_human_str;
461 if(!cfg_summary[
"version"].empty()) {
462 str <<
"\n" <<
_(
"Version: ") << cfg_summary[
"version"];
465 const std::vector<std::string>& active_mods =
utils::split(cfg_summary[
"active_mods"]);
466 if(!active_mods.empty()) {
467 str <<
"\n" <<
_(
"Modifications: ");
468 for(
const auto& mod_id : active_mods) {
469 std::string mod_name;
474 mod_name =
"(" + mod_id +
")";
488 listbox& list = find_widget<listbox>(&window,
"savegame_list",
false);
491 if(index <
games_.size()) {
495 if(!gui2::dialogs::game_delete::execute()) {
532 if(key == SDLK_DELETE) {
539 menu_button& dir_list = find_widget<menu_button>(&window,
"dirList",
false);
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.
Abstract base class for text items.
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.
void display_savegame(window &window)
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_
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 set_save_dir_list(menu_button &dir_list)
bool chars_equal_insensitive(char a, char b)
int get_selected_row() const
Returns the first selected row.
void delete_button_callback(window &window)
Implements some helper classes to ease adding fields to a dialog and hide the synchronization needed...
std::vector< std::string > last_words_
std::vector< std::string > split(const std::string &val, const char c, const int flags)
Splits a (comma-)separated string into a vector of pieces.
const config & summary() const
Class for a single line text area.
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.
static UNUSEDNOWARN std::string _(const char *str)
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.
Iterator for the child items.
static bool is_replay_save(const config &cfg)
void populate_game_list(window &window)
Update (both internally and visually) the list of games.
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.
void key_press_callback(window &window, const SDL_Keycode key)
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.
const config & cache_config_
void handle_dir_select(window &window)
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
const grid * get_row_grid(const unsigned row) const
Returns the grid of the wanted row.
field_bool * cancel_orders_
void filter_text_changed(text_box_base *textbox, const std::string &text)
void display_savegame_internal(window &window)
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.
symbol_table string_table
void remove_row(const unsigned row, unsigned count=1)
Removes a row in the listbox.
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.
const std::string & str() const
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