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();
|
||||
|
||||
PlayerCharacter = Cast<APlayerCharacter>(UGameplayStatics::GetPlayerCharacter(GetWorld(), 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);
|
||||
}
|
||||
|
||||
@ -29,10 +36,10 @@ int AVampireGameMode::GetEnemyDeathCount()
|
||||
return EnemyDeathCount;
|
||||
}
|
||||
|
||||
void AVampireGameMode::HandleOnEnemyDeath(FDamageInfo damageInfo)
|
||||
void AVampireGameMode::HandleOnEnemyDeath(FDamageInfo DamageInfo)
|
||||
{
|
||||
IncrementEnemyDeathCount();
|
||||
EnemyObjectPoolManager->ReturnObject(damageInfo.DamagedActor);
|
||||
EnemyObjectPoolManager->ReturnObject(DamageInfo.DamagedActor);
|
||||
OnEnemyDeathCountIncrementDelegate.Broadcast(EnemyDeathCount);
|
||||
}
|
||||
|
||||
@ -149,6 +156,11 @@ void AVampireGameMode::AddRandomEnemyTypeToPool()
|
||||
}
|
||||
}
|
||||
|
||||
void AVampireGameMode::OnPlayerDeath(FDamageInfo DamageInfo)
|
||||
{
|
||||
GetWorldTimerManager().ClearTimer(SpawnEnemyTimerDelegate);
|
||||
}
|
||||
|
||||
void AVampireGameMode::EndGame()
|
||||
{
|
||||
UKismetSystemLibrary::QuitGame(GetWorld(), UGameplayStatics::GetPlayerController(GetWorld(), 0), EQuitPreference::Quit, true);
|
||||
|
@ -71,7 +71,7 @@ public:
|
||||
|
||||
protected:
|
||||
UFUNCTION()
|
||||
void HandleOnEnemyDeath(FDamageInfo damageInfo);
|
||||
void HandleOnEnemyDeath(FDamageInfo DamageInfo);
|
||||
|
||||
UFUNCTION()
|
||||
void IncrementEnemyDeathCount();
|
||||
@ -85,6 +85,9 @@ protected:
|
||||
UFUNCTION(BlueprintCallable)
|
||||
void AddRandomEnemyTypeToPool();
|
||||
|
||||
UFUNCTION()
|
||||
void OnPlayerDeath(FDamageInfo DamageInfo);
|
||||
|
||||
UFUNCTION(BlueprintCallable)
|
||||
void EndGame();
|
||||
|
||||
|
@ -15,6 +15,7 @@
|
||||
#include "Blueprint/UserWidget.h"
|
||||
#include "Blueprint/WidgetBlueprintLibrary.h"
|
||||
#include "Kismet/GameplayStatics.h"
|
||||
#include "Widgets/GameOverWidget.h"
|
||||
#include "Widgets/HUDWidget.h"
|
||||
#include "Widgets/LevelUpWidget.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)
|
||||
{
|
||||
if (CurrentPlayerHUD)
|
||||
|
@ -7,11 +7,14 @@
|
||||
#include "Interfaces/Playerable.h"
|
||||
#include "VampirePlayerController.generated.h"
|
||||
|
||||
struct FDamageInfo;
|
||||
class UGameOverWidget;
|
||||
class ULevelUpWidget;
|
||||
class UPauseWidget;
|
||||
struct FInputActionValue;
|
||||
class UInputAction;
|
||||
class UHUDWidget;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@ -22,15 +25,18 @@ class VAMPIRES_API AVampirePlayerController : public APlayerController, public I
|
||||
|
||||
public:
|
||||
// UI
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
|
||||
TSubclassOf<UHUDWidget> PlayerHUD = nullptr;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
|
||||
TSubclassOf<UPauseWidget> PauseUI = nullptr;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
|
||||
TSubclassOf<ULevelUpWidget> LevelUpUI = nullptr;
|
||||
|
||||
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
|
||||
TSubclassOf<UGameOverWidget> GameOverUI = nullptr;
|
||||
|
||||
// Inputs
|
||||
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
|
||||
TObjectPtr<UInputAction> MovementAction;
|
||||
@ -39,7 +45,6 @@ public:
|
||||
TObjectPtr<UInputAction> PauseAction;
|
||||
|
||||
private:
|
||||
|
||||
UPROPERTY()
|
||||
TObjectPtr<UHUDWidget> CurrentPlayerHUD = nullptr;
|
||||
|
||||
@ -49,8 +54,15 @@ private:
|
||||
UPROPERTY()
|
||||
TObjectPtr<ULevelUpWidget> CurrentLevelUpUI = nullptr;
|
||||
|
||||
UPROPERTY()
|
||||
TObjectPtr<UGameOverWidget> CurrentGameOverUI = nullptr;
|
||||
|
||||
FTimerHandle PawnLifeTimeHandle;
|
||||
|
||||
public:
|
||||
UFUNCTION()
|
||||
void OnDeath(FDamageInfo DamageInfo);
|
||||
|
||||
protected:
|
||||
virtual void OnPossess(APawn* aPawn) override;
|
||||
|
||||
@ -64,6 +76,7 @@ protected:
|
||||
UFUNCTION()
|
||||
void OnPause(const FInputActionValue& PauseInput);
|
||||
|
||||
|
||||
UFUNCTION()
|
||||
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