Skip to content

Commit a3d561f

Browse files
LillyJadeKatrinAdmiralCurtiss
authored andcommitted
Add badges to achievement messages
Updated OSD::AddMessage calls for achievements and game start to pass in the badges intended to be shown.
1 parent c87b2e4 commit a3d561f

File tree

1 file changed

+43
-9
lines changed

1 file changed

+43
-9
lines changed

Source/Core/Core/AchievementManager.cpp

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@
55

66
#include "Core/AchievementManager.h"
77

8+
#include <memory>
9+
810
#include <fmt/format.h>
911

1012
#include <rcheevos/include/rc_api_info.h>
1113
#include <rcheevos/include/rc_hash.h>
1214

1315
#include "Common/HttpRequest.h"
16+
#include "Common/Image.h"
1417
#include "Common/Logging/Log.h"
1518
#include "Common/WorkQueueThread.h"
1619
#include "Core/Config/AchievementSettings.h"
@@ -23,6 +26,8 @@
2326

2427
static constexpr bool hardcore_mode_enabled = false;
2528

29+
static std::unique_ptr<OSD::Icon> DecodeBadgeToOSDIcon(const AchievementManager::Badge& badge);
30+
2631
AchievementManager* AchievementManager::GetInstance()
2732
{
2833
static AchievementManager s_instance;
@@ -197,18 +202,23 @@ void AchievementManager::LoadGameByFilenameAsync(const std::string& iso_path,
197202
PointSpread spread = TallyScore();
198203
if (hardcore_mode_enabled)
199204
{
200-
OSD::AddMessage(fmt::format("You have {}/{} achievements worth {}/{} points",
201-
spread.hard_unlocks, spread.total_count, spread.hard_points,
202-
spread.total_points),
203-
OSD::Duration::VERY_LONG, OSD::Color::YELLOW);
205+
OSD::AddMessage(
206+
fmt::format("You have {}/{} achievements worth {}/{} points", spread.hard_unlocks,
207+
spread.total_count, spread.hard_points, spread.total_points),
208+
OSD::Duration::VERY_LONG, OSD::Color::YELLOW,
209+
(Config::Get(Config::RA_BADGES_ENABLED)) ? DecodeBadgeToOSDIcon(m_game_badge.badge) :
210+
nullptr);
204211
OSD::AddMessage("Hardcore mode is ON", OSD::Duration::VERY_LONG, OSD::Color::YELLOW);
205212
}
206213
else
207214
{
208215
OSD::AddMessage(fmt::format("You have {}/{} achievements worth {}/{} points",
209216
spread.hard_unlocks + spread.soft_unlocks, spread.total_count,
210217
spread.hard_points + spread.soft_points, spread.total_points),
211-
OSD::Duration::VERY_LONG, OSD::Color::CYAN);
218+
OSD::Duration::VERY_LONG, OSD::Color::CYAN,
219+
(Config::Get(Config::RA_BADGES_ENABLED)) ?
220+
DecodeBadgeToOSDIcon(m_game_badge.badge) :
221+
nullptr);
212222
OSD::AddMessage("Hardcore mode is OFF", OSD::Duration::VERY_LONG, OSD::Color::CYAN);
213223
}
214224
}
@@ -1199,19 +1209,26 @@ void AchievementManager::HandleAchievementTriggeredEvent(const rc_runtime_event_
11991209
OSD::AddMessage(fmt::format("Unlocked: {} ({})", m_game_data.achievements[game_data_index].title,
12001210
m_game_data.achievements[game_data_index].points),
12011211
OSD::Duration::VERY_LONG,
1202-
(hardcore_mode_enabled) ? OSD::Color::YELLOW : OSD::Color::CYAN);
1212+
(hardcore_mode_enabled) ? OSD::Color::YELLOW : OSD::Color::CYAN,
1213+
(Config::Get(Config::RA_BADGES_ENABLED)) ?
1214+
DecodeBadgeToOSDIcon(it->second.unlocked_badge.badge) :
1215+
nullptr);
12031216
PointSpread spread = TallyScore();
12041217
if (spread.hard_points == spread.total_points)
12051218
{
12061219
OSD::AddMessage(
12071220
fmt::format("Congratulations! {} has mastered {}", m_display_name, m_game_data.title),
1208-
OSD::Duration::VERY_LONG, OSD::Color::YELLOW);
1221+
OSD::Duration::VERY_LONG, OSD::Color::YELLOW,
1222+
(Config::Get(Config::RA_BADGES_ENABLED)) ? DecodeBadgeToOSDIcon(m_game_badge.badge) :
1223+
nullptr);
12091224
}
12101225
else if (spread.hard_points + spread.soft_points == spread.total_points)
12111226
{
12121227
OSD::AddMessage(
12131228
fmt::format("Congratulations! {} has completed {}", m_display_name, m_game_data.title),
1214-
OSD::Duration::VERY_LONG, OSD::Color::CYAN);
1229+
OSD::Duration::VERY_LONG, OSD::Color::CYAN,
1230+
(Config::Get(Config::RA_BADGES_ENABLED)) ? DecodeBadgeToOSDIcon(m_game_badge.badge) :
1231+
nullptr);
12151232
}
12161233
ActivateDeactivateAchievement(event_id, Config::Get(Config::RA_ACHIEVEMENTS_ENABLED),
12171234
Config::Get(Config::RA_UNOFFICIAL_ENABLED),
@@ -1240,7 +1257,10 @@ void AchievementManager::HandleAchievementProgressUpdatedEvent(
12401257
}
12411258
OSD::AddMessage(
12421259
fmt::format("{} {}", m_game_data.achievements[game_data_index].title, value.data()),
1243-
OSD::Duration::VERY_LONG, OSD::Color::GREEN);
1260+
OSD::Duration::VERY_LONG, OSD::Color::GREEN,
1261+
(Config::Get(Config::RA_BADGES_ENABLED)) ?
1262+
DecodeBadgeToOSDIcon(it->second.unlocked_badge.badge) :
1263+
nullptr);
12441264
}
12451265

12461266
void AchievementManager::HandleLeaderboardStartedEvent(const rc_runtime_event_t* runtime_event)
@@ -1388,4 +1408,18 @@ AchievementManager::RequestImage(rc_api_fetch_image_request_t rc_request, Badge*
13881408
}
13891409
}
13901410

1411+
static std::unique_ptr<OSD::Icon> DecodeBadgeToOSDIcon(const AchievementManager::Badge& badge)
1412+
{
1413+
if (badge.empty())
1414+
return nullptr;
1415+
1416+
auto icon = std::make_unique<OSD::Icon>();
1417+
if (!Common::LoadPNG(badge, &icon->rgba_data, &icon->width, &icon->height))
1418+
{
1419+
ERROR_LOG_FMT(ACHIEVEMENTS, "Error decoding badge.");
1420+
return nullptr;
1421+
}
1422+
return icon;
1423+
}
1424+
13911425
#endif // USE_RETRO_ACHIEVEMENTS

0 commit comments

Comments
 (0)