16 #define GETTEXT_DOMAIN "wesnoth-lib" 49 tree_view& tree = find_widget<tree_view>(
this,
"campaign_tree",
false);
57 auto iter = std::find(page_ids_.begin(), page_ids_.end(), tree.
selected_item()->
id());
59 const int choice = std::distance(page_ids_.begin(), iter);
60 if(iter == page_ids_.end()) {
64 multi_page& pages = find_widget<multi_page>(
this,
"campaign_details",
false);
67 engine_.set_current_level(choice);
69 styled_widget& background = find_widget<styled_widget>(
this,
"campaign_background",
false);
70 background.
set_label(engine_.current_level().data()[
"background"].str());
73 difficulties_.clear();
75 auto& diff_menu = find_widget<menu_button>(
this,
"difficulty_menu",
false);
78 diff_menu.set_active(diff_config.child_count(
"difficulty") > 1);
80 if(!diff_config.empty()) {
81 std::vector<config> entry_list;
82 unsigned n = 0, selection = 0, max_n = diff_config.child_count(
"difficulty");
84 for(
const auto& cfg : diff_config.child_range(
"difficulty")) {
88 entry[
"label"] = cfg[
"label"].str() +
" (" + cfg[
"description"].str() +
")";
89 entry[
"image"] = cfg[
"image"].str(
"misc/blank-hex.png");
102 entry[
"image"] = laurel +
"~BLIT(" + entry[
"image"] +
")";
105 if(!cfg[
"description"].empty()) {
107 if(cfg[
"auto_markup"].to_bool(
true) ==
false) {
108 desc = cfg[
"description"].str();
111 if(!cfg[
"old_markup"].to_bool()) {
121 desc = cfg[
"label"].str() +
"\n" + desc;
123 entry[
"details"] = std::move(desc);
126 entry_list.emplace_back(std::move(entry));
127 difficulties_.emplace_back(cfg[
"define"].str());
129 if(cfg[
"default"].to_bool(
false)) {
136 diff_menu.set_values(entry_list);
137 diff_menu.set_selected(selection);
144 const std::size_t selection = find_widget<menu_button>(
this,
"difficulty_menu",
false).get_value();
164 std::sort(
levels.begin(),
levels.end(), [ascending](
const level_ptr&
a,
const level_ptr&
b) {
168 if(cpn_b ==
nullptr) {
169 return cpn_a !=
nullptr;
172 if(cpn_a ==
nullptr) {
177 ? cpn_a->
dates().first < cpn_b->dates().first
178 : cpn_a->dates().first > cpn_b->dates().first;
184 std::sort(
levels.begin(),
levels.end(), [ascending](
const level_ptr&
a,
const level_ptr&
b) {
186 return ascending ? cmp < 0 : cmp > 0;
192 tree_view& tree = find_widget<tree_view>(
this,
"campaign_tree",
false);
195 std::string was_selected;
201 boost::dynamic_bitset<> show_items;
202 show_items.resize(
levels.size(),
true);
205 for(
unsigned i = 0;
i <
levels.size(); ++
i) {
220 show_items[
i] = found;
224 bool exists_in_filtered_result =
false;
225 for(
unsigned i = 0;
i <
levels.size(); ++
i) {
229 if (!exists_in_filtered_result) {
230 exists_in_filtered_result =
levels[
i]->id() == was_selected;
235 if(!was_selected.empty() && exists_in_filtered_result) {
236 find_widget<tree_view_node>(
this, was_selected,
false).select_node();
244 static bool force =
false;
266 find_widget<toggle_button>(
this,
"sort_time",
false).set_value(0);
267 }
else if(order ==
DATE) {
268 find_widget<toggle_button>(
this,
"sort_name",
false).set_value(0);
279 const std::vector<std::string> words =
utils::split(text,
' ');
291 text_box* filter = find_widget<text_box>(&
window,
"filter_box",
false,
true);
296 tree_view& tree = find_widget<tree_view>(&
window,
"campaign_tree",
false);
310 window.keyboard_capture(filter);
311 window.add_to_keyboard_chain(&tree);
314 multi_page& pages = find_widget<multi_page>(&
window,
"campaign_details",
false);
326 item[
"label"] = campaign[
"description"];
327 item[
"use_markup"] =
"true";
329 if(!campaign[
"description_alignment"].empty()) {
330 item[
"text_alignment"] = campaign[
"description_alignment"];
333 data.emplace(
"description", item);
335 item[
"label"] = campaign[
"image"];
336 data.emplace(
"image", item);
348 std::vector<config> mod_menu_values;
352 const bool active = std::find(enabled.begin(), enabled.end(), mod->id) != enabled.end();
354 mod_menu_values.emplace_back(
"label", mod->name,
"checkbox", active);
365 mods_menu.
set_label(
_(
"active_modifications^None"));
371 menu_button& diff_menu = find_widget<menu_button>(
this,
"difficulty_menu",
false);
381 tree_view& tree = find_widget<tree_view>(
this,
"campaign_tree",
false);
385 item[
"label"] = campaign[
"icon"];
386 data.emplace(
"icon", item);
388 item[
"label"] = campaign[
"name"];
389 data.emplace(
"name", item);
392 if(campaign[
"completed"].to_bool()) {
395 auto did_complete_at = [](
const config&
c) {
return c[
"completed_at"].to_bool(); };
398 const bool only_first_completed = difficulties.size() > 1 &&
399 std::none_of(difficulties.begin() + 1, difficulties.end(), did_complete_at);
412 if(!difficulties.empty() && did_complete_at(difficulties.back())) {
414 }
else if(only_first_completed && did_complete_at(difficulties.front())) {
420 data.emplace(
"victory", item);
428 tree_view& tree = find_widget<tree_view>(&
window,
"campaign_tree",
false);
450 boost::dynamic_bitset<> new_mod_states =
451 find_widget<multimenu_button>(
this,
"mods_menu",
false).get_toggle_states();
boost::dynamic_bitset mod_states_
window(const builder_window::window_resolution &definition)
< Needs to be initialized in show.
#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::string victory_laurel
std::shared_ptr< level > level_ptr
ng::create_engine & engine_
This shows the dialog which allows the user to choose which campaign to play.
tree_view_node & add_node(const std::string &id, const widget_data &data, const int index=-1)
New lexcical_cast header.
bool is_campaign_completed(const std::string &campaign_id)
child_itors child_range(config_key_type key)
tree_view_node * selected_item()
std::vector< level_ptr > get_levels_by_type_unfiltered(level_type::type type) const
std::string victory_laurel_easy
static std::string _(const char *str)
void campaign_selected()
Called when another campaign is selected.
std::vector< std::pair< const std::string *, const stats * > > levels
Stats (and name) for each scenario.
Class for a single line text area.
std::pair< utils::irdya_date, utils::irdya_date > dates() const
void filter_text_changed(const std::string &text)
std::string span_color(const color_t &color)
Returns a Pango formatting string using the provided color_t object.
void difficulty_selected()
Called when the difficulty selection changes.
bool toggle_mod(int index, bool force=false)
std::map< std::string, t_string > widget_item
int choice_
The chosen campaign.
std::string victory_laurel_hardest
RNG_MODE rng_mode_
whether the player checked the "Deterministic" checkbox.
This file contains the settings handling of the widget library.
virtual void post_show(window &window) override
Actions to be taken after the window has been shown.
void add_campaign_to_tree(const config &campaign)
A tree view is a control that holds several items of the same or different types. ...
std::vector< std::string > & active_mods()
void sort_campaigns(CAMPAIGN_ORDER order, bool ascending)
std::vector< std::string > page_ids_
boost::iterator_range< const_child_iterator > const_child_itors
bool ci_search(const std::string &s1, const std::string &s2)
bool currently_sorted_asc_
void toggle_sorting_selection(CAMPAIGN_ORDER order)
config generate_difficulty_config(const config &source)
Helper function to convert old difficulty markup.
virtual void pre_show(window &window) override
Actions to be taken before showing the window.
void select_page(const unsigned page, const bool select=true)
Selects a page.
std::vector< std::string > difficulties_
grid & add_page(const widget_item &item)
Adds single page to the grid.
std::string current_difficulty_
RNG_MODE
RNG mode selection values.
CAMPAIGN_ORDER current_sorting_
A multi page is a control that contains several 'pages' of which only one is visible.
std::vector< std::string > split(const config_attribute_value &val)
int icompare(const std::string &s1, const std::string &s2)
Case-insensitive lexicographical comparison.
void set_modifications(const std::vector< std::string > &value, bool mp)
const std::vector< extras_metadata_ptr > & get_const_extras_by_type(const MP_EXTRA extra_type) const
std::map< std::string, widget_item > widget_data
A config object defines a single node in a WML file, with access to child nodes.
static map_location::DIRECTION n
base class of top level items, the only item which needs to store the final canvases to draw on...
void connect_signal_notify_modified(dispatcher &dispatcher, const signal_notification &signal)
Connects a signal handler for getting a notification upon modification.
std::pair< std::string, unsigned > item
std::vector< std::string > last_search_words_