Skip to content

Commit

Permalink
Merge pull request #12763 from LillyJadeKatrin/retroachievements-welcome
Browse files Browse the repository at this point in the history
Retooled Achievements Welcome Message
  • Loading branch information
AdmiralCurtiss committed May 4, 2024
2 parents 3029d8a + 91764fd commit 98f0f84
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
23 changes: 14 additions & 9 deletions Source/Core/Core/AchievementManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,14 +215,6 @@ void AchievementManager::DoFrame()
{
if (!IsGameLoaded() || !Core::IsCPUThread())
return;
if (m_framecount == 0x200)
{
DisplayWelcomeMessage();
}
if (m_framecount <= 0x200)
{
m_framecount++;
}
{
std::lock_guard lg{m_lock};
rc_client_do_frame(m_client);
Expand Down Expand Up @@ -593,17 +585,22 @@ void AchievementManager::LoadGameCallback(int result, const char* error_message,
if (result != RC_OK)
{
WARN_LOG_FMT(ACHIEVEMENTS, "Failed to load data for current game.");
OSD::AddMessage("Achievements are not supported for this title.", OSD::Duration::VERY_LONG,
OSD::Color::RED);
return;
}

auto* game = rc_client_get_game_info(client);
if (!game)
{
ERROR_LOG_FMT(ACHIEVEMENTS, "Failed to retrieve game information from client.");
OSD::AddMessage("Failed to load achievements for this title.", OSD::Duration::VERY_LONG,
OSD::Color::RED);
return;
}
INFO_LOG_FMT(ACHIEVEMENTS, "Loaded data for game ID {}.", game->id);

AchievementManager::GetInstance().m_display_welcome_message = true;
AchievementManager::GetInstance().FetchGameBadges();
AchievementManager::GetInstance().m_system = &Core::System::GetInstance();
AchievementManager::GetInstance().m_update_callback({.all = true});
Expand Down Expand Up @@ -634,9 +631,10 @@ void AchievementManager::ChangeMediaCallback(int result, const char* error_messa
void AchievementManager::DisplayWelcomeMessage()
{
std::lock_guard lg{m_lock};
m_display_welcome_message = false;
const u32 color =
rc_client_get_hardcore_enabled(m_client) ? OSD::Color::YELLOW : OSD::Color::CYAN;
if (Config::Get(Config::RA_BADGES_ENABLED))
if (Config::Get(Config::RA_BADGES_ENABLED) && !m_game_badge.name.empty())
{
OSD::AddMessage("", OSD::Duration::VERY_LONG, OSD::Color::GREEN,
DecodeBadgeToOSDIcon(m_game_badge.badge));
Expand Down Expand Up @@ -882,11 +880,18 @@ void AchievementManager::FetchBadge(AchievementManager::BadgeStatus* badge, u32
if (!m_client || !HasAPIToken() || !Config::Get(Config::RA_BADGES_ENABLED))
{
m_update_callback(callback_data);
if (m_display_welcome_message && badge_type == RC_IMAGE_TYPE_GAME)
DisplayWelcomeMessage();
return;
}

m_image_queue.EmplaceItem([this, badge, badge_type, function = std::move(function),
callback_data = std::move(callback_data)] {
Common::ScopeGuard on_end_scope([&]() {
if (m_display_welcome_message && badge_type == RC_IMAGE_TYPE_GAME)
DisplayWelcomeMessage();
});

std::string name_to_fetch;
{
std::lock_guard lg{m_lock};
Expand Down
2 changes: 1 addition & 1 deletion Source/Core/Core/AchievementManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@ class AchievementManager
u32 m_game_id = 0;
rc_api_fetch_game_data_response_t m_game_data{};
bool m_is_game_loaded = false;
u32 m_framecount = 0;
BadgeStatus m_game_badge;
bool m_display_welcome_message = false;
std::unordered_map<AchievementId, BadgeStatus> m_unlocked_badges;
std::unordered_map<AchievementId, BadgeStatus> m_locked_badges;
RichPresence m_rich_presence;
Expand Down

0 comments on commit 98f0f84

Please sign in to comment.