LEAP Documentation 40220
Documentation for the LEAP project
ProjectXGameViewportClient.h
Go to the documentation of this file.
1// Copyright Blue Isle Studios Inc 2018. All Rights Reserved.
2
3#pragma once
4
5#include "CoreMinimal.h"
6#include "Engine/GameViewportClient.h"
9#include "ContextMenuWidget.h"
10#include "Blueprint/UserWidgetPool.h"
11#include "ProjectXGameViewportClient.generated.h"
12
13class AProjectXHUD;
15
16DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FWidgetChangedSignature, TSubclassOf<UUserWidget>, WidgetClass);
17DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FDisplayMeshVisibilityUpdatedSignature, bool, bDisplayVisible);
18DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FViewportGamePadStateChangeSignature, bool, bIsUsingGamepad);
19DECLARE_DYNAMIC_MULTICAST_DELEGATE(FOnKeyBindingViewportUpdatedSignature);
20
21UCLASS(Blueprintable)
22class PROJECTX_API UProjectXGameViewportClient : public UGameViewportClient
23{
24 GENERATED_BODY()
25
26public:
27 virtual void Tick(float DeltaTime) override;
28 virtual void PostRender(UCanvas* Canvas) override;
29 virtual void Init(struct FWorldContext& WorldContext, UGameInstance* OwningGameInstance, bool bCreateNewAudioDevice = true) override;
30 virtual void ClearFade();
31 virtual void Fade(const float inFadeDuration, const bool bInToBlack, const float inFadeDelay = 0.0f, const bool& bInForceFadeToBlack = false);
32 void DrawScreenFade(UCanvas* Canvas);
33 bool IsFading() const;
34 void ReinitializeViewportClientFade();
35 void CleanViewport();
36 void MenuBack();
37 void ToggleEscMenu();
38 /* This should be called only by bound inputs and has custom rules to what allows the toggle */
39 void ToggleMap();
40 void OpenMap();
41 void OpenLandingScreen();
42 void DeferredOpenMapTimerComplete();
43 void CloseMap();
44 void CloseLandingScreen();
45 void DeferredOpenMap(float Delay = -1.f);
46 void ClearMapTimers();
47 void NavigateBumperLeft();
48 void NavigateBumperRight();
49
50 UFUNCTION(BlueprintPure, Category = Bindings)
51 bool IsPlayerBindingNewButton() const { return bIsBinding; }
52 UFUNCTION(BlueprintCallable, Category = Bindings)
53 void SetPlayerBindingNewButton(const bool bIsPlayerCurrentlyBinding) { bIsBinding = bIsPlayerCurrentlyBinding; }
54
55 void TopFaceButton();
56 void BottomFaceButton();
57 void RightFaceButton();
58 void LeftFaceButton();
59 void ToggleKickVoteMenu();
60 void ToggleMapVoteMenu();
61 void ShowScoreboard();
62 void HideScoreboard();
63 bool CanToggleChat() const;
64 bool HasLegalPawn() const;
65 void OpenPostGameScreen();
66 void OpenQuickChat();
67 void CloseQuickChat();
68 void ToggleDeathWidget(bool OpenWidget);
69 void ToggleHUD(bool bToggle);
70 void RemoveHUDUserWidget(UUserWidget* Widget);
71 void RemoveAllHUDUserWidgets();
72 virtual void ToggleSoftwareCursor(const bool bToggle);
73 bool SetUserFocusOnAdvancedUserWidget(UAdvancedUserWidget* Widget);
74 bool SetUserFocusOnFirstChild(UUserWidget* Widget);
75 bool AreAnyActiveWidgetsDisablingInput() const;
76 void AddHUDBaseWidgetToList(UHUDBasicUserWidget* WidgetToAdd);
77 void RemoveHUDBaseWidgetFromList(UHUDBasicUserWidget* WidgetToRemove);
78
79 /* Called by AProjectXPlayerController::ClientTravelInternal_Implementation when travel has been requested. */
80 virtual void LevelTravel();
81
82 template <class T>
84 {
85 ToggleWidgetByClass(T::StaticClass());
86 }
87
88 void ToggleWidgetByClass(TSubclassOf<UAdvancedUserWidget> WidgetClass, EWindowToggleCommand ToggleCommand = EWindowToggleCommand::Toggle);
89 void ToggleWidget(UAdvancedUserWidget* UserWidget, const EWindowToggleCommand ToggleCommand, const UObject* ContextObject = nullptr);
90 UAdvancedUserWidget* GetWidgetByClass(TSubclassOf<UUserWidget> WidgetClass, bool bReturnInheritedClasses = false) const;
91 void CloseAllWidgets(const bool bClosedByAnotherWidget = false);
92 void OnWidgetDestroyed(UAdvancedUserWidget* Widget);
93
94 UContextMenuWidget* CreateContextMenu(const TArray<FContextMenuOption>& ContextMenuOptions, const FText Title, const bool bDismissable, const UObject* ContextObject = nullptr);
95 UContextMenuWidget* CreateGlobalMessageDialogue(FContextMenuOption ContextMenuOption1, FContextMenuOption ContextMenuOption2, const FText Title, const FText Message, const bool bDismissable, const UObject* ContextObject = nullptr);
96 UHUDBasicUserWidget* FindOrCreateHUDUserWidget(UClass* WidgetClass, const int32 ZOrder);
97 UUserWidget* GetHUDWidgetByClass(TSubclassOf<UUserWidget> WidgetClass) const;
98 AProjectXHUD* GetHUD() const;
99 UAdvancedUserWidget* GetOrCreateViewportWidget(UClass* WidgetClass, const int32 ZOrder, const bool bDontCreateCopies = false);
100
101
102 UFUNCTION(BlueprintCallable, Category = "Display Meshes")
103 void ToggleDisplayMesh(bool bToggled);
104 UFUNCTION(BlueprintCallable, Category = "Display Meshes")
105 AActor* const GetDisplayMesh() const;
106 UFUNCTION(BlueprintCallable, Category = "Display Meshes")
107 bool IsDisplayMeshVisible() const { return bShowingDisplayMesh; }
108 UFUNCTION(BlueprintCallable)
109 void KeysRebound() { OnViewportKeybindUpdatedEvent.Broadcast(); }
110 UFUNCTION(BlueprintCallable)
111 TSubclassOf<UAdvancedUserWidget> GetHighestActiveWidget() const { return GetHighestPriorityActiveWidget() ? GetHighestPriorityActiveWidget()->GetClass() : NULL; }
112 UFUNCTION(BlueprintCallable)
113 UUserWidget* GetTooltipWidget();
114
115 UPROPERTY(BlueprintAssignable)
116 FWidgetChangedSignature OnHighestActiveWidgetChanged;
117 UPROPERTY(BlueprintAssignable)
118 FDisplayMeshVisibilityUpdatedSignature OnDisplayMeshVisibilityChangedEvent;
119 UPROPERTY(BlueprintAssignable, Category = "Gamepad Events")
120 FViewportGamePadStateChangeSignature OnGamepadStateChanged;
121 UPROPERTY(BlueprintAssignable, Category = "Gamepad Events")
122 FOnKeyBindingViewportUpdatedSignature OnViewportKeybindUpdatedEvent;
123
124
125 UFUNCTION(BlueprintCallable, meta = (WorldContext = "WorldContextObject", DeterminesOutputType = "UserWidget"))
126 static UUserWidget* CreateUserWidgetFromPool(UObject* const WorldContextObject, TSubclassOf<UUserWidget> UserWidget);
127 UFUNCTION(BlueprintCallable, meta = (WorldContext = "WorldContextObject"))
128 static void ReleaseUserWidgetFromPool(UObject* const WorldContextObject, UUserWidget* const UserWidget);
129 UFUNCTION(BlueprintCallable, meta = (WorldContext = "WorldContextObject"))
130 static void BuildWidgetPoolForWidget(UObject* const WorldContextObject, TSubclassOf<UUserWidget> UserWidget, int32 PoolSize = 10);
131
132 /* We need to talk to UI designers about this function. It should not be taken lightly. */
133 UFUNCTION(BlueprintCallable, Category = Viewport, meta = (WorldContext = "WorldContextObject", CallableWithoutWorldContext))
134 static UAdvancedUserWidget* CreateAdvancedUserWidget(const UObject* WorldContextObject, TSubclassOf<UAdvancedUserWidget> AdvancedUserWidgetClass, const int32 ZOrder);
135 UFUNCTION(BlueprintCallable, Category = Viewport, meta = (WorldContext = "WorldContextObject", CallableWithoutWorldContext))
136 static void ToggleAdvancedUserWidget(const UObject* WorldContextObject, UAdvancedUserWidget* AdvancedUserWidgetClass, const EWindowToggleCommand ToggleCommand);
137 UFUNCTION(BlueprintCallable, Category = Viewport, meta = (WorldContext = "WorldContextObject", CallableWithoutWorldContext))
138 static UAdvancedUserWidget* ToggleAdvancedUserWidgetByClass(const UObject* WorldContextObject, TSubclassOf<UAdvancedUserWidget> AdvancedUserWidgetClass, const EWindowToggleCommand ToggleCommand);
139 UFUNCTION(BlueprintCallable, Category = Viewport, meta = (WorldContext = "WorldContextObject", CallableWithoutWorldContext))
140 static bool IsAdvancedUserWidgetActiveByClass(const UObject* WorldContextObject, TSubclassOf<UAdvancedUserWidget> AdvancedUserWidgetClass);
141 UFUNCTION(BlueprintCallable,BlueprintPure, Category = Viewport, meta = (WorldContext = "WorldContextObject", CallableWithoutWorldContext))
142 static UProjectXGameViewportClient* GetViewportClient(const UObject* WorldContextObject);
143
144 void SetPlayerInputLockingState();
145 bool IsUsingGamePad() const { return bIsUsingGamepad; };
146 UAdvancedUserWidget* GetHighestPriorityActiveWidget() const;
147
148protected:
149 virtual void BeginDestroy() override;
150 virtual APlayerController* GetOwningPlayerController() const;
151 virtual bool InputKey(const FInputKeyEventArgs& EventArgs) override;
152 virtual bool InputAxis(FViewport* InViewport, int32 ControllerId, FKey Key, float Delta, float DeltaTime, int32 NumSamples/* =1 */, bool bGamepad/* =false */) override;
153 void SetUsingGamepad(bool bToggle);
154 void LogFocusedWidget();
155
156 UPROPERTY(EditDefaultsOnly)
157 TSubclassOf<UUserWidget> TooltipWidgetClass = NULL;
158
159private:
161 friend class AProjectXHUD;
163 TArray<TWeakObjectPtr<UAdvancedUserWidget>> AllViewportWidgets;
164 TArray<TWeakObjectPtr<UHUDBasicUserWidget>> AllHUDWidgets;
165
166 int32 GetHighestPriorityWidgetStackIndex() const;
167 bool AreAnyWidgetsActive(const UAdvancedUserWidget* Self = nullptr) const;
168 bool AreAnyActiveWidgetsBlockingNewWidgets(const TArray<UAdvancedUserWidget*> Exceptions) const;
169 bool AreAnyActiveWidgetsBlockingLowerPriorityNewWidgets(const TArray<UAdvancedUserWidget*> Exceptions, uint8 TestPriority) const;
170 void DelayedCollapseWidget(TWeakObjectPtr<UAdvancedUserWidget> UserWidget);
171 void CollapseWidget(UAdvancedUserWidget* UserWidget);
172 void CloseHighestPriorityWidget();
173 UContextMenuWidget* CreateContextMenuWidget(UClass* WidgetClass, const TArray<FContextMenuOption>& ContextMenuOptions, const FText Title, const FText Message, const bool bDismissable = true, const UObject* ContextObject = nullptr);
174
175 UPROPERTY()
176 FTimerHandle MapOpenTimer;
177
178 bool bIsUsingGamepad = false;
179 float FocusIntervalCurrent;
180 int32 ActiveStackIndex;
181 uint32 bFading : 1;
182 uint32 bFadeToBlack : 1; // Fading to black will be applied even if alpha is 1
183 float FadeDelay = 0.0f;
184 float FadeStartTime = 0.0f;
185 float FadeDuration = 0.0f;
186 float CurrentAlpha = 0.0f;
187 bool bInitiating = true;
188 bool bGamePadInUse = false;
189 bool bShowingDisplayMesh = false;
190 bool bIsBinding = false;
191
192 UPROPERTY()
193 UUserWidget* TooltipWidgetObject = NULL;
194 TWeakObjectPtr<AProjectXMapCamera> MapCamera = nullptr;
195 TWeakObjectPtr<AActor> InGameLoadoutDisplay = nullptr;
196
197 TArray<TWeakObjectPtr<UAdvancedUserWidget>> WidgetsWaitingToOpenQueue;
198 static TMap<UWorld*, FUserWidgetPool> UserWidgetPool;
199};
EWindowToggleCommand
Definition: AdvancedUserWidget.h:22
@ Toggle
Definition: AdvancedUserWidget.h:23
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FWidgetChangedSignature, TSubclassOf< UUserWidget >, WidgetClass)
DECLARE_DYNAMIC_MULTICAST_DELEGATE(FOnKeyBindingViewportUpdatedSignature)
Definition: ProjectXHUD.h:20
Definition: ProjectXMapCamera.h:11
virtual void Tick(float DeltaTime) override
Definition: ProjectXMapCamera.cpp:85
Definition: AdvancedUserWidget.h:30
Definition: ContextMenuWidget.h:37
Definition: HUDBasicUserWidget.h:14
Definition: ProjectXGameInstance.h:507
Definition: ProjectXGameViewportClient.h:23
void ToggleWidgetByClass()
Definition: ProjectXGameViewportClient.h:83
Definition: ContextMenuWidget.h:14