From dc9339ef903c9e5bff01deef4ad0e6c185b944ab Mon Sep 17 00:00:00 2001 From: Louis Hobbs Date: Tue, 1 Aug 2023 23:02:32 +0100 Subject: [PATCH] Create PlayerHUDWidget --- Content/UI/WidgetHUD.uasset | 4 +-- Nakatomi.uproject | 3 +- Source/Nakatomi/NakatomiCharacter.cpp | 1 + Source/Nakatomi/NakatomiCharacter.h | 8 +++++ Source/Nakatomi/PlayerCharacter.cpp | 2 ++ Source/Nakatomi/PlayerHUDWidget.cpp | 20 +++++++++++ Source/Nakatomi/PlayerHUDWidget.h | 49 +++++++++++++++++++++++++++ 7 files changed, 84 insertions(+), 3 deletions(-) create mode 100644 Source/Nakatomi/PlayerHUDWidget.cpp create mode 100644 Source/Nakatomi/PlayerHUDWidget.h diff --git a/Content/UI/WidgetHUD.uasset b/Content/UI/WidgetHUD.uasset index e1ca1e2..4cc1ad3 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:08a41645db9e71ba6c95cd7cfb6ab28646dbfd65e11e06e6b3d32ebfe61add23 -size 142032 +oid sha256:b5ca37fc88274daecf4f8fbb27ad550719a79a1b315bf8b77fbeeb2bb2d5f546 +size 140409 diff --git a/Nakatomi.uproject b/Nakatomi.uproject index 39400ad..f6d66c5 100644 --- a/Nakatomi.uproject +++ b/Nakatomi.uproject @@ -11,7 +11,8 @@ "AdditionalDependencies": [ "Engine", "FieldSystemEngine", - "AIModule" + "AIModule", + "UMG" ] } ], diff --git a/Source/Nakatomi/NakatomiCharacter.cpp b/Source/Nakatomi/NakatomiCharacter.cpp index bd32960..d759281 100644 --- a/Source/Nakatomi/NakatomiCharacter.cpp +++ b/Source/Nakatomi/NakatomiCharacter.cpp @@ -211,6 +211,7 @@ int ANakatomiCharacter::GetCurrentInventorySlot() void ANakatomiCharacter::OnFire() { + OnFired.ExecuteIfBound(); } void ANakatomiCharacter::CalculateHits(TArray* hits) diff --git a/Source/Nakatomi/NakatomiCharacter.h b/Source/Nakatomi/NakatomiCharacter.h index ddc78e1..49eef2b 100644 --- a/Source/Nakatomi/NakatomiCharacter.h +++ b/Source/Nakatomi/NakatomiCharacter.h @@ -8,6 +8,10 @@ #include "Weapon.h" #include "NakatomiCharacter.generated.h" + +DECLARE_DELEGATE(FOnFireDelegate) + + /** * */ @@ -16,6 +20,10 @@ class NAKATOMI_API ANakatomiCharacter : public ACharacter { GENERATED_BODY() +public: + + FOnFireDelegate OnFired; + public: UPROPERTY(EditDefaultsOnly, BlueprintReadWrite) TArray> DefaultWeaponInventory; diff --git a/Source/Nakatomi/PlayerCharacter.cpp b/Source/Nakatomi/PlayerCharacter.cpp index 18d29be..d5e3618 100644 --- a/Source/Nakatomi/PlayerCharacter.cpp +++ b/Source/Nakatomi/PlayerCharacter.cpp @@ -479,6 +479,8 @@ void APlayerCharacter::OnFire() { RemoveCurrentWeaponFromInventory(); } + + Super::OnFire(); } void APlayerCharacter::WeaponCooldownHandler() diff --git a/Source/Nakatomi/PlayerHUDWidget.cpp b/Source/Nakatomi/PlayerHUDWidget.cpp new file mode 100644 index 0000000..fd74640 --- /dev/null +++ b/Source/Nakatomi/PlayerHUDWidget.cpp @@ -0,0 +1,20 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "PlayerHUDWidget.h" +#include +#include "PlayerCharacter.h" + +void UPlayerHUDWidget::NativeConstruct() +{ + auto player = Cast(UGameplayStatics::GetPlayerCharacter(GetWorld(), 0)); + + if (player) + { + player->OnFired.BindUFunction(this, "ExpandCrosshair"); + } +} + +void UPlayerHUDWidget::ExpandCrosshair() +{ +} diff --git a/Source/Nakatomi/PlayerHUDWidget.h b/Source/Nakatomi/PlayerHUDWidget.h new file mode 100644 index 0000000..07ac7b9 --- /dev/null +++ b/Source/Nakatomi/PlayerHUDWidget.h @@ -0,0 +1,49 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "Blueprint/UserWidget.h" +#include +#include +#include "PlayerHUDWidget.generated.h" + + +/** + * + */ +UCLASS() +class NAKATOMI_API UPlayerHUDWidget : public UUserWidget +{ + GENERATED_BODY() + + +public: + + + virtual void NativeConstruct() override; + + UFUNCTION() + void ExpandCrosshair(); + + UPROPERTY(BlueprintReadWrite, meta = (BindWidget)) + UTextBlock* HealthText; + + UPROPERTY(BlueprintReadWrite, meta = (BindWidget)) + UTextBlock* AmmoText; + + UPROPERTY(BlueprintReadWrite, meta = (BindWidget)) + UTextBlock* AmmoStaticText; + + UPROPERTY(BlueprintReadWrite, meta = (BindWidget)) + UTextBlock* ProjectilesText; + + UPROPERTY(BlueprintReadWrite, meta = (BindWidget)) + UTextBlock* CooldownText; + + UPROPERTY(BlueprintReadWrite, meta = (BindWidget)) + UTextBlock* SpreadText; + + UPROPERTY(BlueprintReadWrite, meta = (BindWidget)) + UImage* CrosshairImage; +};