2023-06-03 01:20:42 +00:00
|
|
|
// Copyright 2023 Dolphin Emulator Project
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
|
|
|
|
#ifdef USE_RETRO_ACHIEVEMENTS
|
|
|
|
#include "DolphinQt/Achievements/AchievementHeaderWidget.h"
|
|
|
|
|
|
|
|
#include <QGroupBox>
|
|
|
|
#include <QLabel>
|
|
|
|
#include <QLineEdit>
|
|
|
|
#include <QProgressBar>
|
|
|
|
#include <QString>
|
|
|
|
#include <QVBoxLayout>
|
|
|
|
|
Update Achievement Dialog Header to use rc_client
Two portions of this need updating.
Anything related to points and unlock counts and scoring uses game_summary now instead of the TallyScore method. Unfortunately this comes with the drawback that I cannot easily at this time access the number of points/unlocks from the other hardcore mode, so things like the second progress bar have been deleted.
Rich presence, which no longer needs to be stored, but can be calculated at request. As the AchievementHeader can now update just the Rich Presence, DoFrame can now simply call a header update with .rp=true and the current Rich Presence will be calculated immediately.
As the two items above are the last remaining things to use a number of the components in AchievementManager, this also deletes: Request V1 (V2 is renamed accordingly), ResponseType, PointSpread, TallyScore, UnlockStatus, and the RP generation and ping methods.
2024-04-06 02:46:40 +00:00
|
|
|
#include <rcheevos/include/rc_client.h>
|
|
|
|
|
2023-06-03 01:20:42 +00:00
|
|
|
#include "Core/AchievementManager.h"
|
2023-06-17 16:40:07 +00:00
|
|
|
#include "Core/Config/AchievementSettings.h"
|
2023-06-03 01:20:42 +00:00
|
|
|
#include "Core/Core.h"
|
|
|
|
|
2024-03-19 17:33:51 +00:00
|
|
|
#include "DolphinQt/QtUtils/FromStdString.h"
|
2023-06-03 01:20:42 +00:00
|
|
|
#include "DolphinQt/Settings.h"
|
|
|
|
|
|
|
|
AchievementHeaderWidget::AchievementHeaderWidget(QWidget* parent) : QWidget(parent)
|
|
|
|
{
|
2023-06-15 07:57:58 +00:00
|
|
|
m_user_icon = new QLabel();
|
|
|
|
m_game_icon = new QLabel();
|
|
|
|
m_name = new QLabel();
|
|
|
|
m_points = new QLabel();
|
Update Achievement Dialog Header to use rc_client
Two portions of this need updating.
Anything related to points and unlock counts and scoring uses game_summary now instead of the TallyScore method. Unfortunately this comes with the drawback that I cannot easily at this time access the number of points/unlocks from the other hardcore mode, so things like the second progress bar have been deleted.
Rich presence, which no longer needs to be stored, but can be calculated at request. As the AchievementHeader can now update just the Rich Presence, DoFrame can now simply call a header update with .rp=true and the current Rich Presence will be calculated immediately.
As the two items above are the last remaining things to use a number of the components in AchievementManager, this also deletes: Request V1 (V2 is renamed accordingly), ResponseType, PointSpread, TallyScore, UnlockStatus, and the RP generation and ping methods.
2024-04-06 02:46:40 +00:00
|
|
|
m_game_progress = new QProgressBar();
|
2023-06-03 01:20:42 +00:00
|
|
|
m_rich_presence = new QLabel();
|
|
|
|
|
Update Achievement Dialog Header to use rc_client
Two portions of this need updating.
Anything related to points and unlock counts and scoring uses game_summary now instead of the TallyScore method. Unfortunately this comes with the drawback that I cannot easily at this time access the number of points/unlocks from the other hardcore mode, so things like the second progress bar have been deleted.
Rich presence, which no longer needs to be stored, but can be calculated at request. As the AchievementHeader can now update just the Rich Presence, DoFrame can now simply call a header update with .rp=true and the current Rich Presence will be calculated immediately.
As the two items above are the last remaining things to use a number of the components in AchievementManager, this also deletes: Request V1 (V2 is renamed accordingly), ResponseType, PointSpread, TallyScore, UnlockStatus, and the RP generation and ping methods.
2024-04-06 02:46:40 +00:00
|
|
|
QSizePolicy sp_retain = m_game_progress->sizePolicy();
|
2023-06-15 07:57:58 +00:00
|
|
|
sp_retain.setRetainSizeWhenHidden(true);
|
Update Achievement Dialog Header to use rc_client
Two portions of this need updating.
Anything related to points and unlock counts and scoring uses game_summary now instead of the TallyScore method. Unfortunately this comes with the drawback that I cannot easily at this time access the number of points/unlocks from the other hardcore mode, so things like the second progress bar have been deleted.
Rich presence, which no longer needs to be stored, but can be calculated at request. As the AchievementHeader can now update just the Rich Presence, DoFrame can now simply call a header update with .rp=true and the current Rich Presence will be calculated immediately.
As the two items above are the last remaining things to use a number of the components in AchievementManager, this also deletes: Request V1 (V2 is renamed accordingly), ResponseType, PointSpread, TallyScore, UnlockStatus, and the RP generation and ping methods.
2024-04-06 02:46:40 +00:00
|
|
|
m_game_progress->setSizePolicy(sp_retain);
|
2023-06-15 07:57:58 +00:00
|
|
|
|
|
|
|
QVBoxLayout* icon_col = new QVBoxLayout();
|
|
|
|
icon_col->addWidget(m_user_icon);
|
|
|
|
icon_col->addWidget(m_game_icon);
|
|
|
|
QVBoxLayout* text_col = new QVBoxLayout();
|
|
|
|
text_col->addWidget(m_name);
|
|
|
|
text_col->addWidget(m_points);
|
Update Achievement Dialog Header to use rc_client
Two portions of this need updating.
Anything related to points and unlock counts and scoring uses game_summary now instead of the TallyScore method. Unfortunately this comes with the drawback that I cannot easily at this time access the number of points/unlocks from the other hardcore mode, so things like the second progress bar have been deleted.
Rich presence, which no longer needs to be stored, but can be calculated at request. As the AchievementHeader can now update just the Rich Presence, DoFrame can now simply call a header update with .rp=true and the current Rich Presence will be calculated immediately.
As the two items above are the last remaining things to use a number of the components in AchievementManager, this also deletes: Request V1 (V2 is renamed accordingly), ResponseType, PointSpread, TallyScore, UnlockStatus, and the RP generation and ping methods.
2024-04-06 02:46:40 +00:00
|
|
|
text_col->addWidget(m_game_progress);
|
2023-06-15 07:57:58 +00:00
|
|
|
text_col->addWidget(m_rich_presence);
|
|
|
|
QHBoxLayout* header_layout = new QHBoxLayout();
|
|
|
|
header_layout->addLayout(icon_col);
|
|
|
|
header_layout->addLayout(text_col);
|
|
|
|
m_header_box = new QGroupBox();
|
|
|
|
m_header_box->setLayout(header_layout);
|
2023-06-03 01:20:42 +00:00
|
|
|
|
|
|
|
QVBoxLayout* m_total = new QVBoxLayout();
|
2023-06-15 07:57:58 +00:00
|
|
|
m_total->addWidget(m_header_box);
|
2023-06-03 01:20:42 +00:00
|
|
|
|
|
|
|
m_total->setContentsMargins(0, 0, 0, 0);
|
|
|
|
m_total->setAlignment(Qt::AlignTop);
|
|
|
|
setLayout(m_total);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AchievementHeaderWidget::UpdateData()
|
|
|
|
{
|
2024-03-10 01:18:40 +00:00
|
|
|
std::lock_guard lg{AchievementManager::GetInstance().GetLock()};
|
2023-12-11 18:18:02 +00:00
|
|
|
auto& instance = AchievementManager::GetInstance();
|
2024-05-04 01:35:01 +00:00
|
|
|
if (!Config::Get(Config::RA_ENABLED) || !instance.HasAPIToken())
|
2023-06-03 01:20:42 +00:00
|
|
|
{
|
2023-06-15 07:57:58 +00:00
|
|
|
m_header_box->setVisible(false);
|
2023-06-03 01:20:42 +00:00
|
|
|
return;
|
|
|
|
}
|
2024-05-04 01:35:01 +00:00
|
|
|
m_header_box->setVisible(true);
|
2023-06-03 01:20:42 +00:00
|
|
|
|
2024-03-19 17:33:51 +00:00
|
|
|
QString user_name = QtUtils::FromStdString(instance.GetPlayerDisplayName());
|
2024-03-28 03:22:10 +00:00
|
|
|
QString game_name = QtUtils::FromStdString(instance.GetGameDisplayName());
|
2024-05-13 23:21:55 +00:00
|
|
|
const AchievementManager::Badge& player_badge = instance.GetPlayerBadge();
|
|
|
|
const AchievementManager::Badge& game_badge = instance.GetGameBadge();
|
2023-06-15 07:57:58 +00:00
|
|
|
|
|
|
|
m_user_icon->setVisible(false);
|
|
|
|
m_user_icon->clear();
|
|
|
|
m_user_icon->setText({});
|
2024-05-13 23:21:55 +00:00
|
|
|
QImage i_user_icon(&player_badge.data.front(), player_badge.width, player_badge.height,
|
|
|
|
QImage::Format_RGBA8888);
|
|
|
|
m_user_icon->setPixmap(QPixmap::fromImage(i_user_icon)
|
|
|
|
.scaled(64, 64, Qt::KeepAspectRatio, Qt::SmoothTransformation));
|
|
|
|
m_user_icon->adjustSize();
|
|
|
|
m_user_icon->setStyleSheet(QStringLiteral("border: 4px solid transparent"));
|
|
|
|
m_user_icon->setVisible(true);
|
|
|
|
|
2023-06-15 07:57:58 +00:00
|
|
|
m_game_icon->setVisible(false);
|
|
|
|
m_game_icon->clear();
|
|
|
|
m_game_icon->setText({});
|
Update Achievement Dialog Header to use rc_client
Two portions of this need updating.
Anything related to points and unlock counts and scoring uses game_summary now instead of the TallyScore method. Unfortunately this comes with the drawback that I cannot easily at this time access the number of points/unlocks from the other hardcore mode, so things like the second progress bar have been deleted.
Rich presence, which no longer needs to be stored, but can be calculated at request. As the AchievementHeader can now update just the Rich Presence, DoFrame can now simply call a header update with .rp=true and the current Rich Presence will be calculated immediately.
As the two items above are the last remaining things to use a number of the components in AchievementManager, this also deletes: Request V1 (V2 is renamed accordingly), ResponseType, PointSpread, TallyScore, UnlockStatus, and the RP generation and ping methods.
2024-04-06 02:46:40 +00:00
|
|
|
|
|
|
|
if (instance.IsGameLoaded())
|
2023-06-15 07:57:58 +00:00
|
|
|
{
|
Update Achievement Dialog Header to use rc_client
Two portions of this need updating.
Anything related to points and unlock counts and scoring uses game_summary now instead of the TallyScore method. Unfortunately this comes with the drawback that I cannot easily at this time access the number of points/unlocks from the other hardcore mode, so things like the second progress bar have been deleted.
Rich presence, which no longer needs to be stored, but can be calculated at request. As the AchievementHeader can now update just the Rich Presence, DoFrame can now simply call a header update with .rp=true and the current Rich Presence will be calculated immediately.
As the two items above are the last remaining things to use a number of the components in AchievementManager, this also deletes: Request V1 (V2 is renamed accordingly), ResponseType, PointSpread, TallyScore, UnlockStatus, and the RP generation and ping methods.
2024-04-06 02:46:40 +00:00
|
|
|
rc_client_user_game_summary_t game_summary;
|
|
|
|
rc_client_get_user_game_summary(instance.GetClient(), &game_summary);
|
2024-05-13 23:21:55 +00:00
|
|
|
QImage i_game_icon(&game_badge.data.front(), game_badge.width, game_badge.height,
|
|
|
|
QImage::Format_RGBA8888);
|
|
|
|
m_game_icon->setPixmap(QPixmap::fromImage(i_game_icon)
|
|
|
|
.scaled(64, 64, Qt::KeepAspectRatio, Qt::SmoothTransformation));
|
|
|
|
m_game_icon->adjustSize();
|
|
|
|
std::string_view color = AchievementManager::GRAY;
|
|
|
|
if (game_summary.num_core_achievements == game_summary.num_unlocked_achievements)
|
2023-06-15 07:57:58 +00:00
|
|
|
{
|
2024-05-13 23:21:55 +00:00
|
|
|
color = instance.IsHardcoreModeActive() ? AchievementManager::GOLD : AchievementManager::BLUE;
|
2023-06-15 07:57:58 +00:00
|
|
|
}
|
2024-05-13 23:21:55 +00:00
|
|
|
m_game_icon->setStyleSheet(
|
|
|
|
QStringLiteral("border: 4px solid %1").arg(QtUtils::FromStdString(color)));
|
|
|
|
m_game_icon->setVisible(true);
|
2023-06-03 01:20:42 +00:00
|
|
|
|
2023-06-15 07:57:58 +00:00
|
|
|
m_name->setText(tr("%1 is playing %2").arg(user_name).arg(game_name));
|
Update Achievement Dialog Header to use rc_client
Two portions of this need updating.
Anything related to points and unlock counts and scoring uses game_summary now instead of the TallyScore method. Unfortunately this comes with the drawback that I cannot easily at this time access the number of points/unlocks from the other hardcore mode, so things like the second progress bar have been deleted.
Rich presence, which no longer needs to be stored, but can be calculated at request. As the AchievementHeader can now update just the Rich Presence, DoFrame can now simply call a header update with .rp=true and the current Rich Presence will be calculated immediately.
As the two items above are the last remaining things to use a number of the components in AchievementManager, this also deletes: Request V1 (V2 is renamed accordingly), ResponseType, PointSpread, TallyScore, UnlockStatus, and the RP generation and ping methods.
2024-04-06 02:46:40 +00:00
|
|
|
m_points->setText(tr("%1 has unlocked %2/%3 achievements worth %4/%5 points")
|
|
|
|
.arg(user_name)
|
|
|
|
.arg(game_summary.num_unlocked_achievements)
|
|
|
|
.arg(game_summary.num_core_achievements)
|
|
|
|
.arg(game_summary.points_unlocked)
|
|
|
|
.arg(game_summary.points_core));
|
|
|
|
|
|
|
|
m_game_progress->setRange(0, game_summary.num_core_achievements);
|
|
|
|
if (!m_game_progress->isVisible())
|
|
|
|
m_game_progress->setVisible(true);
|
|
|
|
m_game_progress->setValue(game_summary.num_unlocked_achievements);
|
2023-12-11 18:18:02 +00:00
|
|
|
m_rich_presence->setText(QString::fromUtf8(instance.GetRichPresence().data()));
|
2024-04-03 19:18:27 +00:00
|
|
|
m_rich_presence->setVisible(true);
|
2023-06-03 01:20:42 +00:00
|
|
|
}
|
2023-06-15 07:57:58 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
m_name->setText(user_name);
|
2023-12-11 18:18:02 +00:00
|
|
|
m_points->setText(tr("%1 points").arg(instance.GetPlayerScore()));
|
2023-06-03 01:20:42 +00:00
|
|
|
|
Update Achievement Dialog Header to use rc_client
Two portions of this need updating.
Anything related to points and unlock counts and scoring uses game_summary now instead of the TallyScore method. Unfortunately this comes with the drawback that I cannot easily at this time access the number of points/unlocks from the other hardcore mode, so things like the second progress bar have been deleted.
Rich presence, which no longer needs to be stored, but can be calculated at request. As the AchievementHeader can now update just the Rich Presence, DoFrame can now simply call a header update with .rp=true and the current Rich Presence will be calculated immediately.
As the two items above are the last remaining things to use a number of the components in AchievementManager, this also deletes: Request V1 (V2 is renamed accordingly), ResponseType, PointSpread, TallyScore, UnlockStatus, and the RP generation and ping methods.
2024-04-06 02:46:40 +00:00
|
|
|
m_game_progress->setVisible(false);
|
2023-06-15 07:57:58 +00:00
|
|
|
m_rich_presence->setVisible(false);
|
|
|
|
}
|
2023-06-03 01:20:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // USE_RETRO_ACHIEVEMENTS
|