|
5 | 5 |
|
6 | 6 | #include "Core/AchievementManager.h" |
7 | 7 |
|
| 8 | +#include <memory> |
| 9 | + |
8 | 10 | #include <fmt/format.h> |
9 | 11 |
|
10 | 12 | #include <rcheevos/include/rc_api_info.h> |
11 | 13 | #include <rcheevos/include/rc_hash.h> |
12 | 14 |
|
13 | 15 | #include "Common/HttpRequest.h" |
| 16 | +#include "Common/Image.h" |
14 | 17 | #include "Common/Logging/Log.h" |
15 | 18 | #include "Common/WorkQueueThread.h" |
16 | 19 | #include "Core/Config/AchievementSettings.h" |
|
23 | 26 |
|
24 | 27 | static constexpr bool hardcore_mode_enabled = false; |
25 | 28 |
|
| 29 | +static std::unique_ptr<OSD::Icon> DecodeBadgeToOSDIcon(const AchievementManager::Badge& badge); |
| 30 | + |
26 | 31 | AchievementManager* AchievementManager::GetInstance() |
27 | 32 | { |
28 | 33 | static AchievementManager s_instance; |
@@ -197,18 +202,23 @@ void AchievementManager::LoadGameByFilenameAsync(const std::string& iso_path, |
197 | 202 | PointSpread spread = TallyScore(); |
198 | 203 | if (hardcore_mode_enabled) |
199 | 204 | { |
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); |
204 | 211 | OSD::AddMessage("Hardcore mode is ON", OSD::Duration::VERY_LONG, OSD::Color::YELLOW); |
205 | 212 | } |
206 | 213 | else |
207 | 214 | { |
208 | 215 | OSD::AddMessage(fmt::format("You have {}/{} achievements worth {}/{} points", |
209 | 216 | spread.hard_unlocks + spread.soft_unlocks, spread.total_count, |
210 | 217 | 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); |
212 | 222 | OSD::AddMessage("Hardcore mode is OFF", OSD::Duration::VERY_LONG, OSD::Color::CYAN); |
213 | 223 | } |
214 | 224 | } |
@@ -1199,19 +1209,26 @@ void AchievementManager::HandleAchievementTriggeredEvent(const rc_runtime_event_ |
1199 | 1209 | OSD::AddMessage(fmt::format("Unlocked: {} ({})", m_game_data.achievements[game_data_index].title, |
1200 | 1210 | m_game_data.achievements[game_data_index].points), |
1201 | 1211 | 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); |
1203 | 1216 | PointSpread spread = TallyScore(); |
1204 | 1217 | if (spread.hard_points == spread.total_points) |
1205 | 1218 | { |
1206 | 1219 | OSD::AddMessage( |
1207 | 1220 | 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); |
1209 | 1224 | } |
1210 | 1225 | else if (spread.hard_points + spread.soft_points == spread.total_points) |
1211 | 1226 | { |
1212 | 1227 | OSD::AddMessage( |
1213 | 1228 | 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); |
1215 | 1232 | } |
1216 | 1233 | ActivateDeactivateAchievement(event_id, Config::Get(Config::RA_ACHIEVEMENTS_ENABLED), |
1217 | 1234 | Config::Get(Config::RA_UNOFFICIAL_ENABLED), |
@@ -1240,7 +1257,10 @@ void AchievementManager::HandleAchievementProgressUpdatedEvent( |
1240 | 1257 | } |
1241 | 1258 | OSD::AddMessage( |
1242 | 1259 | 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); |
1244 | 1264 | } |
1245 | 1265 |
|
1246 | 1266 | 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* |
1388 | 1408 | } |
1389 | 1409 | } |
1390 | 1410 |
|
| 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 | + |
1391 | 1425 | #endif // USE_RETRO_ACHIEVEMENTS |
0 commit comments