Switch to hard-coded colours instead of relying on pango names (resolves #4348).

* Pango changed its definition of 'green' in version 1.32.2 to align with CSS specifications (see #4348 for details).
* This change focuses only on instances of '<span color="green">', leaving instances of named colours that don't use 'green'.
* Problem: Cannot use this approach with '<format>' (at least not that I'm currently aware) so it breaks time-of-day bonus colour consistency.

(cherry picked from commit 57cfcf87d7)
This commit is contained in:
Wedge009 2021-09-16 21:25:45 +10:00
parent 8d2171df26
commit 1014fd1741
4 changed files with 15 additions and 17 deletions

View file

@ -397,7 +397,6 @@ const std::vector<std::string>& topic_text::parsed_text() const
std::string time_of_day_bonus_colored(const int time_of_day_bonus)
{
// Use same red/green colouring scheme as time_of_day_at() in reports.cpp for consistency
return std::string("<format>color='") + (time_of_day_bonus > 0 ? "green" : (time_of_day_bonus < 0 ? "red" : "white")) + "' text='" + std::to_string(time_of_day_bonus) + "'</format>";
}

View file

@ -1269,13 +1269,12 @@ static config time_of_day_at(reports::context & rc, const map_location& mouseove
std::string chaotic_color("white");
std::string liminal_color("white");
// Use same red/green colouring scheme as time_of_day_bonus_colored() in help/help_impl.cpp for consistency
if (b != 0) {
lawful_color = (b > 0) ? "green" : "red";
chaotic_color = (b < 0) ? "green" : "red";
lawful_color = (b > 0) ? "#0f0" : "#f00";
chaotic_color = (b < 0) ? "#0f0" : "#f00";
}
if (l != 0) {
liminal_color = (l > 0) ? "green" : "red";
liminal_color = (l > 0) ? "#0f0" : "#f00";
}
tooltip << _("Time of day:") << " <b>" << tod.name << "</b>\n"
<< _("Lawful units: ") << "<span foreground=\"" << lawful_color << "\">"

View file

@ -444,7 +444,7 @@ bool attack_type::describe_modification(const config& cfg,std::string* descripti
"<span color=\"$color\">$number_or_percent</span> damage",
"<span color=\"$color\">$number_or_percent</span> damage",
std::stoi(increase_damage),
{{"number_or_percent", utils::print_modifier(increase_damage)}, {"color", increase_damage[0] == '-' ? "red" : "green"}}));
{{"number_or_percent", utils::print_modifier(increase_damage)}, {"color", increase_damage[0] == '-' ? "#f00" : "#0f0"}}));
}
if(!set_damage.empty()) {
@ -462,7 +462,7 @@ bool attack_type::describe_modification(const config& cfg,std::string* descripti
"<span color=\"$color\">$number_or_percent</span> strike",
"<span color=\"$color\">$number_or_percent</span> strikes",
std::stoi(increase_attacks),
{{"number_or_percent", utils::print_modifier(increase_attacks)}, {"color", increase_attacks[0] == '-' ? "red" : "green"}}));
{{"number_or_percent", utils::print_modifier(increase_attacks)}, {"color", increase_attacks[0] == '-' ? "#f00" : "#0f0"}}));
}
if(!set_attacks.empty()) {
@ -485,7 +485,7 @@ bool attack_type::describe_modification(const config& cfg,std::string* descripti
desc.emplace_back(VGETTEXT(
// TRANSLATORS: Current value for WML code increase_accuracy, documented in https://wiki.wesnoth.org/EffectWML
"<span color=\"$color\">$number_or_percent|%</span> accuracy",
{{"number_or_percent", utils::print_modifier(increase_accuracy)}, {"color", increase_accuracy[0] == '-' ? "red" : "green"}}));
{{"number_or_percent", utils::print_modifier(increase_accuracy)}, {"color", increase_accuracy[0] == '-' ? "#f00" : "#0f0"}}));
}
if(!set_parry.empty()) {
@ -499,7 +499,7 @@ bool attack_type::describe_modification(const config& cfg,std::string* descripti
desc.emplace_back(VGETTEXT(
// TRANSLATORS: Current value for WML code increase_parry, documented in https://wiki.wesnoth.org/EffectWML
"<span color=\"$color\">$number_or_percent</span> parry",
{{"number_or_percent", utils::print_modifier(increase_parry)}, {"color", increase_parry[0] == '-' ? "red" : "green"}}));
{{"number_or_percent", utils::print_modifier(increase_parry)}, {"color", increase_parry[0] == '-' ? "#f00" : "#0f0"}}));
}
if(!set_movement.empty()) {
@ -517,7 +517,7 @@ bool attack_type::describe_modification(const config& cfg,std::string* descripti
"<span color=\"$color\">$number_or_percent</span> movement point",
"<span color=\"$color\">$number_or_percent</span> movement points",
std::stoi(increase_movement),
{{"number_or_percent", utils::print_modifier(increase_movement)}, {"color", increase_movement[0] == '-' ? "red" : "green"}}));
{{"number_or_percent", utils::print_modifier(increase_movement)}, {"color", increase_movement[0] == '-' ? "#f00" : "#0f0"}}));
}
*description = utils::format_conjunct_list("", desc);

