Skip to content

Commit

Permalink
Add color names to the Status Table, sidebar and top bar
Browse files Browse the repository at this point in the history
For colorblind MP players

Fixes #1217
  • Loading branch information
jostephd committed Sep 26, 2019
1 parent 4306c79 commit ad0867f
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 7 deletions.
2 changes: 2 additions & 0 deletions src/gui/dialogs/game_stats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
22 changes: 15 additions & 7 deletions src/reports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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: <b>$side_name</b> ($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();
Expand All @@ -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:") << " <b>" << u_team.side_name() << "</b>";
}
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)
Expand Down Expand Up @@ -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)
Expand Down
13 changes: 13 additions & 0 deletions src/team.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"];
Expand Down
1 change: 1 addition & 0 deletions src/team.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit ad0867f

Please sign in to comment.