From a25f08b83234e4f9aafb76b2e5491053a087bbdc Mon Sep 17 00:00:00 2001 From: baz Date: Thu, 11 Apr 2024 00:34:24 +0100 Subject: [PATCH] Replace health number with symbols --- Content/UI/HUD/WidgetHUD.uasset | 4 ++-- Source/Nakatomi/PlayerHUDWidget.cpp | 25 +++++++++++++++++++++++++ Source/Nakatomi/PlayerHUDWidget.h | 5 +++++ 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/Content/UI/HUD/WidgetHUD.uasset b/Content/UI/HUD/WidgetHUD.uasset index 0db4990..6d1c862 100644 --- a/Content/UI/HUD/WidgetHUD.uasset +++ b/Content/UI/HUD/WidgetHUD.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:d4a6bfd75593a8de5b58f870ab2a01503df4f7bd9d1487e7280fee375efe48be -size 178660 +oid sha256:b22a973840330092ea790a347f44a779d128812c96aea3a066a8337ad27e94e0 +size 176337 diff --git a/Source/Nakatomi/PlayerHUDWidget.cpp b/Source/Nakatomi/PlayerHUDWidget.cpp index e19c4ba..8e9c00d 100644 --- a/Source/Nakatomi/PlayerHUDWidget.cpp +++ b/Source/Nakatomi/PlayerHUDWidget.cpp @@ -36,3 +36,28 @@ void UPlayerHUDWidget::ShowHitMarker() PlayAnimation(RevealHitmarker, 0.0f, 1, EUMGSequencePlayMode::Forward, 1.0f); } } + +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; +} diff --git a/Source/Nakatomi/PlayerHUDWidget.h b/Source/Nakatomi/PlayerHUDWidget.h index 3afbf99..9b80a90 100644 --- a/Source/Nakatomi/PlayerHUDWidget.h +++ b/Source/Nakatomi/PlayerHUDWidget.h @@ -6,6 +6,8 @@ #include "Blueprint/UserWidget.h" #include #include + +#include "PlayerCharacter.h" #include "PlayerHUDWidget.generated.h" @@ -29,6 +31,9 @@ public: UFUNCTION() void ShowHitMarker(); + UFUNCTION(BlueprintCallable) + FString GetHealthbarText(APlayerCharacter* PlayerCharacter); + UPROPERTY(BlueprintReadWrite, meta = (BindWidget)) UTextBlock* HealthText;