Fix bug #8624 (unit_help doesn't work)
Now unit_help=true hides if in all the help, but works with "unit description" context-menu action and little "profile" button from recruit/recall. The hyperlinks in different pages are also hidden and the advancement links send to the "unknown unit" page (like unencountered units). Still the problem of visible race section, ability and weapon special if only this unit have it. I will check how to hide at least race (maybe others too but less important). + done some other cleaning in help code, but others need to be done.
This commit is contained in:
parent
a18777bca9
commit
7274be6249
4 changed files with 78 additions and 110 deletions
|
@ -830,13 +830,6 @@ void unit_preview_pane::draw_contents()
|
|||
}
|
||||
}
|
||||
|
||||
void unit_preview_pane::process_event()
|
||||
{
|
||||
if(map_ != NULL && details_button_.pressed() && index_ >= 0 && index_ < int(size())) {
|
||||
help::show_help(disp_, get_profile());
|
||||
}
|
||||
}
|
||||
|
||||
units_list_preview_pane::units_list_preview_pane(game_display& disp, const gamemap* map, const unit& u, TYPE type, bool on_left_side)
|
||||
: unit_preview_pane(disp, map, type, on_left_side),
|
||||
units_(&unit_store_)
|
||||
|
@ -890,10 +883,11 @@ const unit_preview_pane::details units_list_preview_pane::get_details() const
|
|||
return det;
|
||||
}
|
||||
|
||||
const std::string units_list_preview_pane::get_profile() const
|
||||
void units_list_preview_pane::process_event()
|
||||
{
|
||||
unit& u = (*units_)[index_];
|
||||
return "unit_" + u.id();
|
||||
if(map_ != NULL && details_button_.pressed() && index_ >= 0 && index_ < int(size())) {
|
||||
show_unit_description(disp_, (*units_)[index_]);
|
||||
}
|
||||
}
|
||||
|
||||
unit_types_preview_pane::unit_types_preview_pane(game_display& disp, const gamemap* map, std::vector<const unit_type*>& unit_types, int side, TYPE type, bool on_left_side)
|
||||
|
@ -968,16 +962,29 @@ const unit_types_preview_pane::details unit_types_preview_pane::get_details() co
|
|||
return det;
|
||||
}
|
||||
|
||||
const std::string unit_types_preview_pane::get_profile() const
|
||||
void unit_types_preview_pane::process_event()
|
||||
{
|
||||
const unit_type* t = (*unit_types_)[index_];
|
||||
return "unit_" + t->id();
|
||||
if(map_ != NULL && details_button_.pressed() && index_ >= 0 && index_ < int(size())) {
|
||||
const unit_type* type = (*unit_types_)[index_];
|
||||
if (type != NULL)
|
||||
show_unit_description(disp_, *type);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void show_unit_description(game_display &disp, const unit& u)
|
||||
{
|
||||
help::show_help(disp, "unit_" + u.id());
|
||||
const unit_type* t = u.type();
|
||||
if (t != NULL)
|
||||
show_unit_description(disp, *t);
|
||||
else
|
||||
// can't find type, try open the id page to have feedback and unit error page
|
||||
help::show_unit_help(disp, u.id());
|
||||
}
|
||||
|
||||
void show_unit_description(game_display &disp, const unit_type& t)
|
||||
{
|
||||
help::show_unit_help(disp, t.id(), t.hide_help());
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -91,16 +91,15 @@ protected:
|
|||
game_display& disp_;
|
||||
const gamemap* map_;
|
||||
int index_;
|
||||
gui::button details_button_;
|
||||
|
||||
private:
|
||||
virtual size_t size() const = 0;
|
||||
virtual const details get_details() const = 0;
|
||||
virtual const std::string get_profile() const = 0;
|
||||
virtual void process_event() = 0;
|
||||
|
||||
void draw_contents();
|
||||
void process_event();
|
||||
|
||||
gui::button details_button_;
|
||||
bool left_;
|
||||
bool weapons_;
|
||||
};
|
||||
|
@ -114,7 +113,7 @@ public:
|
|||
private:
|
||||
size_t size() const;
|
||||
const details get_details() const;
|
||||
const std::string get_profile() const;
|
||||
void process_event();
|
||||
|
||||
std::vector<unit>* units_;
|
||||
std::vector<unit> unit_store_;
|
||||
|
@ -129,13 +128,14 @@ public:
|
|||
private:
|
||||
size_t size() const;
|
||||
const details get_details() const;
|
||||
const std::string get_profile() const;
|
||||
void process_event();
|
||||
|
||||
std::vector<const unit_type*>* unit_types_;
|
||||
int side_;
|
||||
};
|
||||
|
||||
|
||||
void show_unit_description(game_display &disp, const unit_type& t);
|
||||
void show_unit_description(game_display &disp, const unit& u);
|
||||
|
||||
|
||||
|
|
139
src/help.cpp
139
src/help.cpp
|
@ -491,7 +491,6 @@ enum UNIT_DESCRIPTION_TYPE {FULL_DESCRIPTION, NO_DESCRIPTION, NON_REVEALING_DESC
|
|||
/// about units that should not be shown, for example due to not being
|
||||
/// encountered.
|
||||
static UNIT_DESCRIPTION_TYPE description_type(const unit_type &type);
|
||||
static std::vector<topic> generate_race_topics(const bool);
|
||||
static std::vector<topic> generate_ability_topics(const bool);
|
||||
static std::vector<topic> generate_weapon_special_topics(const bool);
|
||||
|
||||
|
@ -582,6 +581,7 @@ namespace {
|
|||
// The topic to open by default when opening the help dialog.
|
||||
const std::string default_show_topic = "introduction_topic";
|
||||
const std::string unknown_unit_topic = ".unknown_unit";
|
||||
const std::string unit_prefix = "unit_";
|
||||
}
|
||||
|
||||
/// Return true if the id is valid for user defined topics and
|
||||
|
@ -591,7 +591,7 @@ static bool is_valid_id(const std::string &id) {
|
|||
if (id == "toplevel") {
|
||||
return false;
|
||||
}
|
||||
if (id.find("unit_") == 0) {
|
||||
if (id.find(unit_prefix) == 0 || id.find("." + unit_prefix) == 0) {
|
||||
return false;
|
||||
}
|
||||
if (id.find("ability_") == 0) {
|
||||
|
@ -968,9 +968,7 @@ std::vector<topic> generate_topics(const bool sort_generated,const std::string &
|
|||
return res;
|
||||
}
|
||||
|
||||
if (generator == "races") {
|
||||
res = generate_race_topics(sort_generated);
|
||||
} else if (generator == "abilities") {
|
||||
if (generator == "abilities") {
|
||||
res = generate_ability_topics(sort_generated);
|
||||
} else if (generator == "weapon_specials") {
|
||||
res = generate_weapon_special_topics(sort_generated);
|
||||
|
@ -1083,13 +1081,15 @@ std::vector<topic> generate_weapon_special_topics(const bool sort_generated)
|
|||
special_description[special] = description;
|
||||
}
|
||||
|
||||
//add a link in the list of units having this special
|
||||
std::string lang_name = type.language_name();
|
||||
std::string ref_id = std::string("unit_") + type.id();
|
||||
//we put the translated name at the beginning of the hyperlink,
|
||||
//so the automatic alphabetic sorting of std::set can use it
|
||||
std::string link = "<ref>text='" + escape(lang_name) + "' dst='" + escape(ref_id) + "'</ref>";
|
||||
special_units[special].insert(link);
|
||||
if (!type.hide_help()) {
|
||||
//add a link in the list of units having this special
|
||||
std::string lang_name = type.language_name();
|
||||
std::string ref_id = 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
|
||||
std::string link = "<ref>text='" + escape(lang_name) + "' dst='" + escape(ref_id) + "'</ref>";
|
||||
special_units[special].insert(link);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1115,62 +1115,6 @@ std::vector<topic> generate_weapon_special_topics(const bool sort_generated)
|
|||
return topics;
|
||||
}
|
||||
|
||||
std::vector<topic> generate_race_topics(const bool sort_generated)
|
||||
{
|
||||
std::vector<topic> topics;
|
||||
if (game_info == NULL) {
|
||||
return topics;
|
||||
}
|
||||
std::map<std::string, std::set<std::string> > race_units;
|
||||
// Look through all the unit types, check if a unit of this type
|
||||
// should have a full description, if so, add this race for display.
|
||||
for(game_data::unit_type_map::const_iterator i = game_info->unit_types.begin();
|
||||
i != game_info->unit_types.end(); ++i) {
|
||||
const unit_type &type = (*i).second;
|
||||
if (description_type(type) == FULL_DESCRIPTION) {
|
||||
const std::string& race = type.race();
|
||||
|
||||
//add a link in the list of units of this race
|
||||
std::string lang_name = type.language_name();
|
||||
std::string ref_id = std::string("unit_") + type.id();
|
||||
//we put the translated name at the beginning of the hyperlink,
|
||||
//so the automatic alphabetic sorting of std::set can use it
|
||||
std::string link = "<ref>text='" + escape(lang_name) + "' dst='" + escape(ref_id) + "'</ref>";
|
||||
race_units[race].insert(link);
|
||||
}
|
||||
}
|
||||
|
||||
for (std::map<std::string, std::set<std::string> >::iterator r = race_units.begin(); r != race_units.end(); r++) {
|
||||
std::string id = "race_" + r->first;
|
||||
std::string name;
|
||||
std::string description;
|
||||
|
||||
const race_map::const_iterator race_it = game_info->races.find(r->first);
|
||||
if (race_it != game_info->races.end()) {
|
||||
name = race_it->second.plural_name();
|
||||
description = race_it->second.description();
|
||||
// if (description.empty()) description = _("No description Available");
|
||||
} else {
|
||||
name = _ ("race^Miscellaneous");
|
||||
// description = _("Here put the description of the Miscellaneous race");
|
||||
}
|
||||
|
||||
std::stringstream text;
|
||||
text << description;
|
||||
text << "\n\n" << _("Units of this race:") << "\n";
|
||||
std::set<std::string>& units = race_units[r->first];
|
||||
for (std::set<std::string>::iterator u = units.begin(); u != units.end();u++) {
|
||||
text << (*u) << "\n";
|
||||
}
|
||||
|
||||
topics.push_back( topic(name, id, text.str()) );
|
||||
}
|
||||
|
||||
if (sort_generated)
|
||||
std::sort(topics.begin(), topics.end(), title_less());
|
||||
return topics;
|
||||
}
|
||||
|
||||
std::vector<topic> generate_ability_topics(const bool sort_generated)
|
||||
{
|
||||
std::vector<topic> topics;
|
||||
|
@ -1207,13 +1151,15 @@ std::vector<topic> generate_ability_topics(const bool sort_generated)
|
|||
ability_description[*it] = description;
|
||||
}
|
||||
|
||||
//add a link in the list of units having this ability
|
||||
std::string lang_name = type.language_name();
|
||||
std::string ref_id = std::string("unit_") + type.id();
|
||||
//we put the translated name at the beginning of the hyperlink,
|
||||
//so the automatic alphabetic sorting of std::set can use it
|
||||
std::string link = "<ref>text='" + escape(lang_name) + "' dst='" + escape(ref_id) + "'</ref>";
|
||||
ability_units[*it].insert(link);
|
||||
if (!type.hide_help()) {
|
||||
//add a link in the list of units having this ability
|
||||
std::string lang_name = type.language_name();
|
||||
std::string ref_id = 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
|
||||
std::string link = "<ref>text='" + escape(lang_name) + "' dst='" + escape(ref_id) + "'</ref>";
|
||||
ability_units[*it].insert(link);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1299,8 +1245,8 @@ public:
|
|||
{
|
||||
std::string lang_unit = type->second.language_name();
|
||||
std::string ref_id;
|
||||
if (description_type(type->second) == FULL_DESCRIPTION) {
|
||||
ref_id = std::string("unit_") + type->second.id();
|
||||
if (description_type(type->second) == FULL_DESCRIPTION && !type->second.hide_help()) {
|
||||
ref_id = unit_prefix + type->second.id();
|
||||
} else {
|
||||
ref_id = unknown_unit_topic;
|
||||
lang_unit += " (?)";
|
||||
|
@ -1326,8 +1272,8 @@ public:
|
|||
if(type != game_info->unit_types.end()) {
|
||||
std::string lang_unit = type->second.language_name();
|
||||
std::string ref_id;
|
||||
if (description_type(type->second) == FULL_DESCRIPTION) {
|
||||
ref_id = std::string("unit_") + type->second.id();
|
||||
if (description_type(type->second) == FULL_DESCRIPTION && !type->second.hide_help()) {
|
||||
ref_id = unit_prefix + type->second.id();
|
||||
} else {
|
||||
ref_id = unknown_unit_topic;
|
||||
lang_unit += " (?)";
|
||||
|
@ -1578,7 +1524,7 @@ void generate_races_sections(const config *help_cfg, section &sec, int level)
|
|||
i != game_info->unit_types.end(); i++) {
|
||||
const unit_type &type = (*i).second;
|
||||
UNIT_DESCRIPTION_TYPE desc_type = description_type(type);
|
||||
if (desc_type == FULL_DESCRIPTION && !type.hide_help()) {
|
||||
if (desc_type == FULL_DESCRIPTION) {
|
||||
races.insert(type.race());
|
||||
}
|
||||
}
|
||||
|
@ -1624,19 +1570,21 @@ std::vector<topic> generate_unit_topics(const bool sort_generated, const std::st
|
|||
if (type.race() != race)
|
||||
continue;
|
||||
UNIT_DESCRIPTION_TYPE desc_type = description_type(type);
|
||||
if (desc_type != FULL_DESCRIPTION || type.hide_help())
|
||||
if (desc_type != FULL_DESCRIPTION)
|
||||
continue;
|
||||
|
||||
const std::string lang_name = type.language_name();
|
||||
const std::string ref_id = std::string("unit_") + type.id();
|
||||
const std::string ref_id = (type.hide_help() ? "." : "") + unit_prefix + type.id();
|
||||
topic unit_topic(lang_name, ref_id, "");
|
||||
unit_topic.text = new unit_topic_generator(type);
|
||||
topics.push_back(unit_topic);
|
||||
|
||||
// we also record an hyperlink of this unit
|
||||
// in the list used for the race topic
|
||||
std::string link = "<ref>text='" + escape(lang_name) + "' dst='" + escape(ref_id) + "'</ref>";
|
||||
race_units.insert(link);
|
||||
if (!type.hide_help()) {
|
||||
// we also record an hyperlink of this unit
|
||||
// in the list used for the race topic
|
||||
std::string link = "<ref>text='" + escape(lang_name) + "' dst='" + escape(ref_id) + "'</ref>";
|
||||
race_units.insert(link);
|
||||
}
|
||||
}
|
||||
|
||||
//generate the hidden race description topic
|
||||
|
@ -1668,12 +1616,12 @@ std::vector<topic> generate_unit_topics(const bool sort_generated, const std::st
|
|||
|
||||
UNIT_DESCRIPTION_TYPE description_type(const unit_type &type)
|
||||
{
|
||||
const std::string id = type.id();
|
||||
const std::set<std::string> &encountered_units = preferences::encountered_units();
|
||||
if (game_config::debug) {
|
||||
return FULL_DESCRIPTION;
|
||||
}
|
||||
if (encountered_units.find(id) != encountered_units.end()) {
|
||||
|
||||
const std::set<std::string> &encountered_units = preferences::encountered_units();
|
||||
if (encountered_units.find(type.id()) != encountered_units.end()) {
|
||||
return FULL_DESCRIPTION;
|
||||
}
|
||||
return NO_DESCRIPTION;
|
||||
|
@ -2728,8 +2676,9 @@ void help_browser::show_topic(const std::string &topic_id)
|
|||
const topic *t = find_topic(toplevel_, topic_id);
|
||||
if (t != NULL) {
|
||||
show_topic(*t);
|
||||
}
|
||||
else {
|
||||
} else if (topic_id.find(unit_prefix)==0 || topic_id.find("."+unit_prefix)==0) {
|
||||
show_topic(unknown_unit_topic);
|
||||
} else {
|
||||
std::cerr << "Help browser tried to show topic with id '" << topic_id
|
||||
<< "' but that topic could not be found." << std::endl;
|
||||
}
|
||||
|
@ -2977,6 +2926,14 @@ void show_help(display &disp, std::string show_topic, int xloc, int yloc)
|
|||
show_help(disp, toplevel, show_topic, xloc, yloc);
|
||||
}
|
||||
|
||||
//! Open the help browser, show unit with id unit_id.
|
||||
//!
|
||||
//! If show_topic is the empty string, the default topic will be shown.
|
||||
void show_unit_help(display &disp, std::string show_topic, bool hidden, int xloc, int yloc)
|
||||
{
|
||||
show_help(disp, toplevel, (hidden ? ".":"") + unit_prefix + show_topic, xloc, yloc);
|
||||
}
|
||||
|
||||
//! Open a help dialog using a toplevel other than the default.
|
||||
//!
|
||||
//! This allows for complete customization of the contents,
|
||||
|
|
|
@ -44,6 +44,10 @@ void show_help(display &disp, const section &toplevel, const std::string show_to
|
|||
/// will be shown if show_topic is the empty string.
|
||||
void show_help(display &disp, const std::string show_topic="", int xloc=-1, int yloc=-1);
|
||||
|
||||
/// wrapper to add unit prefix and hidding symbol
|
||||
void show_unit_help(display &disp, const std::string unit_id, bool hidden = false,
|
||||
int xloc=-1, int yloc=-1);
|
||||
|
||||
class help_button : public gui::dialog_button, public hotkey::command_executor {
|
||||
public:
|
||||
help_button(display& disp, const std::string &help_topic);
|
||||
|
|
Loading…
Add table
Reference in a new issue