diff --git a/Content/UI/Pause/PauseMenu.uasset b/Content/UI/Pause/PauseMenu.uasset new file mode 100644 index 0000000..1efaa99 --- /dev/null +++ b/Content/UI/Pause/PauseMenu.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2211ded91f9e1ac7685ba4e13f44c8bc44934a9680c666462bd3901b8b6daa8e +size 37560 diff --git a/Source/Nakatomi/PauseUIWidget.cpp b/Source/Nakatomi/PauseUIWidget.cpp index af47059..7287885 100644 --- a/Source/Nakatomi/PauseUIWidget.cpp +++ b/Source/Nakatomi/PauseUIWidget.cpp @@ -3,21 +3,58 @@ #include "PauseUIWidget.h" +#include "Blueprint/WidgetBlueprintLibrary.h" +#include "Kismet/GameplayStatics.h" + void UPauseUIWidget::NativeConstruct() { Super::NativeConstruct(); - ResumeButton->OnClicked.AddUniqueDynamic(this, &UPauseUIWidget::ResumeButtonOnClicked); - OptionsButton->OnClicked.AddUniqueDynamic(this, &UPauseUIWidget::OptionsButtonOnClicked); - SaveButton->OnClicked.AddUniqueDynamic(this, &UPauseUIWidget::SaveButtonOnClicked); - QuitButton->OnClicked.AddUniqueDynamic(this, &UPauseUIWidget::QuitButtonOnClicked); - CloseApplicationButton->OnClicked.AddUniqueDynamic(this, &UPauseUIWidget::CloseApplicationButtonOnClicked); + 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); + } + + 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); } diff --git a/Source/Nakatomi/PauseUIWidget.h b/Source/Nakatomi/PauseUIWidget.h index 47ff80b..f23e3af 100644 --- a/Source/Nakatomi/PauseUIWidget.h +++ b/Source/Nakatomi/PauseUIWidget.h @@ -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(); }; diff --git a/Source/Nakatomi/PlayerCharacter.cpp b/Source/Nakatomi/PlayerCharacter.cpp index 3a87ded..51ffd8a 100644 --- a/Source/Nakatomi/PlayerCharacter.cpp +++ b/Source/Nakatomi/PlayerCharacter.cpp @@ -494,9 +494,15 @@ void APlayerCharacter::EndAimDownSightsCallback(const FInputActionInstance& Inst void APlayerCharacter::PauseCallback(const FInputActionInstance& Instance) { - if (PauseMenuWidget) + APlayerController* PlayerController = Cast(GetController()); + + if (PlayerController->SetPause(true)) { - // TODO: Add pause functionality + if (PauseMenuWidget) + { + // TODO: Add pause functionality + currentPauseMenuWidget->AddToViewport(); + } } }