Space Plunder
Loading...
Searching...
No Matches
PlayerControllerComponent.h
Go to the documentation of this file.
1// Fill out your copyright notice in the Description page of Project Settings.
2
3#pragma once
4
5#include "CoreMinimal.h"
7#include "Components/ActorComponent.h"
8#include "PlayerControllerComponent.generated.h"
9
10struct FGameplayTag;
11DECLARE_LOG_CATEGORY_EXTERN(LogPlayerControllerComp, Display, All);
12
13
17UCLASS(ClassGroup=(BucciGames), meta=(BlueprintSpawnableComponent), Abstract)
18class BASEHELPERS_API UPlayerControllerComponent : public UCommonActorComponent
19{
20 GENERATED_BODY()
21
22 //Taken from GameFramework Component
23public:
25 template <class T>
26 T* GetGameInstance() const
27 {
28 static_assert(TPointerIsConvertibleFromTo<T, UGameInstance>::Value, "'T' template parameter to GetGameInstance must be derived from UGameInstance");
29 AActor* Owner = GetOwner();
30 return Owner ? Owner->GetGameInstance<T>() : nullptr;
31 }
32 template <class T>
33 T* GetGameInstanceChecked() const
34 {
35 static_assert(TPointerIsConvertibleFromTo<T, UGameInstance>::Value, "'T' template parameter to GetGameInstance must be derived from UGameInstance");
36 AActor* Owner = GetOwner();
37 check(Owner);
38 T* GameInstance = Owner->GetGameInstance<T>();
39 check(GameInstance);
40 return GameInstance;
41 }
42
43
44 //Taken from Controller Component
46 template <class T>
47 T* GetController() const
48 {
49 static_assert(TPointerIsConvertibleFromTo<T, AController>::Value, "'T' template parameter to GetController must be derived from AController");
50 return Cast<T>(GetOwner());
51 }
52
53 template <class T>
54 T* GetControllerChecked() const
55 {
56 static_assert(TPointerIsConvertibleFromTo<T, AController>::Value, "'T' template parameter to GetControllerChecked must be derived from AController");
57 return CastChecked<T>(GetOwner());
58 }
59
61 // Controller accessors
62 // Usable for any type of AController owner, only valid if called during gameplay
64
66 template <class T>
67 T* GetPawn() const
68 {
69 static_assert(TPointerIsConvertibleFromTo<T, APawn>::Value, "'T' template parameter to GetPawn must be derived from APawn");
70 return Cast<T>(GetControllerChecked<AController>()->GetPawn());
71 }
72
74 template <class T>
75 T* GetViewTarget() const
76 {
77 static_assert(TPointerIsConvertibleFromTo<T, AActor>::Value, "'T' template parameter to GetViewTarget must be derived from APawn");
78 return Cast<T>(GetControllerChecked<AController>()->GetViewTarget());
79 }
80
82 template <class T>
83 T* GetPawnOrViewTarget() const
84 {
85 if (T* Pawn = GetPawn<T>())
86 {
87 return Pawn;
88 }
89 else
90 {
91 return GetViewTarget<T>();
92 }
93 }
95 template <class T>
96 T* GetPlayerState() const
97 {
98 static_assert(TPointerIsConvertibleFromTo<T, APlayerState>::Value, "'T' template parameter to GetPlayerState must be derived from APlayerState");
99 return GetControllerChecked<AController>()->GetPlayerState<T>();
100 }
101
103 bool IsLocalController() const;
104
106 void GetPlayerViewPoint(FVector& Location, FRotator& Rotation) const;
107
109 // PlayerController accessors
110 // Only returns correct values for APlayerController owners
112
113 template <class T>
114 T* GetPlayer() const
115 {
116 static_assert(TPointerIsConvertibleFromTo<T, UPlayer>::Value, "'T' template parameter to GetPlayer must be derived from UPlayer");
117 APlayerController* PC = Cast<APlayerController>(GetOwner());
118 return PC ? Cast<T>(PC->Player) : nullptr;
119 }
120
121
122public:
123 UPlayerControllerComponent();
124
125 //~~ ISaveLoad ~~//
126 virtual bool SaveGame() override;
127 virtual bool LoadGame() override;
128 //~~ ISaveLoad ~~//
129
130 virtual void ComponentSetupComplete() override;
131
132
133 UFUNCTION(BlueprintImplementableEvent, Category="Controller Component", meta=(DisplayName = "On Component Deactivated"))
134 void OnComponentDeactivatedEvent(UActorComponent* Component);
135 UFUNCTION(BlueprintImplementableEvent, Category="Controller Component", meta=(DisplayName = "On Component Activated"))
136 void OnComponentActivatedEvent(UActorComponent* Component, const bool bReset);
137
138 //- Player Camera //
139 UFUNCTION(BlueprintCallable, Category="Controller Component")
140 virtual FVector GetCameraTraceLocation() const;
141 /* The Camera Trace Location with the Distance to the player Added */
142 UFUNCTION(BlueprintCallable, Category="Controller Component")
143 virtual FVector GetPlayerTraceLocation() const;
144 UFUNCTION(BlueprintCallable, Category="Controller Component")
145 virtual FRotator GetCameraTraceRotation() const;
146 UFUNCTION(BlueprintCallable, Category="Controller Component")
147 virtual FTransform GetCameraTraceTransform() const;
148
149 UUserWidget* PushContentToLayer(const FGameplayTag& LayerName, const TSoftClassPtr<UUserWidget>& WidgetClass) const;
150 UUserWidget* AddWidgetToLayer(const FGameplayTag& LayerName,const TSoftClassPtr<UUserWidget>& WidgetClass) const;
151 UUserWidget* GetContentFromLayer(const FGameplayTag& LayerName, const TSoftClassPtr<UUserWidget>& WidgetClass) const;
152 UUserWidget* AddWidgetToLayerWithSlot(const FGameplayTag& LayerName, const FGameplayTag& SlotTag, const TSoftClassPtr<UUserWidget>& WidgetClass) const;
153
154 // UFUNCTION(BlueprintCallable, Category="Controller Component|Widgets")
155 bool ToggleWidget(const FGameplayTag& LayerName, const TSoftClassPtr<UUserWidget>& WidgetClass) const;
156
157 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Controller Component")
158 bool bAllowAIControllers = false;
159
160protected:
161 virtual void BeginPlay() override;
162
163 virtual void AutoDetect() override;
164
165
166
167 //@ TODO if needed replace with GetOwnerHUD REf and Get AActor* or *IHUDInterface
168 // UFUNCTION(BlueprintCallable, Category="Controller Component")
169 // class AHUD* GetOwnerHUD() const;
170 UFUNCTION(BlueprintCallable, Category="Controller Component")
171 FVector2D GetScreenCenter() const;
172
173 class IPlayerControllerInterface* GetPlayerControllerInterface();
174 class IControllerInterface* GetControllerInterface();
175
176private:
177
178 class IPlayerControllerInterface* PlayerControllerInterface = nullptr;
179 class IControllerInterface* ControllerInterface = nullptr;
180};
UCLASS(Blueprintable, BlueprintType, ClassGroup=(BucciGames), meta=(BlueprintSpawnableComponent)) class CHATSYSTEM_API UChatSystemComponent
Definition ChatSystemComponent.h:13
DECLARE_LOG_CATEGORY_EXTERN(LogPlayerControllerComp, Display, All)
Definition ControllerInterface.h:20
Definition PlayerControllerInterface.h:21