Skip to content

Commit

Permalink
Merge branch '4.26'
Browse files Browse the repository at this point in the history
  • Loading branch information
goncasmage1 committed May 18, 2021
2 parents ae34980 + da6e9c1 commit d443cef
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 4 deletions.
47 changes: 44 additions & 3 deletions Source/UINavigation/Private/UINavPCComponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -472,8 +473,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);
}
Expand All @@ -495,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<FGenericWindow> 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<FGenericWindow> GenWindow;
SlateApp.ProcessMouseButtonUpEvent(MouseUpEvent);
}

void UUINavPCComponent::SimulateMouseClick()
{
SimulateMousePress();
SimulateMouseRelease();
}

void UUINavPCComponent::TimerCallback()
{
MenuInput(CallbackDirection);
Expand Down
5 changes: 4 additions & 1 deletion Source/UINavigation/Private/UINavWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 14 additions & 0 deletions Source/UINavigation/Public/UINavPCComponent.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -292,6 +299,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();

Expand Down

0 comments on commit d443cef

Please sign in to comment.