Create basic HUD

This commit is contained in:
baz 2024-08-14 00:19:47 +01:00
parent 0d5858f421
commit 707728940a
8 changed files with 63 additions and 8 deletions

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

Binary file not shown.

BIN
Content/Widgets/HUD/BP_HUDWidget.uasset (Stored with Git LFS) Normal file

Binary file not shown.

View File

@ -27,19 +27,19 @@ public:
// Sets default values for this component's properties // Sets default values for this component's properties
UEXPComponent(); UEXPComponent();
UFUNCTION() UFUNCTION(BlueprintCallable)
void IncrementEXP(int value); void IncrementEXP(int value);
UFUNCTION() UFUNCTION(BlueprintCallable)
void SetCurrentEXP(int value); void SetCurrentEXP(int value);
UFUNCTION() UFUNCTION(BlueprintCallable, BlueprintPure)
int GetCurrentEXP(); int GetCurrentEXP();
UFUNCTION() UFUNCTION(BlueprintCallable, BlueprintPure)
int GetCurrentLevel(); int GetCurrentLevel();
UFUNCTION() UFUNCTION(BlueprintCallable)
void Reset(); void Reset();
protected: protected:

View File

@ -40,6 +40,16 @@ APlayerCharacter::APlayerCharacter()
void APlayerCharacter::BeginPlay() void APlayerCharacter::BeginPlay()
{ {
Super::BeginPlay(); Super::BeginPlay();
if (PlayerHUD)
{
currentPlayerHUD = UUserWidget::CreateWidgetInstance(*GetWorld(), PlayerHUD, FName("Player HUD"));
if (currentPlayerHUD)
{
currentPlayerHUD->AddToViewport();
}
}
} }
void APlayerCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent) void APlayerCharacter::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)

View File

@ -9,6 +9,7 @@
#include "WeaponInventoryComponent.h" #include "WeaponInventoryComponent.h"
#include "Camera/CameraComponent.h" #include "Camera/CameraComponent.h"
#include "GameFramework/SpringArmComponent.h" #include "GameFramework/SpringArmComponent.h"
#include "Blueprint/UserWidget.h"
#include "PlayerCharacter.generated.h" #include "PlayerCharacter.generated.h"
class UInputMappingContext; class UInputMappingContext;
@ -46,9 +47,14 @@ public:
FVector2D PreviousMovementDirection = FVector2d(1.0f, 0.0f); FVector2D PreviousMovementDirection = FVector2d(1.0f, 0.0f);
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
TSubclassOf<UUserWidget> PlayerHUD = nullptr;
private: private:
FTimerHandle GarlicTimerHandle; FTimerHandle GarlicTimerHandle;
UUserWidget* currentPlayerHUD = nullptr;
public: public:
APlayerCharacter(); APlayerCharacter();

View File

@ -0,0 +1,5 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "HUDWidget.h"

View File

@ -0,0 +1,30 @@
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "Blueprint/UserWidget.h"
#include "Components/ProgressBar.h"
#include "Components/TextBlock.h"
#include "HUDWidget.generated.h"
/**
*
*/
UCLASS()
class VAMPIRES_API UHUDWidget : public UUserWidget
{
GENERATED_BODY()
public:
UPROPERTY(BlueprintReadWrite, meta = (BindWidget))
UProgressBar* EXPbar;
UPROPERTY(BlueprintReadWrite, meta = (BindWidget))
UTextBlock* LevelBlock;
UPROPERTY(BlueprintReadWrite, meta = (BindWidget))
UTextBlock* TimerBLock;
};

View File

@ -10,7 +10,8 @@
"LoadingPhase": "Default", "LoadingPhase": "Default",
"AdditionalDependencies": [ "AdditionalDependencies": [
"Engine", "Engine",
"AIModule" "AIModule",
"UMG"
] ]
} }
], ],