2023-06-03 01:25:01 +00:00
|
|
|
// 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 <rcheevos/include/rc_api_runtime.h>
|
|
|
|
|
|
|
|
#include "Core/AchievementManager.h"
|
|
|
|
#include "Core/Config/AchievementSettings.h"
|
|
|
|
#include "Core/Config/MainSettings.h"
|
|
|
|
#include "Core/Core.h"
|
|
|
|
|
2023-10-15 16:36:11 +00:00
|
|
|
#include "DolphinQt/QtUtils/ClearLayoutRecursively.h"
|
2023-06-03 01:25:01 +00:00
|
|
|
#include "DolphinQt/Settings.h"
|
|
|
|
|
2023-07-04 20:17:10 +00:00
|
|
|
static constexpr bool hardcore_mode_enabled = false;
|
|
|
|
|
2023-06-03 01:25:01 +00:00
|
|
|
AchievementProgressWidget::AchievementProgressWidget(QWidget* parent) : QWidget(parent)
|
|
|
|
{
|
|
|
|
m_common_box = new QGroupBox();
|
|
|
|
m_common_layout = new QVBoxLayout();
|
|
|
|
|
2023-07-04 20:50:54 +00:00
|
|
|
{
|
2023-12-11 18:18:02 +00:00
|
|
|
std::lock_guard lg{*AchievementManager::GetInstance().GetLock()};
|
2023-07-04 20:50:54 +00:00
|
|
|
UpdateData();
|
|
|
|
}
|
2023-06-03 01:25:01 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
setLayout(layout);
|
|
|
|
}
|
|
|
|
|
|
|
|
QGroupBox*
|
|
|
|
AchievementProgressWidget::CreateAchievementBox(const rc_api_achievement_definition_t* achievement)
|
|
|
|
{
|
2023-12-11 18:18:02 +00:00
|
|
|
const auto& instance = AchievementManager::GetInstance();
|
|
|
|
if (!instance.IsGameLoaded())
|
2023-09-26 11:21:22 +00:00
|
|
|
return new QGroupBox();
|
2023-12-11 18:18:02 +00:00
|
|
|
|
2023-07-04 20:50:54 +00:00
|
|
|
QLabel* a_badge = new QLabel();
|
2023-12-11 18:18:02 +00:00
|
|
|
const auto unlock_status = instance.GetUnlockStatus(achievement->id);
|
2023-07-04 20:50:54 +00:00
|
|
|
const AchievementManager::BadgeStatus* badge = &unlock_status.locked_badge;
|
2023-07-04 20:17:10 +00:00
|
|
|
std::string_view color = AchievementManager::GRAY;
|
2023-07-04 20:50:54 +00:00
|
|
|
if (unlock_status.remote_unlock_status == AchievementManager::UnlockStatus::UnlockType::HARDCORE)
|
|
|
|
{
|
|
|
|
badge = &unlock_status.unlocked_badge;
|
2023-07-04 20:17:10 +00:00
|
|
|
color = AchievementManager::GOLD;
|
2023-07-04 20:50:54 +00:00
|
|
|
}
|
|
|
|
else if (hardcore_mode_enabled && unlock_status.session_unlock_count > 1)
|
|
|
|
{
|
|
|
|
badge = &unlock_status.unlocked_badge;
|
2023-07-04 20:17:10 +00:00
|
|
|
color = AchievementManager::GOLD;
|
2023-07-04 20:50:54 +00:00
|
|
|
}
|
|
|
|
else if (unlock_status.remote_unlock_status ==
|
|
|
|
AchievementManager::UnlockStatus::UnlockType::SOFTCORE)
|
|
|
|
{
|
|
|
|
badge = &unlock_status.unlocked_badge;
|
2023-07-04 20:17:10 +00:00
|
|
|
color = AchievementManager::BLUE;
|
2023-07-04 20:50:54 +00:00
|
|
|
}
|
|
|
|
else if (unlock_status.session_unlock_count > 1)
|
|
|
|
{
|
|
|
|
badge = &unlock_status.unlocked_badge;
|
2023-07-04 20:17:10 +00:00
|
|
|
color = AchievementManager::BLUE;
|
2023-07-04 20:50:54 +00:00
|
|
|
}
|
|
|
|
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();
|
2023-07-04 20:17:10 +00:00
|
|
|
a_badge->setStyleSheet(
|
|
|
|
QStringLiteral("border: 4px solid %1").arg(QString::fromStdString(std::string(color))));
|
2023-07-04 20:50:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-03 01:25:01 +00:00
|
|
|
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();
|
2023-07-04 20:50:54 +00:00
|
|
|
QSizePolicy sp_retain = a_progress_bar->sizePolicy();
|
|
|
|
sp_retain.setRetainSizeWhenHidden(true);
|
|
|
|
a_progress_bar->setSizePolicy(sp_retain);
|
2023-06-03 01:25:01 +00:00
|
|
|
unsigned int value = 0;
|
|
|
|
unsigned int target = 0;
|
2023-12-11 18:18:02 +00:00
|
|
|
if (AchievementManager::GetInstance().GetAchievementProgress(achievement->id, &value, &target) ==
|
2023-10-01 04:59:43 +00:00
|
|
|
AchievementManager::ResponseType::SUCCESS &&
|
|
|
|
target > 0)
|
2023-06-03 01:25:01 +00:00
|
|
|
{
|
|
|
|
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();
|
2023-07-04 20:50:54 +00:00
|
|
|
a_total->addWidget(a_badge);
|
2023-06-03 01:25:01 +00:00
|
|
|
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()
|
|
|
|
{
|
2023-10-15 16:36:11 +00:00
|
|
|
ClearLayoutRecursively(m_common_layout);
|
2023-06-03 01:25:01 +00:00
|
|
|
|
2023-12-11 18:18:02 +00:00
|
|
|
auto& instance = AchievementManager::GetInstance();
|
|
|
|
if (!instance.IsGameLoaded())
|
2023-09-26 11:21:22 +00:00
|
|
|
return;
|
2023-12-11 18:18:02 +00:00
|
|
|
|
|
|
|
const auto* game_data = instance.GetGameData();
|
2023-06-03 01:25:01 +00:00
|
|
|
for (u32 ix = 0; ix < game_data->num_achievements; ix++)
|
|
|
|
{
|
|
|
|
m_common_layout->addWidget(CreateAchievementBox(game_data->achievements + ix));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QString AchievementProgressWidget::GetStatusString(u32 achievement_id) const
|
|
|
|
{
|
2023-12-11 18:18:02 +00:00
|
|
|
const auto unlock_status = AchievementManager::GetInstance().GetUnlockStatus(achievement_id);
|
2023-06-03 01:25:01 +00:00
|
|
|
if (unlock_status.session_unlock_count > 0)
|
|
|
|
{
|
|
|
|
if (Config::Get(Config::RA_ENCORE_ENABLED))
|
|
|
|
{
|
|
|
|
return tr("Unlocked %1 times this session").arg(unlock_status.session_unlock_count);
|
|
|
|
}
|
|
|
|
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
|