Nakatomi/Source/Nakatomi/PlayerHUDWidget.cpp

64 lines
1.5 KiB
C++
Raw Normal View History

2023-08-02 00:02:32 +02:00
// Fill out your copyright notice in the Description page of Project Settings.
#include "PlayerHUDWidget.h"
#include <Kismet/GameplayStatics.h>
#include "PlayerCharacter.h"
void UPlayerHUDWidget::NativeConstruct()
{
auto player = Cast<APlayerCharacter>(UGameplayStatics::GetPlayerCharacter(GetWorld(), 0));
if (player)
{
player->OnFired.BindUFunction(this, "ExpandCrosshair");
player->OnEnemyHit.BindUFunction(this, "ShowHitMarker");
2023-08-02 00:02:32 +02:00
}
}
void UPlayerHUDWidget::ExpandCrosshair()
{
if (CrosshairFired)
{
if (auto player = Cast<APlayerCharacter>(UGameplayStatics::GetPlayerCharacter(GetWorld(), 0)))
{
float playbackSpeed = 1.0 / player->GetCurrentWeapon()->GetWeaponProperties()->WeaponCooldown;
PlayAnimation(CrosshairFired, 0.0f, 1, EUMGSequencePlayMode::Forward, playbackSpeed);
}
}
2023-08-02 00:02:32 +02:00
}
void UPlayerHUDWidget::ShowHitMarker()
{
if (RevealHitmarker)
{
PlayAnimation(RevealHitmarker, 0.0f, 1, EUMGSequencePlayMode::Forward, 1.0f);
}
}
2024-04-11 01:34:24 +02:00
FString UPlayerHUDWidget::GetHealthbarText(APlayerCharacter* PlayerCharacter)
{
int healthbarCharacters = 5;
float normalised = PlayerCharacter->GetHealthComponent()->GetCurrentHealth() /
PlayerCharacter->GetHealthComponent()->GetMaxHealth();
float adjusted = normalised * healthbarCharacters;
int segments = FMath::RoundToInt(adjusted);
FString healthBar = FString("[");
for (int i = 0; i < segments; i++)
{
healthBar.Append("=");
}
for (int i = segments; i < healthbarCharacters; i++)
{
healthBar.Append(" ");
}
healthBar.Append("]");
return healthBar;
}