Пример #1
0
void tbrowse::add_row(twindow& window, tlistbox& list, const std::string& name, bool dir)
{
	std::stringstream ss;

	string_map list_item;
	std::map<std::string, string_map> list_item_item;

	list_item["label"] = "misc/open.png~SCALE(32, 32)";
	list_item_item.insert(std::make_pair("open", list_item));

	ss << tintegrate::generate_img(get_browse_icon(dir) + "~SCALE(24, 24)") << name;
	list_item["label"] = ss.str();
	list_item_item.insert(std::make_pair("name", list_item));

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

	list_item["label"] = dir? null_str: "---";
	list_item_item.insert(std::make_pair("size", list_item));

	list.add_row(list_item_item);

	int index = list.get_item_count() - 1;
	ttoggle_panel* panel = dynamic_cast<ttoggle_panel*>(list.get_row_panel(index));

	tbutton* button = find_widget<tbutton>(panel, "open", false, true);
	if (dir) {
		connect_signal_mouse_left_click(
			*button
			, boost::bind(
				&tbrowse::open
				, this
				, boost::ref(window)
				, _3
				, _4
				, (int)true
				, (int)index));

		panel->connect_signal<event::LEFT_BUTTON_DOUBLE_CLICK>(boost::bind(
				  &tbrowse::open
				, this
				, boost::ref(window)
				, _3
				, _4
				, (int)true
				, (int)index)
			, event::tdispatcher::back_pre_child);

	} else {
		button->set_visible(twidget::HIDDEN);
		button->set_active(false);
	}
}
Пример #2
0
void tside_report::fill_table(tlistbox& list, int catalog)
{
	for (std::vector<artifical*>::const_iterator it = candidate_cities_.begin(); it != candidate_cities_.end(); ++ it) {
		artifical& city = **it;
		std::stringstream str;
		
		/*** Add list item ***/
		string_map table_item;
		std::map<std::string, string_map> table_item_item;

		str.str("");
		str << city.name();
		str << "(Lv";
		str << tintegrate::generate_format(city.level(), "green");
		str << ")";
		table_item["label"] = str.str();
		table_item_item.insert(std::make_pair("name", table_item));

		if (catalog == STATUS_PAGE) {
			str.str("");
			if (city.hitpoints() < city.max_hitpoints() / 2) {
				str << tintegrate::generate_format(city.hitpoints(), "red");
			} else if (city.hitpoints() < city.max_hitpoints()) {
				str << tintegrate::generate_format(city.hitpoints(), "yellow");
			} else {
				str << city.hitpoints();
			}
			str << "/" << city.max_hitpoints();
			table_item["label"] = str.str();
			table_item_item.insert(std::make_pair("hp", table_item));

			str.str("");
			str << city.experience() << "/";
			if (city.can_advance()) {
				str << city.max_experience();
			} else {
				str << "-";
			}
			table_item["label"] = str.str();
			table_item_item.insert(std::make_pair("xp", table_item));

			str.str("");
			str << tintegrate::generate_format(city.fresh_heros().size(), "green");
			str << "/";
			str << tintegrate::generate_format(city.finish_heros().size(), "red");
			str << "/";
			str << tintegrate::generate_format(city.wander_heros().size(), "yellow");
			table_item["label"] = str.str();
			table_item_item.insert(std::make_pair("hero", table_item));

			str.str("");
			str << tintegrate::generate_format(city.reside_troops().size(), "yellow");
			str << "/";
			str << city.field_troops().size();
			table_item["label"] = str.str();
			table_item_item.insert(std::make_pair("troop", table_item));

			str.str("");
			str << tintegrate::generate_format(city.total_gold_income(current_team_.market_increase_), "yellow");
			str << "/";
			str << tintegrate::generate_format(city.total_technology_income(current_team_.technology_increase_), "green");
			table_item["label"] = str.str();
			table_item_item.insert(std::make_pair("income", table_item));

			size_t built = 0;
			size_t building = 0;
			const std::vector<map_location>& ea = city.economy_area();
			for (std::vector<map_location>::const_iterator it2 = ea.begin(); it2 != ea.end(); ++ it2) {
				unit* u = units_.find_unit(*it2);
				if (!u || !hero::is_ea_artifical(u->type()->master())) {
					continue;
				}
				if (u->get_state(ustate_tag::BUILDING)) {
					building ++;
				} else {
					built ++;
				}
			}
			str.str("");
			str << tintegrate::generate_format(building + built, building? "yellow": "green");
			str << "/";
			if (building + built != ea.size()) {
				str << tintegrate::generate_format(ea.size(), "red");
			} else {
				str << ea.size();
			}
			table_item["label"] = str.str();
			table_item_item.insert(std::make_pair("ea", table_item));
		}
		list.add_row(table_item_item);

		unsigned hero_index = list.get_item_count() - 1;
		twidget* grid_ptr = list.get_row_panel(hero_index);
		ttoggle_panel* toggle = dynamic_cast<ttoggle_panel*>(grid_ptr);
		toggle->set_data(hero_index);
	}
}