Skip to content

Commit

Permalink
Compass widgets: Change flow control to match with existing pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
wapcaplet authored and dseguin committed Jan 3, 2022
1 parent 9cdc2ea commit ce48b57
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 28 deletions.
26 changes: 10 additions & 16 deletions src/panels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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" );
Expand Down Expand Up @@ -2250,20 +2258,6 @@ static std::string get_compass_legend( const int max_width )
return enumerate_as_string( names, enumeration_conjunction::none );
}

std::pair<std::string, nc_color> 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<std::string, nc_color> 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;
Expand Down
6 changes: 3 additions & 3 deletions src/panels.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ std::pair<std::string, nc_color> safe_mode_text_color( const bool classic_mode )
std::pair<std::string, nc_color> wind_text_color( const Character &u );
std::pair<std::string, nc_color> weather_text_color( const Character &u );

// Get visible threats by cardinal direction
std::pair<std::string, nc_color> compass_text_color( const cardinal_direction dir, int width );
std::pair<std::string, nc_color> 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 );
Expand Down
17 changes: 8 additions & 9 deletions src/widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string, nc_color> desc;
// Give a default color (some widget_vars do not define one)
desc.second = c_light_gray;
Expand Down Expand Up @@ -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<widget_var>( _var ) );
return _( "???" );
}
ret += colorize( desc.first, desc.second );
ret += apply_color ? colorize( desc.first, desc.second ) : desc.first;
return ret;
}

Expand Down

0 comments on commit ce48b57

Please sign in to comment.