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 unit_recall::pre_show(window& window)
{
	label& title = find_widget<label>(&window, "title", true);
	title.set_label(title.get_label() + get_title_suffix(team_.side()));

	text_box* filter
			= find_widget<text_box>(&window, "filter_box", false, true);

	filter->set_text_changed_callback(
			std::bind(&unit_recall::filter_text_changed, this, _1, _2));

	listbox& list = find_widget<listbox>(&window, "recall_list", false);

	connect_signal_notify_modified(list, std::bind(&unit_recall::list_item_clicked, this, std::ref(window)));

	list.clear();

	window.keyboard_capture(filter);
	window.add_to_keyboard_chain(&list);

	connect_signal_mouse_left_click(
		find_widget<button>(&window, "rename", false),
		std::bind(&unit_recall::rename_unit, this, std::ref(window)));

	connect_signal_mouse_left_click(
		find_widget<button>(&window, "dismiss", false),
		std::bind(&unit_recall::dismiss_unit, this, std::ref(window)));

	connect_signal_mouse_left_click(
		find_widget<button>(&window, "show_help", false),
		std::bind(&unit_recall::show_help, this));

	for(const unit_const_ptr& unit : recall_list_) {
		std::map<std::string, string_map> row_data;
		string_map column;

		std::string mods = unit->image_mods();

		if(unit->can_recruit()) {
			mods += "~BLIT(" + unit::leader_crown() + ")";
		}

		for(const std::string& overlay : unit->overlays()) {
			mods += "~BLIT(" + overlay + ")";
		}

		column["use_markup"] = "true";

		column["label"] = unit->absolute_image() + mods;
		row_data.emplace("unit_image", column);

		column["label"] = unit->type_name();
		row_data.emplace("unit_type", column);

		column["label"] = format_cost_string(unit->recall_cost(), team_.recall_cost());
		row_data.emplace("unit_recall_cost", column);

		const std::string& name = !unit->name().empty() ? unit->name().str() : font::unicode_en_dash;
		column["label"] = name;
		row_data.emplace("unit_name", column);

		column["label"] = format_level_string(unit->level());
		row_data.emplace("unit_level", column);

		std::stringstream exp_str;
		exp_str << font::span_color(unit->xp_color());
		if(unit->can_advance()) {
			exp_str << unit->experience() << "/" << unit->max_experience();
		} else {
			exp_str << font::unicode_en_dash;
		}
		exp_str << "</span>";

		column["label"] = exp_str.str();
		row_data.emplace("unit_experience", column);

		// Since the table widgets use heavy formatting, we save a bare copy
		// of certain options to filter on.
		std::string filter_text = unit->type_name() + " " + name + " " + std::to_string(unit->level());

		std::string traits;
		for(const std::string& trait : unit->trait_names()) {
			traits += (traits.empty() ? "" : "\n") + trait;
			filter_text += " " + trait;
		}

		column["label"] = !traits.empty() ? traits : font::unicode_en_dash;
		row_data.emplace("unit_traits", column);

		list.add_row(row_data);
		filter_options_.push_back(filter_text);
	}

	list.register_translatable_sorting_option(0, [this](const int i) { return recall_list_[i]->type_name().str(); });
	list.register_translatable_sorting_option(1, [this](const int i) { return recall_list_[i]->name().str(); });
	list.register_sorting_option(2, [this](const int i) {
		const unit& u = *recall_list_[i];
		return std::make_tuple(u.level(), -static_cast<int>(u.experience_to_advance()));
	});
	list.register_sorting_option(3, [this](const int i) { return recall_list_[i]->experience(); });
	list.register_translatable_sorting_option(4, [this](const int i) {
		return !recall_list_[i]->trait_names().empty() ? recall_list_[i]->trait_names().front().str() : "";
	});

	list.set_active_sorting_option(sort_last.first >= 0 ? sort_last	: sort_default, true);

	list_item_clicked(window);
}
Beispiel #3
0
void lobby_main::pre_show(window& window)
{
	SCOPE_LB;

	gamelistbox_ = find_widget<listbox>(&window, "game_list", false, true);
#ifdef GUI2_EXPERIMENTAL_LISTBOX
	connect_signal_notify_modified(
			*gamelistbox_,
			std::bind(&lobby_main::gamelist_change_callback, *this, std::ref(window)));
#else
	gamelistbox_->set_callback_value_change(
			dialog_callback<lobby_main, &lobby_main::gamelist_change_callback>);
#endif

	window.keyboard_capture(gamelistbox_);

	player_list_.init(window);

	player_list_.sort_by_name->set_value(preferences::playerlist_sort_name());
	player_list_.sort_by_relation->set_value(preferences::playerlist_sort_relation());
	player_list_.update_sort_icons();

	player_list_.sort_by_name->set_callback_state_change(
			std::bind(&lobby_main::player_filter_callback, this, _1));
	player_list_.sort_by_relation->set_callback_state_change(
			std::bind(&lobby_main::player_filter_callback, this, _1));

	window.set_enter_disabled(true);
	window.set_escape_disabled(true);

	// A new key handler to deal with escape in a different manner.
	window.connect_signal<event::SDL_KEY_DOWN>(
		std::bind(&lobby_main::signal_handler_key_down, this, _5, _3, _4),
		event::dispatcher::front_pre_child);

	window_ = &window;

	chatbox_ = find_widget<chatbox>(&window, "chat", false, true);
	chatbox_->set_lobby_info(lobby_info_);
	chatbox_->set_wesnothd_connection(wesnothd_connection_);
	chatbox_->set_active_window_changed_callback([this]() { player_list_dirty_ = true; });

	find_widget<button>(&window, "create", false).set_retval(CREATE);

	connect_signal_mouse_left_click(
		find_widget<button>(&window, "refresh", false),
		std::bind(&lobby_main::refresh_button_callback, this, std::ref(window)));

	connect_signal_mouse_left_click(
		find_widget<button>(&window, "show_preferences", false),
		std::bind(&lobby_main::show_preferences_button_callback, this, std::ref(window)));

	connect_signal_mouse_left_click(
		find_widget<button>(&window, "join_global", false),
		std::bind(&lobby_main::join_global_button_callback, this, std::ref(window)));

	find_widget<button>(&window, "join_global", false).set_active(false);

	connect_signal_mouse_left_click(
		find_widget<button>(&window, "observe_global", false),
		std::bind(&lobby_main::observe_global_button_callback, this, std::ref(window)));

	find_widget<button>(&window, "observe_global", false).set_active(false);

	menu_button& replay_options = find_widget<menu_button>(&window, "replay_options", false);

	if(preferences::skip_mp_replay()) {
		replay_options.set_selected(1);
	}

	if(preferences::blindfold_replay()) {
		replay_options.set_selected(2);
	}

	replay_options.connect_click_handler(
			std::bind(&lobby_main::skip_replay_changed_callback, this, std::ref(window)));

	filter_friends_ = find_widget<toggle_button>(&window, "filter_with_friends", false, true);
	filter_ignored_ = find_widget<toggle_button>(&window, "filter_without_ignored", false, true);
	filter_slots_   = find_widget<toggle_button>(&window, "filter_vacant_slots", false, true);
	filter_invert_  = find_widget<toggle_button>(&window, "filter_invert", false, true);
	filter_text_    = find_widget<text_box>(&window, "filter_text", false, true);

	filter_friends_->set_callback_state_change(
			std::bind(&lobby_main::game_filter_change_callback, this, _1));
	filter_ignored_->set_callback_state_change(
			std::bind(&lobby_main::game_filter_change_callback, this, _1));
	filter_slots_->set_callback_state_change(
			std::bind(&lobby_main::game_filter_change_callback, this, _1));
	filter_invert_->set_callback_state_change(
			std::bind(&lobby_main::game_filter_change_callback, this, _1));
	connect_signal_pre_key_press(
			*filter_text_,
			std::bind(&lobby_main::game_filter_keypress_callback, this, _5));

	chatbox_->room_window_open("lobby", true, false);
	chatbox_->active_window_changed();
	game_filter_reload();

	// Force first update to be directly.
	lobby_main::network_handler();
	lobby_update_timer_ = add_timer(
		game_config::lobby_network_timer, std::bind(&lobby_main::network_handler, this), true);

	// Set up Lua plugin context
	plugins_context_.reset(new plugins_context("Multiplayer Lobby"));

	plugins_context_->set_callback("join",    [&, this](const config&) {
		if(do_game_join(get_game_index_from_id(selected_game_id_), false)) {
			window.set_retval(JOIN);
		}
	}, true);

	plugins_context_->set_callback("observe", [&, this](const config&) {
		if(do_game_join(get_game_index_from_id(selected_game_id_), true)) {
			window.set_retval(OBSERVE);
		}
	}, true);

	plugins_context_->set_callback("create", [this, &window](const config&) { window.set_retval(CREATE); }, true);
	plugins_context_->set_callback("quit", [&window](const config&) { window.set_retval(window::CANCEL); }, false);

	plugins_context_->set_callback("chat", [this](const config& cfg) { chatbox_->send_chat_message(cfg["message"], false); }, true);
	plugins_context_->set_callback("select_game", [this](const config& cfg) {
		selected_game_id_ = cfg.has_attribute("id") ? cfg["id"].to_int() : lobby_info_.games()[cfg["index"].to_int()]->id;
	}, true);

	plugins_context_->set_accessor("game_list",   [this](const config&) { return lobby_info_.gamelist(); });
	plugins_context_->set_accessor("game_config", [this](const config&) { return game_config_; });
}