16 #define GETTEXT_DOMAIN "wesnoth-lib"
45 tree_view& tree = find_widget<tree_view>(
"campaign_tree");
54 if(!campaign_id.empty()) {
55 auto iter = std::find(page_ids_.begin(), page_ids_.end(), campaign_id);
57 button& ok_button = find_widget<button>(
"proceed");
58 ok_button.
set_active(campaign_id != missing_campaign_);
59 ok_button.
set_label((campaign_id == addons_) ?
_(
"game^Get Add-ons") :
_(
"game^Play"));
61 const int choice = std::distance(page_ids_.begin(), iter);
62 if(iter == page_ids_.end()) {
66 multi_page& pages = find_widget<multi_page>(
"campaign_details");
69 engine_.set_current_level(choice);
71 styled_widget& background = find_widget<styled_widget>(
"campaign_background");
72 background.
set_label(engine_.current_level().data()[
"background"].str());
75 difficulties_.clear();
77 auto& diff_menu = find_widget<menu_button>(
"difficulty_menu");
80 diff_menu.set_active(diff_config.child_count(
"difficulty") > 1);
82 if(!diff_config.empty()) {
83 std::vector<config> entry_list;
84 unsigned n = 0, selection = 0, max_n = diff_config.child_count(
"difficulty");
86 for(
const auto& cfg : diff_config.child_range(
"difficulty")) {
90 entry[
"label"] = cfg[
"label"].str() +
" (" + cfg[
"description"].str() +
")";
91 entry[
"image"] = cfg[
"image"].str(
"misc/blank-hex.png");
93 if(
prefs::get().is_campaign_completed(campaign_id, cfg[
"define"])) {
104 entry[
"image"] = laurel +
"~BLIT(" + entry[
"image"].str() +
")";
107 if(!cfg[
"description"].empty()) {
109 if(cfg[
"auto_markup"].to_bool(
true) ==
false) {
110 desc = cfg[
"description"].str();
112 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>(
"difficulty_menu").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>(
"campaign_tree");
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;
225 boost::dynamic_bitset<> filter_comp_options = find_widget<multimenu_button>(
"filter_completion").get_toggle_states();
227 bool exists_in_filtered_result =
false;
228 for(
unsigned i = 0;
i < levels.size(); ++
i) {
231 auto did_complete_at = [](
const config&
c) {
return c[
"completed_at"].to_bool(); };
234 const bool only_first_completed = difficulties.size() > 1 &&
235 std::none_of(difficulties.begin() + 1, difficulties.end(), did_complete_at);
236 const bool completed_easy = only_first_completed && did_complete_at(difficulties.front());
237 const bool completed_hardest = !difficulties.empty() && did_complete_at(difficulties.back());
238 const bool completed_mid = completed && !completed_hardest && !completed_easy;
240 if( show_items[
i] && (
241 ( (!completed) && filter_comp_options[0] )
242 || ( completed && filter_comp_options[4] )
243 || ( completed_hardest && filter_comp_options[3] )
244 || ( completed_easy && filter_comp_options[1] )
245 || ( completed_mid && filter_comp_options[2])
247 add_campaign_to_tree(levels[
i]->
data());
248 if (!exists_in_filtered_result) {
249 exists_in_filtered_result = levels[
i]->id() == was_selected;
254 if(!was_selected.empty() && exists_in_filtered_result) {
255 find_widget<tree_view_node>(was_selected).select_node();
263 static bool force =
false;
285 find_widget<toggle_button>(
"sort_time").set_value(0);
286 }
else if(order ==
DATE) {
287 find_widget<toggle_button>(
"sort_name").set_value(0);
298 const std::vector<std::string> words =
utils::split(text,
' ');
310 text_box* filter = find_widget<text_box>(
"filter_box",
false,
true);
315 tree_view& tree = find_widget<tree_view>(
"campaign_tree");
320 toggle_button& sort_name = find_widget<toggle_button>(
"sort_name");
321 toggle_button& sort_time = find_widget<toggle_button>(
"sort_time");
336 multi_page& pages = find_widget<multi_page>(
"campaign_details");
339 multimenu_button& filter_comp = find_widget<multimenu_button>(
"filter_completion");
342 for (
unsigned j = 0; j < filter_comp.
num_options(); j++) {
357 item[
"label"] = campaign[
"description"];
358 item[
"use_markup"] =
"true";
360 if(!campaign[
"description_alignment"].empty()) {
361 item[
"text_alignment"] = campaign[
"description_alignment"];
364 data.emplace(
"description", item);
366 item[
"label"] = campaign[
"image"];
367 data.emplace(
"image", item);
377 addons[
"icon"] =
"icons/icon-game.png~BLIT(icons/icon-addon-publish.png)";
378 addons[
"name"] =
_(
"More campaigns...");
379 addons[
"completed"] =
false;
387 item[
"label"] =
_(
"In addition to the mainline campaigns, Wesnoth also has an ever-growing list of add-on content created by other players available via the Add-ons server, included but not limited to more single and multiplayer campaigns, multiplayer maps, additional media and various other content! Be sure to give it a try!");
388 data.emplace(
"description", item);
392 std::vector<std::string> dirs;
394 if(dirs.size() <= 15) {
396 missing[
"icon"] =
"units/unknown-unit.png";
397 missing[
"name"] =
_(
"Missing Campaigns");
408 item[
"label"] =
_(
"Wesnoth normally includes more than 15 mainline campaigns, even before installing any from the add-ons server. If you’ve installed the game via a package manager, there’s probably a separate package to install the complete game data.");
409 data.emplace(
"description", item);
421 std::vector<config> mod_menu_values;
425 const bool active = std::find(enabled.begin(), enabled.end(), mod->id) != enabled.end();
427 mod_menu_values.emplace_back(
"label", mod->name,
"checkbox", active);
439 mods_menu.
set_label(
_(
"active_modifications^None"));
445 menu_button& diff_menu = find_widget<menu_button>(
"difficulty_menu");
455 tree_view& tree = find_widget<tree_view>(
"campaign_tree");
459 item[
"label"] = campaign[
"icon"];
460 data.emplace(
"icon", item);
462 item[
"label"] = campaign[
"name"];
463 data.emplace(
"name", item);
466 if(campaign[
"completed"].to_bool()) {
469 auto did_complete_at = [](
const config&
c) {
return c[
"completed_at"].to_bool(); };
472 const bool only_first_completed = difficulties.size() > 1 &&
473 std::none_of(difficulties.begin() + 1, difficulties.end(), did_complete_at);
486 if(!difficulties.empty() && did_complete_at(difficulties.back())) {
488 }
else if(only_first_completed && did_complete_at(difficulties.front())) {
494 data.emplace(
"victory", item);
498 node.
set_id(campaign[
"id"]);
507 tree_view& tree = find_widget<tree_view>(
"campaign_tree");
515 if(!campaign_id.empty()) {
535 boost::dynamic_bitset<> new_mod_states =
536 find_widget<multimenu_button>(
"mods_menu").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
void toggle_sorting_selection(CAMPAIGN_ORDER order)
RNG_MODE rng_mode_
whether the player checked the "Deterministic" checkbox.
CAMPAIGN_ORDER current_sorting_
void difficulty_selected()
Called when the difficulty selection changes.
int choice_
The chosen campaign.
std::vector< std::string > mod_ids_
std::vector< std::string > difficulties_
static const int OPEN_ADDON_MANAGER
RNG_MODE
RNG mode selection values.
static const std::string missing_campaign_
boost::dynamic_bitset mod_states_
std::string current_difficulty_
virtual void pre_show() override
Actions to be taken before showing the window.
void sort_campaigns(CAMPAIGN_ORDER order, bool ascending)
static const std::string addons_
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.
std::vector< std::string > last_search_words_
std::vector< std::string > page_ids_
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.
A widget that allows the user to input text in single line.
tree_view_node & add_node(const std::string &id, const widget_data &data, const int index=-1)
tree_view_node * selected_item()
void set_retval(const int retval, const bool close_window=true)
Sets there return value of the window.
void keyboard_capture(widget *widget)
void add_to_keyboard_chain(widget *widget)
Adds the widget to the keyboard chain.
bool toggle_mod(const std::string &id, bool force=false)
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 is_campaign_completed(const std::string &campaign_id)
void set_modifications(const std::vector< std::string > &value, bool mp=true)
Declarations for File-IO.
static std::string _(const char *str)
void get_files_in_dir(const std::string &dir, std::vector< std::string > *files, std::vector< std::string > *dirs, name_mode mode, filter_mode filter, reorder_mode reorder, file_tree_checksum *checksum)
Get a list of all files and/or directories in a given directory.
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.
REGISTER_DIALOG(editor_edit_unit)
void connect_signal_notify_modified(dispatcher &dispatcher, const signal_notification &signal)
Connects a signal handler for getting a notification upon modification.
void connect_signal_mouse_left_click(dispatcher &dispatcher, const signal &signal)
Connects a signal handler for a left mouse button click.
void connect_signal_mouse_left_double_click(dispatcher &dispatcher, const signal &signal)
Connects a signal handler for a left mouse button double click.
std::map< std::string, widget_item > widget_data
std::map< std::string, t_string > widget_item
@ OK
Dialog was closed with the OK button.
std::string span_color(const color_t &color, Args &&... data)
bool ci_search(const std::string &s1, const std::string &s2)
std::vector< std::string > split(const config_attribute_value &val)
static map_location::direction n