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();
158 std::reverse(levels.begin(), levels.end());
164 std::sort(levels.begin(), levels.end(), [ascending](
const level_ptr&
a,
const level_ptr&
b) {
165 auto cpn_a = std::dynamic_pointer_cast<ng::campaign>(a);
166 auto cpn_b = std::dynamic_pointer_cast<ng::campaign>(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) {
185 const int cmp = translation::icompare(a->name(), b->name());
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);
204 if(!last_search_words_.empty()) {
205 for(
unsigned i = 0;
i < levels.size(); ++
i) {
207 for(
const auto& word : last_search_words_) {
220 show_items[
i] = found;
224 bool exists_in_filtered_result =
false;
225 for(
unsigned i = 0;
i < levels.size(); ++
i) {
227 add_campaign_to_tree(levels[
i]->
data());
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);
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"];
335 item[
"label"] = campaign[
"image"];
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"];
388 item[
"label"] = campaign[
"name"];
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())) {
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();
A config object defines a single node in a WML file, with access to child nodes.
child_itors child_range(config_key_type key)
boost::iterator_range< const_child_iterator > const_child_itors
This shows the dialog which allows the user to choose which campaign to play.
void toggle_sorting_selection(CAMPAIGN_ORDER order)
RNG_MODE rng_mode_
whether the player checked the "Deterministic" checkbox.
CAMPAIGN_ORDER current_sorting_
virtual void pre_show(window &window) override
Actions to be taken before showing the window.
void difficulty_selected()
Called when the difficulty selection changes.
int choice_
The chosen campaign.
std::vector< std::string > difficulties_
RNG_MODE
RNG mode selection values.
boost::dynamic_bitset mod_states_
std::string current_difficulty_
void sort_campaigns(CAMPAIGN_ORDER order, bool ascending)
bool currently_sorted_asc_
ng::create_engine & engine_
void add_campaign_to_tree(const config &campaign)
void filter_text_changed(const std::string &text)
void campaign_selected()
Called when another campaign is selected.
virtual void post_show(window &window) override
Actions to be taken after the window has been shown.
std::vector< std::string > last_search_words_
std::vector< std::string > page_ids_
A multi page is a control that contains several 'pages' of which only one is visible.
grid & add_page(const widget_item &item)
Adds single page to the grid.
void select_page(const unsigned page, const bool select=true)
Selects a page.
void set_text_changed_callback(std::function< void(text_box_base *textbox, const std::string text)> cb)
Set the text_changed callback.
Class for a single line text area.
A tree view is a control that holds several items of the same or different types.
tree_view_node & add_node(const std::string &id, const widget_data &data, const int index=-1)
tree_view_node * selected_item()
base class of top level items, the only item which needs to store the final canvases to draw on.
void keyboard_capture(widget *widget)
void add_to_keyboard_chain(widget *widget)
Adds the widget to the keyboard chain.
std::vector< std::string > & active_mods()
const std::vector< extras_metadata_ptr > & get_const_extras_by_type(const MP_EXTRA extra_type) const
std::shared_ptr< level > level_ptr
std::vector< level_ptr > get_levels_by_type_unfiltered(level_type::type type) const
bool toggle_mod(int index, bool force=false)
static std::string _(const char *str)
New lexcical_cast header.
#define REGISTER_DIALOG(window_id)
Wrapper for REGISTER_DIALOG2.
std::string span_color(const color_t &color)
Returns a Pango formatting string using the provided color_t object.
std::string victory_laurel_hardest
std::string victory_laurel
std::string victory_laurel_easy
config generate_difficulty_config(const config &source)
Helper function to convert old difficulty markup.
void connect_signal_notify_modified(dispatcher &dispatcher, const signal_notification &signal)
Connects a signal handler for getting a notification upon modification.
std::map< std::string, widget_item > widget_data
std::map< std::string, t_string > widget_item
std::pair< std::string, unsigned > item
void set_modifications(const std::vector< std::string > &value, bool mp)
bool is_campaign_completed(const std::string &campaign_id)
bool ci_search(const std::string &s1, const std::string &s2)
std::vector< std::string > split(const config_attribute_value &val)
This file contains the settings handling of the widget library.
static map_location::DIRECTION n