From 6b7a51d73e09b477c3c9e6ac91a70d857b7135f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Thu, 2 Feb 2023 10:29:16 +0100 Subject: [PATCH] Move tilt type selector into the customization dialog --- UI/GameSettingsScreen.cpp | 10 ---------- UI/TiltAnalogSettingsScreen.cpp | 25 ++++++++++++++++++++----- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/UI/GameSettingsScreen.cpp b/UI/GameSettingsScreen.cpp index 276ee7cda3..73ddad201d 100644 --- a/UI/GameSettingsScreen.cpp +++ b/UI/GameSettingsScreen.cpp @@ -694,9 +694,6 @@ void GameSettingsScreen::CreateControlsSettings(UI::ViewGroup *controlsSettings) if (System_GetPropertyInt(SYSPROP_DEVICE_TYPE) == DEVICE_TYPE_MOBILE) { controlsSettings->Add(new CheckBox(&g_Config.bHapticFeedback, co->T("HapticFeedback", "Haptic Feedback (vibration)"))); - static const char *tiltTypes[] = { "None (Disabled)", "Analog Stick", "D-PAD", "PSP Action Buttons", "L/R Trigger Buttons" }; - controlsSettings->Add(new PopupMultiChoice(&g_Config.iTiltInputType, co->T("Tilt Input Type"), tiltTypes, 0, ARRAY_SIZE(tiltTypes), co->GetName(), screenManager()))->OnClick.Handle(this, &GameSettingsScreen::OnTiltTypeChange); - Choice *customizeTilt = controlsSettings->Add(new Choice(co->T("Customize tilt"))); customizeTilt->OnClick.Handle(this, &GameSettingsScreen::OnTiltCustomize); customizeTilt->SetEnabledFunc([] { @@ -1709,13 +1706,6 @@ UI::EventReturn GameSettingsScreen::OnTouchControlLayout(UI::EventParams &e) { return UI::EVENT_DONE; } -//when the tilt event type is modified, we need to reset all tilt settings. -//refer to the ResetTiltEvents() function for a detailed explanation. -UI::EventReturn GameSettingsScreen::OnTiltTypeChange(UI::EventParams &e) { - TiltEventProcessor::ResetTiltEvents(); - return UI::EVENT_DONE; -}; - UI::EventReturn GameSettingsScreen::OnTiltCustomize(UI::EventParams &e) { screenManager()->push(new TiltAnalogSettingsScreen(gamePath_)); return UI::EVENT_DONE; diff --git a/UI/TiltAnalogSettingsScreen.cpp b/UI/TiltAnalogSettingsScreen.cpp index c5827c4394..16246ae098 100644 --- a/UI/TiltAnalogSettingsScreen.cpp +++ b/UI/TiltAnalogSettingsScreen.cpp @@ -83,10 +83,24 @@ void TiltAnalogSettingsScreen::CreateViews() { } } + auto enabledFunc = [=]() -> bool { + return g_Config.iTiltInputType != 0; + }; + LinearLayout *settings = new LinearLayoutList(ORIENT_VERTICAL); settings->SetSpacing(0); + static const char *tiltTypes[] = { "None (Disabled)", "Analog Stick", "D-PAD", "PSP Action Buttons", "L/R Trigger Buttons" }; + settings->Add(new PopupMultiChoice(&g_Config.iTiltInputType, co->T("Tilt Input Type"), tiltTypes, 0, ARRAY_SIZE(tiltTypes), co->GetName(), screenManager()))->OnChoice.Add( + [=](UI::EventParams &p) { + //when the tilt event type is modified, we need to reset all tilt settings. + //refer to the ResetTiltEvents() function for a detailed explanation. + TiltEventProcessor::ResetTiltEvents(); + RecreateViews(); + return UI::EVENT_DONE; + }); + settings->Add(new ItemHeader(co->T("Calibration"))); TextView *calibrationInfo = new TextView(co->T("To Calibrate", "Hold device at your preferred angle and press Calibrate.")); calibrationInfo->SetSmall(true); @@ -94,16 +108,17 @@ void TiltAnalogSettingsScreen::CreateViews() { settings->Add(calibrationInfo); Choice *calibrate = new Choice(co->T("Calibrate")); calibrate->OnClick.Handle(this, &TiltAnalogSettingsScreen::OnCalibrate); + calibrate->SetEnabledFunc(enabledFunc); settings->Add(calibrate); settings->Add(new ItemHeader(co->T("Invert Axes"))); - settings->Add(new CheckBox(&g_Config.bInvertTiltX, co->T("Invert Tilt along X axis"))); - settings->Add(new CheckBox(&g_Config.bInvertTiltY, co->T("Invert Tilt along Y axis"))); + settings->Add(new CheckBox(&g_Config.bInvertTiltX, co->T("Invert Tilt along X axis")))->SetEnabledFunc(enabledFunc); + settings->Add(new CheckBox(&g_Config.bInvertTiltY, co->T("Invert Tilt along Y axis")))->SetEnabledFunc(enabledFunc); settings->Add(new ItemHeader(co->T("Sensitivity"))); - settings->Add(new PopupSliderChoice(&g_Config.iTiltSensitivityX, 0, 100, co->T("Tilt Sensitivity along X axis"), screenManager(), "%")); - settings->Add(new PopupSliderChoice(&g_Config.iTiltSensitivityY, 0, 100, co->T("Tilt Sensitivity along Y axis"), screenManager(), "%")); - settings->Add(new PopupSliderChoiceFloat(&g_Config.fDeadzoneRadius, 0.0, 1.0, co->T("Deadzone radius"), 0.01f, screenManager(), "/ 1.0")); + settings->Add(new PopupSliderChoice(&g_Config.iTiltSensitivityX, 0, 100, co->T("Tilt Sensitivity along X axis"), screenManager(), "%"))->SetEnabledFunc(enabledFunc); + settings->Add(new PopupSliderChoice(&g_Config.iTiltSensitivityY, 0, 100, co->T("Tilt Sensitivity along Y axis"), screenManager(), "%"))->SetEnabledFunc(enabledFunc); + settings->Add(new PopupSliderChoiceFloat(&g_Config.fDeadzoneRadius, 0.0, 1.0, co->T("Deadzone radius"), 0.01f, screenManager(), "/ 1.0"))->SetEnabledFunc(enabledFunc); menuRoot->Add(settings);