Add basic Player HUD

This commit is contained in:
Louis Hobbs 2023-02-06 01:07:01 +00:00
parent 3632cf19f0
commit 8e59d1a8b7
7 changed files with 52 additions and 5 deletions

BIN
Content/Player/DefaultGamemode.uasset (Stored with Git LFS)

Binary file not shown.

BIN
Content/Player/PlayerCharacter.uasset (Stored with Git LFS)

Binary file not shown.

BIN
Content/UI/PlayerHUD.uasset (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Content/UI/WidgetHUD.uasset (Stored with Git LFS) Normal file

Binary file not shown.

View File

@ -8,7 +8,7 @@ public class Nakatomi : ModuleRules
{ {
PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs; PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;
PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "EnhancedInput", "FieldSystemEngine", "GeometryCollectionEngine" }); PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "EnhancedInput", "FieldSystemEngine", "GeometryCollectionEngine", "UMG" });
PrivateDependencyModuleNames.AddRange(new string[] { }); PrivateDependencyModuleNames.AddRange(new string[] { });

View File

@ -63,6 +63,15 @@ void APlayerCharacter::BeginPlay()
this->Tags.Add(FName("Player")); this->Tags.Add(FName("Player"));
} }
if (PlayerHUD)
{
currentPlayerHUD = UUserWidget::CreateWidgetInstance(*GetWorld(), PlayerHUD, FName("PLayer HUD"));
if (currentPlayerHUD)
{
currentPlayerHUD->AddToViewport();
}
}
} }
// Called every frame // Called every frame
@ -469,3 +478,23 @@ void APlayerCharacter::ClearAllTimers()
GetWorldTimerManager().ClearTimer(FireTimerHandle); GetWorldTimerManager().ClearTimer(FireTimerHandle);
GetWorldTimerManager().ClearTimer(CooldownTimerHandle); GetWorldTimerManager().ClearTimer(CooldownTimerHandle);
} }
int APlayerCharacter::GetCurrentAmmoCount()
{
if (CurrentWeapon == nullptr)
{
return -1;
}
return CurrentWeapon->GetAmmoCount();
}
float APlayerCharacter::GetCurrentHealthCount()
{
if (!GetHealthComponent())
{
return -1;
}
return GetHealthComponent()->GetCurrentHealth();
}

View File

@ -11,6 +11,7 @@
#include "Weapon.h" #include "Weapon.h"
#include "Engine/EngineTypes.h" #include "Engine/EngineTypes.h"
#include "Engine/DamageEvents.h" #include "Engine/DamageEvents.h"
#include "Blueprint/UserWidget.h"
#include "PlayerCharacter.generated.h" #include "PlayerCharacter.generated.h"
class UInputAction; class UInputAction;
@ -59,6 +60,9 @@ public:
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite) UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
UInputAction* WeaponSwitchingAction; UInputAction* WeaponSwitchingAction;
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
TSubclassOf<class UUserWidget> PlayerHUD;
protected: protected:
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite) UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
@ -85,6 +89,8 @@ private:
bool IsFiring = false; bool IsFiring = false;
class UUserWidget* currentPlayerHUD;
public: public:
// Sets default values for this character's properties // Sets default values for this character's properties
APlayerCharacter(); APlayerCharacter();
@ -147,4 +153,10 @@ public:
void WeaponCooldownHandler(); void WeaponCooldownHandler();
void ClearAllTimers(); void ClearAllTimers();
UFUNCTION(BlueprintCallable)
int GetCurrentAmmoCount();
UFUNCTION(BlueprintCallable)
float GetCurrentHealthCount();
}; };