Merge pull request #1811 from lioncash/input

yuzu/input: Minor changes
This commit is contained in:
bunnei 2018-11-27 18:38:12 -05:00 committed by GitHub
commit e89a3b9e59
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 72 additions and 94 deletions

View file

@ -4,11 +4,9 @@
#include <algorithm> #include <algorithm>
#include <memory> #include <memory>
#include <utility>
#include <QMenu>
#include <QMessageBox>
#include <QTimer> #include <QTimer>
#include "common/param_package.h"
#include "configuration/configure_touchscreen_advanced.h" #include "configuration/configure_touchscreen_advanced.h"
#include "core/core.h" #include "core/core.h"
#include "core/hle/service/am/am.h" #include "core/hle/service/am/am.h"
@ -16,16 +14,25 @@
#include "core/hle/service/am/applet_oe.h" #include "core/hle/service/am/applet_oe.h"
#include "core/hle/service/hid/controllers/npad.h" #include "core/hle/service/hid/controllers/npad.h"
#include "core/hle/service/sm/sm.h" #include "core/hle/service/sm/sm.h"
#include "input_common/main.h"
#include "ui_configure_input.h" #include "ui_configure_input.h"
#include "ui_configure_input_player.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.h"
#include "yuzu/configuration/configure_input_player.h" #include "yuzu/configuration/configure_input_player.h"
#include "yuzu/configuration/configure_mouse_advanced.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) ConfigureInput::ConfigureInput(QWidget* parent)
: QWidget(parent), ui(std::make_unique<Ui::ConfigureInput>()) { : QWidget(parent), ui(std::make_unique<Ui::ConfigureInput>()) {
ui->setupUi(this); ui->setupUi(this);
@ -65,31 +72,20 @@ ConfigureInput::ConfigureInput(QWidget* parent)
for (std::size_t i = 0; i < players_configure.size(); ++i) { for (std::size_t i = 0; i < players_configure.size(); ++i) {
connect(players_configure[i], &QPushButton::pressed, this, 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, 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, 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, connect(ui->mouse_advanced, &QPushButton::pressed, this,
[this]() { CallConfigureDialog<ConfigureMouseAdvanced>(); }); [this] { CallConfigureDialog<ConfigureMouseAdvanced>(*this); });
connect(ui->touchscreen_advanced, &QPushButton::pressed, this, connect(ui->touchscreen_advanced, &QPushButton::pressed, this,
[this]() { CallConfigureDialog<ConfigureTouchscreenAdvanced>(); }); [this] { CallConfigureDialog<ConfigureTouchscreenAdvanced>(*this); });
}
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();
}
} }
void ConfigureInput::OnDockedModeChanged(bool last_state, bool new_state) { void ConfigureInput::OnDockedModeChanged(bool last_state, bool new_state) {

View file

@ -5,20 +5,12 @@
#pragma once #pragma once
#include <array> #include <array>
#include <functional>
#include <memory> #include <memory>
#include <optional>
#include <string>
#include <unordered_map>
#include <QKeyEvent> #include <QKeyEvent>
#include <QWidget> #include <QWidget>
#include "common/param_package.h"
#include "core/settings.h"
#include "input_common/main.h"
#include "ui_configure_input.h" #include "ui_configure_input.h"
#include "yuzu/configuration/config.h"
class QPushButton; class QPushButton;
class QString; class QString;
@ -40,9 +32,6 @@ public:
private: private:
void updateUIEnabled(); void updateUIEnabled();
template <typename Dialog, typename... Args>
void CallConfigureDialog(Args&&... args);
void OnDockedModeChanged(bool last_state, bool new_state); void OnDockedModeChanged(bool last_state, bool new_state);
/// Load configuration settings. /// Load configuration settings.

View file

@ -25,13 +25,6 @@ const std::array<std::string, ConfigureInputPlayer::ANALOG_SUB_BUTTONS_NUM>
"modifier", "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) { static void LayerGridElements(QGridLayout* grid, QWidget* item, QWidget* onTopOf) {
const int index1 = grid->indexOf(item); const int index1 = grid->indexOf(item);
const int index2 = grid->indexOf(onTopOf); 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) ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_index, bool debug)
: QDialog(parent), ui(std::make_unique<Ui::ConfigureInputPlayer>()), : QDialog(parent), ui(std::make_unique<Ui::ConfigureInputPlayer>()), player_index(player_index),
timeout_timer(std::make_unique<QTimer>()), poll_timer(std::make_unique<QTimer>()), debug(debug), timeout_timer(std::make_unique<QTimer>()),
player_index(player_index), debug(debug) { poll_timer(std::make_unique<QTimer>()) {
ui->setupUi(this); ui->setupUi(this);
setFocusPolicy(Qt::ClickFocus); 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) { for (std::size_t i = 0; i < controller_color_buttons.size(); ++i) {
connect(controller_color_buttons[i], &QPushButton::clicked, this, connect(controller_color_buttons[i], &QPushButton::clicked, this,
std::bind(&ConfigureInputPlayer::OnControllerButtonClick, this, i)); [this, i] { OnControllerButtonClick(static_cast<int>(i)); });
} }
this->loadConfiguration(); this->loadConfiguration();

View file

@ -9,9 +9,10 @@
#include <memory> #include <memory>
#include <optional> #include <optional>
#include <string> #include <string>
#include <unordered_map>
#include <QDialog> #include <QDialog>
#include <QKeyEvent> #include <QKeyEvent>
#include "common/param_package.h" #include "common/param_package.h"
#include "core/settings.h" #include "core/settings.h"
#include "input_common/main.h" #include "input_common/main.h"
@ -29,16 +30,39 @@ class ConfigureInputPlayer : public QDialog {
Q_OBJECT Q_OBJECT
public: 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; ~ConfigureInputPlayer() override;
/// Save all button configurations to settings file /// Save all button configurations to settings file
void applyConfiguration(); void applyConfiguration();
private: 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; std::unique_ptr<Ui::ConfigureInputPlayer> ui;
u8 player_index; std::size_t player_index;
bool debug; bool debug;
std::unique_ptr<QTimer> timeout_timer; std::unique_ptr<QTimer> timeout_timer;
@ -77,27 +101,4 @@ private:
std::array<QPushButton*, 4> controller_color_buttons; std::array<QPushButton*, 4> controller_color_buttons;
std::array<QColor, 4> controller_colors; 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;
}; };

View file

@ -4,11 +4,11 @@
#include <algorithm> #include <algorithm>
#include <memory> #include <memory>
#include <utility>
#include <QKeyEvent> #include <QKeyEvent>
#include <QMenu> #include <QMenu>
#include <QMessageBox>
#include <QTimer> #include <QTimer>
#include "common/assert.h" #include "common/assert.h"
#include "common/param_package.h" #include "common/param_package.h"
#include "input_common/main.h" #include "input_common/main.h"

View file

@ -7,7 +7,7 @@
#include <memory> #include <memory>
#include <optional> #include <optional>
#include <QDialog> #include <QDialog>
#include <QWidget>
#include "core/settings.h" #include "core/settings.h"
class QCheckBox; class QCheckBox;
@ -28,23 +28,6 @@ public:
void applyConfiguration(); void applyConfiguration();
private: 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. /// Load configuration settings.
void loadConfiguration(); void loadConfiguration();
/// Restore all buttons to their default values. /// Restore all buttons to their default values.
@ -65,4 +48,21 @@ private:
/// Handle key press events. /// Handle key press events.
void keyPressEvent(QKeyEvent* event) override; 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;
}; };