Merge pull request #6654 from german77/custom_threshold

input_common: Make button threshold customizable
This commit is contained in:
bunnei 2021-07-21 20:31:33 -04:00 committed by GitHub
commit dff438e219
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 91 additions and 3 deletions

View file

@ -707,7 +707,8 @@ public:
if (params.Has("axis")) { if (params.Has("axis")) {
const int axis = params.Get("axis", 0); const int axis = params.Get("axis", 0);
const float threshold = params.Get("threshold", 0.5f); // Convert range from (0.0, 1.0) to (-1.0, 1.0)
const float threshold = (params.Get("threshold", 0.5f) - 0.5f) * 2.0f;
const std::string direction_name = params.Get("direction", ""); const std::string direction_name = params.Get("direction", "");
bool trigger_if_greater; bool trigger_if_greater;
if (direction_name == "+") { if (direction_name == "+") {
@ -980,12 +981,11 @@ Common::ParamPackage BuildAnalogParamPackageForButton(int port, std::string guid
params.Set("port", port); params.Set("port", port);
params.Set("guid", std::move(guid)); params.Set("guid", std::move(guid));
params.Set("axis", axis); params.Set("axis", axis);
params.Set("threshold", "0.5");
if (value > 0) { if (value > 0) {
params.Set("direction", "+"); params.Set("direction", "+");
params.Set("threshold", "0.5");
} else { } else {
params.Set("direction", "-"); params.Set("direction", "-");
params.Set("threshold", "-0.5");
} }
return params; return params;
} }

View file

@ -314,6 +314,24 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i
buttons_param[button_id].Set("toggle", toggle_value); buttons_param[button_id].Set("toggle", toggle_value);
button_map[button_id]->setText(ButtonToText(buttons_param[button_id])); button_map[button_id]->setText(ButtonToText(buttons_param[button_id]));
}); });
if (buttons_param[button_id].Has("threshold")) {
context_menu.addAction(tr("Set threshold"), [&] {
const int button_threshold = static_cast<int>(
buttons_param[button_id].Get("threshold", 0.5f) * 100.0f);
const int new_threshold = QInputDialog::getInt(
this, tr("Set threshold"), tr("Choose a value between 0% and 100%"),
button_threshold, 0, 100);
buttons_param[button_id].Set("threshold", new_threshold / 100.0f);
if (button_id == Settings::NativeButton::ZL) {
ui->sliderZLThreshold->setValue(new_threshold);
}
if (button_id == Settings::NativeButton::ZR) {
ui->sliderZRThreshold->setValue(new_threshold);
}
});
}
context_menu.exec(button_map[button_id]->mapToGlobal(menu_location)); context_menu.exec(button_map[button_id]->mapToGlobal(menu_location));
ui->controllerFrame->SetPlayerInput(player_index, buttons_param, analogs_param); ui->controllerFrame->SetPlayerInput(player_index, buttons_param, analogs_param);
}); });
@ -342,6 +360,20 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i
}); });
} }
connect(ui->sliderZLThreshold, &QSlider::valueChanged, [=, this] {
if (buttons_param[Settings::NativeButton::ZL].Has("threshold")) {
const auto slider_value = ui->sliderZLThreshold->value();
buttons_param[Settings::NativeButton::ZL].Set("threshold", slider_value / 100.0f);
}
});
connect(ui->sliderZRThreshold, &QSlider::valueChanged, [=, this] {
if (buttons_param[Settings::NativeButton::ZR].Has("threshold")) {
const auto slider_value = ui->sliderZRThreshold->value();
buttons_param[Settings::NativeButton::ZR].Set("threshold", slider_value / 100.0f);
}
});
for (int analog_id = 0; analog_id < Settings::NativeAnalog::NumAnalogs; ++analog_id) { for (int analog_id = 0; analog_id < Settings::NativeAnalog::NumAnalogs; ++analog_id) {
for (int sub_button_id = 0; sub_button_id < ANALOG_SUB_BUTTONS_NUM; ++sub_button_id) { for (int sub_button_id = 0; sub_button_id < ANALOG_SUB_BUTTONS_NUM; ++sub_button_id) {
auto* const analog_button = analog_map_buttons[analog_id][sub_button_id]; auto* const analog_button = analog_map_buttons[analog_id][sub_button_id];
@ -850,6 +882,18 @@ void ConfigureInputPlayer::UpdateUI() {
button_map[button]->setText(ButtonToText(buttons_param[button])); button_map[button]->setText(ButtonToText(buttons_param[button]));
} }
if (buttons_param[Settings::NativeButton::ZL].Has("threshold")) {
const int button_threshold = static_cast<int>(
buttons_param[Settings::NativeButton::ZL].Get("threshold", 0.5f) * 100.0f);
ui->sliderZLThreshold->setValue(button_threshold);
}
if (buttons_param[Settings::NativeButton::ZR].Has("threshold")) {
const int button_threshold = static_cast<int>(
buttons_param[Settings::NativeButton::ZR].Get("threshold", 0.5f) * 100.0f);
ui->sliderZRThreshold->setValue(button_threshold);
}
for (int motion_id = 0; motion_id < Settings::NativeMotion::NumMotions; ++motion_id) { for (int motion_id = 0; motion_id < Settings::NativeMotion::NumMotions; ++motion_id) {
motion_map[motion_id]->setText(ButtonToText(motions_param[motion_id])); motion_map[motion_id]->setText(ButtonToText(motions_param[motion_id]));
} }

View file

@ -1334,6 +1334,12 @@
</item> </item>
<item> <item>
<widget class="QGroupBox" name="buttonShoulderButtonsButtonZLGroup"> <widget class="QGroupBox" name="buttonShoulderButtonsButtonZLGroup">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="title"> <property name="title">
<string>ZL</string> <string>ZL</string>
</property> </property>
@ -1378,6 +1384,22 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QSlider" name="sliderZLThreshold">
<property name="maximumSize">
<size>
<width>70</width>
<height>15</height>
</size>
</property>
<property name="maximum">
<number>100</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
</layout> </layout>
</widget> </widget>
</item> </item>
@ -1759,6 +1781,12 @@
</item> </item>
<item> <item>
<widget class="QGroupBox" name="buttonShoulderButtonsZRGroup"> <widget class="QGroupBox" name="buttonShoulderButtonsZRGroup">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="title"> <property name="title">
<string>ZR</string> <string>ZR</string>
</property> </property>
@ -1803,6 +1831,22 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<widget class="QSlider" name="sliderZRThreshold">
<property name="maximumSize">
<size>
<width>70</width>
<height>15</height>
</size>
</property>
<property name="maximum">
<number>100</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
</layout> </layout>
</widget> </widget>
</item> </item>