| 
									
										
										
										
											2018-11-01 22:11:44 -04:00
										 |  |  | // Copyright 2016 Citra Emulator Project
 | 
					
						
							|  |  |  | // Licensed under GPLv2 or any later version
 | 
					
						
							|  |  |  | // Refer to the license.txt file included.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <algorithm>
 | 
					
						
							|  |  |  | #include <memory>
 | 
					
						
							|  |  |  | #include <utility>
 | 
					
						
							| 
									
										
										
										
											2018-12-01 11:11:11 -05:00
										 |  |  | #include <QGridLayout>
 | 
					
						
							| 
									
										
										
										
											2020-07-22 10:39:53 -04:00
										 |  |  | #include <QInputDialog>
 | 
					
						
							| 
									
										
										
										
											2019-01-17 12:06:38 -05:00
										 |  |  | #include <QKeyEvent>
 | 
					
						
							| 
									
										
										
										
											2018-11-01 22:11:44 -04:00
										 |  |  | #include <QMenu>
 | 
					
						
							|  |  |  | #include <QMessageBox>
 | 
					
						
							|  |  |  | #include <QTimer>
 | 
					
						
							|  |  |  | #include "common/param_package.h"
 | 
					
						
							| 
									
										
										
										
											2021-09-20 19:47:45 -05:00
										 |  |  | #include "core/hid/emulated_controller.h"
 | 
					
						
							|  |  |  | #include "core/hid/hid_core.h"
 | 
					
						
							|  |  |  | #include "core/hid/hid_types.h"
 | 
					
						
							|  |  |  | #include "input_common/drivers/keyboard.h"
 | 
					
						
							|  |  |  | #include "input_common/drivers/mouse.h"
 | 
					
						
							| 
									
										
										
										
											2018-11-01 22:11:44 -04:00
										 |  |  | #include "input_common/main.h"
 | 
					
						
							|  |  |  | #include "ui_configure_input_player.h"
 | 
					
						
							| 
									
										
										
										
											2021-02-23 20:39:02 -06:00
										 |  |  | #include "yuzu/bootmanager.h"
 | 
					
						
							| 
									
										
										
										
											2018-11-01 22:11:44 -04:00
										 |  |  | #include "yuzu/configuration/config.h"
 | 
					
						
							|  |  |  | #include "yuzu/configuration/configure_input_player.h"
 | 
					
						
							| 
									
										
										
										
											2021-01-12 21:09:59 -06:00
										 |  |  | #include "yuzu/configuration/configure_input_player_widget.h"
 | 
					
						
							| 
									
										
										
										
											2020-10-20 13:55:25 -04:00
										 |  |  | #include "yuzu/configuration/configure_vibration.h"
 | 
					
						
							| 
									
										
										
										
											2020-09-23 09:52:25 -04:00
										 |  |  | #include "yuzu/configuration/input_profiles.h"
 | 
					
						
							|  |  |  | #include "yuzu/util/limitable_input_dialog.h"
 | 
					
						
							| 
									
										
										
										
											2018-11-01 22:11:44 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | const std::array<std::string, ConfigureInputPlayer::ANALOG_SUB_BUTTONS_NUM> | 
					
						
							| 
									
										
										
										
											2020-06-21 15:31:57 -04:00
										 |  |  |     ConfigureInputPlayer::analog_sub_buttons{{ | 
					
						
							|  |  |  |         "up", | 
					
						
							|  |  |  |         "down", | 
					
						
							|  |  |  |         "left", | 
					
						
							|  |  |  |         "right", | 
					
						
							|  |  |  |     }}; | 
					
						
							| 
									
										
										
										
											2018-11-01 22:11:44 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-22 10:39:53 -04:00
										 |  |  | namespace { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | QString GetKeyName(int key_code) { | 
					
						
							| 
									
										
										
										
											2018-11-01 22:11:44 -04:00
										 |  |  |     switch (key_code) { | 
					
						
							|  |  |  |     case Qt::Key_Shift: | 
					
						
							|  |  |  |         return QObject::tr("Shift"); | 
					
						
							|  |  |  |     case Qt::Key_Control: | 
					
						
							|  |  |  |         return QObject::tr("Ctrl"); | 
					
						
							|  |  |  |     case Qt::Key_Alt: | 
					
						
							|  |  |  |         return QObject::tr("Alt"); | 
					
						
							|  |  |  |     case Qt::Key_Meta: | 
					
						
							| 
									
										
										
										
											2019-05-19 11:38:28 -04:00
										 |  |  |         return {}; | 
					
						
							| 
									
										
										
										
											2018-11-01 22:11:44 -04:00
										 |  |  |     default: | 
					
						
							|  |  |  |         return QKeySequence(key_code).toString(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-21 14:12:01 -06:00
										 |  |  | QString GetButtonName(Common::Input::ButtonNames button_name) { | 
					
						
							|  |  |  |     switch (button_name) { | 
					
						
							|  |  |  |     case Common::Input::ButtonNames::ButtonLeft: | 
					
						
							|  |  |  |         return QObject::tr("Left"); | 
					
						
							|  |  |  |     case Common::Input::ButtonNames::ButtonRight: | 
					
						
							|  |  |  |         return QObject::tr("Right"); | 
					
						
							|  |  |  |     case Common::Input::ButtonNames::ButtonDown: | 
					
						
							|  |  |  |         return QObject::tr("Down"); | 
					
						
							|  |  |  |     case Common::Input::ButtonNames::ButtonUp: | 
					
						
							|  |  |  |         return QObject::tr("Up"); | 
					
						
							|  |  |  |     case Common::Input::ButtonNames::TriggerZ: | 
					
						
							|  |  |  |         return QObject::tr("Z"); | 
					
						
							|  |  |  |     case Common::Input::ButtonNames::TriggerR: | 
					
						
							|  |  |  |         return QObject::tr("R"); | 
					
						
							|  |  |  |     case Common::Input::ButtonNames::TriggerL: | 
					
						
							|  |  |  |         return QObject::tr("L"); | 
					
						
							|  |  |  |     case Common::Input::ButtonNames::ButtonA: | 
					
						
							|  |  |  |         return QObject::tr("A"); | 
					
						
							|  |  |  |     case Common::Input::ButtonNames::ButtonB: | 
					
						
							|  |  |  |         return QObject::tr("B"); | 
					
						
							|  |  |  |     case Common::Input::ButtonNames::ButtonX: | 
					
						
							|  |  |  |         return QObject::tr("X"); | 
					
						
							|  |  |  |     case Common::Input::ButtonNames::ButtonY: | 
					
						
							|  |  |  |         return QObject::tr("Y"); | 
					
						
							|  |  |  |     case Common::Input::ButtonNames::ButtonStart: | 
					
						
							|  |  |  |         return QObject::tr("Start"); | 
					
						
							| 
									
										
										
										
											2021-11-26 15:45:37 -06:00
										 |  |  |     case Common::Input::ButtonNames::L1: | 
					
						
							|  |  |  |         return QObject::tr("L1"); | 
					
						
							|  |  |  |     case Common::Input::ButtonNames::L2: | 
					
						
							|  |  |  |         return QObject::tr("L2"); | 
					
						
							|  |  |  |     case Common::Input::ButtonNames::L3: | 
					
						
							|  |  |  |         return QObject::tr("L3"); | 
					
						
							|  |  |  |     case Common::Input::ButtonNames::R1: | 
					
						
							|  |  |  |         return QObject::tr("R1"); | 
					
						
							|  |  |  |     case Common::Input::ButtonNames::R2: | 
					
						
							|  |  |  |         return QObject::tr("R2"); | 
					
						
							|  |  |  |     case Common::Input::ButtonNames::R3: | 
					
						
							|  |  |  |         return QObject::tr("R3"); | 
					
						
							|  |  |  |     case Common::Input::ButtonNames::Circle: | 
					
						
							|  |  |  |         return QObject::tr("Circle"); | 
					
						
							|  |  |  |     case Common::Input::ButtonNames::Cross: | 
					
						
							|  |  |  |         return QObject::tr("Cross"); | 
					
						
							|  |  |  |     case Common::Input::ButtonNames::Square: | 
					
						
							|  |  |  |         return QObject::tr("Square"); | 
					
						
							|  |  |  |     case Common::Input::ButtonNames::Triangle: | 
					
						
							|  |  |  |         return QObject::tr("Triangle"); | 
					
						
							|  |  |  |     case Common::Input::ButtonNames::Share: | 
					
						
							|  |  |  |         return QObject::tr("Share"); | 
					
						
							|  |  |  |     case Common::Input::ButtonNames::Options: | 
					
						
							|  |  |  |         return QObject::tr("Options"); | 
					
						
							| 
									
										
										
										
											2022-01-16 18:03:11 -06:00
										 |  |  |     case Common::Input::ButtonNames::ButtonMouseWheel: | 
					
						
							|  |  |  |         return QObject::tr("Wheel", "Indicates the mouse wheel"); | 
					
						
							|  |  |  |     case Common::Input::ButtonNames::ButtonBackward: | 
					
						
							|  |  |  |         return QObject::tr("Backward"); | 
					
						
							|  |  |  |     case Common::Input::ButtonNames::ButtonForward: | 
					
						
							|  |  |  |         return QObject::tr("Forward"); | 
					
						
							|  |  |  |     case Common::Input::ButtonNames::ButtonTask: | 
					
						
							|  |  |  |         return QObject::tr("Task"); | 
					
						
							|  |  |  |     case Common::Input::ButtonNames::ButtonExtra: | 
					
						
							|  |  |  |         return QObject::tr("Extra"); | 
					
						
							| 
									
										
										
										
											2021-11-21 14:12:01 -06:00
										 |  |  |     default: | 
					
						
							|  |  |  |         return QObject::tr("[undefined]"); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-22 10:39:53 -04:00
										 |  |  | void SetAnalogParam(const Common::ParamPackage& input_param, Common::ParamPackage& analog_param, | 
					
						
							|  |  |  |                     const std::string& button_name) { | 
					
						
							|  |  |  |     // The poller returned a complete axis, so set all the buttons
 | 
					
						
							|  |  |  |     if (input_param.Has("axis_x") && input_param.Has("axis_y")) { | 
					
						
							|  |  |  |         analog_param = input_param; | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     // Check if the current configuration has either no engine or an axis binding.
 | 
					
						
							|  |  |  |     // Clears out the old binding and adds one with analog_from_button.
 | 
					
						
							|  |  |  |     if (!analog_param.Has("engine") || analog_param.Has("axis_x") || analog_param.Has("axis_y")) { | 
					
						
							| 
									
										
										
										
											2018-11-01 22:11:44 -04:00
										 |  |  |         analog_param = { | 
					
						
							|  |  |  |             {"engine", "analog_from_button"}, | 
					
						
							|  |  |  |         }; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     analog_param.Set(button_name, input_param.Serialize()); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2021-09-20 19:47:45 -05:00
										 |  |  | } // namespace
 | 
					
						
							| 
									
										
										
										
											2018-11-01 22:11:44 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-20 19:47:45 -05:00
										 |  |  | QString ConfigureInputPlayer::ButtonToText(const Common::ParamPackage& param) { | 
					
						
							| 
									
										
										
										
											2018-11-01 22:11:44 -04:00
										 |  |  |     if (!param.Has("engine")) { | 
					
						
							|  |  |  |         return QObject::tr("[not set]"); | 
					
						
							| 
									
										
										
										
											2019-05-19 11:38:28 -04:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-21 14:12:01 -06:00
										 |  |  |     const QString toggle = QString::fromStdString(param.Get("toggle", false) ? "~" : ""); | 
					
						
							|  |  |  |     const QString inverted = QString::fromStdString(param.Get("inverted", false) ? "!" : ""); | 
					
						
							|  |  |  |     const auto common_button_name = input_subsystem->GetButtonName(param); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-20 19:47:45 -05:00
										 |  |  |     // Retrieve the names from Qt
 | 
					
						
							| 
									
										
										
										
											2019-05-19 11:38:28 -04:00
										 |  |  |     if (param.Get("engine", "") == "keyboard") { | 
					
						
							| 
									
										
										
										
											2021-03-05 19:21:04 -06:00
										 |  |  |         const QString button_str = GetKeyName(param.Get("code", 0)); | 
					
						
							| 
									
										
										
										
											2022-01-21 20:41:16 -06:00
										 |  |  |         return QObject::tr("%1%2%3").arg(toggle, inverted, button_str); | 
					
						
							| 
									
										
										
										
											2019-05-19 11:38:28 -04:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-21 14:12:01 -06:00
										 |  |  |     if (common_button_name == Common::Input::ButtonNames::Invalid) { | 
					
						
							|  |  |  |         return QObject::tr("[invalid]"); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (common_button_name == Common::Input::ButtonNames::Engine) { | 
					
						
							|  |  |  |         return QString::fromStdString(param.Get("engine", "")); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (common_button_name == Common::Input::ButtonNames::Value) { | 
					
						
							|  |  |  |         if (param.Has("hat")) { | 
					
						
							|  |  |  |             const QString hat = QString::fromStdString(param.Get("direction", "")); | 
					
						
							|  |  |  |             return QObject::tr("%1%2Hat %3").arg(toggle, inverted, hat); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         if (param.Has("axis")) { | 
					
						
							|  |  |  |             const QString axis = QString::fromStdString(param.Get("axis", "")); | 
					
						
							|  |  |  |             return QObject::tr("%1%2Axis %3").arg(toggle, inverted, axis); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         if (param.Has("axis_x") && param.Has("axis_y") && param.Has("axis_z")) { | 
					
						
							|  |  |  |             const QString axis_x = QString::fromStdString(param.Get("axis_x", "")); | 
					
						
							|  |  |  |             const QString axis_y = QString::fromStdString(param.Get("axis_y", "")); | 
					
						
							|  |  |  |             const QString axis_z = QString::fromStdString(param.Get("axis_z", "")); | 
					
						
							|  |  |  |             return QObject::tr("%1%2Axis %3,%4,%5").arg(toggle, inverted, axis_x, axis_y, axis_z); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         if (param.Has("motion")) { | 
					
						
							|  |  |  |             const QString motion = QString::fromStdString(param.Get("motion", "")); | 
					
						
							|  |  |  |             return QObject::tr("%1%2Motion %3").arg(toggle, inverted, motion); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         if (param.Has("button")) { | 
					
						
							|  |  |  |             const QString button = QString::fromStdString(param.Get("button", "")); | 
					
						
							|  |  |  |             return QObject::tr("%1%2Button %3").arg(toggle, inverted, button); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QString button_name = GetButtonName(common_button_name); | 
					
						
							|  |  |  |     if (param.Has("hat")) { | 
					
						
							|  |  |  |         return QObject::tr("%1%2Hat %3").arg(toggle, inverted, button_name); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (param.Has("axis")) { | 
					
						
							|  |  |  |         return QObject::tr("%1%2Axis %3").arg(toggle, inverted, button_name); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (param.Has("motion")) { | 
					
						
							|  |  |  |         return QObject::tr("%1%2Axis %3").arg(toggle, inverted, button_name); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (param.Has("button")) { | 
					
						
							|  |  |  |         return QObject::tr("%1%2Button %3").arg(toggle, inverted, button_name); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return QObject::tr("[unknown]"); | 
					
						
							| 
									
										
										
										
											2019-05-19 11:38:28 -04:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2018-11-01 22:11:44 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-20 19:47:45 -05:00
										 |  |  | QString ConfigureInputPlayer::AnalogToText(const Common::ParamPackage& param, | 
					
						
							|  |  |  |                                            const std::string& dir) { | 
					
						
							| 
									
										
										
										
											2018-11-01 22:11:44 -04:00
										 |  |  |     if (!param.Has("engine")) { | 
					
						
							|  |  |  |         return QObject::tr("[not set]"); | 
					
						
							| 
									
										
										
										
											2019-05-19 11:38:28 -04:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (param.Get("engine", "") == "analog_from_button") { | 
					
						
							| 
									
										
										
										
											2018-11-01 22:11:44 -04:00
										 |  |  |         return ButtonToText(Common::ParamPackage{param.Get(dir, "")}); | 
					
						
							| 
									
										
										
										
											2019-05-19 11:38:28 -04:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-20 19:47:45 -05:00
										 |  |  |     if (!param.Has("axis_x") || !param.Has("axis_y")) { | 
					
						
							|  |  |  |         return QObject::tr("[unknown]"); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-26 12:17:22 -06:00
										 |  |  |     const auto engine_str = param.Get("engine", ""); | 
					
						
							|  |  |  |     const QString axis_x_str = QString::fromStdString(param.Get("axis_x", "")); | 
					
						
							|  |  |  |     const QString axis_y_str = QString::fromStdString(param.Get("axis_y", "")); | 
					
						
							|  |  |  |     const bool invert_x = param.Get("invert_x", "+") == "-"; | 
					
						
							|  |  |  |     const bool invert_y = param.Get("invert_y", "+") == "-"; | 
					
						
							| 
									
										
										
										
											2018-11-01 22:11:44 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-20 19:47:45 -05:00
										 |  |  |     if (dir == "modifier") { | 
					
						
							|  |  |  |         return QObject::tr("[unused]"); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-11-17 22:55:09 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-20 19:47:45 -05:00
										 |  |  |     if (dir == "left") { | 
					
						
							|  |  |  |         const QString invert_x_str = QString::fromStdString(invert_x ? "+" : "-"); | 
					
						
							|  |  |  |         return QObject::tr("Axis %1%2").arg(axis_x_str, invert_x_str); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (dir == "right") { | 
					
						
							|  |  |  |         const QString invert_x_str = QString::fromStdString(invert_x ? "-" : "+"); | 
					
						
							|  |  |  |         return QObject::tr("Axis %1%2").arg(axis_x_str, invert_x_str); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (dir == "up") { | 
					
						
							|  |  |  |         const QString invert_y_str = QString::fromStdString(invert_y ? "-" : "+"); | 
					
						
							|  |  |  |         return QObject::tr("Axis %1%2").arg(axis_y_str, invert_y_str); | 
					
						
							| 
									
										
										
										
											2020-11-17 22:55:09 -06:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-09-20 19:47:45 -05:00
										 |  |  |     if (dir == "down") { | 
					
						
							|  |  |  |         const QString invert_y_str = QString::fromStdString(invert_y ? "+" : "-"); | 
					
						
							|  |  |  |         return QObject::tr("Axis %1%2").arg(axis_y_str, invert_y_str); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-19 11:38:28 -04:00
										 |  |  |     return QObject::tr("[unknown]"); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2018-11-01 22:11:44 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-22 10:39:53 -04:00
										 |  |  | ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_index, | 
					
						
							| 
									
										
										
										
											2020-08-27 15:16:47 -04:00
										 |  |  |                                            QWidget* bottom_row, | 
					
						
							|  |  |  |                                            InputCommon::InputSubsystem* input_subsystem_, | 
					
						
							| 
									
										
										
										
											2021-11-04 21:54:22 -06:00
										 |  |  |                                            InputProfiles* profiles_, Core::HID::HIDCore& hid_core_, | 
					
						
							|  |  |  |                                            bool is_powered_on_, bool debug) | 
					
						
							| 
									
										
										
										
											2020-07-22 10:39:53 -04:00
										 |  |  |     : QWidget(parent), ui(std::make_unique<Ui::ConfigureInputPlayer>()), player_index(player_index), | 
					
						
							| 
									
										
										
										
											2021-11-04 21:54:22 -06:00
										 |  |  |       debug(debug), is_powered_on{is_powered_on_}, input_subsystem{input_subsystem_}, | 
					
						
							|  |  |  |       profiles(profiles_), timeout_timer(std::make_unique<QTimer>()), | 
					
						
							|  |  |  |       poll_timer(std::make_unique<QTimer>()), bottom_row(bottom_row), hid_core{hid_core_} { | 
					
						
							| 
									
										
										
										
											2021-10-18 23:15:46 -05:00
										 |  |  |     if (player_index == 0) { | 
					
						
							|  |  |  |         auto* emulated_controller_p1 = | 
					
						
							| 
									
										
										
										
											2021-11-04 21:54:22 -06:00
										 |  |  |             hid_core.GetEmulatedController(Core::HID::NpadIdType::Player1); | 
					
						
							| 
									
										
										
										
											2021-11-29 17:22:59 -05:00
										 |  |  |         auto* emulated_controller_handheld = | 
					
						
							| 
									
										
										
										
											2021-11-04 21:54:22 -06:00
										 |  |  |             hid_core.GetEmulatedController(Core::HID::NpadIdType::Handheld); | 
					
						
							| 
									
										
										
										
											2021-10-18 23:15:46 -05:00
										 |  |  |         emulated_controller_p1->SaveCurrentConfig(); | 
					
						
							|  |  |  |         emulated_controller_p1->EnableConfiguration(); | 
					
						
							| 
									
										
										
										
											2021-11-29 17:22:59 -05:00
										 |  |  |         emulated_controller_handheld->SaveCurrentConfig(); | 
					
						
							|  |  |  |         emulated_controller_handheld->EnableConfiguration(); | 
					
						
							|  |  |  |         if (emulated_controller_handheld->IsConnected(true)) { | 
					
						
							| 
									
										
										
										
											2021-10-18 23:15:46 -05:00
										 |  |  |             emulated_controller_p1->Disconnect(); | 
					
						
							| 
									
										
										
										
											2021-11-29 17:22:59 -05:00
										 |  |  |             emulated_controller = emulated_controller_handheld; | 
					
						
							| 
									
										
										
										
											2021-10-18 23:15:46 -05:00
										 |  |  |         } else { | 
					
						
							|  |  |  |             emulated_controller = emulated_controller_p1; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } else { | 
					
						
							| 
									
										
										
										
											2021-11-04 21:54:22 -06:00
										 |  |  |         emulated_controller = hid_core.GetEmulatedControllerByIndex(player_index); | 
					
						
							| 
									
										
										
										
											2021-10-18 23:15:46 -05:00
										 |  |  |         emulated_controller->SaveCurrentConfig(); | 
					
						
							|  |  |  |         emulated_controller->EnableConfiguration(); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2018-11-01 22:11:44 -04:00
										 |  |  |     ui->setupUi(this); | 
					
						
							| 
									
										
										
										
											2020-07-22 10:39:53 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-01 22:11:44 -04:00
										 |  |  |     setFocusPolicy(Qt::ClickFocus); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     button_map = { | 
					
						
							| 
									
										
										
										
											2020-08-23 10:56:19 -04:00
										 |  |  |         ui->buttonA,        ui->buttonB,      ui->buttonX,         ui->buttonY, | 
					
						
							|  |  |  |         ui->buttonLStick,   ui->buttonRStick, ui->buttonL,         ui->buttonR, | 
					
						
							|  |  |  |         ui->buttonZL,       ui->buttonZR,     ui->buttonPlus,      ui->buttonMinus, | 
					
						
							|  |  |  |         ui->buttonDpadLeft, ui->buttonDpadUp, ui->buttonDpadRight, ui->buttonDpadDown, | 
					
						
							|  |  |  |         ui->buttonSL,       ui->buttonSR,     ui->buttonHome,      ui->buttonScreenshot, | 
					
						
							| 
									
										
										
										
											2018-11-01 22:11:44 -04:00
										 |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     analog_map_buttons = {{ | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             ui->buttonLStickUp, | 
					
						
							|  |  |  |             ui->buttonLStickDown, | 
					
						
							|  |  |  |             ui->buttonLStickLeft, | 
					
						
							|  |  |  |             ui->buttonLStickRight, | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             ui->buttonRStickUp, | 
					
						
							|  |  |  |             ui->buttonRStickDown, | 
					
						
							|  |  |  |             ui->buttonRStickLeft, | 
					
						
							|  |  |  |             ui->buttonRStickRight, | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |     }}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-04 21:48:03 -05:00
										 |  |  |     motion_map = { | 
					
						
							|  |  |  |         ui->buttonMotionLeft, | 
					
						
							|  |  |  |         ui->buttonMotionRight, | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-22 10:39:53 -04:00
										 |  |  |     analog_map_deadzone_label = {ui->labelLStickDeadzone, ui->labelRStickDeadzone}; | 
					
						
							|  |  |  |     analog_map_deadzone_slider = {ui->sliderLStickDeadzone, ui->sliderRStickDeadzone}; | 
					
						
							|  |  |  |     analog_map_modifier_groupbox = {ui->buttonLStickModGroup, ui->buttonRStickModGroup}; | 
					
						
							| 
									
										
										
										
											2020-10-20 14:23:25 -04:00
										 |  |  |     analog_map_modifier_button = {ui->buttonLStickMod, ui->buttonRStickMod}; | 
					
						
							| 
									
										
										
										
											2020-07-22 10:39:53 -04:00
										 |  |  |     analog_map_modifier_label = {ui->labelLStickModifierRange, ui->labelRStickModifierRange}; | 
					
						
							|  |  |  |     analog_map_modifier_slider = {ui->sliderLStickModifierRange, ui->sliderRStickModifierRange}; | 
					
						
							|  |  |  |     analog_map_range_groupbox = {ui->buttonLStickRangeGroup, ui->buttonRStickRangeGroup}; | 
					
						
							|  |  |  |     analog_map_range_spinbox = {ui->spinboxLStickRange, ui->spinboxRStickRange}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-20 19:47:45 -05:00
										 |  |  |     ui->controllerFrame->SetController(emulated_controller); | 
					
						
							| 
									
										
										
										
											2020-07-22 10:39:53 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |     for (int button_id = 0; button_id < Settings::NativeButton::NumButtons; ++button_id) { | 
					
						
							|  |  |  |         auto* const button = button_map[button_id]; | 
					
						
							| 
									
										
										
										
											2020-09-01 10:02:18 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-22 10:39:53 -04:00
										 |  |  |         if (button == nullptr) { | 
					
						
							|  |  |  |             continue; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-09-01 10:02:18 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-20 19:47:45 -05:00
										 |  |  |         connect(button, &QPushButton::clicked, [=, this] { | 
					
						
							|  |  |  |             HandleClick( | 
					
						
							|  |  |  |                 button, button_id, | 
					
						
							| 
									
										
										
										
											2022-02-01 12:20:01 -05:00
										 |  |  |                 [=, this](const Common::ParamPackage& params) { | 
					
						
							| 
									
										
										
										
											2021-09-20 19:47:45 -05:00
										 |  |  |                     emulated_controller->SetButtonParam(button_id, params); | 
					
						
							|  |  |  |                 }, | 
					
						
							|  |  |  |                 InputCommon::Polling::InputType::Button); | 
					
						
							|  |  |  |         }); | 
					
						
							| 
									
										
										
										
											2020-09-01 10:02:18 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |         button->setContextMenuPolicy(Qt::CustomContextMenu); | 
					
						
							|  |  |  |         connect(button, &QPushButton::customContextMenuRequested, | 
					
						
							|  |  |  |                 [=, this](const QPoint& menu_location) { | 
					
						
							|  |  |  |                     QMenu context_menu; | 
					
						
							| 
									
										
										
										
											2021-09-20 19:47:45 -05:00
										 |  |  |                     Common::ParamPackage param = emulated_controller->GetButtonParam(button_id); | 
					
						
							| 
									
										
										
										
											2020-09-01 10:02:18 -04:00
										 |  |  |                     context_menu.addAction(tr("Clear"), [&] { | 
					
						
							| 
									
										
										
										
											2021-09-20 19:47:45 -05:00
										 |  |  |                         emulated_controller->SetButtonParam(button_id, {}); | 
					
						
							| 
									
										
										
										
											2020-09-01 10:02:18 -04:00
										 |  |  |                         button_map[button_id]->setText(tr("[not set]")); | 
					
						
							|  |  |  |                     }); | 
					
						
							| 
									
										
										
										
											2022-01-21 20:41:16 -06:00
										 |  |  |                     if (param.Has("code") || param.Has("button") || param.Has("hat")) { | 
					
						
							| 
									
										
										
										
											2021-07-22 19:59:26 -05:00
										 |  |  |                         context_menu.addAction(tr("Toggle button"), [&] { | 
					
						
							| 
									
										
										
										
											2021-09-20 19:47:45 -05:00
										 |  |  |                             const bool toggle_value = !param.Get("toggle", false); | 
					
						
							|  |  |  |                             param.Set("toggle", toggle_value); | 
					
						
							|  |  |  |                             button_map[button_id]->setText(ButtonToText(param)); | 
					
						
							|  |  |  |                             emulated_controller->SetButtonParam(button_id, param); | 
					
						
							|  |  |  |                         }); | 
					
						
							|  |  |  |                         context_menu.addAction(tr("Invert button"), [&] { | 
					
						
							| 
									
										
										
										
											2022-01-21 20:41:16 -06:00
										 |  |  |                             const bool invert_value = !param.Get("inverted", false); | 
					
						
							|  |  |  |                             param.Set("inverted", invert_value); | 
					
						
							| 
									
										
										
										
											2021-09-20 19:47:45 -05:00
										 |  |  |                             button_map[button_id]->setText(ButtonToText(param)); | 
					
						
							|  |  |  |                             emulated_controller->SetButtonParam(button_id, param); | 
					
						
							| 
									
										
										
										
											2021-07-22 19:59:26 -05:00
										 |  |  |                         }); | 
					
						
							|  |  |  |                     } | 
					
						
							| 
									
										
										
										
											2021-09-20 19:47:45 -05:00
										 |  |  |                     if (param.Has("axis")) { | 
					
						
							|  |  |  |                         context_menu.addAction(tr("Invert axis"), [&] { | 
					
						
							|  |  |  |                             const bool toggle_value = !(param.Get("invert", "+") == "-"); | 
					
						
							|  |  |  |                             param.Set("invert", toggle_value ? "-" : "+"); | 
					
						
							|  |  |  |                             button_map[button_id]->setText(ButtonToText(param)); | 
					
						
							|  |  |  |                             emulated_controller->SetButtonParam(button_id, param); | 
					
						
							|  |  |  |                         }); | 
					
						
							| 
									
										
										
										
											2021-07-15 23:43:51 -05:00
										 |  |  |                         context_menu.addAction(tr("Set threshold"), [&] { | 
					
						
							| 
									
										
										
										
											2021-09-20 19:47:45 -05:00
										 |  |  |                             const int button_threshold = | 
					
						
							|  |  |  |                                 static_cast<int>(param.Get("threshold", 0.5f) * 100.0f); | 
					
						
							| 
									
										
										
										
											2021-07-15 23:43:51 -05:00
										 |  |  |                             const int new_threshold = QInputDialog::getInt( | 
					
						
							|  |  |  |                                 this, tr("Set threshold"), tr("Choose a value between 0% and 100%"), | 
					
						
							|  |  |  |                                 button_threshold, 0, 100); | 
					
						
							| 
									
										
										
										
											2021-09-20 19:47:45 -05:00
										 |  |  |                             param.Set("threshold", new_threshold / 100.0f); | 
					
						
							| 
									
										
										
										
											2021-07-17 13:30:43 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |                             if (button_id == Settings::NativeButton::ZL) { | 
					
						
							|  |  |  |                                 ui->sliderZLThreshold->setValue(new_threshold); | 
					
						
							|  |  |  |                             } | 
					
						
							|  |  |  |                             if (button_id == Settings::NativeButton::ZR) { | 
					
						
							|  |  |  |                                 ui->sliderZRThreshold->setValue(new_threshold); | 
					
						
							|  |  |  |                             } | 
					
						
							| 
									
										
										
										
											2021-09-20 19:47:45 -05:00
										 |  |  |                             emulated_controller->SetButtonParam(button_id, param); | 
					
						
							| 
									
										
										
										
											2021-07-15 23:43:51 -05:00
										 |  |  |                         }); | 
					
						
							|  |  |  |                     } | 
					
						
							| 
									
										
										
										
											2020-09-01 10:02:18 -04:00
										 |  |  |                     context_menu.exec(button_map[button_id]->mapToGlobal(menu_location)); | 
					
						
							|  |  |  |                 }); | 
					
						
							| 
									
										
										
										
											2018-11-01 22:11:44 -04:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-04 21:48:03 -05:00
										 |  |  |     for (int motion_id = 0; motion_id < Settings::NativeMotion::NumMotions; ++motion_id) { | 
					
						
							|  |  |  |         auto* const button = motion_map[motion_id]; | 
					
						
							|  |  |  |         if (button == nullptr) { | 
					
						
							|  |  |  |             continue; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-20 19:47:45 -05:00
										 |  |  |         connect(button, &QPushButton::clicked, [=, this] { | 
					
						
							|  |  |  |             HandleClick( | 
					
						
							|  |  |  |                 button, motion_id, | 
					
						
							| 
									
										
										
										
											2022-02-01 12:20:01 -05:00
										 |  |  |                 [=, this](const Common::ParamPackage& params) { | 
					
						
							| 
									
										
										
										
											2021-09-20 19:47:45 -05:00
										 |  |  |                     emulated_controller->SetMotionParam(motion_id, params); | 
					
						
							|  |  |  |                 }, | 
					
						
							|  |  |  |                 InputCommon::Polling::InputType::Motion); | 
					
						
							|  |  |  |         }); | 
					
						
							| 
									
										
										
										
											2020-09-01 10:02:18 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-04 21:48:03 -05:00
										 |  |  |         button->setContextMenuPolicy(Qt::CustomContextMenu); | 
					
						
							| 
									
										
										
										
											2020-09-01 10:02:18 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-04 21:48:03 -05:00
										 |  |  |         connect(button, &QPushButton::customContextMenuRequested, | 
					
						
							|  |  |  |                 [=, this](const QPoint& menu_location) { | 
					
						
							|  |  |  |                     QMenu context_menu; | 
					
						
							| 
									
										
										
										
											2022-01-23 21:54:33 -06:00
										 |  |  |                     Common::ParamPackage param = emulated_controller->GetMotionParam(motion_id); | 
					
						
							| 
									
										
										
										
											2020-09-04 21:48:03 -05:00
										 |  |  |                     context_menu.addAction(tr("Clear"), [&] { | 
					
						
							| 
									
										
										
										
											2021-09-20 19:47:45 -05:00
										 |  |  |                         emulated_controller->SetMotionParam(motion_id, {}); | 
					
						
							| 
									
										
										
										
											2020-09-04 21:48:03 -05:00
										 |  |  |                         motion_map[motion_id]->setText(tr("[not set]")); | 
					
						
							|  |  |  |                     }); | 
					
						
							| 
									
										
										
										
											2022-01-23 21:54:33 -06:00
										 |  |  |                     if (param.Has("motion")) { | 
					
						
							|  |  |  |                         context_menu.addAction(tr("Set gyro threshold"), [&] { | 
					
						
							|  |  |  |                             const int gyro_threshold = | 
					
						
							|  |  |  |                                 static_cast<int>(param.Get("threshold", 0.007f) * 1000.0f); | 
					
						
							|  |  |  |                             const int new_threshold = QInputDialog::getInt( | 
					
						
							|  |  |  |                                 this, tr("Set threshold"), tr("Choose a value between 0% and 100%"), | 
					
						
							|  |  |  |                                 gyro_threshold, 0, 100); | 
					
						
							|  |  |  |                             param.Set("threshold", new_threshold / 1000.0f); | 
					
						
							|  |  |  |                             emulated_controller->SetMotionParam(motion_id, param); | 
					
						
							|  |  |  |                         }); | 
					
						
							|  |  |  |                     } | 
					
						
							| 
									
										
										
										
											2020-09-04 21:48:03 -05:00
										 |  |  |                     context_menu.exec(motion_map[motion_id]->mapToGlobal(menu_location)); | 
					
						
							|  |  |  |                 }); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-17 13:30:43 -05:00
										 |  |  |     connect(ui->sliderZLThreshold, &QSlider::valueChanged, [=, this] { | 
					
						
							| 
									
										
										
										
											2021-09-20 19:47:45 -05:00
										 |  |  |         Common::ParamPackage param = | 
					
						
							|  |  |  |             emulated_controller->GetButtonParam(Settings::NativeButton::ZL); | 
					
						
							|  |  |  |         if (param.Has("threshold")) { | 
					
						
							| 
									
										
										
										
											2021-07-17 13:30:43 -05:00
										 |  |  |             const auto slider_value = ui->sliderZLThreshold->value(); | 
					
						
							| 
									
										
										
										
											2021-09-20 19:47:45 -05:00
										 |  |  |             param.Set("threshold", slider_value / 100.0f); | 
					
						
							|  |  |  |             emulated_controller->SetButtonParam(Settings::NativeButton::ZL, param); | 
					
						
							| 
									
										
										
										
											2021-07-17 13:30:43 -05:00
										 |  |  |         } | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     connect(ui->sliderZRThreshold, &QSlider::valueChanged, [=, this] { | 
					
						
							| 
									
										
										
										
											2021-09-20 19:47:45 -05:00
										 |  |  |         Common::ParamPackage param = | 
					
						
							|  |  |  |             emulated_controller->GetButtonParam(Settings::NativeButton::ZR); | 
					
						
							|  |  |  |         if (param.Has("threshold")) { | 
					
						
							| 
									
										
										
										
											2021-07-17 13:30:43 -05:00
										 |  |  |             const auto slider_value = ui->sliderZRThreshold->value(); | 
					
						
							| 
									
										
										
										
											2021-09-20 19:47:45 -05:00
										 |  |  |             param.Set("threshold", slider_value / 100.0f); | 
					
						
							|  |  |  |             emulated_controller->SetButtonParam(Settings::NativeButton::ZR, param); | 
					
						
							| 
									
										
										
										
											2021-07-17 13:30:43 -05:00
										 |  |  |         } | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-22 10:39:53 -04:00
										 |  |  |     for (int analog_id = 0; analog_id < Settings::NativeAnalog::NumAnalogs; ++analog_id) { | 
					
						
							|  |  |  |         for (int sub_button_id = 0; sub_button_id < ANALOG_SUB_BUTTONS_NUM; ++sub_button_id) { | 
					
						
							| 
									
										
										
										
											2019-05-19 12:08:48 -04:00
										 |  |  |             auto* const analog_button = analog_map_buttons[analog_id][sub_button_id]; | 
					
						
							| 
									
										
										
										
											2020-07-22 10:39:53 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-19 12:08:48 -04:00
										 |  |  |             if (analog_button == nullptr) { | 
					
						
							| 
									
										
										
										
											2018-11-01 22:11:44 -04:00
										 |  |  |                 continue; | 
					
						
							| 
									
										
										
										
											2019-05-19 12:08:48 -04:00
										 |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-03 11:28:18 -04:00
										 |  |  |             connect(analog_button, &QPushButton::clicked, [=, this] { | 
					
						
							| 
									
										
										
										
											2020-10-27 13:15:57 -04:00
										 |  |  |                 if (!map_analog_stick_accepted) { | 
					
						
							|  |  |  |                     map_analog_stick_accepted = | 
					
						
							|  |  |  |                         QMessageBox::information( | 
					
						
							|  |  |  |                             this, tr("Map Analog Stick"), | 
					
						
							|  |  |  |                             tr("After pressing OK, first move your joystick horizontally, and then " | 
					
						
							|  |  |  |                                "vertically.\nTo invert the axes, first move your joystick " | 
					
						
							|  |  |  |                                "vertically, and then horizontally."), | 
					
						
							|  |  |  |                             QMessageBox::Ok | QMessageBox::Cancel) == QMessageBox::Ok; | 
					
						
							|  |  |  |                     if (!map_analog_stick_accepted) { | 
					
						
							|  |  |  |                         return; | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                 } | 
					
						
							| 
									
										
										
										
											2020-08-11 11:08:10 -04:00
										 |  |  |                 HandleClick( | 
					
						
							| 
									
										
										
										
											2021-01-12 21:09:59 -06:00
										 |  |  |                     analog_map_buttons[analog_id][sub_button_id], analog_id, | 
					
						
							| 
									
										
										
										
											2020-08-11 11:08:10 -04:00
										 |  |  |                     [=, this](const Common::ParamPackage& params) { | 
					
						
							| 
									
										
										
										
											2021-09-20 19:47:45 -05:00
										 |  |  |                         Common::ParamPackage param = emulated_controller->GetStickParam(analog_id); | 
					
						
							|  |  |  |                         SetAnalogParam(params, param, analog_sub_buttons[sub_button_id]); | 
					
						
							|  |  |  |                         emulated_controller->SetStickParam(analog_id, param); | 
					
						
							| 
									
										
										
										
											2020-08-11 11:08:10 -04:00
										 |  |  |                     }, | 
					
						
							| 
									
										
										
										
											2021-09-20 19:47:45 -05:00
										 |  |  |                     InputCommon::Polling::InputType::Stick); | 
					
						
							| 
									
										
										
										
											2018-11-01 22:11:44 -04:00
										 |  |  |             }); | 
					
						
							| 
									
										
										
										
											2020-09-01 10:02:18 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |             analog_button->setContextMenuPolicy(Qt::CustomContextMenu); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-20 19:47:45 -05:00
										 |  |  |             connect(analog_button, &QPushButton::customContextMenuRequested, | 
					
						
							|  |  |  |                     [=, this](const QPoint& menu_location) { | 
					
						
							|  |  |  |                         QMenu context_menu; | 
					
						
							|  |  |  |                         Common::ParamPackage param = emulated_controller->GetStickParam(analog_id); | 
					
						
							|  |  |  |                         context_menu.addAction(tr("Clear"), [&] { | 
					
						
							|  |  |  |                             emulated_controller->SetStickParam(analog_id, {}); | 
					
						
							|  |  |  |                             analog_map_buttons[analog_id][sub_button_id]->setText(tr("[not set]")); | 
					
						
							|  |  |  |                         }); | 
					
						
							|  |  |  |                         context_menu.addAction(tr("Invert axis"), [&] { | 
					
						
							|  |  |  |                             if (sub_button_id == 2 || sub_button_id == 3) { | 
					
						
							|  |  |  |                                 const bool invert_value = param.Get("invert_x", "+") == "-"; | 
					
						
							|  |  |  |                                 const std::string invert_str = invert_value ? "+" : "-"; | 
					
						
							|  |  |  |                                 param.Set("invert_x", invert_str); | 
					
						
							|  |  |  |                                 emulated_controller->SetStickParam(analog_id, param); | 
					
						
							|  |  |  |                             } | 
					
						
							|  |  |  |                             if (sub_button_id == 0 || sub_button_id == 1) { | 
					
						
							|  |  |  |                                 const bool invert_value = param.Get("invert_y", "+") == "-"; | 
					
						
							|  |  |  |                                 const std::string invert_str = invert_value ? "+" : "-"; | 
					
						
							|  |  |  |                                 param.Set("invert_y", invert_str); | 
					
						
							|  |  |  |                                 emulated_controller->SetStickParam(analog_id, param); | 
					
						
							|  |  |  |                             } | 
					
						
							|  |  |  |                             for (int sub_button_id = 0; sub_button_id < ANALOG_SUB_BUTTONS_NUM; | 
					
						
							|  |  |  |                                  ++sub_button_id) { | 
					
						
							|  |  |  |                                 analog_map_buttons[analog_id][sub_button_id]->setText( | 
					
						
							|  |  |  |                                     AnalogToText(param, analog_sub_buttons[sub_button_id])); | 
					
						
							|  |  |  |                             } | 
					
						
							|  |  |  |                         }); | 
					
						
							|  |  |  |                         context_menu.exec(analog_map_buttons[analog_id][sub_button_id]->mapToGlobal( | 
					
						
							|  |  |  |                             menu_location)); | 
					
						
							| 
									
										
										
										
											2020-09-01 10:02:18 -04:00
										 |  |  |                     }); | 
					
						
							| 
									
										
										
										
											2018-11-01 22:11:44 -04:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-07-22 10:39:53 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-01 10:02:18 -04:00
										 |  |  |         // Handle clicks for the modifier buttons as well.
 | 
					
						
							| 
									
										
										
										
											2020-10-20 14:23:25 -04:00
										 |  |  |         connect(analog_map_modifier_button[analog_id], &QPushButton::clicked, [=, this] { | 
					
						
							|  |  |  |             HandleClick( | 
					
						
							| 
									
										
										
										
											2021-01-12 21:09:59 -06:00
										 |  |  |                 analog_map_modifier_button[analog_id], analog_id, | 
					
						
							| 
									
										
										
										
											2020-10-20 14:23:25 -04:00
										 |  |  |                 [=, this](const Common::ParamPackage& params) { | 
					
						
							| 
									
										
										
										
											2021-09-20 19:47:45 -05:00
										 |  |  |                     Common::ParamPackage param = emulated_controller->GetStickParam(analog_id); | 
					
						
							|  |  |  |                     param.Set("modifier", params.Serialize()); | 
					
						
							|  |  |  |                     emulated_controller->SetStickParam(analog_id, param); | 
					
						
							| 
									
										
										
										
											2020-10-20 14:23:25 -04:00
										 |  |  |                 }, | 
					
						
							| 
									
										
										
										
											2021-09-20 19:47:45 -05:00
										 |  |  |                 InputCommon::Polling::InputType::Button); | 
					
						
							| 
									
										
										
										
											2020-10-20 14:23:25 -04:00
										 |  |  |         }); | 
					
						
							| 
									
										
										
										
											2020-09-01 10:02:18 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-20 14:23:25 -04:00
										 |  |  |         analog_map_modifier_button[analog_id]->setContextMenuPolicy(Qt::CustomContextMenu); | 
					
						
							| 
									
										
										
										
											2020-09-01 10:02:18 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-21 20:41:16 -06:00
										 |  |  |         connect( | 
					
						
							|  |  |  |             analog_map_modifier_button[analog_id], &QPushButton::customContextMenuRequested, | 
					
						
							|  |  |  |             [=, this](const QPoint& menu_location) { | 
					
						
							|  |  |  |                 QMenu context_menu; | 
					
						
							|  |  |  |                 Common::ParamPackage param = emulated_controller->GetStickParam(analog_id); | 
					
						
							|  |  |  |                 context_menu.addAction(tr("Clear"), [&] { | 
					
						
							|  |  |  |                     param.Set("modifier", ""); | 
					
						
							|  |  |  |                     analog_map_modifier_button[analog_id]->setText(tr("[not set]")); | 
					
						
							|  |  |  |                     emulated_controller->SetStickParam(analog_id, param); | 
					
						
							|  |  |  |                 }); | 
					
						
							|  |  |  |                 context_menu.addAction(tr("Toggle button"), [&] { | 
					
						
							|  |  |  |                     Common::ParamPackage modifier_param = | 
					
						
							|  |  |  |                         Common::ParamPackage{param.Get("modifier", "")}; | 
					
						
							|  |  |  |                     const bool toggle_value = !modifier_param.Get("toggle", false); | 
					
						
							|  |  |  |                     modifier_param.Set("toggle", toggle_value); | 
					
						
							|  |  |  |                     param.Set("modifier", modifier_param.Serialize()); | 
					
						
							|  |  |  |                     analog_map_modifier_button[analog_id]->setText(ButtonToText(modifier_param)); | 
					
						
							|  |  |  |                     emulated_controller->SetStickParam(analog_id, param); | 
					
						
							| 
									
										
										
										
											2020-09-01 10:02:18 -04:00
										 |  |  |                 }); | 
					
						
							| 
									
										
										
										
											2022-01-21 20:41:16 -06:00
										 |  |  |                 context_menu.addAction(tr("Invert button"), [&] { | 
					
						
							|  |  |  |                     Common::ParamPackage modifier_param = | 
					
						
							|  |  |  |                         Common::ParamPackage{param.Get("modifier", "")}; | 
					
						
							|  |  |  |                     const bool invert_value = !modifier_param.Get("inverted", false); | 
					
						
							|  |  |  |                     modifier_param.Set("inverted", invert_value); | 
					
						
							|  |  |  |                     param.Set("modifier", modifier_param.Serialize()); | 
					
						
							|  |  |  |                     analog_map_modifier_button[analog_id]->setText(ButtonToText(modifier_param)); | 
					
						
							|  |  |  |                     emulated_controller->SetStickParam(analog_id, param); | 
					
						
							|  |  |  |                 }); | 
					
						
							|  |  |  |                 context_menu.exec( | 
					
						
							|  |  |  |                     analog_map_modifier_button[analog_id]->mapToGlobal(menu_location)); | 
					
						
							|  |  |  |             }); | 
					
						
							| 
									
										
										
										
											2020-09-01 10:02:18 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-22 10:39:53 -04:00
										 |  |  |         connect(analog_map_range_spinbox[analog_id], qOverload<int>(&QSpinBox::valueChanged), | 
					
						
							| 
									
										
										
										
											2020-08-03 11:28:18 -04:00
										 |  |  |                 [=, this] { | 
					
						
							| 
									
										
										
										
											2021-09-20 19:47:45 -05:00
										 |  |  |                     Common::ParamPackage param = emulated_controller->GetStickParam(analog_id); | 
					
						
							| 
									
										
										
										
											2020-07-22 10:39:53 -04:00
										 |  |  |                     const auto spinbox_value = analog_map_range_spinbox[analog_id]->value(); | 
					
						
							| 
									
										
										
										
											2021-09-20 19:47:45 -05:00
										 |  |  |                     param.Set("range", spinbox_value / 100.0f); | 
					
						
							|  |  |  |                     emulated_controller->SetStickParam(analog_id, param); | 
					
						
							| 
									
										
										
										
											2020-08-03 11:28:18 -04:00
										 |  |  |                 }); | 
					
						
							| 
									
										
										
										
											2020-07-22 10:39:53 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |         connect(analog_map_deadzone_slider[analog_id], &QSlider::valueChanged, [=, this] { | 
					
						
							| 
									
										
										
										
											2021-09-20 19:47:45 -05:00
										 |  |  |             Common::ParamPackage param = emulated_controller->GetStickParam(analog_id); | 
					
						
							| 
									
										
										
										
											2020-07-22 10:39:53 -04:00
										 |  |  |             const auto slider_value = analog_map_deadzone_slider[analog_id]->value(); | 
					
						
							|  |  |  |             analog_map_deadzone_label[analog_id]->setText(tr("Deadzone: %1%").arg(slider_value)); | 
					
						
							| 
									
										
										
										
											2021-09-20 19:47:45 -05:00
										 |  |  |             param.Set("deadzone", slider_value / 100.0f); | 
					
						
							|  |  |  |             emulated_controller->SetStickParam(analog_id, param); | 
					
						
							| 
									
										
										
										
											2020-07-22 10:39:53 -04:00
										 |  |  |         }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         connect(analog_map_modifier_slider[analog_id], &QSlider::valueChanged, [=, this] { | 
					
						
							| 
									
										
										
										
											2021-09-20 19:47:45 -05:00
										 |  |  |             Common::ParamPackage param = emulated_controller->GetStickParam(analog_id); | 
					
						
							| 
									
										
										
										
											2020-07-22 10:39:53 -04:00
										 |  |  |             const auto slider_value = analog_map_modifier_slider[analog_id]->value(); | 
					
						
							|  |  |  |             analog_map_modifier_label[analog_id]->setText( | 
					
						
							|  |  |  |                 tr("Modifier Range: %1%").arg(slider_value)); | 
					
						
							| 
									
										
										
										
											2021-09-20 19:47:45 -05:00
										 |  |  |             param.Set("modifier_scale", slider_value / 100.0f); | 
					
						
							|  |  |  |             emulated_controller->SetStickParam(analog_id, param); | 
					
						
							| 
									
										
										
										
											2020-07-22 10:39:53 -04:00
										 |  |  |         }); | 
					
						
							| 
									
										
										
										
											2018-11-01 22:11:44 -04:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-22 10:39:53 -04:00
										 |  |  |     // Player Connected checkbox
 | 
					
						
							| 
									
										
										
										
											2021-09-20 19:47:45 -05:00
										 |  |  |     connect(ui->groupConnectedController, &QGroupBox::toggled, | 
					
						
							|  |  |  |             [this](bool checked) { emit Connected(checked); }); | 
					
						
							| 
									
										
										
										
											2020-07-22 10:39:53 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (player_index == 0) { | 
					
						
							|  |  |  |         connect(ui->comboControllerType, qOverload<int>(&QComboBox::currentIndexChanged), | 
					
						
							| 
									
										
										
										
											2020-08-15 15:26:29 -04:00
										 |  |  |                 [this](int index) { | 
					
						
							| 
									
										
										
										
											2020-07-22 10:39:53 -04:00
										 |  |  |                     emit HandheldStateChanged(GetControllerTypeFromIndex(index) == | 
					
						
							| 
									
										
										
										
											2021-11-04 12:08:54 -06:00
										 |  |  |                                               Core::HID::NpadStyleIndex::Handheld); | 
					
						
							| 
									
										
										
										
											2020-07-22 10:39:53 -04:00
										 |  |  |                 }); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-26 03:28:03 -04:00
										 |  |  |     if (debug || player_index == 9) { | 
					
						
							|  |  |  |         ui->groupConnectedController->setCheckable(false); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-22 10:39:53 -04:00
										 |  |  |     // The Debug Controller can only choose the Pro Controller.
 | 
					
						
							|  |  |  |     if (debug) { | 
					
						
							|  |  |  |         ui->buttonScreenshot->setEnabled(false); | 
					
						
							|  |  |  |         ui->buttonHome->setEnabled(false); | 
					
						
							| 
									
										
										
										
											2020-11-20 09:48:26 -05:00
										 |  |  |         ui->comboControllerType->addItem(tr("Pro Controller")); | 
					
						
							| 
									
										
										
										
											2020-07-22 10:39:53 -04:00
										 |  |  |     } else { | 
					
						
							| 
									
										
										
										
											2020-11-20 09:48:26 -05:00
										 |  |  |         SetConnectableControllers(); | 
					
						
							| 
									
										
										
										
											2020-07-22 10:39:53 -04:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     UpdateControllerAvailableButtons(); | 
					
						
							| 
									
										
										
										
											2021-02-06 11:53:25 -06:00
										 |  |  |     UpdateControllerEnabledButtons(); | 
					
						
							|  |  |  |     UpdateControllerButtonNames(); | 
					
						
							| 
									
										
										
										
											2020-09-02 12:33:37 -04:00
										 |  |  |     UpdateMotionButtons(); | 
					
						
							| 
									
										
										
										
											2021-10-24 11:22:20 -05:00
										 |  |  |     connect(ui->comboControllerType, qOverload<int>(&QComboBox::currentIndexChanged), | 
					
						
							|  |  |  |             [this, player_index](int) { | 
					
						
							|  |  |  |                 UpdateControllerAvailableButtons(); | 
					
						
							|  |  |  |                 UpdateControllerEnabledButtons(); | 
					
						
							|  |  |  |                 UpdateControllerButtonNames(); | 
					
						
							|  |  |  |                 UpdateMotionButtons(); | 
					
						
							| 
									
										
										
										
											2021-11-04 12:08:54 -06:00
										 |  |  |                 const Core::HID::NpadStyleIndex type = | 
					
						
							| 
									
										
										
										
											2021-10-24 11:22:20 -05:00
										 |  |  |                     GetControllerTypeFromIndex(ui->comboControllerType->currentIndex()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |                 if (player_index == 0) { | 
					
						
							|  |  |  |                     auto* emulated_controller_p1 = | 
					
						
							| 
									
										
										
										
											2021-11-04 21:54:22 -06:00
										 |  |  |                         hid_core.GetEmulatedController(Core::HID::NpadIdType::Player1); | 
					
						
							| 
									
										
										
										
											2021-11-29 17:22:59 -05:00
										 |  |  |                     auto* emulated_controller_handheld = | 
					
						
							| 
									
										
										
										
											2021-11-04 21:54:22 -06:00
										 |  |  |                         hid_core.GetEmulatedController(Core::HID::NpadIdType::Handheld); | 
					
						
							| 
									
										
										
										
											2021-10-24 11:22:20 -05:00
										 |  |  |                     bool is_connected = emulated_controller->IsConnected(true); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-04 12:08:54 -06:00
										 |  |  |                     emulated_controller_p1->SetNpadStyleIndex(type); | 
					
						
							| 
									
										
										
										
											2021-11-29 17:22:59 -05:00
										 |  |  |                     emulated_controller_handheld->SetNpadStyleIndex(type); | 
					
						
							| 
									
										
										
										
											2021-10-24 11:22:20 -05:00
										 |  |  |                     if (is_connected) { | 
					
						
							| 
									
										
										
										
											2021-11-04 12:08:54 -06:00
										 |  |  |                         if (type == Core::HID::NpadStyleIndex::Handheld) { | 
					
						
							| 
									
										
										
										
											2021-10-24 11:22:20 -05:00
										 |  |  |                             emulated_controller_p1->Disconnect(); | 
					
						
							| 
									
										
										
										
											2021-12-29 22:15:08 -06:00
										 |  |  |                             emulated_controller_handheld->Connect(true); | 
					
						
							| 
									
										
										
										
											2021-11-29 17:22:59 -05:00
										 |  |  |                             emulated_controller = emulated_controller_handheld; | 
					
						
							| 
									
										
										
										
											2021-10-24 11:22:20 -05:00
										 |  |  |                         } else { | 
					
						
							| 
									
										
										
										
											2021-11-29 17:22:59 -05:00
										 |  |  |                             emulated_controller_handheld->Disconnect(); | 
					
						
							| 
									
										
										
										
											2021-12-29 22:15:08 -06:00
										 |  |  |                             emulated_controller_p1->Connect(true); | 
					
						
							| 
									
										
										
										
											2021-10-24 11:22:20 -05:00
										 |  |  |                             emulated_controller = emulated_controller_p1; | 
					
						
							|  |  |  |                         } | 
					
						
							|  |  |  |                     } | 
					
						
							|  |  |  |                     ui->controllerFrame->SetController(emulated_controller); | 
					
						
							| 
									
										
										
										
											2021-10-18 23:15:46 -05:00
										 |  |  |                 } | 
					
						
							| 
									
										
										
										
											2021-11-04 12:08:54 -06:00
										 |  |  |                 emulated_controller->SetNpadStyleIndex(type); | 
					
						
							| 
									
										
										
										
											2021-10-24 11:22:20 -05:00
										 |  |  |             }); | 
					
						
							| 
									
										
										
										
											2020-07-22 10:39:53 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-17 12:00:29 -04:00
										 |  |  |     connect(ui->comboDevices, qOverload<int>(&QComboBox::activated), this, | 
					
						
							| 
									
										
										
										
											2020-08-15 15:26:29 -04:00
										 |  |  |             &ConfigureInputPlayer::UpdateMappingWithDefaults); | 
					
						
							| 
									
										
										
										
											2020-07-22 10:39:53 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-17 12:00:29 -04:00
										 |  |  |     ui->comboDevices->setCurrentIndex(-1); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-22 10:39:53 -04:00
										 |  |  |     ui->buttonRefreshDevices->setIcon(QIcon::fromTheme(QStringLiteral("view-refresh"))); | 
					
						
							| 
									
										
										
										
											2020-08-15 15:26:29 -04:00
										 |  |  |     connect(ui->buttonRefreshDevices, &QPushButton::clicked, | 
					
						
							|  |  |  |             [this] { emit RefreshInputDevices(); }); | 
					
						
							| 
									
										
										
										
											2018-11-01 22:11:44 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |     timeout_timer->setSingleShot(true); | 
					
						
							| 
									
										
										
										
											2019-05-26 00:39:23 -04:00
										 |  |  |     connect(timeout_timer.get(), &QTimer::timeout, [this] { SetPollingResult({}, true); }); | 
					
						
							| 
									
										
										
										
											2018-11-01 22:11:44 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-21 15:31:57 -04:00
										 |  |  |     connect(poll_timer.get(), &QTimer::timeout, [this] { | 
					
						
							| 
									
										
										
										
											2021-09-20 19:47:45 -05:00
										 |  |  |         const auto& params = input_subsystem->GetNextInput(); | 
					
						
							|  |  |  |         if (params.Has("engine") && IsInputAcceptable(params)) { | 
					
						
							|  |  |  |             SetPollingResult(params, false); | 
					
						
							|  |  |  |             return; | 
					
						
							| 
									
										
										
										
											2018-11-01 22:11:44 -04:00
										 |  |  |         } | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-29 12:15:35 -04:00
										 |  |  |     UpdateInputProfiles(); | 
					
						
							| 
									
										
										
										
											2020-09-23 09:52:25 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |     connect(ui->buttonProfilesNew, &QPushButton::clicked, this, | 
					
						
							|  |  |  |             &ConfigureInputPlayer::CreateProfile); | 
					
						
							|  |  |  |     connect(ui->buttonProfilesDelete, &QPushButton::clicked, this, | 
					
						
							|  |  |  |             &ConfigureInputPlayer::DeleteProfile); | 
					
						
							|  |  |  |     connect(ui->comboProfiles, qOverload<int>(&QComboBox::activated), this, | 
					
						
							|  |  |  |             &ConfigureInputPlayer::LoadProfile); | 
					
						
							|  |  |  |     connect(ui->buttonProfilesSave, &QPushButton::clicked, this, | 
					
						
							|  |  |  |             &ConfigureInputPlayer::SaveProfile); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-26 00:39:23 -04:00
										 |  |  |     LoadConfiguration(); | 
					
						
							| 
									
										
										
										
											2018-11-01 22:11:44 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-20 19:47:45 -05:00
										 |  |  | ConfigureInputPlayer::~ConfigureInputPlayer() { | 
					
						
							| 
									
										
										
										
											2021-10-18 23:15:46 -05:00
										 |  |  |     if (player_index == 0) { | 
					
						
							|  |  |  |         auto* emulated_controller_p1 = | 
					
						
							| 
									
										
										
										
											2021-11-04 21:54:22 -06:00
										 |  |  |             hid_core.GetEmulatedController(Core::HID::NpadIdType::Player1); | 
					
						
							| 
									
										
										
										
											2021-11-29 17:22:59 -05:00
										 |  |  |         auto* emulated_controller_handheld = | 
					
						
							| 
									
										
										
										
											2021-11-04 21:54:22 -06:00
										 |  |  |             hid_core.GetEmulatedController(Core::HID::NpadIdType::Handheld); | 
					
						
							| 
									
										
										
										
											2021-10-18 23:15:46 -05:00
										 |  |  |         emulated_controller_p1->DisableConfiguration(); | 
					
						
							| 
									
										
										
										
											2021-11-29 17:22:59 -05:00
										 |  |  |         emulated_controller_handheld->DisableConfiguration(); | 
					
						
							| 
									
										
										
										
											2021-10-18 23:15:46 -05:00
										 |  |  |     } else { | 
					
						
							|  |  |  |         emulated_controller->DisableConfiguration(); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-10-24 11:22:20 -05:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2018-11-04 10:18:59 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-26 00:39:23 -04:00
										 |  |  | void ConfigureInputPlayer::ApplyConfiguration() { | 
					
						
							| 
									
										
										
										
											2021-10-18 23:15:46 -05:00
										 |  |  |     if (player_index == 0) { | 
					
						
							|  |  |  |         auto* emulated_controller_p1 = | 
					
						
							| 
									
										
										
										
											2021-11-04 21:54:22 -06:00
										 |  |  |             hid_core.GetEmulatedController(Core::HID::NpadIdType::Player1); | 
					
						
							| 
									
										
										
										
											2021-11-29 17:22:59 -05:00
										 |  |  |         auto* emulated_controller_handheld = | 
					
						
							| 
									
										
										
										
											2021-11-04 21:54:22 -06:00
										 |  |  |             hid_core.GetEmulatedController(Core::HID::NpadIdType::Handheld); | 
					
						
							| 
									
										
										
										
											2021-10-18 23:15:46 -05:00
										 |  |  |         emulated_controller_p1->DisableConfiguration(); | 
					
						
							|  |  |  |         emulated_controller_p1->SaveCurrentConfig(); | 
					
						
							|  |  |  |         emulated_controller_p1->EnableConfiguration(); | 
					
						
							| 
									
										
										
										
											2021-11-29 17:22:59 -05:00
										 |  |  |         emulated_controller_handheld->DisableConfiguration(); | 
					
						
							|  |  |  |         emulated_controller_handheld->SaveCurrentConfig(); | 
					
						
							|  |  |  |         emulated_controller_handheld->EnableConfiguration(); | 
					
						
							| 
									
										
										
										
											2021-10-18 23:15:46 -05:00
										 |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     emulated_controller->DisableConfiguration(); | 
					
						
							| 
									
										
										
										
											2021-09-20 19:47:45 -05:00
										 |  |  |     emulated_controller->SaveCurrentConfig(); | 
					
						
							| 
									
										
										
										
											2021-10-18 23:15:46 -05:00
										 |  |  |     emulated_controller->EnableConfiguration(); | 
					
						
							| 
									
										
										
										
											2020-12-21 10:46:19 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-17 12:00:29 -04:00
										 |  |  | void ConfigureInputPlayer::showEvent(QShowEvent* event) { | 
					
						
							|  |  |  |     if (bottom_row == nullptr) { | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     QWidget::showEvent(event); | 
					
						
							|  |  |  |     ui->main->addWidget(bottom_row); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-05 18:39:46 -04:00
										 |  |  | void ConfigureInputPlayer::changeEvent(QEvent* event) { | 
					
						
							|  |  |  |     if (event->type() == QEvent::LanguageChange) { | 
					
						
							|  |  |  |         RetranslateUI(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-22 10:39:53 -04:00
										 |  |  |     QWidget::changeEvent(event); | 
					
						
							| 
									
										
										
										
											2019-06-05 18:39:46 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ConfigureInputPlayer::RetranslateUI() { | 
					
						
							|  |  |  |     ui->retranslateUi(this); | 
					
						
							| 
									
										
										
										
											2020-07-22 10:39:53 -04:00
										 |  |  |     UpdateUI(); | 
					
						
							| 
									
										
										
										
											2018-11-01 22:11:44 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-26 00:39:23 -04:00
										 |  |  | void ConfigureInputPlayer::LoadConfiguration() { | 
					
						
							| 
									
										
										
										
											2021-10-22 12:34:44 -05:00
										 |  |  |     emulated_controller->ReloadFromSettings(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-22 10:39:53 -04:00
										 |  |  |     UpdateUI(); | 
					
						
							| 
									
										
										
										
											2020-09-17 12:00:29 -04:00
										 |  |  |     UpdateInputDeviceCombobox(); | 
					
						
							| 
									
										
										
										
											2021-10-22 12:34:44 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (debug) { | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-04 12:08:54 -06:00
										 |  |  |     const int comboBoxIndex = | 
					
						
							|  |  |  |         GetIndexFromControllerType(emulated_controller->GetNpadStyleIndex(true)); | 
					
						
							| 
									
										
										
										
											2021-09-20 19:47:45 -05:00
										 |  |  |     ui->comboControllerType->setCurrentIndex(comboBoxIndex); | 
					
						
							| 
									
										
										
										
											2021-10-18 23:15:46 -05:00
										 |  |  |     ui->groupConnectedController->setChecked(emulated_controller->IsConnected(true)); | 
					
						
							| 
									
										
										
										
											2020-07-22 10:39:53 -04:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2018-11-01 22:11:44 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-17 12:00:29 -04:00
										 |  |  | void ConfigureInputPlayer::ConnectPlayer(bool connected) { | 
					
						
							|  |  |  |     ui->groupConnectedController->setChecked(connected); | 
					
						
							| 
									
										
										
										
											2021-10-11 00:43:11 -05:00
										 |  |  |     if (connected) { | 
					
						
							| 
									
										
										
										
											2021-12-29 22:15:08 -06:00
										 |  |  |         emulated_controller->Connect(true); | 
					
						
							| 
									
										
										
										
											2021-10-11 00:43:11 -05:00
										 |  |  |     } else { | 
					
						
							|  |  |  |         emulated_controller->Disconnect(); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-09-17 12:00:29 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ConfigureInputPlayer::UpdateInputDeviceCombobox() { | 
					
						
							|  |  |  |     // Skip input device persistence if "Input Devices" is set to "Any".
 | 
					
						
							|  |  |  |     if (ui->comboDevices->currentIndex() == 0) { | 
					
						
							|  |  |  |         UpdateInputDevices(); | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-08 20:28:09 -06:00
										 |  |  |     const auto devices = | 
					
						
							|  |  |  |         emulated_controller->GetMappedDevices(Core::HID::EmulatedDeviceIndex::AllDevices); | 
					
						
							| 
									
										
										
										
											2021-09-20 19:47:45 -05:00
										 |  |  |     UpdateInputDevices(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (devices.empty()) { | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (devices.size() > 2) { | 
					
						
							|  |  |  |         ui->comboDevices->setCurrentIndex(0); | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const auto first_engine = devices[0].Get("engine", ""); | 
					
						
							|  |  |  |     const auto first_guid = devices[0].Get("guid", ""); | 
					
						
							| 
									
										
										
										
											2021-10-24 11:22:20 -05:00
										 |  |  |     const auto first_port = devices[0].Get("port", 0); | 
					
						
							| 
									
										
										
										
											2022-01-07 16:55:55 -06:00
										 |  |  |     const auto first_pad = devices[0].Get("pad", 0); | 
					
						
							| 
									
										
										
										
											2020-09-17 12:00:29 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-20 19:47:45 -05:00
										 |  |  |     if (devices.size() == 1) { | 
					
						
							| 
									
										
										
										
											2022-01-07 16:55:55 -06:00
										 |  |  |         const auto devices_it = std::find_if( | 
					
						
							|  |  |  |             input_devices.begin(), input_devices.end(), | 
					
						
							| 
									
										
										
										
											2022-02-01 12:20:01 -05:00
										 |  |  |             [first_engine, first_guid, first_port, first_pad](const Common::ParamPackage& param) { | 
					
						
							| 
									
										
										
										
											2022-01-07 16:55:55 -06:00
										 |  |  |                 return param.Get("engine", "") == first_engine && | 
					
						
							|  |  |  |                        param.Get("guid", "") == first_guid && param.Get("port", 0) == first_port && | 
					
						
							|  |  |  |                        param.Get("pad", 0) == first_pad; | 
					
						
							|  |  |  |             }); | 
					
						
							| 
									
										
										
										
											2021-09-20 19:47:45 -05:00
										 |  |  |         const int device_index = | 
					
						
							|  |  |  |             devices_it != input_devices.end() | 
					
						
							|  |  |  |                 ? static_cast<int>(std::distance(input_devices.begin(), devices_it)) | 
					
						
							|  |  |  |                 : 0; | 
					
						
							|  |  |  |         ui->comboDevices->setCurrentIndex(device_index); | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-09-17 12:00:29 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-20 19:47:45 -05:00
										 |  |  |     const auto second_engine = devices[1].Get("engine", ""); | 
					
						
							|  |  |  |     const auto second_guid = devices[1].Get("guid", ""); | 
					
						
							| 
									
										
										
										
											2021-10-24 11:22:20 -05:00
										 |  |  |     const auto second_port = devices[1].Get("port", 0); | 
					
						
							| 
									
										
										
										
											2020-11-11 07:46:41 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-20 19:47:45 -05:00
										 |  |  |     const bool is_keyboard_mouse = (first_engine == "keyboard" || first_engine == "mouse") && | 
					
						
							|  |  |  |                                    (second_engine == "keyboard" || second_engine == "mouse"); | 
					
						
							| 
									
										
										
										
											2020-09-17 12:00:29 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-20 19:47:45 -05:00
										 |  |  |     if (is_keyboard_mouse) { | 
					
						
							|  |  |  |         ui->comboDevices->setCurrentIndex(2); | 
					
						
							| 
									
										
										
										
											2020-09-17 12:00:29 -04:00
										 |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-20 19:47:45 -05:00
										 |  |  |     const bool is_engine_equal = first_engine == second_engine; | 
					
						
							|  |  |  |     const bool is_port_equal = first_port == second_port; | 
					
						
							| 
									
										
										
										
											2020-09-17 12:00:29 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-20 19:47:45 -05:00
										 |  |  |     if (is_engine_equal && is_port_equal) { | 
					
						
							| 
									
										
										
										
											2020-09-17 12:00:29 -04:00
										 |  |  |         const auto devices_it = std::find_if( | 
					
						
							|  |  |  |             input_devices.begin(), input_devices.end(), | 
					
						
							| 
									
										
										
										
											2022-02-01 12:20:01 -05:00
										 |  |  |             [first_engine, first_guid, second_guid, first_port](const Common::ParamPackage& param) { | 
					
						
							| 
									
										
										
										
											2021-09-20 19:47:45 -05:00
										 |  |  |                 const bool is_guid_valid = | 
					
						
							|  |  |  |                     (param.Get("guid", "") == first_guid && | 
					
						
							|  |  |  |                      param.Get("guid2", "") == second_guid) || | 
					
						
							|  |  |  |                     (param.Get("guid", "") == second_guid && param.Get("guid2", "") == first_guid); | 
					
						
							|  |  |  |                 return param.Get("engine", "") == first_engine && is_guid_valid && | 
					
						
							| 
									
										
										
										
											2021-10-24 11:22:20 -05:00
										 |  |  |                        param.Get("port", 0) == first_port; | 
					
						
							| 
									
										
										
										
											2020-09-17 12:00:29 -04:00
										 |  |  |             }); | 
					
						
							|  |  |  |         const int device_index = | 
					
						
							|  |  |  |             devices_it != input_devices.end() | 
					
						
							|  |  |  |                 ? static_cast<int>(std::distance(input_devices.begin(), devices_it)) | 
					
						
							|  |  |  |                 : 0; | 
					
						
							|  |  |  |         ui->comboDevices->setCurrentIndex(device_index); | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |         ui->comboDevices->setCurrentIndex(0); | 
					
						
							| 
									
										
										
										
											2018-11-01 22:11:44 -04:00
										 |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-05-26 00:39:23 -04:00
										 |  |  | void ConfigureInputPlayer::RestoreDefaults() { | 
					
						
							| 
									
										
										
										
											2020-09-28 10:27:29 -04:00
										 |  |  |     UpdateMappingWithDefaults(); | 
					
						
							| 
									
										
										
										
											2018-11-01 22:11:44 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ConfigureInputPlayer::ClearAll() { | 
					
						
							| 
									
										
										
										
											2020-07-22 10:39:53 -04:00
										 |  |  |     for (int button_id = 0; button_id < Settings::NativeButton::NumButtons; ++button_id) { | 
					
						
							| 
									
										
										
										
											2019-05-19 12:08:48 -04:00
										 |  |  |         const auto* const button = button_map[button_id]; | 
					
						
							| 
									
										
										
										
											2020-09-01 10:02:18 -04:00
										 |  |  |         if (button == nullptr) { | 
					
						
							| 
									
										
										
										
											2019-05-19 12:08:48 -04:00
										 |  |  |             continue; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2021-09-20 19:47:45 -05:00
										 |  |  |         emulated_controller->SetButtonParam(button_id, {}); | 
					
						
							| 
									
										
										
										
											2018-11-01 22:11:44 -04:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2019-05-19 12:08:48 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-22 10:39:53 -04:00
										 |  |  |     for (int analog_id = 0; analog_id < Settings::NativeAnalog::NumAnalogs; ++analog_id) { | 
					
						
							|  |  |  |         for (int sub_button_id = 0; sub_button_id < ANALOG_SUB_BUTTONS_NUM; ++sub_button_id) { | 
					
						
							| 
									
										
										
										
											2019-05-19 12:08:48 -04:00
										 |  |  |             const auto* const analog_button = analog_map_buttons[analog_id][sub_button_id]; | 
					
						
							| 
									
										
										
										
											2020-09-01 10:02:18 -04:00
										 |  |  |             if (analog_button == nullptr) { | 
					
						
							| 
									
										
										
										
											2019-05-19 12:08:48 -04:00
										 |  |  |                 continue; | 
					
						
							|  |  |  |             } | 
					
						
							| 
									
										
										
										
											2021-09-20 19:47:45 -05:00
										 |  |  |             emulated_controller->SetStickParam(analog_id, {}); | 
					
						
							| 
									
										
										
										
											2018-11-01 22:11:44 -04:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-04 21:48:03 -05:00
										 |  |  |     for (int motion_id = 0; motion_id < Settings::NativeMotion::NumMotions; ++motion_id) { | 
					
						
							| 
									
										
										
										
											2020-09-01 10:02:18 -04:00
										 |  |  |         const auto* const motion_button = motion_map[motion_id]; | 
					
						
							|  |  |  |         if (motion_button == nullptr) { | 
					
						
							| 
									
										
										
										
											2020-09-04 21:48:03 -05:00
										 |  |  |             continue; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2021-09-20 19:47:45 -05:00
										 |  |  |         emulated_controller->SetMotionParam(motion_id, {}); | 
					
						
							| 
									
										
										
										
											2020-09-04 21:48:03 -05:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-22 10:39:53 -04:00
										 |  |  |     UpdateUI(); | 
					
						
							|  |  |  |     UpdateInputDevices(); | 
					
						
							| 
									
										
										
										
											2018-11-01 22:11:44 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-22 10:39:53 -04:00
										 |  |  | void ConfigureInputPlayer::UpdateUI() { | 
					
						
							|  |  |  |     for (int button = 0; button < Settings::NativeButton::NumButtons; ++button) { | 
					
						
							| 
									
										
										
										
											2021-09-20 19:47:45 -05:00
										 |  |  |         const Common::ParamPackage param = emulated_controller->GetButtonParam(button); | 
					
						
							|  |  |  |         button_map[button]->setText(ButtonToText(param)); | 
					
						
							| 
									
										
										
										
											2018-11-01 22:11:44 -04:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-20 19:47:45 -05:00
										 |  |  |     const Common::ParamPackage ZL_param = | 
					
						
							|  |  |  |         emulated_controller->GetButtonParam(Settings::NativeButton::ZL); | 
					
						
							|  |  |  |     if (ZL_param.Has("threshold")) { | 
					
						
							|  |  |  |         const int button_threshold = static_cast<int>(ZL_param.Get("threshold", 0.5f) * 100.0f); | 
					
						
							| 
									
										
										
										
											2021-07-17 13:30:43 -05:00
										 |  |  |         ui->sliderZLThreshold->setValue(button_threshold); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-20 19:47:45 -05:00
										 |  |  |     const Common::ParamPackage ZR_param = | 
					
						
							|  |  |  |         emulated_controller->GetButtonParam(Settings::NativeButton::ZR); | 
					
						
							|  |  |  |     if (ZR_param.Has("threshold")) { | 
					
						
							|  |  |  |         const int button_threshold = static_cast<int>(ZR_param.Get("threshold", 0.5f) * 100.0f); | 
					
						
							| 
									
										
										
										
											2021-07-17 13:30:43 -05:00
										 |  |  |         ui->sliderZRThreshold->setValue(button_threshold); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-04 21:48:03 -05:00
										 |  |  |     for (int motion_id = 0; motion_id < Settings::NativeMotion::NumMotions; ++motion_id) { | 
					
						
							| 
									
										
										
										
											2021-09-20 19:47:45 -05:00
										 |  |  |         const Common::ParamPackage param = emulated_controller->GetMotionParam(motion_id); | 
					
						
							|  |  |  |         motion_map[motion_id]->setText(ButtonToText(param)); | 
					
						
							| 
									
										
										
										
											2020-09-04 21:48:03 -05:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-22 10:39:53 -04:00
										 |  |  |     for (int analog_id = 0; analog_id < Settings::NativeAnalog::NumAnalogs; ++analog_id) { | 
					
						
							| 
									
										
										
										
											2021-09-20 19:47:45 -05:00
										 |  |  |         const Common::ParamPackage param = emulated_controller->GetStickParam(analog_id); | 
					
						
							| 
									
										
										
										
											2020-07-22 10:39:53 -04:00
										 |  |  |         for (int sub_button_id = 0; sub_button_id < ANALOG_SUB_BUTTONS_NUM; ++sub_button_id) { | 
					
						
							| 
									
										
										
										
											2019-05-19 12:08:48 -04:00
										 |  |  |             auto* const analog_button = analog_map_buttons[analog_id][sub_button_id]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             if (analog_button == nullptr) { | 
					
						
							|  |  |  |                 continue; | 
					
						
							| 
									
										
										
										
											2018-11-01 22:11:44 -04:00
										 |  |  |             } | 
					
						
							| 
									
										
										
										
											2019-05-19 12:08:48 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-20 19:47:45 -05:00
										 |  |  |             analog_button->setText(AnalogToText(param, analog_sub_buttons[sub_button_id])); | 
					
						
							| 
									
										
										
										
											2018-11-01 22:11:44 -04:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-01-03 08:54:57 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-20 14:23:25 -04:00
										 |  |  |         analog_map_modifier_button[analog_id]->setText( | 
					
						
							| 
									
										
										
										
											2021-09-20 19:47:45 -05:00
										 |  |  |             ButtonToText(Common::ParamPackage{param.Get("modifier", "")})); | 
					
						
							| 
									
										
										
										
											2020-09-01 10:02:18 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-22 10:39:53 -04:00
										 |  |  |         const auto deadzone_label = analog_map_deadzone_label[analog_id]; | 
					
						
							|  |  |  |         const auto deadzone_slider = analog_map_deadzone_slider[analog_id]; | 
					
						
							|  |  |  |         const auto modifier_groupbox = analog_map_modifier_groupbox[analog_id]; | 
					
						
							|  |  |  |         const auto modifier_label = analog_map_modifier_label[analog_id]; | 
					
						
							|  |  |  |         const auto modifier_slider = analog_map_modifier_slider[analog_id]; | 
					
						
							|  |  |  |         const auto range_groupbox = analog_map_range_groupbox[analog_id]; | 
					
						
							|  |  |  |         const auto range_spinbox = analog_map_range_spinbox[analog_id]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         int slider_value; | 
					
						
							| 
									
										
										
										
											2021-09-20 19:47:45 -05:00
										 |  |  |         const bool is_controller = input_subsystem->IsController(param); | 
					
						
							| 
									
										
										
										
											2020-07-22 10:39:53 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if (is_controller) { | 
					
						
							| 
									
										
										
										
											2021-09-20 19:47:45 -05:00
										 |  |  |             slider_value = static_cast<int>(param.Get("deadzone", 0.15f) * 100); | 
					
						
							| 
									
										
										
										
											2020-07-22 10:39:53 -04:00
										 |  |  |             deadzone_label->setText(tr("Deadzone: %1%").arg(slider_value)); | 
					
						
							|  |  |  |             deadzone_slider->setValue(slider_value); | 
					
						
							|  |  |  |             range_spinbox->setValue(static_cast<int>(param.Get("range", 1.0f) * 100)); | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             slider_value = static_cast<int>(param.Get("modifier_scale", 0.5f) * 100); | 
					
						
							|  |  |  |             modifier_label->setText(tr("Modifier Range: %1%").arg(slider_value)); | 
					
						
							|  |  |  |             modifier_slider->setValue(slider_value); | 
					
						
							| 
									
										
										
										
											2020-01-03 08:54:57 +01:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-07-22 10:39:53 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |         deadzone_label->setVisible(is_controller); | 
					
						
							|  |  |  |         deadzone_slider->setVisible(is_controller); | 
					
						
							|  |  |  |         modifier_groupbox->setVisible(!is_controller); | 
					
						
							|  |  |  |         modifier_label->setVisible(!is_controller); | 
					
						
							|  |  |  |         modifier_slider->setVisible(!is_controller); | 
					
						
							|  |  |  |         range_groupbox->setVisible(is_controller); | 
					
						
							| 
									
										
										
										
											2018-11-01 22:11:44 -04:00
										 |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-20 09:48:26 -05:00
										 |  |  | void ConfigureInputPlayer::SetConnectableControllers() { | 
					
						
							| 
									
										
										
										
											2022-01-01 20:44:28 -06:00
										 |  |  |     const auto npad_style_set = hid_core.GetSupportedStyleTag(); | 
					
						
							| 
									
										
										
										
											2021-12-04 19:37:03 -06:00
										 |  |  |     index_controller_type_pairs.clear(); | 
					
						
							|  |  |  |     ui->comboControllerType->clear(); | 
					
						
							| 
									
										
										
										
											2020-11-20 09:48:26 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-01 20:44:28 -06:00
										 |  |  |     const auto add_item = [&](Core::HID::NpadStyleIndex controller_type, | 
					
						
							|  |  |  |                               const QString& controller_name) { | 
					
						
							|  |  |  |         index_controller_type_pairs.emplace_back(ui->comboControllerType->count(), controller_type); | 
					
						
							|  |  |  |         ui->comboControllerType->addItem(controller_name); | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-04 19:37:03 -06:00
										 |  |  |     if (npad_style_set.fullkey == 1) { | 
					
						
							| 
									
										
										
										
											2022-01-01 20:44:28 -06:00
										 |  |  |         add_item(Core::HID::NpadStyleIndex::ProController, tr("Pro Controller")); | 
					
						
							| 
									
										
										
										
											2021-12-04 19:37:03 -06:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-11-20 09:48:26 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-04 19:37:03 -06:00
										 |  |  |     if (npad_style_set.joycon_dual == 1) { | 
					
						
							| 
									
										
										
										
											2022-01-01 20:44:28 -06:00
										 |  |  |         add_item(Core::HID::NpadStyleIndex::JoyconDual, tr("Dual Joycons")); | 
					
						
							| 
									
										
										
										
											2021-12-04 19:37:03 -06:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-11-20 09:48:26 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-04 19:37:03 -06:00
										 |  |  |     if (npad_style_set.joycon_left == 1) { | 
					
						
							| 
									
										
										
										
											2022-01-01 20:44:28 -06:00
										 |  |  |         add_item(Core::HID::NpadStyleIndex::JoyconLeft, tr("Left Joycon")); | 
					
						
							| 
									
										
										
										
											2021-12-04 19:37:03 -06:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-02-06 11:53:25 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-04 19:37:03 -06:00
										 |  |  |     if (npad_style_set.joycon_right == 1) { | 
					
						
							| 
									
										
										
										
											2022-01-01 20:44:28 -06:00
										 |  |  |         add_item(Core::HID::NpadStyleIndex::JoyconRight, tr("Right Joycon")); | 
					
						
							| 
									
										
										
										
											2021-12-04 19:37:03 -06:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-11-27 20:05:45 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-04 19:37:03 -06:00
										 |  |  |     if (player_index == 0 && npad_style_set.handheld == 1) { | 
					
						
							| 
									
										
										
										
											2022-01-01 20:44:28 -06:00
										 |  |  |         add_item(Core::HID::NpadStyleIndex::Handheld, tr("Handheld")); | 
					
						
							| 
									
										
										
										
											2021-12-04 19:37:03 -06:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-11-27 20:05:45 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-04 19:37:03 -06:00
										 |  |  |     if (npad_style_set.gamecube == 1) { | 
					
						
							| 
									
										
										
										
											2022-01-01 20:44:28 -06:00
										 |  |  |         add_item(Core::HID::NpadStyleIndex::GameCube, tr("GameCube Controller")); | 
					
						
							| 
									
										
										
										
											2021-12-04 19:37:03 -06:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-11-27 20:05:45 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-04 19:37:03 -06:00
										 |  |  |     // Disable all unsupported controllers
 | 
					
						
							|  |  |  |     if (!Settings::values.enable_all_controllers) { | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2022-01-01 20:44:28 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-04 19:37:03 -06:00
										 |  |  |     if (npad_style_set.palma == 1) { | 
					
						
							| 
									
										
										
										
											2022-01-01 20:44:28 -06:00
										 |  |  |         add_item(Core::HID::NpadStyleIndex::Pokeball, tr("Poke Ball Plus")); | 
					
						
							| 
									
										
										
										
											2021-12-04 19:37:03 -06:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-11-27 20:05:45 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-04 19:37:03 -06:00
										 |  |  |     if (npad_style_set.lark == 1) { | 
					
						
							| 
									
										
										
										
											2022-01-01 20:44:28 -06:00
										 |  |  |         add_item(Core::HID::NpadStyleIndex::NES, tr("NES Controller")); | 
					
						
							| 
									
										
										
										
											2021-12-04 19:37:03 -06:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-11-27 20:05:45 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-04 19:37:03 -06:00
										 |  |  |     if (npad_style_set.lucia == 1) { | 
					
						
							| 
									
										
										
										
											2022-01-01 20:44:28 -06:00
										 |  |  |         add_item(Core::HID::NpadStyleIndex::SNES, tr("SNES Controller")); | 
					
						
							| 
									
										
										
										
											2021-12-04 19:37:03 -06:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-11-20 09:48:26 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-04 19:37:03 -06:00
										 |  |  |     if (npad_style_set.lagoon == 1) { | 
					
						
							| 
									
										
										
										
											2022-01-01 20:44:28 -06:00
										 |  |  |         add_item(Core::HID::NpadStyleIndex::N64, tr("N64 Controller")); | 
					
						
							| 
									
										
										
										
											2020-11-20 09:48:26 -05:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-04 19:37:03 -06:00
										 |  |  |     if (npad_style_set.lager == 1) { | 
					
						
							| 
									
										
										
										
											2022-01-01 20:44:28 -06:00
										 |  |  |         add_item(Core::HID::NpadStyleIndex::SegaGenesis, tr("Sega Genesis")); | 
					
						
							| 
									
										
										
										
											2021-12-04 19:37:03 -06:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-11-20 09:48:26 -05:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-04 12:08:54 -06:00
										 |  |  | Core::HID::NpadStyleIndex ConfigureInputPlayer::GetControllerTypeFromIndex(int index) const { | 
					
						
							| 
									
										
										
										
											2020-11-20 09:48:26 -05:00
										 |  |  |     const auto it = | 
					
						
							|  |  |  |         std::find_if(index_controller_type_pairs.begin(), index_controller_type_pairs.end(), | 
					
						
							|  |  |  |                      [index](const auto& pair) { return pair.first == index; }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (it == index_controller_type_pairs.end()) { | 
					
						
							| 
									
										
										
										
											2021-11-04 12:08:54 -06:00
										 |  |  |         return Core::HID::NpadStyleIndex::ProController; | 
					
						
							| 
									
										
										
										
											2020-11-20 09:48:26 -05:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return it->second; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-04 12:08:54 -06:00
										 |  |  | int ConfigureInputPlayer::GetIndexFromControllerType(Core::HID::NpadStyleIndex type) const { | 
					
						
							| 
									
										
										
										
											2020-11-20 09:48:26 -05:00
										 |  |  |     const auto it = | 
					
						
							|  |  |  |         std::find_if(index_controller_type_pairs.begin(), index_controller_type_pairs.end(), | 
					
						
							|  |  |  |                      [type](const auto& pair) { return pair.second == type; }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (it == index_controller_type_pairs.end()) { | 
					
						
							|  |  |  |         return -1; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return it->first; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-17 12:00:29 -04:00
										 |  |  | void ConfigureInputPlayer::UpdateInputDevices() { | 
					
						
							|  |  |  |     input_devices = input_subsystem->GetInputDevices(); | 
					
						
							|  |  |  |     ui->comboDevices->clear(); | 
					
						
							| 
									
										
										
										
											2022-02-01 12:20:01 -05:00
										 |  |  |     for (const auto& device : input_devices) { | 
					
						
							| 
									
										
										
										
											2021-09-20 19:47:45 -05:00
										 |  |  |         ui->comboDevices->addItem(QString::fromStdString(device.Get("display", "Unknown")), {}); | 
					
						
							| 
									
										
										
										
											2018-11-01 22:11:44 -04:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-01-03 09:11:34 +01:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2020-07-22 10:39:53 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | void ConfigureInputPlayer::UpdateControllerAvailableButtons() { | 
					
						
							|  |  |  |     auto layout = GetControllerTypeFromIndex(ui->comboControllerType->currentIndex()); | 
					
						
							|  |  |  |     if (debug) { | 
					
						
							| 
									
										
										
										
											2021-11-04 12:08:54 -06:00
										 |  |  |         layout = Core::HID::NpadStyleIndex::ProController; | 
					
						
							| 
									
										
										
										
											2020-07-22 10:39:53 -04:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // List of all the widgets that will be hidden by any of the following layouts that need
 | 
					
						
							|  |  |  |     // "unhidden" after the controller type changes
 | 
					
						
							| 
									
										
										
										
											2021-02-06 11:53:25 -06:00
										 |  |  |     const std::array<QWidget*, 11> layout_show = { | 
					
						
							| 
									
										
										
										
											2020-07-22 10:39:53 -04:00
										 |  |  |         ui->buttonShoulderButtonsSLSR, | 
					
						
							|  |  |  |         ui->horizontalSpacerShoulderButtonsWidget, | 
					
						
							|  |  |  |         ui->horizontalSpacerShoulderButtonsWidget2, | 
					
						
							|  |  |  |         ui->buttonShoulderButtonsLeft, | 
					
						
							|  |  |  |         ui->buttonMiscButtonsMinusScreenshot, | 
					
						
							|  |  |  |         ui->bottomLeft, | 
					
						
							|  |  |  |         ui->buttonShoulderButtonsRight, | 
					
						
							|  |  |  |         ui->buttonMiscButtonsPlusHome, | 
					
						
							|  |  |  |         ui->bottomRight, | 
					
						
							| 
									
										
										
										
											2021-02-06 11:53:25 -06:00
										 |  |  |         ui->buttonMiscButtonsMinusGroup, | 
					
						
							|  |  |  |         ui->buttonMiscButtonsScreenshotGroup, | 
					
						
							| 
									
										
										
										
											2020-07-22 10:39:53 -04:00
										 |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     for (auto* widget : layout_show) { | 
					
						
							|  |  |  |         widget->show(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     std::vector<QWidget*> layout_hidden; | 
					
						
							|  |  |  |     switch (layout) { | 
					
						
							| 
									
										
										
										
											2021-11-04 12:08:54 -06:00
										 |  |  |     case Core::HID::NpadStyleIndex::ProController: | 
					
						
							|  |  |  |     case Core::HID::NpadStyleIndex::JoyconDual: | 
					
						
							|  |  |  |     case Core::HID::NpadStyleIndex::Handheld: | 
					
						
							| 
									
										
										
										
											2020-07-22 10:39:53 -04:00
										 |  |  |         layout_hidden = { | 
					
						
							|  |  |  |             ui->buttonShoulderButtonsSLSR, | 
					
						
							|  |  |  |             ui->horizontalSpacerShoulderButtonsWidget2, | 
					
						
							|  |  |  |         }; | 
					
						
							|  |  |  |         break; | 
					
						
							| 
									
										
										
										
											2021-11-04 12:08:54 -06:00
										 |  |  |     case Core::HID::NpadStyleIndex::JoyconLeft: | 
					
						
							| 
									
										
										
										
											2020-07-22 10:39:53 -04:00
										 |  |  |         layout_hidden = { | 
					
						
							|  |  |  |             ui->horizontalSpacerShoulderButtonsWidget2, | 
					
						
							|  |  |  |             ui->buttonShoulderButtonsRight, | 
					
						
							|  |  |  |             ui->buttonMiscButtonsPlusHome, | 
					
						
							|  |  |  |             ui->bottomRight, | 
					
						
							|  |  |  |         }; | 
					
						
							|  |  |  |         break; | 
					
						
							| 
									
										
										
										
											2021-11-04 12:08:54 -06:00
										 |  |  |     case Core::HID::NpadStyleIndex::JoyconRight: | 
					
						
							| 
									
										
										
										
											2020-07-22 10:39:53 -04:00
										 |  |  |         layout_hidden = { | 
					
						
							|  |  |  |             ui->horizontalSpacerShoulderButtonsWidget, | 
					
						
							|  |  |  |             ui->buttonShoulderButtonsLeft, | 
					
						
							|  |  |  |             ui->buttonMiscButtonsMinusScreenshot, | 
					
						
							|  |  |  |             ui->bottomLeft, | 
					
						
							|  |  |  |         }; | 
					
						
							|  |  |  |         break; | 
					
						
							| 
									
										
										
										
											2021-11-04 12:08:54 -06:00
										 |  |  |     case Core::HID::NpadStyleIndex::GameCube: | 
					
						
							| 
									
										
										
										
											2021-02-06 11:53:25 -06:00
										 |  |  |         layout_hidden = { | 
					
						
							|  |  |  |             ui->buttonShoulderButtonsSLSR, | 
					
						
							|  |  |  |             ui->horizontalSpacerShoulderButtonsWidget2, | 
					
						
							|  |  |  |             ui->buttonMiscButtonsMinusGroup, | 
					
						
							|  |  |  |             ui->buttonMiscButtonsScreenshotGroup, | 
					
						
							|  |  |  |         }; | 
					
						
							|  |  |  |         break; | 
					
						
							| 
									
										
										
										
											2021-09-20 19:47:45 -05:00
										 |  |  |     default: | 
					
						
							|  |  |  |         break; | 
					
						
							| 
									
										
										
										
											2020-07-22 10:39:53 -04:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     for (auto* widget : layout_hidden) { | 
					
						
							|  |  |  |         widget->hide(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-06 11:53:25 -06:00
										 |  |  | void ConfigureInputPlayer::UpdateControllerEnabledButtons() { | 
					
						
							|  |  |  |     auto layout = GetControllerTypeFromIndex(ui->comboControllerType->currentIndex()); | 
					
						
							|  |  |  |     if (debug) { | 
					
						
							| 
									
										
										
										
											2021-11-04 12:08:54 -06:00
										 |  |  |         layout = Core::HID::NpadStyleIndex::ProController; | 
					
						
							| 
									
										
										
										
											2021-02-06 11:53:25 -06:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // List of all the widgets that will be disabled by any of the following layouts that need
 | 
					
						
							|  |  |  |     // "enabled" after the controller type changes
 | 
					
						
							| 
									
										
										
										
											2021-09-20 19:47:45 -05:00
										 |  |  |     const std::array<QWidget*, 3> layout_enable = { | 
					
						
							| 
									
										
										
										
											2021-02-06 11:53:25 -06:00
										 |  |  |         ui->buttonLStickPressedGroup, | 
					
						
							|  |  |  |         ui->groupRStickPressed, | 
					
						
							|  |  |  |         ui->buttonShoulderButtonsButtonLGroup, | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     for (auto* widget : layout_enable) { | 
					
						
							|  |  |  |         widget->setEnabled(true); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     std::vector<QWidget*> layout_disable; | 
					
						
							|  |  |  |     switch (layout) { | 
					
						
							| 
									
										
										
										
											2021-11-04 12:08:54 -06:00
										 |  |  |     case Core::HID::NpadStyleIndex::ProController: | 
					
						
							|  |  |  |     case Core::HID::NpadStyleIndex::JoyconDual: | 
					
						
							|  |  |  |     case Core::HID::NpadStyleIndex::Handheld: | 
					
						
							|  |  |  |     case Core::HID::NpadStyleIndex::JoyconLeft: | 
					
						
							|  |  |  |     case Core::HID::NpadStyleIndex::JoyconRight: | 
					
						
							| 
									
										
										
										
											2021-02-06 11:53:25 -06:00
										 |  |  |         break; | 
					
						
							| 
									
										
										
										
											2021-11-04 12:08:54 -06:00
										 |  |  |     case Core::HID::NpadStyleIndex::GameCube: | 
					
						
							| 
									
										
										
										
											2021-02-06 11:53:25 -06:00
										 |  |  |         layout_disable = { | 
					
						
							|  |  |  |             ui->buttonHome, | 
					
						
							|  |  |  |             ui->buttonLStickPressedGroup, | 
					
						
							|  |  |  |             ui->groupRStickPressed, | 
					
						
							|  |  |  |             ui->buttonShoulderButtonsButtonLGroup, | 
					
						
							|  |  |  |         }; | 
					
						
							|  |  |  |         break; | 
					
						
							| 
									
										
										
										
											2021-09-20 19:47:45 -05:00
										 |  |  |     default: | 
					
						
							|  |  |  |         break; | 
					
						
							| 
									
										
										
										
											2021-02-06 11:53:25 -06:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     for (auto* widget : layout_disable) { | 
					
						
							|  |  |  |         widget->setEnabled(false); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-02 12:33:37 -04:00
										 |  |  | void ConfigureInputPlayer::UpdateMotionButtons() { | 
					
						
							|  |  |  |     if (debug) { | 
					
						
							|  |  |  |         // Motion isn't used with the debug controller, hide both groupboxes.
 | 
					
						
							|  |  |  |         ui->buttonMotionLeftGroup->hide(); | 
					
						
							|  |  |  |         ui->buttonMotionRightGroup->hide(); | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // Show/hide the "Motion 1/2" groupboxes depending on the currently selected controller.
 | 
					
						
							|  |  |  |     switch (GetControllerTypeFromIndex(ui->comboControllerType->currentIndex())) { | 
					
						
							| 
									
										
										
										
											2021-11-04 12:08:54 -06:00
										 |  |  |     case Core::HID::NpadStyleIndex::ProController: | 
					
						
							|  |  |  |     case Core::HID::NpadStyleIndex::JoyconLeft: | 
					
						
							|  |  |  |     case Core::HID::NpadStyleIndex::Handheld: | 
					
						
							| 
									
										
										
										
											2020-09-02 12:33:37 -04:00
										 |  |  |         // Show "Motion 1" and hide "Motion 2".
 | 
					
						
							|  |  |  |         ui->buttonMotionLeftGroup->show(); | 
					
						
							|  |  |  |         ui->buttonMotionRightGroup->hide(); | 
					
						
							|  |  |  |         break; | 
					
						
							| 
									
										
										
										
											2021-11-04 12:08:54 -06:00
										 |  |  |     case Core::HID::NpadStyleIndex::JoyconRight: | 
					
						
							| 
									
										
										
										
											2020-09-02 12:33:37 -04:00
										 |  |  |         // Show "Motion 2" and hide "Motion 1".
 | 
					
						
							|  |  |  |         ui->buttonMotionLeftGroup->hide(); | 
					
						
							|  |  |  |         ui->buttonMotionRightGroup->show(); | 
					
						
							|  |  |  |         break; | 
					
						
							| 
									
										
										
										
											2021-11-04 12:08:54 -06:00
										 |  |  |     case Core::HID::NpadStyleIndex::GameCube: | 
					
						
							| 
									
										
										
										
											2021-02-06 11:53:25 -06:00
										 |  |  |         // Hide both "Motion 1/2".
 | 
					
						
							|  |  |  |         ui->buttonMotionLeftGroup->hide(); | 
					
						
							|  |  |  |         ui->buttonMotionRightGroup->hide(); | 
					
						
							|  |  |  |         break; | 
					
						
							| 
									
										
										
										
											2021-11-04 12:08:54 -06:00
										 |  |  |     case Core::HID::NpadStyleIndex::JoyconDual: | 
					
						
							| 
									
										
										
										
											2020-09-02 12:33:37 -04:00
										 |  |  |     default: | 
					
						
							|  |  |  |         // Show both "Motion 1/2".
 | 
					
						
							|  |  |  |         ui->buttonMotionLeftGroup->show(); | 
					
						
							|  |  |  |         ui->buttonMotionRightGroup->show(); | 
					
						
							|  |  |  |         break; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-02-06 11:53:25 -06:00
										 |  |  | void ConfigureInputPlayer::UpdateControllerButtonNames() { | 
					
						
							|  |  |  |     auto layout = GetControllerTypeFromIndex(ui->comboControllerType->currentIndex()); | 
					
						
							|  |  |  |     if (debug) { | 
					
						
							| 
									
										
										
										
											2021-11-04 12:08:54 -06:00
										 |  |  |         layout = Core::HID::NpadStyleIndex::ProController; | 
					
						
							| 
									
										
										
										
											2021-02-06 11:53:25 -06:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     switch (layout) { | 
					
						
							| 
									
										
										
										
											2021-11-04 12:08:54 -06:00
										 |  |  |     case Core::HID::NpadStyleIndex::ProController: | 
					
						
							|  |  |  |     case Core::HID::NpadStyleIndex::JoyconDual: | 
					
						
							|  |  |  |     case Core::HID::NpadStyleIndex::Handheld: | 
					
						
							|  |  |  |     case Core::HID::NpadStyleIndex::JoyconLeft: | 
					
						
							|  |  |  |     case Core::HID::NpadStyleIndex::JoyconRight: | 
					
						
							| 
									
										
										
										
											2021-02-06 11:53:25 -06:00
										 |  |  |         ui->buttonMiscButtonsPlusGroup->setTitle(tr("Plus")); | 
					
						
							|  |  |  |         ui->buttonShoulderButtonsButtonZLGroup->setTitle(tr("ZL")); | 
					
						
							|  |  |  |         ui->buttonShoulderButtonsZRGroup->setTitle(tr("ZR")); | 
					
						
							|  |  |  |         ui->buttonShoulderButtonsRGroup->setTitle(tr("R")); | 
					
						
							|  |  |  |         ui->LStick->setTitle(tr("Left Stick")); | 
					
						
							|  |  |  |         ui->RStick->setTitle(tr("Right Stick")); | 
					
						
							|  |  |  |         break; | 
					
						
							| 
									
										
										
										
											2021-11-04 12:08:54 -06:00
										 |  |  |     case Core::HID::NpadStyleIndex::GameCube: | 
					
						
							| 
									
										
										
										
											2021-02-06 11:53:25 -06:00
										 |  |  |         ui->buttonMiscButtonsPlusGroup->setTitle(tr("Start / Pause")); | 
					
						
							|  |  |  |         ui->buttonShoulderButtonsButtonZLGroup->setTitle(tr("L")); | 
					
						
							|  |  |  |         ui->buttonShoulderButtonsZRGroup->setTitle(tr("R")); | 
					
						
							|  |  |  |         ui->buttonShoulderButtonsRGroup->setTitle(tr("Z")); | 
					
						
							|  |  |  |         ui->LStick->setTitle(tr("Control Stick")); | 
					
						
							|  |  |  |         ui->RStick->setTitle(tr("C-Stick")); | 
					
						
							|  |  |  |         break; | 
					
						
							| 
									
										
										
										
											2021-09-20 19:47:45 -05:00
										 |  |  |     default: | 
					
						
							|  |  |  |         break; | 
					
						
							| 
									
										
										
										
											2021-02-06 11:53:25 -06:00
										 |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-17 12:00:29 -04:00
										 |  |  | void ConfigureInputPlayer::UpdateMappingWithDefaults() { | 
					
						
							| 
									
										
										
										
											2020-09-28 10:27:29 -04:00
										 |  |  |     if (ui->comboDevices->currentIndex() == 0) { | 
					
						
							| 
									
										
										
										
											2020-07-22 10:39:53 -04:00
										 |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-09-28 10:27:29 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-20 19:47:45 -05:00
										 |  |  |     for (int button_id = 0; button_id < Settings::NativeButton::NumButtons; ++button_id) { | 
					
						
							|  |  |  |         const auto* const button = button_map[button_id]; | 
					
						
							|  |  |  |         if (button == nullptr) { | 
					
						
							|  |  |  |             continue; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         emulated_controller->SetButtonParam(button_id, {}); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     for (int analog_id = 0; analog_id < Settings::NativeAnalog::NumAnalogs; ++analog_id) { | 
					
						
							|  |  |  |         for (int sub_button_id = 0; sub_button_id < ANALOG_SUB_BUTTONS_NUM; ++sub_button_id) { | 
					
						
							|  |  |  |             const auto* const analog_button = analog_map_buttons[analog_id][sub_button_id]; | 
					
						
							|  |  |  |             if (analog_button == nullptr) { | 
					
						
							|  |  |  |                 continue; | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |             emulated_controller->SetStickParam(analog_id, {}); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     for (int motion_id = 0; motion_id < Settings::NativeMotion::NumMotions; ++motion_id) { | 
					
						
							|  |  |  |         const auto* const motion_button = motion_map[motion_id]; | 
					
						
							|  |  |  |         if (motion_button == nullptr) { | 
					
						
							|  |  |  |             continue; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         emulated_controller->SetMotionParam(motion_id, {}); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-24 11:22:20 -05:00
										 |  |  |     // Reset keyboard or mouse bindings
 | 
					
						
							|  |  |  |     if (ui->comboDevices->currentIndex() == 1 || ui->comboDevices->currentIndex() == 2) { | 
					
						
							| 
									
										
										
										
											2020-09-28 10:27:29 -04:00
										 |  |  |         for (int button_id = 0; button_id < Settings::NativeButton::NumButtons; ++button_id) { | 
					
						
							| 
									
										
										
										
											2021-09-20 19:47:45 -05:00
										 |  |  |             emulated_controller->SetButtonParam( | 
					
						
							|  |  |  |                 button_id, Common::ParamPackage{InputCommon::GenerateKeyboardParam( | 
					
						
							|  |  |  |                                Config::default_buttons[button_id])}); | 
					
						
							| 
									
										
										
										
											2020-09-28 10:27:29 -04:00
										 |  |  |         } | 
					
						
							|  |  |  |         for (int analog_id = 0; analog_id < Settings::NativeAnalog::NumAnalogs; ++analog_id) { | 
					
						
							| 
									
										
										
										
											2021-09-20 19:47:45 -05:00
										 |  |  |             Common::ParamPackage analog_param{}; | 
					
						
							| 
									
										
										
										
											2020-09-28 10:27:29 -04:00
										 |  |  |             for (int sub_button_id = 0; sub_button_id < ANALOG_SUB_BUTTONS_NUM; ++sub_button_id) { | 
					
						
							|  |  |  |                 Common::ParamPackage params{InputCommon::GenerateKeyboardParam( | 
					
						
							|  |  |  |                     Config::default_analogs[analog_id][sub_button_id])}; | 
					
						
							| 
									
										
										
										
											2021-09-20 19:47:45 -05:00
										 |  |  |                 SetAnalogParam(params, analog_param, analog_sub_buttons[sub_button_id]); | 
					
						
							| 
									
										
										
										
											2020-09-28 10:27:29 -04:00
										 |  |  |             } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-20 19:47:45 -05:00
										 |  |  |             analog_param.Set("modifier", InputCommon::GenerateKeyboardParam( | 
					
						
							|  |  |  |                                              Config::default_stick_mod[analog_id])); | 
					
						
							|  |  |  |             emulated_controller->SetStickParam(analog_id, analog_param); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         for (int motion_id = 0; motion_id < Settings::NativeMotion::NumMotions; ++motion_id) { | 
					
						
							|  |  |  |             emulated_controller->SetMotionParam( | 
					
						
							|  |  |  |                 motion_id, Common::ParamPackage{InputCommon::GenerateKeyboardParam( | 
					
						
							|  |  |  |                                Config::default_motions[motion_id])}); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-24 11:22:20 -05:00
										 |  |  |         // If mouse is selected we want to override with mappings from the driver
 | 
					
						
							|  |  |  |         if (ui->comboDevices->currentIndex() == 1) { | 
					
						
							|  |  |  |             UpdateUI(); | 
					
						
							|  |  |  |             return; | 
					
						
							| 
									
										
										
										
											2020-09-28 10:27:29 -04:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // Reset controller bindings
 | 
					
						
							| 
									
										
										
										
											2020-09-17 12:00:29 -04:00
										 |  |  |     const auto& device = input_devices[ui->comboDevices->currentIndex()]; | 
					
						
							| 
									
										
										
										
											2021-10-24 11:22:20 -05:00
										 |  |  |     auto button_mappings = input_subsystem->GetButtonMappingForDevice(device); | 
					
						
							|  |  |  |     auto analog_mappings = input_subsystem->GetAnalogMappingForDevice(device); | 
					
						
							|  |  |  |     auto motion_mappings = input_subsystem->GetMotionMappingForDevice(device); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     for (const auto& button_mapping : button_mappings) { | 
					
						
							|  |  |  |         const std::size_t index = button_mapping.first; | 
					
						
							|  |  |  |         emulated_controller->SetButtonParam(index, button_mapping.second); | 
					
						
							| 
									
										
										
										
											2020-09-17 12:00:29 -04:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-10-24 11:22:20 -05:00
										 |  |  |     for (const auto& analog_mapping : analog_mappings) { | 
					
						
							|  |  |  |         const std::size_t index = analog_mapping.first; | 
					
						
							|  |  |  |         emulated_controller->SetStickParam(index, analog_mapping.second); | 
					
						
							| 
									
										
										
										
											2020-09-17 12:00:29 -04:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2021-10-24 11:22:20 -05:00
										 |  |  |     for (const auto& motion_mapping : motion_mappings) { | 
					
						
							|  |  |  |         const std::size_t index = motion_mapping.first; | 
					
						
							|  |  |  |         emulated_controller->SetMotionParam(index, motion_mapping.second); | 
					
						
							| 
									
										
										
										
											2021-04-25 18:03:57 -05:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-09-17 12:00:29 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |     UpdateUI(); | 
					
						
							| 
									
										
										
										
											2020-07-22 10:39:53 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-17 12:00:29 -04:00
										 |  |  | void ConfigureInputPlayer::HandleClick( | 
					
						
							| 
									
										
										
										
											2021-01-12 21:09:59 -06:00
										 |  |  |     QPushButton* button, std::size_t button_id, | 
					
						
							|  |  |  |     std::function<void(const Common::ParamPackage&)> new_input_setter, | 
					
						
							| 
									
										
										
										
											2021-09-20 19:47:45 -05:00
										 |  |  |     InputCommon::Polling::InputType type) { | 
					
						
							| 
									
										
										
										
											2020-09-17 12:00:29 -04:00
										 |  |  |     if (button == ui->buttonMotionLeft || button == ui->buttonMotionRight) { | 
					
						
							|  |  |  |         button->setText(tr("Shake!")); | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |         button->setText(tr("[waiting]")); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     button->setFocus(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     input_setter = new_input_setter; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-20 19:47:45 -05:00
										 |  |  |     input_subsystem->BeginMapping(type); | 
					
						
							| 
									
										
										
										
											2020-09-17 12:00:29 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |     QWidget::grabMouse(); | 
					
						
							|  |  |  |     QWidget::grabKeyboard(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-20 19:47:45 -05:00
										 |  |  |     if (type == InputCommon::Polling::InputType::Button) { | 
					
						
							| 
									
										
										
										
											2021-01-12 21:09:59 -06:00
										 |  |  |         ui->controllerFrame->BeginMappingButton(button_id); | 
					
						
							| 
									
										
										
										
											2021-09-20 19:47:45 -05:00
										 |  |  |     } else if (type == InputCommon::Polling::InputType::Stick) { | 
					
						
							| 
									
										
										
										
											2021-01-12 21:09:59 -06:00
										 |  |  |         ui->controllerFrame->BeginMappingAnalog(button_id); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-17 12:00:29 -04:00
										 |  |  |     timeout_timer->start(2500); // Cancel after 2.5 seconds
 | 
					
						
							| 
									
										
										
										
											2021-10-25 12:53:14 -05:00
										 |  |  |     poll_timer->start(25);      // Check for new inputs every 25ms
 | 
					
						
							| 
									
										
										
										
											2020-09-17 12:00:29 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ConfigureInputPlayer::SetPollingResult(const Common::ParamPackage& params, bool abort) { | 
					
						
							|  |  |  |     timeout_timer->stop(); | 
					
						
							|  |  |  |     poll_timer->stop(); | 
					
						
							| 
									
										
										
										
											2021-09-20 19:47:45 -05:00
										 |  |  |     input_subsystem->StopMapping(); | 
					
						
							| 
									
										
										
										
											2020-09-17 12:00:29 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |     QWidget::releaseMouse(); | 
					
						
							|  |  |  |     QWidget::releaseKeyboard(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (!abort) { | 
					
						
							|  |  |  |         (*input_setter)(params); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     UpdateUI(); | 
					
						
							|  |  |  |     UpdateInputDeviceCombobox(); | 
					
						
							| 
									
										
										
										
											2021-01-12 21:09:59 -06:00
										 |  |  |     ui->controllerFrame->EndMapping(); | 
					
						
							| 
									
										
										
										
											2020-09-17 12:00:29 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |     input_setter = std::nullopt; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool ConfigureInputPlayer::IsInputAcceptable(const Common::ParamPackage& params) const { | 
					
						
							|  |  |  |     if (ui->comboDevices->currentIndex() == 0) { | 
					
						
							|  |  |  |         return true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-25 12:53:14 -05:00
										 |  |  |     if (params.Has("motion")) { | 
					
						
							|  |  |  |         return true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-11 07:46:41 -05:00
										 |  |  |     // Keyboard/Mouse
 | 
					
						
							| 
									
										
										
										
											2021-10-24 11:22:20 -05:00
										 |  |  |     if (ui->comboDevices->currentIndex() == 1 || ui->comboDevices->currentIndex() == 2) { | 
					
						
							| 
									
										
										
										
											2020-11-11 07:46:41 -05:00
										 |  |  |         return params.Get("engine", "") == "keyboard" || params.Get("engine", "") == "mouse"; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-01 12:20:01 -05:00
										 |  |  |     const auto& current_input_device = input_devices[ui->comboDevices->currentIndex()]; | 
					
						
							| 
									
										
										
										
											2021-09-20 19:47:45 -05:00
										 |  |  |     return params.Get("engine", "") == current_input_device.Get("engine", "") && | 
					
						
							|  |  |  |            (params.Get("guid", "") == current_input_device.Get("guid", "") || | 
					
						
							|  |  |  |             params.Get("guid", "") == current_input_device.Get("guid2", "")) && | 
					
						
							| 
									
										
										
										
											2021-10-24 11:22:20 -05:00
										 |  |  |            params.Get("port", 0) == current_input_device.Get("port", 0); | 
					
						
							| 
									
										
										
										
											2020-09-17 12:00:29 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ConfigureInputPlayer::mousePressEvent(QMouseEvent* event) { | 
					
						
							|  |  |  |     if (!input_setter || !event) { | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-20 19:47:45 -05:00
										 |  |  |     const auto button = GRenderWindow::QtButtonToMouseButton(event->button()); | 
					
						
							|  |  |  |     input_subsystem->GetMouse()->PressButton(0, 0, 0, 0, button); | 
					
						
							| 
									
										
										
										
											2020-09-17 12:00:29 -04:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ConfigureInputPlayer::keyPressEvent(QKeyEvent* event) { | 
					
						
							| 
									
										
										
										
											2021-09-20 19:47:45 -05:00
										 |  |  |     event->ignore(); | 
					
						
							| 
									
										
										
										
											2020-09-17 12:00:29 -04:00
										 |  |  |     if (!input_setter || !event) { | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if (event->key() != Qt::Key_Escape) { | 
					
						
							| 
									
										
										
										
											2021-09-20 19:47:45 -05:00
										 |  |  |         input_subsystem->GetKeyboard()->PressKey(event->key()); | 
					
						
							| 
									
										
										
										
											2020-09-17 12:00:29 -04:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-07-22 10:39:53 -04:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2020-09-23 09:52:25 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | void ConfigureInputPlayer::CreateProfile() { | 
					
						
							|  |  |  |     const auto profile_name = | 
					
						
							| 
									
										
										
										
											2021-06-04 12:24:18 +02:00
										 |  |  |         LimitableInputDialog::GetText(this, tr("New Profile"), tr("Enter a profile name:"), 1, 20, | 
					
						
							|  |  |  |                                       LimitableInputDialog::InputLimiter::Filesystem); | 
					
						
							| 
									
										
										
										
											2020-09-23 09:52:25 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (profile_name.isEmpty()) { | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-17 23:12:42 -05:00
										 |  |  |     if (!InputProfiles::IsProfileNameValid(profile_name.toStdString())) { | 
					
						
							| 
									
										
										
										
											2020-09-23 09:52:25 -04:00
										 |  |  |         QMessageBox::critical(this, tr("Create Input Profile"), | 
					
						
							|  |  |  |                               tr("The given profile name is not valid!")); | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ApplyConfiguration(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (!profiles->CreateProfile(profile_name.toStdString(), player_index)) { | 
					
						
							|  |  |  |         QMessageBox::critical(this, tr("Create Input Profile"), | 
					
						
							|  |  |  |                               tr("Failed to create the input profile \"%1\"").arg(profile_name)); | 
					
						
							| 
									
										
										
										
											2020-10-29 12:15:35 -04:00
										 |  |  |         UpdateInputProfiles(); | 
					
						
							|  |  |  |         emit RefreshInputProfiles(player_index); | 
					
						
							| 
									
										
										
										
											2020-09-23 09:52:25 -04:00
										 |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-29 12:15:35 -04:00
										 |  |  |     emit RefreshInputProfiles(player_index); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-23 09:52:25 -04:00
										 |  |  |     ui->comboProfiles->addItem(profile_name); | 
					
						
							|  |  |  |     ui->comboProfiles->setCurrentIndex(ui->comboProfiles->count() - 1); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ConfigureInputPlayer::DeleteProfile() { | 
					
						
							|  |  |  |     const QString profile_name = ui->comboProfiles->itemText(ui->comboProfiles->currentIndex()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (profile_name.isEmpty()) { | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (!profiles->DeleteProfile(profile_name.toStdString())) { | 
					
						
							|  |  |  |         QMessageBox::critical(this, tr("Delete Input Profile"), | 
					
						
							|  |  |  |                               tr("Failed to delete the input profile \"%1\"").arg(profile_name)); | 
					
						
							| 
									
										
										
										
											2020-10-29 12:15:35 -04:00
										 |  |  |         UpdateInputProfiles(); | 
					
						
							|  |  |  |         emit RefreshInputProfiles(player_index); | 
					
						
							| 
									
										
										
										
											2020-09-23 09:52:25 -04:00
										 |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-29 12:15:35 -04:00
										 |  |  |     emit RefreshInputProfiles(player_index); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-23 09:52:25 -04:00
										 |  |  |     ui->comboProfiles->removeItem(ui->comboProfiles->currentIndex()); | 
					
						
							|  |  |  |     ui->comboProfiles->setCurrentIndex(-1); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ConfigureInputPlayer::LoadProfile() { | 
					
						
							|  |  |  |     const QString profile_name = ui->comboProfiles->itemText(ui->comboProfiles->currentIndex()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (profile_name.isEmpty()) { | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ApplyConfiguration(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (!profiles->LoadProfile(profile_name.toStdString(), player_index)) { | 
					
						
							|  |  |  |         QMessageBox::critical(this, tr("Load Input Profile"), | 
					
						
							|  |  |  |                               tr("Failed to load the input profile \"%1\"").arg(profile_name)); | 
					
						
							| 
									
										
										
										
											2020-10-29 12:15:35 -04:00
										 |  |  |         UpdateInputProfiles(); | 
					
						
							|  |  |  |         emit RefreshInputProfiles(player_index); | 
					
						
							| 
									
										
										
										
											2020-09-23 09:52:25 -04:00
										 |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     LoadConfiguration(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ConfigureInputPlayer::SaveProfile() { | 
					
						
							|  |  |  |     const QString profile_name = ui->comboProfiles->itemText(ui->comboProfiles->currentIndex()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (profile_name.isEmpty()) { | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ApplyConfiguration(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (!profiles->SaveProfile(profile_name.toStdString(), player_index)) { | 
					
						
							|  |  |  |         QMessageBox::critical(this, tr("Save Input Profile"), | 
					
						
							|  |  |  |                               tr("Failed to save the input profile \"%1\"").arg(profile_name)); | 
					
						
							| 
									
										
										
										
											2020-10-29 12:15:35 -04:00
										 |  |  |         UpdateInputProfiles(); | 
					
						
							|  |  |  |         emit RefreshInputProfiles(player_index); | 
					
						
							| 
									
										
										
										
											2020-09-23 09:52:25 -04:00
										 |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-29 12:15:35 -04:00
										 |  |  | void ConfigureInputPlayer::UpdateInputProfiles() { | 
					
						
							| 
									
										
										
										
											2020-09-23 09:52:25 -04:00
										 |  |  |     ui->comboProfiles->clear(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     for (const auto& profile_name : profiles->GetInputProfileNames()) { | 
					
						
							|  |  |  |         ui->comboProfiles->addItem(QString::fromStdString(profile_name)); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ui->comboProfiles->setCurrentIndex(-1); | 
					
						
							|  |  |  | } |