Show ability of a selected unit as active/inactive with respect to mouseover hex. For example, selecting an Elvish Ranger that stands on a forest and highlighting a water hex should show the "ambush" ability in gray.
This commit is contained in:
parent
1182e9595b
commit
af433b1f7c
5 changed files with 81 additions and 33 deletions
|
@ -65,6 +65,7 @@
|
|||
* Fix SDL_DestroyRenderer assertion failure under XMonad. (part of issue #3716)
|
||||
* Fix map item names not being translated in the scenario editor.
|
||||
* Usernames specified in the MP UI and command line are now stripped of leading and trailing whitespace, including newlines.
|
||||
* Show ability of a selected unit as active/inactive with respect to mouseover hex. (issue #3912)
|
||||
### Multiplayer server
|
||||
* Fix stale temporary bans continuing to have an effect on players until cleared by
|
||||
phpBB on the next ban/unban operation.
|
||||
|
|
|
@ -1129,6 +1129,9 @@
|
|||
name = "Chusslove Illich (caslav.ilic)"
|
||||
comment = "wmlxgetext improvements"
|
||||
[/entry]
|
||||
[entry]
|
||||
name = "David Slabý (blaf)"
|
||||
[/entry]
|
||||
[entry]
|
||||
name = "Daniel Bruegmann"
|
||||
[/entry]
|
||||
|
|
|
@ -397,16 +397,15 @@ REPORT_GENERATOR(selected_unit_alignment, rc)
|
|||
return unit_alignment(rc, u, hex_to_show_alignment_at);
|
||||
}
|
||||
|
||||
|
||||
static config unit_abilities(const unit* u)
|
||||
static config unit_abilities(const unit* u, const map_location& loc)
|
||||
{
|
||||
if (!u) return config();
|
||||
config res;
|
||||
|
||||
boost::dynamic_bitset<> active;
|
||||
const std::vector<std::tuple<std::string, t_string,t_string,t_string>> &abilities = u->ability_tooltips(&active);
|
||||
const size_t abilities_size = abilities.size();
|
||||
for ( size_t i = 0; i != abilities_size; ++i )
|
||||
const std::vector<std::tuple<std::string, t_string,t_string,t_string>> &abilities = u->ability_tooltips(active, loc);
|
||||
const std::size_t abilities_size = abilities.size();
|
||||
for ( std::size_t i = 0; i != abilities_size; ++i )
|
||||
{
|
||||
// Aliases for readability:
|
||||
const std::string& id = std::get<0>(abilities[i]);
|
||||
|
@ -435,12 +434,20 @@ static config unit_abilities(const unit* u)
|
|||
REPORT_GENERATOR(unit_abilities, rc)
|
||||
{
|
||||
const unit *u = get_visible_unit(rc);
|
||||
return unit_abilities(u);
|
||||
const map_location& mouseover_hex = rc.screen().mouseover_hex();
|
||||
|
||||
return unit_abilities(u, mouseover_hex);
|
||||
}
|
||||
REPORT_GENERATOR(selected_unit_abilities, rc)
|
||||
{
|
||||
const unit *u = get_selected_unit(rc);
|
||||
return unit_abilities(u);
|
||||
|
||||
const map_location& mouseover_hex = rc.screen().mouseover_hex();
|
||||
const unit *visible_unit = get_visible_unit(rc);
|
||||
if(visible_unit && u && visible_unit->id() != u->id() && mouseover_hex.valid())
|
||||
return unit_abilities(u, mouseover_hex);
|
||||
else
|
||||
return unit_abilities(u, u->get_location());
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -260,39 +260,36 @@ namespace {
|
|||
gender == unit_race::MALE ? male_key : female_key,
|
||||
default_key);
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<std::tuple<std::string, t_string, t_string, t_string>> unit::ability_tooltips(boost::dynamic_bitset<>* active_list) const
|
||||
{
|
||||
std::vector<std::tuple<std::string, t_string,t_string,t_string>> res;
|
||||
if ( active_list )
|
||||
active_list->clear();
|
||||
|
||||
for (const config::any_child &ab : this->abilities_.all_children_range())
|
||||
/**
|
||||
* Adds a quadruple consisting of (in order) id, base name,
|
||||
* male or female name as appropriate for the unit, and description.
|
||||
*
|
||||
* @returns Whether name was resolved and quadruple added.
|
||||
*/
|
||||
bool add_ability_tooltip(const config::any_child &ab, unit_race::GENDER gender, std::vector<std::tuple<std::string, t_string,t_string,t_string>>& res, bool active)
|
||||
{
|
||||
if ( !active_list || ability_active(ab.key, ab.cfg, loc_) )
|
||||
{
|
||||
const t_string& name =
|
||||
gender_value(ab.cfg, gender_, "name", "female_name", "name").t_str();
|
||||
const t_string& name =
|
||||
gender_value(ab.cfg, gender, "name", "female_name", "name").t_str();
|
||||
|
||||
if (active) {
|
||||
if (!name.empty()) {
|
||||
res.emplace_back(
|
||||
ab.cfg["id"],
|
||||
ab.cfg["name"].t_str(),
|
||||
name,
|
||||
ab.cfg["description"].t_str() );
|
||||
if ( active_list )
|
||||
active_list->push_back(true);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// See if an inactive name was specified.
|
||||
const config::attribute_value& inactive_value =
|
||||
gender_value(ab.cfg, gender_, "name_inactive",
|
||||
"female_name_inactive", "name_inactive");
|
||||
gender_value(ab.cfg, gender, "name_inactive",
|
||||
"female_name_inactive", "name_inactive");
|
||||
const t_string& name = !inactive_value.blank() ? inactive_value.t_str() :
|
||||
gender_value(ab.cfg, gender_, "name", "female_name", "name").t_str();
|
||||
gender_value(ab.cfg, gender, "name", "female_name", "name").t_str();
|
||||
|
||||
if (!name.empty()) {
|
||||
res.emplace_back(
|
||||
|
@ -300,9 +297,38 @@ std::vector<std::tuple<std::string, t_string, t_string, t_string>> unit::ability
|
|||
default_value(ab.cfg, "name_inactive", "name").t_str(),
|
||||
name,
|
||||
default_value(ab.cfg, "description_inactive", "description").t_str() );
|
||||
active_list->push_back(false);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<std::tuple<std::string, t_string, t_string, t_string>> unit::ability_tooltips() const
|
||||
{
|
||||
std::vector<std::tuple<std::string, t_string,t_string,t_string>> res;
|
||||
|
||||
for (const config::any_child &ab : this->abilities_.all_children_range())
|
||||
{
|
||||
add_ability_tooltip(ab, gender_, res, true);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
std::vector<std::tuple<std::string, t_string, t_string, t_string>> unit::ability_tooltips(boost::dynamic_bitset<>& active_list, const map_location& loc) const
|
||||
{
|
||||
std::vector<std::tuple<std::string, t_string,t_string,t_string>> res;
|
||||
active_list.clear();
|
||||
|
||||
for (const config::any_child &ab : this->abilities_.all_children_range())
|
||||
{
|
||||
bool active = ability_active(ab.key, ab.cfg, loc);
|
||||
if (add_ability_tooltip(ab, gender_, res, active))
|
||||
{
|
||||
active_list.push_back(active);
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
|
|
@ -1495,17 +1495,28 @@ public:
|
|||
}
|
||||
|
||||
/**
|
||||
* Gets the names and descriptions of this unit's abilities.
|
||||
* Gets the names and descriptions of this unit's abilities. Location-independent variant
|
||||
* with all abilities shown as active.
|
||||
*
|
||||
* @param active_list If nullptr, then all abilities are forced active. If not, this vector
|
||||
* will be the same length as the returned one and will indicate whether or
|
||||
* not the corresponding ability is active.
|
||||
*
|
||||
* @returns A list of triples consisting of (in order) id, base name, male or female
|
||||
* name as appropriate for the unit, and description.
|
||||
* @returns A list of quadruples consisting of (in order) id, base name,
|
||||
* male or female name as appropriate for the unit, and description.
|
||||
*/
|
||||
std::vector<std::tuple<std::string, t_string, t_string, t_string>>
|
||||
ability_tooltips(boost::dynamic_bitset<>* active_list = nullptr) const;
|
||||
ability_tooltips() const;
|
||||
|
||||
/**
|
||||
* Gets the names and descriptions of this unit's abilities.
|
||||
*
|
||||
* @param active_list This vector will be the same length as the returned one and will
|
||||
* indicate whether or not the corresponding ability is active.
|
||||
*
|
||||
* @param loc The location on which to resolve the ability.
|
||||
*
|
||||
* @returns A list of quadruples consisting of (in order) id, base name,
|
||||
* male or female name as appropriate for the unit, and description.
|
||||
*/
|
||||
std::vector<std::tuple<std::string, t_string, t_string, t_string>>
|
||||
ability_tooltips(boost::dynamic_bitset<>& active_list, const map_location& loc) const;
|
||||
|
||||
/** Get a list of all abilities by ID. */
|
||||
std::vector<std::string> get_ability_list() const;
|
||||
|
|
Loading…
Add table
Reference in a new issue