Space Plunder
Loading...
Searching...
No Matches
UIncomingThreatWidget Class Reference

Base class for Damage Indicator & AI Threat Detector. More...

#include <IncomingThreatWidget.h>

Inheritance diagram for UIncomingThreatWidget:

Public Member Functions

void StartThreatIndicationFromActor (AActor *ActorThreat, const float Amount=-1.0f, const UDamageType *DamageType=nullptr)
 
void StartThreatIndicationFromLocation (const FVector &Location, const float Amount=-1.0f, const UDamageType *DamageType=nullptr)
 
void OnStartThreatIndication (const bool bActor, const bool bLocation)
 
void UpdateThreatIndication (const FVector &Location, const float DetectionAmount)
 
void StopThreatIndication ()
 
void SetLifetime (const float Life)
 

Protected Member Functions

virtual bool Initialize () override
 
virtual void NativePreConstruct () override
 
virtual void NativeConstruct () override
 

Protected Attributes

class UBorder * ThreatBorder = nullptr
 
UMaterialInstanceDynamic * ThreatMaterial = nullptr
 
float UpdateRate = 0.01f
 
float Lifetime = 4.0f
 
float MaxIntensity = 100.0f
 
float Intensity = -1.0f
 
float Progress = 0.0f
 
FVector TargetLocation = FVector::ZeroVector
 
AActor * TargetActor = nullptr
 
UDamageType * TargetDamageType = nullptr
 

Private Member Functions

void OptimizedTick () const
 
void SetThreatAngle () const
 
void SetThreatIntensity () const
 
void Destroy ()
 

Private Attributes

FTimerHandle LifetimeTimerHandle
 
FTimerHandle UpdateRateTimerHandle
 

Detailed Description

Base class for Damage Indicator & AI Threat Detector.

Member Function Documentation

◆ Destroy()

void UIncomingThreatWidget::Destroy ( )
private
119{
120 RemoveFromParent();
121}

◆ Initialize()

bool UIncomingThreatWidget::Initialize ( )
overrideprotectedvirtual
11{
12 const bool bSuccess = Super::Initialize();
13 if (!ensure(ThreatBorder != nullptr)) return false;
14 if(!bSuccess) return false;
15 return true;
16}
class UBorder * ThreatBorder
Definition IncomingThreatWidget.h:46

◆ NativeConstruct()

void UIncomingThreatWidget::NativeConstruct ( )
overrideprotectedvirtual
28{
29 Super::NativeConstruct();
30 if(ThreatBorder != nullptr && ThreatMaterial == nullptr)
31 {
32 ThreatMaterial = ThreatBorder->GetDynamicMaterial();
33 }
34 if(GetOwningPlayer() != nullptr)
35 {
36 GetOwningPlayer()->GetWorldTimerManager().SetTimer(UpdateRateTimerHandle, this, &UIncomingThreatWidget::OptimizedTick, UpdateRate, true);
37 GetOwningPlayer()->GetWorldTimerManager().SetTimer(LifetimeTimerHandle, this, &UIncomingThreatWidget::Destroy, Lifetime);
38 }
39}
float UpdateRate
Definition IncomingThreatWidget.h:55
float Lifetime
Definition IncomingThreatWidget.h:58
void OptimizedTick() const
Definition IncomingThreatWidget.cpp:42
void Destroy()
Definition IncomingThreatWidget.cpp:118
UMaterialInstanceDynamic * ThreatMaterial
Definition IncomingThreatWidget.h:51
FTimerHandle LifetimeTimerHandle
Definition IncomingThreatWidget.h:82
FTimerHandle UpdateRateTimerHandle
Definition IncomingThreatWidget.h:83

◆ NativePreConstruct()

void UIncomingThreatWidget::NativePreConstruct ( )
overrideprotectedvirtual
19{
20 Super::NativePreConstruct();
21 if(ThreatBorder != nullptr && ThreatMaterial == nullptr)
22 {
23 ThreatMaterial = ThreatBorder->GetDynamicMaterial();
24 }
25}

◆ OnStartThreatIndication()

void UIncomingThreatWidget::OnStartThreatIndication ( const bool bActor,
const bool bLocation )

◆ OptimizedTick()

void UIncomingThreatWidget::OptimizedTick ( ) const
private
43{
46}
void SetThreatAngle() const
Definition IncomingThreatWidget.cpp:48
void SetThreatIntensity() const
Definition IncomingThreatWidget.cpp:72

◆ SetLifetime()

void UIncomingThreatWidget::SetLifetime ( const float Life)
inline
37{Lifetime = Life;};

◆ SetThreatAngle()

