Handle Achievement Challenge Indicator Show/Hide Client Events

Also deletes the corresponding runtime-based events from the old event handler.
This commit is contained in:
LillyJadeKatrin 2024-04-01 14:30:39 -04:00
parent 7895b739ee
commit a70733f74f
2 changed files with 30 additions and 36 deletions

View File

@ -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;

View File

@ -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 <typename RcRequest, typename RcResponse>
ResponseType Request(RcRequest rc_request, RcResponse* rc_response,