From ba6485d1cde811da3ecb58f7475eea0778034d6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gon=C3=A7alo=20Marques?= Date: Tue, 18 May 2021 12:56:05 +0100 Subject: [PATCH 1/3] Allow overriding UseLeftThumbstickAsMouse from UINavPC --- Source/UINavigation/Private/UINavPCComponent.cpp | 4 ++-- Source/UINavigation/Private/UINavWidget.cpp | 5 ++++- Source/UINavigation/Public/UINavPCComponent.h | 7 +++++++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/Source/UINavigation/Private/UINavPCComponent.cpp b/Source/UINavigation/Private/UINavPCComponent.cpp index 4206ea50..940d4403 100644 --- a/Source/UINavigation/Private/UINavPCComponent.cpp +++ b/Source/UINavigation/Private/UINavPCComponent.cpp @@ -472,8 +472,8 @@ void UUINavPCComponent::HandleAnalogInputEvent(FSlateApplication& SlateApp, cons void UUINavPCComponent::HandleMouseMoveEvent(FSlateApplication& SlateApp, const FPointerEvent& MouseEvent) { - const bool bUseLeftThumbstickAsMouse = ActiveWidget != nullptr && ActiveWidget->bUseLeftThumbstickAsMouse; - if (CurrentInputType != EInputType::Mouse && MouseEvent.GetCursorDelta().SizeSquared() > 0.0f && (!bUseLeftThumbstickAsMouse || !IsMovingLeftStick())) + const bool bShouldUseLeftThumbstickAsMouse = (ActiveWidget != nullptr && ActiveWidget->bUseLeftThumbstickAsMouse) || bUseLeftThumbstickAsMouse; + if (CurrentInputType != EInputType::Mouse && MouseEvent.GetCursorDelta().SizeSquared() > 0.0f && (!bShouldUseLeftThumbstickAsMouse || !IsMovingLeftStick())) { NotifyInputTypeChange(EInputType::Mouse); } diff --git a/Source/UINavigation/Private/UINavWidget.cpp b/Source/UINavigation/Private/UINavWidget.cpp index c2827aed..2d2660ce 100644 --- a/Source/UINavigation/Private/UINavWidget.cpp +++ b/Source/UINavigation/Private/UINavWidget.cpp @@ -3193,7 +3193,10 @@ void UUINavWidget::HoverEvent(int Index) const bool bIsVR = false; #endif - if (Index == ButtonIndex || (!bIsVR && UINavPC->GetCurrentInputType() != EInputType::Mouse && (!bUseLeftThumbstickAsMouse || !UINavPC->IsMovingLeftStick()))) + if (Index == ButtonIndex || + (!bIsVR && + UINavPC->GetCurrentInputType() != EInputType::Mouse && + ((!bUseLeftThumbstickAsMouse && !UINavPC->bUseLeftThumbstickAsMouse) || !UINavPC->IsMovingLeftStick()))) { if (bUseButtonStates) RevertButtonStyle(Index); return; diff --git a/Source/UINavigation/Public/UINavPCComponent.h b/Source/UINavigation/Public/UINavPCComponent.h index cb3b2258..db934fca 100644 --- a/Source/UINavigation/Public/UINavPCComponent.h +++ b/Source/UINavigation/Public/UINavPCComponent.h @@ -152,6 +152,13 @@ class UINAVIGATION_API UUINavPCComponent : public UActorComponent UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = UINavController) float NavigationChainFrequency = 0.2f; + /* + Indicates whether the controller should use the left stick as mouse. + If the active UINavWidget has this set to false, this will override that. + */ + UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = UINavController) + bool bUseLeftThumbstickAsMouse = false; + /* The sensitivity of the cursor when moved with the left stick */ From fa2b5e4ae382c3560bf06bdee4038f696afefd3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gon=C3=A7alo=20Marques?= Date: Tue, 18 May 2021 12:56:49 +0100 Subject: [PATCH 2/3] Apply mouse movement when overriden --- Source/UINavigation/Private/UINavPCComponent.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Source/UINavigation/Private/UINavPCComponent.cpp b/Source/UINavigation/Private/UINavPCComponent.cpp index 940d4403..8ac54b7f 100644 --- a/Source/UINavigation/Private/UINavPCComponent.cpp +++ b/Source/UINavigation/Private/UINavPCComponent.cpp @@ -433,7 +433,8 @@ void UUINavPCComponent::HandleAnalogInputEvent(FSlateApplication& SlateApp, cons NotifyInputTypeChange(EInputType::Gamepad); } - if (ActiveWidget != nullptr && ActiveWidget->bUseLeftThumbstickAsMouse) + if ((ActiveWidget != nullptr && ActiveWidget->bUseLeftThumbstickAsMouse) || + bUseLeftThumbstickAsMouse) { const FKey Key = InAnalogInputEvent.GetKey(); if (Key == EKeys::Gamepad_LeftX || Key == EKeys::Gamepad_LeftY) From 7d0ada48c5295007b18c2f2066628ac8d6684ba5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gon=C3=A7alo=20Marques?= Date: Tue, 18 May 2021 12:57:03 +0100 Subject: [PATCH 3/3] Add SimulateMousePress functions --- .../UINavigation/Private/UINavPCComponent.cpp | 40 +++++++++++++++++++ Source/UINavigation/Public/UINavPCComponent.h | 7 ++++ 2 files changed, 47 insertions(+) diff --git a/Source/UINavigation/Private/UINavPCComponent.cpp b/Source/UINavigation/Private/UINavPCComponent.cpp index 8ac54b7f..78731033 100644 --- a/Source/UINavigation/Private/UINavPCComponent.cpp +++ b/Source/UINavigation/Private/UINavPCComponent.cpp @@ -496,6 +496,46 @@ void UUINavPCComponent::HandleMouseWheelOrGestureEvent(FSlateApplication& SlateA } } +void UUINavPCComponent::SimulateMousePress() +{ + FSlateApplication& SlateApp = FSlateApplication::Get(); + FPointerEvent MouseDownEvent( + 0, + SlateApp.CursorPointerIndex, + SlateApp.GetCursorPos(), + SlateApp.GetLastCursorPos(), + SlateApp.GetPressedMouseButtons(), + EKeys::LeftMouseButton, + 0, + SlateApp.GetPlatformApplication()->GetModifierKeys() + ); + TSharedPtr GenWindow; + SlateApp.ProcessMouseButtonDownEvent(GenWindow, MouseDownEvent); +} + +void UUINavPCComponent::SimulateMouseRelease() +{ + FSlateApplication& SlateApp = FSlateApplication::Get(); + FPointerEvent MouseUpEvent( + 0, + SlateApp.CursorPointerIndex, + SlateApp.GetCursorPos(), + SlateApp.GetLastCursorPos(), + SlateApp.GetPressedMouseButtons(), + EKeys::LeftMouseButton, + 0, + SlateApp.GetPlatformApplication()->GetModifierKeys() + ); + TSharedPtr GenWindow; + SlateApp.ProcessMouseButtonUpEvent(MouseUpEvent); +} + +void UUINavPCComponent::SimulateMouseClick() +{ + SimulateMousePress(); + SimulateMouseRelease(); +} + void UUINavPCComponent::TimerCallback() { MenuInput(CallbackDirection); diff --git a/Source/UINavigation/Public/UINavPCComponent.h b/Source/UINavigation/Public/UINavPCComponent.h index db934fca..1d844350 100644 --- a/Source/UINavigation/Public/UINavPCComponent.h +++ b/Source/UINavigation/Public/UINavPCComponent.h @@ -279,6 +279,13 @@ class UINAVIGATION_API UUINavPCComponent : public UActorComponent void HandleMouseButtonDownEvent(FSlateApplication& SlateApp, const FPointerEvent& MouseEvent); void HandleMouseWheelOrGestureEvent(FSlateApplication& SlateApp, const FPointerEvent& InWheelEvent, const FPointerEvent* InGesture); + UFUNCTION(BlueprintCallable, Category = UINavController) + void SimulateMousePress(); + UFUNCTION(BlueprintCallable, Category = UINavController) + void SimulateMouseRelease(); + UFUNCTION(BlueprintCallable, Category = UINavController) + void SimulateMouseClick(); + void BindMouseWorkaround(); void UnbindMouseWorkaround();