Refactored AchievementProgress UpdateData to Re-Sort
When AchievementProgress::UpdateData(false) is called, it will now empty itself and reinsert all existing boxes, re-sorted into their current buckets, and call UpdateProgress on them all.
This commit is contained in:
parent
75c2360aea
commit
9b9e6c4582
|
@ -62,6 +62,9 @@ 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())
|
||||
return;
|
||||
|
||||
const auto& badge = AchievementManager::GetInstance().GetAchievementBadge(
|
||||
m_achievement->id, m_achievement->state != RC_CLIENT_ACHIEVEMENT_STATE_UNLOCKED);
|
||||
|
@ -92,6 +95,11 @@ void AchievementBox::UpdateData()
|
|||
|
||||
void AchievementBox::UpdateProgress()
|
||||
{
|
||||
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())
|
||||
return;
|
||||
|
||||
if (m_achievement->measured_percent > 0.000)
|
||||
{
|
||||
m_progress_bar->setRange(0, 100);
|
||||
|
|
|
@ -42,33 +42,47 @@ void AchievementProgressWidget::UpdateData(bool clean_all)
|
|||
{
|
||||
m_achievement_boxes.clear();
|
||||
ClearLayoutRecursively(m_common_layout);
|
||||
|
||||
auto& instance = AchievementManager::GetInstance();
|
||||
if (!instance.IsGameLoaded())
|
||||
return;
|
||||
auto* client = instance.GetClient();
|
||||
auto* achievement_list = rc_client_create_achievement_list(
|
||||
client, RC_CLIENT_ACHIEVEMENT_CATEGORY_CORE_AND_UNOFFICIAL,
|
||||
RC_CLIENT_ACHIEVEMENT_LIST_GROUPING_PROGRESS);
|
||||
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];
|
||||
m_achievement_boxes[achievement->id] = std::make_shared<AchievementBox>(this, achievement);
|
||||
m_common_layout->addWidget(m_achievement_boxes[achievement->id].get());
|
||||
}
|
||||
}
|
||||
rc_client_destroy_achievement_list(achievement_list);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (auto box : m_achievement_boxes)
|
||||
while (auto* item = m_common_layout->takeAt(0))
|
||||
{
|
||||
box.second->UpdateData();
|
||||
auto* widget = item->widget();
|
||||
m_common_layout->removeWidget(widget);
|
||||
if (std::strcmp(widget->metaObject()->className(), "QLabel") == 0)
|
||||
{
|
||||
delete widget;
|
||||
delete item;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
auto& instance = AchievementManager::GetInstance();
|
||||
if (!instance.IsGameLoaded())
|
||||
return;
|
||||
auto* client = instance.GetClient();
|
||||
auto* achievement_list =
|
||||
rc_client_create_achievement_list(client, RC_CLIENT_ACHIEVEMENT_CATEGORY_CORE_AND_UNOFFICIAL,
|
||||
RC_CLIENT_ACHIEVEMENT_LIST_GROUPING_PROGRESS);
|
||||
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())
|
||||
{
|
||||
m_achievement_boxes[achievement->id] = std::make_shared<AchievementBox>(this, achievement);
|
||||
}
|
||||
else
|
||||
{
|
||||
box_itr->second->UpdateProgress();
|
||||
}
|
||||
m_common_layout->addWidget(m_achievement_boxes[achievement->id].get());
|
||||
}
|
||||
}
|
||||
rc_client_destroy_achievement_list(achievement_list);
|
||||
}
|
||||
|
||||
void AchievementProgressWidget::UpdateData(
|
||||
|
|
Loading…
Reference in New Issue