Skip to content

Commit

Permalink
Resolve #4736 (XP always displayed in light blue) (#4740)
Browse files Browse the repository at this point in the history
* Remove hard-coded colouring for HP as well as XP.

Co-authored-by: gfgtdf <daniel.gfgtdf@gmail.com>
  • Loading branch information
Wedge009 and gfgtdf committed Feb 17, 2020
1 parent 0593144 commit f6f9b2d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/gui/widgets/unit_preview_pane.cpp
Expand Up @@ -341,12 +341,12 @@ void unit_preview_pane::set_displayed_type(const unit_type& type)
tree_details_->clear();
tree_details_->add_node("hp_xp_mp", {
{ "hp",{
{ "label", (formatter() << "<small>" << "<span color='#21e100'>" << "<b>" << _("HP: ") << "</b>" << type.hitpoints() << "</span>" << " | </small>").str() },
{ "label", (formatter() << "<small>" << font::span_color(unit::hp_color_max()) << "<b>" << _("HP: ") << "</b>" << type.hitpoints() << "</span>" << " | </small>").str() },
{ "use_markup", "true" },
{ "tooltip", get_hp_tooltip(type.movement_type().get_resistances().damage_table(), [&type](const std::string& dt, bool is_attacker) { return type.resistance_against(dt, is_attacker); }) }
} },
{ "xp",{
{ "label", (formatter() << "<small>" << "<span color='#00a0e1'>" << "<b>" << _("XP: ") << "</b>" << type.experience_needed() << "</span>" << " | </small>").str() },
{ "label", (formatter() << "<small>" << font::span_color(unit::xp_color(100, type.can_advance(), true)) << "<b>" << _("XP: ") << "</b>" << type.experience_needed() << "</span>" << " | </small>").str() },
{ "use_markup", "true" },
{ "tooltip", (formatter() << _("Experience Modifier: ") << unit_experience_accelerator::get_acceleration() << '%').str() }
} },
Expand Down
32 changes: 21 additions & 11 deletions src/units/unit.cpp
Expand Up @@ -1131,7 +1131,12 @@ color_t unit::hp_color(int new_hitpoints) const
return hp_color_impl(new_hitpoints, hitpoints());
}

color_t unit::xp_color() const
color_t unit::hp_color_max()
{
return hp_color_impl(1, 1);
}

color_t unit::xp_color(int xp_to_advance, bool can_advance, bool has_amla)
{
const color_t near_advance_color {255,255,255,255};
const color_t mid_advance_color {150,255,255,255};
Expand All @@ -1142,18 +1147,12 @@ color_t unit::xp_color() const
const color_t far_amla_color {139,0,237,255};
const color_t amla_color {170,0,255,255};

const bool near_advance = static_cast<int>(experience_to_advance()) <= game_config::kill_experience;
const bool mid_advance = static_cast<int>(experience_to_advance()) <= game_config::kill_experience*2;
const bool far_advance = static_cast<int>(experience_to_advance()) <= game_config::kill_experience*3;
const bool near_advance = static_cast<int>(xp_to_advance) <= game_config::kill_experience;
const bool mid_advance = static_cast<int>(xp_to_advance) <= game_config::kill_experience*2;
const bool far_advance = static_cast<int>(xp_to_advance) <= game_config::kill_experience*3;

color_t color = normal_color;
bool major_amla = false;
bool has_amla = false;
for(const config& adv:get_modification_advances()){
major_amla |= adv["major_amla"].to_bool();
has_amla = true;
}
if(advances_to().size() ||major_amla){
if(can_advance){
if(near_advance){
color=near_advance_color;
} else if(mid_advance){
Expand All @@ -1176,6 +1175,17 @@ color_t unit::xp_color() const
return(color);
}

color_t unit::xp_color() const
{
bool major_amla = false;
bool has_amla = false;
for(const config& adv:get_modification_advances()){
major_amla |= adv["major_amla"].to_bool();
has_amla = true;
}
return xp_color(experience_to_advance(), !advances_to().empty() || major_amla, has_amla);
}

void unit::set_recruits(const std::vector<std::string>& recruits)
{
unit_types.check_types(recruits);
Expand Down
2 changes: 2 additions & 0 deletions src/units/unit.hpp
Expand Up @@ -1571,6 +1571,7 @@ class unit
* The maximum_hitpoints are considered as base.
*/
color_t hp_color() const;
static color_t hp_color_max();

/**
* Color for this unit's hitpoints.
Expand All @@ -1584,6 +1585,7 @@ class unit
* Color for this unit's XP. See also @ref hp_color
*/
color_t xp_color() const;
static color_t xp_color(int xp_to_advance, bool can_advance, bool has_amla);

/**
* @}
Expand Down

0 comments on commit f6f9b2d

Please sign in to comment.