Remove names from badge objects

The names attached to the BadgeStatus object are obsolete and unneeded and are removed from everything that uses them. All BadgeStatus references are updated to just Badge.
This commit is contained in:
LillyJadeKatrin 2024-05-13 19:21:55 -04:00 committed by Admiral H. Curtiss
parent 3b61b6d816
commit 1e9e0cd2d7
No known key found for this signature in database
GPG Key ID: F051B4C4044F33FB
4 changed files with 58 additions and 79 deletions

View File

@ -280,7 +280,7 @@ u32 AchievementManager::GetPlayerScore() const
return user->score;
}
const AchievementManager::BadgeStatus& AchievementManager::GetPlayerBadge() const
const AchievementManager::Badge& AchievementManager::GetPlayerBadge() const
{
return m_player_badge;
}
@ -300,17 +300,19 @@ rc_api_fetch_game_data_response_t* AchievementManager::GetGameData()
return &m_game_data;
}
const AchievementManager::BadgeStatus& AchievementManager::GetGameBadge() const
const AchievementManager::Badge& AchievementManager::GetGameBadge() const
{
return m_game_badge;
}
const AchievementManager::BadgeStatus& AchievementManager::GetAchievementBadge(AchievementId id,
bool locked) const
const AchievementManager::Badge& AchievementManager::GetAchievementBadge(AchievementId id,
bool locked) const
{
auto& badge_list = locked ? m_locked_badges : m_unlocked_badges;
// Brief regression - difficult to return a default BadgeStatus, will be fixed in later commit
return badge_list.find(id)->second;
auto itr = badge_list.find(id);
return (itr != badge_list.end() && itr->second.data.size() > 0) ?
itr->second :
(locked ? m_default_locked_badge : m_default_unlocked_badge);
}
const AchievementManager::LeaderboardStatus*
@ -395,7 +397,9 @@ void AchievementManager::CloseGame()
{
m_active_challenges.clear();
m_active_leaderboards.clear();
m_game_badge.name.clear();
m_game_badge.width = 0;
m_game_badge.height = 0;
m_game_badge.data.clear();
m_unlocked_badges.clear();
m_locked_badges.clear();
m_leaderboard_map.clear();
@ -417,7 +421,9 @@ void AchievementManager::Logout()
{
std::lock_guard lg{m_lock};
CloseGame();
m_player_badge.name.clear();
m_player_badge.width = 0;
m_player_badge.height = 0;
m_player_badge.data.clear();
Config::SetBaseOrCurrent(Config::RA_API_TOKEN, "");
}
@ -517,7 +523,7 @@ void AchievementManager::LoadDefaultBadges()
DEFAULT_PLAYER_BADGE_FILENAME);
}
}
m_player_badge.badge = m_default_player_badge;
m_player_badge = m_default_player_badge;
if (m_default_game_badge.data.empty())
{
@ -528,7 +534,7 @@ void AchievementManager::LoadDefaultBadges()
DEFAULT_GAME_BADGE_FILENAME);
}
}
m_game_badge.badge = m_default_game_badge;
m_game_badge = m_default_game_badge;
if (m_default_unlocked_badge.data.empty())
{
@ -688,10 +694,8 @@ void AchievementManager::DisplayWelcomeMessage()
m_display_welcome_message = false;
const u32 color =
rc_client_get_hardcore_enabled(m_client) ? OSD::Color::YELLOW : OSD::Color::CYAN;
if (!m_game_badge.name.empty())
{
OSD::AddMessage("", OSD::Duration::VERY_LONG, OSD::Color::GREEN, &m_game_badge.badge);
}
OSD::AddMessage("", OSD::Duration::VERY_LONG, OSD::Color::GREEN, &m_game_badge);
auto info = rc_client_get_game_info(m_client);
if (!info)
{
@ -727,7 +731,7 @@ void AchievementManager::HandleAchievementTriggeredEvent(const rc_client_event_t
OSD::Duration::VERY_LONG,
(rc_client_get_hardcore_enabled(instance.m_client)) ? OSD::Color::YELLOW :
OSD::Color::CYAN,
&instance.GetAchievementBadge(client_event->achievement->id, false).badge);
&instance.GetAchievementBadge(client_event->achievement->id, false));
}
void AchievementManager::HandleLeaderboardStartedEvent(const rc_client_event_t* client_event)
@ -786,9 +790,7 @@ void AchievementManager::HandleAchievementChallengeIndicatorShowEvent(
{
auto& instance = AchievementManager::GetInstance();
instance.m_active_challenges[client_event->achievement->badge_name] =
&AchievementManager::GetInstance()
.GetAchievementBadge(client_event->achievement->id, false)
.badge;
&AchievementManager::GetInstance().GetAchievementBadge(client_event->achievement->id, false);
}
void AchievementManager::HandleAchievementChallengeIndicatorHideEvent(
@ -805,7 +807,7 @@ void AchievementManager::HandleAchievementProgressIndicatorShowEvent(
OSD::AddMessage(fmt::format("{} {}", client_event->achievement->title,
client_event->achievement->measured_progress),
OSD::Duration::SHORT, OSD::Color::GREEN,
&instance.GetAchievementBadge(client_event->achievement->id, false).badge);
&instance.GetAchievementBadge(client_event->achievement->id, false));
}
void AchievementManager::HandleGameCompletedEvent(const rc_client_event_t* client_event,
@ -822,7 +824,7 @@ void AchievementManager::HandleGameCompletedEvent(const rc_client_event_t* clien
OSD::AddMessage(fmt::format("Congratulations! {} has {} {}", user_info->display_name,
hardcore ? "mastered" : "completed", game_info->title),
OSD::Duration::VERY_LONG, hardcore ? OSD::Color::YELLOW : OSD::Color::CYAN,
&AchievementManager::GetInstance().m_game_badge.badge);
&AchievementManager::GetInstance().m_game_badge);
}
void AchievementManager::HandleResetEvent(const rc_client_event_t* client_event)
@ -898,7 +900,7 @@ u32 AchievementManager::MemoryPeeker(u32 address, u8* buffer, u32 num_bytes, rc_
return num_bytes;
}
void AchievementManager::FetchBadge(AchievementManager::BadgeStatus* badge, u32 badge_type,
void AchievementManager::FetchBadge(AchievementManager::Badge* badge, u32 badge_type,
const AchievementManager::BadgeNameFunction function,
const UpdatedItems callback_data)
{
@ -954,12 +956,11 @@ void AchievementManager::FetchBadge(AchievementManager::BadgeStatus* badge, u32
return;
}
if (!LoadPNGTexture(&badge->badge, *http_response))
if (!LoadPNGTexture(badge, *http_response))
{
ERROR_LOG_FMT(ACHIEVEMENTS, "Default game badge '{}' failed to load",
DEFAULT_GAME_BADGE_FILENAME);
}
badge->name = std::move(name_to_fetch);
m_update_callback(callback_data);
});

View File

@ -47,12 +47,6 @@ public:
using NamedBadgeMap = std::unordered_map<std::string, const Badge*>;
static constexpr size_t MAX_DISPLAYED_LBOARDS = 4;
struct BadgeStatus
{
std::string name = "";
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";
@ -108,12 +102,12 @@ public:
void SetSpectatorMode();
std::string_view GetPlayerDisplayName() const;
u32 GetPlayerScore() const;
const BadgeStatus& GetPlayerBadge() const;
const Badge& GetPlayerBadge() const;
std::string_view GetGameDisplayName() const;
rc_client_t* GetClient();
rc_api_fetch_game_data_response_t* GetGameData();
const BadgeStatus& GetGameBadge() const;
const BadgeStatus& GetAchievementBadge(AchievementId id, bool locked) const;
const Badge& GetGameBadge() const;
const Badge& GetAchievementBadge(AchievementId id, bool locked) const;
const LeaderboardStatus* GetLeaderboardInfo(AchievementId leaderboard_id);
RichPresence GetRichPresence() const;
const NamedBadgeMap& GetChallengeIcons() const;
@ -176,7 +170,7 @@ private:
static void Request(const rc_api_request_t* request, rc_client_server_callback_t callback,
void* callback_data, rc_client_t* client);
static u32 MemoryPeeker(u32 address, u8* buffer, u32 num_bytes, rc_client_t* client);
void FetchBadge(BadgeStatus* badge, u32 badge_type, const BadgeNameFunction function,
void FetchBadge(Badge* badge, u32 badge_type, const BadgeNameFunction function,
const UpdatedItems callback_data);
static void EventHandler(const rc_client_event_t* event, rc_client_t* client);
@ -190,15 +184,15 @@ private:
Badge m_default_game_badge;
Badge m_default_unlocked_badge;
Badge m_default_locked_badge;
BadgeStatus m_player_badge;
Badge m_player_badge;
Hash m_game_hash{};
u32 m_game_id = 0;
rc_api_fetch_game_data_response_t m_game_data{};
bool m_is_game_loaded = false;
BadgeStatus m_game_badge;
Badge 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;
std::unordered_map<AchievementId, Badge> m_unlocked_badges;
std::unordered_map<AchievementId, Badge> m_locked_badges;
RichPresence m_rich_presence;
std::chrono::steady_clock::time_point m_last_rp_time = std::chrono::steady_clock::now();

View File

@ -61,20 +61,11 @@ void AchievementBox::UpdateData()
color = AchievementManager::GOLD;
else if (m_achievement->unlocked & RC_CLIENT_ACHIEVEMENT_UNLOCKED_SOFTCORE)
color = AchievementManager::BLUE;
if (badge.name != "")
{
QImage i_badge(&badge.badge.data.front(), badge.badge.width, badge.badge.height,
QImage::Format_RGBA8888);
m_badge->setPixmap(
QPixmap::fromImage(i_badge).scaled(64, 64, Qt::KeepAspectRatio, Qt::SmoothTransformation));
m_badge->adjustSize();
m_badge->setStyleSheet(
QStringLiteral("border: 4px solid %1").arg(QtUtils::FromStdString(color)));
}
else
{
m_badge->setText({});
}
QImage i_badge(&badge.data.front(), badge.width, badge.height, QImage::Format_RGBA8888);
m_badge->setPixmap(
QPixmap::fromImage(i_badge).scaled(64, 64, Qt::KeepAspectRatio, Qt::SmoothTransformation));
m_badge->adjustSize();
m_badge->setStyleSheet(QStringLiteral("border: 4px solid %1").arg(QtUtils::FromStdString(color)));
if (m_achievement->state == RC_CLIENT_ACHIEVEMENT_STATE_UNLOCKED)
{

View File

@ -68,22 +68,20 @@ void AchievementHeaderWidget::UpdateData()
QString user_name = QtUtils::FromStdString(instance.GetPlayerDisplayName());
QString game_name = QtUtils::FromStdString(instance.GetGameDisplayName());
AchievementManager::BadgeStatus player_badge = instance.GetPlayerBadge();
AchievementManager::BadgeStatus game_badge = instance.GetGameBadge();
const AchievementManager::Badge& player_badge = instance.GetPlayerBadge();
const AchievementManager::Badge& game_badge = instance.GetGameBadge();
m_user_icon->setVisible(false);
m_user_icon->clear();
m_user_icon->setText({});
if (!player_badge.name.empty())
{
QImage i_user_icon(&player_badge.badge.data.front(), player_badge.badge.width,
player_badge.badge.height, QImage::Format_RGBA8888);
m_user_icon->setPixmap(QPixmap::fromImage(i_user_icon)
.scaled(64, 64, Qt::KeepAspectRatio, Qt::SmoothTransformation));
m_user_icon->adjustSize();
m_user_icon->setStyleSheet(QStringLiteral("border: 4px solid transparent"));
m_user_icon->setVisible(true);
}
QImage i_user_icon(&player_badge.data.front(), player_badge.width, player_badge.height,
QImage::Format_RGBA8888);
m_user_icon->setPixmap(QPixmap::fromImage(i_user_icon)
.scaled(64, 64, Qt::KeepAspectRatio, Qt::SmoothTransformation));
m_user_icon->adjustSize();
m_user_icon->setStyleSheet(QStringLiteral("border: 4px solid transparent"));
m_user_icon->setVisible(true);
m_game_icon->setVisible(false);
m_game_icon->clear();
m_game_icon->setText({});
@ -92,24 +90,19 @@ void AchievementHeaderWidget::UpdateData()
{
rc_client_user_game_summary_t game_summary;
rc_client_get_user_game_summary(instance.GetClient(), &game_summary);
if (!game_badge.name.empty())
QImage i_game_icon(&game_badge.data.front(), game_badge.width, game_badge.height,
QImage::Format_RGBA8888);
m_game_icon->setPixmap(QPixmap::fromImage(i_game_icon)
.scaled(64, 64, Qt::KeepAspectRatio, Qt::SmoothTransformation));
m_game_icon->adjustSize();
std::string_view color = AchievementManager::GRAY;
if (game_summary.num_core_achievements == game_summary.num_unlocked_achievements)
{
QImage i_game_icon(&game_badge.badge.data.front(), game_badge.badge.width,
game_badge.badge.height, QImage::Format_RGBA8888);
m_game_icon->setPixmap(QPixmap::fromImage(i_game_icon)
.scaled(64, 64, Qt::KeepAspectRatio, Qt::SmoothTransformation));
m_game_icon->adjustSize();
std::string_view color = AchievementManager::GRAY;
if (game_summary.num_core_achievements == game_summary.num_unlocked_achievements)
{
color =
instance.IsHardcoreModeActive() ? AchievementManager::GOLD : AchievementManager::BLUE;
}
m_game_icon->setStyleSheet(
QStringLiteral("border: 4px solid %1").arg(QtUtils::FromStdString(color)));
m_game_icon->setVisible(true);
color = instance.IsHardcoreModeActive() ? AchievementManager::GOLD : AchievementManager::BLUE;
}
m_game_icon->setStyleSheet(
QStringLiteral("border: 4px solid %1").arg(QtUtils::FromStdString(color)));
m_game_icon->setVisible(true);
m_name->setText(tr("%1 is playing %2").arg(user_name).arg(game_name));
m_points->setText(tr("%1 has unlocked %2/%3 achievements worth %4/%5 points")