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(
|
2023-06-03 01:31:30 +00:00
|
|
|
[this] { QueueOnObject(this, &AchievementsWindow::UpdateData); });
|
2023-06-08 02:23:10 +00:00
|
|
|
connect(&Settings::Instance(), &Settings::EmulationStateChanged, this,
|
|
|
|
&AchievementsWindow::UpdateData);
|
2023-09-27 03:31:04 +00:00
|
|
|
|
|
|
|
UpdateData();
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AchievementsWindow::UpdateData()
|
|
|
|
{
|
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();
|
|
|
|
|
2023-06-09 21:05:52 +00:00
|
|
|
m_header_widget->UpdateData();
|
2024-03-19 16:41:18 +00:00
|
|
|
m_header_widget->setVisible(instance.HasAPIToken());
|
2023-06-08 02:23:10 +00:00
|
|
|
m_settings_widget->UpdateData();
|
2024-03-10 02:34:20 +00:00
|
|
|
m_progress_widget->UpdateData(true);
|
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_leaderboard_widget->UpdateData();
|
2023-12-11 18:18:02 +00:00
|
|
|
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
|