mirror of
https://github.com/starr-dusT/yuzu-mainline
synced 2024-03-05 21:12:25 -08:00
input_common: Add property to invert an axis button
This commit is contained in:
parent
46e835f2d6
commit
f017335fef
@ -111,6 +111,8 @@ struct AnalogProperties {
|
|||||||
float offset{};
|
float offset{};
|
||||||
// Invert direction of the sensor data
|
// Invert direction of the sensor data
|
||||||
bool inverted{};
|
bool inverted{};
|
||||||
|
// Invert the state if it's converted to a button
|
||||||
|
bool inverted_button{};
|
||||||
// Press once to activate, press again to release
|
// Press once to activate, press again to release
|
||||||
bool toggle{};
|
bool toggle{};
|
||||||
};
|
};
|
||||||
|
@ -265,7 +265,7 @@ public:
|
|||||||
z = std::sin(roll) * temp + std::cos(roll) * z;
|
z = std::sin(roll) * temp + std::cos(roll) * z;
|
||||||
|
|
||||||
temp = x;
|
temp = x;
|
||||||
x = std::cosf(pitch) * x + std::sin(pitch) * z;
|
x = std::cos(pitch) * x + std::sin(pitch) * z;
|
||||||
z = -std::sin(pitch) * temp + std::cos(pitch) * z;
|
z = -std::sin(pitch) * temp + std::cos(pitch) * z;
|
||||||
|
|
||||||
temp = x;
|
temp = x;
|
||||||
|
@ -54,6 +54,7 @@ Common::Input::ButtonStatus TransformToButton(const Common::Input::CallbackStatu
|
|||||||
case Common::Input::InputType::Analog:
|
case Common::Input::InputType::Analog:
|
||||||
status.value = TransformToTrigger(callback).pressed.value;
|
status.value = TransformToTrigger(callback).pressed.value;
|
||||||
status.toggle = callback.analog_status.properties.toggle;
|
status.toggle = callback.analog_status.properties.toggle;
|
||||||
|
status.inverted = callback.analog_status.properties.inverted_button;
|
||||||
break;
|
break;
|
||||||
case Common::Input::InputType::Trigger:
|
case Common::Input::InputType::Trigger:
|
||||||
status.value = TransformToTrigger(callback).pressed.value;
|
status.value = TransformToTrigger(callback).pressed.value;
|
||||||
|
@ -58,6 +58,8 @@ void InputEngine::SetHatButton(const PadIdentifier& identifier, int button, u8 v
|
|||||||
}
|
}
|
||||||
|
|
||||||
void InputEngine::SetAxis(const PadIdentifier& identifier, int axis, f32 value) {
|
void InputEngine::SetAxis(const PadIdentifier& identifier, int axis, f32 value) {
|
||||||
|
value /= 2.0f;
|
||||||
|
value -= 0.5f;
|
||||||
{
|
{
|
||||||
std::scoped_lock lock{mutex};
|
std::scoped_lock lock{mutex};
|
||||||
ControllerData& controller = controller_list.at(identifier);
|
ControllerData& controller = controller_list.at(identifier);
|
||||||
|
@ -939,6 +939,7 @@ std::unique_ptr<Common::Input::InputDevice> InputFactory::CreateAnalogDevice(
|
|||||||
.threshold = std::clamp(params.Get("threshold", 0.5f), 0.0f, 1.0f),
|
.threshold = std::clamp(params.Get("threshold", 0.5f), 0.0f, 1.0f),
|
||||||
.offset = std::clamp(params.Get("offset", 0.0f), -1.0f, 1.0f),
|
.offset = std::clamp(params.Get("offset", 0.0f), -1.0f, 1.0f),
|
||||||
.inverted = params.Get("invert", "+") == "-",
|
.inverted = params.Get("invert", "+") == "-",
|
||||||
|
.inverted_button = params.Get("inverted", false) != 0,
|
||||||
.toggle = params.Get("toggle", false) != 0,
|
.toggle = params.Get("toggle", false) != 0,
|
||||||
};
|
};
|
||||||
input_engine->PreSetController(identifier);
|
input_engine->PreSetController(identifier);
|
||||||
|
@ -206,7 +206,7 @@ QString ConfigureInputPlayer::ButtonToText(const Common::ParamPackage& param) {
|
|||||||
}
|
}
|
||||||
if (param.Has("axis")) {
|
if (param.Has("axis")) {
|
||||||
const QString axis = QString::fromStdString(param.Get("axis", ""));
|
const QString axis = QString::fromStdString(param.Get("axis", ""));
|
||||||
return QObject::tr("%1%2Axis %3").arg(toggle, invert, axis);
|
return QObject::tr("%1%2%3Axis %4").arg(toggle, inverted, invert, axis);
|
||||||
}
|
}
|
||||||
if (param.Has("axis_x") && param.Has("axis_y") && param.Has("axis_z")) {
|
if (param.Has("axis_x") && param.Has("axis_y") && param.Has("axis_z")) {
|
||||||
const QString axis_x = QString::fromStdString(param.Get("axis_x", ""));
|
const QString axis_x = QString::fromStdString(param.Get("axis_x", ""));
|
||||||
@ -229,7 +229,7 @@ QString ConfigureInputPlayer::ButtonToText(const Common::ParamPackage& param) {
|
|||||||
return QObject::tr("%1%2%3Hat %4").arg(turbo, toggle, inverted, button_name);
|
return QObject::tr("%1%2%3Hat %4").arg(turbo, toggle, inverted, button_name);
|
||||||
}
|
}
|
||||||
if (param.Has("axis")) {
|
if (param.Has("axis")) {
|
||||||
return QObject::tr("%1%2Axis %3").arg(toggle, inverted, button_name);
|
return QObject::tr("%1%2%3Axis %4").arg(toggle, inverted, invert, button_name);
|
||||||
}
|
}
|
||||||
if (param.Has("motion")) {
|
if (param.Has("motion")) {
|
||||||
return QObject::tr("%1%2Axis %3").arg(toggle, inverted, button_name);
|
return QObject::tr("%1%2Axis %3").arg(toggle, inverted, button_name);
|
||||||
@ -410,6 +410,12 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i
|
|||||||
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);
|
||||||
});
|
});
|
||||||
|
context_menu.addAction(tr("Invert button"), [&] {
|
||||||
|
const bool invert_value = !param.Get("inverted", false);
|
||||||
|
param.Set("inverted", invert_value);
|
||||||
|
button_map[button_id]->setText(ButtonToText(param));
|
||||||
|
emulated_controller->SetButtonParam(button_id, param);
|
||||||
|
});
|
||||||
context_menu.addAction(tr("Set threshold"), [&] {
|
context_menu.addAction(tr("Set threshold"), [&] {
|
||||||
const int button_threshold =
|
const int button_threshold =
|
||||||
static_cast<int>(param.Get("threshold", 0.5f) * 100.0f);
|
static_cast<int>(param.Get("threshold", 0.5f) * 100.0f);
|
||||||
|
Loading…
Reference in New Issue
Block a user