Space Plunder
Loading...
Searching...
No Matches
InteractionComponent.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"
8#include "InteractionComponent.generated.h"
9
11struct FPingData;
13DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnTraceEvent, const FHitResult&, HitResult);
14
15DECLARE_LOG_CATEGORY_EXTERN(LogInteraction, Display, All);
16
17UCLASS(Blueprintable, BlueprintType, ClassGroup=(BucciGames), meta=(BlueprintSpawnableComponent) )
18class INTERACTION_API UInteractionComponent : public UCharacterComponent
19{
20 GENERATED_BODY()
21
22
23public:
24 UInteractionComponent();
25
26 UPROPERTY(BlueprintAssignable, Category = "Interaction")
27 FOnTraceEvent OnTraceEventHit;
29 UPROPERTY(BlueprintAssignable, Category = "Interaction")
30 FOnTraceEvent OnTraceEventAny;
31
32
33
34
35 UFUNCTION(BlueprintCallable, Category = "Interaction")
36 void Aim(const bool bValue);
37
38
39
41 UFUNCTION(BlueprintPure, BlueprintCallable, Category = "Interaction")
42 float GetUseLength() const{return UseLength;};
44 UFUNCTION(BlueprintPure, BlueprintCallable, Category = "Interaction")
45 float GetTraceLength() const{return TraceLength;};
46
47 UFUNCTION(BlueprintCallable, Category = "Interaction")
48 bool GetIsTracing() const {return bIsTracing;}
49
51 UFUNCTION(BlueprintCallable, Category = "Interaction")
52 void UpdateInteractionData();
53
55 UFUNCTION(BlueprintCallable, Category = "Interaction")
56 void StartTraceForward();
58 UFUNCTION(BlueprintCallable, Category = "Interaction")
59 void StopTraceForward();
60
62 UFUNCTION(BlueprintCallable, Category = "Interaction")
63 void StartTraceInteractForward();
65 UFUNCTION(BlueprintCallable, Category = "Interaction")
66 void StopTraceInteractForward();
68 UFUNCTION(BlueprintCallable, Category = "Interaction")
69 FHitResult TraceTowardLocation(const FVector& TargetLocation);
70
73 UFUNCTION(BlueprintCallable, Category = "Interaction")
74 AActor* Use();
75 UFUNCTION(BlueprintCallable, Category = "Interaction")
76 void OpenPingMenu();
77
78 //- Return reference to ping Actor //
79 UFUNCTION(BlueprintCallable, Category = "Interaction")
80 bool PingItem(FInteractionData& InteractionData, FVector& PingLocation);
82 UFUNCTION(BlueprintCallable, Category = "Interaction")
83 void StopInteract();
84
85 UFUNCTION(BlueprintCallable, Category = "Interaction")
86 FHitResult GetHitResult();
87 UFUNCTION(BlueprintCallable, Category = "Interaction")
88 FVector GetTraceEndLocation();
89
90 UFUNCTION(BlueprintCallable, Category = "Interaction")
91 void ChangeInteractionSelection(const bool bUpSelection);
92
94 UFUNCTION(BlueprintCallable, Category = "Interaction")
95 void ShowCustomPrompt(const FInteractionData& InteractionData) const;
96 UFUNCTION(BlueprintCallable, Category = "Interaction")
97 void HideCustomPrompt() const;
98
99 UFUNCTION(BlueprintCallable, Category = "Interaction")
100 int32 GetSelectedInteraction() const{return SelectedInteraction;};
101 UFUNCTION(BlueprintCallable, Category = "Interaction")
102 EInteractionType GetSelectedInteractionType() const;
103
104
106 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Interaction|General")
107 bool bBindOverlap = false;
109 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Interaction|General")
110 bool bInteractOnAim = false;
112 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Interaction|General")
113 bool bStartLocationOffset = false;
115 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Interaction|General")
116 bool bDoesTraceTick = false;
118 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Interaction|General")
119 float TraceTickRate = 0.1f;
121 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Interaction|General")
122 float InteractionTime = 0.6f;
123 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Interaction|General")
124 float OverlapCheckFrequency = 0.5f;
125
127 AActor* GetFocusedActor() const {return FocusedActor;};
129 AActor* GetCurrentOverlapActor() const{return CurrentOverlapActor;};
131 AActor* GetInteractionActor() const{return InteractionActor;};
133 TArray<AActor*>& GetCurrentOverlappedActors() {return CurrentOverlappedActors;};
134 int32 GetCurrentNumOfOverlappedActors() const {return CurrentOverlappedActors.Num();};
135
136
137protected:
138
139 virtual void BeginPlay() override;
140 virtual void ComponentSetupComplete() override;
141
142
144 void TraceInteractForward();
146 void TraceForward();
147 void TraceForward(const bool bInteract = true, const bool bUseOverrideLength = false, const float OverrideLength = 2000.0f);
148
149 AActor* GetClosestOverlapActor();
150
151
153 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Interaction|Distance")
154 float TraceLength = 2000.0f;
156 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Interaction|Distance")
157 float UseLength = 1000.0f;
158
159 //@TODO change to PingData Struct, Make if not already made, then have function to convert InteractionData to PingData.
160 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Interaction|Ping")
161 struct FRadialMenuData PingMenuData;
162 // UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Interaction|Ping")
163 // UDataTable* PingDataTable = nullptr;
164 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Interaction|Ping")
165 TArray<FInteractionData> PingInteractions;
167 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Interaction|Ping")
168 float PingLength = 5000.0f;
169 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Interaction|Ping")
170 int32 MaxPingActors = 3;
171
172 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Interaction|Debug")
173 float DebugPointSize = 50.0f;
174 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Interaction|Debug")
175 float DebugPointTime = 20.0f;
176 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Interaction|Debug")
177 int32 DebugPointPriority = 1;
178
180 UPROPERTY(ReplicatedUsing=OnInteractionActorReplicated, VisibleAnywhere, BlueprintReadOnly, Category="Interaction|Actors")
181 AActor* InteractionActor;
183 UPROPERTY(Replicated, VisibleAnywhere, BlueprintReadOnly, Category="Interaction|Actors")
184 AActor* FocusedActor;
186 UPROPERTY(Replicated, VisibleAnywhere, BlueprintReadOnly, Category="Interaction|Actors")
187 AActor* CurrentOverlapActor;
189 UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="Interaction|Actors")
190 TArray<AActor*> CurrentOverlappedActors;
192 UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Interaction|Ping")
193 TArray<AActor*> PingActors;
194
195
196 UPROPERTY(EditAnywhere, BlueprintReadOnly, Category="Interaction|Widget")
197 TSoftClassPtr<UUserWidget> InteractionCrosshairWidgetClass;
198 UPROPERTY(EditAnywhere, BlueprintReadOnly, Category="Interaction|Widget")
199 TSoftClassPtr<UUserWidget> InteractionContextWidgetClass;
200
201private:
202
203 void CompareOverlapDistances();
204
205
206 IInteractionInterface* GetInteractComponentFromActor(const AActor* Actor) const;
207
209 UFUNCTION()
210 void OnInteractionActorReplicated(AActor* LastActor);
211
212 UFUNCTION()
213 void ActorOverlap(AActor* OverlappedActor, AActor* OtherActor);
214 UFUNCTION()
215 void ActorEndOverlap(AActor* OverlappedActor, AActor* OtherActor);
216
217 void StartFocusOnActor(AActor* Actor) const;
218 void EndFocusOnActor(AActor* Actor) const;
219 void InteractAfterDelay();
220
221
222 UFUNCTION(Server, Reliable)
223 void Server_FocusOnActor(const bool bStartFocus, AActor* ActorToFocus);
224 void FocusOnActor(const bool bStartFocus, AActor* ActorToFocus);
225 UFUNCTION(Server, Reliable, Category = "Interaction")
226 void Server_Interact(const int32 Index);
227
228
229 UFUNCTION(Server, Reliable, Category="Interaction")
230 void Server_SpawnPingActor(const FPingData& PingData, const FVector& SpawnLocation);
231
233 UFUNCTION()
234 void CheckForOverlappedActors();
235
238 AActor* GetCurrentActor() const;
239
240 // bool GetCurrentActorInteractionData(FInteractionData& InteractionData) const;
241 bool GetCurrentActorInteractionData(FInteractionData& InteractionData) const;
242
244 void UpdateHUD(const bool bStartFocus, AActor* ActorToFocus) const;
246 void UpdateHUDSelection() const;
247 void StartHUDSelection(const bool bStart = true, const float Multiplier = 1.0f) const;
248
249 void SetupInteractionCrosshairWidget();
250 void SetupInteractionContextWidget();
251
252
254 UPROPERTY(EditDefaultsOnly, Category = "Interaction|Ping")
255 TSubclassOf<AActor> PingActorToSpawn;
256 UPROPERTY(VisibleAnywhere, Category = "Interaction|General")
257 int32 SelectedInteraction = 0;
258
259
260 class IInteractionHUD* InteractionWidget = nullptr;
261 IInteractionCrosshair* InteractionCrosshair = nullptr;
262
263 UPROPERTY()
264 FVector CurrentTraceEnd = FVector::ZeroVector;
265 UPROPERTY()
266 FHitResult CurrentHitResult;
267
268 FTimerHandle TraceForwardTimerHandle;
269 FTimerHandle TraceInteractForwardTimerHandle;
270 FTimerHandle UpdateHUDTimerHandle;
271 FTimerHandle UseActionTimerHandle;
272
273
274 FTimerHandle CheckOverlapsTimerHandle;
275
276
277 bool bIsTracing = false;
278
279
280};
281
EInteractionType
Definition BaseData.h:149
@ Use
Definition InteractionComponent.cpp:798
UCLASS(Blueprintable, BlueprintType, ClassGroup=(BucciGames), meta=(BlueprintSpawnableComponent)) class CHATSYSTEM_API UChatSystemComponent
Definition ChatSystemComponent.h:13
DECLARE_LOG_CATEGORY_EXTERN(LogInteraction, Display, All)
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnTraceEvent, const FHitResult &, HitResult)
Definition InteractionCrosshair.h:21
Definition InteractionHUD.h:17
Definition InteractionInterface.h:18
Definition Interaction.Build.cs:6
Represents a character component that can be added to an actor.
Definition BaseData.h:420
Definition InteractionData.h:37
Definition RadialWheelData.h:100