Compare commits

..

No commits in common. "4386f0e3838015621601b32a56b7fcb744aa0212" and "3b2301b270fb8fd0686b38e3559cf600a6323beb" have entirely different histories.

12 changed files with 32 additions and 97 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.Broadcast(CurrentEXP, GetCurrentLevelPercent());
OnEXPGained.ExecuteIfBound(value);
CurrentLevel = FMath::Floor(CurrentEXP / 100.0f);
if (CurrentLevel != oldLevel)
{
OnEXPLevelUp.Broadcast(CurrentLevel);
OnEXPLevelUp.ExecuteIfBound(CurrentLevel);
}
}
@ -36,13 +36,13 @@ void UEXPComponent::SetCurrentEXP(int value)
// TODO: I should be updating the level here
CurrentEXP = value;
OnEXPGained.Broadcast(CurrentEXP, GetCurrentLevelPercent());
OnEXPGained.ExecuteIfBound(value);
CurrentLevel = FMath::Floor(CurrentEXP / 100.0f);
if (CurrentLevel != oldLevel)
{
OnEXPLevelUp.Broadcast(CurrentLevel);
OnEXPLevelUp.ExecuteIfBound(CurrentLevel);
}
}
@ -60,8 +60,8 @@ void UEXPComponent::Reset()
{
CurrentEXP = 0;
CurrentLevel = 0;
OnEXPGained.Broadcast(CurrentEXP, GetCurrentLevelPercent());
OnEXPLevelUp.Broadcast(CurrentLevel);
OnEXPGained.ExecuteIfBound(CurrentEXP);
OnEXPLevelUp.ExecuteIfBound(CurrentLevel);
}
float UEXPComponent::GetCurrentLevelPercent()

View File

@ -6,8 +6,8 @@
#include "Components/ActorComponent.h"
#include "EXPComponent.generated.h"
DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FOnEXPGainedDelegate, int, exp, float, currentLevelPercent);
DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FOnEXPLevelUpDelegate, int, level);
DECLARE_DELEGATE_OneParam(FOnEXPGainedDelegate, int)
DECLARE_DELEGATE_OneParam(FOnEXPLevelUpDelegate, int)
UCLASS(ClassGroup=(Custom), meta=(BlueprintSpawnableComponent))
class VAMPIRES_API UEXPComponent : public UActorComponent
@ -15,10 +15,7 @@ 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,6 +54,16 @@ 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,12 +48,17 @@ 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,36 +3,3 @@
#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,27 +6,12 @@
#include "GameFramework/PlayerController.h"
#include "VampirePlayerController.generated.h"
class UHUDWidget;
/**
*
*/
UCLASS(Abstract)
UCLASS()
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.AddUniqueDynamic(this, &AWeapon::UpgradeWeapon);
expcomponent->OnEXPLevelUp.BindUObject(this, &AWeapon::UpgradeWeapon);
}
}

View File

@ -3,21 +3,3 @@
#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,16 +26,5 @@ public:
UPROPERTY(BlueprintReadWrite, meta = (BindWidget))
UTextBlock* TimerBLock;
void Init();
UFUNCTION()
void UpdateEXPBar(float currentLevelPercent);
UFUNCTION()
void UpdateLevelBlock();
UFUNCTION()
void UpdateTimerBlock();
};