diff --git a/Content/Player/BP_PlayerController.uasset b/Content/Player/BP_PlayerController.uasset index f0dc7a8..4487558 100644 --- a/Content/Player/BP_PlayerController.uasset +++ b/Content/Player/BP_PlayerController.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:9ad042c2f0a2049fb8ed28507448931deccc4c27225c3910723d4dcb3e2effa4 -size 21374 +oid sha256:4ade3473858f8e50f55a3c1bfbd54281857c83f0f623a29339852f52bd9f96e3 +size 21963 diff --git a/Content/Widgets/GameOver/BP_GameOverWidget.uasset b/Content/Widgets/GameOver/BP_GameOverWidget.uasset index 0b1dd6f..23d5ced 100644 --- a/Content/Widgets/GameOver/BP_GameOverWidget.uasset +++ b/Content/Widgets/GameOver/BP_GameOverWidget.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:58801e8ecba29fb9bf0fcb365f471996ddfa2f8e62595e76df86bd97402b7d3f -size 25324 +oid sha256:42ea120a4334e9c989b651de74237112b443439db14fa9f584614840535e9af1 +size 48318 diff --git a/Source/vampires/VampirePlayerController.cpp b/Source/vampires/VampirePlayerController.cpp index f6a2e72..1189109 100644 --- a/Source/vampires/VampirePlayerController.cpp +++ b/Source/vampires/VampirePlayerController.cpp @@ -147,6 +147,26 @@ void AVampirePlayerController::OnDeath(FDamageInfo DamageInfo) CurrentGameOverUI->AddToViewport(); UWidgetBlueprintLibrary::SetInputMode_UIOnlyEx(this, CurrentPauseUI, EMouseLockMode::LockInFullscreen); bShowMouseCursor = true; + + int Level = -1; + if (UEXPComponent* EXPComponent = GetPawn()->GetComponentByClass()) + { + Level = EXPComponent->GetCurrentLevel(); + } + + int Kills = -1; + if (AVampireGameMode* GameMode = Cast(UGameplayStatics::GetGameMode(GetWorld()))) + { + Kills = GameMode->GetEnemyDeathCount(); + } + + int Gold = -1; + if (UGoldComponent* GoldComponent = GetPawn()->GetComponentByClass()) + { + Gold = GoldComponent->GetCurrentGold(); + } + + CurrentGameOverUI->SetGameInfo(Level, ElapsedTime, Kills, Gold); } } } @@ -223,6 +243,8 @@ void AVampirePlayerController::UpdateGoldCountHUD(int GoldCount) void AVampirePlayerController::UpdateTimerHUDElement_Implementation(float DeltaTime) { + ElapsedTime = DeltaTime; + if (CurrentPlayerHUD) { CurrentPlayerHUD->UpdateTimerBlock(DeltaTime); diff --git a/Source/vampires/VampirePlayerController.h b/Source/vampires/VampirePlayerController.h index d1022c0..d0ab775 100644 --- a/Source/vampires/VampirePlayerController.h +++ b/Source/vampires/VampirePlayerController.h @@ -59,6 +59,8 @@ private: FTimerHandle PawnLifeTimeHandle; + float ElapsedTime = 0.0f; + public: UFUNCTION() void OnDeath(FDamageInfo DamageInfo); @@ -76,7 +78,6 @@ protected: UFUNCTION() void OnPause(const FInputActionValue& PauseInput); - UFUNCTION() void UpdatePlayerEXPHUD(int Exp, float CurrentLevelPercent); diff --git a/Source/vampires/Widgets/GameOverWidget.cpp b/Source/vampires/Widgets/GameOverWidget.cpp index 8c35fe5..784025e 100644 --- a/Source/vampires/Widgets/GameOverWidget.cpp +++ b/Source/vampires/Widgets/GameOverWidget.cpp @@ -2,3 +2,65 @@ #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(GetGameInstance())) + { + if (!GameInstance->MainMenuWorld.IsNull()) + { + UGameplayStatics::OpenLevelBySoftObjectPtr(GetWorld(), GameInstance->MainMenuWorld); + + if (APlayerController* PlayerController = UGameplayStatics::GetPlayerController(GetWorld(), 0)) + { + PlayerController->bShowMouseCursor = true; + } + SetIsFocusable(true); + } + } +} diff --git a/Source/vampires/Widgets/GameOverWidget.h b/Source/vampires/Widgets/GameOverWidget.h index e612ebd..d3c5eee 100644 --- a/Source/vampires/Widgets/GameOverWidget.h +++ b/Source/vampires/Widgets/GameOverWidget.h @@ -6,6 +6,8 @@ #include "Blueprint/UserWidget.h" #include "GameOverWidget.generated.h" +class UTextBlock; +class UButton; /** * */ @@ -13,4 +15,29 @@ UCLASS() class VAMPIRES_API UGameOverWidget : public UUserWidget { GENERATED_BODY() + +protected: + UPROPERTY(BlueprintReadWrite, meta=(BindWidget)) + TObjectPtr ReturnButton; + + UPROPERTY(BlueprintReadWrite, meta = (BindWidget)) + TObjectPtr LevelBlock; + + UPROPERTY(BlueprintReadWrite, meta = (BindWidget)) + TObjectPtr TimerBlock; + + UPROPERTY(BlueprintReadWrite, meta = (BindWidget)) + TObjectPtr KillBlock; + + UPROPERTY(BlueprintReadWrite, meta = (BindWidget)) + TObjectPtr GoldBlock; + + virtual void NativeConstruct() override; + +public: + void SetGameInfo(int Level, float Timer, int Kill, int Gold); + +private: + UFUNCTION() + void ReturnButtonClicked(); };