Add Basic Pause functionality

This commit is contained in:
baz 2023-10-03 22:52:28 +01:00
parent 149de8788f
commit da1fcc15bd
4 changed files with 68 additions and 12 deletions

BIN
Content/UI/Pause/PauseMenu.uasset (Stored with Git LFS) Normal file

Binary file not shown.

View File

@ -3,21 +3,58 @@
#include "PauseUIWidget.h"
#include "Blueprint/WidgetBlueprintLibrary.h"
#include "Kismet/GameplayStatics.h"
void UPauseUIWidget::NativeConstruct()
{
Super::NativeConstruct();
if (ResumeButton)
{
ResumeButton->OnClicked.AddUniqueDynamic(this, &UPauseUIWidget::ResumeButtonOnClicked);
}
if (OptionsButton)
{
OptionsButton->OnClicked.AddUniqueDynamic(this, &UPauseUIWidget::OptionsButtonOnClicked);
}
if (SaveButton)
{
SaveButton->OnClicked.AddUniqueDynamic(this, &UPauseUIWidget::SaveButtonOnClicked);
}
if (QuitButton)
{
QuitButton->OnClicked.AddUniqueDynamic(this, &UPauseUIWidget::QuitButtonOnClicked);
CloseApplicationButton->OnClicked.AddUniqueDynamic(this, &UPauseUIWidget::CloseApplicationButtonOnClicked);
}
if (ExitGameButton)
{
ExitGameButton->OnClicked.AddUniqueDynamic(this, &UPauseUIWidget::ExitGameButtonOnClicked);
}
if (APlayerController* PlayerController = UGameplayStatics::GetPlayerController(GetWorld(), 0))
{
UWidgetBlueprintLibrary::SetInputMode_UIOnlyEx(PlayerController, this, EMouseLockMode::LockAlways);
PlayerController->bShowMouseCursor = true;
}
SetIsFocusable(true);
}
void UPauseUIWidget::ResumeButtonOnClicked()
{
// TODO: Implement Functionality
this->RemoveFromParent();
if (APlayerController* PlayerController = UGameplayStatics::GetPlayerController(GetWorld(), 0))
{
UWidgetBlueprintLibrary::SetInputMode_GameOnly(PlayerController);
PlayerController->bShowMouseCursor = false;
PlayerController->SetPause(false);
}
}
void UPauseUIWidget::OptionsButtonOnClicked()
@ -35,7 +72,12 @@ void UPauseUIWidget::QuitButtonOnClicked()
// TODO: Implement Functionality
}
void UPauseUIWidget::CloseApplicationButtonOnClicked()
void UPauseUIWidget::ExitGameButtonOnClicked()
{
// TODO: Implement Functionality
// TODO: We probably want to do an autosave here.
// TODO: Add platform specific Exit requests
// This is not a bit deal for the moment as we are only building for windows
// For some reason the generic version does not work the same as FWindowsPlatformMisc
FWindowsPlatformMisc::RequestExit(false);
}

View File

@ -33,19 +33,24 @@ public:
UButton* QuitButton;
UPROPERTY(BlueprintReadWrite, meta = (BindWidget))
UButton* CloseApplicationButton;
UButton* ExitGameButton;
public:
virtual void NativeConstruct() override;
private:
UFUNCTION()
void ResumeButtonOnClicked();
UFUNCTION()
void OptionsButtonOnClicked();
UFUNCTION()
void SaveButtonOnClicked();
UFUNCTION()
void QuitButtonOnClicked();
void CloseApplicationButtonOnClicked();
UFUNCTION()
void ExitGameButtonOnClicked();
};

View File

@ -493,10 +493,16 @@ void APlayerCharacter::EndAimDownSightsCallback(const FInputActionInstance& Inst
}
void APlayerCharacter::PauseCallback(const FInputActionInstance& Instance)
{
APlayerController* PlayerController = Cast<APlayerController>(GetController());
if (PlayerController->SetPause(true))
{
if (PauseMenuWidget)
{
// TODO: Add pause functionality
currentPauseMenuWidget->AddToViewport();
}
}
}