Compare commits

..

5 Commits

12 changed files with 97 additions and 32 deletions

Binary file not shown.

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

Binary file not shown.

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

Binary file not shown.

View File

@ -19,13 +19,13 @@ void UEXPComponent::IncrementEXP(int value)
int oldLevel = CurrentLevel;
CurrentEXP += value;
OnEXPGained.ExecuteIfBound(value);
OnEXPGained.Broadcast(CurrentEXP, GetCurrentLevelPercent());
CurrentLevel = FMath::Floor(CurrentEXP / 100.0f);
if (CurrentLevel != oldLevel)
{
OnEXPLevelUp.ExecuteIfBound(CurrentLevel);
OnEXPLevelUp.Broadcast(CurrentLevel);
}
}
@ -36,13 +36,13 @@ void UEXPComponent::SetCurrentEXP(int value)
// TODO: I should be updating the level here
CurrentEXP = value;
OnEXPGained.ExecuteIfBound(value);
OnEXPGained.Broadcast(CurrentEXP, GetCurrentLevelPercent());
CurrentLevel = FMath::Floor(CurrentEXP / 100.0f);
if (CurrentLevel != oldLevel)
{
OnEXPLevelUp.ExecuteIfBound(CurrentLevel);
OnEXPLevelUp.Broadcast(CurrentLevel);
}
}
@ -60,8 +60,8 @@ void UEXPComponent::Reset()
{
CurrentEXP = 0;
CurrentLevel = 0;
OnEXPGained.ExecuteIfBound(CurrentEXP);
OnEXPLevelUp.ExecuteIfBound(CurrentLevel);
OnEXPGained.Broadcast(CurrentEXP, GetCurrentLevelPercent());
OnEXPLevelUp.Broadcast(CurrentLevel);
}
float UEXPComponent::GetCurrentLevelPercent()

View File

@ -6,8 +6,8 @@
#include "Components/ActorComponent.h"
#include "EXPComponent.generated.h"
DECLARE_DELEGATE_OneParam(FOnEXPGainedDelegate, int)
DECLARE_DELEGATE_OneParam(FOnEXPLevelUpDelegate, int)
DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FOnEXPGainedDelegate, int, exp, float, currentLevelPercent);
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnEXPLevelUpDelegate, int, level);
UCLASS(ClassGroup=(Custom), meta=(BlueprintSpawnableComponent))
class VAMPIRES_API UEXPComponent : public UActorComponent
@ -15,7 +15,10 @@ class VAMPIRES_API UEXPComponent : public UActorComponent
GENERATED_BODY()
public:
UPROPERTY(BlueprintAssignable, Category="EXP")
FOnEXPGainedDelegate OnEXPGained;
UPROPERTY(BlueprintAssignable, Category="EXP")
FOnEXPLevelUpDelegate OnEXPLevelUp;
protected:

View File

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

View File

@ -48,17 +48,12 @@ public:
FVector2D PreviousMovementDirection = FVector2d(1.0f, 0.0f);
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
TSubclassOf<UUserWidget> PlayerHUD = nullptr;
UPROPERTY(EditAnywhere)
UWidgetComponent* HealthBarWidgetComponent;
private:
FTimerHandle GarlicTimerHandle;
UUserWidget* currentPlayerHUD = nullptr;
public:
APlayerCharacter();

View File

@ -3,3 +3,36 @@
#include "VampirePlayerController.h"
#include "EXPComponent.h"
#include "HealthComponent.h"
#include "Blueprint/UserWidget.h"
#include "Widgets/HUDWidget.h"
void AVampirePlayerController::OnPossess(APawn* aPawn)
{
Super::OnPossess(aPawn);
if (PlayerHUD)
{
currentPlayerHUD = CreateWidget<UHUDWidget, AVampirePlayerController*>(this, PlayerHUD.Get());
if (UEXPComponent* expComponent = aPawn->GetComponentByClass<UEXPComponent>())
{
expComponent->OnEXPGained.AddUniqueDynamic(this, &AVampirePlayerController::UpdatePlayerEXPHUD);
UpdatePlayerEXPHUD(expComponent->GetCurrentEXP(), expComponent->GetCurrentLevelPercent());
}
if (currentPlayerHUD)
{
currentPlayerHUD->AddToViewport();
}
}
}
void AVampirePlayerController::UpdatePlayerEXPHUD(int exp, float currentLevelPercent)
{
if (currentPlayerHUD)
{
currentPlayerHUD->UpdateEXPBar(currentLevelPercent);
}
}

View File

@ -6,12 +6,27 @@
#include "GameFramework/PlayerController.h"
#include "VampirePlayerController.generated.h"
class UHUDWidget;
/**
*
*/
UCLASS()
UCLASS(Abstract)
class VAMPIRES_API AVampirePlayerController : public APlayerController
{
GENERATED_BODY()
public:
UPROPERTY(EditAnywhere, BlueprintReadWrite)
TSubclassOf<UHUDWidget> PlayerHUD = nullptr;
private:
TObjectPtr<UHUDWidget> currentPlayerHUD = nullptr;
protected:
virtual void OnPossess(APawn* aPawn) override;
UFUNCTION()
void UpdatePlayerEXPHUD(int exp, float currentLevelPercent);
};

View File

@ -23,7 +23,7 @@ void AWeapon::BeginPlay()
if (expcomponent)
{
expcomponent->OnEXPLevelUp.BindUObject(this, &AWeapon::UpgradeWeapon);
expcomponent->OnEXPLevelUp.AddUniqueDynamic(this, &AWeapon::UpgradeWeapon);
}
}

View File

@ -3,3 +3,21 @@
#include "HUDWidget.h"
#include "Components/ProgressBar.h"
void UHUDWidget::Init()
{
}
void UHUDWidget::UpdateEXPBar(float currentLevelPercent)
{
EXPbar->SetPercent(currentLevelPercent);
}
void UHUDWidget::UpdateLevelBlock()
{
}
void UHUDWidget::UpdateTimerBlock()
{
}

View File

@ -15,7 +15,7 @@ UCLASS()
class VAMPIRES_API UHUDWidget : public UUserWidget
{
GENERATED_BODY()
public:
UPROPERTY(BlueprintReadWrite, meta = (BindWidget))
@ -26,5 +26,16 @@ public:
UPROPERTY(BlueprintReadWrite, meta = (BindWidget))
UTextBlock* TimerBLock;
void Init();
UFUNCTION()
void UpdateEXPBar(float currentLevelPercent);
UFUNCTION()
void UpdateLevelBlock();
UFUNCTION()
void UpdateTimerBlock();
};