From ddb698c1c140db2f4fad8e6785f096b6a962f24a Mon Sep 17 00:00:00 2001 From: Martin Lange <44003176+mlange-42@users.noreply.github.com> Date: Tue, 30 Aug 2022 12:28:31 +0200 Subject: [PATCH] Fix: Make graph color in health and bandaging menu consistent with sidebar (#60572) * make HP colors in bandaging and health menu consistent with sidebar * adapt tests for changed color scales (satiety) --- src/character_body.cpp | 9 ++++++--- src/medical_ui.cpp | 9 ++++++--- src/output.cpp | 2 +- tests/comestible_test.cpp | 6 +++--- 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/character_body.cpp b/src/character_body.cpp index 580cd6d2f7258..a4250ee30cc83 100644 --- a/src/character_body.cpp +++ b/src/character_body.cpp @@ -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( 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 ); diff --git a/src/medical_ui.cpp b/src/medical_ui.cpp index a53f720683f1b..5820244bf0a84 100644 --- a/src/medical_ui.cpp +++ b/src/medical_ui.cpp @@ -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( 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 ); diff --git a/src/output.cpp b/src/output.cpp index af31b791cffb5..fe89fdfc77183 100644 --- a/src/output.cpp +++ b/src/output.cpp @@ -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( ( 1 - status ) * colors.size() ); + int ind = std::floor( ( 1.0 - status ) * ( colors.size() - 1 ) + 0.5 ); ind = clamp( ind, 0, colors.size() - 1 ); col = colors[ind]; } diff --git a/tests/comestible_test.cpp b/tests/comestible_test.cpp index acdaa4a649030..7cc4690002c8b 100644 --- a/tests/comestible_test.cpp +++ b/tests/comestible_test.cpp @@ -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 ) == ":...." ); // NOLINTNEXTLINE(cata-text-style): verbatim ellipses necessary for validation - CHECK( satiety_bar( 50 ) == "\\...." ); + CHECK( satiety_bar( 50 ) == "\\...." ); // NOLINTNEXTLINE(cata-text-style): verbatim ellipses necessary for validation CHECK( satiety_bar( 100 ) == "|...." ); // NOLINTNEXTLINE(cata-text-style): verbatim ellipses necessary for validation @@ -328,8 +328,8 @@ TEST_CASE( "food satiety bar", "[character][food][satiety]" ) CHECK( satiety_bar( 700 ) == "|||.." ); CHECK( satiety_bar( 800 ) == "|||\\." ); CHECK( satiety_bar( 900 ) == "|||\\." ); - CHECK( satiety_bar( 1000 ) == "||||." ); - CHECK( satiety_bar( 1100 ) == "||||." ); + CHECK( satiety_bar( 1000 ) == "||||." ); + CHECK( satiety_bar( 1100 ) == "||||." ); CHECK( satiety_bar( 1200 ) == "||||." ); CHECK( satiety_bar( 1300 ) == "||||\\" ); CHECK( satiety_bar( 1400 ) == "||||\\" );