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-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"
|
|
|
|
|
|
|
|
AchievementsWindow::AchievementsWindow(QWidget* parent) : QDialog(parent)
|
|
|
|
{
|
|
|
|
setWindowTitle(tr("Achievements"));
|
|
|
|
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
|
|
|
|
|
|
|
CreateMainLayout();
|
|
|
|
ConnectWidgets();
|
2023-06-03 01:31:30 +00:00
|
|
|
AchievementManager::GetInstance()->SetUpdateCallback(
|
|
|
|
[this] { QueueOnObject(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()
|
|
|
|
{
|
|
|
|
auto* layout = new QVBoxLayout();
|
|
|
|
|
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-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-05-26 22:29:22 +00:00
|
|
|
m_tab_widget->addTab(
|
|
|
|
GetWrappedWidget(new AchievementSettingsWidget(m_tab_widget, this), 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-06-17 15:47:56 +00:00
|
|
|
m_tab_widget->setTabVisible(1, AchievementManager::GetInstance()->IsGameLoaded());
|
|
|
|
m_tab_widget->addTab(GetWrappedWidget(m_leaderboard_widget, this, 125, 100), tr("Leaderboards"));
|
|
|
|
m_tab_widget->setTabVisible(2, AchievementManager::GetInstance()->IsGameLoaded());
|
2023-05-26 22:29:22 +00:00
|
|
|
|
2023-05-26 13:35:50 +00:00
|
|
|
m_button_box = new QDialogButtonBox(QDialogButtonBox::Close);
|
|
|
|
|
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
|
|
|
{
|
|
|
|
std::lock_guard lg{*AchievementManager::GetInstance()->GetLock()};
|
|
|
|
m_header_widget->UpdateData();
|
|
|
|
m_header_widget->setVisible(AchievementManager::GetInstance()->IsLoggedIn());
|
|
|
|
// Settings tab handles its own updates ... indeed, that calls this
|
|
|
|
m_progress_widget->UpdateData();
|
|
|
|
m_tab_widget->setTabVisible(1, AchievementManager::GetInstance()->IsGameLoaded());
|
2023-06-17 15:47:56 +00:00
|
|
|
m_leaderboard_widget->UpdateData();
|
|
|
|
m_tab_widget->setTabVisible(2, AchievementManager::GetInstance()->IsGameLoaded());
|
2023-06-09 21:05:52 +00:00
|
|
|
}
|
2023-05-26 13:35:50 +00:00
|
|
|
update();
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // USE_RETRO_ACHIEVEMENTS
|