示例#1
0
static std::string format_stats(const unit& u)
{
	const std::string name = "<span size='large'>" + (!u.name().empty() ? u.name() : " ") + "</span>";
	std::string traits;

	BOOST_FOREACH(const std::string& trait, u.get_traits_list()) {
		traits += (traits.empty() ? "" : ", ") + trait;
	}

	if (traits.empty()) {
		traits = " ";
	}

	std::stringstream str;

	str << name << "\n";

	str << "<small>";

	str << "<span color='#f5e6c1'>" << u.type_name() << "</span>" << "\n";

	str << "Lvl " << u.level() << "\n";

	str << u.alignment() << "\n";

	str << traits << "\n";

	str << font::span_color(u.hp_color()) 
		<< _("HP: ") << u.hitpoints() << "/" << u.max_hitpoints() << "</span>" << "\n";
	str << font::span_color(u.xp_color()) 
		<< _("XP: ") << u.experience() << "/" << u.max_experience() << "</span>" << "\n";

	str << "</small>" << "\n";

	return str.str();
}
示例#2
0
void tunit_preview_pane::set_displayed_unit(const unit& u)
{
	// Sets the current type id for the profile button callback to use
	current_type_ = u.type_id();

	if(icon_type_) {
		std::string mods = u.image_mods();

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

		for(const std::string& overlay : u.overlays()) {
			mods += "~BLIT(" + overlay + ")";
		}

		mods += "~SCALE_INTO_SHARP(144,144)" + image_mods_;

		icon_type_->set_label(u.absolute_image() + mods);
	}

	if(label_name_) {
		std::string name;
		if(!u.name().empty()) {
			name = "<span size='large'>" + u.name() + "</span>" + "\n" + "<small><span color='#a69275'>" + u.type_name() + "</span></small>";
		} else {
			name = "<span size='large'>" + u.type_name() + "</span>\n";
		}

		label_name_->set_label(name);
		label_name_->set_use_markup(true);
	}

	if(label_level_) {
		std::string l_str = vgettext("Lvl $lvl", {{"lvl", std::to_string(u.level())}});

		label_level_->set_label("<b>" + l_str + "</b>");
		label_level_->set_use_markup(true);
	}

	if(icon_race_) {
		icon_race_->set_label("icons/unit-groups/race_" + u.race()->id() + "_30.png");
		icon_race_->set_tooltip(u.race()->name(u.gender()));
	}

	if(icon_alignment_) {
		const std::string& alignment_name = u.alignment().to_string();

		icon_alignment_->set_label("icons/alignments/alignment_" + alignment_name + "_30.png");
		icon_alignment_->set_tooltip(unit_type::alignment_description(
			u.alignment(),
			u.gender()));
	}

	if(label_details_minimal_) {
		std::stringstream str;

		const std::string name = "<span size='large'>" + (!u.name().empty() ? u.name() : " ") + "</span>";
		str << name << "\n";

		str << "<span color='#a69275'>" << u.type_name() << "</span>" << "\n";

		str << "Lvl " << u.level() << "\n";

		str << u.alignment() << "\n";

		str << utils::join(u.trait_names(), ", ") << "\n";

		str << font::span_color(u.hp_color())
			<< _("HP: ") << u.hitpoints() << "/" << u.max_hitpoints() << "</span>" << "\n";

		str << font::span_color(u.xp_color())
			<< _("XP: ") << u.experience() << "/" << u.max_experience() << "</span>";

		label_details_minimal_->set_label(str.str());
		label_details_minimal_->set_use_markup(true);
	}

	if(tree_details_) {
		std::stringstream str;
		str << "<small>";

		str << font::span_color(u.hp_color())
			<< "<b>" << _("HP: ") << "</b>" << u.hitpoints() << "/" << u.max_hitpoints() << "</span>" << " | ";

		str << font::span_color(u.xp_color())
			<< "<b>" << _("XP: ") << "</b>" << u.experience() << "/" << u.max_experience() << "</span>" << " | ";

		str << "<b>" << _("MP: ") << "</b>"
			<< u.movement_left() << "/" << u.total_movement();

		str << "</small>";

		tree_details_->clear();

		add_name_tree_node(
			tree_details_->get_root_node(),
			"item",
			str.str()
		);

		if (!u.trait_names().empty()) {
			auto& header_node = add_name_tree_node(
				tree_details_->get_root_node(),
				"header",
				"<b>" + _("Traits") + "</b>"
			);

			assert(u.trait_names().size() == u.trait_descriptions().size());
			for (size_t i = 0; i < u.trait_names().size(); ++i) {
				add_name_tree_node(
					header_node,
					"item",
					u.trait_names()[i],
					u.trait_descriptions()[i]
				);
			}
		}
		if (!u.get_ability_list().empty()) {
			auto& header_node = add_name_tree_node(
				tree_details_->get_root_node(),
				"header",
				"<b>" + _("Abilities") + "</b>"
			);

			for (const auto& ab : u.ability_tooltips()) {
				add_name_tree_node(
					header_node,
					"item",
					std::get<1>(ab),
					std::get<2>(ab)
				);
			}
		}
		print_attack_details(u.attacks(), tree_details_->get_root_node());
	}
}