void tcampaign_selection::pre_show(CVideo& /*video*/, twindow& window)
{
	/***** Setup campaign list. *****/
	tlistbox& list =
			find_widget<tlistbox>(&window, "campaign_list", false);
#ifdef GUI2_EXPERIMENTAL_LISTBOX
	connect_signal_notify_modified(list, boost::bind(
			  &tcampaign_selection::campaign_selected
			, this
			, boost::ref(window)));
#else
	list.set_callback_value_change(dialog_callback
			<tcampaign_selection
			, &tcampaign_selection::campaign_selected>);
#endif
	window.keyboard_capture(&list);

	/***** Setup campaign details. *****/

	tmulti_page& multi_page = find_widget<tmulti_page>(
			&window, "campaign_details", false);

	size_t n = 0;
	foreach (const config &c, campaigns_) {
		if (c["id"] == "tutorial") {
			n ++;
			continue;
		}
		/*** Add list item ***/
		string_map list_item;
		std::map<std::string, string_map> list_item_item;

		list_item["label"] = c["icon"];
		list_item_item.insert(std::make_pair("icon", list_item));

		list_item["label"] = c["name"];
		list_item_item.insert(std::make_pair("name", list_item));

		list.add_row(list_item_item);

		tgrid* grid = list.get_row_grid(list.get_item_count() - 1);
		assert(grid);

		tcontrol* widget = dynamic_cast<tcontrol*>(grid->find("mode", false));
		if (widget) {
			const std::string& mode = c["mode"].str();
			if (mode == "rpg") {
				widget->set_label("misc/mode-rpg.png");
			} else if (mode == "tower") {
				widget->set_label("misc/mode-tower.png");
			}
		}

		ttoggle_panel* toggle = dynamic_cast<ttoggle_panel*>(grid->find("_toggle", true));
		toggle->set_data(n ++);

		/*** Add detail item ***/
		string_map detail_item;
		std::map<std::string, string_map> detail_page;

		detail_item["label"] = c["description"];
		detail_item["use_markup"] = "true";
		detail_page.insert(std::make_pair("description", detail_item));

		detail_item["label"] = c["image"];
		detail_page.insert(std::make_pair("image", detail_item));

		multi_page.add_page(detail_page);
	}

	campaign_selected(window);
}
Example #2
0
void campaign_selection::pre_show(window& window)
{
	/***** Setup campaign tree. *****/
	tree_view& tree = find_widget<tree_view>(&window, "campaign_tree", false);

	tree.set_selection_change_callback(
		std::bind(&campaign_selection::campaign_selected, this, std::ref(window)));

	window.keyboard_capture(&tree);

	/***** Setup campaign details. *****/
	multi_page& pages = find_widget<multi_page>(&window, "campaign_details", false);

	unsigned id = 0;
	for(const auto & level : engine_.get_levels_by_type_unfiltered(ng::level::TYPE::SP_CAMPAIGN)) {
		const config& campaign = level->data();

		/*** Add tree item ***/
		std::map<std::string, string_map> data;
		string_map item;

		item["label"] = campaign["icon"];
		data.emplace("icon", item);

		item["label"] = campaign["name"];
		data.emplace("name", item);

		item["label"] = campaign["completed"].to_bool() ? "misc/laurel.png" : "misc/blank-hex.png";
		data.emplace("victory", item);

		tree.add_node("campaign", data).set_id(std::to_string(id++));

		/*** Add detail item ***/
		item.clear();
		data.clear();

		item["label"] = campaign["description"];
		item["use_markup"] = "true";

		if(!campaign["description_alignment"].empty()) {
			item["text_alignment"] = campaign["description_alignment"];
		}

		data.emplace("description", item);

		item["label"] = campaign["image"];
		data.emplace("image", item);

		pages.add_page(data);
	}

	if(!engine_.get_const_extras_by_type(ng::create_engine::MOD).empty()) {
		std::map<std::string, string_map> data;
		string_map item;

		item["label"] = "Modifications";
		data.emplace("tree_view_node_label", item);

		tree_view_node& mods_node = tree.add_node("campaign_group", data);
		std::vector<std::string> enabled = engine_.active_mods();

		id = 0;
		for(const auto& mod : engine_.get_const_extras_by_type(ng::create_engine::MOD)) {
			data.clear();
			item.clear();

			bool active = std::find(enabled.begin(), enabled.end(), mod->id) != enabled.end();

			/*** Add tree item ***/
			item["label"] = mod->name;
			data.emplace("checkb", item);

			tree_view_node& node = mods_node.add_child("modification", data);

			toggle_button* checkbox = dynamic_cast<toggle_button*>(node.find("checkb", true));
			VALIDATE(checkbox, missing_widget("checkb"));

			checkbox->set_value(active);
			checkbox->set_label(mod->name);
			checkbox->set_callback_state_change(std::bind(&campaign_selection::mod_toggled, this, id, _1));

			++id;
		}
	}

	campaign_selected(window);

	/***** Setup advanced settings button *****/
	button* advanced_settings_button =
			find_widget<button>(&window, "advanced_settings", false, false);
	if(advanced_settings_button) {
		advanced_settings_button->connect_click_handler(
			std::bind(&campaign_selection::show_settings, this, std::ref(window.video())));
	}
}
void tcampaign_selection::pre_show(twindow& window)
{
	if(new_widgets || true) {
		/***** Setup campaign tree. *****/
		ttree_view& tree
				= find_widget<ttree_view>(&window, "campaign_tree", false);

		tree.set_selection_change_callback(
				std::bind(&tcampaign_selection::campaign_selected,
							this,
							std::ref(window)));

		window.keyboard_capture(&tree);

		string_map tree_group_field;
		std::map<std::string, string_map> tree_group_item;
		/***** Setup campaign details. *****/
		tmulti_page& multi_page
				= find_widget<tmulti_page>(&window, "campaign_details", false);

		unsigned id = 0;
		for(const auto & level : engine_.get_levels_by_type_unfiltered(ng::level::TYPE::SP_CAMPAIGN))
		{
			const config& campaign = level->data();

			/*** Add tree item ***/
			tree_group_field["label"] = campaign["icon"];
			tree_group_item["icon"] = tree_group_field;

			tree_group_field["label"] = campaign["name"];
			tree_group_item["name"] = tree_group_field;

			tree_group_field["label"] = campaign["completed"].to_bool() ? "misc/laurel.png" : "misc/blank-hex.png";
			tree_group_item["victory"] = tree_group_field;

			tree.add_node("campaign", tree_group_item).set_id(std::to_string(id++));

			/*** Add detail item ***/
			string_map detail_item;
			std::map<std::string, string_map> detail_page;

			detail_item["label"] = campaign["description"];
			detail_item["use_markup"] = "true";

			if(!campaign["description_alignment"].empty()) {
				detail_item["text_alignment"] = campaign["description_alignment"];
			}

			detail_page.emplace("description", detail_item);

			detail_item["label"] = campaign["image"];
			detail_page.emplace("image", detail_item);

			multi_page.add_page(detail_page);
		}
		if (!engine_.get_const_extras_by_type(ng::create_engine::MOD).empty()) {

			tree_group_field["label"] = "Modifications";
			tree_group_item["tree_view_node_label"] = tree_group_field;
			//tree_group_item["tree_view_node_label"] = tree_group_field;
			ttree_view_node& mods_node = tree.add_node("campaign_group", tree_group_item);
			std::vector<std::string> enabled = engine_.active_mods();

			id = 0;
			tree_group_item.clear();
			for(const auto& mod : engine_.get_const_extras_by_type(ng::create_engine::MOD))
			{
				bool active = std::find(enabled.begin(), enabled.end(), mod->id) != enabled.end();
				/*** Add tree item ***/
				tree_group_field["label"] = mod->name;
				tree_group_item["checkb"] = tree_group_field;

				ttree_view_node & node = mods_node.add_child("modification", tree_group_item);
				ttoggle_button* checkbox = dynamic_cast<ttoggle_button*>(node.find("checkb", true));
				VALIDATE(checkbox, missing_widget("checkb"));
				checkbox->set_value(active);
				checkbox->set_label(mod->name);
				checkbox->set_callback_state_change(std::bind(&tcampaign_selection::mod_toggled, this, id, _1));
				++id;
			}
		}
	} else {
		/***** Hide the tree view. *****/
		if(ttree_view* tree
		   = find_widget<ttree_view>(&window, "campaign_tree", false, false)) {

			tree->set_visible(twidget::tvisible::invisible);
		}

		/***** Setup campaign list. *****/
		tlistbox& list = find_widget<tlistbox>(&window, "campaign_list", false);
#ifdef GUI2_EXPERIMENTAL_LISTBOX
		connect_signal_notify_modified(
				list,
				std::bind(&tcampaign_selection::campaign_selected,
							this,
							std::ref(window)));
#else
		list.set_callback_value_change(
				dialog_callback<tcampaign_selection,
								&tcampaign_selection::campaign_selected>);
#endif
		window.keyboard_capture(&list);

		/***** Setup campaign details. *****/
		tmulti_page& multi_page
				= find_widget<tmulti_page>(&window, "campaign_details", false);

		for(const auto & level : engine_.get_levels_by_type_unfiltered(ng::level::TYPE::SP_CAMPAIGN))
		{
			const config& campaign = level->data();

			/*** Add list item ***/
			string_map list_item;
			std::map<std::string, string_map> list_item_item;

			list_item["label"] = campaign["icon"];
			list_item_item.emplace("icon", list_item);

			list_item["label"] = campaign["name"];
			list_item_item.emplace("name", list_item);

			tgrid* grid = &list.add_row(list_item_item);
			assert(grid);

			twidget* widget = grid->find("victory", false);
			if(widget && !campaign["completed"].to_bool()) {
				widget->set_visible(twidget::tvisible::hidden);
			}

			/*** Add detail item ***/
			string_map detail_item;
			std::map<std::string, string_map> detail_page;

			detail_item["use_markup"] = "true";

			detail_item["label"] = campaign["description"];
			detail_page.emplace("description", detail_item);

			detail_item["label"] = campaign["image"];
			detail_page.emplace("image", detail_item);

			multi_page.add_page(detail_page);
		}
	}
	campaign_selected(window);

	/***** Setup advanced settings button *****/
	tbutton* advanced_settings_button =
			find_widget<tbutton>(&window, "advanced_settings", false, false);
	if(advanced_settings_button) {
		advanced_settings_button->connect_click_handler(
			std::bind(&tcampaign_selection::show_settings, this, std::ref(window.video())));
	}
}
void tcampaign_selection::pre_show(CVideo& /*video*/, twindow& window)
{
	tlabel* label = find_widget<tlabel>(&window, "title", false, true);
	if (catalog_ == TUTORIAL_CATALOG) {
		label->set_label(_("Tutorial"));
	}

	/***** Setup campaign list. *****/
	tlistbox& list =
			find_widget<tlistbox>(&window, "campaign_list", false);

	list.set_callback_value_change(dialog_callback3<tcampaign_selection, tlistbox, &tcampaign_selection::campaign_selected>);

	window.keyboard_capture(&list);

	std::vector<config> campaigns_cfg = campaigns_cfg_;
	campaigns_cfg.push_back(config());
	config& sub = campaigns_cfg.back();
	sub["id"] = "random_map";
	sub["name"] = _("random_map");
	sub["description"] = _("random_map description");
	sub["icon"] = "data/app-kingdom/campaigns/random_map/images/icon.png";
	sub["image"] = "data/app-kingdom/campaigns/random_map/images/image.png";

	size_t n = 0;
	BOOST_FOREACH (const config &c, campaigns_cfg) {
		const std::string catalog = c["catalog"].str();
		if (catalog_ == NONE_CATALOG) {
			if (!catalog.empty()) {
				n ++;
				continue;
			}
		} else if (catalog_ == TUTORIAL_CATALOG) {
			if (catalog != "tutorial") {
				n ++;
				continue;
			}
		}
		const std::string mode = c["mode"].str();
		if ((!preferences::developer() && c["subcontinent"].to_bool()) || mode_tag::find(mode) == mode_tag::SIEGE) {
			n ++;
			continue;
		}

		/*** Add list item ***/
		string_map list_item;
		std::map<std::string, string_map> list_item_item;

		list_item["label"] = c["icon"];
		list_item_item.insert(std::make_pair("icon", list_item));

		list_item["label"] = c["name"];
		list_item_item.insert(std::make_pair("name", list_item));

		list.add_row(list_item_item);

		twidget* panel = list.get_row_panel(list.get_item_count() - 1);

		tcontrol* widget = dynamic_cast<tcontrol*>(panel->find("mode", false));
		if (widget) {
			if (mode == "tower") {
				widget->set_label("misc/mode-tower.png");
			} else if (c["rank"].to_int() == 100) {
				widget->set_label("misc/mode-rpg.png");
			}
		}

		ttoggle_panel* toggle = dynamic_cast<ttoggle_panel*>(panel);
		toggle->set_data(n ++);

		/*** Add detail item ***/
		campaigns_.push_back(tcampaign(c["description"].str(), c["image"].str()));
	}
	
	campaign_selected(window, list);
}