Skip to content

Commit

Permalink
Re-colorize achievements UI (#42228)
Browse files Browse the repository at this point in the history
  • Loading branch information
nexusmrsep authored Jul 19, 2020
1 parent 8993acc commit 6e29528
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
19 changes: 12 additions & 7 deletions src/achievement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,11 @@ std::string enum_to_string<requirement_visibility>( requirement_visibility data

} // namespace io

static nc_color color_from_completion( bool is_conduct, achievement_completion comp )
static nc_color color_from_completion( bool is_conduct, achievement_completion comp, bool is_title )
{
switch( comp ) {
case achievement_completion::pending:
return is_conduct ? c_light_green : c_yellow;
return is_conduct ? c_light_green : ( is_title ? c_white : c_light_cyan );
case achievement_completion::completed:
return c_light_green;
case achievement_completion::failed:
Expand Down Expand Up @@ -325,7 +325,7 @@ std::string achievement::time_bound::ui_text( bool is_conduct ) const
time_point now = calendar::turn;
achievement_completion comp = completed();

nc_color c = color_from_completion( is_conduct, comp );
nc_color c = color_from_completion( is_conduct, comp, false );

auto translate_epoch = []( epoch e ) {
switch( e ) {
Expand Down Expand Up @@ -570,8 +570,9 @@ std::string enum_to_string<achievement_completion>( achievement_completion data
std::string achievement_state::ui_text( const achievement *ach ) const
{
// First: the achievement name and description
nc_color c = color_from_completion( ach->is_conduct(), completion );
std::string result = colorize( ach->name(), c ) + "\n";
nc_color c = color_from_completion( ach->is_conduct(), completion, false );
nc_color c_title = color_from_completion( ach->is_conduct(), completion, true );
std::string result = colorize( ach->name(), c_title ) + "\n";
if( !ach->description().empty() ) {
result += " " + colorize( ach->description(), c ) + "\n";
}
Expand Down Expand Up @@ -696,8 +697,12 @@ std::string achievement_tracker::ui_text() const

// First: the achievement name and description
nc_color c = color_from_completion( achievement_->is_conduct(),
achievement_completion::pending );
std::string result = colorize( achievement_->name(), c ) + "\n";
achievement_completion::pending,
false );
nc_color c_title = color_from_completion( achievement_->is_conduct(),
achievement_completion::pending,
true );
std::string result = colorize( achievement_->name(), c_title ) + "\n";
if( !achievement_->description().empty() ) {
result += " " + colorize( achievement_->description(), c ) + "\n";
}
Expand Down
10 changes: 6 additions & 4 deletions src/scores_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include "ui_manager.h"

static std::string get_achievements_text( const achievements_tracker &achievements,
bool use_conducts )
bool use_conducts, int width )
{
std::string thing_name = use_conducts ? _( "conducts" ) : _( "achievements" );
std::string cap_thing_name = use_conducts ? _( "Conducts" ) : _( "Achievements" );
Expand Down Expand Up @@ -47,8 +47,10 @@ static std::string get_achievements_text( const achievements_tracker &achievemen
return std::make_tuple( comp, ach->name().translated(), ach );
} );
std::sort( sortable_achievements.begin(), sortable_achievements.end(), localized_compare );
char ch = string_from_int( LINE_OXOX ).at( 0 );
for( const sortable_achievement &ach : sortable_achievements ) {
os += achievements.ui_text_for( std::get<const achievement *>( ach ) ) + "\n";
os += achievements.ui_text_for( std::get<const achievement *>( ach ) );
os += colorize( std::string( width, ch ), c_magenta );
}
if( valid_achievements.empty() ) {
os += string_format( _( "This game has no valid %s.\n" ), thing_name );
Expand Down Expand Up @@ -132,10 +134,10 @@ void show_scores_ui( const achievements_tracker &achievements, stats_tracker &st
if( new_tab ) {
switch( tab ) {
case tab_mode::achievements:
view.set_text( get_achievements_text( achievements, false ) );
view.set_text( get_achievements_text( achievements, false, getmaxx( w ) - 2 ) );
break;
case tab_mode::conducts:
view.set_text( get_achievements_text( achievements, true ) );
view.set_text( get_achievements_text( achievements, true, getmaxx( w ) - 2 ) );
break;
case tab_mode::scores:
view.set_text( get_scores_text( stats ) );
Expand Down
4 changes: 2 additions & 2 deletions tests/stats_tracker_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -638,11 +638,11 @@ TEST_CASE( "achievments_tracker", "[stats]" )
send_game_start( b, u_id );

CHECK( a.ui_text_for( &*a_kill_zombie ) ==
"<color_c_yellow>One down, billions to go…</color>\n"
"<color_c_white>One down, billions to go…</color>\n"
" <color_c_yellow>0/1 zombie killed</color>\n" );
if( time_since_game_start < 1_minutes ) {
CHECK( a.ui_text_for( &*a_kill_in_first_minute ) ==
"<color_c_yellow>Rude awakening</color>\n"
"<color_c_white>Rude awakening</color>\n"
" <color_c_light_green>Within 1 minute of start of game (30 seconds remaining)</color>\n"
" <color_c_yellow>0/1 monster killed</color>\n" );
} else {
Expand Down

0 comments on commit 6e29528

Please sign in to comment.