From ad0867fa4206b237b45d4059ac9a74a034859719 Mon Sep 17 00:00:00 2001 From: josteph Date: Thu, 12 Sep 2019 04:36:51 +0000 Subject: [PATCH] Add color names to the Status Table, sidebar and top bar For colorblind MP players Fixes #1217 --- src/gui/dialogs/game_stats.cpp | 2 ++ src/reports.cpp | 22 +++++++++++++++------- src/team.cpp | 13 +++++++++++++ src/team.hpp | 1 + 4 files changed, 31 insertions(+), 7 deletions(-) diff --git a/src/gui/dialogs/game_stats.cpp b/src/gui/dialogs/game_stats.cpp index ed2a7c79084c..9d50eef24d9d 100644 --- a/src/gui/dialogs/game_stats.cpp +++ b/src/gui/dialogs/game_stats.cpp @@ -127,7 +127,9 @@ void game_stats::pre_show(window& window) row_data_stats.emplace("team_leader_image", column_stats); column_stats["label"] = leader_name + "\n" + controller_name(team); + column_stats["tooltip"] = team::get_side_color_name_for_UI(team.side()); row_data_stats.emplace("team_leader_name", column_stats); + column_stats.erase("tooltip"); column_stats["label"] = team.user_team_name().empty() ? team.team_name() : team.user_team_name().str(); row_data_stats.emplace("team_name", column_stats); diff --git a/src/reports.cpp b/src/reports.cpp index 948d5e536390..1944fea7e4d1 100644 --- a/src/reports.cpp +++ b/src/reports.cpp @@ -18,6 +18,7 @@ #include "font/pango/escape.hpp" #include "font/text_formatting.hpp" #include "formatter.hpp" +#include "formula/string_utils.hpp" #include "preferences/game.hpp" #include "gettext.hpp" #include "language.hpp" @@ -214,6 +215,16 @@ REPORT_GENERATOR(selected_unit_race, rc) return unit_race(u); } +static std::string side_tooltip(const team& team) +{ + if(team.side_name().empty()) + return ""; + + return VGETTEXT("Side: $side_name ($color_name)", + {{"side_name", team.side_name()}, + {"color_name", team::get_side_color_name_for_UI(team.side()) }}); +} + static config unit_side(reports::context & rc, const unit* u) { if (!u) return config(); @@ -230,12 +241,9 @@ static config unit_side(reports::context & rc, const unit* u) std::stringstream text; text << " " << u->side(); - std::ostringstream tooltip; - if (!u_team.side_name().empty()) { - tooltip << _("Side:") << " " << u_team.side_name() << ""; - } - add_image(report, flag_icon + mods, tooltip.str(), ""); - add_text(report, text.str(), tooltip.str(), ""); + const std::string& tooltip = side_tooltip(u_team); + add_image(report, flag_icon + mods, tooltip, ""); + add_text(report, text.str(), tooltip, ""); return report; } REPORT_GENERATOR(unit_side, rc) @@ -1637,7 +1645,7 @@ REPORT_GENERATOR(side_playing, rc) std::string mods = "~RC(" + old_rgb + ">" + new_rgb + ")"; if (flag_icon.empty()) flag_icon = game_config::images::flag_icon; - return image_report(flag_icon + mods, active_team.side_name()); + return image_report(flag_icon + mods, side_tooltip(active_team)); } REPORT_GENERATOR(observers, rc) diff --git a/src/team.cpp b/src/team.cpp index 8908717dd029..543f8cae48c7 100644 --- a/src/team.cpp +++ b/src/team.cpp @@ -21,6 +21,7 @@ #include "ai/manager.hpp" #include "color.hpp" +#include "formula/string_utils.hpp" // for VGETTEXT #include "game_data.hpp" #include "game_events/pump.hpp" #include "lexical_cast.hpp" @@ -976,6 +977,18 @@ std::string team::get_side_color_id(unsigned side) } } +const t_string team::get_side_color_name_for_UI(unsigned side) +{ + const std::string& color_id = team::get_side_color_id(side); + const auto& rgb_name = game_config::team_rgb_name[color_id]; + if(rgb_name.empty()) + // TRANSLATORS: $color_id is the internal identifier of a side color, for example, 'lightred'. + // Translate the quotation marks only. + return VGETTEXT("\"$color_id\"", {{ "color_id", color_id }}); + else + return rgb_name; +} + std::string team::get_side_color_id_from_config(const config& cfg) { const config::attribute_value& c = cfg["color"]; diff --git a/src/team.hpp b/src/team.hpp index 1c520c1fffec..909b44cd298a 100644 --- a/src/team.hpp +++ b/src/team.hpp @@ -370,6 +370,7 @@ class team static color_t get_minimap_color(int side); static std::string get_side_color_id(unsigned side); + static const t_string get_side_color_name_for_UI(unsigned side); static std::string get_side_color_id_from_config(const config& cfg); static std::string get_side_highlight_pango(int side);