From 70116b222d5063e309b06e6f568cc9660ad3e276 Mon Sep 17 00:00:00 2001 From: LillyJadeKatrin Date: Mon, 1 Apr 2024 15:20:35 -0400 Subject: [PATCH] Handle Game Completed Client Event --- Source/Core/Core/AchievementManager.cpp | 22 ++++++++++++++++++++++ Source/Core/Core/AchievementManager.h | 1 + 2 files changed, 23 insertions(+) diff --git a/Source/Core/Core/AchievementManager.cpp b/Source/Core/Core/AchievementManager.cpp index a0715f3ea5..451aa4d49a 100644 --- a/Source/Core/Core/AchievementManager.cpp +++ b/Source/Core/Core/AchievementManager.cpp @@ -828,6 +828,25 @@ void AchievementManager::HandleAchievementProgressIndicatorShowEvent( nullptr); } +void AchievementManager::HandleGameCompletedEvent(const rc_client_event_t* client_event, + rc_client_t* client) +{ + auto* user_info = rc_client_get_user_info(client); + auto* game_info = rc_client_get_game_info(client); + if (!user_info || !game_info) + { + WARN_LOG_FMT(ACHIEVEMENTS, "Received Game Completed event when game not running."); + return; + } + bool hardcore = rc_client_get_hardcore_enabled(client); + OSD::AddMessage(fmt::format("Congratulations! {} has {} {}", user_info->display_name, + hardcore ? "mastered" : "completed", game_info->title), + OSD::Duration::VERY_LONG, hardcore ? OSD::Color::YELLOW : OSD::Color::CYAN, + (Config::Get(Config::RA_BADGES_ENABLED)) ? + DecodeBadgeToOSDIcon(AchievementManager::GetInstance().m_game_badge.badge) : + nullptr); +} + // Every RetroAchievements API call, with only a partial exception for fetch_image, follows // the same design pattern (here, X is the name of the call): // Create a specific rc_api_X_request_t struct and populate with the necessary values @@ -1047,6 +1066,9 @@ void AchievementManager::EventHandler(const rc_client_event_t* event, rc_client_ // OnScreenDisplay messages disappear over time, so this is unnecessary // unless the display algorithm changes in the future. break; + case RC_CLIENT_EVENT_GAME_COMPLETED: + HandleGameCompletedEvent(event, client); + break; default: INFO_LOG_FMT(ACHIEVEMENTS, "Event triggered of unhandled type {}", event->type); break; diff --git a/Source/Core/Core/AchievementManager.h b/Source/Core/Core/AchievementManager.h index addc3aff49..cc2dcda34e 100644 --- a/Source/Core/Core/AchievementManager.h +++ b/Source/Core/Core/AchievementManager.h @@ -193,6 +193,7 @@ private: static void HandleAchievementChallengeIndicatorShowEvent(const rc_client_event_t* client_event); static void HandleAchievementChallengeIndicatorHideEvent(const rc_client_event_t* client_event); static void HandleAchievementProgressIndicatorShowEvent(const rc_client_event_t* client_event); + static void HandleGameCompletedEvent(const rc_client_event_t* client_event, rc_client_t* client); template ResponseType Request(RcRequest rc_request, RcResponse* rc_response,