mirror of
https://github.com/yuzu-emu/yuzu-android.git
synced 2025-07-07 03:48:01 -05:00
Include HID and configuration changes related to motion
This commit is contained in:
@ -36,6 +36,11 @@ const std::array<int, Settings::NativeButton::NumButtons> Config::default_button
|
||||
Qt::Key_H, Qt::Key_G, Qt::Key_D, Qt::Key_C, Qt::Key_B, Qt::Key_V,
|
||||
};
|
||||
|
||||
const std::array<int, Settings::NativeMotion::NumMotions> Config::default_motions = {
|
||||
Qt::Key_7,
|
||||
Qt::Key_8,
|
||||
};
|
||||
|
||||
const std::array<std::array<int, 4>, Settings::NativeAnalog::NumAnalogs> Config::default_analogs{{
|
||||
{
|
||||
Qt::Key_Up,
|
||||
@ -284,6 +289,22 @@ void Config::ReadPlayerValues() {
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < Settings::NativeMotion::NumMotions; ++i) {
|
||||
const std::string default_param =
|
||||
InputCommon::GenerateKeyboardParam(default_motions[i]);
|
||||
auto& player_motions = player.motions[i];
|
||||
|
||||
player_motions = qt_config
|
||||
->value(QStringLiteral("player_%1_").arg(p) +
|
||||
QString::fromUtf8(Settings::NativeMotion::mapping[i]),
|
||||
QString::fromStdString(default_param))
|
||||
.toString()
|
||||
.toStdString();
|
||||
if (player_motions.empty()) {
|
||||
player_motions = default_param;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < Settings::NativeAnalog::NumAnalogs; ++i) {
|
||||
const std::string default_param = InputCommon::GenerateAnalogParamFromKeys(
|
||||
default_analogs[i][0], default_analogs[i][1], default_analogs[i][2],
|
||||
@ -922,6 +943,14 @@ void Config::SavePlayerValues() {
|
||||
QString::fromStdString(player.buttons[i]),
|
||||
QString::fromStdString(default_param));
|
||||
}
|
||||
for (int i = 0; i < Settings::NativeMotion::NumMotions; ++i) {
|
||||
const std::string default_param =
|
||||
InputCommon::GenerateKeyboardParam(default_motions[i]);
|
||||
WriteSetting(QStringLiteral("player_%1_").arg(p) +
|
||||
QString::fromStdString(Settings::NativeMotion::mapping[i]),
|
||||
QString::fromStdString(player.motions[i]),
|
||||
QString::fromStdString(default_param));
|
||||
}
|
||||
for (int i = 0; i < Settings::NativeAnalog::NumAnalogs; ++i) {
|
||||
const std::string default_param = InputCommon::GenerateAnalogParamFromKeys(
|
||||
default_analogs[i][0], default_analogs[i][1], default_analogs[i][2],
|
||||
|
@ -23,6 +23,7 @@ public:
|
||||
void Save();
|
||||
|
||||
static const std::array<int, Settings::NativeButton::NumButtons> default_buttons;
|
||||
static const std::array<int, Settings::NativeMotion::NumMotions> default_motions;
|
||||
static const std::array<std::array<int, 4>, Settings::NativeAnalog::NumAnalogs> default_analogs;
|
||||
static const std::array<int, 2> default_stick_mod;
|
||||
static const std::array<int, Settings::NativeMouseButton::NumMouseButtons>
|
||||
|
@ -262,6 +262,11 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i
|
||||
},
|
||||
}};
|
||||
|
||||
motion_map = {
|
||||
ui->buttonMotionLeft,
|
||||
ui->buttonMotionRight,
|
||||
};
|
||||
|
||||
analog_map_deadzone_label = {ui->labelLStickDeadzone, ui->labelRStickDeadzone};
|
||||
analog_map_deadzone_slider = {ui->sliderLStickDeadzone, ui->sliderRStickDeadzone};
|
||||
analog_map_modifier_groupbox = {ui->buttonLStickModGroup, ui->buttonRStickModGroup};
|
||||
@ -304,6 +309,37 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i
|
||||
Config::default_buttons[button_id]);
|
||||
}
|
||||
|
||||
for (int motion_id = 0; motion_id < Settings::NativeMotion::NumMotions; ++motion_id) {
|
||||
auto* const button = motion_map[motion_id];
|
||||
if (button == nullptr) {
|
||||
continue;
|
||||
}
|
||||
|
||||
button->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
connect(button, &QPushButton::clicked, [=, this] {
|
||||
HandleClick(
|
||||
motion_map[motion_id],
|
||||
[=, this](Common::ParamPackage params) {
|
||||
motions_param[motion_id] = std::move(params);
|
||||
},
|
||||
InputCommon::Polling::DeviceType::Motion);
|
||||
});
|
||||
connect(button, &QPushButton::customContextMenuRequested,
|
||||
[=, this](const QPoint& menu_location) {
|
||||
QMenu context_menu;
|
||||
context_menu.addAction(tr("Clear"), [&] {
|
||||
motions_param[motion_id].Clear();
|
||||
motion_map[motion_id]->setText(tr("[not set]"));
|
||||
});
|
||||
context_menu.addAction(tr("Restore Default"), [&] {
|
||||
motions_param[motion_id] = Common::ParamPackage{
|
||||
InputCommon::GenerateKeyboardParam(Config::default_motions[motion_id])};
|
||||
motion_map[motion_id]->setText(ButtonToText(motions_param[motion_id]));
|
||||
});
|
||||
context_menu.exec(motion_map[motion_id]->mapToGlobal(menu_location));
|
||||
});
|
||||
}
|
||||
|
||||
// Handle clicks for the modifier buttons as well.
|
||||
ConfigureButtonClick(ui->buttonLStickMod, &lstick_mod, Config::default_stick_mod[0]);
|
||||
ConfigureButtonClick(ui->buttonRStickMod, &rstick_mod, Config::default_stick_mod[1]);
|
||||
@ -448,6 +484,10 @@ void ConfigureInputPlayer::ApplyConfiguration() {
|
||||
return;
|
||||
}
|
||||
|
||||
auto& motions = player.motions;
|
||||
std::transform(motions_param.begin(), motions_param.end(), motions.begin(),
|
||||
[](const Common::ParamPackage& param) { return param.Serialize(); });
|
||||
|
||||
player.controller_type =
|
||||
static_cast<Settings::ControllerType>(ui->comboControllerType->currentIndex());
|
||||
player.connected = ui->groupConnectedController->isChecked();
|
||||
@ -501,6 +541,8 @@ void ConfigureInputPlayer::LoadConfiguration() {
|
||||
[](const std::string& str) { return Common::ParamPackage(str); });
|
||||
std::transform(player.analogs.begin(), player.analogs.end(), analogs_param.begin(),
|
||||
[](const std::string& str) { return Common::ParamPackage(str); });
|
||||
std::transform(player.motions.begin(), player.motions.end(), motions_param.begin(),
|
||||
[](const std::string& str) { return Common::ParamPackage(str); });
|
||||
}
|
||||
|
||||
UpdateUI();
|
||||
@ -544,6 +586,12 @@ void ConfigureInputPlayer::RestoreDefaults() {
|
||||
SetAnalogParam(params, analogs_param[analog_id], analog_sub_buttons[sub_button_id]);
|
||||
}
|
||||
}
|
||||
|
||||
for (int motion_id = 0; motion_id < Settings::NativeMotion::NumMotions; ++motion_id) {
|
||||
motions_param[motion_id] = Common::ParamPackage{
|
||||
InputCommon::GenerateKeyboardParam(Config::default_motions[motion_id])};
|
||||
}
|
||||
|
||||
UpdateUI();
|
||||
UpdateInputDevices();
|
||||
ui->comboControllerType->setCurrentIndex(0);
|
||||
@ -573,6 +621,15 @@ void ConfigureInputPlayer::ClearAll() {
|
||||
}
|
||||
}
|
||||
|
||||
for (int motion_id = 0; motion_id < Settings::NativeMotion::NumMotions; ++motion_id) {
|
||||
const auto* const button = motion_map[motion_id];
|
||||
if (button == nullptr || !button->isEnabled()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
motions_param[motion_id].Clear();
|
||||
}
|
||||
|
||||
UpdateUI();
|
||||
UpdateInputDevices();
|
||||
}
|
||||
@ -582,6 +639,10 @@ void ConfigureInputPlayer::UpdateUI() {
|
||||
button_map[button]->setText(ButtonToText(buttons_param[button]));
|
||||
}
|
||||
|
||||
for (int motion_id = 0; motion_id < Settings::NativeMotion::NumMotions; ++motion_id) {
|
||||
motion_map[motion_id]->setText(ButtonToText(motions_param[motion_id]));
|
||||
}
|
||||
|
||||
ui->buttonLStickMod->setText(ButtonToText(lstick_mod));
|
||||
ui->buttonRStickMod->setText(ButtonToText(rstick_mod));
|
||||
|
||||
|
@ -128,11 +128,14 @@ private:
|
||||
|
||||
std::array<Common::ParamPackage, Settings::NativeButton::NumButtons> buttons_param;
|
||||
std::array<Common::ParamPackage, Settings::NativeAnalog::NumAnalogs> analogs_param;
|
||||
std::array<Common::ParamPackage, Settings::NativeMotion::NumMotions> motions_param;
|
||||
|
||||
static constexpr int ANALOG_SUB_BUTTONS_NUM = 4;
|
||||
|
||||
/// Each button input is represented by a QPushButton.
|
||||
std::array<QPushButton*, Settings::NativeButton::NumButtons> button_map;
|
||||
/// Each motion input is represented by a QPushButton.
|
||||
std::array<QPushButton*, Settings::NativeMotion::NumMotions> motion_map;
|
||||
/// Extra buttons for the modifiers.
|
||||
Common::ParamPackage lstick_mod;
|
||||
Common::ParamPackage rstick_mod;
|
||||
|
@ -2264,6 +2264,105 @@
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
|
||||
<item alignment="Qt::AlignHCenter">
|
||||
<widget class="QGroupBox" name="buttonMotionLeftGroup">
|
||||
<property name="title">
|
||||
<string>Motion left</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="buttonMotionLeftVerticalLayout">
|
||||
<property name="spacing">
|
||||
<number>3</number>
|
||||
</property>
|
||||
<property name="leftMargin">
|
||||
<number>3</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>3</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>3</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>3</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QPushButton" name="buttonMotionLeft">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>57</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>55</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">min-width: 55px;</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Motion left</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item alignment="Qt::AlignHCenter">
|
||||
<widget class="QGroupBox" name="buttonMotionRightGroup">
|
||||
<property name="title">
|
||||
<string>Motion right</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="buttonMotionRightVerticalLayout">
|
||||
<property name="spacing">
|
||||
<number>3</number>
|
||||
</property>
|
||||
<property name="leftMargin">
|
||||
<number>3</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>3</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>3</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>3</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QPushButton" name="buttonMotionRight">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>57</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>55</width>
|
||||
<height>16777215</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">min-width: 55px;</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Motion right</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
|
Reference in New Issue
Block a user