Automatic Controller Binding (#5100)
* Implement the basics of controller auto mapping. From testing doesn't currenlty work. Opening the controller requires the device index, but it is only known and guaranteed at boot time or when a controller is connected. * Use the SDL_INIT_GAMECONTROLLER flag to initialize the controller subsystem. It automatically initializes the joystick subsystem too, so SDL_INIT_JOYSTICK is not needed. * Implement the SDLGameController class to handle open game controllers. Based on the SDLJoystick implementation. * Address review comments * Changes SDLJoystick and SDLGameController to use a custom default constructible destructor, to improve readability. The only deleters used previously were SDL_JoystickClose and SDL_GameControllerClose, respectively, plus null lambdas. Given that both SDL functions accept null pointers with just an early return, this should be functionally the same. with just an early return * warn the user when a controller mapping is not found * Get axis direction and threshold from SDL_ExtendedGameControllerBind * Reject analog bind if it's not axis, for the couple of examples present in SDL2.0.10's db. Also add SDL_CONTROLLER_BINDTYPE_NONE for the button bind switch, with a better log message. * sdl_impl.cpp: Log the error returned by SDL_GetError upon failure to open joystick * sdl: only use extended binding on SDL2.0.6 and up * sdl_impl.cpp: minor changes
This commit is contained in:
parent
6f2bbbcced
commit
ce16653cc8
7 changed files with 438 additions and 26 deletions
|
@ -276,6 +276,7 @@ ConfigureInput::ConfigureInput(QWidget* parent)
|
|||
|
||||
ui->buttonDelete->setEnabled(ui->profile->count() > 1);
|
||||
|
||||
connect(ui->buttonAutoMap, &QPushButton::clicked, this, &ConfigureInput::AutoMap);
|
||||
connect(ui->buttonClearAll, &QPushButton::clicked, this, &ConfigureInput::ClearAll);
|
||||
connect(ui->buttonRestoreDefaults, &QPushButton::clicked, this,
|
||||
&ConfigureInput::RestoreDefaults);
|
||||
|
@ -440,6 +441,52 @@ void ConfigureInput::UpdateButtonLabels() {
|
|||
EmitInputKeysChanged();
|
||||
}
|
||||
|
||||
void ConfigureInput::MapFromButton(const Common::ParamPackage& params) {
|
||||
Common::ParamPackage aux_param;
|
||||
bool mapped = false;
|
||||
for (int button_id = 0; button_id < Settings::NativeButton::NumButtons; button_id++) {
|
||||
aux_param = InputCommon::GetSDLControllerButtonBindByGUID(params.Get("guid", "0"),
|
||||
params.Get("port", 0), button_id);
|
||||
if (aux_param.Has("engine")) {
|
||||
buttons_param[button_id] = aux_param;
|
||||
mapped = true;
|
||||
}
|
||||
}
|
||||
for (int analog_id = 0; analog_id < Settings::NativeAnalog::NumAnalogs; analog_id++) {
|
||||
aux_param = InputCommon::GetSDLControllerAnalogBindByGUID(params.Get("guid", "0"),
|
||||
params.Get("port", 0), analog_id);
|
||||
if (aux_param.Has("engine")) {
|
||||
analogs_param[analog_id] = aux_param;
|
||||
mapped = true;
|
||||
}
|
||||
}
|
||||
if (!mapped) {
|
||||
QMessageBox::warning(
|
||||
this, tr("Warning"),
|
||||
tr("Auto mapping failed. Your controller may not have a corresponding mapping"));
|
||||
}
|
||||
}
|
||||
|
||||
void ConfigureInput::AutoMap() {
|
||||
if (QMessageBox::information(this, tr("Information"),
|
||||
tr("After pressing OK, press any button on your joystick"),
|
||||
QMessageBox::Ok | QMessageBox::Cancel) == QMessageBox::Cancel) {
|
||||
return;
|
||||
}
|
||||
input_setter = [=](const Common::ParamPackage& params) {
|
||||
MapFromButton(params);
|
||||
ApplyConfiguration();
|
||||
Settings::SaveProfile(ui->profile->currentIndex());
|
||||
};
|
||||
device_pollers = InputCommon::Polling::GetPollers(InputCommon::Polling::DeviceType::Button);
|
||||
want_keyboard_keys = false;
|
||||
for (auto& poller : device_pollers) {
|
||||
poller->Start();
|
||||
}
|
||||
timeout_timer->start(5000); // Cancel after 5 seconds
|
||||
poll_timer->start(200); // Check for new inputs every 200ms
|
||||
}
|
||||
|
||||
void ConfigureInput::HandleClick(QPushButton* button,
|
||||
std::function<void(const Common::ParamPackage&)> new_input_setter,
|
||||
InputCommon::Polling::DeviceType type) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue