From 2fb940610c59b8ba4da4c3b826e752803a5b2348 Mon Sep 17 00:00:00 2001 From: baz Date: Wed, 3 Apr 2024 00:24:11 +0100 Subject: [PATCH] Add OnHovered Sound2D in PauseMenuUIWidget --- Content/UI/Pause/PauseMenu.uasset | 4 ++-- Source/Nakatomi/PauseUIWidget.cpp | 13 +++++++++++++ Source/Nakatomi/PauseUIWidget.h | 6 ++++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/Content/UI/Pause/PauseMenu.uasset b/Content/UI/Pause/PauseMenu.uasset index 9818c1a..9b8a765 100644 --- a/Content/UI/Pause/PauseMenu.uasset +++ b/Content/UI/Pause/PauseMenu.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:9ab3be377dc041e744ac1fbb98f5666cb4986a29a50998192fcf382542db5faa -size 40335 +oid sha256:556e20cc22844d703fe870eb3e39208bbee0d3c0688639b2429aa6c1f166489f +size 40537 diff --git a/Source/Nakatomi/PauseUIWidget.cpp b/Source/Nakatomi/PauseUIWidget.cpp index 43decb4..5c5218d 100644 --- a/Source/Nakatomi/PauseUIWidget.cpp +++ b/Source/Nakatomi/PauseUIWidget.cpp @@ -14,26 +14,31 @@ void UPauseUIWidget::NativeConstruct() if (ResumeButton) { ResumeButton->OnClicked.AddUniqueDynamic(this, &UPauseUIWidget::ResumeButtonOnClicked); + ResumeButton->OnHovered.AddUniqueDynamic(this, &UPauseUIWidget::PlayHoveredSound); } if (OptionsButton) { OptionsButton->OnClicked.AddUniqueDynamic(this, &UPauseUIWidget::OptionsButtonOnClicked); + OptionsButton->OnHovered.AddUniqueDynamic(this, &UPauseUIWidget::PlayHoveredSound); } if (SaveButton) { SaveButton->OnClicked.AddUniqueDynamic(this, &UPauseUIWidget::SaveButtonOnClicked); + SaveButton->OnHovered.AddUniqueDynamic(this, &UPauseUIWidget::PlayHoveredSound); } if (QuitButton) { QuitButton->OnClicked.AddUniqueDynamic(this, &UPauseUIWidget::QuitButtonOnClicked); + QuitButton->OnHovered.AddUniqueDynamic(this, &UPauseUIWidget::PlayHoveredSound); } if (ExitGameButton) { ExitGameButton->OnClicked.AddUniqueDynamic(this, &UPauseUIWidget::ExitGameButtonOnClicked); + ExitGameButton->OnHovered.AddUniqueDynamic(this, &UPauseUIWidget::PlayHoveredSound); } if (APlayerController* PlayerController = UGameplayStatics::GetPlayerController(GetWorld(), 0)) @@ -87,3 +92,11 @@ void UPauseUIWidget::ExitGameButtonOnClicked() // For some reason the generic version does not work the same as FWindowsPlatformMisc FWindowsPlatformMisc::RequestExit(false); } + +void UPauseUIWidget::PlayHoveredSound() +{ + if (ButtonHoveredSound) + { + UGameplayStatics::PlaySound2D(GetWorld(), ButtonHoveredSound); + } +} diff --git a/Source/Nakatomi/PauseUIWidget.h b/Source/Nakatomi/PauseUIWidget.h index 94ea56c..3ea2b92 100644 --- a/Source/Nakatomi/PauseUIWidget.h +++ b/Source/Nakatomi/PauseUIWidget.h @@ -35,6 +35,9 @@ public: UPROPERTY(EditDefaultsOnly, BlueprintReadWrite) TSubclassOf OptionsMenuWidget; + UPROPERTY(EditDefaultsOnly, BlueprintReadWrite) + USoundBase* ButtonHoveredSound; + private: UOptionsUIWidget* currentOptionsMenuWidget; @@ -56,4 +59,7 @@ private: UFUNCTION() void ExitGameButtonOnClicked(); + + UFUNCTION() + void PlayHoveredSound(); };