View file

@ -1829,7 +1829,7 @@ std::string unit::describe_builtin_effect(std::string apply_to, const config& ef
if(!increase_total.empty()) {
return VGETTEXT(
"<span color=\"$color\">$number_or_percent</span> HP",
{{"number_or_percent", utils::print_modifier(increase_total)}, {"color", increase_total[0] == '-' ? "red" : "green"}});
{{"number_or_percent", utils::print_modifier(increase_total)}, {"color", increase_total[0] == '-' ? "#f00" : "#0f0"}});
}
} else {
const std::string& increase = effect["increase"];
@ -1841,31 +1841,31 @@ std::string unit::describe_builtin_effect(std::string apply_to, const config& ef
"<span color=\"$color\">$number_or_percent</span> move",
"<span color=\"$color\">$number_or_percent</span> moves",
std::stoi(increase),
{{"number_or_percent", utils::print_modifier(increase)}, {"color", increase[0] == '-' ? "red" : "green"}});
{{"number_or_percent", utils::print_modifier(increase)}, {"color", increase[0] == '-' ? "#f00" : "#0f0"}});
} else if(apply_to == "vision") {
return VGETTEXT(
"<span color=\"$color\">$number_or_percent</span> vision",
{{"number_or_percent", utils::print_modifier(increase)}, {"color", increase[0] == '-' ? "red" : "green"}});
{{"number_or_percent", utils::print_modifier(increase)}, {"color", increase[0] == '-' ? "#f00" : "#0f0"}});
} else if(apply_to == "jamming") {
return VGETTEXT(
"<span color=\"$color\">$number_or_percent</span> jamming",
{{"number_or_percent", utils::print_modifier(increase)}, {"color", increase[0] == '-' ? "red" : "green"}});
{{"number_or_percent", utils::print_modifier(increase)}, {"color", increase[0] == '-' ? "#f00" : "#0f0"}});
} else if(apply_to == "max_experience") {
// Unlike others, decreasing experience is a *GOOD* thing
return VGETTEXT(
"<span color=\"$color\">$number_or_percent</span> XP to advance",
{{"number_or_percent", utils::print_modifier(increase)}, {"color", increase[0] == '-' ? "green" : "red"}});
{{"number_or_percent", utils::print_modifier(increase)}, {"color", increase[0] == '-' ? "#0f0" : "#f00"}});
} else if(apply_to == "max_attacks") {
return VNGETTEXT(
"<span color=\"$color\">$number_or_percent</span> attack per turn",
"<span color=\"$color\">$number_or_percent</span> attacks per turn",
std::stoi(increase),
{{"number_or_percent", utils::print_modifier(increase)}, {"color", increase[0] == '-' ? "red" : "green"}});
{{"number_or_percent", utils::print_modifier(increase)}, {"color", increase[0] == '-' ? "#f00" : "#0f0"}});
} else if(apply_to == "recall_cost") {
// Unlike others, decreasing recall cost is a *GOOD* thing
return VGETTEXT(
"<span color=\"$color\">$number_or_percent</span> cost to recall",
{{"number_or_percent", utils::print_modifier(increase)}, {"color", increase[0] == '-' ? "green" : "red"}});
{{"number_or_percent", utils::print_modifier(increase)}, {"color", increase[0] == '-' ? "#0f0" : "#f00"}});
}
}
return "";