void UIncomingThreatWidget::SetThreatAngle ( ) const
private
49{
50 if(GetOwningPlayer() == nullptr){return;}
51 FVector PlayerLocation;
52 FRotator PlayerRotation;
53 // GetOwningPlayerPawn()->GetActorLocation();
54 GetOwningPlayer()->GetActorEyesViewPoint(PlayerLocation, PlayerRotation);
55 const FVector PlayerForwardVector = PlayerRotation.Vector();//GetOwningPlayerPawn()->GetActorForwardVector();
56 FVector ThreatLocation = TargetLocation;
57 if(TargetActor != nullptr)
58 {
59 ThreatLocation = TargetActor->GetActorLocation();
60 }
61 FVector PlayerMinusLocation = (PlayerLocation - ThreatLocation);
62 PlayerMinusLocation.Normalize();
63 const float Degrees = UKismetMathLibrary::DegAtan2((PlayerForwardVector.X * PlayerMinusLocation.Y) - (PlayerForwardVector.Y * PlayerMinusLocation.X), PlayerForwardVector.Dot(PlayerMinusLocation));
64 const float ClampedResult = UKismetMathLibrary::MapRangeClamped(Degrees, 180.0f, -180.0f, 0.0f, 1.0f);
65
66 if(ThreatMaterial != nullptr)
67 {
68 ThreatMaterial->SetScalarParameterValue(FName("Angle"), ClampedResult);
69 }
70}
FVector TargetLocation
Definition IncomingThreatWidget.h:68
AActor * TargetActor
Definition IncomingThreatWidget.h:70

◆ SetThreatIntensity()

void UIncomingThreatWidget::SetThreatIntensity ( ) const
private
73{
74 if(Intensity < 0){return;}
75 const float ClampedIntensityResult = UKismetMathLibrary::MapRangeClamped(Intensity, 0.0f, MaxIntensity, 0.0f, 50.0f);
76 const float ClampedAlphaResult = UKismetMathLibrary::MapRangeClamped(Intensity, 0.0f, MaxIntensity, 0.05f, 0.15f);
77
78
79 if(ThreatMaterial != nullptr)
80 {
81 ThreatMaterial->SetScalarParameterValue(FName("AlphaIntensity"), ClampedIntensityResult);
82 ThreatMaterial->SetScalarParameterValue(FName("Alpha"), ClampedAlphaResult);
83 }
84}
float Intensity
Definition IncomingThreatWidget.h:63
float MaxIntensity
Definition IncomingThreatWidget.h:60

◆ StartThreatIndicationFromActor()

void UIncomingThreatWidget::StartThreatIndicationFromActor ( AActor * ActorThreat,
const float Amount = -1.0f,
const UDamageType * DamageType = nullptr )
88{
89 TargetActor = ActorThreat;
90 Intensity = Amount;
91 TargetDamageType = const_cast<UDamageType*>(DamageType);
92 OnStartThreatIndication(true, false);
95}
void OnStartThreatIndication(const bool bActor, const bool bLocation)
UDamageType * TargetDamageType
Definition IncomingThreatWidget.h:72

◆ StartThreatIndicationFromLocation()

void UIncomingThreatWidget::StartThreatIndicationFromLocation ( const FVector & Location,
const float Amount = -1.0f,
const UDamageType * DamageType = nullptr )
98{
100 Intensity = Amount;
101 TargetDamageType = const_cast<UDamageType*>(DamageType);
102 OnStartThreatIndication(false, true);
105}

◆ StopThreatIndication()

void UIncomingThreatWidget::StopThreatIndication ( )
114{
115
116}

◆ UpdateThreatIndication()

void UIncomingThreatWidget::UpdateThreatIndication ( const FVector & Location,
const float DetectionAmount )
109{
110
111}

Member Data Documentation

◆ Intensity

float UIncomingThreatWidget::Intensity = -1.0f
protected

◆ Lifetime

float UIncomingThreatWidget::Lifetime = 4.0f
protected

◆ LifetimeTimerHandle

FTimerHandle UIncomingThreatWidget::LifetimeTimerHandle
private

◆ MaxIntensity

float UIncomingThreatWidget::MaxIntensity = 100.0f
protected

◆ Progress

float UIncomingThreatWidget::Progress = 0.0f
protected

◆ TargetActor

AActor* UIncomingThreatWidget::TargetActor = nullptr
protected

◆ TargetDamageType

UDamageType* UIncomingThreatWidget::TargetDamageType = nullptr
protected

◆ TargetLocation

FVector UIncomingThreatWidget::TargetLocation = FVector::ZeroVector
protected

◆ ThreatBorder

class UBorder* UIncomingThreatWidget::ThreatBorder = nullptr
protected

◆ ThreatMaterial

UMaterialInstanceDynamic* UIncomingThreatWidget::ThreatMaterial = nullptr
protected

◆ UpdateRate

float UIncomingThreatWidget::UpdateRate = 0.01f
protected

◆ UpdateRateTimerHandle

FTimerHandle UIncomingThreatWidget::UpdateRateTimerHandle
private

The documentation for this class was generated from the following files: