sdl_impl: Revert to the "old" method of mapping sticks
Not all controllers have a SDL_GameController binding. This caused controllers not present in the SDL GameController database to have buttons mapped instead of axes. Furthermore, it was not possible to invert the axes when it could be useful such as emulating a horizontal single joycon or other potential cases. This allows us to invert the axes by reversing the order of mapping (vertical, then horizontal).
This commit is contained in:
parent
760a9e8693
commit
117bdc71e0
|
@ -1068,7 +1068,6 @@ public:
|
||||||
|
|
||||||
void Start(const std::string& device_id) override {
|
void Start(const std::string& device_id) override {
|
||||||
SDLPoller::Start(device_id);
|
SDLPoller::Start(device_id);
|
||||||
// Load the game controller
|
|
||||||
// Reset stored axes
|
// Reset stored axes
|
||||||
analog_x_axis = -1;
|
analog_x_axis = -1;
|
||||||
analog_y_axis = -1;
|
analog_y_axis = -1;
|
||||||
|
@ -1081,40 +1080,21 @@ public:
|
||||||
if (event.type == SDL_JOYAXISMOTION && std::abs(event.jaxis.value / 32767.0) < 0.5) {
|
if (event.type == SDL_JOYAXISMOTION && std::abs(event.jaxis.value / 32767.0) < 0.5) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// Simplify controller config by testing if game controller support is enabled.
|
|
||||||
if (event.type == SDL_JOYAXISMOTION) {
|
if (event.type == SDL_JOYAXISMOTION) {
|
||||||
const auto axis = event.jaxis.axis;
|
const auto axis = event.jaxis.axis;
|
||||||
if (const auto joystick = state.GetSDLJoystickBySDLID(event.jaxis.which);
|
// In order to return a complete analog param, we need inputs for both axes.
|
||||||
auto* const controller = joystick->GetSDLGameController()) {
|
// First we take the x-axis (horizontal) input, then the y-axis (vertical) input.
|
||||||
const auto axis_left_x =
|
if (analog_x_axis == -1) {
|
||||||
SDL_GameControllerGetBindForAxis(controller, SDL_CONTROLLER_AXIS_LEFTX)
|
analog_x_axis = axis;
|
||||||
.value.axis;
|
} else if (analog_y_axis == -1 && analog_x_axis != axis) {
|
||||||
const auto axis_left_y =
|
analog_y_axis = axis;
|
||||||
SDL_GameControllerGetBindForAxis(controller, SDL_CONTROLLER_AXIS_LEFTY)
|
}
|
||||||
.value.axis;
|
} else {
|
||||||
const auto axis_right_x =
|
// If the press wasn't accepted as a joy axis, check for a button press
|
||||||
SDL_GameControllerGetBindForAxis(controller, SDL_CONTROLLER_AXIS_RIGHTX)
|
auto button_press = button_poller.FromEvent(event);
|
||||||
.value.axis;
|
if (button_press) {
|
||||||
const auto axis_right_y =
|
return *button_press;
|
||||||
SDL_GameControllerGetBindForAxis(controller, SDL_CONTROLLER_AXIS_RIGHTY)
|
|
||||||
.value.axis;
|
|
||||||
|
|
||||||
if (axis == axis_left_x || axis == axis_left_y) {
|
|
||||||
analog_x_axis = axis_left_x;
|
|
||||||
analog_y_axis = axis_left_y;
|
|
||||||
break;
|
|
||||||
} else if (axis == axis_right_x || axis == axis_right_y) {
|
|
||||||
analog_x_axis = axis_right_x;
|
|
||||||
analog_y_axis = axis_right_y;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// If the press wasn't accepted as a joy axis, check for a button press
|
|
||||||
auto button_press = button_poller.FromEvent(event);
|
|
||||||
if (button_press) {
|
|
||||||
return *button_press;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1127,6 +1107,7 @@ public:
|
||||||
return params;
|
return params;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -370,6 +370,18 @@ ConfigureInputPlayer::ConfigureInputPlayer(QWidget* parent, std::size_t player_i
|
||||||
}
|
}
|
||||||
|
|
||||||
connect(analog_button, &QPushButton::clicked, [=, this] {
|
connect(analog_button, &QPushButton::clicked, [=, this] {
|
||||||
|
if (!map_analog_stick_accepted) {
|
||||||
|
map_analog_stick_accepted =
|
||||||
|
QMessageBox::information(
|
||||||
|
this, tr("Map Analog Stick"),
|
||||||
|
tr("After pressing OK, first move your joystick horizontally, and then "
|
||||||
|
"vertically.\nTo invert the axes, first move your joystick "
|
||||||
|
"vertically, and then horizontally."),
|
||||||
|
QMessageBox::Ok | QMessageBox::Cancel) == QMessageBox::Ok;
|
||||||
|
if (!map_analog_stick_accepted) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
HandleClick(
|
HandleClick(
|
||||||
analog_map_buttons[analog_id][sub_button_id],
|
analog_map_buttons[analog_id][sub_button_id],
|
||||||
[=, this](const Common::ParamPackage& params) {
|
[=, this](const Common::ParamPackage& params) {
|
||||||
|
|
|
@ -181,9 +181,12 @@ private:
|
||||||
|
|
||||||
std::vector<std::unique_ptr<InputCommon::Polling::DevicePoller>> device_pollers;
|
std::vector<std::unique_ptr<InputCommon::Polling::DevicePoller>> device_pollers;
|
||||||
|
|
||||||
|
/// A flag to indicate that the "Map Analog Stick" pop-up has been shown and accepted once.
|
||||||
|
bool map_analog_stick_accepted{};
|
||||||
|
|
||||||
/// A flag to indicate if keyboard keys are okay when configuring an input. If this is false,
|
/// A flag to indicate if keyboard keys are okay when configuring an input. If this is false,
|
||||||
/// keyboard events are ignored.
|
/// keyboard events are ignored.
|
||||||
bool want_keyboard_mouse = false;
|
bool want_keyboard_mouse{};
|
||||||
|
|
||||||
/// List of physical devices users can map with. If a SDL backed device is selected, then you
|
/// List of physical devices users can map with. If a SDL backed device is selected, then you
|
||||||
/// can use this device to get a default mapping.
|
/// can use this device to get a default mapping.
|
||||||
|
|
Loading…
Reference in New Issue