diff options
author | bunnei <bunneidev@gmail.com> | 2018-11-28 00:38:12 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-11-28 00:38:12 +0100 |
commit | e89a3b9e59ec6daebaf4ce112eaa2d5761bcdd42 (patch) | |
tree | 2b10a5e3cf0eacdb86fa3d11a06353f1abe61ad0 /src | |
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 instead of u8 (diff) | |
download | yuzu-e89a3b9e59ec6daebaf4ce112eaa2d5761bcdd42.tar yuzu-e89a3b9e59ec6daebaf4ce112eaa2d5761bcdd42.tar.gz yuzu-e89a3b9e59ec6daebaf4ce112eaa2d5761bcdd42.tar.bz2 yuzu-e89a3b9e59ec6daebaf4ce112eaa2d5761bcdd42.tar.lz yuzu-e89a3b9e59ec6daebaf4ce112eaa2d5761bcdd42.tar.xz yuzu-e89a3b9e59ec6daebaf4ce112eaa2d5761bcdd42.tar.zst yuzu-e89a3b9e59ec6daebaf4ce112eaa2d5761bcdd42.zip |
Diffstat (limited to 'src')
-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 @@ #include <algorithm> #include <memory> -#include <utility> -#include <QMenu> -#include <QMessageBox> + #include <QTimer> -#include "common/param_package.h" + #include "configuration/configure_touchscreen_advanced.h" #include "core/core.h" #include "core/hle/service/am/am.h" @@ -16,16 +14,25 @@ #include "core/hle/service/am/applet_oe.h" #include "core/hle/service/hid/controllers/npad.h" #include "core/hle/service/sm/sm.h" -#include "input_common/main.h" #include "ui_configure_input.h" #include "ui_configure_input_player.h" -#include "ui_configure_mouse_advanced.h" -#include "ui_configure_touchscreen_advanced.h" -#include "yuzu/configuration/config.h" #include "yuzu/configuration/configure_input.h" #include "yuzu/configuration/configure_input_player.h" #include "yuzu/configuration/configure_mouse_advanced.h" +namespace { +template <typename Dialog, typename... Args> +void CallConfigureDialog(ConfigureInput& parent, Args&&... args) { + parent.applyConfiguration(); + Dialog dialog(&parent, std::forward<Args>(args)...); + + const auto res = dialog.exec(); + if (res == QDialog::Accepted) { + dialog.applyConfiguration(); + } +} +} // Anonymous namespace + ConfigureInput::ConfigureInput(QWidget* parent) : QWidget(parent), ui(std::make_unique<Ui::ConfigureInput>()) { ui->setupUi(this); @@ -65,31 +72,20 @@ ConfigureInput::ConfigureInput(QWidget* parent) for (std::size_t i = 0; i < players_configure.size(); ++i) { connect(players_configure[i], &QPushButton::pressed, this, - [this, i]() { CallConfigureDialog<ConfigureInputPlayer>(i, false); }); + [this, i] { CallConfigureDialog<ConfigureInputPlayer>(*this, i, false); }); } connect(ui->handheld_configure, &QPushButton::pressed, this, - [this]() { CallConfigureDialog<ConfigureInputPlayer>(8, false); }); + [this] { CallConfigureDialog<ConfigureInputPlayer>(*this, 8, false); }); connect(ui->debug_configure, &QPushButton::pressed, this, - [this]() { CallConfigureDialog<ConfigureInputPlayer>(9, true); }); + [this] { CallConfigureDialog<ConfigureInputPlayer>(*this, 9, true); }); connect(ui->mouse_advanced, &QPushButton::pressed, this, - [this]() { CallConfigureDialog<ConfigureMouseAdvanced>(); }); + [this] { CallConfigureDialog<ConfigureMouseAdvanced>(*this); }); connect(ui->touchscreen_advanced, &QPushButton::pressed, this, - [this]() { CallConfigureDialog<ConfigureTouchscreenAdvanced>(); }); -} - -template <typename Dialog, typename... Args> -void ConfigureInput::CallConfigureDialog(Args&&... args) { - this->applyConfiguration(); - Dialog dialog(this, std::forward<Args>(args)...); - - const auto res = dialog.exec(); - if (res == QDialog::Accepted) { - dialog.applyConfiguration(); - } + [this] { CallConfigureDialog<ConfigureTouchscreenAdvanced>(*this); }); } 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 @@ #pragma once #include <array> -#include <functional> #include <memory> -#include <optional> -#include <string> -#include <unordered_map> #include <QKeyEvent> #include <QWidget> -#include "common/param_package.h" -#include "core/settings.h" -#include "input_common/main.h" #include "ui_configure_input.h" -#include "yuzu/configuration/config.h" class QPushButton; class QString; @@ -40,9 +32,6 @@ public: private: void updateUIEnabled(); - template <typename Dialog, typename... Args> - void CallConfigureDialog(Args&&... args); - void OnDockedModeChanged(bool last_state, bool new_state); /// 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> "modifier", }}; -static void MoveGridElement(QGridLayout* grid, int row_old, int column_old, int row_new, - int column_new) { - const auto item = grid->itemAtPosition(row_old, column_old); - // grid->removeItem(item); - grid->addItem(item, row_new, column_new); -} - static void LayerGridElements(QGridLayout* grid, QWidget* item, QWidget* onTopOf) { const int index1 = grid->indexOf(item); const int index2 = grid->indexOf(onTopOf); @@ -111,11 +104,10 @@ static QString AnalogToText(const Common::ParamPackage& param, const std::string } }; -ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, u8 player_index, bool debug) - : QDialog(parent), ui(std::make_unique<Ui::ConfigureInputPlayer>()), - timeout_timer(std::make_unique<QTimer>()), poll_timer(std::make_unique<QTimer>()), - player_index(player_index), debug(debug) { - +ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_index, bool debug) + : QDialog(parent), ui(std::make_unique<Ui::ConfigureInputPlayer>()), player_index(player_index), + debug(debug), timeout_timer(std::make_unique<QTimer>()), + poll_timer(std::make_unique<QTimer>()) { ui->setupUi(this); setFocusPolicy(Qt::ClickFocus); @@ -315,7 +307,7 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, u8 player_index, boo for (std::size_t i = 0; i < controller_color_buttons.size(); ++i) { connect(controller_color_buttons[i], &QPushButton::clicked, this, - std::bind(&ConfigureInputPlayer::OnControllerButtonClick, this, i)); + [this, i] { OnControllerButtonClick(static_cast<int>(i)); }); } 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 @@ #include <memory> #include <optional> #include <string> -#include <unordered_map> + #include <QDialog> #include <QKeyEvent> + #include "common/param_package.h" #include "core/settings.h" #include "input_common/main.h" @@ -29,16 +30,39 @@ class ConfigureInputPlayer : public QDialog { Q_OBJECT public: - explicit ConfigureInputPlayer(QWidget* parent, u8 player_index, bool debug = false); + explicit ConfigureInputPlayer(QWidget* parent, std::size_t player_index, bool debug = false); ~ConfigureInputPlayer() override; /// Save all button configurations to settings file void applyConfiguration(); private: + void OnControllerButtonClick(int i); + + /// Load configuration settings. + void loadConfiguration(); + /// Restore all buttons to their default values. + void restoreDefaults(); + /// Clear all input configuration + void ClearAll(); + + /// Update UI to reflect current configuration. + void updateButtonLabels(); + + /// Called when the button was pressed. + void handleClick(QPushButton* button, + std::function<void(const Common::ParamPackage&)> new_input_setter, + InputCommon::Polling::DeviceType type); + + /// Finish polling and configure input using the input_setter + void setPollingResult(const Common::ParamPackage& params, bool abort); + + /// Handle key press events. + void keyPressEvent(QKeyEvent* event) override; + std::unique_ptr<Ui::ConfigureInputPlayer> ui; - u8 player_index; + std::size_t player_index; bool debug; std::unique_ptr<QTimer> timeout_timer; @@ -77,27 +101,4 @@ private: std::array<QPushButton*, 4> controller_color_buttons; std::array<QColor, 4> controller_colors; - - void OnControllerButtonClick(int i); - - /// Load configuration settings. - void loadConfiguration(); - /// Restore all buttons to their default values. - void restoreDefaults(); - /// Clear all input configuration - void ClearAll(); - - /// Update UI to reflect current configuration. - void updateButtonLabels(); - - /// Called when the button was pressed. - void handleClick(QPushButton* button, - std::function<void(const Common::ParamPackage&)> new_input_setter, - InputCommon::Polling::DeviceType type); - - /// Finish polling and configure input using the input_setter - void setPollingResult(const Common::ParamPackage& params, bool abort); - - /// Handle key press events. - void keyPressEvent(QKeyEvent* event) override; }; 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 @@ #include <algorithm> #include <memory> -#include <utility> + #include <QKeyEvent> #include <QMenu> -#include <QMessageBox> #include <QTimer> + #include "common/assert.h" #include "common/param_package.h" #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 @@ #include <memory> #include <optional> #include <QDialog> -#include <QWidget> + #include "core/settings.h" class QCheckBox; @@ -28,23 +28,6 @@ public: void applyConfiguration(); private: - std::unique_ptr<Ui::ConfigureMouseAdvanced> ui; - - /// This will be the the setting function when an input is awaiting configuration. - std::optional<std::function<void(const Common::ParamPackage&)>> input_setter; - - std::array<QPushButton*, Settings::NativeMouseButton::NumMouseButtons> button_map; - std::array<Common::ParamPackage, Settings::NativeMouseButton::NumMouseButtons> buttons_param; - - std::vector<std::unique_ptr<InputCommon::Polling::DevicePoller>> device_pollers; - - std::unique_ptr<QTimer> timeout_timer; - std::unique_ptr<QTimer> poll_timer; - - /// A flag to indicate if keyboard keys are okay when configuring an input. If this is false, - /// keyboard events are ignored. - bool want_keyboard_keys = false; - /// Load configuration settings. void loadConfiguration(); /// Restore all buttons to their default values. @@ -65,4 +48,21 @@ private: /// Handle key press events. void keyPressEvent(QKeyEvent* event) override; + + std::unique_ptr<Ui::ConfigureMouseAdvanced> ui; + + /// This will be the the setting function when an input is awaiting configuration. + std::optional<std::function<void(const Common::ParamPackage&)>> input_setter; + + std::array<QPushButton*, Settings::NativeMouseButton::NumMouseButtons> button_map; + std::array<Common::ParamPackage, Settings::NativeMouseButton::NumMouseButtons> buttons_param; + + std::vector<std::unique_ptr<InputCommon::Polling::DevicePoller>> device_pollers; + + std::unique_ptr<QTimer> timeout_timer; + std::unique_ptr<QTimer> poll_timer; + + /// A flag to indicate if keyboard keys are okay when configuring an input. If this is false, + /// keyboard events are ignored. + bool want_keyboard_keys = false; }; |