mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-23 06:09:50 -06:00
Created AchievementBox Qt object
AchievementBox is an extension of QGroupBox that contains the data for a single achievement, initialized with the achievement data and able to reference AchievementManager to update itself.
This commit is contained in:
@ -18,11 +18,10 @@
|
||||
#include "Core/Config/MainSettings.h"
|
||||
#include "Core/Core.h"
|
||||
|
||||
#include "DolphinQt/Achievements/AchievementBox.h"
|
||||
#include "DolphinQt/QtUtils/ClearLayoutRecursively.h"
|
||||
#include "DolphinQt/Settings.h"
|
||||
|
||||
static constexpr bool hardcore_mode_enabled = false;
|
||||
|
||||
AchievementProgressWidget::AchievementProgressWidget(QWidget* parent) : QWidget(parent)
|
||||
{
|
||||
m_common_box = new QGroupBox();
|
||||
@ -42,88 +41,6 @@ AchievementProgressWidget::AchievementProgressWidget(QWidget* parent) : QWidget(
|
||||
setLayout(layout);
|
||||
}
|
||||
|
||||
QGroupBox*
|
||||
AchievementProgressWidget::CreateAchievementBox(const rc_api_achievement_definition_t* achievement)
|
||||
{
|
||||
const auto& instance = AchievementManager::GetInstance();
|
||||
if (!instance.IsGameLoaded())
|
||||
return new QGroupBox();
|
||||
|
||||
QLabel* a_badge = new QLabel();
|
||||
const auto unlock_status = instance.GetUnlockStatus(achievement->id);
|
||||
const AchievementManager::BadgeStatus* badge = &unlock_status.locked_badge;
|
||||
std::string_view color = AchievementManager::GRAY;
|
||||
if (unlock_status.remote_unlock_status == AchievementManager::UnlockStatus::UnlockType::HARDCORE)
|
||||
{
|
||||
badge = &unlock_status.unlocked_badge;
|
||||
color = AchievementManager::GOLD;
|
||||
}
|
||||
else if (hardcore_mode_enabled && unlock_status.session_unlock_count > 1)
|
||||
{
|
||||
badge = &unlock_status.unlocked_badge;
|
||||
color = AchievementManager::GOLD;
|
||||
}
|
||||
else if (unlock_status.remote_unlock_status ==
|
||||
AchievementManager::UnlockStatus::UnlockType::SOFTCORE)
|
||||
{
|
||||
badge = &unlock_status.unlocked_badge;
|
||||
color = AchievementManager::BLUE;
|
||||
}
|
||||
else if (unlock_status.session_unlock_count > 1)
|
||||
{
|
||||
badge = &unlock_status.unlocked_badge;
|
||||
color = AchievementManager::BLUE;
|
||||
}
|
||||
if (Config::Get(Config::RA_BADGES_ENABLED) && badge->name != "")
|
||||
{
|
||||
QImage i_badge{};
|
||||
if (i_badge.loadFromData(&badge->badge.front(), (int)badge->badge.size()))
|
||||
{
|
||||
a_badge->setPixmap(QPixmap::fromImage(i_badge).scaled(64, 64, Qt::KeepAspectRatio,
|
||||
Qt::SmoothTransformation));
|
||||
a_badge->adjustSize();
|
||||
a_badge->setStyleSheet(
|
||||
QStringLiteral("border: 4px solid %1").arg(QString::fromStdString(std::string(color))));
|
||||
}
|
||||
}
|
||||
|
||||
QLabel* a_title = new QLabel(QString::fromUtf8(achievement->title, strlen(achievement->title)));
|
||||
QLabel* a_description =
|
||||
new QLabel(QString::fromUtf8(achievement->description, strlen(achievement->description)));
|
||||
QLabel* a_points = new QLabel(tr("%1 points").arg(achievement->points));
|
||||
QLabel* a_status = new QLabel(GetStatusString(achievement->id));
|
||||
QProgressBar* a_progress_bar = new QProgressBar();
|
||||
QSizePolicy sp_retain = a_progress_bar->sizePolicy();
|
||||
sp_retain.setRetainSizeWhenHidden(true);
|
||||
a_progress_bar->setSizePolicy(sp_retain);
|
||||
unsigned int value = 0;
|
||||
unsigned int target = 0;
|
||||
if (AchievementManager::GetInstance().GetAchievementProgress(achievement->id, &value, &target) ==
|
||||
AchievementManager::ResponseType::SUCCESS &&
|
||||
target > 0)
|
||||
{
|
||||
a_progress_bar->setRange(0, target);
|
||||
a_progress_bar->setValue(value);
|
||||
}
|
||||
else
|
||||
{
|
||||
a_progress_bar->setVisible(false);
|
||||
}
|
||||
|
||||
QVBoxLayout* a_col_right = new QVBoxLayout();
|
||||
a_col_right->addWidget(a_title);
|
||||
a_col_right->addWidget(a_description);
|
||||
a_col_right->addWidget(a_points);
|
||||
a_col_right->addWidget(a_status);
|
||||
a_col_right->addWidget(a_progress_bar);
|
||||
QHBoxLayout* a_total = new QHBoxLayout();
|
||||
a_total->addWidget(a_badge);
|
||||
a_total->addLayout(a_col_right);
|
||||
QGroupBox* a_group_box = new QGroupBox();
|
||||
a_group_box->setLayout(a_total);
|
||||
return a_group_box;
|
||||
}
|
||||
|
||||
void AchievementProgressWidget::UpdateData()
|
||||
{
|
||||
ClearLayoutRecursively(m_common_layout);
|
||||
@ -132,34 +49,18 @@ void AchievementProgressWidget::UpdateData()
|
||||
if (!instance.IsGameLoaded())
|
||||
return;
|
||||
|
||||
const auto* game_data = instance.GetGameData();
|
||||
for (u32 ix = 0; ix < game_data->num_achievements; ix++)
|
||||
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_LOCK_STATE);
|
||||
for (u32 ix = 0; ix < achievement_list->num_buckets; ix++)
|
||||
{
|
||||
m_common_layout->addWidget(CreateAchievementBox(game_data->achievements + ix));
|
||||
}
|
||||
}
|
||||
|
||||
QString AchievementProgressWidget::GetStatusString(u32 achievement_id) const
|
||||
{
|
||||
const auto unlock_status = AchievementManager::GetInstance().GetUnlockStatus(achievement_id);
|
||||
if (unlock_status.session_unlock_count > 0)
|
||||
{
|
||||
if (Config::Get(Config::RA_ENCORE_ENABLED))
|
||||
for (u32 jx = 0; jx < achievement_list->buckets[ix].num_achievements; jx++)
|
||||
{
|
||||
return tr("Unlocked %1 times this session").arg(unlock_status.session_unlock_count);
|
||||
m_common_layout->addWidget(
|
||||
new AchievementBox(this, achievement_list->buckets[ix].achievements[jx]));
|
||||
}
|
||||
return tr("Unlocked this session");
|
||||
}
|
||||
switch (unlock_status.remote_unlock_status)
|
||||
{
|
||||
case AchievementManager::UnlockStatus::UnlockType::LOCKED:
|
||||
return tr("Locked");
|
||||
case AchievementManager::UnlockStatus::UnlockType::SOFTCORE:
|
||||
return tr("Unlocked (Casual)");
|
||||
case AchievementManager::UnlockStatus::UnlockType::HARDCORE:
|
||||
return tr("Unlocked");
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
#endif // USE_RETRO_ACHIEVEMENTS
|
||||
|
Reference in New Issue
Block a user