Enhanced formatting for ability / weapon special tooltips.

With this change, there is no longer a need to include the name of the
ability/special as the first line of the description, so this practice
is deprecated.
This commit is contained in:
J. Tyne 2012-10-25 21:10:41 +00:00
parent 75a3f1b731
commit a824a260f3
3 changed files with 74 additions and 33 deletions

View file

@ -1120,15 +1120,7 @@ std::vector<topic> generate_weapon_special_topics(const bool sort_generated)
std::vector<std::pair<t_string, t_string> > specials = it->special_tooltips();
for ( size_t i = 0; i != specials.size(); ++i )
{
if ( special_description.find(specials[i].first) == special_description.end() ) {
std::string description = specials[i].second;
const size_t colon_pos = description.find(':');
if (colon_pos != std::string::npos) {
// Remove the first colon and the following newline.
description.erase(0, colon_pos + 2);
}
special_description[specials[i].first] = description;
}
special_description.insert(std::make_pair(specials[i].first, specials[i].second));
if (!type.hide_help()) {
//add a link in the list of units having this special
@ -1163,6 +1155,35 @@ std::vector<topic> generate_weapon_special_topics(const bool sort_generated)
return topics;
}
namespace {
/**
* Strips the name of an ability/special from the description.
* This is legacy support, introduced for version 1.11.1.
* Can (should) be removed post-1.12.
*/
t_string legacy_description(const t_string & description)
{
// The legacy format is name + ':' + newline + description.
// We identify this by the colon.
std::string revision = description.str();
const size_t colon_pos = revision.find(':');
if ( colon_pos != std::string::npos )
// Make sure this colon ends the first line.
if ( revision.find('\n') == colon_pos + 1 ) {
//@deprecated Format changed for 1.11.1.
lg::wml_error << "Descriptions should no longer include the name as the first line.\n";
// Remove the first line.
revision.erase(0, colon_pos + 2);
return t_string(revision);
}
// No adaptation needed.
return description;
}
}
std::vector<topic> generate_ability_topics(const bool sort_generated)
{
std::vector<topic> topics;
@ -1190,21 +1211,10 @@ std::vector<topic> generate_ability_topics(const bool sort_generated)
std::vector<t_string> const& desc_vec = *desc_vecs[i];
for(size_t j=0; j < abil_vec.size(); ++j) {
t_string const& abil_name = abil_vec[j];
if (ability_description.find(abil_name) == ability_description.end()) {
//new ability, generate a descripion
if(j >= desc_vec.size()) {
ability_description[abil_name] = "";
} else {
std::string const& abil_desc = desc_vec[j];
const size_t colon_pos = abil_desc.find(':');
if(colon_pos != std::string::npos && colon_pos + 1 < abil_desc.length()) {
// Remove the first colon and the following newline.
ability_description[abil_name] = abil_desc.substr(colon_pos + 2);
} else {
ability_description[abil_name] = abil_desc;
}
}
}
std::string const abil_desc =
j >= desc_vec.size() ? "" : legacy_description(desc_vec[j]).str();
ability_description.insert(std::make_pair(abil_name, abil_desc));
if (!type.hide_help()) {
//add a link in the list of units having this ability

View file

@ -377,8 +377,10 @@ static config unit_abilities(const unit* u)
if ( i + 1 != abilities_size )
str << ", ";
tooltip << (active[i] ? _("Ability: ") : _("Ability (inactive): ") )
<< description;
tooltip << _("Ability: ") << "<b>" << display_name << "</b>";
if ( !active[i] )
tooltip << "<i>" << _(" (inactive)") << "</i>";
tooltip << '\n' << description;
add_text(res, str.str(), tooltip.str(), "ability_" + base_name);
}
@ -733,9 +735,10 @@ static int attack_info(const attack_type &at, config &res, const unit &u, const
str << span_color(details_color) << " " << name << naps << '\n';
std::string help_page = "weaponspecial_" + name.base_str();
//FIXME pull out special's name from description
tooltip << (active[i] ? _("Weapon special: ") : _("Weapon special (inactive): ") )
<< description << '\n';
tooltip << _("Weapon special: ") << "<b>" << name << "</b>";
if ( !active[i] )
tooltip << "<i>" << _(" (inactive)") << "</i>";
tooltip << '\n' << description;
add_text(res, flush(str), flush(tooltip), help_page);
}

View file

@ -214,6 +214,34 @@ namespace {
gender == unit_race::MALE ? male_key : female_key,
default_key);
}
/**
* Strips the name of an ability/special from the description.
* This is legacy support, introduced for version 1.11.1.
* Can (should) be removed post-1.12.
*/
t_string legacy_description(const t_string & description)
{
// The legacy format is name + ':' + newline + description.
// We identify this by the colon.
std::string revision = description.str();
const size_t colon_pos = revision.find(':');
if ( colon_pos != std::string::npos )
// Make sure this colon ends the first line.
if ( revision.find('\n') == colon_pos + 1 ) {
//@deprecated Format changed for 1.11.1.
// Not logging this here because it would spam the screen,
// and these will have been caught when the help was generated.
//lg::wml_error << "Descriptions should no longer include the name as the first line.\n";
// Remove the first line.
revision.erase(0, colon_pos + 2);
return t_string(revision);
}
// No adaptation needed.
return description;
}
}
/**
@ -245,7 +273,7 @@ std::vector<boost::tuple<t_string,t_string,t_string> > unit::ability_tooltips(st
res.push_back(boost::make_tuple(
ab.cfg["name"].t_str(),
name,
ab.cfg["description"].t_str()));
legacy_description(ab.cfg["description"].t_str()) ));
if ( active_list )
active_list->push_back(true);
}
@ -263,7 +291,7 @@ std::vector<boost::tuple<t_string,t_string,t_string> > unit::ability_tooltips(st
res.push_back(boost::make_tuple(
default_value(ab.cfg, "name_inactive", "name").t_str(),
name,
default_value(ab.cfg, "description_inactive", "description").t_str()));
legacy_description(default_value(ab.cfg, "description_inactive", "description").t_str()) ));
active_list->push_back(false);
}
}
@ -582,7 +610,7 @@ std::vector<std::pair<t_string, t_string> > attack_type::special_tooltips(
if ( !active_list || special_active(sp.cfg, AFFECT_EITHER) ) {
const t_string &name = sp.cfg["name"];
if (!name.empty()) {
res.push_back(std::make_pair(name, sp.cfg["description"].t_str()));
res.push_back(std::make_pair(name, legacy_description(sp.cfg["description"].t_str()) ));
if ( active_list )
active_list->push_back(true);
}
@ -590,7 +618,7 @@ std::vector<std::pair<t_string, t_string> > attack_type::special_tooltips(
t_string const &name = default_value(sp.cfg, "name_inactive", "name").t_str();
if (!name.empty()) {
res.push_back(std::make_pair(
name, default_value(sp.cfg, "description_inactive", "description").t_str()));
name, legacy_description(default_value(sp.cfg, "description_inactive", "description").t_str()) ));
active_list->push_back(false);
}
}