diff --git a/src/panels.cpp b/src/panels.cpp index d91bb5d8b3801..8e27df36f3423 100644 --- a/src/panels.cpp +++ b/src/panels.cpp @@ -2202,9 +2202,17 @@ static std::string get_compass_for_direction( const cardinal_direction dir, int return ret; } -static std::string get_compass_legend( const int max_width ) +std::string display::colorized_compass_text_color( const cardinal_direction dir, int width ) { - int wavail = max_width; + if( dir == cardinal_direction::num_cardinal_directions ) { + return ""; + } + return get_compass_for_direction( dir, width ); +} + +std::string display::colorized_compass_legend_text_color( int width ) +{ + int wavail = width; const monster_visible_info &mon_visible = get_avatar().get_mon_visible(); //~ Creature name format in compass legend. 1$ = symbol, 2$ = name. ex: "Z shocker zombie" const std::string name_fmt = _( "%1$s %2$s" ); @@ -2250,20 +2258,6 @@ static std::string get_compass_legend( const int max_width ) return enumerate_as_string( names, enumeration_conjunction::none ); } -std::pair display::compass_text_color( const cardinal_direction dir, - int width ) -{ - if( dir == cardinal_direction::num_cardinal_directions ) { - return { "", c_white }; - } - return { get_compass_for_direction( dir, width ), c_white }; -} - -std::pair display::compass_legend_text_color( int width ) -{ - return { get_compass_legend( width ), c_white }; -} - static void draw_health_classic( const draw_args &args ) { const avatar &u = args._ava; diff --git a/src/panels.h b/src/panels.h index cc57d5462073e..c230f31c2b3ca 100644 --- a/src/panels.h +++ b/src/panels.h @@ -98,9 +98,9 @@ std::pair safe_mode_text_color( const bool classic_mode ) std::pair wind_text_color( const Character &u ); std::pair weather_text_color( const Character &u ); -// Get visible threats by cardinal direction -std::pair compass_text_color( const cardinal_direction dir, int width ); -std::pair compass_legend_text_color( int width ); +// Get visible threats by cardinal direction - Already colorized +std::string colorized_compass_text_color( const cardinal_direction dir, int width ); +std::string colorized_compass_legend_text_color( int width ); // Define color for displaying the body temperature nc_color bodytemp_color( const Character &u, const bodypart_id &bp ); diff --git a/src/widget.cpp b/src/widget.cpp index ae33ff3dc472b..eb4687fa9ff4b 100644 --- a/src/widget.cpp +++ b/src/widget.cpp @@ -477,6 +477,7 @@ bool widget::uses_text_function() std::string widget::color_text_function_string( const avatar &ava ) { std::string ret; + bool apply_color = true; std::pair desc; // Give a default color (some widget_vars do not define one) desc.second = c_light_gray; @@ -554,21 +555,19 @@ std::string widget::color_text_function_string( const avatar &ava ) desc = display::wind_text_color( ava ); break; case widget_var::compass_text: - // Compass color is specific to individual threats. - // Skip colorization. - desc = display::compass_text_color( _direction, _width ); - return desc.first; + desc.first = display::colorized_compass_text_color( _direction, _width ); + apply_color = false; // Already colorized + break; case widget_var::compass_legend_text: - // Compass color is specific to individual threats. - // Skip colorization. - desc = display::compass_legend_text_color( _width ); - return desc.first; + desc.first = display::colorized_compass_legend_text_color( _width ); + apply_color = false; // Already colorized + break; default: debugmsg( "Unexpected widget_var %s - no text_color function defined", io::enum_to_string( _var ) ); return _( "???" ); } - ret += colorize( desc.first, desc.second ); + ret += apply_color ? colorize( desc.first, desc.second ) : desc.first; return ret; }