diff --git a/Source/Core/Core/AchievementManager.cpp b/Source/Core/Core/AchievementManager.cpp index 61f002209a..a0715f3ea5 100644 --- a/Source/Core/Core/AchievementManager.cpp +++ b/Source/Core/Core/AchievementManager.cpp @@ -40,7 +40,7 @@ void AchievementManager::Init() std::string host_url = Config::Get(Config::RA_HOST_URL); if (!host_url.empty()) rc_client_set_host(m_client, host_url.c_str()); - rc_client_set_event_handler(m_client, EventHandlerV2); + rc_client_set_event_handler(m_client, EventHandler); rc_client_enable_logging(m_client, RC_CLIENT_LOG_LEVEL_VERBOSE, [](const char* message, const rc_client_t* client) { INFO_LOG_FMT(ACHIEVEMENTS, "{}", message); @@ -230,16 +230,6 @@ void AchievementManager::DoFrame() } } -void AchievementManager::AchievementEventHandler(const rc_runtime_event_t* runtime_event) -{ - switch (runtime_event->type) - { - case RC_RUNTIME_EVENT_ACHIEVEMENT_PROGRESS_UPDATED: - HandleAchievementProgressUpdatedEvent(runtime_event); - break; - } -} - std::recursive_mutex& AchievementManager::GetLock() { return m_lock; @@ -740,34 +730,6 @@ void AchievementManager::DisplayWelcomeMessage() OSD::Duration::VERY_LONG, color); } -void AchievementManager::HandleAchievementProgressUpdatedEvent( - const rc_runtime_event_t* runtime_event) -{ - if (!Config::Get(Config::RA_PROGRESS_ENABLED)) - return; - auto it = m_unlock_map.find(runtime_event->id); - if (it == m_unlock_map.end()) - { - ERROR_LOG_FMT(ACHIEVEMENTS, "Invalid achievement progress updated event with id {}.", - runtime_event->id); - return; - } - AchievementId game_data_index = it->second.game_data_index; - FormattedValue value{}; - if (rc_runtime_format_achievement_measured(&m_runtime, runtime_event->id, value.data(), - FORMAT_SIZE) == 0) - { - ERROR_LOG_FMT(ACHIEVEMENTS, "Failed to format measured data {}.", value.data()); - return; - } - OSD::AddMessage( - fmt::format("{} {}", m_game_data.achievements[game_data_index].title, value.data()), - OSD::Duration::SHORT, OSD::Color::GREEN, - (Config::Get(Config::RA_BADGES_ENABLED)) ? - DecodeBadgeToOSDIcon(it->second.unlocked_badge.badge) : - nullptr); -} - void AchievementManager::HandleAchievementTriggeredEvent(const rc_client_event_t* client_event) { OSD::AddMessage(fmt::format("Unlocked: {} ({})", client_event->achievement->title, @@ -853,6 +815,19 @@ void AchievementManager::HandleAchievementChallengeIndicatorHideEvent( client_event->achievement->badge_name); } +void AchievementManager::HandleAchievementProgressIndicatorShowEvent( + const rc_client_event_t* client_event) +{ + OSD::AddMessage(fmt::format("{} {}", client_event->achievement->title, + client_event->achievement->measured_progress), + OSD::Duration::SHORT, OSD::Color::GREEN, + (Config::Get(Config::RA_BADGES_ENABLED)) ? + DecodeBadgeToOSDIcon(AchievementManager::GetInstance() + .m_unlocked_badges[client_event->achievement->id] + .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 @@ -1033,7 +1008,7 @@ void AchievementManager::FetchBadge(AchievementManager::BadgeStatus* badge, u32 }); } -void AchievementManager::EventHandlerV2(const rc_client_event_t* event, rc_client_t* client) +void AchievementManager::EventHandler(const rc_client_event_t* event, rc_client_t* client) { switch (event->type) { @@ -1064,6 +1039,14 @@ void AchievementManager::EventHandlerV2(const rc_client_event_t* event, rc_clien case RC_CLIENT_EVENT_ACHIEVEMENT_CHALLENGE_INDICATOR_HIDE: HandleAchievementChallengeIndicatorHideEvent(event); break; + case RC_CLIENT_EVENT_ACHIEVEMENT_PROGRESS_INDICATOR_SHOW: + case RC_CLIENT_EVENT_ACHIEVEMENT_PROGRESS_INDICATOR_UPDATE: + HandleAchievementProgressIndicatorShowEvent(event); + break; + case RC_CLIENT_EVENT_ACHIEVEMENT_PROGRESS_INDICATOR_HIDE: + // OnScreenDisplay messages disappear over time, so this is unnecessary + // unless the display algorithm changes in the future. + 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 5292cc182e..addc3aff49 100644 --- a/Source/Core/Core/AchievementManager.h +++ b/Source/Core/Core/AchievementManager.h @@ -128,7 +128,6 @@ public: void FetchGameBadges(); void DoFrame(); - void AchievementEventHandler(const rc_runtime_event_t* runtime_event); std::recursive_mutex& GetLock(); bool IsHardcoreModeActive() const; @@ -184,8 +183,6 @@ private: void* userdata); void DisplayWelcomeMessage(); - void HandleAchievementProgressUpdatedEvent(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); static void HandleLeaderboardFailedEvent(const rc_client_event_t* client_event); @@ -195,6 +192,7 @@ private: 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); + static void HandleAchievementProgressIndicatorShowEvent(const rc_client_event_t* client_event); template ResponseType Request(RcRequest rc_request, RcResponse* rc_response, @@ -205,7 +203,7 @@ private: void* callback_data, rc_client_t* client); static u32 MemoryPeeker(u32 address, u8* buffer, u32 num_bytes, rc_client_t* client); void FetchBadge(BadgeStatus* badge, u32 badge_type, const BadgeNameFunction function); - static void EventHandlerV2(const rc_client_event_t* event, rc_client_t* client); + static void EventHandler(const rc_client_event_t* event, rc_client_t* client); rc_runtime_t m_runtime{}; rc_client_t* m_client{};