LEAP Documentation 40220
Documentation for the LEAP project
AdvancedUserWidget.h
Go to the documentation of this file.
1// Copyright Blue Isle Studios Inc 2017. All Rights Reserved.
2
3#pragma once
4
5#include "CoreMinimal.h"
6#include "BasicUserWidget.h"
7#include "AdvancedUserWidget.generated.h"
8
9DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FWidgetVisibleSignature, const UObject*, ContextObject);
10DECLARE_DYNAMIC_MULTICAST_DELEGATE(FWidgetCollapsedSignature);
11
12UENUM(BlueprintType)
13enum class EWidgetDismissType : uint8
14{
15 Input = 0,
16 Widget = 1,
17 Forced = 2
18};
19
20UENUM(Blueprintable)
22{
23 Toggle = 0,
24 Open = 1,
25 Close = 2
26};
27
28UCLASS()
29class PROJECTX_API UAdvancedUserWidget : public UBasicUserWidget
30{
31 GENERATED_UCLASS_BODY()
32
34
35public:
36 /* If true, this widget will auto register with the viewport client. Must be a child of a canvas panel.*/
37 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Input")
38 bool bAutoRegister = false;
39 /* If this is true, this widget will close all other managed widgets when activated.*/
40 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Input")
41 bool bCloseOtherWidgets = true;
42 /* If this is true, this widget will prevent all other managed widgets to open while it's active.*/
43 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Input")
44 bool bPreventWidgetsFromOpening = false;
45 /* If this is true, this widget will prevent all other lower-priority managed widgets to open while it's active.*/
46 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Input")
47 bool bPreventLowerPriorityWidgetsFromOpening = false;
48 /* If this is true, player input will be turned off while this widget is active.*/
49 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Input")
50 bool bDisablesPlayerInputWhenActive = true;
51 /* Widget will not collapse until this time has expired. Useful for delaying cleanup until an animation or fade out has completed.*/
52 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Input")
53 float CollapseDelay = 0.0f;
54 /* Can this widget be dismissed with a back button? (escape).*/
55 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Input")
56 bool bDismissableByBackInput = true;
57 /* Does opening another widget close this one?*/
58 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Input")
59 bool bDismissableByOtherWidgets = true;
60 /* Should this widget get destroyed on level travel?*/
61 UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Input")
62 bool bDestroyOnLevelTravel = true;
63 UPROPERTY(BlueprintReadWrite, EditDefaultsOnly, Category = "Controller")
64 bool bAutoFocusWidget = true;
65 UPROPERTY(BlueprintReadOnly, EditDefaultsOnly, Category = "Controller", meta = (EditCondition = "bAutoFocusWidget"))
66 bool bRestoreLastFocusedChild = true;
67 UPROPERTY(BlueprintReadWrite, EditInstanceOnly, Category = "Controller")
68 UWidget* FocusPriorityWidget = nullptr;
69 UPROPERTY(BlueprintReadOnly, EditDefaultsOnly, Category = "Controller")
70 bool bUsesVirtualCursor = false;
71 UPROPERTY(BlueprintReadOnly, EditDefaultsOnly, Category = "Controller")
72 bool bRestrictNavigationToWidget = true;
73 /* Does closing this widget activate another? */
74 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Input")
75 TSubclassOf<UAdvancedUserWidget> WidgetToActivateWhenClosed = nullptr;
76
77 float bAutoDestroy = false;
78 bool bWantsToCollapse = false;
79 uint8 ZOrder = 0;
80 FTimerHandle CollapseDelayTimerHandle;
81 uint32 FadeOutInterpolationID = INDEX_NONE;
82
83 UPROPERTY(BlueprintAssignable, Category = "Widget Events")
84 FWidgetVisibleSignature OnWidgetMadeVisible;
85 UPROPERTY(BlueprintAssignable, Category = "Widget Events")
86 FWidgetCollapsedSignature OnWidgetWasCollapsed;
87
88 UFUNCTION(BlueprintImplementableEvent, Category = "Widget Events")
89 void OnGamepadAxisMoved(const FName AxisName, const int32 ControllerId, const float Delta);
90 UFUNCTION(BlueprintImplementableEvent, Category = "Widget Events")
91 void OnGamepadButtonPressed(const FInputEvent InputEvent, const int32 ControllerId);
92 UFUNCTION(BlueprintImplementableEvent, Category = "Widget Events")
93 void OnLeftBumper();
94 UFUNCTION(BlueprintImplementableEvent, Category = "Widget Events")
95 void OnRightBumper();
96 UFUNCTION(BlueprintImplementableEvent, Category = "Widget Events")
97 void OnRightFaceButton();
98 UFUNCTION(BlueprintImplementableEvent, Category = "Widget Events")
99 void OnLeftFaceButton();
100 UFUNCTION(BlueprintImplementableEvent, Category = "Widget Events")
101 void OnTopFaceButton();
102 UFUNCTION(BlueprintImplementableEvent, Category = "Widget Events")
103 void OnBottomFaceButton();
104 UFUNCTION(BlueprintNativeEvent, Category = "Widget Events")
105 bool CanDisplayWidget() const;
106 UFUNCTION(BlueprintNativeEvent, Category = "Widget Events")
107 void OnWidgetVisible(const UObject* ContextObject = nullptr);
108 UFUNCTION(BlueprintNativeEvent, Category = "Widget Events")
109 void OnWidgetDelayedCollapseStart(const UObject* ContextObject = nullptr);
110
111 UFUNCTION()
112 virtual bool CanDismissWidget(EWidgetDismissType Type) const;
113
114 UFUNCTION(BlueprintPure, Category = "Context Menu")
115 FORCEINLINE bool IsDismissable() const { return bDismissableByBackInput || bDismissableByOtherWidgets; }
116
117 UFUNCTION(BlueprintImplementableEvent, Category = "Widget Events")
118 void OnMenuBack();
119
120 UFUNCTION(BlueprintNativeEvent, Category = "Widget Controls")
121 void CollapseWidget();
122 UFUNCTION(BlueprintNativeEvent, Category = "Widget Controls")
123 void SetWidgetVisible();
124 UFUNCTION(BlueprintNativeEvent, BlueprintPure, Category = "Widget Controls")
125 bool IsWidgetActive() const;
126
127 /* Toggle this widget open or closed. This will lock player input if showing and restore if closing. */
128 UFUNCTION(BlueprintCallable, Category = "Widget Controls")
129 virtual void ToggleWidget(const EWindowToggleCommand ToggleCommand = EWindowToggleCommand::Toggle);
130 /* Close this widget and restore player input (if applicable).*/
131 UFUNCTION(BlueprintCallable, Category = "Widget Controls")
132 void Close();
133
134 FORCEINLINE float GetTimeSpawned() { return TimeSpawned; }
135
136 UFUNCTION()
137 void LevelTravel();
138
139 void AlertInterfaceMenuWasToggled(bool bToggle);
140
141 UWidget* GetLastFocusedWidget() { return LastFocusedWidget.Get(); }
142protected:
143 virtual void NativeConstruct() override;
144 virtual void NativeDestruct() override;
145 void CacheFocusedElement();
146 UWidget* GetFocusedChild(const UUserWidget* Widget);
147 virtual void AddToScreen(class ULocalPlayer* LocalPlayer, int32 inZOrder) override;
148 virtual FReply NativeOnFocusReceived( const FGeometry& InGeometry, const FFocusEvent& InFocusEvent ) override;
149 virtual class UProjectXGameViewportClient* GetViewportClient() const;
150
151 UFUNCTION(BlueprintImplementableEvent, Category = "Widget Events")
152 void OnLevelTravel();
153private:
154 float TimeSpawned = 0.0f;
155
156 void FadeWidget(float FadeTo, float Time);
157 TWeakObjectPtr<UWidget> LastFocusedWidget;
158};
EWindowToggleCommand
Definition: AdvancedUserWidget.h:22
@ Toggle
Definition: AdvancedUserWidget.h:23
@ Close
Definition: AdvancedUserWidget.h:25
@ Open
Definition: AdvancedUserWidget.h:24
DECLARE_DYNAMIC_MULTICAST_DELEGATE(FWidgetCollapsedSignature)
EWidgetDismissType
Definition: AdvancedUserWidget.h:14
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FWidgetVisibleSignature, const UObject *, ContextObject)
Definition: AdvancedUserWidget.h:30
Definition: BasicUserWidget.h:14
Definition: ProjectXGameViewportClient.h:23
static UProjectXGameViewportClient * GetViewportClient(const UObject *WorldContextObject)
Definition: ProjectXGameViewportClient.cpp:621