Finalise initial implementation of game over ui
This commit is contained in:
parent
109da799f2
commit
8ab53108a4
BIN
Content/Player/BP_PlayerController.uasset
(Stored with Git LFS)
BIN
Content/Player/BP_PlayerController.uasset
(Stored with Git LFS)
Binary file not shown.
BIN
Content/Widgets/GameOver/BP_GameOverWidget.uasset
(Stored with Git LFS)
BIN
Content/Widgets/GameOver/BP_GameOverWidget.uasset
(Stored with Git LFS)
Binary file not shown.
@ -147,6 +147,26 @@ void AVampirePlayerController::OnDeath(FDamageInfo DamageInfo)
|
|||||||
CurrentGameOverUI->AddToViewport();
|
CurrentGameOverUI->AddToViewport();
|
||||||
UWidgetBlueprintLibrary::SetInputMode_UIOnlyEx(this, CurrentPauseUI, EMouseLockMode::LockInFullscreen);
|
UWidgetBlueprintLibrary::SetInputMode_UIOnlyEx(this, CurrentPauseUI, EMouseLockMode::LockInFullscreen);
|
||||||
bShowMouseCursor = true;
|
bShowMouseCursor = true;
|
||||||
|
|
||||||
|
int Level = -1;
|
||||||
|
if (UEXPComponent* EXPComponent = GetPawn()->GetComponentByClass<UEXPComponent>())
|
||||||
|
{
|
||||||
|
Level = EXPComponent->GetCurrentLevel();
|
||||||
|
}
|
||||||
|
|
||||||
|
int Kills = -1;
|
||||||
|
if (AVampireGameMode* GameMode = Cast<AVampireGameMode>(UGameplayStatics::GetGameMode(GetWorld())))
|
||||||
|
{
|
||||||
|
Kills = GameMode->GetEnemyDeathCount();
|
||||||
|
}
|
||||||
|
|
||||||
|
int Gold = -1;
|
||||||
|
if (UGoldComponent* GoldComponent = GetPawn()->GetComponentByClass<UGoldComponent>())
|
||||||
|
{
|
||||||
|
Gold = GoldComponent->GetCurrentGold();
|
||||||
|
}
|
||||||
|
|
||||||
|
CurrentGameOverUI->SetGameInfo(Level, ElapsedTime, Kills, Gold);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -223,6 +243,8 @@ void AVampirePlayerController::UpdateGoldCountHUD(int GoldCount)
|
|||||||
|
|
||||||
void AVampirePlayerController::UpdateTimerHUDElement_Implementation(float DeltaTime)
|
void AVampirePlayerController::UpdateTimerHUDElement_Implementation(float DeltaTime)
|
||||||
{
|
{
|
||||||
|
ElapsedTime = DeltaTime;
|
||||||
|
|
||||||
if (CurrentPlayerHUD)
|
if (CurrentPlayerHUD)
|
||||||
{
|
{
|
||||||
CurrentPlayerHUD->UpdateTimerBlock(DeltaTime);
|
CurrentPlayerHUD->UpdateTimerBlock(DeltaTime);
|
||||||
|
@ -59,6 +59,8 @@ private:
|
|||||||
|
|
||||||
FTimerHandle PawnLifeTimeHandle;
|
FTimerHandle PawnLifeTimeHandle;
|
||||||
|
|
||||||
|
float ElapsedTime = 0.0f;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
UFUNCTION()
|
UFUNCTION()
|
||||||
void OnDeath(FDamageInfo DamageInfo);
|
void OnDeath(FDamageInfo DamageInfo);
|
||||||
@ -76,7 +78,6 @@ 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);
|
||||||
|
|
||||||
|
@ -2,3 +2,65 @@
|
|||||||
|
|
||||||
|
|
||||||
#include "GameOverWidget.h"
|
#include "GameOverWidget.h"
|
||||||
|
|
||||||
|
#include "Blueprint/WidgetBlueprintLibrary.h"
|
||||||
|
#include "Components/Button.h"
|
||||||
|
#include "Components/TextBlock.h"
|
||||||
|
#include "Kismet/GameplayStatics.h"
|
||||||
|
#include "vampires/VampireGameInstance.h"
|
||||||
|
|
||||||
|
void UGameOverWidget::NativeConstruct()
|
||||||
|
{
|
||||||
|
Super::NativeConstruct();
|
||||||
|
|
||||||
|
if (ReturnButton)
|
||||||
|
{
|
||||||
|
ReturnButton->OnClicked.AddUniqueDynamic(this, &UGameOverWidget::ReturnButtonClicked);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void UGameOverWidget::SetGameInfo(int Level, float Timer, int Kill, int Gold)
|
||||||
|
{
|
||||||
|
// Set Level
|
||||||
|
LevelBlock->SetText(FText::FromString(FString::FromInt(Level)));
|
||||||
|
|
||||||
|
// Set timer
|
||||||
|
int TimeSinceStart = FMath::FloorToInt(Timer);
|
||||||
|
|
||||||
|
FString Mins = FString::FromInt(TimeSinceStart / 60);
|
||||||
|
if (TimeSinceStart / 60 < 10)
|
||||||
|
{
|
||||||
|
Mins = "0" + Mins;
|
||||||
|
}
|
||||||
|
|
||||||
|
FString Secs = FString::FromInt(TimeSinceStart % 60);
|
||||||
|
if (TimeSinceStart % 60 < 10)
|
||||||
|
{
|
||||||
|
Secs = "0" + Secs;
|
||||||
|
}
|
||||||
|
|
||||||
|
TimerBlock->SetText(FText::FromString(Mins + ":" + Secs));
|
||||||
|
|
||||||
|
// Set Kill count
|
||||||
|
KillBlock->SetText(FText::FromString(FString::FromInt(Kill)));
|
||||||
|
|
||||||
|
// Set Gold count
|
||||||
|
GoldBlock->SetText(FText::FromString(FString::FromInt(Gold)));
|
||||||
|
}
|
||||||
|
|
||||||
|
void UGameOverWidget::ReturnButtonClicked()
|
||||||
|
{
|
||||||
|
if (UVampireGameInstance* GameInstance = Cast<UVampireGameInstance>(GetGameInstance()))
|
||||||
|
{
|
||||||
|
if (!GameInstance->MainMenuWorld.IsNull())
|
||||||
|
{
|
||||||
|
UGameplayStatics::OpenLevelBySoftObjectPtr(GetWorld(), GameInstance->MainMenuWorld);
|
||||||
|
|
||||||
|
if (APlayerController* PlayerController = UGameplayStatics::GetPlayerController(GetWorld(), 0))
|
||||||
|
{
|
||||||
|
PlayerController->bShowMouseCursor = true;
|
||||||
|
}
|
||||||
|
SetIsFocusable(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -6,6 +6,8 @@
|
|||||||
#include "Blueprint/UserWidget.h"
|
#include "Blueprint/UserWidget.h"
|
||||||
#include "GameOverWidget.generated.h"
|
#include "GameOverWidget.generated.h"
|
||||||
|
|
||||||
|
class UTextBlock;
|
||||||
|
class UButton;
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@ -13,4 +15,29 @@ UCLASS()
|
|||||||
class VAMPIRES_API UGameOverWidget : public UUserWidget
|
class VAMPIRES_API UGameOverWidget : public UUserWidget
|
||||||
{
|
{
|
||||||
GENERATED_BODY()
|
GENERATED_BODY()
|
||||||
|
|
||||||
|
protected:
|
||||||
|
UPROPERTY(BlueprintReadWrite, meta=(BindWidget))
|
||||||
|
TObjectPtr<UButton> ReturnButton;
|
||||||
|
|
||||||
|
UPROPERTY(BlueprintReadWrite, meta = (BindWidget))
|
||||||
|
TObjectPtr <UTextBlock> LevelBlock;
|
||||||
|
|
||||||
|
UPROPERTY(BlueprintReadWrite, meta = (BindWidget))
|
||||||
|
TObjectPtr <UTextBlock> TimerBlock;
|
||||||
|
|
||||||
|
UPROPERTY(BlueprintReadWrite, meta = (BindWidget))
|
||||||
|
TObjectPtr <UTextBlock> KillBlock;
|
||||||
|
|
||||||
|
UPROPERTY(BlueprintReadWrite, meta = (BindWidget))
|
||||||
|
TObjectPtr <UTextBlock> GoldBlock;
|
||||||
|
|
||||||
|
virtual void NativeConstruct() override;
|
||||||
|
|
||||||
|
public:
|
||||||
|
void SetGameInfo(int Level, float Timer, int Kill, int Gold);
|
||||||
|
|
||||||
|
private:
|
||||||
|
UFUNCTION()
|
||||||
|
void ReturnButtonClicked();
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user