Add Default Achievement Badges

The defaults get loaded in by Dolphin at emulator start, and are used if the badge that would normally be displayed has not for whatever reason been downloaded yet. Badges attached to this PR are placeholders (MayIMilae is designing permanent badges) and reside in Sys\Load\RetroAchievements.
This commit is contained in:
LillyJadeKatrin 2024-05-13 18:53:06 -04:00 committed by Admiral H. Curtiss
parent dc8f3f6eae
commit 3b61b6d816
No known key found for this signature in database
GPG Key ID: F051B4C4044F33FB
6 changed files with 78 additions and 20 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 460 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 235 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 335 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 235 B

View File

@ -13,6 +13,8 @@
#include <rcheevos/include/rc_api_info.h> #include <rcheevos/include/rc_api_info.h>
#include <rcheevos/include/rc_hash.h> #include <rcheevos/include/rc_hash.h>
#include "Common/CommonPaths.h"
#include "Common/FileUtil.h"
#include "Common/Image.h" #include "Common/Image.h"
#include "Common/Logging/Log.h" #include "Common/Logging/Log.h"
#include "Common/ScopeGuard.h" #include "Common/ScopeGuard.h"
@ -35,6 +37,7 @@ AchievementManager& AchievementManager::GetInstance()
void AchievementManager::Init() void AchievementManager::Init()
{ {
LoadDefaultBadges();
if (!m_client && Config::Get(Config::RA_ENABLED)) if (!m_client && Config::Get(Config::RA_ENABLED))
{ {
m_client = rc_client_create(MemoryPeeker, Request); m_client = rc_client_create(MemoryPeeker, Request);
@ -499,6 +502,55 @@ void AchievementManager::FilereaderClose(void* file_handle)
delete static_cast<FilereaderState*>(file_handle); delete static_cast<FilereaderState*>(file_handle);
} }
void AchievementManager::LoadDefaultBadges()
{
std::lock_guard lg{m_lock};
std::string directory = File::GetSysDirectory() + DIR_SEP + RESOURCES_DIR + DIR_SEP;
if (m_default_player_badge.data.empty())
{
if (!LoadPNGTexture(&m_default_player_badge,
fmt::format("{}{}", directory, DEFAULT_PLAYER_BADGE_FILENAME)))
{
ERROR_LOG_FMT(ACHIEVEMENTS, "Default player badge '{}' failed to load",
DEFAULT_PLAYER_BADGE_FILENAME);
}
}
m_player_badge.badge = m_default_player_badge;
if (m_default_game_badge.data.empty())
{
if (!LoadPNGTexture(&m_default_game_badge,
fmt::format("{}{}", directory, DEFAULT_GAME_BADGE_FILENAME)))
{
ERROR_LOG_FMT(ACHIEVEMENTS, "Default game badge '{}' failed to load",
DEFAULT_GAME_BADGE_FILENAME);
}
}
m_game_badge.badge = m_default_game_badge;
if (m_default_unlocked_badge.data.empty())
{
if (!LoadPNGTexture(&m_default_unlocked_badge,
fmt::format("{}{}", directory, DEFAULT_UNLOCKED_BADGE_FILENAME)))
{
ERROR_LOG_FMT(ACHIEVEMENTS, "Default unlocked achievement badge '{}' failed to load",
DEFAULT_UNLOCKED_BADGE_FILENAME);
}
}
if (m_default_locked_badge.data.empty())
{
if (!LoadPNGTexture(&m_default_locked_badge,
fmt::format("{}{}", directory, DEFAULT_LOCKED_BADGE_FILENAME)))
{
ERROR_LOG_FMT(ACHIEVEMENTS, "Default locked achievement badge '{}' failed to load",
DEFAULT_LOCKED_BADGE_FILENAME);
}
}
}
void AchievementManager::LoginCallback(int result, const char* error_message, rc_client_t* client, void AchievementManager::LoginCallback(int result, const char* error_message, rc_client_t* client,
void* userdata) void* userdata)
{ {
@ -669,14 +721,13 @@ void AchievementManager::DisplayWelcomeMessage()
void AchievementManager::HandleAchievementTriggeredEvent(const rc_client_event_t* client_event) void AchievementManager::HandleAchievementTriggeredEvent(const rc_client_event_t* client_event)
{ {
OSD::AddMessage( const auto& instance = AchievementManager::GetInstance();
fmt::format("Unlocked: {} ({})", client_event->achievement->title, OSD::AddMessage(fmt::format("Unlocked: {} ({})", client_event->achievement->title,
client_event->achievement->points), client_event->achievement->points),
OSD::Duration::VERY_LONG, OSD::Duration::VERY_LONG,
(rc_client_get_hardcore_enabled(AchievementManager::GetInstance().m_client)) ? (rc_client_get_hardcore_enabled(instance.m_client)) ? OSD::Color::YELLOW :
OSD::Color::YELLOW : OSD::Color::CYAN,
OSD::Color::CYAN, &instance.GetAchievementBadge(client_event->achievement->id, false).badge);
&AchievementManager::GetInstance().m_unlocked_badges[client_event->achievement->id].badge);
} }
void AchievementManager::HandleLeaderboardStartedEvent(const rc_client_event_t* client_event) void AchievementManager::HandleLeaderboardStartedEvent(const rc_client_event_t* client_event)
@ -733,13 +784,11 @@ void AchievementManager::HandleLeaderboardTrackerHideEvent(const rc_client_event
void AchievementManager::HandleAchievementChallengeIndicatorShowEvent( void AchievementManager::HandleAchievementChallengeIndicatorShowEvent(
const rc_client_event_t* client_event) const rc_client_event_t* client_event)
{ {
auto& unlocked_badges = AchievementManager::GetInstance().m_unlocked_badges; auto& instance = AchievementManager::GetInstance();
if (const auto unlocked_iter = unlocked_badges.find(client_event->achievement->id); instance.m_active_challenges[client_event->achievement->badge_name] =
unlocked_iter != unlocked_badges.end()) &AchievementManager::GetInstance()
{ .GetAchievementBadge(client_event->achievement->id, false)
AchievementManager::GetInstance().m_active_challenges[client_event->achievement->badge_name] = .badge;
&unlocked_iter->second.badge;
}
} }
void AchievementManager::HandleAchievementChallengeIndicatorHideEvent( void AchievementManager::HandleAchievementChallengeIndicatorHideEvent(
@ -752,11 +801,11 @@ void AchievementManager::HandleAchievementChallengeIndicatorHideEvent(
void AchievementManager::HandleAchievementProgressIndicatorShowEvent( void AchievementManager::HandleAchievementProgressIndicatorShowEvent(
const rc_client_event_t* client_event) const rc_client_event_t* client_event)
{ {
OSD::AddMessage( const auto& instance = AchievementManager::GetInstance();
fmt::format("{} {}", client_event->achievement->title, OSD::AddMessage(fmt::format("{} {}", client_event->achievement->title,
client_event->achievement->measured_progress), client_event->achievement->measured_progress),
OSD::Duration::SHORT, OSD::Color::GREEN, OSD::Duration::SHORT, OSD::Color::GREEN,
&AchievementManager::GetInstance().m_unlocked_badges[client_event->achievement->id].badge); &instance.GetAchievementBadge(client_event->achievement->id, false).badge);
} }
void AchievementManager::HandleGameCompletedEvent(const rc_client_event_t* client_event, void AchievementManager::HandleGameCompletedEvent(const rc_client_event_t* client_event,

View File

@ -53,6 +53,10 @@ public:
Badge badge{}; Badge badge{};
}; };
static constexpr std::string_view DEFAULT_PLAYER_BADGE_FILENAME = "achievements_player.png";
static constexpr std::string_view DEFAULT_GAME_BADGE_FILENAME = "achievements_game.png";
static constexpr std::string_view DEFAULT_LOCKED_BADGE_FILENAME = "achievements_locked.png";
static constexpr std::string_view DEFAULT_UNLOCKED_BADGE_FILENAME = "achievements_unlocked.png";
static constexpr std::string_view GRAY = "transparent"; static constexpr std::string_view GRAY = "transparent";
static constexpr std::string_view GOLD = "#FFD700"; static constexpr std::string_view GOLD = "#FFD700";
static constexpr std::string_view BLUE = "#0B71C1"; static constexpr std::string_view BLUE = "#0B71C1";
@ -137,6 +141,7 @@ private:
static size_t FilereaderRead(void* file_handle, void* buffer, size_t requested_bytes); static size_t FilereaderRead(void* file_handle, void* buffer, size_t requested_bytes);
static void FilereaderClose(void* file_handle); static void FilereaderClose(void* file_handle);
void LoadDefaultBadges();
static void LoginCallback(int result, const char* error_message, rc_client_t* client, static void LoginCallback(int result, const char* error_message, rc_client_t* client,
void* userdata); void* userdata);
@ -181,6 +186,10 @@ private:
bool m_is_runtime_initialized = false; bool m_is_runtime_initialized = false;
UpdateCallback m_update_callback = [](const UpdatedItems&) {}; UpdateCallback m_update_callback = [](const UpdatedItems&) {};
std::unique_ptr<DiscIO::Volume> m_loading_volume; std::unique_ptr<DiscIO::Volume> m_loading_volume;
Badge m_default_player_badge;
Badge m_default_game_badge;
Badge m_default_unlocked_badge;
Badge m_default_locked_badge;
BadgeStatus m_player_badge; BadgeStatus m_player_badge;
Hash m_game_hash{}; Hash m_game_hash{};
u32 m_game_id = 0; u32 m_game_id = 0;