From 2a338971987d0446cfb109d094669e2d9293ae29 Mon Sep 17 00:00:00 2001 From: Louis Hobbs Date: Tue, 8 Aug 2023 22:31:37 +0100 Subject: [PATCH] Add Hitmarker HUD asset, animation and Enemy Hit Delegate --- Content/UI/WidgetHUD.uasset | 4 ++-- Source/Nakatomi/PlayerCharacter.cpp | 2 ++ Source/Nakatomi/PlayerCharacter.h | 4 ++++ Source/Nakatomi/PlayerHUDWidget.cpp | 9 +++++++++ Source/Nakatomi/PlayerHUDWidget.h | 9 +++++++++ 5 files changed, 26 insertions(+), 2 deletions(-) diff --git a/Content/UI/WidgetHUD.uasset b/Content/UI/WidgetHUD.uasset index 14ae101..cb81fb4 100644 --- a/Content/UI/WidgetHUD.uasset +++ b/Content/UI/WidgetHUD.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:3328013e820944df8a863932da622b33025137290968e81f8cea55385e3f7e98 -size 152326 +oid sha256:bc50946c35629b3ad7c3b110521a40347f57233611a5631151e22cd4ad1f5743 +size 164044 diff --git a/Source/Nakatomi/PlayerCharacter.cpp b/Source/Nakatomi/PlayerCharacter.cpp index d5e3618..d488a62 100644 --- a/Source/Nakatomi/PlayerCharacter.cpp +++ b/Source/Nakatomi/PlayerCharacter.cpp @@ -342,6 +342,8 @@ void APlayerCharacter::ProcessHits(TArray hits) { healthComponent->TakeDamage(Hit.GetActor(), CurrentWeapon->GetWeaponProperties()->WeaponDamage, nullptr, GetController(), this); + + OnEnemyHit.ExecuteIfBound(); } } } diff --git a/Source/Nakatomi/PlayerCharacter.h b/Source/Nakatomi/PlayerCharacter.h index f6a03cc..cfe6171 100644 --- a/Source/Nakatomi/PlayerCharacter.h +++ b/Source/Nakatomi/PlayerCharacter.h @@ -19,6 +19,8 @@ class UInputAction; class UInputMappingContext; +DECLARE_DELEGATE(FOnEnemyHitDelegate) + /** * */ @@ -61,6 +63,8 @@ public: UPROPERTY(EditDefaultsOnly, BlueprintReadWrite) TSubclassOf PlayerHUD; + FOnEnemyHitDelegate OnEnemyHit; + protected: UPROPERTY(EditDefaultsOnly, BlueprintReadWrite) float SprintSpeedMultiplier = 2.0f; diff --git a/Source/Nakatomi/PlayerHUDWidget.cpp b/Source/Nakatomi/PlayerHUDWidget.cpp index 98633af..bf73bbc 100644 --- a/Source/Nakatomi/PlayerHUDWidget.cpp +++ b/Source/Nakatomi/PlayerHUDWidget.cpp @@ -12,6 +12,7 @@ void UPlayerHUDWidget::NativeConstruct() if (player) { player->OnFired.BindUFunction(this, "ExpandCrosshair"); + player->OnEnemyHit.BindUFunction(this, "ShowHitMarker"); } } @@ -25,3 +26,11 @@ void UPlayerHUDWidget::ExpandCrosshair() PlayAnimation(CrosshairFired, 0.0f, 1, EUMGSequencePlayMode::Forward, playbackSpeed); } } + +void UPlayerHUDWidget::ShowHitMarker() +{ + if (RevealHitmarker) + { + PlayAnimation(RevealHitmarker, 0.0f, 1, EUMGSequencePlayMode::Forward, 1.0f); + } +} diff --git a/Source/Nakatomi/PlayerHUDWidget.h b/Source/Nakatomi/PlayerHUDWidget.h index dc1deb2..3afbf99 100644 --- a/Source/Nakatomi/PlayerHUDWidget.h +++ b/Source/Nakatomi/PlayerHUDWidget.h @@ -26,6 +26,9 @@ public: UFUNCTION() void ExpandCrosshair(); + UFUNCTION() + void ShowHitMarker(); + UPROPERTY(BlueprintReadWrite, meta = (BindWidget)) UTextBlock* HealthText; @@ -47,6 +50,12 @@ public: UPROPERTY(BlueprintReadWrite, meta = (BindWidget)) UImage* CrosshairImage; + UPROPERTY(BlueprintReadWrite, meta = (BindWidget)) + UImage* HitmarkerImage; + UPROPERTY(Transient, meta = (BindWidgetAnim)) UWidgetAnimation* CrosshairFired; + + UPROPERTY(Transient, meta = (BindWidgetAnim)) + UWidgetAnimation* RevealHitmarker; };