configure_input_player: Change "Defaults" button behavior

RestoreDefaults() now restores the selected devices' mappings using UpdateMappingWithDefaults().
This allows us to move the keyboard mapping from RestoreDefaults() to UpdateMappingWithDefaults().
This commit is contained in:
Morph 2020-09-28 10:27:29 -04:00
parent 8f2959f680
commit ceb7b11f16
2 changed files with 30 additions and 35 deletions

View file

@ -96,10 +96,6 @@ struct InputSubsystem::Impl {
if (!params.Has("class") || params.Get("class", "") == "any") { if (!params.Has("class") || params.Get("class", "") == "any") {
return {}; return {};
} }
if (params.Get("class", "") == "keyboard") {
// TODO consider returning the SDL key codes for the default keybindings
return {};
}
if (params.Get("class", "") == "gcpad") { if (params.Get("class", "") == "gcpad") {
return gcadapter->GetAnalogMappingForDevice(params); return gcadapter->GetAnalogMappingForDevice(params);
} }
@ -116,10 +112,6 @@ struct InputSubsystem::Impl {
if (!params.Has("class") || params.Get("class", "") == "any") { if (!params.Has("class") || params.Get("class", "") == "any") {
return {}; return {};
} }
if (params.Get("class", "") == "keyboard") {
// TODO consider returning the SDL key codes for the default keybindings
return {};
}
if (params.Get("class", "") == "gcpad") { if (params.Get("class", "") == "gcpad") {
return gcadapter->GetButtonMappingForDevice(params); return gcadapter->GetButtonMappingForDevice(params);
} }

View file

@ -693,32 +693,7 @@ void ConfigureInputPlayer::UpdateInputDeviceCombobox() {
} }
void ConfigureInputPlayer::RestoreDefaults() { void ConfigureInputPlayer::RestoreDefaults() {
// Reset Buttons UpdateMappingWithDefaults();
for (int button_id = 0; button_id < Settings::NativeButton::NumButtons; ++button_id) {
buttons_param[button_id] = Common::ParamPackage{
InputCommon::GenerateKeyboardParam(Config::default_buttons[button_id])};
}
// Reset Analogs and Modifier Buttons
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) {
Common::ParamPackage params{InputCommon::GenerateKeyboardParam(
Config::default_analogs[analog_id][sub_button_id])};
SetAnalogParam(params, analogs_param[analog_id], analog_sub_buttons[sub_button_id]);
}
analogs_param[analog_id].Set(
"modifier", InputCommon::GenerateKeyboardParam(Config::default_stick_mod[analog_id]));
}
for (int motion_id = 0; motion_id < Settings::NativeMotion::NumMotions; ++motion_id) {
motions_param[motion_id] = Common::ParamPackage{
InputCommon::GenerateKeyboardParam(Config::default_motions[motion_id])};
}
UpdateUI();
UpdateInputDeviceCombobox();
ui->comboControllerType->setCurrentIndex(0);
} }
void ConfigureInputPlayer::ClearAll() { void ConfigureInputPlayer::ClearAll() {
@ -951,9 +926,37 @@ void ConfigureInputPlayer::UpdateMotionButtons() {
} }
void ConfigureInputPlayer::UpdateMappingWithDefaults() { void ConfigureInputPlayer::UpdateMappingWithDefaults() {
if (ui->comboDevices->currentIndex() < 2) { if (ui->comboDevices->currentIndex() == 0) {
return; return;
} }
if (ui->comboDevices->currentIndex() == 1) {
// Reset keyboard bindings
for (int button_id = 0; button_id < Settings::NativeButton::NumButtons; ++button_id) {
buttons_param[button_id] = Common::ParamPackage{
InputCommon::GenerateKeyboardParam(Config::default_buttons[button_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) {
Common::ParamPackage params{InputCommon::GenerateKeyboardParam(
Config::default_analogs[analog_id][sub_button_id])};
SetAnalogParam(params, analogs_param[analog_id], analog_sub_buttons[sub_button_id]);
}
analogs_param[analog_id].Set("modifier", InputCommon::GenerateKeyboardParam(
Config::default_stick_mod[analog_id]));
}
for (int motion_id = 0; motion_id < Settings::NativeMotion::NumMotions; ++motion_id) {
motions_param[motion_id] = Common::ParamPackage{
InputCommon::GenerateKeyboardParam(Config::default_motions[motion_id])};
}
UpdateUI();
return;
}
// Reset controller bindings
const auto& device = input_devices[ui->comboDevices->currentIndex()]; const auto& device = input_devices[ui->comboDevices->currentIndex()];
auto button_mapping = input_subsystem->GetButtonMappingForDevice(device); auto button_mapping = input_subsystem->GetButtonMappingForDevice(device);
auto analog_mapping = input_subsystem->GetAnalogMappingForDevice(device); auto analog_mapping = input_subsystem->GetAnalogMappingForDevice(device);