Skip to content

Commit

Permalink
Fix: Make graph color in health and bandaging menu consistent with si…
Browse files Browse the repository at this point in the history
…debar (CleverRaven#60572)

* make HP colors in bandaging and health menu consistent with sidebar

* adapt tests for changed color scales (satiety)
  • Loading branch information
mlange-42 authored Aug 30, 2022
1 parent dc531ed commit ddb698c
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
9 changes: 6 additions & 3 deletions src/character_body.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1145,11 +1145,14 @@ bodypart_id Character::body_window( const std::string &menu_header,
desc += colorize( _( "It is broken. It needs a splint or surgical attention." ), c_red ) + "\n";
hp_str = "==%==";
} else if( no_feeling ) {
if( current_hp < maximal_hp * 0.25 ) {
const float cur_hp_pcnt = current_hp / static_cast<float>( maximal_hp );
if( cur_hp_pcnt < 0.125f ) {
hp_str = colorize( _( "Very Bad" ), c_red );
} else if( current_hp < maximal_hp * 0.5 ) {
} else if( cur_hp_pcnt < 0.375f ) {
hp_str = colorize( _( "Bad" ), c_light_red );
} else if( current_hp < maximal_hp * 0.75 ) {
} else if( cur_hp_pcnt < 0.625f ) {
hp_str = colorize( _( "So-so" ), c_yellow );
} else if( cur_hp_pcnt < 0.875f ) {
hp_str = colorize( _( "Okay" ), c_light_green );
} else {
hp_str = colorize( _( "Good" ), c_green );
Expand Down
9 changes: 6 additions & 3 deletions src/medical_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,11 +374,14 @@ static medical_column draw_health_summary( const int column_count, avatar *playe
detail += string_format( _( "[ %s ]" ), colorize( _( "BROKEN" ), c_red ) );
hp_str = "==%==";
} else if( no_feeling ) {
if( current_hp < maximal_hp * 0.25 ) {
const float cur_hp_pcnt = current_hp / static_cast<float>( maximal_hp );
if( cur_hp_pcnt < 0.125f ) {
hp_str = colorize( _( "Very Bad" ), c_red );
} else if( current_hp < maximal_hp * 0.5 ) {
} else if( cur_hp_pcnt < 0.375f ) {
hp_str = colorize( _( "Bad" ), c_light_red );
} else if( current_hp < maximal_hp * 0.75 ) {
} else if( cur_hp_pcnt < 0.625f ) {
hp_str = colorize( _( "So-so" ), c_yellow );
} else if( cur_hp_pcnt < 0.875f ) {
hp_str = colorize( _( "Okay" ), c_light_green );
} else {
hp_str = colorize( _( "Good" ), c_green );
Expand Down
2 changes: 1 addition & 1 deletion src/output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2204,7 +2204,7 @@ get_bar( const float cur, const float max,
if( !std::isfinite( status ) || colors.empty() ) {
col = c_red_red;
} else {
int ind = static_cast<int>( ( 1 - status ) * colors.size() );
int ind = std::floor( ( 1.0 - status ) * ( colors.size() - 1 ) + 0.5 );
ind = clamp<int>( ind, 0, colors.size() - 1 );
col = colors[ind];
}
Expand Down
6 changes: 3 additions & 3 deletions tests/comestible_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ TEST_CASE( "food satiety bar", "[character][food][satiety]" )
// NOLINTNEXTLINE(cata-text-style): verbatim ellipses necessary for validation
CHECK( satiety_bar( 1 ) == "<color_c_red>:</color>...." );
// NOLINTNEXTLINE(cata-text-style): verbatim ellipses necessary for validation
CHECK( satiety_bar( 50 ) == "<color_c_red>\\</color>...." );
CHECK( satiety_bar( 50 ) == "<color_c_light_red>\\</color>...." );
// NOLINTNEXTLINE(cata-text-style): verbatim ellipses necessary for validation
CHECK( satiety_bar( 100 ) == "<color_c_light_red>|</color>...." );
// NOLINTNEXTLINE(cata-text-style): verbatim ellipses necessary for validation
Expand All @@ -328,8 +328,8 @@ TEST_CASE( "food satiety bar", "[character][food][satiety]" )
CHECK( satiety_bar( 700 ) == "<color_c_light_green>|||</color>.." );
CHECK( satiety_bar( 800 ) == "<color_c_light_green>|||\\</color>." );
CHECK( satiety_bar( 900 ) == "<color_c_light_green>|||\\</color>." );
CHECK( satiety_bar( 1000 ) == "<color_c_green>||||</color>." );
CHECK( satiety_bar( 1100 ) == "<color_c_green>||||</color>." );
CHECK( satiety_bar( 1000 ) == "<color_c_light_green>||||</color>." );
CHECK( satiety_bar( 1100 ) == "<color_c_light_green>||||</color>." );
CHECK( satiety_bar( 1200 ) == "<color_c_green>||||</color>." );
CHECK( satiety_bar( 1300 ) == "<color_c_green>||||\\</color>" );
CHECK( satiety_bar( 1400 ) == "<color_c_green>||||\\</color>" );
Expand Down

0 comments on commit ddb698c

Please sign in to comment.