diff options
| author | 2018-11-27 18:38:12 -0500 | |
|---|---|---|
| committer | 2018-11-27 18:38:12 -0500 | |
| commit | e89a3b9e59ec6daebaf4ce112eaa2d5761bcdd42 (patch) | |
| tree | 2b10a5e3cf0eacdb86fa3d11a06353f1abe61ad0 | |
| parent | Merge pull request #1815 from DarkLordZach/npad-pos-fix (diff) | |
| parent | yuzu/configure_input_player: Use std::size_t to represent the player index in... (diff) | |
| download | yuzu-e89a3b9e59ec6daebaf4ce112eaa2d5761bcdd42.tar.gz yuzu-e89a3b9e59ec6daebaf4ce112eaa2d5761bcdd42.tar.xz yuzu-e89a3b9e59ec6daebaf4ce112eaa2d5761bcdd42.zip | |
Merge pull request #1811 from lioncash/input
yuzu/input: Minor changes
| -rw-r--r-- | src/yuzu/configuration/configure_input.cpp | 44 | ||||
| -rw-r--r-- | src/yuzu/configuration/configure_input.h | 11 | ||||
| -rw-r--r-- | src/yuzu/configuration/configure_input_player.cpp | 18 | ||||
| -rw-r--r-- | src/yuzu/configuration/configure_input_player.h | 53 | ||||
| -rw-r--r-- | src/yuzu/configuration/configure_mouse_advanced.cpp | 4 | ||||
| -rw-r--r-- | src/yuzu/configuration/configure_mouse_advanced.h | 36 |
6 files changed, 72 insertions, 94 deletions
diff --git a/src/yuzu/configuration/configure_input.cpp b/src/yuzu/configuration/configure_input.cpp index 7ee572761..ec46dc4e3 100644 --- a/src/yuzu/configuration/configure_input.cpp +++ b/src/yuzu/configuration/configure_input.cpp | |||
| @@ -4,11 +4,9 @@ | |||
| 4 | 4 | ||
| 5 | #include <algorithm> | 5 | #include <algorithm> |
| 6 | #include <memory> | 6 | #include <memory> |
| 7 | #include <utility> | 7 | |
| 8 | #include <QMenu> | ||
| 9 | #include <QMessageBox> | ||
| 10 | #include <QTimer> | 8 | #include <QTimer> |
| 11 | #include "common/param_package.h" | 9 | |
| 12 | #include "configuration/configure_touchscreen_advanced.h" | 10 | #include "configuration/configure_touchscreen_advanced.h" |
| 13 | #include "core/core.h" | 11 | #include "core/core.h" |
| 14 | #include "core/hle/service/am/am.h" | 12 | #include "core/hle/service/am/am.h" |
| @@ -16,16 +14,25 @@ | |||
| 16 | #include "core/hle/service/am/applet_oe.h" | 14 | #include "core/hle/service/am/applet_oe.h" |
| 17 | #include "core/hle/service/hid/controllers/npad.h" | 15 | #include "core/hle/service/hid/controllers/npad.h" |
| 18 | #include "core/hle/service/sm/sm.h" | 16 | #include "core/hle/service/sm/sm.h" |
| 19 | #include "input_common/main.h" | ||
| 20 | #include "ui_configure_input.h" | 17 | #include "ui_configure_input.h" |
| 21 | #include "ui_configure_input_player.h" | 18 | #include "ui_configure_input_player.h" |
| 22 | #include "ui_configure_mouse_advanced.h" | ||
| 23 | #include "ui_configure_touchscreen_advanced.h" | ||
| 24 | #include "yuzu/configuration/config.h" | ||
| 25 | #include "yuzu/configuration/configure_input.h" | 19 | #include "yuzu/configuration/configure_input.h" |
| 26 | #include "yuzu/configuration/configure_input_player.h" | 20 | #include "yuzu/configuration/configure_input_player.h" |
| 27 | #include "yuzu/configuration/configure_mouse_advanced.h" | 21 | #include "yuzu/configuration/configure_mouse_advanced.h" |
| 28 | 22 | ||
| 23 | namespace { | ||
| 24 | template <typename Dialog, typename... Args> | ||
| 25 | void CallConfigureDialog(ConfigureInput& parent, Args&&... args) { | ||
| 26 | parent.applyConfiguration(); | ||
| 27 | Dialog dialog(&parent, std::forward<Args>(args)...); | ||
| 28 | |||
| 29 | const auto res = dialog.exec(); | ||
| 30 | if (res == QDialog::Accepted) { | ||
| 31 | dialog.applyConfiguration(); | ||
| 32 | } | ||
| 33 | } | ||
| 34 | } // Anonymous namespace | ||
| 35 | |||
| 29 | ConfigureInput::ConfigureInput(QWidget* parent) | 36 | ConfigureInput::ConfigureInput(QWidget* parent) |
| 30 | : QWidget(parent), ui(std::make_unique<Ui::ConfigureInput>()) { | 37 | : QWidget(parent), ui(std::make_unique<Ui::ConfigureInput>()) { |
| 31 | ui->setupUi(this); | 38 | ui->setupUi(this); |
| @@ -65,31 +72,20 @@ ConfigureInput::ConfigureInput(QWidget* parent) | |||
| 65 | 72 | ||
| 66 | for (std::size_t i = 0; i < players_configure.size(); ++i) { | 73 | for (std::size_t i = 0; i < players_configure.size(); ++i) { |
| 67 | connect(players_configure[i], &QPushButton::pressed, this, | 74 | connect(players_configure[i], &QPushButton::pressed, this, |
| 68 | [this, i]() { CallConfigureDialog<ConfigureInputPlayer>(i, false); }); | 75 | [this, i] { CallConfigureDialog<ConfigureInputPlayer>(*this, i, false); }); |
| 69 | } | 76 | } |
| 70 | 77 | ||
| 71 | connect(ui->handheld_configure, &QPushButton::pressed, this, | 78 | connect(ui->handheld_configure, &QPushButton::pressed, this, |
| 72 | [this]() { CallConfigureDialog<ConfigureInputPlayer>(8, false); }); | 79 | [this] { CallConfigureDialog<ConfigureInputPlayer>(*this, 8, false); }); |
| 73 | 80 | ||
| 74 | connect(ui->debug_configure, &QPushButton::pressed, this, | 81 | connect(ui->debug_configure, &QPushButton::pressed, this, |
| 75 | [this]() { CallConfigureDialog<ConfigureInputPlayer>(9, true); }); | 82 | [this] { CallConfigureDialog<ConfigureInputPlayer>(*this, 9, true); }); |
| 76 | 83 | ||
| 77 | connect(ui->mouse_advanced, &QPushButton::pressed, this, | 84 | connect(ui->mouse_advanced, &QPushButton::pressed, this, |
| 78 | [this]() { CallConfigureDialog<ConfigureMouseAdvanced>(); }); | 85 | [this] { CallConfigureDialog<ConfigureMouseAdvanced>(*this); }); |
| 79 | 86 | ||
| 80 | connect(ui->touchscreen_advanced, &QPushButton::pressed, this, | 87 | connect(ui->touchscreen_advanced, &QPushButton::pressed, this, |
| 81 | [this]() { CallConfigureDialog<ConfigureTouchscreenAdvanced>(); }); | 88 | [this] { CallConfigureDialog<ConfigureTouchscreenAdvanced>(*this); }); |
| 82 | } | ||
| 83 | |||
| 84 | template <typename Dialog, typename... Args> | ||
| 85 | void ConfigureInput::CallConfigureDialog(Args&&... args) { | ||
| 86 | this->applyConfiguration(); | ||
| 87 | Dialog dialog(this, std::forward<Args>(args)...); | ||
| 88 | |||
| 89 | const auto res = dialog.exec(); | ||
| 90 | if (res == QDialog::Accepted) { | ||
| 91 | dialog.applyConfiguration(); | ||
| 92 | } | ||
| 93 | } | 89 | } |
| 94 | 90 | ||
| 95 | void ConfigureInput::OnDockedModeChanged(bool last_state, bool new_state) { | 91 | void ConfigureInput::OnDockedModeChanged(bool last_state, bool new_state) { |
diff --git a/src/yuzu/configuration/configure_input.h b/src/yuzu/configuration/configure_input.h index 29a8a03f8..e8723dfcb 100644 --- a/src/yuzu/configuration/configure_input.h +++ b/src/yuzu/configuration/configure_input.h | |||
| @@ -5,20 +5,12 @@ | |||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include <array> | 7 | #include <array> |
| 8 | #include <functional> | ||
| 9 | #include <memory> | 8 | #include <memory> |
| 10 | #include <optional> | ||
| 11 | #include <string> | ||
| 12 | #include <unordered_map> | ||
| 13 | 9 | ||
| 14 | #include <QKeyEvent> | 10 | #include <QKeyEvent> |
| 15 | #include <QWidget> | 11 | #include <QWidget> |
| 16 | 12 | ||
| 17 | #include "common/param_package.h" | ||
| 18 | #include "core/settings.h" | ||
| 19 | #include "input_common/main.h" | ||
| 20 | #include "ui_configure_input.h" | 13 | #include "ui_configure_input.h" |
| 21 | #include "yuzu/configuration/config.h" | ||
| 22 | 14 | ||
| 23 | class QPushButton; | 15 | class QPushButton; |
| 24 | class QString; | 16 | class QString; |
| @@ -40,9 +32,6 @@ public: | |||
| 40 | private: | 32 | private: |
| 41 | void updateUIEnabled(); | 33 | void updateUIEnabled(); |
| 42 | 34 | ||
| 43 | template <typename Dialog, typename... Args> | ||
| 44 | void CallConfigureDialog(Args&&... args); | ||
| 45 | |||
| 46 | void OnDockedModeChanged(bool last_state, bool new_state); | 35 | void OnDockedModeChanged(bool last_state, bool new_state); |
| 47 | 36 | ||
| 48 | /// Load configuration settings. | 37 | /// Load configuration settings. |
diff --git a/src/yuzu/configuration/configure_input_player.cpp b/src/yuzu/configuration/configure_input_player.cpp index ba6e09368..7dadd83c1 100644 --- a/src/yuzu/configuration/configure_input_player.cpp +++ b/src/yuzu/configuration/configure_input_player.cpp | |||
| @@ -25,13 +25,6 @@ const std::array<std::string, ConfigureInputPlayer::ANALOG_SUB_BUTTONS_NUM> | |||
| 25 | "modifier", | 25 | "modifier", |
| 26 | }}; | 26 | }}; |
| 27 | 27 | ||
| 28 | static void MoveGridElement(QGridLayout* grid, int row_old, int column_old, int row_new, | ||
| 29 | int column_new) { | ||
| 30 | const auto item = grid->itemAtPosition(row_old, column_old); | ||
| 31 | // grid->removeItem(item); | ||
| 32 | grid->addItem(item, row_new, column_new); | ||
| 33 | } | ||
| 34 | |||
| 35 | static void LayerGridElements(QGridLayout* grid, QWidget* item, QWidget* onTopOf) { | 28 | static void LayerGridElements(QGridLayout* grid, QWidget* item, QWidget* onTopOf) { |
| 36 | const int index1 = grid->indexOf(item); | 29 | const int index1 = grid->indexOf(item); |
| 37 | const int index2 = grid->indexOf(onTopOf); | 30 | const int index2 = grid->indexOf(onTopOf); |
| @@ -111,11 +104,10 @@ static QString AnalogToText(const Common::ParamPackage& param, const std::string | |||
| 111 | } | 104 | } |
| 112 | }; | 105 | }; |
| 113 | 106 | ||
| 114 | ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, u8 player_index, bool debug) | 107 | ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_index, bool debug) |
| 115 | : QDialog(parent), ui(std::make_unique<Ui::ConfigureInputPlayer>()), | 108 | : QDialog(parent), ui(std::make_unique<Ui::ConfigureInputPlayer>()), player_index(player_index), |
| 116 | timeout_timer(std::make_unique<QTimer>()), poll_timer(std::make_unique<QTimer>()), | 109 | debug(debug), timeout_timer(std::make_unique<QTimer>()), |
| 117 | player_index(player_index), debug(debug) { | 110 | poll_timer(std::make_unique<QTimer>()) { |
| 118 | |||
| 119 | ui->setupUi(this); | 111 | ui->setupUi(this); |
| 120 | setFocusPolicy(Qt::ClickFocus); | 112 | setFocusPolicy(Qt::ClickFocus); |
| 121 | 113 | ||
| @@ -315,7 +307,7 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, u8 player_index, boo | |||
| 315 | 307 | ||
| 316 | for (std::size_t i = 0; i < controller_color_buttons.size(); ++i) { | 308 | for (std::size_t i = 0; i < controller_color_buttons.size(); ++i) { |
| 317 | connect(controller_color_buttons[i], &QPushButton::clicked, this, | 309 | connect(controller_color_buttons[i], &QPushButton::clicked, this, |
| 318 | std::bind(&ConfigureInputPlayer::OnControllerButtonClick, this, i)); | 310 | [this, i] { OnControllerButtonClick(static_cast<int>(i)); }); |
| 319 | } | 311 | } |
| 320 | 312 | ||
| 321 | this->loadConfiguration(); | 313 | this->loadConfiguration(); |
diff --git a/src/yuzu/configuration/configure_input_player.h b/src/yuzu/configuration/configure_input_player.h index b0e5550c5..7a53f6715 100644 --- a/src/yuzu/configuration/configure_input_player.h +++ b/src/yuzu/configuration/configure_input_player.h | |||
| @@ -9,9 +9,10 @@ | |||
| 9 | #include <memory> | 9 | #include <memory> |
| 10 | #include <optional> | 10 | #include <optional> |
| 11 | #include <string> | 11 | #include <string> |
| 12 | #include <unordered_map> | 12 | |
| 13 | #include <QDialog> | 13 | #include <QDialog> |
| 14 | #include <QKeyEvent> | 14 | #include <QKeyEvent> |
| 15 | |||
| 15 | #include "common/param_package.h" | 16 | #include "common/param_package.h" |
| 16 | #include "core/settings.h" | 17 | #include "core/settings.h" |
| 17 | #include "input_common/main.h" | 18 | #include "input_common/main.h" |
| @@ -29,16 +30,39 @@ class ConfigureInputPlayer : public QDialog { | |||
| 29 | Q_OBJECT | 30 | Q_OBJECT |
| 30 | 31 | ||
| 31 | public: | 32 | public: |
| 32 | explicit ConfigureInputPlayer(QWidget* parent, u8 player_index, bool debug = false); | 33 | explicit ConfigureInputPlayer(QWidget* parent, std::size_t player_index, bool debug = false); |
| 33 | ~ConfigureInputPlayer() override; | 34 | ~ConfigureInputPlayer() override; |
| 34 | 35 | ||
| 35 | /// Save all button configurations to settings file | 36 | /// Save all button configurations to settings file |
| 36 | void applyConfiguration(); | 37 | void applyConfiguration(); |
| 37 | 38 | ||
| 38 | private: | 39 | private: |
| 40 | void OnControllerButtonClick(int i); | ||
| 41 | |||
| 42 | /// Load configuration settings. | ||
| 43 | void loadConfiguration(); | ||
| 44 | /// Restore all buttons to their default values. | ||
| 45 | void restoreDefaults(); | ||
| 46 | /// Clear all input configuration | ||
| 47 | void ClearAll(); | ||
| 48 | |||
| 49 | /// Update UI to reflect current configuration. | ||
| 50 | void updateButtonLabels(); | ||
| 51 | |||
| 52 | /// Called when the button was pressed. | ||
| 53 | void handleClick(QPushButton* button, | ||
| 54 | std::function<void(const Common::ParamPackage&)> new_input_setter, | ||
| 55 | InputCommon::Polling::DeviceType type); | ||
| 56 | |||
| 57 | /// Finish polling and configure input using the input_setter | ||
| 58 | void setPollingResult(const Common::ParamPackage& params, bool abort); | ||
| 59 | |||
| 60 | /// Handle key press events. | ||
| 61 | void keyPressEvent(QKeyEvent* event) override; | ||
| 62 | |||
| 39 | std::unique_ptr<Ui::ConfigureInputPlayer> ui; | 63 | std::unique_ptr<Ui::ConfigureInputPlayer> ui; |
| 40 | 64 | ||
| 41 | u8 player_index; | 65 | std::size_t player_index; |
| 42 | bool debug; | 66 | bool debug; |
| 43 | 67 | ||
| 44 | std::unique_ptr<QTimer> timeout_timer; | 68 | std::unique_ptr<QTimer> timeout_timer; |
| @@ -77,27 +101,4 @@ private: | |||
| 77 | 101 | ||
| 78 | std::array<QPushButton*, 4> controller_color_buttons; | 102 | std::array<QPushButton*, 4> controller_color_buttons; |
| 79 | std::array<QColor, 4> controller_colors; | 103 | std::array<QColor, 4> controller_colors; |
| 80 | |||
| 81 | void OnControllerButtonClick(int i); | ||
| 82 | |||
| 83 | /// Load configuration settings. | ||
| 84 | void loadConfiguration(); | ||
| 85 | /// Restore all buttons to their default values. | ||
| 86 | void restoreDefaults(); | ||
| 87 | /// Clear all input configuration | ||
| 88 | void ClearAll(); | ||
| 89 | |||
| 90 | /// Update UI to reflect current configuration. | ||
| 91 | void updateButtonLabels(); | ||
| 92 | |||
| 93 | /// Called when the button was pressed. | ||
| 94 | void handleClick(QPushButton* button, | ||
| 95 | std::function<void(const Common::ParamPackage&)> new_input_setter, | ||
| 96 | InputCommon::Polling::DeviceType type); | ||
| 97 | |||
| 98 | /// Finish polling and configure input using the input_setter | ||
| 99 | void setPollingResult(const Common::ParamPackage& params, bool abort); | ||
| 100 | |||
| 101 | /// Handle key press events. | ||
| 102 | void keyPressEvent(QKeyEvent* event) override; | ||
| 103 | }; | 104 | }; |
diff --git a/src/yuzu/configuration/configure_mouse_advanced.cpp b/src/yuzu/configuration/configure_mouse_advanced.cpp index dab58fbaa..ef857035e 100644 --- a/src/yuzu/configuration/configure_mouse_advanced.cpp +++ b/src/yuzu/configuration/configure_mouse_advanced.cpp | |||
| @@ -4,11 +4,11 @@ | |||
| 4 | 4 | ||
| 5 | #include <algorithm> | 5 | #include <algorithm> |
| 6 | #include <memory> | 6 | #include <memory> |
| 7 | #include <utility> | 7 | |
| 8 | #include <QKeyEvent> | 8 | #include <QKeyEvent> |
| 9 | #include <QMenu> | 9 | #include <QMenu> |
| 10 | #include <QMessageBox> | ||
| 11 | #include <QTimer> | 10 | #include <QTimer> |
| 11 | |||
| 12 | #include "common/assert.h" | 12 | #include "common/assert.h" |
| 13 | #include "common/param_package.h" | 13 | #include "common/param_package.h" |
| 14 | #include "input_common/main.h" | 14 | #include "input_common/main.h" |
diff --git a/src/yuzu/configuration/configure_mouse_advanced.h b/src/yuzu/configuration/configure_mouse_advanced.h index 218df2bda..e04da4bf2 100644 --- a/src/yuzu/configuration/configure_mouse_advanced.h +++ b/src/yuzu/configuration/configure_mouse_advanced.h | |||
| @@ -7,7 +7,7 @@ | |||
| 7 | #include <memory> | 7 | #include <memory> |
| 8 | #include <optional> | 8 | #include <optional> |
| 9 | #include <QDialog> | 9 | #include <QDialog> |
| 10 | #include <QWidget> | 10 | |
| 11 | #include "core/settings.h" | 11 | #include "core/settings.h" |
| 12 | 12 | ||
| 13 | class QCheckBox; | 13 | class QCheckBox; |
| @@ -28,23 +28,6 @@ public: | |||
| 28 | void applyConfiguration(); | 28 | void applyConfiguration(); |
| 29 | 29 | ||
| 30 | private: | 30 | private: |
| 31 | std::unique_ptr<Ui::ConfigureMouseAdvanced> ui; | ||
| 32 | |||
| 33 | /// This will be the the setting function when an input is awaiting configuration. | ||
| 34 | std::optional<std::function<void(const Common::ParamPackage&)>> input_setter; | ||
| 35 | |||
| 36 | std::array<QPushButton*, Settings::NativeMouseButton::NumMouseButtons> button_map; | ||
| 37 | std::array<Common::ParamPackage, Settings::NativeMouseButton::NumMouseButtons> buttons_param; | ||
| 38 | |||
| 39 | std::vector<std::unique_ptr<InputCommon::Polling::DevicePoller>> device_pollers; | ||
| 40 | |||
| 41 | std::unique_ptr<QTimer> timeout_timer; | ||
| 42 | std::unique_ptr<QTimer> poll_timer; | ||
| 43 | |||
| 44 | /// A flag to indicate if keyboard keys are okay when configuring an input. If this is false, | ||
| 45 | /// keyboard events are ignored. | ||
| 46 | bool want_keyboard_keys = false; | ||
| 47 | |||
| 48 | /// Load configuration settings. | 31 | /// Load configuration settings. |
| 49 | void loadConfiguration(); | 32 | void loadConfiguration(); |
| 50 | /// Restore all buttons to their default values. | 33 | /// Restore all buttons to their default values. |
| @@ -65,4 +48,21 @@ private: | |||
| 65 | 48 | ||
| 66 | /// Handle key press events. | 49 | /// Handle key press events. |
| 67 | void keyPressEvent(QKeyEvent* event) override; | 50 | void keyPressEvent(QKeyEvent* event) override; |
| 51 | |||
| 52 | std::unique_ptr<Ui::ConfigureMouseAdvanced> ui; | ||
| 53 | |||
| 54 | /// This will be the the setting function when an input is awaiting configuration. | ||
| 55 | std::optional<std::function<void(const Common::ParamPackage&)>> input_setter; | ||
| 56 | |||
| 57 | std::array<QPushButton*, Settings::NativeMouseButton::NumMouseButtons> button_map; | ||
| 58 | std::array<Common::ParamPackage, Settings::NativeMouseButton::NumMouseButtons> buttons_param; | ||
| 59 | |||
| 60 | std::vector<std::unique_ptr<InputCommon::Polling::DevicePoller>> device_pollers; | ||
| 61 | |||
| 62 | std::unique_ptr<QTimer> timeout_timer; | ||
| 63 | std::unique_ptr<QTimer> poll_timer; | ||
| 64 | |||
| 65 | /// A flag to indicate if keyboard keys are okay when configuring an input. If this is false, | ||
| 66 | /// keyboard events are ignored. | ||
| 67 | bool want_keyboard_keys = false; | ||
| 68 | }; | 68 | }; |