2023-05-26 13:35:50 +00:00
|
|
|
// Copyright 2023 Dolphin Emulator Project
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
|
|
|
|
#ifdef USE_RETRO_ACHIEVEMENTS
|
|
|
|
#include "DolphinQt/Achievements/AchievementsWindow.h"
|
|
|
|
|
2023-06-09 21:05:52 +00:00
|
|
|
#include <mutex>
|
|
|
|
|
2023-05-26 13:35:50 +00:00
|
|
|
#include <QDialogButtonBox>
|
2023-05-26 22:29:22 +00:00
|
|
|
#include <QTabWidget>
|
|
|
|
#include <QVBoxLayout>
|
2023-05-26 13:35:50 +00:00
|
|
|
|
2023-12-11 18:38:04 +00:00
|
|
|
#include "Core/AchievementManager.h"
|
|
|
|
|
2023-06-03 01:20:42 +00:00
|
|
|
#include "DolphinQt/Achievements/AchievementHeaderWidget.h"
|
2023-06-17 15:47:56 +00:00
|
|
|
#include "DolphinQt/Achievements/AchievementLeaderboardWidget.h"
|
2023-06-03 01:25:01 +00:00
|
|
|
#include "DolphinQt/Achievements/AchievementProgressWidget.h"
|
2023-05-26 22:29:22 +00:00
|
|
|
#include "DolphinQt/Achievements/AchievementSettingsWidget.h"
|
2023-06-03 01:31:30 +00:00
|
|
|
#include "DolphinQt/QtUtils/QueueOnObject.h"
|
2023-05-26 13:35:50 +00:00
|
|
|
#include "DolphinQt/QtUtils/WrapInScrollArea.h"
|
2023-06-08 02:23:10 +00:00
|
|
|
#include "DolphinQt/Settings.h"
|
2023-05-26 13:35:50 +00:00
|
|
|
|
|
|
|
AchievementsWindow::AchievementsWindow(QWidget* parent) : QDialog(parent)
|
|
|
|
{
|
|
|
|
setWindowTitle(tr("Achievements"));
|
|
|
|
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
|
|
|
|
|
|
|
CreateMainLayout();
|
|
|
|
ConnectWidgets();
|
2023-12-11 18:18:02 +00:00
|
|
|
AchievementManager::GetInstance().SetUpdateCallback(
|
2024-03-10 01:18:40 +00:00
|
|
|
[this](AchievementManager::UpdatedItems updated_items) {
|
|
|
|
QueueOnObject(this, [this, updated_items = std::move(updated_items)] {
|
|
|
|
AchievementsWindow::UpdateData(std::move(updated_items));
|
|
|
|
});
|
|
|
|
});
|
2023-06-08 02:23:10 +00:00
|
|
|
connect(&Settings::Instance(), &Settings::EmulationStateChanged, this,
|
2024-06-20 11:59:59 +00:00
|
|
|
[this] { m_settings_widget->UpdateData(); });
|
|
|
|
connect(&Settings::Instance(), &Settings::HardcoreStateChanged, this,
|
2024-03-10 01:18:40 +00:00
|
|
|
[this] { AchievementsWindow::UpdateData({.all = true}); });
|
2023-05-26 13:35:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void AchievementsWindow::showEvent(QShowEvent* event)
|
|
|
|
{
|
|
|
|
QDialog::showEvent(event);
|
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
void AchievementsWindow::CreateMainLayout()
|
|
|
|
{
|
2023-12-11 18:18:02 +00:00
|
|
|
const auto is_game_loaded = AchievementManager::GetInstance().IsGameLoaded();
|
2023-05-26 13:35:50 +00:00
|
|
|
|
2023-06-03 01:20:42 +00:00
|
|
|
m_header_widget = new AchievementHeaderWidget(this);
|
2023-05-26 22:29:22 +00:00
|
|
|
m_tab_widget = new QTabWidget();
|
2023-06-08 02:23:10 +00:00
|
|
|
m_settings_widget = new AchievementSettingsWidget(m_tab_widget);
|
2023-06-03 01:25:01 +00:00
|
|
|
m_progress_widget = new AchievementProgressWidget(m_tab_widget);
|
2023-06-17 15:47:56 +00:00
|
|
|
m_leaderboard_widget = new AchievementLeaderboardWidget(m_tab_widget);
|
2023-06-08 02:23:10 +00:00
|
|
|
m_tab_widget->addTab(GetWrappedWidget(m_settings_widget, this, 125, 100), tr("Settings"));
|
2023-06-03 01:25:01 +00:00
|
|
|
m_tab_widget->addTab(GetWrappedWidget(m_progress_widget, this, 125, 100), tr("Progress"));
|
2023-12-11 18:18:02 +00:00
|
|
|
m_tab_widget->setTabVisible(1, is_game_loaded);
|
2023-06-17 15:47:56 +00:00
|
|
|
m_tab_widget->addTab(GetWrappedWidget(m_leaderboard_widget, this, 125, 100), tr("Leaderboards"));
|
2023-12-11 18:18:02 +00:00
|
|
|
m_tab_widget->setTabVisible(2, is_game_loaded);
|
2023-05-26 22:29:22 +00:00
|
|
|
|
2023-05-26 13:35:50 +00:00
|
|
|
m_button_box = new QDialogButtonBox(QDialogButtonBox::Close);
|
|
|
|
|
2023-12-11 18:18:02 +00:00
|
|
|
auto* layout = new QVBoxLayout();
|
2023-06-03 01:20:42 +00:00
|
|
|
layout->addWidget(m_header_widget);
|
2023-05-26 22:29:22 +00:00
|
|
|
layout->addWidget(m_tab_widget);
|
2023-05-26 13:35:50 +00:00
|
|
|
layout->addWidget(m_button_box);
|
|
|
|
|
|
|
|
WrapInScrollArea(this, layout);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AchievementsWindow::ConnectWidgets()
|
|
|
|
{
|
|
|
|
connect(m_button_box, &QDialogButtonBox::rejected, this, &QDialog::reject);
|
|
|
|
}
|
|
|
|
|
2024-03-10 01:18:40 +00:00
|
|
|
void AchievementsWindow::UpdateData(AchievementManager::UpdatedItems updated_items)
|
2023-05-26 13:35:50 +00:00
|
|
|
{
|
2024-03-10 01:18:40 +00:00
|
|
|
m_settings_widget->UpdateData();
|
|
|
|
if (updated_items.all)
|
|
|
|
{
|
|
|
|
m_header_widget->UpdateData();
|
|
|
|
m_progress_widget->UpdateData(true);
|
|
|
|
m_leaderboard_widget->UpdateData(true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (updated_items.player_icon || updated_items.game_icon || updated_items.rich_presence ||
|
|
|
|
updated_items.all_achievements || updated_items.achievements.size() > 0)
|
|
|
|
{
|
|
|
|
m_header_widget->UpdateData();
|
|
|
|
}
|
|
|
|
if (updated_items.all_achievements)
|
|
|
|
m_progress_widget->UpdateData(false);
|
|
|
|
else if (updated_items.achievements.size() > 0)
|
|
|
|
m_progress_widget->UpdateData(updated_items.achievements);
|
|
|
|
if (updated_items.all_leaderboards)
|
|
|
|
m_leaderboard_widget->UpdateData(false);
|
|
|
|
else if (updated_items.leaderboards.size() > 0)
|
|
|
|
m_leaderboard_widget->UpdateData(updated_items.leaderboards);
|
|
|
|
}
|
|
|
|
|
2023-06-09 21:05:52 +00:00
|
|
|
{
|
2023-12-11 18:18:02 +00:00
|
|
|
auto& instance = AchievementManager::GetInstance();
|
2023-12-11 18:51:47 +00:00
|
|
|
std::lock_guard lg{instance.GetLock()};
|
2023-12-11 18:18:02 +00:00
|
|
|
const bool is_game_loaded = instance.IsGameLoaded();
|
2024-03-19 16:41:18 +00:00
|
|
|
m_header_widget->setVisible(instance.HasAPIToken());
|
2023-12-11 18:18:02 +00:00
|
|
|
m_tab_widget->setTabVisible(1, is_game_loaded);
|
|
|
|
m_tab_widget->setTabVisible(2, is_game_loaded);
|
2023-06-09 21:05:52 +00:00
|
|
|
}
|
2023-05-26 13:35:50 +00:00
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
2023-11-15 15:56:15 +00:00
|
|
|
void AchievementsWindow::ForceSettingsTab()
|
|
|
|
{
|
|
|
|
m_tab_widget->setCurrentIndex(0);
|
|
|
|
}
|
|
|
|
|
2023-05-26 13:35:50 +00:00
|
|
|
#endif // USE_RETRO_ACHIEVEMENTS
|