From a70733f74f5b337f5da4bc9888cfa3b79d465ce7 Mon Sep 17 00:00:00 2001 From: LillyJadeKatrin Date: Mon, 1 Apr 2024 14:30:39 -0400 Subject: [PATCH] Handle Achievement Challenge Indicator Show/Hide Client Events Also deletes the corresponding runtime-based events from the old event handler. --- Source/Core/Core/AchievementManager.cpp | 62 +++++++++++-------------- Source/Core/Core/AchievementManager.h | 4 +- 2 files changed, 30 insertions(+), 36 deletions(-) diff --git a/Source/Core/Core/AchievementManager.cpp b/Source/Core/Core/AchievementManager.cpp index f3e4b41ba6..61f002209a 100644 --- a/Source/Core/Core/AchievementManager.cpp +++ b/Source/Core/Core/AchievementManager.cpp @@ -237,12 +237,6 @@ void AchievementManager::AchievementEventHandler(const rc_runtime_event_t* runti case RC_RUNTIME_EVENT_ACHIEVEMENT_PROGRESS_UPDATED: HandleAchievementProgressUpdatedEvent(runtime_event); break; - case RC_RUNTIME_EVENT_ACHIEVEMENT_PRIMED: - HandleAchievementPrimedEvent(runtime_event); - break; - case RC_RUNTIME_EVENT_ACHIEVEMENT_UNPRIMED: - HandleAchievementUnprimedEvent(runtime_event); - break; } } @@ -774,34 +768,6 @@ void AchievementManager::HandleAchievementProgressUpdatedEvent( nullptr); } -void AchievementManager::HandleAchievementPrimedEvent(const rc_runtime_event_t* runtime_event) -{ - if (!Config::Get(Config::RA_BADGES_ENABLED)) - return; - auto it = m_unlock_map.find(runtime_event->id); - if (it == m_unlock_map.end()) - { - ERROR_LOG_FMT(ACHIEVEMENTS, "Invalid achievement primed event with id {}.", runtime_event->id); - return; - } - m_active_challenges[it->second.unlocked_badge.name] = - DecodeBadgeToOSDIcon(it->second.unlocked_badge.badge); -} - -void AchievementManager::HandleAchievementUnprimedEvent(const rc_runtime_event_t* runtime_event) -{ - if (!Config::Get(Config::RA_BADGES_ENABLED)) - return; - auto it = m_unlock_map.find(runtime_event->id); - if (it == m_unlock_map.end()) - { - ERROR_LOG_FMT(ACHIEVEMENTS, "Invalid achievement unprimed event with id {}.", - runtime_event->id); - return; - } - m_active_challenges.erase(it->second.unlocked_badge.name); -} - void AchievementManager::HandleAchievementTriggeredEvent(const rc_client_event_t* client_event) { OSD::AddMessage(fmt::format("Unlocked: {} ({})", client_event->achievement->title, @@ -865,6 +831,28 @@ void AchievementManager::HandleLeaderboardTrackerHideEvent(const rc_client_event }); } +void AchievementManager::HandleAchievementChallengeIndicatorShowEvent( + const rc_client_event_t* client_event) +{ + if (Config::Get(Config::RA_BADGES_ENABLED)) + { + auto& unlocked_badges = AchievementManager::GetInstance().m_unlocked_badges; + if (const auto unlocked_iter = unlocked_badges.find(client_event->achievement->id); + unlocked_iter != unlocked_badges.end()) + { + AchievementManager::GetInstance().m_active_challenges[client_event->achievement->badge_name] = + DecodeBadgeToOSDIcon(unlocked_iter->second.badge); + } + } +} + +void AchievementManager::HandleAchievementChallengeIndicatorHideEvent( + const rc_client_event_t* client_event) +{ + AchievementManager::GetInstance().m_active_challenges.erase( + client_event->achievement->badge_name); +} + // 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 @@ -1070,6 +1058,12 @@ void AchievementManager::EventHandlerV2(const rc_client_event_t* event, rc_clien case RC_CLIENT_EVENT_LEADERBOARD_TRACKER_HIDE: HandleLeaderboardTrackerHideEvent(event); break; + case RC_CLIENT_EVENT_ACHIEVEMENT_CHALLENGE_INDICATOR_SHOW: + HandleAchievementChallengeIndicatorShowEvent(event); + break; + case RC_CLIENT_EVENT_ACHIEVEMENT_CHALLENGE_INDICATOR_HIDE: + HandleAchievementChallengeIndicatorHideEvent(event); + 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 a833de0be9..5292cc182e 100644 --- a/Source/Core/Core/AchievementManager.h +++ b/Source/Core/Core/AchievementManager.h @@ -185,8 +185,6 @@ private: void DisplayWelcomeMessage(); void HandleAchievementProgressUpdatedEvent(const rc_runtime_event_t* runtime_event); - void HandleAchievementPrimedEvent(const rc_runtime_event_t* runtime_event); - void HandleAchievementUnprimedEvent(const rc_runtime_event_t* runtime_event); static void HandleAchievementTriggeredEvent(const rc_client_event_t* client_event); static void HandleLeaderboardStartedEvent(const rc_client_event_t* client_event); @@ -195,6 +193,8 @@ private: static void HandleLeaderboardTrackerUpdateEvent(const rc_client_event_t* client_event); static void HandleLeaderboardTrackerShowEvent(const rc_client_event_t* client_event); static void HandleLeaderboardTrackerHideEvent(const rc_client_event_t* client_event); + static void HandleAchievementChallengeIndicatorShowEvent(const rc_client_event_t* client_event); + static void HandleAchievementChallengeIndicatorHideEvent(const rc_client_event_t* client_event); template ResponseType Request(RcRequest rc_request, RcResponse* rc_response,