160 - Shield Bar
This commit is contained in:
parent
81ae27f9fb
commit
6a5eecca49
Binary file not shown.
|
@ -71,6 +71,7 @@ void ABlasterCharacter::GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& Ou
|
|||
|
||||
DOREPLIFETIME_CONDITION(ABlasterCharacter, OverlappingWeapon, COND_OwnerOnly);
|
||||
DOREPLIFETIME(ABlasterCharacter, Health);
|
||||
DOREPLIFETIME(ABlasterCharacter, Shield);
|
||||
DOREPLIFETIME(ABlasterCharacter, bDisableGameplay);
|
||||
}
|
||||
|
||||
|
@ -639,6 +640,15 @@ void ABlasterCharacter::OnRep_Health(float LastHealth)
|
|||
}
|
||||
}
|
||||
|
||||
void ABlasterCharacter::OnRep_Shield(float LastShield)
|
||||
{
|
||||
UpdateHUDShield();
|
||||
if (Shield < LastShield)
|
||||
{
|
||||
PlayHitReactMontage();
|
||||
}
|
||||
}
|
||||
|
||||
void ABlasterCharacter::UpdateHUDHealth()
|
||||
{
|
||||
BlasterPlayerController = BlasterPlayerController == nullptr ? Cast<ABlasterPlayerController>(Controller) : BlasterPlayerController;
|
||||
|
@ -648,6 +658,15 @@ void ABlasterCharacter::UpdateHUDHealth()
|
|||
}
|
||||
}
|
||||
|
||||
void ABlasterCharacter::UpdateHUDShield()
|
||||
{
|
||||
BlasterPlayerController = BlasterPlayerController == nullptr ? Cast<ABlasterPlayerController>(Controller) : BlasterPlayerController;
|
||||
if (BlasterPlayerController)
|
||||
{
|
||||
BlasterPlayerController->SetHUDShield(Shield, MaxShield);
|
||||
}
|
||||
}
|
||||
|
||||
void ABlasterCharacter::PollInit()
|
||||
{
|
||||
if (BlasterPlayerState == nullptr)
|
||||
|
|
|
@ -42,6 +42,7 @@ public:
|
|||
void ShowSniperScopeWidget(bool bShowScope);
|
||||
|
||||
void UpdateHUDHealth();
|
||||
void UpdateHUDShield();
|
||||
|
||||
protected:
|
||||
virtual void BeginPlay() override;
|
||||
|
@ -148,6 +149,17 @@ private:
|
|||
UFUNCTION()
|
||||
void OnRep_Health(float LastHealth);
|
||||
|
||||
// Shield
|
||||
|
||||
UPROPERTY(EditAnywhere, Category= "Player Stats")
|
||||
float MaxShield = 100.f;
|
||||
|
||||
UPROPERTY(ReplicatedUsing = OnRep_Shield, VisibleAnywhere, Category= "Player Stats")
|
||||
float Shield = 50.f;
|
||||
|
||||
UFUNCTION()
|
||||
void OnRep_Shield(float LastShield);
|
||||
|
||||
UPROPERTY()
|
||||
class ABlasterPlayerController* BlasterPlayerController;
|
||||
|
||||
|
|
|
@ -22,6 +22,12 @@ public:
|
|||
UPROPERTY(meta = (BindWidget))
|
||||
class UTextBlock* HealthText;
|
||||
|
||||
UPROPERTY(meta = (BindWidget))
|
||||
UProgressBar* ShieldBar;
|
||||
|
||||
UPROPERTY(meta = (BindWidget))
|
||||
UTextBlock* ShieldText;
|
||||
|
||||
UPROPERTY(meta = (BindWidget))
|
||||
UTextBlock* ScoreValue;
|
||||
|
||||
|
|
|
@ -164,6 +164,28 @@ void ABlasterPlayerController::SetHUDHealth(float Health, float MaxHealth)
|
|||
}
|
||||
}
|
||||
|
||||
void ABlasterPlayerController::SetHUDShield(float Shield, float MaxShield)
|
||||
{
|
||||
BlasterHUD = BlasterHUD == nullptr ? Cast<ABlasterHUD>(GetHUD()) : BlasterHUD;
|
||||
bool bHUDValid = BlasterHUD &&
|
||||
BlasterHUD->CharacterOverlay &&
|
||||
BlasterHUD->CharacterOverlay->ShieldBar &&
|
||||
BlasterHUD->CharacterOverlay->ShieldText;
|
||||
if (bHUDValid)
|
||||
{
|
||||
const float ShieldPercent = Shield / MaxShield;
|
||||
BlasterHUD->CharacterOverlay->ShieldBar->SetPercent(ShieldPercent);
|
||||
FString ShieldText = FString::Printf(TEXT("%d/%d"), FMath::CeilToInt(Shield), FMath::CeilToInt(MaxShield));
|
||||
BlasterHUD->CharacterOverlay->ShieldText->SetText(FText::FromString(ShieldText));
|
||||
}
|
||||
else
|
||||
{
|
||||
bInitializeCharacterOverlay = true;
|
||||
HUDShield = Shield;
|
||||
HUDMaxShield = MaxShield;
|
||||
}
|
||||
}
|
||||
|
||||
void ABlasterPlayerController::SetHUDScore(float Score)
|
||||
{
|
||||
BlasterHUD = BlasterHUD == nullptr ? Cast<ABlasterHUD>(GetHUD()) : BlasterHUD;
|
||||
|
@ -341,6 +363,7 @@ void ABlasterPlayerController::PollInit()
|
|||
if (CharacterOverlay)
|
||||
{
|
||||
SetHUDHealth(HUDHealth, HUDMaxHealth);
|
||||
SetHUDShield(HUDShield, HUDMaxShield);
|
||||
SetHUDScore(HUDScore);
|
||||
SetHUDDefeats(HUDDefeats);
|
||||
ABlasterCharacter* BlasterCharacter = Cast<ABlasterCharacter>(GetPawn());
|
||||
|
|
|
@ -30,6 +30,7 @@ public:
|
|||
void SetDebugMsg7(FString Key, FString Value);
|
||||
|
||||
void SetHUDHealth(float Health, float MaxHealth);
|
||||
void SetHUDShield(float Shield, float MaxShield);
|
||||
void SetHUDScore(float Score);
|
||||
void SetHUDDefeats(int32 Defeats);
|
||||
void SetHUDWeaponAmmo(int32 Ammo);
|
||||
|
@ -104,6 +105,8 @@ private:
|
|||
|
||||
float HUDHealth;
|
||||
float HUDMaxHealth;
|
||||
float HUDShield;
|
||||
float HUDMaxShield;
|
||||
float HUDScore;
|
||||
int32 HUDDefeats;
|
||||
int32 HUDGrenades;
|
||||
|
|
Loading…
Reference in New Issue