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 "PauseUIWidget.h"
#include "Blueprint/WidgetBlueprintLibrary.h"
#include "Kismet/GameplayStatics.h"
void UPauseUIWidget::NativeConstruct() void UPauseUIWidget::NativeConstruct()
{ {
Super::NativeConstruct(); Super::NativeConstruct();
ResumeButton->OnClicked.AddUniqueDynamic(this, &UPauseUIWidget::ResumeButtonOnClicked); if (ResumeButton)
OptionsButton->OnClicked.AddUniqueDynamic(this, &UPauseUIWidget::OptionsButtonOnClicked); {
SaveButton->OnClicked.AddUniqueDynamic(this, &UPauseUIWidget::SaveButtonOnClicked); ResumeButton->OnClicked.AddUniqueDynamic(this, &UPauseUIWidget::ResumeButtonOnClicked);
QuitButton->OnClicked.AddUniqueDynamic(this, &UPauseUIWidget::QuitButtonOnClicked); }
CloseApplicationButton->OnClicked.AddUniqueDynamic(this, &UPauseUIWidget::CloseApplicationButtonOnClicked);
if (OptionsButton)
{
OptionsButton->OnClicked.AddUniqueDynamic(this, &UPauseUIWidget::OptionsButtonOnClicked);
}
if (SaveButton)
{
SaveButton->OnClicked.AddUniqueDynamic(this, &UPauseUIWidget::SaveButtonOnClicked);
}
if (QuitButton)
{
QuitButton->OnClicked.AddUniqueDynamic(this, &UPauseUIWidget::QuitButtonOnClicked);
}
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() 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() void UPauseUIWidget::OptionsButtonOnClicked()
@ -35,7 +72,12 @@ void UPauseUIWidget::QuitButtonOnClicked()
// TODO: Implement Functionality // 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; UButton* QuitButton;
UPROPERTY(BlueprintReadWrite, meta = (BindWidget)) UPROPERTY(BlueprintReadWrite, meta = (BindWidget))
UButton* CloseApplicationButton; UButton* ExitGameButton;
public: public:
virtual void NativeConstruct() override; virtual void NativeConstruct() override;
private: private:
UFUNCTION()
void ResumeButtonOnClicked(); void ResumeButtonOnClicked();
UFUNCTION()
void OptionsButtonOnClicked(); void OptionsButtonOnClicked();
UFUNCTION()
void SaveButtonOnClicked(); void SaveButtonOnClicked();
UFUNCTION()
void QuitButtonOnClicked(); void QuitButtonOnClicked();
void CloseApplicationButtonOnClicked(); UFUNCTION()
void ExitGameButtonOnClicked();
}; };

View File

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