36 lines
1.0 KiB
C++
36 lines
1.0 KiB
C++
// Fill out your copyright notice in the Description page of Project Settings.
|
|
|
|
|
|
#include "BlasterPlayerController.h"
|
|
|
|
#include "Blaster/HUD/BlasterHUD.h"
|
|
#include "Blaster/HUD/CharacterOverlay.h"
|
|
#include "Components/ProgressBar.h"
|
|
#include "Components/TextBlock.h"
|
|
|
|
|
|
void ABlasterPlayerController::BeginPlay()
|
|
{
|
|
Super::BeginPlay();
|
|
|
|
BlasterHUD = Cast<ABlasterHUD>(GetHUD());
|
|
}
|
|
|
|
void ABlasterPlayerController::SetHUDHealth(float Health, float MaxHealth)
|
|
{
|
|
BlasterHUD = BlasterHUD == nullptr ? Cast<ABlasterHUD>(GetHUD()) : BlasterHUD;
|
|
bool bHUDValid =
|
|
BlasterHUD &&
|
|
BlasterHUD->CharacterOverlay &&
|
|
BlasterHUD->CharacterOverlay->HealthBar &&
|
|
BlasterHUD->CharacterOverlay->HealthText;
|
|
|
|
if (bHUDValid)
|
|
{
|
|
const float HealthPercent = Health / MaxHealth;
|
|
BlasterHUD->CharacterOverlay->HealthBar->SetPercent(HealthPercent);
|
|
const FString HealthText = FString::Printf(TEXT("%d/%d"), FMath::CeilToInt(Health), FMath::CeilToInt(MaxHealth));
|
|
BlasterHUD->CharacterOverlay->HealthText->SetText(FText::FromString(HealthText));
|
|
}
|
|
}
|