From 56beb2c85bd2cfba2dd177a9286a50c91f6e3650 Mon Sep 17 00:00:00 2001 From: Zach Hilman Date: Mon, 24 Dec 2018 17:35:40 -0500 Subject: [PATCH] qt: Add Qt frontend for controller selector applet --- src/yuzu/CMakeLists.txt | 2 + src/yuzu/applets/controller.cpp | 65 +++++++++++++++++++++++++++++++++ src/yuzu/applets/controller.h | 55 ++++++++++++++++++++++++++++ src/yuzu/main.cpp | 16 ++++++++ src/yuzu/main.h | 8 ++++ 5 files changed, 146 insertions(+) create mode 100644 src/yuzu/applets/controller.cpp create mode 100644 src/yuzu/applets/controller.h diff --git a/src/yuzu/CMakeLists.txt b/src/yuzu/CMakeLists.txt index 4cab599b4d..b8265fba7f 100644 --- a/src/yuzu/CMakeLists.txt +++ b/src/yuzu/CMakeLists.txt @@ -7,6 +7,8 @@ add_executable(yuzu Info.plist about_dialog.cpp about_dialog.h + applets/controller.cpp + applets/controller.h applets/profile_select.cpp applets/profile_select.h applets/software_keyboard.cpp diff --git a/src/yuzu/applets/controller.cpp b/src/yuzu/applets/controller.cpp new file mode 100644 index 0000000000..adfd1f954f --- /dev/null +++ b/src/yuzu/applets/controller.cpp @@ -0,0 +1,65 @@ +// Copyright 2018 yuzu Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#include +#include +#include "core/hle/lock.h" +#include "core/hle/service/hid/hid.h" +#include "yuzu/applets/controller.h" +#include "yuzu/configuration/configure_input_simple.h" +#include "yuzu/main.h" + +QtControllerAppletDialog::QtControllerAppletDialog( + QWidget* parent, Core::Frontend::ControllerParameters parameters) { + layout = new QVBoxLayout; + buttons = new QDialogButtonBox; + buttons->addButton(tr("Cancel"), QDialogButtonBox::RejectRole); + buttons->addButton(tr("OK"), QDialogButtonBox::AcceptRole); + + connect(buttons, &QDialogButtonBox::accepted, this, &QtControllerAppletDialog::accept); + connect(buttons, &QDialogButtonBox::rejected, this, &QtControllerAppletDialog::reject); + + input = new ConfigureInputSimple(this, parameters); + layout->addWidget(input); + layout->addWidget(buttons); + setLayout(layout); +} + +QtControllerAppletDialog::~QtControllerAppletDialog() = default; + +void QtControllerAppletDialog::accept() { + input->applyConfiguration(); + ok = true; + QDialog::accept(); +} + +void QtControllerAppletDialog::reject() { + ok = false; + QDialog::reject(); +} + +bool QtControllerAppletDialog::GetStatus() const { + return ok; +} + +QtControllerApplet::QtControllerApplet(GMainWindow& parent) { + connect(this, &QtControllerApplet::MainWindowReconfigureControllers, &parent, + &GMainWindow::ControllerAppletReconfigureControllers, Qt::QueuedConnection); + connect(&parent, &GMainWindow::ControllerAppletReconfigureFinished, this, + &QtControllerApplet::MainWindowReconfigureFinished, Qt::QueuedConnection); +} + +QtControllerApplet::~QtControllerApplet() = default; + +void QtControllerApplet::ReconfigureControllers( + std::function completed, Core::Frontend::ControllerParameters parameters) const { + this->completed = std::move(completed); + emit MainWindowReconfigureControllers(parameters); +} + +void QtControllerApplet::MainWindowReconfigureFinished(bool ok) { + // Acquire the HLE mutex + std::lock_guard lock(HLE::g_hle_lock); + completed(ok); +} diff --git a/src/yuzu/applets/controller.h b/src/yuzu/applets/controller.h new file mode 100644 index 0000000000..2260e0e1b8 --- /dev/null +++ b/src/yuzu/applets/controller.h @@ -0,0 +1,55 @@ +// Copyright 2018 yuzu Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include +#include "core/frontend/applets/controller.h" + +class ConfigureInputSimple; +class GMainWindow; +class QDialogButtonBox; +class QVBoxLayout; + +class QtControllerAppletDialog final : public QDialog { + Q_OBJECT + +public: + QtControllerAppletDialog(QWidget* parent, Core::Frontend::ControllerParameters parameters); + ~QtControllerAppletDialog() override; + + void accept() override; + void reject() override; + + bool GetStatus() const; + +private: + bool ok = false; + + QVBoxLayout* layout; + + QDialogButtonBox* buttons; + ConfigureInputSimple* input; + + Core::Frontend::ControllerParameters parameters; +}; + +class QtControllerApplet final : public QObject, public Core::Frontend::ControllerApplet { + Q_OBJECT + +public: + explicit QtControllerApplet(GMainWindow& parent); + ~QtControllerApplet() override; + + void ReconfigureControllers(std::function completed, + Core::Frontend::ControllerParameters parameters) const override; + +signals: + void MainWindowReconfigureControllers(Core::Frontend::ControllerParameters parameters) const; + +private: + void MainWindowReconfigureFinished(bool ok); + + mutable std::function completed; +}; diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index 5ab7896d4e..c5c400418d 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp @@ -8,12 +8,15 @@ #include // VFS includes must be before glad as they will conflict with Windows file api, which uses defines. +#include "applets/controller.h" #include "applets/profile_select.h" #include "applets/software_keyboard.h" #include "applets/web_browser.h" +#include "configuration/configure_input_simple.h" #include "configuration/configure_per_general.h" #include "core/file_sys/vfs.h" #include "core/file_sys/vfs_real.h" +#include "core/frontend/applets/controller.h" #include "core/frontend/scope_acquire_window_context.h" #include "core/hle/service/acc/profile_manager.h" #include "core/hle/service/am/applets/applets.h" @@ -222,6 +225,17 @@ GMainWindow::~GMainWindow() { delete render_window; } +void GMainWindow::ControllerAppletReconfigureControllers( + const Core::Frontend::ControllerParameters& parameters) { + QtControllerAppletDialog dialog(this, parameters); + dialog.setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint | + Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint); + dialog.setWindowModality(Qt::WindowModal); + dialog.exec(); + + emit ControllerAppletReconfigureFinished(dialog.GetStatus()); +} + void GMainWindow::ProfileSelectorSelectProfile() { QtProfileSelectionDialog dialog(this); dialog.setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint | @@ -777,6 +791,7 @@ bool GMainWindow::LoadROM(const QString& filename) { system.SetGPUDebugContext(debug_context); + system.SetControllerApplet(std::make_unique(*this)); system.SetProfileSelector(std::make_unique(*this)); system.SetSoftwareKeyboard(std::make_unique(*this)); system.SetWebBrowser(std::make_unique(*this)); @@ -1491,6 +1506,7 @@ void GMainWindow::OnMenuRecentFile() { void GMainWindow::OnStartGame() { emu_thread->SetRunning(true); + qRegisterMetaType("Core::Frontend::ControllerParameters"); qRegisterMetaType( "Core::Frontend::SoftwareKeyboardParameters"); qRegisterMetaType("Core::System::ResultStatus"); diff --git a/src/yuzu/main.h b/src/yuzu/main.h index e07c892cf2..5cf3dd69f7 100644 --- a/src/yuzu/main.h +++ b/src/yuzu/main.h @@ -33,6 +33,7 @@ class WaitTreeWidget; enum class GameListOpenTarget; namespace Core::Frontend { +struct ControllerParameters; struct SoftwareKeyboardParameters; } // namespace Core::Frontend @@ -102,7 +103,10 @@ signals: // Signal that tells widgets to update icons to use the current theme void UpdateThemedIcons(); + void ControllerAppletReconfigureFinished(bool ok); + void ProfileSelectorFinishedSelection(std::optional uuid); + void SoftwareKeyboardFinishedText(std::optional text); void SoftwareKeyboardFinishedCheckDialog(); @@ -111,7 +115,11 @@ signals: public slots: void OnLoadComplete(); + void ControllerAppletReconfigureControllers( + const Core::Frontend::ControllerParameters& parameters); + void ProfileSelectorSelectProfile(); + void SoftwareKeyboardGetText(const Core::Frontend::SoftwareKeyboardParameters& parameters); void SoftwareKeyboardInvokeCheckDialog(std::u16string error_message); void WebBrowserOpenPage(std::string_view filename, std::string_view arguments);