From 3bd680ca16098bcc670edba9bcffcdeb81bfa34a Mon Sep 17 00:00:00 2001 From: baz Date: Wed, 3 Apr 2024 23:59:29 +0100 Subject: [PATCH] Add OnClicked Sound Functionality --- Source/Nakatomi/MainMenuUIWidget.cpp | 4 ++++ Source/Nakatomi/UI/NakatomiInteractiveWidget.cpp | 8 ++++++++ Source/Nakatomi/UI/NakatomiInteractiveWidget.h | 6 ++++++ 3 files changed, 18 insertions(+) diff --git a/Source/Nakatomi/MainMenuUIWidget.cpp b/Source/Nakatomi/MainMenuUIWidget.cpp index b30b9f9..1aab59f 100644 --- a/Source/Nakatomi/MainMenuUIWidget.cpp +++ b/Source/Nakatomi/MainMenuUIWidget.cpp @@ -13,6 +13,7 @@ void UMainMenuUIWidget::NativeConstruct() if (NewGameButton) { NewGameButton->OnClicked.AddUniqueDynamic(this, &UMainMenuUIWidget::NewGameButtonOnClicked); + NewGameButton->OnClicked.AddUniqueDynamic(this, &UMainMenuUIWidget::PlayClickedSound); NewGameButton->OnHovered.AddUniqueDynamic(this, &UMainMenuUIWidget::PlayHoveredSound); NewGameButton->OnHovered.AddUniqueDynamic(this, &UMainMenuUIWidget::NewGameTextBlockHoveredDelegate); @@ -24,6 +25,7 @@ void UMainMenuUIWidget::NativeConstruct() if (LoadGameButton) { LoadGameButton->OnClicked.AddUniqueDynamic(this, &UMainMenuUIWidget::LoadGameButtonOnClicked); + LoadGameButton->OnClicked.AddUniqueDynamic(this, &UMainMenuUIWidget::PlayClickedSound); LoadGameButton->OnHovered.AddUniqueDynamic(this, &UMainMenuUIWidget::PlayHoveredSound); LoadGameButton->OnHovered.AddUniqueDynamic(this, &UMainMenuUIWidget::LoadGameTextBlockHoveredDelegate); @@ -35,6 +37,7 @@ void UMainMenuUIWidget::NativeConstruct() if (OptionsButton) { OptionsButton->OnClicked.AddUniqueDynamic(this, &UMainMenuUIWidget::OptionsButtonOnClicked); + OptionsButton->OnClicked.AddUniqueDynamic(this, &UMainMenuUIWidget::PlayClickedSound); OptionsButton->OnHovered.AddUniqueDynamic(this, &UMainMenuUIWidget::PlayHoveredSound); OptionsButton->OnHovered.AddUniqueDynamic(this, &UMainMenuUIWidget::OptionsTextBlockHoveredDelegate); @@ -46,6 +49,7 @@ void UMainMenuUIWidget::NativeConstruct() if (QuitButton) { QuitButton->OnClicked.AddUniqueDynamic(this, &UMainMenuUIWidget::QuitButtonOnClicked); + QuitButton->OnClicked.AddUniqueDynamic(this, &UMainMenuUIWidget::PlayClickedSound); QuitButton->OnHovered.AddUniqueDynamic(this, &UMainMenuUIWidget::PlayHoveredSound); QuitButton->OnHovered.AddUniqueDynamic(this, &UMainMenuUIWidget::QuitTextBlockHoveredDelegate); diff --git a/Source/Nakatomi/UI/NakatomiInteractiveWidget.cpp b/Source/Nakatomi/UI/NakatomiInteractiveWidget.cpp index f80ff09..ad7503a 100644 --- a/Source/Nakatomi/UI/NakatomiInteractiveWidget.cpp +++ b/Source/Nakatomi/UI/NakatomiInteractiveWidget.cpp @@ -30,3 +30,11 @@ void UNakatomiInteractiveWidget::PlayUnhoveredSound() UGameplayStatics::PlaySound2D(GetWorld(), ButtonUnhoveredSound); } } + +void UNakatomiInteractiveWidget::PlayClickedSound() +{ + if (ButtonClickedSound) + { + UGameplayStatics::PlaySound2D(GetWorld(), ButtonUnhoveredSound); + } +} diff --git a/Source/Nakatomi/UI/NakatomiInteractiveWidget.h b/Source/Nakatomi/UI/NakatomiInteractiveWidget.h index 2d6315b..e2bb91b 100644 --- a/Source/Nakatomi/UI/NakatomiInteractiveWidget.h +++ b/Source/Nakatomi/UI/NakatomiInteractiveWidget.h @@ -29,6 +29,9 @@ public: UPROPERTY(EditDefaultsOnly, BlueprintReadWrite) USoundBase* ButtonUnhoveredSound; + UPROPERTY(EditDefaultsOnly, BlueprintReadWrite) + USoundBase* ButtonClickedSound; + protected: UFUNCTION() void PlayHoveredSound(); @@ -41,5 +44,8 @@ protected: UFUNCTION() void PlayUnhoveredSound(); + + UFUNCTION() + void PlayClickedSound(); };