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

A widget class used for displaying health-related information in the HUD. Including Health Bar & Low Health Vignette. More...

#include <HealthHUDWidget.h>

Inheritance diagram for UHealthHUDWidget:
IHealthInterface

Public Member Functions

virtual void NativePreConstruct () override
 
virtual void NativeConstruct () override
 
virtual void HealthChanged (const float Health, const float MaxHealth, const class UDamageType *DamageType) override
 
virtual void HealthAndShieldChanged (const float Health, const float MaxHealth, const float ShieldHealth, const float MaxShieldHealth, const class UDamageType *DamageType) override
 
virtual void ShieldBreak () override
 
virtual void InjuredBodyPart (const EBodyPartName InjuredBodyPart, const FVector &HitLocation, const TArray< FBodyPart > &AllBodyParts) override
 
virtual void SetHasShield (const bool bHasShield) override
 

Protected Member Functions

virtual bool Initialize () override
 
void ApplyDamageMaterial ()
 

Protected Attributes

FLinearColor HealthColor = FLinearColor(0.548611f, 0.0f, 0.0f, 0.0f)
 
FLinearColor ShieldColor = FLinearColor(0.1f, 0.0f, 0.5f, 0.0f)
 
UMaterialInterface * DamageVignetteMaterial = nullptr
 
UMaterialInstanceDynamic * DamageVignette = nullptr
 
class UHealthWidgetHealthWidget = nullptr
 
class UImage * LowHealthImage = nullptr
 

Private Attributes

bool bShield = false
 

Detailed Description

A widget class used for displaying health-related information in the HUD. Including Health Bar & Low Health Vignette.

Todo
Add in Damage Indicator

Member Function Documentation

◆ ApplyDamageMaterial()

void UHealthHUDWidget::ApplyDamageMaterial ( )
protected
33{
34 if(DamageVignette != nullptr){return;}
35 if(DamageVignetteMaterial == nullptr)
36 {
37 UE_LOG(LogHealthSystem, Error, TEXT("UHealthHUDWidget::ApplyDamageMaterial: Add Damage Vin Material"));
38 return;
39 }
40 if(GetWorld() != nullptr)
41 {
42 DamageVignette = UKismetMaterialLibrary::CreateDynamicMaterialInstance(GetWorld(), DamageVignetteMaterial);
43 if(LowHealthImage != nullptr)
44 {
45 LowHealthImage->SetBrushFromMaterial(DamageVignette);
46 }
47 }
48}
UMaterialInstanceDynamic * DamageVignette
Definition HealthHUDWidget.h:46
UMaterialInterface * DamageVignetteMaterial
Definition HealthHUDWidget.h:43
class UImage * LowHealthImage
Definition HealthHUDWidget.h:52

◆ HealthAndShieldChanged()

void UHealthHUDWidget::HealthAndShieldChanged ( const float Health,
const float MaxHealth,
const float ShieldHealth,
const float MaxShieldHealth,
const class UDamageType * DamageType )
overridevirtual

Implements IHealthInterface.

61{
62 HealthWidget->UpdateHealthAndShield(Health, MaxHealth, ShieldHealth, MaxShieldHealth, DamageType);
63 if(DamageVignette != nullptr)
64 {
65 DamageVignette->SetScalarParameterValue(FName("Opacity"), ((Health / MaxHealth) - 1.0f) * -1.0f);
66 if(bShield)
67 {
68 if(ShieldHealth > 5.0f)
69 {
70 DamageVignette->SetScalarParameterValue(FName("Opacity"), ((ShieldHealth / MaxShieldHealth) - 1.0f) * -1.0f);
71 DamageVignette->SetVectorParameterValue(FName("Color"), ShieldColor);
72 }
73 else
74 {
75 DamageVignette->SetScalarParameterValue(FName("Opacity"), ((Health / MaxHealth) - 1.0f) * -1.0f);
76 DamageVignette->SetVectorParameterValue(FName("Color"), HealthColor);
77 }
78 }
79 }
80}
Definition Health.Build.cs:6
FLinearColor ShieldColor
Definition HealthHUDWidget.h:40
FLinearColor HealthColor
Definition HealthHUDWidget.h:38
bool bShield
Definition HealthHUDWidget.h:59
class UHealthWidget * HealthWidget
Definition HealthHUDWidget.h:50
void UpdateHealthAndShield(const float CurrentHealth, const float MaxHealth, const float CurrentShieldHealth, const float MaxShieldHealth, const class UDamageType *DamageType=nullptr)

