Skip generating help sections for units without hide_help=no variations

This fixes many instances of unit types with "technical" variations in
my campaign After the Storm being assigned help sections of their own.

Required adding a new method to unit_type that's actually cheaper than
checking for variations().empty(), as it doesn't involve allocating new
objects.
This commit is contained in:
Ignacio R. Morelle 2014-12-22 19:55:31 -03:00
parent 6221971368
commit be0c1a36db
8 changed files with 33 additions and 9 deletions

View file

@ -13,6 +13,9 @@ Version 1.12.0+dev:
* Editor:
* Fixed falcon race missing an icon due to having incorrectly-named image
files.
* Help browser:
* Unit types that do not include any visible (hide_help=no) variations no
longer generate topic sections.
* Language and i18n:
* Updated translations: Portuguese
* Multiplayer:

View file

@ -7,6 +7,10 @@ Version 1.12.0+dev:
* Liberty:
* Fixed possibility of no viable routes around guards in 'Hide and Seek'.
* Help browser:
* Unit types that do not include any visible (hide_help=no) variations no
longer generate topic sections.
* Language and i18n:
* Updated translations: Portuguese.

View file

@ -1389,7 +1389,7 @@ void show_unit_description(const unit_type &t)
if (use_variation)
help::show_variation_help(*display::get_singleton(), t.id(), var_id, hide_help);
else
help::show_unit_help(*display::get_singleton(), t.id(), !t.variations().empty(), hide_help);
help::show_unit_help(*display::get_singleton(), t.id(), t.show_variations_in_help(), hide_help);
}
static network::connection network_data_dialog(display& disp, const std::string& msg, config& cfg, network::connection connection_num, network::statistics (*get_stats)(network::connection handle))

View file

@ -1046,7 +1046,7 @@ void editor_controller::unit_description()
const unit_map & units = context_manager_->get_map_context().get_units();
const unit_map::const_unit_iterator un = units.find(loc);
if(un != units.end()) {
help::show_unit_help(*gui_, un->type_id(), !un->type().variations().empty(), false);
help::show_unit_help(*gui_, un->type_id(), un->type().show_variations_in_help(), false);
} else {
help::show_help(*gui_, "..units");
}

View file

@ -1134,7 +1134,7 @@ std::vector<topic> generate_weapon_special_topics(const bool sort_generated)
//add a link in the list of units having this special
std::string type_name = type.type_name();
//check for variations (walking corpse/soulless etc)
const std::string section_prefix = type.variations().empty() ? "" : "..";
const std::string section_prefix = type.show_variations_in_help() ? ".." : "";
std::string ref_id = section_prefix + unit_prefix + type.id();
//we put the translated name at the beginning of the hyperlink,
//so the automatic alphabetic sorting of std::set can use it
@ -1445,7 +1445,7 @@ public:
std::string lang_unit = type->type_name();
std::string ref_id;
if (description_type(*type) == FULL_DESCRIPTION) {
const std::string section_prefix = type->variations().empty() ? "" : "..";
const std::string section_prefix = type->show_variations_in_help() ? ".." : "";
ref_id = section_prefix + unit_prefix + type->id();
} else {
ref_id = unknown_unit_topic;
@ -1471,7 +1471,7 @@ public:
first = false;
}
const unit_type* base_type = unit_types.find(base_id, unit_type::HELP_INDEXED);
const std::string section_prefix = base_type->variations().empty() ? "" : "..";
const std::string section_prefix = base_type->show_variations_in_help() ? ".." : "";
ss << make_link(base_type->type_name(), section_prefix + unit_prefix + base_id) << "\n";
}
}
@ -1831,7 +1831,7 @@ std::string make_unit_link(const std::string& type_id)
std::string name = type->type_name();
std::string ref_id;
if (description_type(*type) == FULL_DESCRIPTION) {
const std::string section_prefix = type->variations().empty() ? "" : "..";
const std::string section_prefix = type->show_variations_in_help() ? ".." : "";
ref_id = section_prefix + unit_prefix + type->id();
} else {
ref_id = unknown_unit_topic;
@ -1953,7 +1953,7 @@ void generate_unit_sections(const config* /*help_cfg*/, section& sec, int level,
if (type.race_id() != race)
continue;
if (type.variations().empty())
if (!type.show_variations_in_help())
continue;
section base_unit;
@ -1997,7 +1997,7 @@ std::vector<topic> generate_unit_topics(const bool sort_generated, const std::st
continue;
const std::string type_name = type.type_name();
const std::string real_prefix = type.variations().empty() ? "" : "..";
const std::string real_prefix = type.show_variations_in_help() ? ".." : "";
const std::string ref_id = hidden_symbol(type.hide_help()) + real_prefix + unit_prefix + type.id();
topic unit_topic(type_name, ref_id, "");
unit_topic.text = new unit_topic_generator(type);

View file

@ -174,7 +174,7 @@ REPORT_GENERATOR(selected_unit_name)
static config unit_type(const unit* u)
{
if (!u) return report();
std::string has_variations_prefix = (!u->type().variations().empty() ? ".." : "");
std::string has_variations_prefix = (u->type().show_variations_in_help() ? ".." : "");
std::ostringstream str, tooltip;
str << u->type_name();
tooltip << _("Type: ") << "<b>" << u->type_name() << "</b>\n"

View file

@ -1068,6 +1068,18 @@ bool unit_type::has_variation(const std::string& variation_id) const
return variations_.find(variation_id) != variations_.end();
}
bool unit_type::show_variations_in_help() const
{
BOOST_FOREACH(const variations_map::value_type &val, variations_) {
assert(val.second != NULL);
if (!val.second->hide_help()) {
return true;
}
}
return false;
}
/**
* Generates (and returns) a trimmed config suitable for use with units.
*/

View file

@ -260,6 +260,11 @@ public:
*/
bool has_variation(const std::string& variation_id) const;
/**
* Whether the unit type has at least one help-visible variation.
*/
bool show_variations_in_help() const;
/// Returns the ID of this type's race without the need to build the type.
std::string race_id() const { return cfg_["race"]; } //race_->id(); }
/// Never returns NULL, but may point to the null race.