Update Achievement Sort and Progress on RP

Whenever a request to update the Rich Presence comes in, typically every ten seconds, the Achievement Progress Widget will update the sort order of the achievements and all of their measured values.
This commit is contained in:
LillyJadeKatrin 2024-06-20 00:35:46 -04:00
parent 9b9e6c4582
commit 1a33e28452
3 changed files with 40 additions and 33 deletions

View File

@ -61,6 +61,7 @@ AchievementBox::AchievementBox(QWidget* parent, rc_client_achievement_t* achieve
void AchievementBox::UpdateData()
{
{
std::lock_guard lg{AchievementManager::GetInstance().GetLock()};
// rc_client guarantees m_achievement will be valid as long as the game is loaded
if (!AchievementManager::GetInstance().IsGameLoaded())
@ -77,7 +78,8 @@ void AchievementBox::UpdateData()
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)));
m_badge->setStyleSheet(
QStringLiteral("border: 4px solid %1").arg(QtUtils::FromStdString(color)));
if (m_achievement->state == RC_CLIENT_ACHIEVEMENT_STATE_UNLOCKED)
{
@ -89,6 +91,7 @@ void AchievementBox::UpdateData()
{
m_status->setText(tr("Locked"));
}
}
UpdateProgress();
}

View File

@ -51,7 +51,7 @@ void AchievementProgressWidget::UpdateData(bool clean_all)
m_common_layout->removeWidget(widget);
if (std::strcmp(widget->metaObject()->className(), "QLabel") == 0)
{
delete widget;
widget->deleteLater();
delete item;
}
}
@ -64,22 +64,26 @@ void AchievementProgressWidget::UpdateData(bool clean_all)
auto* achievement_list =
rc_client_create_achievement_list(client, RC_CLIENT_ACHIEVEMENT_CATEGORY_CORE_AND_UNOFFICIAL,
RC_CLIENT_ACHIEVEMENT_LIST_GROUPING_PROGRESS);
if (!achievement_list)
return;
for (u32 ix = 0; ix < achievement_list->num_buckets; ix++)
{
m_common_layout->addWidget(new QLabel(tr(achievement_list->buckets[ix].label)));
for (u32 jx = 0; jx < achievement_list->buckets[ix].num_achievements; jx++)
{
auto* achievement = achievement_list->buckets[ix].achievements[jx];
auto box_itr = m_achievement_boxes.find(achievement->id);
if (box_itr == m_achievement_boxes.end())
auto box_itr = m_achievement_boxes.lower_bound(achievement->id);
if (box_itr != m_achievement_boxes.end() && box_itr->first == achievement->id)
{
m_achievement_boxes[achievement->id] = std::make_shared<AchievementBox>(this, achievement);
box_itr->second->UpdateProgress();
m_common_layout->addWidget(box_itr->second.get());
}
else
{
box_itr->second->UpdateProgress();
const auto new_box_itr = m_achievement_boxes.try_emplace(
box_itr, achievement->id, std::make_shared<AchievementBox>(this, achievement));
m_common_layout->addWidget(new_box_itr->second.get());
}
m_common_layout->addWidget(m_achievement_boxes[achievement->id].get());
}
}
rc_client_destroy_achievement_list(achievement_list);

View File

@ -89,7 +89,7 @@ void AchievementsWindow::UpdateData(AchievementManager::UpdatedItems updated_ite
{
m_header_widget->UpdateData();
}
if (updated_items.all_achievements)
if (updated_items.all_achievements || updated_items.rich_presence)
m_progress_widget->UpdateData(false);
else if (updated_items.achievements.size() > 0)
m_progress_widget->UpdateData(updated_items.achievements);