Skip to content

Commit

Permalink
Skip generating help sections for units without hide_help=no variations
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
irydacea committed Dec 22, 2014
1 parent f5cb10f commit 6fe72e8
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 7 deletions.
2 changes: 2 additions & 0 deletions changelog
Expand Up @@ -121,6 +121,8 @@ Version 1.13.0-dev:
* Fixed in-game help descriptions of default factions, using content from wiki
* Added automatically generated lists of races and alignments to the descriptions of factions
* Autogenerated Time of Day Schedule section
* Unit types that do not include any visible (hide_help=no) variations no
longer generate topic sections.
* Language and i18n:
* Updated translations: Czech, French, Galician, German, Greek, Hungarian,
Italian, Lithuanian, Portuguese, Russian, Scottish Gaelic, Slovak, Spanish,
Expand Down
2 changes: 2 additions & 0 deletions players_changelog
Expand Up @@ -44,6 +44,8 @@ Version 1.13.0-dev:

* Help Browser:
* Autogenerated Time of Day Schedule section
* Unit types that do not include any visible (hide_help=no) variations no
longer generate topic sections.

* Language and i18n:
* Updated translations: Czech, French, Galician, German, Greek, Hungarian,
Expand Down
2 changes: 1 addition & 1 deletion src/editor/controller/editor_controller.cpp
Expand Up @@ -1075,7 +1075,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");
}
Expand Down
2 changes: 1 addition & 1 deletion src/help/help.cpp
Expand Up @@ -88,7 +88,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);
}

help_manager::help_manager(const config *cfg) //, gamemap *_map)
Expand Down
8 changes: 4 additions & 4 deletions src/help/help_impl.cpp
Expand Up @@ -416,7 +416,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
Expand Down Expand Up @@ -639,7 +639,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;
Expand Down Expand Up @@ -785,7 +785,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;
Expand Down Expand Up @@ -830,7 +830,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);
Expand Down
2 changes: 1 addition & 1 deletion src/reports.cpp
Expand Up @@ -163,7 +163,7 @@ REPORT_GENERATOR(selected_unit_name, rc)
static config unit_type(const unit* u)
{
if (!u) return config();
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"
Expand Down
12 changes: 12 additions & 0 deletions src/unit_types.cpp
Expand Up @@ -1052,6 +1052,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.
*/
Expand Down
5 changes: 5 additions & 0 deletions src/unit_types.hpp
Expand Up @@ -288,6 +288,11 @@ class unit_type
*/
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.
Expand Down

0 comments on commit 6fe72e8

Please sign in to comment.