diff options
| author | 2018-12-23 14:34:29 -0500 | |
|---|---|---|
| committer | 2018-12-23 14:34:29 -0500 | |
| commit | d08bdc861f056cd217fb58b3cbe9beb2357d9d22 (patch) | |
| tree | b34733dbf529f83476d96b2354e4fe71f63ba2e6 /src | |
| parent | Merge pull request #1921 from ogniK5377/no-unit (diff) | |
| parent | configure_input_simple: Properly signal docked mode change (diff) | |
| download | yuzu-d08bdc861f056cd217fb58b3cbe9beb2357d9d22.tar.gz yuzu-d08bdc861f056cd217fb58b3cbe9beb2357d9d22.tar.xz yuzu-d08bdc861f056cd217fb58b3cbe9beb2357d9d22.zip | |
Merge pull request #1780 from DarkLordZach/controller-profiles
configure_input: Add Controller Setup Profiles and simplify input UI
Diffstat (limited to 'src')
| -rw-r--r-- | src/yuzu/CMakeLists.txt | 3 | ||||
| -rw-r--r-- | src/yuzu/configuration/config.cpp | 12 | ||||
| -rw-r--r-- | src/yuzu/configuration/config.h | 1 | ||||
| -rw-r--r-- | src/yuzu/configuration/configure.ui | 52 | ||||
| -rw-r--r-- | src/yuzu/configuration/configure_input.cpp | 60 | ||||
| -rw-r--r-- | src/yuzu/configuration/configure_input.h | 8 | ||||
| -rw-r--r-- | src/yuzu/configuration/configure_input.ui | 48 | ||||
| -rw-r--r-- | src/yuzu/configuration/configure_input_player.cpp | 1 | ||||
| -rw-r--r-- | src/yuzu/configuration/configure_input_simple.cpp | 142 | ||||
| -rw-r--r-- | src/yuzu/configuration/configure_input_simple.h | 40 | ||||
| -rw-r--r-- | src/yuzu/configuration/configure_input_simple.ui | 97 | ||||
| -rw-r--r-- | src/yuzu/ui_settings.h | 3 |
12 files changed, 401 insertions, 66 deletions
diff --git a/src/yuzu/CMakeLists.txt b/src/yuzu/CMakeLists.txt index 3232aa8fb..0691b91a2 100644 --- a/src/yuzu/CMakeLists.txt +++ b/src/yuzu/CMakeLists.txt | |||
| @@ -31,6 +31,8 @@ add_executable(yuzu | |||
| 31 | configuration/configure_input.h | 31 | configuration/configure_input.h |
| 32 | configuration/configure_input_player.cpp | 32 | configuration/configure_input_player.cpp |
| 33 | configuration/configure_input_player.h | 33 | configuration/configure_input_player.h |
| 34 | configuration/configure_input_simple.cpp | ||
| 35 | configuration/configure_input_simple.h | ||
| 34 | configuration/configure_mouse_advanced.cpp | 36 | configuration/configure_mouse_advanced.cpp |
| 35 | configuration/configure_mouse_advanced.h | 37 | configuration/configure_mouse_advanced.h |
| 36 | configuration/configure_system.cpp | 38 | configuration/configure_system.cpp |
| @@ -87,6 +89,7 @@ set(UIS | |||
| 87 | configuration/configure_graphics.ui | 89 | configuration/configure_graphics.ui |
| 88 | configuration/configure_input.ui | 90 | configuration/configure_input.ui |
| 89 | configuration/configure_input_player.ui | 91 | configuration/configure_input_player.ui |
| 92 | configuration/configure_input_simple.ui | ||
| 90 | configuration/configure_mouse_advanced.ui | 93 | configuration/configure_mouse_advanced.ui |
| 91 | configuration/configure_per_general.ui | 94 | configuration/configure_per_general.ui |
| 92 | configuration/configure_system.ui | 95 | configuration/configure_system.ui |
diff --git a/src/yuzu/configuration/config.cpp b/src/yuzu/configuration/config.cpp index eb2077b0f..759362ce3 100644 --- a/src/yuzu/configuration/config.cpp +++ b/src/yuzu/configuration/config.cpp | |||
| @@ -4,6 +4,7 @@ | |||
| 4 | 4 | ||
| 5 | #include <QSettings> | 5 | #include <QSettings> |
| 6 | #include "common/file_util.h" | 6 | #include "common/file_util.h" |
| 7 | #include "configure_input_simple.h" | ||
| 7 | #include "core/hle/service/acc/profile_manager.h" | 8 | #include "core/hle/service/acc/profile_manager.h" |
| 8 | #include "core/hle/service/hid/controllers/npad.h" | 9 | #include "core/hle/service/hid/controllers/npad.h" |
| 9 | #include "input_common/main.h" | 10 | #include "input_common/main.h" |
| @@ -339,6 +340,13 @@ void Config::ReadTouchscreenValues() { | |||
| 339 | qt_config->endGroup(); | 340 | qt_config->endGroup(); |
| 340 | } | 341 | } |
| 341 | 342 | ||
| 343 | void Config::ApplyDefaultProfileIfInputInvalid() { | ||
| 344 | if (!std::any_of(Settings::values.players.begin(), Settings::values.players.end(), | ||
| 345 | [](const Settings::PlayerInput& in) { return in.connected; })) { | ||
| 346 | ApplyInputProfileConfiguration(UISettings::values.profile_index); | ||
| 347 | } | ||
| 348 | } | ||
| 349 | |||
| 342 | void Config::ReadValues() { | 350 | void Config::ReadValues() { |
| 343 | qt_config->beginGroup("Controls"); | 351 | qt_config->beginGroup("Controls"); |
| 344 | 352 | ||
| @@ -518,6 +526,9 @@ void Config::ReadValues() { | |||
| 518 | UISettings::values.first_start = qt_config->value("firstStart", true).toBool(); | 526 | UISettings::values.first_start = qt_config->value("firstStart", true).toBool(); |
| 519 | UISettings::values.callout_flags = qt_config->value("calloutFlags", 0).toUInt(); | 527 | UISettings::values.callout_flags = qt_config->value("calloutFlags", 0).toUInt(); |
| 520 | UISettings::values.show_console = qt_config->value("showConsole", false).toBool(); | 528 | UISettings::values.show_console = qt_config->value("showConsole", false).toBool(); |
| 529 | UISettings::values.profile_index = qt_config->value("profileIndex", 0).toUInt(); | ||
| 530 | |||
| 531 | ApplyDefaultProfileIfInputInvalid(); | ||
| 521 | 532 | ||
| 522 | qt_config->endGroup(); | 533 | qt_config->endGroup(); |
| 523 | } | 534 | } |
| @@ -720,6 +731,7 @@ void Config::SaveValues() { | |||
| 720 | qt_config->setValue("firstStart", UISettings::values.first_start); | 731 | qt_config->setValue("firstStart", UISettings::values.first_start); |
| 721 | qt_config->setValue("calloutFlags", UISettings::values.callout_flags); | 732 | qt_config->setValue("calloutFlags", UISettings::values.callout_flags); |
| 722 | qt_config->setValue("showConsole", UISettings::values.show_console); | 733 | qt_config->setValue("showConsole", UISettings::values.show_console); |
| 734 | qt_config->setValue("profileIndex", UISettings::values.profile_index); | ||
| 723 | qt_config->endGroup(); | 735 | qt_config->endGroup(); |
| 724 | } | 736 | } |
| 725 | 737 | ||
diff --git a/src/yuzu/configuration/config.h b/src/yuzu/configuration/config.h index a1c27bbf9..e73ad19bb 100644 --- a/src/yuzu/configuration/config.h +++ b/src/yuzu/configuration/config.h | |||
| @@ -34,6 +34,7 @@ private: | |||
| 34 | void ReadKeyboardValues(); | 34 | void ReadKeyboardValues(); |
| 35 | void ReadMouseValues(); | 35 | void ReadMouseValues(); |
| 36 | void ReadTouchscreenValues(); | 36 | void ReadTouchscreenValues(); |
| 37 | void ApplyDefaultProfileIfInputInvalid(); | ||
| 37 | 38 | ||
| 38 | void SaveValues(); | 39 | void SaveValues(); |
| 39 | void SavePlayerValues(); | 40 | void SavePlayerValues(); |
diff --git a/src/yuzu/configuration/configure.ui b/src/yuzu/configuration/configure.ui index 9b297df28..8706b80d2 100644 --- a/src/yuzu/configuration/configure.ui +++ b/src/yuzu/configuration/configure.ui | |||
| @@ -7,7 +7,7 @@ | |||
| 7 | <x>0</x> | 7 | <x>0</x> |
| 8 | <y>0</y> | 8 | <y>0</y> |
| 9 | <width>461</width> | 9 | <width>461</width> |
| 10 | <height>500</height> | 10 | <height>659</height> |
| 11 | </rect> | 11 | </rect> |
| 12 | </property> | 12 | </property> |
| 13 | <property name="windowTitle"> | 13 | <property name="windowTitle"> |
| @@ -24,17 +24,17 @@ | |||
| 24 | <string>General</string> | 24 | <string>General</string> |
| 25 | </attribute> | 25 | </attribute> |
| 26 | </widget> | 26 | </widget> |
| 27 | <widget class="ConfigureGameList" name="gameListTab"> | 27 | <widget class="ConfigureGameList" name="gameListTab"> |
| 28 | <attribute name="title"> | 28 | <attribute name="title"> |
| 29 | <string>Game List</string> | 29 | <string>Game List</string> |
| 30 | </attribute> | 30 | </attribute> |
| 31 | </widget> | 31 | </widget> |
| 32 | <widget class="ConfigureSystem" name="systemTab"> | 32 | <widget class="ConfigureSystem" name="systemTab"> |
| 33 | <attribute name="title"> | 33 | <attribute name="title"> |
| 34 | <string>System</string> | 34 | <string>System</string> |
| 35 | </attribute> | 35 | </attribute> |
| 36 | </widget> | 36 | </widget> |
| 37 | <widget class="ConfigureInput" name="inputTab"> | 37 | <widget class="ConfigureInputSimple" name="inputTab"> |
| 38 | <attribute name="title"> | 38 | <attribute name="title"> |
| 39 | <string>Input</string> | 39 | <string>Input</string> |
| 40 | </attribute> | 40 | </attribute> |
| @@ -54,11 +54,11 @@ | |||
| 54 | <string>Debug</string> | 54 | <string>Debug</string> |
| 55 | </attribute> | 55 | </attribute> |
| 56 | </widget> | 56 | </widget> |
| 57 | <widget class="ConfigureWeb" name="webTab"> | 57 | <widget class="ConfigureWeb" name="webTab"> |
| 58 | <attribute name="title"> | 58 | <attribute name="title"> |
| 59 | <string>Web</string> | 59 | <string>Web</string> |
| 60 | </attribute> | 60 | </attribute> |
| 61 | </widget> | 61 | </widget> |
| 62 | </widget> | 62 | </widget> |
| 63 | </item> | 63 | </item> |
| 64 | <item> | 64 | <item> |
| @@ -77,12 +77,12 @@ | |||
| 77 | <header>configuration/configure_general.h</header> | 77 | <header>configuration/configure_general.h</header> |
| 78 | <container>1</container> | 78 | <container>1</container> |
| 79 | </customwidget> | 79 | </customwidget> |
| 80 | <customwidget> | 80 | <customwidget> |
| 81 | <class>ConfigureGameList</class> | 81 | <class>ConfigureGameList</class> |
| 82 | <extends>QWidget</extends> | 82 | <extends>QWidget</extends> |
| 83 | <header>configuration/configure_gamelist.h</header> | 83 | <header>configuration/configure_gamelist.h</header> |
| 84 | <container>1</container> | 84 | <container>1</container> |
| 85 | </customwidget> | 85 | </customwidget> |
| 86 | <customwidget> | 86 | <customwidget> |
| 87 | <class>ConfigureSystem</class> | 87 | <class>ConfigureSystem</class> |
| 88 | <extends>QWidget</extends> | 88 | <extends>QWidget</extends> |
| @@ -102,9 +102,9 @@ | |||
| 102 | <container>1</container> | 102 | <container>1</container> |
| 103 | </customwidget> | 103 | </customwidget> |
| 104 | <customwidget> | 104 | <customwidget> |
| 105 | <class>ConfigureInput</class> | 105 | <class>ConfigureInputSimple</class> |
| 106 | <extends>QWidget</extends> | 106 | <extends>QWidget</extends> |
| 107 | <header>configuration/configure_input.h</header> | 107 | <header>configuration/configure_input_simple.h</header> |
| 108 | <container>1</container> | 108 | <container>1</container> |
| 109 | </customwidget> | 109 | </customwidget> |
| 110 | <customwidget> | 110 | <customwidget> |
| @@ -113,12 +113,12 @@ | |||
| 113 | <header>configuration/configure_graphics.h</header> | 113 | <header>configuration/configure_graphics.h</header> |
| 114 | <container>1</container> | 114 | <container>1</container> |
| 115 | </customwidget> | 115 | </customwidget> |
| 116 | <customwidget> | 116 | <customwidget> |
| 117 | <class>ConfigureWeb</class> | 117 | <class>ConfigureWeb</class> |
| 118 | <extends>QWidget</extends> | 118 | <extends>QWidget</extends> |
| 119 | <header>configuration/configure_web.h</header> | 119 | <header>configuration/configure_web.h</header> |
| 120 | <container>1</container> | 120 | <container>1</container> |
| 121 | </customwidget> | 121 | </customwidget> |
| 122 | </customwidgets> | 122 | </customwidgets> |
| 123 | <resources/> | 123 | <resources/> |
| 124 | <connections> | 124 | <connections> |
diff --git a/src/yuzu/configuration/configure_input.cpp b/src/yuzu/configuration/configure_input.cpp index 830d26115..f39d57998 100644 --- a/src/yuzu/configuration/configure_input.cpp +++ b/src/yuzu/configuration/configure_input.cpp | |||
| @@ -20,6 +20,33 @@ | |||
| 20 | #include "yuzu/configuration/configure_input_player.h" | 20 | #include "yuzu/configuration/configure_input_player.h" |
| 21 | #include "yuzu/configuration/configure_mouse_advanced.h" | 21 | #include "yuzu/configuration/configure_mouse_advanced.h" |
| 22 | 22 | ||
| 23 | void OnDockedModeChanged(bool last_state, bool new_state) { | ||
| 24 | if (last_state == new_state) { | ||
| 25 | return; | ||
| 26 | } | ||
| 27 | |||
| 28 | Core::System& system{Core::System::GetInstance()}; | ||
| 29 | if (!system.IsPoweredOn()) { | ||
| 30 | return; | ||
| 31 | } | ||
| 32 | Service::SM::ServiceManager& sm = system.ServiceManager(); | ||
| 33 | |||
| 34 | // Message queue is shared between these services, we just need to signal an operation | ||
| 35 | // change to one and it will handle both automatically | ||
| 36 | auto applet_oe = sm.GetService<Service::AM::AppletOE>("appletOE"); | ||
| 37 | auto applet_ae = sm.GetService<Service::AM::AppletAE>("appletAE"); | ||
| 38 | bool has_signalled = false; | ||
| 39 | |||
| 40 | if (applet_oe != nullptr) { | ||
| 41 | applet_oe->GetMessageQueue()->OperationModeChanged(); | ||
| 42 | has_signalled = true; | ||
| 43 | } | ||
| 44 | |||
| 45 | if (applet_ae != nullptr && !has_signalled) { | ||
| 46 | applet_ae->GetMessageQueue()->OperationModeChanged(); | ||
| 47 | } | ||
| 48 | } | ||
| 49 | |||
| 23 | namespace { | 50 | namespace { |
| 24 | template <typename Dialog, typename... Args> | 51 | template <typename Dialog, typename... Args> |
| 25 | void CallConfigureDialog(ConfigureInput& parent, Args&&... args) { | 52 | void CallConfigureDialog(ConfigureInput& parent, Args&&... args) { |
| @@ -34,7 +61,7 @@ void CallConfigureDialog(ConfigureInput& parent, Args&&... args) { | |||
| 34 | } // Anonymous namespace | 61 | } // Anonymous namespace |
| 35 | 62 | ||
| 36 | ConfigureInput::ConfigureInput(QWidget* parent) | 63 | ConfigureInput::ConfigureInput(QWidget* parent) |
| 37 | : QWidget(parent), ui(std::make_unique<Ui::ConfigureInput>()) { | 64 | : QDialog(parent), ui(std::make_unique<Ui::ConfigureInput>()) { |
| 38 | ui->setupUi(this); | 65 | ui->setupUi(this); |
| 39 | 66 | ||
| 40 | players_controller = { | 67 | players_controller = { |
| @@ -90,37 +117,6 @@ ConfigureInput::ConfigureInput(QWidget* parent) | |||
| 90 | 117 | ||
| 91 | ConfigureInput::~ConfigureInput() = default; | 118 | ConfigureInput::~ConfigureInput() = default; |
| 92 | 119 | ||
| 93 | void ConfigureInput::OnDockedModeChanged(bool last_state, bool new_state) { | ||
| 94 | if (ui->use_docked_mode->isChecked() && ui->handheld_connected->isChecked()) { | ||
| 95 | ui->handheld_connected->setChecked(false); | ||
| 96 | } | ||
| 97 | |||
| 98 | if (last_state == new_state) { | ||
| 99 | return; | ||
| 100 | } | ||
| 101 | |||
| 102 | Core::System& system{Core::System::GetInstance()}; | ||
| 103 | if (!system.IsPoweredOn()) { | ||
| 104 | return; | ||
| 105 | } | ||
| 106 | Service::SM::ServiceManager& sm = system.ServiceManager(); | ||
| 107 | |||
| 108 | // Message queue is shared between these services, we just need to signal an operation | ||
| 109 | // change to one and it will handle both automatically | ||
| 110 | auto applet_oe = sm.GetService<Service::AM::AppletOE>("appletOE"); | ||
| 111 | auto applet_ae = sm.GetService<Service::AM::AppletAE>("appletAE"); | ||
| 112 | bool has_signalled = false; | ||
| 113 | |||
| 114 | if (applet_oe != nullptr) { | ||
| 115 | applet_oe->GetMessageQueue()->OperationModeChanged(); | ||
| 116 | has_signalled = true; | ||
| 117 | } | ||
| 118 | |||
| 119 | if (applet_ae != nullptr && !has_signalled) { | ||
| 120 | applet_ae->GetMessageQueue()->OperationModeChanged(); | ||
| 121 | } | ||
| 122 | } | ||
| 123 | |||
| 124 | void ConfigureInput::applyConfiguration() { | 120 | void ConfigureInput::applyConfiguration() { |
| 125 | for (std::size_t i = 0; i < players_controller.size(); ++i) { | 121 | for (std::size_t i = 0; i < players_controller.size(); ++i) { |
| 126 | const auto controller_type_index = players_controller[i]->currentIndex(); | 122 | const auto controller_type_index = players_controller[i]->currentIndex(); |
diff --git a/src/yuzu/configuration/configure_input.h b/src/yuzu/configuration/configure_input.h index 1649e4c0b..b8e62cc2b 100644 --- a/src/yuzu/configuration/configure_input.h +++ b/src/yuzu/configuration/configure_input.h | |||
| @@ -7,8 +7,8 @@ | |||
| 7 | #include <array> | 7 | #include <array> |
| 8 | #include <memory> | 8 | #include <memory> |
| 9 | 9 | ||
| 10 | #include <QDialog> | ||
| 10 | #include <QKeyEvent> | 11 | #include <QKeyEvent> |
| 11 | #include <QWidget> | ||
| 12 | 12 | ||
| 13 | #include "ui_configure_input.h" | 13 | #include "ui_configure_input.h" |
| 14 | 14 | ||
| @@ -20,7 +20,9 @@ namespace Ui { | |||
| 20 | class ConfigureInput; | 20 | class ConfigureInput; |
| 21 | } | 21 | } |
| 22 | 22 | ||
| 23 | class ConfigureInput : public QWidget { | 23 | void OnDockedModeChanged(bool last_state, bool new_state); |
| 24 | |||
| 25 | class ConfigureInput : public QDialog { | ||
| 24 | Q_OBJECT | 26 | Q_OBJECT |
| 25 | 27 | ||
| 26 | public: | 28 | public: |
| @@ -33,8 +35,6 @@ public: | |||
| 33 | private: | 35 | private: |
| 34 | void updateUIEnabled(); | 36 | void updateUIEnabled(); |
| 35 | 37 | ||
| 36 | void OnDockedModeChanged(bool last_state, bool new_state); | ||
| 37 | |||
| 38 | /// Load configuration settings. | 38 | /// Load configuration settings. |
| 39 | void loadConfiguration(); | 39 | void loadConfiguration(); |
| 40 | /// Restore all buttons to their default values. | 40 | /// Restore all buttons to their default values. |
diff --git a/src/yuzu/configuration/configure_input.ui b/src/yuzu/configuration/configure_input.ui index dae8277bc..0a2d9f024 100644 --- a/src/yuzu/configuration/configure_input.ui +++ b/src/yuzu/configuration/configure_input.ui | |||
| @@ -1,13 +1,13 @@ | |||
| 1 | <?xml version="1.0" encoding="UTF-8"?> | 1 | <?xml version="1.0" encoding="UTF-8"?> |
| 2 | <ui version="4.0"> | 2 | <ui version="4.0"> |
| 3 | <class>ConfigureInput</class> | 3 | <class>ConfigureInput</class> |
| 4 | <widget class="QWidget" name="ConfigureInput"> | 4 | <widget class="QDialog" name="ConfigureInput"> |
| 5 | <property name="geometry"> | 5 | <property name="geometry"> |
| 6 | <rect> | 6 | <rect> |
| 7 | <x>0</x> | 7 | <x>0</x> |
| 8 | <y>0</y> | 8 | <y>0</y> |
| 9 | <width>473</width> | 9 | <width>384</width> |
| 10 | <height>685</height> | 10 | <height>576</height> |
| 11 | </rect> | 11 | </rect> |
| 12 | </property> | 12 | </property> |
| 13 | <property name="windowTitle"> | 13 | <property name="windowTitle"> |
| @@ -478,6 +478,13 @@ | |||
| 478 | </property> | 478 | </property> |
| 479 | </spacer> | 479 | </spacer> |
| 480 | </item> | 480 | </item> |
| 481 | <item> | ||
| 482 | <widget class="QDialogButtonBox" name="buttonBox"> | ||
| 483 | <property name="standardButtons"> | ||
| 484 | <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> | ||
| 485 | </property> | ||
| 486 | </widget> | ||
| 487 | </item> | ||
| 481 | </layout> | 488 | </layout> |
| 482 | </item> | 489 | </item> |
| 483 | </layout> | 490 | </layout> |
| @@ -485,5 +492,38 @@ | |||
| 485 | </layout> | 492 | </layout> |
| 486 | </widget> | 493 | </widget> |
| 487 | <resources/> | 494 | <resources/> |
| 488 | <connections/> | 495 | <connections> |
| 496 | <connection> | ||
| 497 | <sender>buttonBox</sender> | ||
| 498 | <signal>accepted()</signal> | ||
| 499 | <receiver>ConfigureInput</receiver> | ||
| 500 | <slot>accept()</slot> | ||
| 501 | <hints> | ||
| 502 | <hint type="sourcelabel"> | ||
| 503 | <x>294</x> | ||
| 504 | <y>553</y> | ||
| 505 | </hint> | ||
| 506 | <hint type="destinationlabel"> | ||
| 507 | <x>191</x> | ||
| 508 | <y>287</y> | ||
| 509 | </hint> | ||
| 510 | </hints> | ||
| 511 | </connection> | ||
| 512 | <connection> | ||
| 513 | <sender>buttonBox</sender> | ||
| 514 | <signal>rejected()</signal> | ||
| 515 | <receiver>ConfigureInput</receiver> | ||
| 516 | <slot>reject()</slot> | ||
| 517 | <hints> | ||
| 518 | <hint type="sourcelabel"> | ||
| 519 | <x>294</x> | ||
| 520 | <y>553</y> | ||
| 521 | </hint> | ||
| 522 | <hint type="destinationlabel"> | ||
| 523 | <x>191</x> | ||
| 524 | <y>287</y> | ||
| 525 | </hint> | ||
| 526 | </hints> | ||
| 527 | </connection> | ||
| 528 | </connections> | ||
| 489 | </ui> | 529 | </ui> |
diff --git a/src/yuzu/configuration/configure_input_player.cpp b/src/yuzu/configuration/configure_input_player.cpp index 7dadd83c1..ba2b32c4f 100644 --- a/src/yuzu/configuration/configure_input_player.cpp +++ b/src/yuzu/configuration/configure_input_player.cpp | |||
| @@ -6,6 +6,7 @@ | |||
| 6 | #include <memory> | 6 | #include <memory> |
| 7 | #include <utility> | 7 | #include <utility> |
| 8 | #include <QColorDialog> | 8 | #include <QColorDialog> |
| 9 | #include <QGridLayout> | ||
| 9 | #include <QMenu> | 10 | #include <QMenu> |
| 10 | #include <QMessageBox> | 11 | #include <QMessageBox> |
| 11 | #include <QTimer> | 12 | #include <QTimer> |
diff --git a/src/yuzu/configuration/configure_input_simple.cpp b/src/yuzu/configuration/configure_input_simple.cpp new file mode 100644 index 000000000..b4f3724bd --- /dev/null +++ b/src/yuzu/configuration/configure_input_simple.cpp | |||
| @@ -0,0 +1,142 @@ | |||
| 1 | // Copyright 2016 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include <array> | ||
| 6 | #include <cstring> | ||
| 7 | #include <functional> | ||
| 8 | #include <tuple> | ||
| 9 | |||
| 10 | #include <QDialog> | ||
| 11 | |||
| 12 | #include "ui_configure_input_simple.h" | ||
| 13 | #include "yuzu/configuration/configure_input.h" | ||
| 14 | #include "yuzu/configuration/configure_input_player.h" | ||
| 15 | #include "yuzu/configuration/configure_input_simple.h" | ||
| 16 | #include "yuzu/ui_settings.h" | ||
| 17 | |||
| 18 | namespace { | ||
| 19 | |||
| 20 | template <typename Dialog, typename... Args> | ||
| 21 | void CallConfigureDialog(ConfigureInputSimple* caller, Args&&... args) { | ||
| 22 | caller->applyConfiguration(); | ||
| 23 | Dialog dialog(caller, std::forward<Args>(args)...); | ||
| 24 | |||
| 25 | const auto res = dialog.exec(); | ||
| 26 | if (res == QDialog::Accepted) { | ||
| 27 | dialog.applyConfiguration(); | ||
| 28 | } | ||
| 29 | } | ||
| 30 | |||
| 31 | // OnProfileSelect functions should (when applicable): | ||
| 32 | // - Set controller types | ||
| 33 | // - Set controller enabled | ||
| 34 | // - Set docked mode | ||
| 35 | // - Set advanced controller config/enabled (i.e. debug, kbd, mouse, touch) | ||
| 36 | // | ||
| 37 | // OnProfileSelect function should NOT however: | ||
| 38 | // - Reset any button mappings | ||
| 39 | // - Open any dialogs | ||
| 40 | // - Block in any way | ||
| 41 | |||
| 42 | constexpr std::size_t HANDHELD_INDEX = 8; | ||
| 43 | |||
| 44 | void HandheldOnProfileSelect() { | ||
| 45 | Settings::values.players[HANDHELD_INDEX].connected = true; | ||
| 46 | Settings::values.players[HANDHELD_INDEX].type = Settings::ControllerType::DualJoycon; | ||
| 47 | |||
| 48 | for (std::size_t player = 0; player < HANDHELD_INDEX; ++player) { | ||
| 49 | Settings::values.players[player].connected = false; | ||
| 50 | } | ||
| 51 | |||
| 52 | Settings::values.use_docked_mode = false; | ||
| 53 | Settings::values.keyboard_enabled = false; | ||
| 54 | Settings::values.mouse_enabled = false; | ||
| 55 | Settings::values.debug_pad_enabled = false; | ||
| 56 | Settings::values.touchscreen.enabled = true; | ||
| 57 | } | ||
| 58 | |||
| 59 | void DualJoyconsDockedOnProfileSelect() { | ||
| 60 | Settings::values.players[0].connected = true; | ||
| 61 | Settings::values.players[0].type = Settings::ControllerType::DualJoycon; | ||
| 62 | |||
| 63 | for (std::size_t player = 1; player <= HANDHELD_INDEX; ++player) { | ||
| 64 | Settings::values.players[player].connected = false; | ||
| 65 | } | ||
| 66 | |||
| 67 | Settings::values.use_docked_mode = true; | ||
| 68 | Settings::values.keyboard_enabled = false; | ||
| 69 | Settings::values.mouse_enabled = false; | ||
| 70 | Settings::values.debug_pad_enabled = false; | ||
| 71 | Settings::values.touchscreen.enabled = false; | ||
| 72 | } | ||
| 73 | |||
| 74 | // Name, OnProfileSelect (called when selected in drop down), OnConfigure (called when configure | ||
| 75 | // is clicked) | ||
| 76 | using InputProfile = | ||
| 77 | std::tuple<QString, std::function<void()>, std::function<void(ConfigureInputSimple*)>>; | ||
| 78 | |||
| 79 | const std::array<InputProfile, 3> INPUT_PROFILES{{ | ||
| 80 | {ConfigureInputSimple::tr("Single Player - Handheld - Undocked"), HandheldOnProfileSelect, | ||
| 81 | [](ConfigureInputSimple* caller) { | ||
| 82 | CallConfigureDialog<ConfigureInputPlayer>(caller, HANDHELD_INDEX, false); | ||
| 83 | }}, | ||
| 84 | {ConfigureInputSimple::tr("Single Player - Dual Joycons - Docked"), | ||
| 85 | DualJoyconsDockedOnProfileSelect, | ||
| 86 | [](ConfigureInputSimple* caller) { | ||
| 87 | CallConfigureDialog<ConfigureInputPlayer>(caller, 1, false); | ||
| 88 | }}, | ||
| 89 | {ConfigureInputSimple::tr("Custom"), [] {}, CallConfigureDialog<ConfigureInput>}, | ||
| 90 | }}; | ||
| 91 | |||
| 92 | } // namespace | ||
| 93 | |||
| 94 | void ApplyInputProfileConfiguration(int profile_index) { | ||
| 95 | std::get<1>( | ||
| 96 | INPUT_PROFILES.at(std::min(profile_index, static_cast<int>(INPUT_PROFILES.size() - 1))))(); | ||
| 97 | } | ||
| 98 | |||
| 99 | ConfigureInputSimple::ConfigureInputSimple(QWidget* parent) | ||
| 100 | : QWidget(parent), ui(std::make_unique<Ui::ConfigureInputSimple>()) { | ||
| 101 | ui->setupUi(this); | ||
| 102 | |||
| 103 | for (const auto& profile : INPUT_PROFILES) { | ||
| 104 | ui->profile_combobox->addItem(std::get<0>(profile), std::get<0>(profile)); | ||
| 105 | } | ||
| 106 | |||
| 107 | connect(ui->profile_combobox, QOverload<int>::of(&QComboBox::currentIndexChanged), this, | ||
| 108 | &ConfigureInputSimple::OnSelectProfile); | ||
| 109 | connect(ui->profile_configure, &QPushButton::pressed, this, &ConfigureInputSimple::OnConfigure); | ||
| 110 | |||
| 111 | this->loadConfiguration(); | ||
| 112 | } | ||
| 113 | |||
| 114 | ConfigureInputSimple::~ConfigureInputSimple() = default; | ||
| 115 | |||
| 116 | void ConfigureInputSimple::applyConfiguration() { | ||
| 117 | auto index = ui->profile_combobox->currentIndex(); | ||
| 118 | // Make the stored index for "Custom" very large so that if new profiles are added it | ||
| 119 | // doesn't change. | ||
| 120 | if (index >= static_cast<int>(INPUT_PROFILES.size() - 1)) | ||
| 121 | index = std::numeric_limits<int>::max(); | ||
| 122 | |||
| 123 | UISettings::values.profile_index = index; | ||
| 124 | } | ||
| 125 | |||
| 126 | void ConfigureInputSimple::loadConfiguration() { | ||
| 127 | const auto index = UISettings::values.profile_index; | ||
| 128 | if (index >= static_cast<int>(INPUT_PROFILES.size()) || index < 0) | ||
| 129 | ui->profile_combobox->setCurrentIndex(static_cast<int>(INPUT_PROFILES.size() - 1)); | ||
| 130 | else | ||
| 131 | ui->profile_combobox->setCurrentIndex(index); | ||
| 132 | } | ||
| 133 | |||
| 134 | void ConfigureInputSimple::OnSelectProfile(int index) { | ||
| 135 | const auto old_docked = Settings::values.use_docked_mode; | ||
| 136 | ApplyInputProfileConfiguration(index); | ||
| 137 | OnDockedModeChanged(old_docked, Settings::values.use_docked_mode); | ||
| 138 | } | ||
| 139 | |||
| 140 | void ConfigureInputSimple::OnConfigure() { | ||
| 141 | std::get<2>(INPUT_PROFILES.at(ui->profile_combobox->currentIndex()))(this); | ||
| 142 | } | ||
diff --git a/src/yuzu/configuration/configure_input_simple.h b/src/yuzu/configuration/configure_input_simple.h new file mode 100644 index 000000000..5b6b69994 --- /dev/null +++ b/src/yuzu/configuration/configure_input_simple.h | |||
| @@ -0,0 +1,40 @@ | |||
| 1 | // Copyright 2016 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include <memory> | ||
| 8 | |||
| 9 | #include <QWidget> | ||
| 10 | |||
| 11 | class QPushButton; | ||
| 12 | class QString; | ||
| 13 | class QTimer; | ||
| 14 | |||
| 15 | namespace Ui { | ||
| 16 | class ConfigureInputSimple; | ||
| 17 | } | ||
| 18 | |||
| 19 | // Used by configuration loader to apply a profile if the input is invalid. | ||
| 20 | void ApplyInputProfileConfiguration(int profile_index); | ||
| 21 | |||
| 22 | class ConfigureInputSimple : public QWidget { | ||
| 23 | Q_OBJECT | ||
| 24 | |||
| 25 | public: | ||
| 26 | explicit ConfigureInputSimple(QWidget* parent = nullptr); | ||
| 27 | ~ConfigureInputSimple() override; | ||
| 28 | |||
| 29 | /// Save all button configurations to settings file | ||
| 30 | void applyConfiguration(); | ||
| 31 | |||
| 32 | private: | ||
| 33 | /// Load configuration settings. | ||
| 34 | void loadConfiguration(); | ||
| 35 | |||
| 36 | void OnSelectProfile(int index); | ||
| 37 | void OnConfigure(); | ||
| 38 | |||
| 39 | std::unique_ptr<Ui::ConfigureInputSimple> ui; | ||
| 40 | }; | ||
diff --git a/src/yuzu/configuration/configure_input_simple.ui b/src/yuzu/configuration/configure_input_simple.ui new file mode 100644 index 000000000..c4889caa9 --- /dev/null +++ b/src/yuzu/configuration/configure_input_simple.ui | |||
| @@ -0,0 +1,97 @@ | |||
| 1 | <?xml version="1.0" encoding="UTF-8"?> | ||
| 2 | <ui version="4.0"> | ||
| 3 | <class>ConfigureInputSimple</class> | ||
| 4 | <widget class="QWidget" name="ConfigureInputSimple"> | ||
| 5 | <property name="geometry"> | ||
| 6 | <rect> | ||
| 7 | <x>0</x> | ||
| 8 | <y>0</y> | ||
| 9 | <width>473</width> | ||
| 10 | <height>685</height> | ||
| 11 | </rect> | ||
| 12 | </property> | ||
| 13 | <property name="windowTitle"> | ||
| 14 | <string>ConfigureInputSimple</string> | ||
| 15 | </property> | ||
| 16 | <layout class="QVBoxLayout" name="verticalLayout_5"> | ||
| 17 | <item> | ||
| 18 | <layout class="QVBoxLayout" name="verticalLayout"> | ||
| 19 | <item> | ||
| 20 | <widget class="QGroupBox" name="gridGroupBox"> | ||
| 21 | <property name="title"> | ||
| 22 | <string>Profile</string> | ||
| 23 | </property> | ||
| 24 | <layout class="QGridLayout" name="gridLayout"> | ||
| 25 | <item row="1" column="2"> | ||
| 26 | <widget class="QPushButton" name="profile_configure"> | ||
| 27 | <property name="text"> | ||
| 28 | <string>Configure</string> | ||
| 29 | </property> | ||
| 30 | </widget> | ||
| 31 | </item> | ||
| 32 | <item row="1" column="0"> | ||
| 33 | <spacer name="horizontalSpacer"> | ||
| 34 | <property name="orientation"> | ||
| 35 | <enum>Qt::Horizontal</enum> | ||
| 36 | </property> | ||
| 37 | <property name="sizeHint" stdset="0"> | ||
| 38 | <size> | ||
| 39 | <width>40</width> | ||
| 40 | <height>20</height> | ||
| 41 | </size> | ||
| 42 | </property> | ||
| 43 | </spacer> | ||
| 44 | </item> | ||
| 45 | <item row="1" column="3"> | ||
| 46 | <spacer name="horizontalSpacer_2"> | ||
| 47 | <property name="orientation"> | ||
| 48 | <enum>Qt::Horizontal</enum> | ||
| 49 | </property> | ||
| 50 | <property name="sizeHint" stdset="0"> | ||
| 51 | <size> | ||
| 52 | <width>40</width> | ||
| 53 | <height>20</height> | ||
| 54 | </size> | ||
| 55 | </property> | ||
| 56 | </spacer> | ||
| 57 | </item> | ||
| 58 | <item row="1" column="1"> | ||
| 59 | <widget class="QComboBox" name="profile_combobox"> | ||
| 60 | <property name="minimumSize"> | ||
| 61 | <size> | ||
| 62 | <width>250</width> | ||
| 63 | <height>0</height> | ||
| 64 | </size> | ||
| 65 | </property> | ||
| 66 | </widget> | ||
| 67 | </item> | ||
| 68 | <item row="0" column="1" colspan="2"> | ||
| 69 | <widget class="QLabel" name="label"> | ||
| 70 | <property name="text"> | ||
| 71 | <string>Choose a controller configuration:</string> | ||
| 72 | </property> | ||
| 73 | </widget> | ||
| 74 | </item> | ||
| 75 | </layout> | ||
| 76 | </widget> | ||
| 77 | </item> | ||
| 78 | </layout> | ||
| 79 | </item> | ||
| 80 | <item> | ||
| 81 | <spacer name="verticalSpacer"> | ||
| 82 | <property name="orientation"> | ||
| 83 | <enum>Qt::Vertical</enum> | ||
| 84 | </property> | ||
| 85 | <property name="sizeHint" stdset="0"> | ||
| 86 | <size> | ||
| 87 | <width>20</width> | ||
| 88 | <height>40</height> | ||
| 89 | </size> | ||
| 90 | </property> | ||
| 91 | </spacer> | ||
| 92 | </item> | ||
| 93 | </layout> | ||
| 94 | </widget> | ||
| 95 | <resources/> | ||
| 96 | <connections/> | ||
| 97 | </ui> | ||
diff --git a/src/yuzu/ui_settings.h b/src/yuzu/ui_settings.h index e80aebc0a..2f434eab0 100644 --- a/src/yuzu/ui_settings.h +++ b/src/yuzu/ui_settings.h | |||
| @@ -58,6 +58,9 @@ struct Values { | |||
| 58 | // logging | 58 | // logging |
| 59 | bool show_console; | 59 | bool show_console; |
| 60 | 60 | ||
| 61 | // Controllers | ||
| 62 | int profile_index; | ||
| 63 | |||
| 61 | // Game List | 64 | // Game List |
| 62 | bool show_unknown; | 65 | bool show_unknown; |
| 63 | bool show_add_ons; | 66 | bool show_add_ons; |