Add template game over ui
This commit is contained in:
parent
fa03e49f1a
commit
109da799f2
BIN
Content/Levels/MainMenu/BP_MainMenuGameMode.uasset
(Stored with Git LFS)
BIN
Content/Levels/MainMenu/BP_MainMenuGameMode.uasset
(Stored with Git LFS)
Binary file not shown.
BIN
Content/Levels/MainMenu/BP_MainMenuPawn.uasset
(Stored with Git LFS)
Normal file
BIN
Content/Levels/MainMenu/BP_MainMenuPawn.uasset
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Content/Widgets/GameOver/BP_GameOverWidget.uasset
(Stored with Git LFS)
Normal file
BIN
Content/Widgets/GameOver/BP_GameOverWidget.uasset
(Stored with Git LFS)
Normal file
Binary file not shown.
@ -19,8 +19,15 @@ void AVampireGameMode::BeginPlay()
|
|||||||
Super::BeginPlay();
|
Super::BeginPlay();
|
||||||
|
|
||||||
PlayerCharacter = Cast<APlayerCharacter>(UGameplayStatics::GetPlayerCharacter(GetWorld(), 0));
|
PlayerCharacter = Cast<APlayerCharacter>(UGameplayStatics::GetPlayerCharacter(GetWorld(), 0));
|
||||||
|
|
||||||
PlayerController = Cast<AVampirePlayerController>(UGameplayStatics::GetPlayerController(PlayerCharacter, 0));
|
PlayerController = Cast<AVampirePlayerController>(UGameplayStatics::GetPlayerController(PlayerCharacter, 0));
|
||||||
|
|
||||||
|
if (UHealthComponent* HealthComponent = PlayerCharacter->GetHealthComponent())
|
||||||
|
{
|
||||||
|
HealthComponent->OnDeath.AddDynamic(this, &AVampireGameMode::OnPlayerDeath);
|
||||||
|
HealthComponent->OnDeath.AddDynamic(PlayerController, &AVampirePlayerController::OnDeath);
|
||||||
|
}
|
||||||
|
|
||||||
GetWorldTimerManager().SetTimer(SpawnEnemyTimerDelegate, this, &AVampireGameMode::SpawnEnemy, 1.0f, true);
|
GetWorldTimerManager().SetTimer(SpawnEnemyTimerDelegate, this, &AVampireGameMode::SpawnEnemy, 1.0f, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -29,10 +36,10 @@ int AVampireGameMode::GetEnemyDeathCount()
|
|||||||
return EnemyDeathCount;
|
return EnemyDeathCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AVampireGameMode::HandleOnEnemyDeath(FDamageInfo damageInfo)
|
void AVampireGameMode::HandleOnEnemyDeath(FDamageInfo DamageInfo)
|
||||||
{
|
{
|
||||||
IncrementEnemyDeathCount();
|
IncrementEnemyDeathCount();
|
||||||
EnemyObjectPoolManager->ReturnObject(damageInfo.DamagedActor);
|
EnemyObjectPoolManager->ReturnObject(DamageInfo.DamagedActor);
|
||||||
OnEnemyDeathCountIncrementDelegate.Broadcast(EnemyDeathCount);
|
OnEnemyDeathCountIncrementDelegate.Broadcast(EnemyDeathCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -149,6 +156,11 @@ void AVampireGameMode::AddRandomEnemyTypeToPool()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AVampireGameMode::OnPlayerDeath(FDamageInfo DamageInfo)
|
||||||
|
{
|
||||||
|
GetWorldTimerManager().ClearTimer(SpawnEnemyTimerDelegate);
|
||||||
|
}
|
||||||
|
|
||||||
void AVampireGameMode::EndGame()
|
void AVampireGameMode::EndGame()
|
||||||
{
|
{
|
||||||
UKismetSystemLibrary::QuitGame(GetWorld(), UGameplayStatics::GetPlayerController(GetWorld(), 0), EQuitPreference::Quit, true);
|
UKismetSystemLibrary::QuitGame(GetWorld(), UGameplayStatics::GetPlayerController(GetWorld(), 0), EQuitPreference::Quit, true);
|
||||||
|
@ -71,7 +71,7 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
UFUNCTION()
|
UFUNCTION()
|
||||||
void HandleOnEnemyDeath(FDamageInfo damageInfo);
|
void HandleOnEnemyDeath(FDamageInfo DamageInfo);
|
||||||
|
|
||||||
UFUNCTION()
|
UFUNCTION()
|
||||||
void IncrementEnemyDeathCount();
|
void IncrementEnemyDeathCount();
|
||||||
@ -85,6 +85,9 @@ protected:
|
|||||||
UFUNCTION(BlueprintCallable)
|
UFUNCTION(BlueprintCallable)
|
||||||
void AddRandomEnemyTypeToPool();
|
void AddRandomEnemyTypeToPool();
|
||||||
|
|
||||||
|
UFUNCTION()
|
||||||
|
void OnPlayerDeath(FDamageInfo DamageInfo);
|
||||||
|
|
||||||
UFUNCTION(BlueprintCallable)
|
UFUNCTION(BlueprintCallable)
|
||||||
void EndGame();
|
void EndGame();
|
||||||
|
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
#include "Blueprint/UserWidget.h"
|
#include "Blueprint/UserWidget.h"
|
||||||
#include "Blueprint/WidgetBlueprintLibrary.h"
|
#include "Blueprint/WidgetBlueprintLibrary.h"
|
||||||
#include "Kismet/GameplayStatics.h"
|
#include "Kismet/GameplayStatics.h"
|
||||||
|
#include "Widgets/GameOverWidget.h"
|
||||||
#include "Widgets/HUDWidget.h"
|
#include "Widgets/HUDWidget.h"
|
||||||
#include "Widgets/LevelUpWidget.h"
|
#include "Widgets/LevelUpWidget.h"
|
||||||
#include "Widgets/PauseWidget.h"
|
#include "Widgets/PauseWidget.h"
|
||||||
@ -132,6 +133,24 @@ void AVampirePlayerController::OnPause(const FInputActionValue& PauseInput)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AVampirePlayerController::OnDeath(FDamageInfo DamageInfo)
|
||||||
|
{
|
||||||
|
if (GameOverUI)
|
||||||
|
{
|
||||||
|
if (CurrentPlayerHUD) { CurrentPlayerHUD->RemoveFromParent(); }
|
||||||
|
if (CurrentLevelUpUI) { CurrentLevelUpUI->RemoveFromParent(); }
|
||||||
|
if (CurrentPauseUI) { CurrentPauseUI->RemoveFromParent(); }
|
||||||
|
|
||||||
|
CurrentGameOverUI = CreateWidget<UGameOverWidget, AVampirePlayerController*>(this, GameOverUI.Get());
|
||||||
|
if (CurrentGameOverUI)
|
||||||
|
{
|
||||||
|
CurrentGameOverUI->AddToViewport();
|
||||||
|
UWidgetBlueprintLibrary::SetInputMode_UIOnlyEx(this, CurrentPauseUI, EMouseLockMode::LockInFullscreen);
|
||||||
|
bShowMouseCursor = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void AVampirePlayerController::UpdatePlayerEXPHUD(int Exp, float CurrentLevelPercent)
|
void AVampirePlayerController::UpdatePlayerEXPHUD(int Exp, float CurrentLevelPercent)
|
||||||
{
|
{
|
||||||
if (CurrentPlayerHUD)
|
if (CurrentPlayerHUD)
|
||||||
|
@ -7,11 +7,14 @@
|
|||||||
#include "Interfaces/Playerable.h"
|
#include "Interfaces/Playerable.h"
|
||||||
#include "VampirePlayerController.generated.h"
|
#include "VampirePlayerController.generated.h"
|
||||||
|
|
||||||
|
struct FDamageInfo;
|
||||||
|
class UGameOverWidget;
|
||||||
class ULevelUpWidget;
|
class ULevelUpWidget;
|
||||||
class UPauseWidget;
|
class UPauseWidget;
|
||||||
struct FInputActionValue;
|
struct FInputActionValue;
|
||||||
class UInputAction;
|
class UInputAction;
|
||||||
class UHUDWidget;
|
class UHUDWidget;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@ -22,15 +25,18 @@ class VAMPIRES_API AVampirePlayerController : public APlayerController, public I
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
// UI
|
// UI
|
||||||
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
|
||||||
TSubclassOf<UHUDWidget> PlayerHUD = nullptr;
|
TSubclassOf<UHUDWidget> PlayerHUD = nullptr;
|
||||||
|
|
||||||
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
|
||||||
TSubclassOf<UPauseWidget> PauseUI = nullptr;
|
TSubclassOf<UPauseWidget> PauseUI = nullptr;
|
||||||
|
|
||||||
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
|
||||||
TSubclassOf<ULevelUpWidget> LevelUpUI = nullptr;
|
TSubclassOf<ULevelUpWidget> LevelUpUI = nullptr;
|
||||||
|
|
||||||
|
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
|
||||||
|
TSubclassOf<UGameOverWidget> GameOverUI = nullptr;
|
||||||
|
|
||||||
// Inputs
|
// Inputs
|
||||||
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
|
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
|
||||||
TObjectPtr<UInputAction> MovementAction;
|
TObjectPtr<UInputAction> MovementAction;
|
||||||
@ -39,7 +45,6 @@ public:
|
|||||||
TObjectPtr<UInputAction> PauseAction;
|
TObjectPtr<UInputAction> PauseAction;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
UPROPERTY()
|
UPROPERTY()
|
||||||
TObjectPtr<UHUDWidget> CurrentPlayerHUD = nullptr;
|
TObjectPtr<UHUDWidget> CurrentPlayerHUD = nullptr;
|
||||||
|
|
||||||
@ -48,9 +53,16 @@ private:
|
|||||||
|
|
||||||
UPROPERTY()
|
UPROPERTY()
|
||||||
TObjectPtr<ULevelUpWidget> CurrentLevelUpUI = nullptr;
|
TObjectPtr<ULevelUpWidget> CurrentLevelUpUI = nullptr;
|
||||||
|
|
||||||
|
UPROPERTY()
|
||||||
|
TObjectPtr<UGameOverWidget> CurrentGameOverUI = nullptr;
|
||||||
|
|
||||||
FTimerHandle PawnLifeTimeHandle;
|
FTimerHandle PawnLifeTimeHandle;
|
||||||
|
|
||||||
|
public:
|
||||||
|
UFUNCTION()
|
||||||
|
void OnDeath(FDamageInfo DamageInfo);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void OnPossess(APawn* aPawn) override;
|
virtual void OnPossess(APawn* aPawn) override;
|
||||||
|
|
||||||
@ -64,6 +76,7 @@ protected:
|
|||||||
UFUNCTION()
|
UFUNCTION()
|
||||||
void OnPause(const FInputActionValue& PauseInput);
|
void OnPause(const FInputActionValue& PauseInput);
|
||||||
|
|
||||||
|
|
||||||
UFUNCTION()
|
UFUNCTION()
|
||||||
void UpdatePlayerEXPHUD(int Exp, float CurrentLevelPercent);
|
void UpdatePlayerEXPHUD(int Exp, float CurrentLevelPercent);
|
||||||
|
|
||||||
|
4
Source/vampires/Widgets/GameOverWidget.cpp
Normal file
4
Source/vampires/Widgets/GameOverWidget.cpp
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
// Louis Hobbs | 2024-2025
|
||||||
|
|
||||||
|
|
||||||
|
#include "GameOverWidget.h"
|
16
Source/vampires/Widgets/GameOverWidget.h
Normal file
16
Source/vampires/Widgets/GameOverWidget.h
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
// Louis Hobbs | 2024-2025
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "CoreMinimal.h"
|
||||||
|
#include "Blueprint/UserWidget.h"
|
||||||
|
#include "GameOverWidget.generated.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
UCLASS()
|
||||||
|
class VAMPIRES_API UGameOverWidget : public UUserWidget
|
||||||
|
{
|
||||||
|
GENERATED_BODY()
|
||||||
|
};
|
Loading…
x
Reference in New Issue
Block a user