From 64da0f54e416c413d7075e973d4e403a8690d76e Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 20 Dec 2015 23:16:45 -0800 Subject: [PATCH] Add L/R trigger button tilt support. --- UI/GameSettingsScreen.cpp | 2 +- UI/TiltEventProcessor.cpp | 23 +++++++++++++++++++++++ UI/TiltEventProcessor.h | 6 ++++-- 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/UI/GameSettingsScreen.cpp b/UI/GameSettingsScreen.cpp index e3783bfb3f..cdcfe4aff3 100644 --- a/UI/GameSettingsScreen.cpp +++ b/UI/GameSettingsScreen.cpp @@ -387,7 +387,7 @@ void GameSettingsScreen::CreateViews() { #if defined(MOBILE_DEVICE) 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"}; + 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"))); diff --git a/UI/TiltEventProcessor.cpp b/UI/TiltEventProcessor.cpp index 48a76ea21d..8638859934 100644 --- a/UI/TiltEventProcessor.cpp +++ b/UI/TiltEventProcessor.cpp @@ -89,6 +89,10 @@ void TiltEventProcessor::TranslateTiltToInput(const Tilt &tilt) { case TILT_ACTION_BUTTON: GenerateActionButtonEvent(tilt); break; + + case TILT_TRIGGER_BUTTON: + GenerateTriggerButtonEvent(tilt); + break; } } @@ -154,6 +158,25 @@ void TiltEventProcessor::GenerateActionButtonEvent(const Tilt &tilt) { tiltButtonsDown |= buttons[direction]; } +void TiltEventProcessor::GenerateTriggerButtonEvent(const Tilt &tilt) { + u32 upButtons = 0; + u32 downButtons = 0; + // KISS, let's only look at X. Expect deadzone to already be applied. + if (tilt.x_ == 0.0f) { + upButtons = CTRL_LTRIGGER | CTRL_RTRIGGER; + } else if (tilt.x_ < 0.0f) { + downButtons = CTRL_LTRIGGER; + upButtons = CTRL_RTRIGGER; + } else if (tilt.x_ > 0.0f) { + downButtons = CTRL_RTRIGGER; + upButtons = CTRL_LTRIGGER; + } + + __CtrlButtonUp(upButtons); + __CtrlButtonDown(downButtons); + tiltButtonsDown = (tiltButtonsDown & ~upButtons) | downButtons; +} + void TiltEventProcessor::ResetTiltEvents() { // Reset the buttons we have marked pressed. __CtrlButtonUp(tiltButtonsDown); diff --git a/UI/TiltEventProcessor.h b/UI/TiltEventProcessor.h index 4d42d79d94..8f916d2077 100644 --- a/UI/TiltEventProcessor.h +++ b/UI/TiltEventProcessor.h @@ -6,7 +6,8 @@ namespace TiltEventProcessor { TILT_NULL = 0, TILT_ANALOG, TILT_DPAD, - TILT_ACTION_BUTTON + TILT_ACTION_BUTTON, + TILT_TRIGGER_BUTTON, }; @@ -33,7 +34,8 @@ namespace TiltEventProcessor { //and the deadzone radius. void GenerateAnalogStickEvent(const Tilt &tilt); void GenerateDPadEvent(const Tilt &tilt); - void GenerateActionButtonEvent(const Tilt &tilt); + void GenerateActionButtonEvent(const Tilt &tilt); + void GenerateTriggerButtonEvent(const Tilt &tilt); void ResetTiltEvents();