15 #define GETTEXT_DOMAIN "wesnoth-lib"
31 #ifdef GUI2_EXPERIMENTAL_LISTBOX
92 : txtFilter_(register_text("txtFilter", true))
93 , chk_change_difficulty_(register_bool("change_difficulty", true))
94 , chk_show_replay_(register_bool("show_replay", true))
95 , chk_cancel_orders_(register_bool("cancel_orders", true))
97 , change_difficulty_(false)
99 , cancel_orders_(false)
101 , cache_config_(cache_config)
111 find_widget<tminimap>(&window,
"minimap",
false).set_config(&
cache_config_);
114 = find_widget<ttext_box>(&window,
"txtFilter",
false,
true);
120 = find_widget<tlistbox>(&window,
"savegame_list",
false,
true);
122 #ifdef GUI2_EXPERIMENTAL_LISTBOX
129 dialog_callback<tgame_load, &tgame_load::list_item_clicked>);
131 window.keyboard_capture(list);
140 find_widget<tbutton>(&window,
"delete",
false),
169 std::vector<savegame::save_info>& games)
171 tlistbox& list = find_widget<tlistbox>(&window,
"savegame_list",
false);
174 for(
const auto &
game : games)
176 std::map<std::string, string_map>
data;
181 item[
"label"] =
name;
182 data.insert(std::make_pair(
"filename", item));
184 item[
"label"] =
game.format_time_summary();
185 data.insert(std::make_pair(
"date", item));
189 std::vector<tgenerator_::torder_func> order_funcs(2);
207 tlistbox& list = find_widget<tlistbox>(&window,
"savegame_list",
false);
209 const std::vector<std::string> words =
utils::split(text,
' ');
223 = find_widget<tlabel>(*it,
"filename",
false);
226 for(
const auto & word : words)
228 found = std::search(filename_label.
label().
str().begin(),
233 != filename_label.
label().
str().end();
241 show_items[
i] = found;
256 find_widget<tlistbox>(&window,
"savegame_list",
false).get_selected_row();
263 const int selected_row
264 = find_widget<tlistbox>(&window,
"savegame_list",
false)
267 if(selected_row == -1) {
276 find_widget<timage>(&window,
"imgLeader",
false)
279 find_widget<tminimap>(&window,
"minimap",
false)
280 .set_map_data(summary[
"map_data"]);
282 find_widget<tlabel>(&window,
"lblScenario",
false)
285 std::stringstream str;
290 find_widget<ttoggle_button>(&window,
"show_replay",
false);
293 find_widget<ttoggle_button>(&window,
"cancel_orders",
false);
296 const bool is_scenario_start = summary[
"turn"].
empty();
300 replay_toggle.
set_active(!is_replay && !is_scenario_start);
303 cancel_orders_toggle.set_active(!is_replay && !is_scenario_start);
305 find_widget<tlabel>(&window,
"lblSummary",
false).
set_label(str.str());
312 const config& cfg_summary)
315 const std::string& campaign_type = cfg_summary[
"campaign_type"];
316 if(cfg_summary[
"corrupt"].to_bool()) {
317 str <<
"\n" <<
_(
"#(Invalid)");
323 game_classification::CAMPAIGN_TYPE ct
329 const std::string campaign_id = cfg_summary[
"campaign"];
330 const config* campaign =
nullptr;
331 if(!campaign_id.empty()) {
333 "campaign",
"id", campaign_id)) {
339 if(campaign !=
nullptr) {
340 symbols[
"campaign_name"] = (*campaign)[
"name"];
343 symbols[
"campaign_name"] =
"(" + campaign_id +
")";
345 str <<
vgettext(
"Campaign: $campaign_name", symbols);
349 str <<
'\n' <<
"(" << campaign_id <<
")";
353 case game_classification::CAMPAIGN_TYPE::MULTIPLAYER:
354 str <<
_(
"Multiplayer");
356 case game_classification::CAMPAIGN_TYPE::TUTORIAL:
357 str <<
_(
"Tutorial");
359 case game_classification::CAMPAIGN_TYPE::TEST:
360 str <<
_(
"Test scenario");
366 str << campaign_type;
373 }
else if(!cfg_summary[
"turn"].empty()) {
374 str <<
_(
"Turn") <<
" " << cfg_summary[
"turn"];
376 str <<
_(
"Scenario start");
379 str <<
"\n" <<
_(
"Difficulty: ")
382 if(!cfg_summary[
"version"].empty()) {
383 str <<
"\n" <<
_(
"Version: ") << cfg_summary[
"version"];
390 tlistbox& list = find_widget<tlistbox>(&window,
"savegame_list",
false);
393 if(index <
games_.size()) {
Define the common log macros for the gui toolkit.
const config & cache_config_
tfield_bool * chk_cancel_orders_
void set_row_shown(const unsigned row, const bool shown)
Makes a row visible or invisible.
void remove_row(const unsigned row, unsigned count=1)
Removes a row in the listbox.
void connect_signal_notify_modified(tdispatcher &dispatcher, const tsignal_notification_function &signal)
Connects a signal handler for getting a notification upon modification.
std::vector< save_info > get_saves_list(const std::string *dir, const std::string *filter)
Get a list of available saves.
REGISTER_DIALOG(label_settings)
void connect_signal_mouse_left_click(tdispatcher &dispatcher, const tsignal_function &signal)
Connects a signal handler for a left mouse button click.
std::vector< savegame::save_info > games_
Class for a single line text area.
T get_widget_value(twindow &window)
Gets the value of the field.
Implements some helper classes to ease adding fields to a dialog and hide the synchronization needed...
GLint GLenum GLsizei GLint GLsizei const GLvoid * data
To lexical_cast(From value)
Lexical cast converts one type to another.
void pre_show(twindow &window)
Inherited from tdialog.
base class of top level items, the only item which needs to store the final canvases to draw on ...
A class inherited from ttext_box that displays its input as stars.
tfield_bool * chk_show_replay_
void ellipsis_truncate(std::string &str, const size_t size)
Truncates a string to a given utf-8 character count and then appends an ellipsis. ...
static UNUSEDNOWARN std::string _(const char *str)
std::vector< std::string > last_words_
const config & summary() const
bool chars_equal_insensitive(char a, char b)
bool compare_date_rev(unsigned i1, unsigned i2) const
std::map< std::string, t_string > string_map
unsigned get_item_count() const
Returns the number of items in the listbox.
void 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.
void delete_button_callback(twindow &window)
bool compare_date(unsigned i1, unsigned i2) const
void delete_game(const std::string &name)
Delete a savegame.
bool compare_name_rev(unsigned i1, unsigned i2) const
static bool is_replay_save(const config &cfg)
std::string format_time_local() const
void set_column_order(unsigned col, const std::vector< tgenerator_::torder_func > &func)
Iterator for the tchild items.
const t_string & label() const
void fill_game_list(twindow &window, std::vector< savegame::save_info > &games)
std::map< std::string, t_string > string_map
void display_savegame(twindow &window)
void list_item_clicked(twindow &window)
static bool execute(CVideo &video)
The execute function see tdialog for more information.
void post_show(twindow &window)
Inherited from tdialog.
void filter_text_changed(ttext_ *textbox, const std::string &text)
bool compare_name(unsigned i1, unsigned i2) const
GLuint const GLchar * name
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
GLenum GLenum GLvoid * row
Filename and modification date for a file list.
const std::string & name() const
symbol_table string_table
config & find_child(const std::string &key, const std::string &name, const std::string &value)
Returns the first child of tag key with a name attribute containing value.
void set_callback_value_change(const std::function< void(twidget &)> &callback)
void evaluate_summary_string(std::stringstream &str, const config &cfg_summary)
static void set_label(twindow &window, const std::string &id, const std::string &label)
std::vector< std::string > split(std::string const &val, const char c, const int flags)
Splits a (comma-)separated string into a vector of pieces.
const std::string & str() const
tfield_bool * chk_change_difficulty_
A config object defines a single node in a WML file, with access to child nodes.
int get_selected_row() const
Returns the first selected row.
Thrown when a lexical_cast fails.
GLsizei const GLcharARB ** string
Abstract base class for text items.
void clear()
Removes all the rows in the listbox, clearing it.
const tgrid * get_row_grid(const unsigned row) const
Returns the grid of the wanted row.
void set_text_changed_callback(std::function< void(ttext_ *textbox, const std::string text)> cb)
Set the text_changed callback.