From e1e662b86a15bb533ae3a9f04ce92d551460ef5e Mon Sep 17 00:00:00 2001 From: LillyJadeKatrin Date: Fri, 26 May 2023 09:35:50 -0400 Subject: [PATCH] Added AchievementsWindow QDialog AchievementsWindow is the dialog box that will eventually contain the settings and progress data for RetroAchievements on Dolphin. This adds the barebones dialog, and connects it to MainWindow's MenuBar. --- .../Achievements/AchievementsWindow.cpp | 48 +++++++++++++++++++ .../Achievements/AchievementsWindow.h | 26 ++++++++++ Source/Core/DolphinQt/CMakeLists.txt | 2 + Source/Core/DolphinQt/DolphinQt.vcxproj | 2 + Source/Core/DolphinQt/MainWindow.cpp | 19 ++++++++ Source/Core/DolphinQt/MainWindow.h | 9 ++++ Source/Core/DolphinQt/MenuBar.cpp | 10 ++++ Source/Core/DolphinQt/MenuBar.h | 4 ++ 8 files changed, 120 insertions(+) create mode 100644 Source/Core/DolphinQt/Achievements/AchievementsWindow.cpp create mode 100644 Source/Core/DolphinQt/Achievements/AchievementsWindow.h diff --git a/Source/Core/DolphinQt/Achievements/AchievementsWindow.cpp b/Source/Core/DolphinQt/Achievements/AchievementsWindow.cpp new file mode 100644 index 0000000000..b3b9616dcb --- /dev/null +++ b/Source/Core/DolphinQt/Achievements/AchievementsWindow.cpp @@ -0,0 +1,48 @@ +// Copyright 2023 Dolphin Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#ifdef USE_RETRO_ACHIEVEMENTS +#include "DolphinQt/Achievements/AchievementsWindow.h" + +#include +#include + +#include "DolphinQt/QtUtils/WrapInScrollArea.h" + +AchievementsWindow::AchievementsWindow(QWidget* parent) : QDialog(parent) +{ + setWindowTitle(tr("Achievements")); + setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint); + + CreateMainLayout(); + ConnectWidgets(); +} + +void AchievementsWindow::showEvent(QShowEvent* event) +{ + QDialog::showEvent(event); + update(); +} + +void AchievementsWindow::CreateMainLayout() +{ + auto* layout = new QVBoxLayout(); + + m_button_box = new QDialogButtonBox(QDialogButtonBox::Close); + + layout->addWidget(m_button_box); + + WrapInScrollArea(this, layout); +} + +void AchievementsWindow::ConnectWidgets() +{ + connect(m_button_box, &QDialogButtonBox::rejected, this, &QDialog::reject); +} + +void AchievementsWindow::UpdateData() +{ + update(); +} + +#endif // USE_RETRO_ACHIEVEMENTS diff --git a/Source/Core/DolphinQt/Achievements/AchievementsWindow.h b/Source/Core/DolphinQt/Achievements/AchievementsWindow.h new file mode 100644 index 0000000000..3ac28c6a17 --- /dev/null +++ b/Source/Core/DolphinQt/Achievements/AchievementsWindow.h @@ -0,0 +1,26 @@ +// Copyright 2023 Dolphin Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#ifdef USE_RETRO_ACHIEVEMENTS +#include + +class QDialogButtonBox; + +class AchievementsWindow : public QDialog +{ + Q_OBJECT +public: + explicit AchievementsWindow(QWidget* parent); + void UpdateData(); + +private: + void CreateMainLayout(); + void showEvent(QShowEvent* event); + void ConnectWidgets(); + + QDialogButtonBox* m_button_box; +}; + +#endif // USE_RETRO_ACHIEVEMENTS diff --git a/Source/Core/DolphinQt/CMakeLists.txt b/Source/Core/DolphinQt/CMakeLists.txt index 4b576c1776..4c774831c8 100644 --- a/Source/Core/DolphinQt/CMakeLists.txt +++ b/Source/Core/DolphinQt/CMakeLists.txt @@ -27,6 +27,8 @@ add_executable(dolphin-emu CheatSearchWidget.h CheatsManager.cpp CheatsManager.h + Achievements/AchievementsWindow.cpp + Achievements/AchievementsWindow.h Config/ARCodeWidget.cpp Config/ARCodeWidget.h Config/CheatCodeEditor.cpp diff --git a/Source/Core/DolphinQt/DolphinQt.vcxproj b/Source/Core/DolphinQt/DolphinQt.vcxproj index 55eedc5424..a9de3f8a14 100644 --- a/Source/Core/DolphinQt/DolphinQt.vcxproj +++ b/Source/Core/DolphinQt/DolphinQt.vcxproj @@ -50,6 +50,7 @@ + @@ -252,6 +253,7 @@ + diff --git a/Source/Core/DolphinQt/MainWindow.cpp b/Source/Core/DolphinQt/MainWindow.cpp index e0342a4f8e..8262c8f01e 100644 --- a/Source/Core/DolphinQt/MainWindow.cpp +++ b/Source/Core/DolphinQt/MainWindow.cpp @@ -72,6 +72,7 @@ #include "DiscIO/RiivolutionPatcher.h" #include "DolphinQt/AboutDialog.h" +#include "DolphinQt/Achievements/AchievementsWindow.h" #include "DolphinQt/CheatsManager.h" #include "DolphinQt/Config/ControllersWindow.h" #include "DolphinQt/Config/FreeLookWindow.h" @@ -544,6 +545,10 @@ void MainWindow::ConnectMenuBar() connect(m_menu_bar, &MenuBar::ShowInfinityBase, this, &MainWindow::ShowInfinityBase); connect(m_menu_bar, &MenuBar::ConnectWiiRemote, this, &MainWindow::OnConnectWiiRemote); +#ifdef USE_RETRO_ACHIEVEMENTS + connect(m_menu_bar, &MenuBar::ShowAchievementsWindow, this, &MainWindow::ShowAchievementsWindow); +#endif // USE_RETRO_ACHIEVEMENTS + // Movie connect(m_menu_bar, &MenuBar::PlayRecording, this, &MainWindow::OnPlayRecording); connect(m_menu_bar, &MenuBar::StartRecording, this, &MainWindow::OnStartRecording); @@ -1892,6 +1897,20 @@ void MainWindow::OnConnectWiiRemote(int id) }); } +#ifdef USE_RETRO_ACHIEVEMENTS +void MainWindow::ShowAchievementsWindow() +{ + if (!m_achievements_window) + { + m_achievements_window = new AchievementsWindow(this); + } + + m_achievements_window->show(); + m_achievements_window->raise(); + m_achievements_window->activateWindow(); +} +#endif // USE_RETRO_ACHIEVEMENTS + void MainWindow::ShowMemcardManager() { GCMemcardManager manager(this); diff --git a/Source/Core/DolphinQt/MainWindow.h b/Source/Core/DolphinQt/MainWindow.h index 869d77cc07..fa3a274bfc 100644 --- a/Source/Core/DolphinQt/MainWindow.h +++ b/Source/Core/DolphinQt/MainWindow.h @@ -16,6 +16,7 @@ class QStackedWidget; class QString; +class AchievementsWindow; class BreakpointWidget; struct BootParameters; class CheatsManager; @@ -168,6 +169,10 @@ private: void ShowCheatsManager(); void ShowRiivolutionBootWidget(const UICommon::GameFile& game); +#ifdef USE_RETRO_ACHIEVEMENTS + void ShowAchievementsWindow(); +#endif // USE_RETRO_ACHIEVEMENTS + void NetPlayInit(); bool NetPlayJoin(); bool NetPlayHost(const UICommon::GameFile& game); @@ -241,6 +246,10 @@ private: static constexpr int num_wii_controllers = 4; std::array m_wii_tas_input_windows{}; +#ifdef USE_RETRO_ACHIEVEMENTS + AchievementsWindow* m_achievements_window = nullptr; +#endif // USE_RETRO_ACHIEVEMENTS + BreakpointWidget* m_breakpoint_widget; CodeWidget* m_code_widget; JITWidget* m_jit_widget; diff --git a/Source/Core/DolphinQt/MenuBar.cpp b/Source/Core/DolphinQt/MenuBar.cpp index 663aadd341..b0989fae66 100644 --- a/Source/Core/DolphinQt/MenuBar.cpp +++ b/Source/Core/DolphinQt/MenuBar.cpp @@ -21,6 +21,7 @@ #include "Core/Boot/Boot.h" #include "Core/CommonTitles.h" +#include "Core/Config/AchievementSettings.h" #include "Core/Config/MainSettings.h" #include "Core/ConfigManager.h" #include "Core/Core.h" @@ -236,6 +237,15 @@ void MenuBar::AddToolsMenu() tools_menu->addSeparator(); +#ifdef USE_RETRO_ACHIEVEMENTS + if (Config::Get(Config::RA_ENABLED)) + { + tools_menu->addAction(tr("Achievements"), this, [this] { emit ShowAchievementsWindow(); }); + + tools_menu->addSeparator(); + } +#endif // USE_RETRO_ACHIEVEMENTS + QMenu* gc_ipl = tools_menu->addMenu(tr("Load GameCube Main Menu")); m_ntscj_ipl = gc_ipl->addAction(tr("NTSC-J"), this, diff --git a/Source/Core/DolphinQt/MenuBar.h b/Source/Core/DolphinQt/MenuBar.h index ba6490e1d9..a5c5730b6b 100644 --- a/Source/Core/DolphinQt/MenuBar.h +++ b/Source/Core/DolphinQt/MenuBar.h @@ -93,6 +93,10 @@ signals: void ShowInfinityBase(); void ConnectWiiRemote(int id); +#ifdef USE_RETRO_ACHIEVEMENTS + void ShowAchievementsWindow(); +#endif // USE_RETRO_ACHIEVEMENTS + // Options void Configure(); void ConfigureGraphics();