15 #define GETTEXT_DOMAIN "wesnoth-lib" 50 tree_view& tree = find_widget<tree_view>(get_window(),
"campaign_tree",
false);
58 auto iter = std::find(page_ids_.begin(), page_ids_.end(), tree.
selected_item()->
id());
60 const int choice = std::distance(page_ids_.begin(), iter);
61 if(iter == page_ids_.end()) {
65 multi_page& pages = find_widget<multi_page>(get_window(),
"campaign_details",
false);
68 engine_.set_current_level(choice);
70 styled_widget& background = find_widget<styled_widget>(get_window(),
"campaign_background",
false);
71 background.
set_label(engine_.current_level().data()[
"background"].str());
74 difficulties_.clear();
76 auto& diff_menu = find_widget<menu_button>(get_window(),
"difficulty_menu",
false);
79 diff_menu.set_active(diff_config.child_count(
"difficulty") > 1);
81 if(!diff_config.empty()) {
82 std::vector<config> entry_list;
83 unsigned n = 0, selection = 0, max_n = diff_config.child_count(
"difficulty");
85 for(
const auto& cfg : diff_config.child_range(
"difficulty")) {
89 entry[
"label"] = cfg[
"label"].str() +
" (" + cfg[
"description"].str() +
")";
90 entry[
"image"] = cfg[
"image"].str(
"misc/blank-hex.png");
103 entry[
"image"] = laurel +
"~BLIT(" + entry[
"image"] +
")";
106 if(!cfg[
"description"].empty()) {
108 if(cfg[
"auto_markup"].to_bool(
true) ==
false) {
109 desc = cfg[
"description"].str();
112 if(!cfg[
"old_markup"].to_bool()) {
122 desc = cfg[
"label"].str() +
"\n" + desc;
124 entry[
"details"] = std::move(desc);
127 entry_list.emplace_back(std::move(entry));
128 difficulties_.emplace_back(cfg[
"define"].str());
130 if(cfg[
"default"].to_bool(
false)) {
137 diff_menu.set_values(entry_list);
138 diff_menu.set_selected(selection);
145 const std::size_t selection = find_widget<menu_button>(
get_window(),
"difficulty_menu",
false).get_value();
169 if(cpn_b ==
nullptr) {
170 return cpn_a !=
nullptr;
173 if(cpn_a ==
nullptr) {
178 ? cpn_a->
dates().first < cpn_b->dates().first
179 : cpn_a->dates().first > cpn_b->dates().first;
187 return ascending ? cmp < 0 : cmp > 0;
196 std::string was_selected;
202 boost::dynamic_bitset<> show_items;
203 show_items.resize(
levels.size(),
true);
206 for(
unsigned i = 0;
i <
levels.size(); ++
i) {
221 show_items[
i] = found;
225 bool exists_in_filtered_result =
false;
226 for(
unsigned i = 0;
i <
levels.size(); ++
i) {
230 if (!exists_in_filtered_result) {
231 exists_in_filtered_result =
levels[
i]->id() == was_selected;
236 if(!was_selected.empty() && exists_in_filtered_result) {
237 find_widget<tree_view_node>(
get_window(), was_selected,
false).select_node();
245 static bool force =
false;
267 find_widget<toggle_button>(
get_window(),
"sort_time",
false).set_value(0);
268 }
else if(order ==
DATE) {
269 find_widget<toggle_button>(
get_window(),
"sort_name",
false).set_value(0);
280 const std::vector<std::string> words =
utils::split(text,
' ');
292 text_box* filter = find_widget<text_box>(&window,
"filter_box",
false,
true);
297 tree_view& tree = find_widget<tree_view>(&window,
"campaign_tree",
false);
302 toggle_button& sort_name = find_widget<toggle_button>(&window,
"sort_name",
false);
303 toggle_button& sort_time = find_widget<toggle_button>(&window,
"sort_time",
false);
311 window.keyboard_capture(filter);
312 window.add_to_keyboard_chain(&tree);
315 multi_page& pages = find_widget<multi_page>(&window,
"campaign_details",
false);
324 std::map<std::string, string_map> data;
327 item[
"label"] = campaign[
"description"];
328 item[
"use_markup"] =
"true";
330 if(!campaign[
"description_alignment"].empty()) {
331 item[
"text_alignment"] = campaign[
"description_alignment"];
334 data.emplace(
"description", item);
336 item[
"label"] = campaign[
"image"];
337 data.emplace(
"image", item);
346 multimenu_button& mods_menu = find_widget<multimenu_button>(&window,
"mods_menu",
false);
349 std::vector<config> mod_menu_values;
353 const bool active = std::find(enabled.begin(), enabled.end(), mod->id) != enabled.end();
355 mod_menu_values.emplace_back(
"label", mod->name,
"checkbox", active);
366 mods_menu.
set_label(
_(
"active_modifications^None"));
383 std::map<std::string, string_map> data;
386 item[
"label"] = campaign[
"icon"];
387 data.emplace(
"icon", item);
389 item[
"label"] = campaign[
"name"];
390 data.emplace(
"name", item);
393 if(campaign[
"completed"].to_bool()) {
396 auto did_complete_at = [](
const config&
c) {
return c[
"completed_at"].to_bool(); };
399 const bool only_first_completed = difficulties.size() > 1 &&
400 std::none_of(difficulties.begin() + 1, difficulties.end(), did_complete_at);
413 if(!difficulties.empty() && did_complete_at(difficulties.back())) {
415 }
else if(only_first_completed && did_complete_at(difficulties.front())) {
421 data.emplace(
"victory", item);
429 tree_view& tree = find_widget<tree_view>(&window,
"campaign_tree",
false);
451 boost::dynamic_bitset<> new_mod_states =
452 find_widget<multimenu_button>(
get_window(),
"mods_menu",
false).get_toggle_states();
boost::dynamic_bitset mod_states_
#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
void add_campaign_to_tree(const config &campaign) const
std::shared_ptr< level > level_ptr
ng::create_engine & engine_
This shows the dialog which allows the user to choose which campaign to play.
grid & add_page(const string_map &item)
Adds single page to the grid.
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()
window * get_window() const
Returns a pointer to the dialog's window.
std::string victory_laurel_easy
std::pair< irdya_date, irdya_date > dates() const
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.
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)
int choice_
The chosen campaign.
void connect_signal_notify_modified(dispatcher &dispatcher, const signal_notification_function &signal)
Connects a signal handler for getting a notification upon modification.
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.
std::vector< level_ptr > get_levels_by_type_unfiltered(level::TYPE type) const
virtual void post_show(window &window) override
Inherited from modal_dialog.
A tree view is a control that holds several items of the same or different types. ...
std::vector< std::string > & active_mods()
Various uncategorised dialogs.
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
Inherited from modal_dialog.
void select_page(const unsigned page, const bool select=true)
Selects a page.
std::vector< std::string > difficulties_
static int sort(lua_State *L)
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
static void reverse(lua_State *L, StkId from, StkId to)
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...
tree_view_node & add_node(const std::string &id, const std::map< std::string, string_map > &data, const int index=-1)
std::pair< std::string, unsigned > item
std::vector< std::string > last_search_words_