Merge pull request #7760 from german77/inverted_keyboard

yuzu: Add modifiers for keyboard
merge-requests/60/head
bunnei 2022-01-24 15:41:49 +07:00 committed by GitHub
commit 3442365127
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 34 additions and 25 deletions

@ -147,7 +147,7 @@ QString ConfigureInputPlayer::ButtonToText(const Common::ParamPackage& param) {
// Retrieve the names from Qt // Retrieve the names from Qt
if (param.Get("engine", "") == "keyboard") { if (param.Get("engine", "") == "keyboard") {
const QString button_str = GetKeyName(param.Get("code", 0)); const QString button_str = GetKeyName(param.Get("code", 0));
return QObject::tr("%1%2").arg(toggle, button_str); return QObject::tr("%1%2%3").arg(toggle, inverted, button_str);
} }
if (common_button_name == Common::Input::ButtonNames::Invalid) { if (common_button_name == Common::Input::ButtonNames::Invalid) {
@ -341,7 +341,7 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i
emulated_controller->SetButtonParam(button_id, {}); emulated_controller->SetButtonParam(button_id, {});
button_map[button_id]->setText(tr("[not set]")); button_map[button_id]->setText(tr("[not set]"));
}); });
if (param.Has("button") || param.Has("hat")) { if (param.Has("code") || param.Has("button") || param.Has("hat")) {
context_menu.addAction(tr("Toggle button"), [&] { context_menu.addAction(tr("Toggle button"), [&] {
const bool toggle_value = !param.Get("toggle", false); const bool toggle_value = !param.Get("toggle", false);
param.Set("toggle", toggle_value); param.Set("toggle", toggle_value);
@ -349,8 +349,8 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i
emulated_controller->SetButtonParam(button_id, param); emulated_controller->SetButtonParam(button_id, param);
}); });
context_menu.addAction(tr("Invert button"), [&] { context_menu.addAction(tr("Invert button"), [&] {
const bool toggle_value = !param.Get("inverted", false); const bool invert_value = !param.Get("inverted", false);
param.Set("inverted", toggle_value); param.Set("inverted", invert_value);
button_map[button_id]->setText(ButtonToText(param)); button_map[button_id]->setText(ButtonToText(param));
emulated_controller->SetButtonParam(button_id, param); emulated_controller->SetButtonParam(button_id, param);
}); });
@ -510,28 +510,37 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i
analog_map_modifier_button[analog_id]->setContextMenuPolicy(Qt::CustomContextMenu); analog_map_modifier_button[analog_id]->setContextMenuPolicy(Qt::CustomContextMenu);
connect(analog_map_modifier_button[analog_id], &QPushButton::customContextMenuRequested, connect(
[=, this](const QPoint& menu_location) { analog_map_modifier_button[analog_id], &QPushButton::customContextMenuRequested,
QMenu context_menu; [=, this](const QPoint& menu_location) {
Common::ParamPackage param = emulated_controller->GetStickParam(analog_id); QMenu context_menu;
context_menu.addAction(tr("Clear"), [&] { Common::ParamPackage param = emulated_controller->GetStickParam(analog_id);
param.Set("modifier", ""); context_menu.addAction(tr("Clear"), [&] {
analog_map_modifier_button[analog_id]->setText(tr("[not set]")); param.Set("modifier", "");
emulated_controller->SetStickParam(analog_id, param); analog_map_modifier_button[analog_id]->setText(tr("[not set]"));
}); emulated_controller->SetStickParam(analog_id, param);
context_menu.addAction(tr("Toggle button"), [&] {
Common::ParamPackage modifier_param =
Common::ParamPackage{param.Get("modifier", "")};
const bool toggle_value = !modifier_param.Get("toggle", false);
modifier_param.Set("toggle", toggle_value);
param.Set("modifier", modifier_param.Serialize());
analog_map_modifier_button[analog_id]->setText(
ButtonToText(modifier_param));
emulated_controller->SetStickParam(analog_id, param);
});
context_menu.exec(
analog_map_modifier_button[analog_id]->mapToGlobal(menu_location));
}); });
context_menu.addAction(tr("Toggle button"), [&] {
Common::ParamPackage modifier_param =
Common::ParamPackage{param.Get("modifier", "")};
const bool toggle_value = !modifier_param.Get("toggle", false);
modifier_param.Set("toggle", toggle_value);
param.Set("modifier", modifier_param.Serialize());
analog_map_modifier_button[analog_id]->setText(ButtonToText(modifier_param));
emulated_controller->SetStickParam(analog_id, param);
});
context_menu.addAction(tr("Invert button"), [&] {
Common::ParamPackage modifier_param =
Common::ParamPackage{param.Get("modifier", "")};
const bool invert_value = !modifier_param.Get("inverted", false);
modifier_param.Set("inverted", invert_value);
param.Set("modifier", modifier_param.Serialize());
analog_map_modifier_button[analog_id]->setText(ButtonToText(modifier_param));
emulated_controller->SetStickParam(analog_id, param);
});
context_menu.exec(
analog_map_modifier_button[analog_id]->mapToGlobal(menu_location));
});
connect(analog_map_range_spinbox[analog_id], qOverload<int>(&QSpinBox::valueChanged), connect(analog_map_range_spinbox[analog_id], qOverload<int>(&QSpinBox::valueChanged),
[=, this] { [=, this] {