Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Achievement completed popup #42829

Merged
merged 2 commits into from
Aug 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@
#include "overmap_ui.h"
#include "overmapbuffer.h"
#include "panels.h"
#include "past_games_info.h"
#include "path_info.h"
#include "pickup.h"
#include "player.h"
Expand Down Expand Up @@ -284,6 +285,29 @@ static void achievement_attained( const achievement *a, bool achievements_enable
if( achievements_enabled ) {
add_msg( m_good, _( "You completed the achievement \"%s\"." ),
a->name() );
std::string popup_option = get_option<std::string>( "ACHIEVEMENT_COMPLETED_POPUP" );
bool show_popup;
if( test_mode || popup_option == "never" ) {
show_popup = false;
} else if( popup_option == "always" ) {
show_popup = true;
} else if( popup_option == "first" ) {
const achievement_completion_info *past_info = get_past_games().achievement( a->id );
show_popup = !past_info || past_info->games_completed.empty();
} else {
debugmsg( "Unexpected ACHIEVEMENT_COMPLETED_POPUP option value %s", popup_option );
show_popup = false;
}

if( show_popup ) {
std::string message = colorize( _( "Achievement completed!" ), c_light_green );
message += "\n\n";
message += get_achievements().ui_text_for( a );
message += "\n";
message += colorize( _( "Achievement completion popups can be\nconfigured via the "
"Interface options" ), c_dark_gray );
popup( message );
}
}
get_event_bus().send<event_type::player_gets_achievement>( a->id, achievements_enabled );
}
Expand Down
11 changes: 11 additions & 0 deletions src/options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1545,6 +1545,17 @@ void options_manager::add_options_interface()
false
);

add( "ACHIEVEMENT_COMPLETED_POPUP", "interface",
translate_marker( "Popup window when achievmement completed" ),
translate_marker( "Whether to trigger a popup window when completing an achievement. "
"First: when completing an achievement that has not been completed in "
"a previous game." ), {
{ "never", translate_marker( "Never" ) },
{ "always", translate_marker( "Always" ) },
{ "first", translate_marker( "First" ) }
},
"first" );

add( "LOOKAROUND_POSITION", "interface", translate_marker( "Look around position" ),
translate_marker( "Switch between look around panel being left or right." ),
{ { "left", translate_marker( "Left" ) }, { "right", translate_marker( "Right" ) } },
Expand Down
10 changes: 10 additions & 0 deletions src/past_games_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@

static void no_op( const achievement *, bool ) {}

class too_old_memorial_file_error : std::runtime_error
{
using runtime_error::runtime_error;
};

past_game_info::past_game_info( JsonIn &jsin )
{
JsonObject jo = jsin.get_object();
Expand All @@ -33,6 +38,9 @@ past_game_info::past_game_info( JsonIn &jsin )
event_multiset &events = stats_->get_events( event_type::game_start );
const event_multiset::summaries_type &counts = events.counts();
if( counts.size() != 1 ) {
if( counts.empty() ) {
throw too_old_memorial_file_error( "memorial file lacks game_start event" );
}
debugmsg( "Unexpected number of game start events: %d\n", counts.size() );
return;
}
Expand Down Expand Up @@ -99,6 +107,8 @@ void past_games_info::ensure_loaded()
info_.push_back( past_game_info( jsin ) );
} catch( const JsonError &err ) {
debugmsg( "Error reading memorial file %s: %s", filename, err.what() );
} catch( const too_old_memorial_file_error & ) {
// do nothing
}
}

Expand Down