mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2026-04-29 11:31:00 -05:00
Yellow squiggly lines begone! Done automatically on .cpp files through `run-clang-tidy`, with manual corrections to the mistakes. If an import is directly used, but is technically unnecessary since it's recursively imported by something else, it is *not* removed. The tool doesn't touch .h files, so I did some of them by hand while fixing errors due to old recursive imports. Not everything is removed, but the cleanup should be substantial enough. Because this done on Linux, code that isn't used on it is mostly untouched. (Hopefully no open PR is depending on these imports...)
100 lines
2.8 KiB
C++
100 lines
2.8 KiB
C++
// Copyright 2023 Dolphin Emulator Project
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
#ifdef USE_RETRO_ACHIEVEMENTS
|
|
#include "DolphinQt/Achievements/AchievementProgressWidget.h"
|
|
|
|
#include <QGroupBox>
|
|
#include <QLabel>
|
|
#include <QLineEdit>
|
|
#include <QProgressBar>
|
|
#include <QString>
|
|
#include <QVBoxLayout>
|
|
|
|
#include "Core/AchievementManager.h"
|
|
|
|
#include "DolphinQt/Achievements/AchievementBox.h"
|
|
#include "DolphinQt/QtUtils/ClearLayoutRecursively.h"
|
|
|
|
AchievementProgressWidget::AchievementProgressWidget(QWidget* parent) : QWidget(parent)
|
|
{
|
|
m_common_box = new QGroupBox();
|
|
m_common_layout = new QVBoxLayout();
|
|
|
|
m_common_box->setLayout(m_common_layout);
|
|
|
|
auto* layout = new QVBoxLayout;
|
|
layout->setContentsMargins(0, 0, 0, 0);
|
|
layout->setAlignment(Qt::AlignTop);
|
|
layout->addWidget(m_common_box);
|
|
layout->setSizeConstraint(QLayout::SetFixedSize);
|
|
setLayout(layout);
|
|
}
|
|
|
|
void AchievementProgressWidget::UpdateData(bool clean_all)
|
|
{
|
|
if (clean_all)
|
|
{
|
|
m_achievement_boxes.clear();
|
|
ClearLayoutRecursively(m_common_layout);
|
|
}
|
|
else
|
|
{
|
|
while (auto* item = m_common_layout->takeAt(0))
|
|
{
|
|
auto* widget = item->widget();
|
|
m_common_layout->removeWidget(widget);
|
|
if (std::strcmp(widget->metaObject()->className(), "QLabel") == 0)
|
|
{
|
|
widget->deleteLater();
|
|
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);
|
|
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.lower_bound(achievement->id);
|
|
if (box_itr != m_achievement_boxes.end() && box_itr->first == achievement->id)
|
|
{
|
|
box_itr->second->UpdateProgress();
|
|
m_common_layout->addWidget(box_itr->second.get());
|
|
}
|
|
else
|
|
{
|
|
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());
|
|
}
|
|
}
|
|
}
|
|
rc_client_destroy_achievement_list(achievement_list);
|
|
}
|
|
|
|
void AchievementProgressWidget::UpdateData(
|
|
const std::set<AchievementManager::AchievementId>& update_ids)
|
|
{
|
|
for (auto& [id, box] : m_achievement_boxes)
|
|
{
|
|
if (update_ids.contains(id))
|
|
{
|
|
box->UpdateData();
|
|
}
|
|
}
|
|
}
|
|
|
|
#endif // USE_RETRO_ACHIEVEMENTS
|