mirror of
https://git.suyu.dev/suyu/suyu.git
synced 2024-11-14 10:52:45 +01:00
commit
e89a3b9e59
6 changed files with 72 additions and 94 deletions
|
@ -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) {
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue