void tunit_create::pre_show(CVideo& /*video*/, twindow& window)
{
	ttoggle_button& male_toggle = find_widget<ttoggle_button>(
			&window, "male_toggle", false);
	ttoggle_button& female_toggle = find_widget<ttoggle_button>(
			&window, "female_toggle", false);
	ttoggle_button& namegen_toggle = find_widget<ttoggle_button>(
			&window, "namegen_toggle", false);
	tlistbox& list = find_widget<tlistbox>(&window, "unit_type_list", false);

	male_toggle.set_callback_state_change(
		dialog_callback<tunit_create, &tunit_create::gender_toggle_callback>
	);
	female_toggle.set_callback_state_change(
		dialog_callback<tunit_create, &tunit_create::gender_toggle_callback>
	);
	update_male_female_toggles(male_toggle, female_toggle, gender_);
	namegen_toggle.set_value(generate_name_);
	list.clear();

	// We use this container to "map" unit_type ids to list subscripts
	// later, so it ought to be empty before proceeding.
	type_ids_.clear();

	std::vector< std::string > type_labels, race_labels;

	foreach (const unit_type_data::unit_type_map::value_type &i, unit_types.types())
	{
		unit_types.find(i.first, unit_type::HELP_INDEX);

		// And so we map an unit_type id to a list subscript. Ugh.
		type_ids_.push_back(i.first);

		std::string race_label;

		if (const unit_race *r = unit_types.find_race(i.second.race())) {
			race_label = r->plural_name();
		}

		std::map< std::string, string_map > row_data;
		string_map column;

		column["label"] = i.second.type_name();
		row_data.insert(std::make_pair("unit_type", column));
		column["label"] = race_label;
		row_data.insert(std::make_pair("race", column));

		list.add_row(row_data);

		// Select the previous choice, if any.
		if(choice_.empty() != true && choice_ == i.first) {
			list.select_row(list.get_item_count() - 1);
		}
	}

	if(type_ids_.empty()) {
		ERR_GUI_G << "no unit types found for unit create dialog; not good\n";
	}
}
示例#2
0
void tunit_create::pre_show(CVideo& /*video*/, twindow& window)
{
	ttoggle_button& male_toggle
			= find_widget<ttoggle_button>(&window, "male_toggle", false);
	ttoggle_button& female_toggle
			= find_widget<ttoggle_button>(&window, "female_toggle", false);
	tlistbox& list = find_widget<tlistbox>(&window, "unit_type_list", false);

	male_toggle.set_callback_state_change(
			dialog_callback<tunit_create,
							&tunit_create::gender_toggle_callback>);
	female_toggle.set_callback_state_change(
			dialog_callback<tunit_create,
							&tunit_create::gender_toggle_callback>);
	update_male_female_toggles(male_toggle, female_toggle, gender_);
	list.clear();

	// We use this container to "map" unit_type ids to list subscripts
	// later, so it ought to be empty before proceeding.
	type_ids_.clear();

	FOREACH(const AUTO & i, unit_types.types())
	{
		if(i.second.do_not_list())
			continue;

		// Make sure this unit type is built with the data we need.
		unit_types.build_unit_type(i.second, unit_type::HELP_INDEXED);

		// And so we map an unit_type id to a list subscript. Ugh.
		type_ids_.push_back(i.first);

		std::map<std::string, string_map> row_data;
		string_map column;

		column["label"] = i.second.type_name();
		row_data.insert(std::make_pair("unit_type", column));
		column["label"] = i.second.race()->plural_name();
		row_data.insert(std::make_pair("race", column));

		list.add_row(row_data);

		// Select the previous choice, if any.
		if(choice_.empty() != true && choice_ == i.first) {
			list.select_row(list.get_item_count() - 1);
		}
	}

	if(type_ids_.empty()) {
		ERR_GUI_G << "no unit types found for unit create dialog; not good"
				  << std::endl;
	}
}
示例#3
0
void tunit_create::gender_toggle_callback(twindow& window)
{
	ttoggle_button& male_toggle = find_widget<ttoggle_button>(
			&window, "male_toggle", false);
	ttoggle_button& female_toggle = find_widget<ttoggle_button>(
			&window, "female_toggle", false);

	// Ye olde ugly hack for the lack of radio buttons.

	if(gender_ == unit_race::MALE) {
		gender_ = female_toggle.get_value() ? unit_race::FEMALE : unit_race::MALE;
	}
	else {
		gender_ = male_toggle.get_value() ? unit_race::MALE : unit_race::FEMALE;
	}

	update_male_female_toggles(male_toggle, female_toggle, gender_);
}
示例#4
0
void tunit_create::pre_show(CVideo& /*video*/, twindow& window)
{
	ttoggle_button& male_toggle
			= find_widget<ttoggle_button>(&window, "male_toggle", false);
	ttoggle_button& female_toggle
			= find_widget<ttoggle_button>(&window, "female_toggle", false);
	tlistbox& list = find_widget<tlistbox>(&window, "unit_type_list", false);

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

	filter->set_text_changed_callback(
			boost::bind(&tunit_create::filter_text_changed, this, _1, _2));

#ifdef GUI2_EXPERIMENTAL_LISTBOX
	connect_signal_notify_modified(*list,
								   boost::bind(&tunit_create::list_item_clicked,
											   *this,
											   boost::ref(window)));
#else
	list.set_callback_value_change(
			dialog_callback<tunit_create, &tunit_create::list_item_clicked>);
#endif

	window.keyboard_capture(&list);

	connect_signal_mouse_left_click(
			find_widget<tbutton>(&window, "type_profile", false),
			boost::bind(&tunit_create::profile_button_callback,
						this,
						boost::ref(window)));

	male_toggle.set_callback_state_change(
			dialog_callback<tunit_create, &tunit_create::gender_toggle_callback>);

	female_toggle.set_callback_state_change(
			dialog_callback<tunit_create, &tunit_create::gender_toggle_callback>);

	update_male_female_toggles(male_toggle, female_toggle, gender_);

	list.clear();

	FOREACH(const AUTO & i, unit_types.types())
	{
		if(i.second.do_not_list())
			continue;

		// Make sure this unit type is built with the data we need.
		unit_types.build_unit_type(i.second, unit_type::WITHOUT_ANIMATIONS);

		units_.push_back(&i.second);

		std::map<std::string, string_map> row_data;
		string_map column;

		column["label"] = units_.back()->race()->plural_name();
		row_data.insert(std::make_pair("race", column));
		column["label"] = units_.back()->type_name();
		row_data.insert(std::make_pair("unit_type", column));

		list.add_row(row_data);

		// Select the previous choice, if any.
		if(choice_.empty() != true && choice_ == i.first) {
			list.select_row(list.get_item_count() - 1);
		}
	}

	if(units_.empty()) {
		ERR_GUI_G << "no unit types found for unit create dialog; not good"
				  << std::endl;
	}

	std::vector<tgenerator_::torder_func> order_funcs(2);
	order_funcs[0] = boost::bind(&tunit_create::compare_race, this, _1, _2);
	order_funcs[1] = boost::bind(&tunit_create::compare_race_rev, this, _1, _2);
	list.set_column_order(0, order_funcs);
	order_funcs[0] = boost::bind(&tunit_create::compare_type, this, _1, _2);
	order_funcs[1] = boost::bind(&tunit_create::compare_type_rev, this, _1, _2);
	list.set_column_order(1, order_funcs);

	list_item_clicked(window);
}