mirror of
https://github.com/yuzu-emu/yuzu-android
synced 2025-08-02 07:22:26 -07:00
hid: Use player-defined controller type as PREFERRED_CONTROLLER
This commit is contained in:
@@ -203,9 +203,8 @@ const std::array<int, Settings::NativeKeyboard::NumKeyboardMods> Config::default
|
||||
Qt::Key_Control, Qt::Key_Shift, Qt::Key_AltGr, Qt::Key_ApplicationRight,
|
||||
};
|
||||
|
||||
void Config::ReadValues() {
|
||||
qt_config->beginGroup("Controls");
|
||||
for (std::size_t p = 0; p < 10; ++p) {
|
||||
void Config::ReadPlayerValues() {
|
||||
for (std::size_t p = 0; p < Settings::values.players.size(); ++p) {
|
||||
Settings::values.players[p].connected =
|
||||
qt_config->value(QString("player_%1_connected").arg(p), false).toBool();
|
||||
|
||||
@@ -265,28 +264,9 @@ void Config::ReadValues() {
|
||||
|
||||
std::stable_partition(Settings::values.players.begin(), Settings::values.players.end(),
|
||||
[](const auto& player) { return player.connected; });
|
||||
}
|
||||
|
||||
Settings::values.motion_device =
|
||||
qt_config->value("motion_device", "engine:motion_emu,update_period:100,sensitivity:0.01")
|
||||
.toString()
|
||||
.toStdString();
|
||||
|
||||
Settings::values.mouse_enabled = qt_config->value("mouse_enabled", false).toBool();
|
||||
|
||||
for (int i = 0; i < Settings::NativeMouseButton::NumMouseButtons; ++i) {
|
||||
std::string default_param = InputCommon::GenerateKeyboardParam(default_mouse_buttons[i]);
|
||||
Settings::values.mouse_buttons[i] =
|
||||
qt_config
|
||||
->value(QString("mouse_") + Settings::NativeMouseButton::mapping[i],
|
||||
QString::fromStdString(default_param))
|
||||
.toString()
|
||||
.toStdString();
|
||||
if (Settings::values.mouse_buttons[i].empty())
|
||||
Settings::values.mouse_buttons[i] = default_param;
|
||||
}
|
||||
|
||||
Settings::values.keyboard_enabled = qt_config->value("keyboard_enabled", false).toBool();
|
||||
|
||||
void Config::ReadDebugValues() {
|
||||
Settings::values.debug_pad_enabled = qt_config->value("debug_pad_enabled", false).toBool();
|
||||
for (int i = 0; i < Settings::NativeButton::NumButtons; ++i) {
|
||||
std::string default_param = InputCommon::GenerateKeyboardParam(default_buttons[i]);
|
||||
@@ -313,7 +293,38 @@ void Config::ReadValues() {
|
||||
if (Settings::values.debug_pad_analogs[i].empty())
|
||||
Settings::values.debug_pad_analogs[i] = default_param;
|
||||
}
|
||||
}
|
||||
|
||||
void Config::ReadKeyboardValues() {
|
||||
Settings::values.keyboard_enabled = qt_config->value("keyboard_enabled", false).toBool();
|
||||
|
||||
std::transform(default_keyboard_keys.begin(), default_keyboard_keys.end(),
|
||||
Settings::values.keyboard_keys.begin(), InputCommon::GenerateKeyboardParam);
|
||||
std::transform(default_keyboard_mods.begin(), default_keyboard_mods.end(),
|
||||
Settings::values.keyboard_keys.begin() +
|
||||
Settings::NativeKeyboard::LeftControlKey,
|
||||
InputCommon::GenerateKeyboardParam);
|
||||
std::transform(default_keyboard_mods.begin(), default_keyboard_mods.end(),
|
||||
Settings::values.keyboard_mods.begin(), InputCommon::GenerateKeyboardParam);
|
||||
}
|
||||
|
||||
void Config::ReadMouseValues() {
|
||||
Settings::values.mouse_enabled = qt_config->value("mouse_enabled", false).toBool();
|
||||
|
||||
for (int i = 0; i < Settings::NativeMouseButton::NumMouseButtons; ++i) {
|
||||
std::string default_param = InputCommon::GenerateKeyboardParam(default_mouse_buttons[i]);
|
||||
Settings::values.mouse_buttons[i] =
|
||||
qt_config
|
||||
->value(QString("mouse_") + Settings::NativeMouseButton::mapping[i],
|
||||
QString::fromStdString(default_param))
|
||||
.toString()
|
||||
.toStdString();
|
||||
if (Settings::values.mouse_buttons[i].empty())
|
||||
Settings::values.mouse_buttons[i] = default_param;
|
||||
}
|
||||
}
|
||||
|
||||
void Config::ReadTouchscreenValues() {
|
||||
Settings::values.touchscreen.enabled = qt_config->value("touchscreen_enabled", true).toBool();
|
||||
Settings::values.touchscreen.device =
|
||||
qt_config->value("touchscreen_device", "engine:emu_window").toString().toStdString();
|
||||
@@ -325,6 +336,21 @@ void Config::ReadValues() {
|
||||
Settings::values.touchscreen.diameter_y =
|
||||
qt_config->value("touchscreen_diameter_y", 15).toUInt();
|
||||
qt_config->endGroup();
|
||||
}
|
||||
|
||||
void Config::ReadValues() {
|
||||
qt_config->beginGroup("Controls");
|
||||
|
||||
ReadPlayerValues();
|
||||
ReadDebugValues();
|
||||
ReadKeyboardValues();
|
||||
ReadMouseValues();
|
||||
ReadTouchscreenValues();
|
||||
|
||||
Settings::values.motion_device =
|
||||
qt_config->value("motion_device", "engine:motion_emu,update_period:100,sensitivity:0.01")
|
||||
.toString()
|
||||
.toStdString();
|
||||
|
||||
qt_config->beginGroup("Core");
|
||||
Settings::values.use_cpu_jit = qt_config->value("use_cpu_jit", true).toBool();
|
||||
@@ -370,15 +396,6 @@ void Config::ReadValues() {
|
||||
.toStdString());
|
||||
qt_config->endGroup();
|
||||
|
||||
std::transform(default_keyboard_keys.begin(), default_keyboard_keys.end(),
|
||||
Settings::values.keyboard_keys.begin(), InputCommon::GenerateKeyboardParam);
|
||||
std::transform(default_keyboard_mods.begin(), default_keyboard_mods.end(),
|
||||
Settings::values.keyboard_keys.begin() +
|
||||
Settings::NativeKeyboard::LeftControlKey,
|
||||
InputCommon::GenerateKeyboardParam);
|
||||
std::transform(default_keyboard_mods.begin(), default_keyboard_mods.end(),
|
||||
Settings::values.keyboard_mods.begin(), InputCommon::GenerateKeyboardParam);
|
||||
|
||||
qt_config->beginGroup("Core");
|
||||
Settings::values.use_cpu_jit = qt_config->value("use_cpu_jit", true).toBool();
|
||||
Settings::values.use_multi_core = qt_config->value("use_multi_core", false).toBool();
|
||||
@@ -488,9 +505,8 @@ void Config::ReadValues() {
|
||||
qt_config->endGroup();
|
||||
}
|
||||
|
||||
void Config::SaveValues() {
|
||||
qt_config->beginGroup("Controls");
|
||||
for (int p = 0; p < 10; ++p) {
|
||||
void Config::SavePlayerValues() {
|
||||
for (int p = 0; p < Settings::values.players.size(); ++p) {
|
||||
qt_config->setValue(QString("player_%1_connected").arg(p),
|
||||
Settings::values.players[p].connected);
|
||||
qt_config->setValue(QString("player_%1_type").arg(p),
|
||||
@@ -516,19 +532,9 @@ void Config::SaveValues() {
|
||||
QString::fromStdString(Settings::values.players[p].analogs[i]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
qt_config->setValue("motion_device", QString::fromStdString(Settings::values.motion_device));
|
||||
|
||||
qt_config->setValue("mouse_enabled", Settings::values.mouse_enabled);
|
||||
|
||||
for (int i = 0; i < Settings::NativeMouseButton::NumMouseButtons; ++i) {
|
||||
qt_config->setValue(QString("mouse_") +
|
||||
QString::fromStdString(Settings::NativeMouseButton::mapping[i]),
|
||||
QString::fromStdString(Settings::values.mouse_buttons[i]));
|
||||
}
|
||||
|
||||
qt_config->setValue("keyboard_enabled", Settings::values.keyboard_enabled);
|
||||
|
||||
void Config::SaveDebugValues() {
|
||||
qt_config->setValue("debug_pad_enabled", Settings::values.debug_pad_enabled);
|
||||
for (int i = 0; i < Settings::NativeButton::NumButtons; ++i) {
|
||||
qt_config->setValue(QString("debug_pad_") +
|
||||
@@ -540,7 +546,19 @@ void Config::SaveValues() {
|
||||
QString::fromStdString(Settings::NativeAnalog::mapping[i]),
|
||||
QString::fromStdString(Settings::values.debug_pad_analogs[i]));
|
||||
}
|
||||
}
|
||||
|
||||
void Config::SaveMouseValues() {
|
||||
qt_config->setValue("mouse_enabled", Settings::values.mouse_enabled);
|
||||
|
||||
for (int i = 0; i < Settings::NativeMouseButton::NumMouseButtons; ++i) {
|
||||
qt_config->setValue(QString("mouse_") +
|
||||
QString::fromStdString(Settings::NativeMouseButton::mapping[i]),
|
||||
QString::fromStdString(Settings::values.mouse_buttons[i]));
|
||||
}
|
||||
}
|
||||
|
||||
void Config::SaveTouchscreenValues() {
|
||||
qt_config->setValue("touchscreen_enabled", Settings::values.touchscreen.enabled);
|
||||
qt_config->setValue("touchscreen_device",
|
||||
QString::fromStdString(Settings::values.touchscreen.device));
|
||||
@@ -549,6 +567,19 @@ void Config::SaveValues() {
|
||||
qt_config->setValue("touchscreen_angle", Settings::values.touchscreen.rotation_angle);
|
||||
qt_config->setValue("touchscreen_diameter_x", Settings::values.touchscreen.diameter_x);
|
||||
qt_config->setValue("touchscreen_diameter_y", Settings::values.touchscreen.diameter_y);
|
||||
}
|
||||
|
||||
void Config::SaveValues() {
|
||||
qt_config->beginGroup("Controls");
|
||||
|
||||
SavePlayerValues();
|
||||
SaveDebugValues();
|
||||
SaveMouseValues();
|
||||
SaveTouchscreenValues();
|
||||
|
||||
qt_config->setValue("motion_device", QString::fromStdString(Settings::values.motion_device));
|
||||
qt_config->setValue("keyboard_enabled", Settings::values.keyboard_enabled);
|
||||
|
||||
qt_config->endGroup();
|
||||
|
||||
qt_config->beginGroup("Core");
|
||||
|
@@ -29,7 +29,17 @@ public:
|
||||
|
||||
private:
|
||||
void ReadValues();
|
||||
void ReadPlayerValues();
|
||||
void ReadDebugValues();
|
||||
void ReadKeyboardValues();
|
||||
void ReadMouseValues();
|
||||
void ReadTouchscreenValues();
|
||||
|
||||
void SaveValues();
|
||||
void SavePlayerValues();
|
||||
void SaveDebugValues();
|
||||
void SaveMouseValues();
|
||||
void SaveTouchscreenValues();
|
||||
|
||||
std::unique_ptr<QSettings> qt_config;
|
||||
std::string qt_config_loc;
|
||||
|
@@ -11,6 +11,7 @@
|
||||
#include "common/param_package.h"
|
||||
#include "configuration/configure_touchscreen_advanced.h"
|
||||
#include "core/core.h"
|
||||
#include "core/hle/service/hid/controllers/npad.h"
|
||||
#include "input_common/main.h"
|
||||
#include "ui_configure_input.h"
|
||||
#include "ui_configure_input_player.h"
|
||||
@@ -83,9 +84,9 @@ ConfigureInput::ConfigureInput(QWidget* parent)
|
||||
}
|
||||
|
||||
template <typename Dialog, typename... Args>
|
||||
void ConfigureInput::CallConfigureDialog(Args... args) {
|
||||
void ConfigureInput::CallConfigureDialog(Args&&... args) {
|
||||
this->applyConfiguration();
|
||||
Dialog dialog(this, args...);
|
||||
Dialog dialog(this, std::forward<Args>(args)...);
|
||||
|
||||
const auto res = dialog.exec();
|
||||
if (res == QDialog::Accepted) {
|
||||
@@ -94,14 +95,16 @@ void ConfigureInput::CallConfigureDialog(Args... args) {
|
||||
}
|
||||
|
||||
void ConfigureInput::applyConfiguration() {
|
||||
for (std::size_t i = 0; i < 8; ++i) {
|
||||
for (std::size_t i = 0; i < players_enabled.size(); ++i) {
|
||||
Settings::values.players[i].connected = players_enabled[i]->isChecked();
|
||||
Settings::values.players[i].type =
|
||||
static_cast<Settings::ControllerType>(player_controller[i]->currentIndex());
|
||||
}
|
||||
|
||||
Settings::values.use_docked_mode = ui->use_docked_mode->isChecked();
|
||||
Settings::values.players[8].connected = ui->handheld_connected->isChecked();
|
||||
Settings::values
|
||||
.players[Service::HID::Controller_NPad::NPadIdToIndex(Service::HID::NPAD_HANDHELD)]
|
||||
.connected = ui->handheld_connected->isChecked();
|
||||
Settings::values.debug_pad_enabled = ui->debug_enabled->isChecked();
|
||||
Settings::values.mouse_enabled = ui->mouse_enabled->isChecked();
|
||||
Settings::values.keyboard_enabled = ui->keyboard_enabled->isChecked();
|
||||
@@ -109,7 +112,7 @@ void ConfigureInput::applyConfiguration() {
|
||||
}
|
||||
|
||||
void ConfigureInput::updateUIEnabled() {
|
||||
for (std::size_t i = 0; i < 8; ++i) {
|
||||
for (std::size_t i = 0; i < players_enabled.size(); ++i) {
|
||||
const auto enabled = players_enabled[i]->checkState() == Qt::Checked;
|
||||
|
||||
player_controller[i]->setEnabled(enabled);
|
||||
@@ -118,10 +121,7 @@ void ConfigureInput::updateUIEnabled() {
|
||||
|
||||
bool hit_disabled = false;
|
||||
for (auto* player : players_enabled) {
|
||||
if (hit_disabled)
|
||||
player->setDisabled(true);
|
||||
else
|
||||
player->setEnabled(true);
|
||||
player->setDisabled(hit_disabled);
|
||||
if (!player->isChecked())
|
||||
hit_disabled = true;
|
||||
}
|
||||
@@ -138,13 +138,16 @@ void ConfigureInput::loadConfiguration() {
|
||||
std::stable_partition(Settings::values.players.begin(), Settings::values.players.end(),
|
||||
[](const auto& player) { return player.connected; });
|
||||
|
||||
for (std::size_t i = 0; i < 8; ++i) {
|
||||
for (std::size_t i = 0; i < players_enabled.size(); ++i) {
|
||||
players_enabled[i]->setChecked(Settings::values.players[i].connected);
|
||||
player_controller[i]->setCurrentIndex(static_cast<u8>(Settings::values.players[i].type));
|
||||
}
|
||||
|
||||
ui->use_docked_mode->setChecked(Settings::values.use_docked_mode);
|
||||
ui->handheld_connected->setChecked(Settings::values.players[8].connected);
|
||||
ui->handheld_connected->setChecked(
|
||||
Settings::values
|
||||
.players[Service::HID::Controller_NPad::NPadIdToIndex(Service::HID::NPAD_HANDHELD)]
|
||||
.connected);
|
||||
ui->debug_enabled->setChecked(Settings::values.debug_pad_enabled);
|
||||
ui->mouse_enabled->setChecked(Settings::values.mouse_enabled);
|
||||
ui->keyboard_enabled->setChecked(Settings::values.keyboard_enabled);
|
||||
@@ -157,7 +160,7 @@ void ConfigureInput::restoreDefaults() {
|
||||
players_enabled[0]->setCheckState(Qt::Checked);
|
||||
player_controller[0]->setCurrentIndex(1);
|
||||
|
||||
for (std::size_t i = 1; i < 8; ++i) {
|
||||
for (std::size_t i = 1; i < players_enabled.size(); ++i) {
|
||||
players_enabled[i]->setCheckState(Qt::Unchecked);
|
||||
player_controller[i]->setCurrentIndex(0);
|
||||
}
|
||||
|
@@ -41,7 +41,7 @@ private:
|
||||
void updateUIEnabled();
|
||||
|
||||
template <typename Dialog, typename... Args>
|
||||
void CallConfigureDialog(Args... args);
|
||||
void CallConfigureDialog(Args&&... args);
|
||||
|
||||
/// Load configuration settings.
|
||||
void loadConfiguration();
|
||||
|
@@ -41,7 +41,7 @@ static void LayerGridElements(QGridLayout* grid, QWidget* item, QWidget* onTopOf
|
||||
grid->addWidget(item, row, column, rowSpan, columnSpan);
|
||||
}
|
||||
|
||||
static QString getKeyName(int key_code) {
|
||||
static QString GetKeyName(int key_code) {
|
||||
switch (key_code) {
|
||||
case Qt::Key_Shift:
|
||||
return QObject::tr("Shift");
|
||||
@@ -71,7 +71,7 @@ static QString ButtonToText(const Common::ParamPackage& param) {
|
||||
if (!param.Has("engine")) {
|
||||
return QObject::tr("[not set]");
|
||||
} else if (param.Get("engine", "") == "keyboard") {
|
||||
return getKeyName(param.Get("code", 0));
|
||||
return GetKeyName(param.Get("code", 0));
|
||||
} else if (param.Get("engine", "") == "sdl") {
|
||||
if (param.Has("hat")) {
|
||||
return QString(QObject::tr("Hat %1 %2"))
|
||||
@@ -486,7 +486,7 @@ void ConfigureInputPlayer::setPollingResult(const Common::ParamPackage& params,
|
||||
}
|
||||
|
||||
updateButtonLabels();
|
||||
input_setter = boost::none;
|
||||
input_setter = std::nullopt;
|
||||
}
|
||||
|
||||
void ConfigureInputPlayer::keyPressEvent(QKeyEvent* event) {
|
||||
|
@@ -7,11 +7,11 @@
|
||||
#include <array>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <QDialog>
|
||||
#include <QKeyEvent>
|
||||
#include <boost/optional.hpp>
|
||||
#include "common/param_package.h"
|
||||
#include "core/settings.h"
|
||||
#include "input_common/main.h"
|
||||
@@ -44,7 +44,7 @@ private:
|
||||
std::unique_ptr<QTimer> poll_timer;
|
||||
|
||||
/// This will be the the setting function when an input is awaiting configuration.
|
||||
boost::optional<std::function<void(const Common::ParamPackage&)>> input_setter;
|
||||
std::optional<std::function<void(const Common::ParamPackage&)>> input_setter;
|
||||
|
||||
std::array<Common::ParamPackage, Settings::NativeButton::NumButtons> buttons_param;
|
||||
std::array<Common::ParamPackage, Settings::NativeAnalog::NumAnalogs> analogs_param;
|
||||
|
@@ -16,7 +16,7 @@
|
||||
#include "yuzu/configuration/config.h"
|
||||
#include "yuzu/configuration/configure_mouse_advanced.h"
|
||||
|
||||
static QString getKeyName(int key_code) {
|
||||
static QString GetKeyName(int key_code) {
|
||||
switch (key_code) {
|
||||
case Qt::Key_Shift:
|
||||
return QObject::tr("Shift");
|
||||
@@ -35,7 +35,7 @@ static QString ButtonToText(const Common::ParamPackage& param) {
|
||||
if (!param.Has("engine")) {
|
||||
return QObject::tr("[not set]");
|
||||
} else if (param.Get("engine", "") == "keyboard") {
|
||||
return getKeyName(param.Get("code", 0));
|
||||
return GetKeyName(param.Get("code", 0));
|
||||
} else if (param.Get("engine", "") == "sdl") {
|
||||
if (param.Has("hat")) {
|
||||
return QString(QObject::tr("Hat %1 %2"))
|
||||
@@ -191,7 +191,7 @@ void ConfigureMouseAdvanced::setPollingResult(const Common::ParamPackage& params
|
||||
}
|
||||
|
||||
updateButtonLabels();
|
||||
input_setter = boost::none;
|
||||
input_setter = std::nullopt;
|
||||
}
|
||||
|
||||
void ConfigureMouseAdvanced::keyPressEvent(QKeyEvent* event) {
|
||||
|
@@ -5,9 +5,9 @@
|
||||
#pragma once
|
||||
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <QDialog>
|
||||
#include <QWidget>
|
||||
#include <boost/optional.hpp>
|
||||
#include "core/settings.h"
|
||||
|
||||
class QCheckBox;
|
||||
@@ -30,7 +30,7 @@ private:
|
||||
std::unique_ptr<Ui::ConfigureMouseAdvanced> ui;
|
||||
|
||||
/// This will be the the setting function when an input is awaiting configuration.
|
||||
boost::optional<std::function<void(const Common::ParamPackage&)>> input_setter;
|
||||
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;
|
||||
|
@@ -2,15 +2,7 @@
|
||||
// Licensed under GPLv2 or any later version
|
||||
// Refer to the license.txt file included.
|
||||
|
||||
#include <algorithm>
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
#include <QMenu>
|
||||
#include <QMessageBox>
|
||||
#include <QTimer>
|
||||
#include "common/assert.h"
|
||||
#include "common/param_package.h"
|
||||
#include "input_common/main.h"
|
||||
#include "ui_configure_touchscreen_advanced.h"
|
||||
#include "yuzu/configuration/config.h"
|
||||
#include "yuzu/configuration/configure_touchscreen_advanced.h"
|
||||
@@ -22,10 +14,12 @@ ConfigureTouchscreenAdvanced::ConfigureTouchscreenAdvanced(QWidget* parent)
|
||||
connect(ui->restore_defaults_button, &QPushButton::pressed, this,
|
||||
&ConfigureTouchscreenAdvanced::restoreDefaults);
|
||||
|
||||
this->loadConfiguration();
|
||||
this->resize(0, 0);
|
||||
loadConfiguration();
|
||||
resize(0, 0);
|
||||
}
|
||||
|
||||
ConfigureTouchscreenAdvanced::~ConfigureTouchscreenAdvanced() = default;
|
||||
|
||||
void ConfigureTouchscreenAdvanced::applyConfiguration() {
|
||||
Settings::values.touchscreen.finger = ui->finger_box->value();
|
||||
Settings::values.touchscreen.diameter_x = ui->diameter_x_box->value();
|
||||
|
@@ -18,6 +18,7 @@ class ConfigureTouchscreenAdvanced : public QDialog {
|
||||
|
||||
public:
|
||||
explicit ConfigureTouchscreenAdvanced(QWidget* parent);
|
||||
~ConfigureTouchscreenAdvanced() override;
|
||||
|
||||
void applyConfiguration();
|
||||
|
||||
|
Reference in New Issue
Block a user