第一次提交
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
// Copyright 2025 https://yuewu.dev/en All Rights Reserved.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "UI/Mobile/GUIS_SimulatedInputWidget.h"
|
||||
#include "GUIS_JoystickWidget.generated.h"
|
||||
|
||||
|
||||
class UImage;
|
||||
class UObject;
|
||||
struct FGeometry;
|
||||
struct FPointerEvent;
|
||||
|
||||
/**
|
||||
* A UMG wrapper for the lyra virtual joystick.
|
||||
*
|
||||
* This will calculate a 2D vector clamped between -1 and 1
|
||||
* to input as a key value to the player, simulating a gamepad analog stick.
|
||||
*
|
||||
* This is intended for use with and Enhanced Input player.
|
||||
*/
|
||||
UCLASS()
|
||||
class GENERICUISYSTEM_API UGUIS_JoystickWidget : public UGUIS_SimulatedInputWidget
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
UGUIS_JoystickWidget(const FObjectInitializer& ObjectInitializer);
|
||||
|
||||
//~ Begin UUserWidget
|
||||
virtual FReply NativeOnTouchStarted(const FGeometry& InGeometry, const FPointerEvent& InGestureEvent) override;
|
||||
virtual FReply NativeOnTouchMoved(const FGeometry& InGeometry, const FPointerEvent& InGestureEvent) override;
|
||||
virtual FReply NativeOnTouchEnded(const FGeometry& InGeometry, const FPointerEvent& InGestureEvent) override;
|
||||
virtual void NativeOnMouseLeave(const FPointerEvent& InMouseEvent) override;
|
||||
virtual void NativeTick(const FGeometry& MyGeometry, float InDeltaTime) override;
|
||||
//~ End UUserWidget interface
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Calculate the delta position of the current touch from the origin.
|
||||
*
|
||||
* Input the associated gamepad key on the player
|
||||
*
|
||||
* Move the foreground joystick image in association with the given input to give the appearance that it
|
||||
* is moving along with the player's finger
|
||||
*/
|
||||
void HandleTouchDelta(const FGeometry& InGeometry, const FPointerEvent& InGestureEvent);
|
||||
|
||||
/** Flush any player input that has been injected and disable the use of this analog stick. */
|
||||
void StopInputSimulation();
|
||||
|
||||
/** How far can the inner image of the joystick be moved? */
|
||||
UPROPERTY(BlueprintReadOnly, EditAnywhere, Category="GUIS")
|
||||
float StickRange = 50.0f;
|
||||
|
||||
/** Image to be used as the background of the joystick */
|
||||
UPROPERTY(BlueprintReadWrite, Category="GUIS", meta = (BindWidget))
|
||||
TObjectPtr<UImage> JoystickBackground;
|
||||
|
||||
/** Image to be used as the foreground of the joystick */
|
||||
UPROPERTY(BlueprintReadWrite, Category="GUIS", meta = (BindWidget))
|
||||
TObjectPtr<UImage> JoystickForeground;
|
||||
|
||||
/** Should we negate the Y-axis value of the joystick? This is common for "movement" sticks */
|
||||
UPROPERTY(BlueprintReadWrite, Category="GUIS", EditAnywhere)
|
||||
bool bNegateYAxis = false;
|
||||
|
||||
/** The origin of the touch. Set on NativeOnTouchStarted */
|
||||
UPROPERTY(Transient)
|
||||
FVector2D TouchOrigin = FVector2D::ZeroVector;
|
||||
|
||||
UPROPERTY(Transient)
|
||||
FVector2D StickVector = FVector2D::ZeroVector;
|
||||
};
|
||||
Reference in New Issue
Block a user