◆ HealthChanged()

void UHealthHUDWidget::HealthChanged ( const float Health,
const float MaxHealth,
const class UDamageType * DamageType )
overridevirtual

Implements IHealthInterface.

51{
52 HealthWidget->UpdateHealth(Health, MaxHealth, DamageType);
53 if(DamageVignette != nullptr)
54 {
55 DamageVignette->SetScalarParameterValue(FName("Opacity"), ((Health / MaxHealth) - 1.0f) * -1.0f);
56 }
57}
void UpdateHealth(const float CurrentHealth, const float MaxHealth, const class UDamageType *DamageType)

◆ Initialize()

bool UHealthHUDWidget::Initialize ( )
overrideprotectedvirtual
24{
25 const bool Success = Super::Initialize();
26 if(!Success) return false;
27 if (!ensure(HealthWidget != nullptr)) return false;
28 if (!ensure(LowHealthImage != nullptr)) return false;
29 return true;
30}

◆ InjuredBodyPart()

void UHealthHUDWidget::InjuredBodyPart ( const EBodyPartName InjuredBodyPart,
const FVector & HitLocation,
const TArray< FBodyPart > & AllBodyParts )
overridevirtual

Implements IHealthInterface.

90{
91 HealthWidget->InjuredBodyPart(InjuredBodyPart, HitLocation, AllBodyParts);
92}
virtual void InjuredBodyPart(const EBodyPartName InjuredBodyPart, const FVector &HitLocation, const TArray< FBodyPart > &AllBodyParts) override
Definition HealthHUDWidget.cpp:88
void InjuredBodyPart(EBodyPartName InjuredBodyPart, FVector HitLocation, const TArray< FBodyPart > &AllBodyParts)

◆ NativeConstruct()

void UHealthHUDWidget::NativeConstruct ( )
overridevirtual
18{
19 Super::NativeConstruct();
21}
void ApplyDamageMaterial()
Definition HealthHUDWidget.cpp:32

◆ NativePreConstruct()

void UHealthHUDWidget::NativePreConstruct ( )
overridevirtual
12{
13 Super::NativePreConstruct();
15}

◆ SetHasShield()

void UHealthHUDWidget::SetHasShield ( const bool bHasShield)
overridevirtual

Implements IHealthInterface.

95{
96 bShield = bHasShield;
97 HealthWidget->SetHasShield(bHasShield);
98 if(bHasShield)
99 {
100 DamageVignette->SetVectorParameterValue(FName("Color"), ShieldColor);
101 }
102 else
103 {
104 DamageVignette->SetVectorParameterValue(FName("Color"), HealthColor);
105 }
106
107}
void SetHasShield(const bool in_bHasShield)
Definition HealthWidget.cpp:53

◆ ShieldBreak()

void UHealthHUDWidget::ShieldBreak ( )
overridevirtual

Implements IHealthInterface.

83{
85 DamageVignette->SetVectorParameterValue(FName("Color"), HealthColor);
86}
void ShieldBroken()

Member Data Documentation

◆ bShield

bool UHealthHUDWidget::bShield = false
private

◆ DamageVignette

UMaterialInstanceDynamic* UHealthHUDWidget::DamageVignette = nullptr
protected

◆ DamageVignetteMaterial

UMaterialInterface* UHealthHUDWidget::DamageVignetteMaterial = nullptr
protected

◆ HealthColor

FLinearColor UHealthHUDWidget::HealthColor = FLinearColor(0.548611f, 0.0f, 0.0f, 0.0f)
protected

◆ HealthWidget

class UHealthWidget* UHealthHUDWidget::HealthWidget = nullptr
protected

◆ LowHealthImage

class UImage* UHealthHUDWidget::LowHealthImage = nullptr
protected

◆ ShieldColor

FLinearColor UHealthHUDWidget::ShieldColor = FLinearColor(0.1f, 0.0f, 0.5f, 0.0f)
protected

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