vampires/Source/vampires/VampirePlayerController.cpp

76 lines
2.0 KiB
C++
Raw Normal View History

2024-06-12 00:34:11 +01:00
// Fill out your copyright notice in the Description page of Project Settings.
#include "VampirePlayerController.h"
#include "EXPComponent.h"
2024-11-16 02:22:41 +00:00
#include "HealthComponent.h"
2024-11-17 20:02:59 +00:00
#include "VampireGameMode.h"
#include "Blueprint/UserWidget.h"
2024-11-17 20:02:59 +00:00
#include "Kismet/GameplayStatics.h"
#include "Widgets/HUDWidget.h"
void AVampirePlayerController::OnPossess(APawn* aPawn)
{
Super::OnPossess(aPawn);
if (PlayerHUD)
{
currentPlayerHUD = CreateWidget<UHUDWidget, AVampirePlayerController*>(this, PlayerHUD.Get());
2024-11-16 02:22:41 +00:00
if (UEXPComponent* expComponent = aPawn->GetComponentByClass<UEXPComponent>())
{
expComponent->OnEXPGained.AddUniqueDynamic(this, &AVampirePlayerController::UpdatePlayerEXPHUD);
2024-11-17 20:02:59 +00:00
expComponent->OnEXPLevelUp.AddUniqueDynamic(this, &AVampirePlayerController::UpdatePlayerLevelHUD);
2024-11-16 02:22:41 +00:00
UpdatePlayerEXPHUD(expComponent->GetCurrentEXP(), expComponent->GetCurrentLevelPercent());
2024-11-17 20:02:59 +00:00
UpdatePlayerLevelHUD(expComponent->GetCurrentLevel());
}
AVampireGameMode* gamemode = Cast<AVampireGameMode>(UGameplayStatics::GetGameMode(GetWorld()));
if (gamemode)
{
gamemode->OnEnemyDeathCountIncrementDelegate.AddDynamic(this, &AVampirePlayerController::UpdateKillCountHUD);
UpdateKillCountHUD(gamemode->GetEnemyDeathCount());
2024-11-16 02:22:41 +00:00
}
2024-11-17 21:43:49 +00:00
GetWorld()->GetTimerManager().SetTimer(pawnLifeTimeHandle, this, &AVampirePlayerController::UpdateTimerHUD, 1.0f, true,0.f);
2024-11-16 02:22:41 +00:00
if (currentPlayerHUD)
{
currentPlayerHUD->AddToViewport();
}
}
}
2024-11-16 02:22:41 +00:00
void AVampirePlayerController::UpdatePlayerEXPHUD(int exp, float currentLevelPercent)
{
if (currentPlayerHUD)
{
currentPlayerHUD->UpdateEXPBar(currentLevelPercent);
}
}
2024-11-17 20:02:59 +00:00
void AVampirePlayerController::UpdatePlayerLevelHUD(int level)
{
if (currentPlayerHUD)
{
currentPlayerHUD->UpdateLevelBlock(level);
}
}
2024-11-17 21:43:49 +00:00
void AVampirePlayerController::UpdateTimerHUD()
{
if (currentPlayerHUD)
{
currentPlayerHUD->UpdateTimerBlock(GetPawn());
}
}
2024-11-17 20:02:59 +00:00
void AVampirePlayerController::UpdateKillCountHUD(int killCount)
{
if (currentPlayerHUD)
{
currentPlayerHUD->UpdateKillBlock(killCount);
}
}