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

View File

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

View File

@ -54,6 +54,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

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

View File

@ -3,36 +3,3 @@
#include "VampirePlayerController.h" #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 "GameFramework/PlayerController.h"
#include "VampirePlayerController.generated.h" #include "VampirePlayerController.generated.h"
class UHUDWidget;
/** /**
* *
*/ */
UCLASS(Abstract) UCLASS()
class VAMPIRES_API AVampirePlayerController : public APlayerController class VAMPIRES_API AVampirePlayerController : public APlayerController
{ {
GENERATED_BODY() 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) if (expcomponent)
{ {
expcomponent->OnEXPLevelUp.AddUniqueDynamic(this, &AWeapon::UpgradeWeapon); expcomponent->OnEXPLevelUp.BindUObject(this, &AWeapon::UpgradeWeapon);
} }
} }

View File

@ -3,21 +3,3 @@
#include "HUDWidget.h" #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 class VAMPIRES_API UHUDWidget : public UUserWidget
{ {
GENERATED_BODY() GENERATED_BODY()
public: public:
UPROPERTY(BlueprintReadWrite, meta = (BindWidget)) UPROPERTY(BlueprintReadWrite, meta = (BindWidget))
@ -26,16 +26,5 @@ public:
UPROPERTY(BlueprintReadWrite, meta = (BindWidget)) UPROPERTY(BlueprintReadWrite, meta = (BindWidget))
UTextBlock* TimerBLock; UTextBlock* TimerBLock;
void Init();
UFUNCTION()
void UpdateEXPBar(float currentLevelPercent);
UFUNCTION()
void UpdateLevelBlock();
UFUNCTION()
void UpdateTimerBlock();
}; };