Handle Achievement Progress Event

Added handling to Achievement Progress Events, which are generated when an achievement with a Measured field updates in value. For example, an achievement for collecting 120 stars will throw this event when the player collects each star, and with this handling, the player will get a message on screen informing them of this progress. This message will only appear if the newly added RA_PROGRESS_ENABLED setting is true.
This commit is contained in:
LillyJadeKatrin 2023-06-16 20:27:04 -04:00
parent b2e016f012
commit 6d96b7173e
5 changed files with 33 additions and 0 deletions

View file

@ -606,6 +606,9 @@ void AchievementManager::AchievementEventHandler(const rc_runtime_event_t* runti
case RC_RUNTIME_EVENT_ACHIEVEMENT_TRIGGERED:
HandleAchievementTriggeredEvent(runtime_event);
break;
case RC_RUNTIME_EVENT_ACHIEVEMENT_PROGRESS_UPDATED:
HandleAchievementProgressUpdatedEvent(runtime_event);
break;
case RC_RUNTIME_EVENT_LBOARD_STARTED:
HandleLeaderboardStartedEvent(runtime_event);
break;
@ -1104,6 +1107,31 @@ void AchievementManager::HandleAchievementTriggeredEvent(const rc_runtime_event_
Config::Get(Config::RA_ENCORE_ENABLED));
}
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::VERY_LONG, OSD::Color::GREEN);
}
void AchievementManager::HandleLeaderboardStartedEvent(const rc_runtime_event_t* runtime_event)
{
for (u32 ix = 0; ix < m_game_data.num_leaderboards; ix++)

View file

@ -137,6 +137,7 @@ private:
ResponseType PingRichPresence(const RichPresence& rich_presence);
void HandleAchievementTriggeredEvent(const rc_runtime_event_t* runtime_event);
void HandleAchievementProgressUpdatedEvent(const rc_runtime_event_t* runtime_event);
void HandleLeaderboardStartedEvent(const rc_runtime_event_t* runtime_event);
void HandleLeaderboardCanceledEvent(const rc_runtime_event_t* runtime_event);
void HandleLeaderboardTriggeredEvent(const rc_runtime_event_t* runtime_event);

View file

@ -19,6 +19,8 @@ const Info<bool> RA_LEADERBOARDS_ENABLED{
{System::Achievements, "Achievements", "LeaderboardsEnabled"}, false};
const Info<bool> RA_RICH_PRESENCE_ENABLED{
{System::Achievements, "Achievements", "RichPresenceEnabled"}, false};
const Info<bool> RA_PROGRESS_ENABLED{{System::Achievements, "Achievements", "ProgressEnabled"},
false};
const Info<bool> RA_BADGES_ENABLED{{System::Achievements, "Achievements", "BadgesEnabled"}, false};
const Info<bool> RA_UNOFFICIAL_ENABLED{{System::Achievements, "Achievements", "UnofficialEnabled"},
false};

View file

@ -14,6 +14,7 @@ extern const Info<std::string> RA_API_TOKEN;
extern const Info<bool> RA_ACHIEVEMENTS_ENABLED;
extern const Info<bool> RA_LEADERBOARDS_ENABLED;
extern const Info<bool> RA_RICH_PRESENCE_ENABLED;
extern const Info<bool> RA_PROGRESS_ENABLED;
extern const Info<bool> RA_BADGES_ENABLED;
extern const Info<bool> RA_UNOFFICIAL_ENABLED;
extern const Info<bool> RA_ENCORE_ENABLED;

View file

@ -47,6 +47,7 @@ bool IsSettingSaveable(const Config::Location& config_location)
&Config::RA_ACHIEVEMENTS_ENABLED.GetLocation(),
&Config::RA_LEADERBOARDS_ENABLED.GetLocation(),
&Config::RA_RICH_PRESENCE_ENABLED.GetLocation(),
&Config::RA_PROGRESS_ENABLED.GetLocation(),
&Config::RA_BADGES_ENABLED.GetLocation(),
&Config::RA_UNOFFICIAL_ENABLED.GetLocation(),
&Config::RA_ENCORE_ENABLED.GetLocation(),