Implement basic Level Up UI
This commit is contained in:
parent
6340639844
commit
773338e912
BIN
Content/Player/BP_PlayerCharacter.uasset
(Stored with Git LFS)
BIN
Content/Player/BP_PlayerCharacter.uasset
(Stored with Git LFS)
Binary file not shown.
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/LevelUp/BP_LevelUpWidget.uasset
(Stored with Git LFS)
Normal file
BIN
Content/Widgets/LevelUp/BP_LevelUpWidget.uasset
(Stored with Git LFS)
Normal file
Binary file not shown.
@ -12,6 +12,7 @@
|
||||
#include "Blueprint/WidgetBlueprintLibrary.h"
|
||||
#include "Kismet/GameplayStatics.h"
|
||||
#include "Widgets/HUDWidget.h"
|
||||
#include "Widgets/LevelUpWidget.h"
|
||||
#include "Widgets/PauseWidget.h"
|
||||
|
||||
void AVampirePlayerController::OnPossess(APawn* aPawn)
|
||||
@ -34,6 +35,7 @@ void AVampirePlayerController::OnPossess(APawn* aPawn)
|
||||
{
|
||||
expComponent->OnEXPGained.AddUniqueDynamic(this, &AVampirePlayerController::UpdatePlayerEXPHUD);
|
||||
expComponent->OnEXPLevelUp.AddUniqueDynamic(this, &AVampirePlayerController::UpdatePlayerLevelHUD);
|
||||
expComponent->OnEXPLevelUp.AddUniqueDynamic(this, &AVampirePlayerController::ShowLevelUpScreen);
|
||||
UpdatePlayerEXPHUD(expComponent->GetCurrentEXP(), expComponent->GetCurrentLevelPercent());
|
||||
UpdatePlayerLevelHUD(expComponent->GetCurrentLevel());
|
||||
}
|
||||
@ -94,9 +96,9 @@ void AVampirePlayerController::OnPause(const FInputActionValue& PauseInput)
|
||||
}
|
||||
}
|
||||
|
||||
if (SetPause(true))
|
||||
{
|
||||
if (PauseUI)
|
||||
{
|
||||
if (SetPause(true))
|
||||
{
|
||||
currentPauseUI = CreateWidget<UPauseWidget, AVampirePlayerController*>(this, PauseUI.Get());
|
||||
if (currentPauseUI)
|
||||
@ -117,6 +119,35 @@ void AVampirePlayerController::UpdatePlayerEXPHUD(int exp, float currentLevelPer
|
||||
}
|
||||
}
|
||||
|
||||
void AVampirePlayerController::ShowLevelUpScreen(int level)
|
||||
{
|
||||
APawn* pawn = GetPawn();
|
||||
if (!pawn)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
UEXPComponent* expComponent = pawn->GetComponentByClass<UEXPComponent>();
|
||||
if (!expComponent || expComponent->GetCurrentLevel() == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (LevelUpUI)
|
||||
{
|
||||
if (SetPause(true))
|
||||
{
|
||||
currentLevelUpUI = CreateWidget<ULevelUpWidget, AVampirePlayerController*>(this, LevelUpUI.Get());
|
||||
if (currentLevelUpUI)
|
||||
{
|
||||
currentLevelUpUI->AddToViewport();
|
||||
UWidgetBlueprintLibrary::SetInputMode_UIOnlyEx(this, currentLevelUpUI, EMouseLockMode::LockInFullscreen);
|
||||
bShowMouseCursor = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AVampirePlayerController::UpdatePlayerLevelHUD(int level)
|
||||
{
|
||||
if (currentPlayerHUD)
|
||||
|
@ -6,6 +6,7 @@
|
||||
#include "GameFramework/PlayerController.h"
|
||||
#include "VampirePlayerController.generated.h"
|
||||
|
||||
class ULevelUpWidget;
|
||||
class UPauseWidget;
|
||||
struct FInputActionValue;
|
||||
class UInputAction;
|
||||
@ -26,6 +27,9 @@ public:
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||
TSubclassOf<UPauseWidget> PauseUI = nullptr;
|
||||
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||
TSubclassOf<ULevelUpWidget> LevelUpUI = nullptr;
|
||||
|
||||
// Inputs
|
||||
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
|
||||
UInputAction* MovementAction;
|
||||
@ -39,6 +43,8 @@ private:
|
||||
|
||||
TObjectPtr<UPauseWidget> currentPauseUI = nullptr;
|
||||
|
||||
TObjectPtr<ULevelUpWidget> currentLevelUpUI = nullptr;
|
||||
|
||||
FTimerHandle pawnLifeTimeHandle;
|
||||
|
||||
protected:
|
||||
@ -57,6 +63,9 @@ protected:
|
||||
UFUNCTION()
|
||||
void UpdatePlayerEXPHUD(int exp, float currentLevelPercent);
|
||||
|
||||
UFUNCTION()
|
||||
void ShowLevelUpScreen(int level);
|
||||
|
||||
UFUNCTION()
|
||||
void UpdatePlayerLevelHUD(int level);
|
||||
|
||||
|
34
Source/vampires/Widgets/LevelUpWidget.cpp
Normal file
34
Source/vampires/Widgets/LevelUpWidget.cpp
Normal file
@ -0,0 +1,34 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
|
||||
#include "LevelUpWidget.h"
|
||||
|
||||
#include "Blueprint/WidgetBlueprintLibrary.h"
|
||||
#include "Components/Button.h"
|
||||
#include "Kismet/GameplayStatics.h"
|
||||
|
||||
void ULevelUpWidget::NativeConstruct()
|
||||
{
|
||||
Super::NativeConstruct();
|
||||
|
||||
if (ResumeButton)
|
||||
{
|
||||
ResumeButton->OnClicked.AddUniqueDynamic(this, &ULevelUpWidget::ResumeButtonClicked);
|
||||
}
|
||||
|
||||
SetIsFocusable(true);
|
||||
}
|
||||
|
||||
void ULevelUpWidget::ResumeButtonClicked()
|
||||
{
|
||||
RemoveFromParent();
|
||||
|
||||
if (APlayerController* playerController = UGameplayStatics::GetPlayerController(GetWorld(), 0))
|
||||
{
|
||||
UWidgetBlueprintLibrary::SetInputMode_GameOnly(playerController);
|
||||
playerController->bShowMouseCursor = false;
|
||||
playerController->SetPause(false);
|
||||
}
|
||||
|
||||
SetIsFocusable(false);
|
||||
}
|
30
Source/vampires/Widgets/LevelUpWidget.h
Normal file
30
Source/vampires/Widgets/LevelUpWidget.h
Normal file
@ -0,0 +1,30 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "Blueprint/UserWidget.h"
|
||||
#include "LevelUpWidget.generated.h"
|
||||
|
||||
class UButton;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
UCLASS()
|
||||
class VAMPIRES_API ULevelUpWidget : public UUserWidget
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
|
||||
UPROPERTY(BlueprintReadWrite, meta=(BindWidget))
|
||||
UButton* ResumeButton;
|
||||
|
||||
virtual void NativeConstruct() override;
|
||||
|
||||
private:
|
||||
|
||||
|
||||
UFUNCTION()
|
||||
void ResumeButtonClicked();
|
||||
};
|
@ -25,8 +25,6 @@ void UPauseWidget::NativeConstruct()
|
||||
|
||||
void UPauseWidget::ResumeButtonClicked()
|
||||
{
|
||||
//TODO: Implementation
|
||||
|
||||
RemoveFromParent();
|
||||
|
||||
if (APlayerController* playerController = UGameplayStatics::GetPlayerController(GetWorld(), 0))
|
||||
|
Loading…
x
Reference in New Issue
Block a user