Beispiel #1
0
void taddon_connect::pre_show(CVideo& /*video*/, twindow& window)
{
	ttext_box* host_widget = dynamic_cast<ttext_box*>(window.find_widget("host_name", false));
	VALIDATE(host_widget, missing_widget("host_name"));

	host_widget->set_value(host_name_);
	window.keyboard_capture(host_widget);
}
Beispiel #2
0
void tmessage::pre_show(CVideo& /*video*/, twindow& window)
{
	if(!title_.empty()) {
		tlabel* title =
			dynamic_cast<tlabel*>(window.find_widget("title", false));
		VALIDATE(title, missing_widget("title"));

		title->set_label(title_);
	}

	if(!image_.empty()) {
		timage* image =
			dynamic_cast<timage*>(window.find_widget("image", false));
		VALIDATE(image, missing_widget("image"));

		image->set_label(image_);
	}

	tcontrol* label =
		dynamic_cast<tcontrol*>(window.find_widget("label", false));
	VALIDATE(label, missing_widget("label"));

	label->set_label(message_);
	// The label might not always be a scroll_label but the capturing
	// shouldn't hurt.
	window.keyboard_capture(label);
	
	if(auto_close_) {
		/*
		 * Hide the buttton and do the layout, if window.does_easy_close() is
		 * false the scroll_label has a scrollbar so we need to show the
		 * button. When the button is hidden the text for the label is bigger
		 * and thus not need a scrollbar. Also when the button is visible
		 * easy_close will always return false.
		 */
		tbutton* button =
			dynamic_cast<tbutton*>(window.find_widget("ok", false));
		VALIDATE(button, missing_widget("ok"));
		button->set_visible(twidget::INVISIBLE);
		window.layout();

		if(! window.does_easy_close()) {
			button->set_visible(twidget::VISIBLE);
		}
	}
}
Beispiel #3
0
	const T* find_widget(const std::string& id,
			const bool must_be_active, const bool must_exist) const
	{
		const T* widget =
			dynamic_cast<const T*>(find_widget(id, must_be_active));
		VALIDATE(!must_exist || widget, missing_widget(id));

		return widget;
	}
T* find_widget(typename tconst_duplicator<T, twidget>::type* widget
		, const std::string& id
		, const bool must_be_active
		, const bool must_exist)
{
	T* result =
		dynamic_cast<T*>(widget->find(id, must_be_active));
	VALIDATE(!must_exist || result, missing_widget(id));

	return result;
}
std::pair<T*, config::attribute_value> mp_options_helper::add_node_and_get_widget(
		tree_view_node& option_node, const std::string& id, data_map& data, const config& cfg)
{
	tree_view_node& node = option_node.add_child(id + "_node", data);

	T* widget = dynamic_cast<T*>(node.find(id, true));
	VALIDATE(widget, missing_widget(id));

	const std::string widget_id = cfg["id"];

	auto& option_config = options_data_[visible_options_.back().id];
	if(!option_config.has_attribute(widget_id) || option_config[widget_id].empty()) {
		option_config[widget_id] = cfg["default"];
	}

	widget->set_id(widget_id);
	widget->set_tooltip(cfg["description"]);

	return {widget, option_config[widget_id]};
}
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 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(CVideo& video, 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(
				boost::bind(&tcampaign_selection::campaign_selected,
							this,
							boost::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;
		FOREACH(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(lexical_cast<std::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";
			detail_page.insert(std::make_pair("description", detail_item));

			detail_item["label"] = campaign["image"];
			detail_page.insert(std::make_pair("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();
			FOREACH(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(boost::bind(&tcampaign_selection::mod_toggled, this, id, _1));
				++id;
			}
		}
Beispiel #9
0
void tmp_create_game::display_custom_options(ttree_view& tree, std::string&& type, const std::string& id, const config& cfg)
{
	auto& map = visible_options_[{type, id}];
	static const std::map<std::string, string_map> empty;

	for(const auto& options : cfg.child_range("options")) {
		std::map<std::string, string_map> data;
		string_map item;

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

		ttree_view_node& option_node = tree.add_node("option_node", data);

		for(const auto& checkbox_option : options.child_range("checkbox")) {
			data.clear();

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

			ttree_view_node& node = option_node.add_child("option_checkbox_node", data);

			ttoggle_button* checkbox = dynamic_cast<ttoggle_button*>(node.find("option_checkbox", true));

			VALIDATE(checkbox, missing_widget("option_checkbox"));

			checkbox->set_value(checkbox_option["default"].to_bool());
			//checkbox->set_label(checkbox_option["name"].str());
			map[checkbox_option["id"]] = [checkbox]() { return cav(checkbox->get_value_bool()); };
		}

		// Only add a spacer if there were an option of this type
		if(options.has_child("checkbox")) {
			option_node.add_child("options_spacer_node", empty);
		}

		for(const auto& combobox_option : options.child_range("combo")) {
			data.clear();

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

			std::vector<config> combo_items;
			std::vector<std::string> combo_values;

			for(const auto& item : combobox_option.child_range("item")) {
				combo_items.push_back(item);
				combo_values.push_back(item["value"]);
			}

			if(combo_items.empty()) {
				continue;
			}

			ttree_view_node& node = option_node.add_child("option_combobox_node", data);

			tcombobox* combobox = dynamic_cast<tcombobox*>(node.find("option_combobox", true));

			VALIDATE(combobox, missing_widget("option_combobox"));

			combobox->set_values(combo_items);

			map[combobox_option["id"]] = [combobox, combo_values]() { return cav(combo_values[combobox->get_value()]); };
		}

		// Only add a spacer if there were an option of this type
		if(options.has_child("combo")) {
			option_node.add_child("options_spacer_node", empty);
		}

		for(const auto& slider_option : options.child_range("slider")) {
			data.clear();

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

			ttree_view_node& node = option_node.add_child("option_slider_node", data);

			tslider* slider = dynamic_cast<tslider*>(node.find("option_slider", true));

			VALIDATE(slider, missing_widget("option_slider"));

			slider->set_maximum_value(slider_option["max"].to_int());
			slider->set_minimum_value(slider_option["min"].to_int());
			slider->set_step_size(slider_option["step"].to_int(1));
			slider->set_value(slider_option["default"].to_int());

			map[slider_option["id"]] = [slider]() { return cav(slider->get_value()); };
		}

		// Only add a spacer if there were an option of this type
		if(options.has_child("slider")) {
			option_node.add_child("options_spacer_node", empty);
		}

		for(const auto& text_entry_option : options.child_range("entry")) {
			data.clear();

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

			ttree_view_node& node = option_node.add_child("option_text_entry_node", data);

			ttext_box* textbox = dynamic_cast<ttext_box*>(node.find("option_text_entry", true));

			VALIDATE(textbox, missing_widget("option_text_entry"));

			textbox->set_value(text_entry_option["default"].str());

			map[text_entry_option["id"]] = [textbox]() { return cav(textbox->get_value()); };
		}

		// Add the Defaults button at the end
		option_node.add_child("options_default_button", empty);
	}
}
Beispiel #10
0
	const T& get_widget(const std::string& id, const bool must_be_active) const
	{
		const T* result = dynamic_cast<const T*>(find_widget(id, must_be_active));
		VALIDATE(result, missing_widget(id));
		return *result;
	}