Add OnClicked Sound Functionality

This commit is contained in:
baz 2024-04-03 23:59:29 +01:00
parent 2981ca4f79
commit 3bd680ca16
3 changed files with 18 additions and 0 deletions

View File

@ -13,6 +13,7 @@ void UMainMenuUIWidget::NativeConstruct()
if (NewGameButton) if (NewGameButton)
{ {
NewGameButton->OnClicked.AddUniqueDynamic(this, &UMainMenuUIWidget::NewGameButtonOnClicked); NewGameButton->OnClicked.AddUniqueDynamic(this, &UMainMenuUIWidget::NewGameButtonOnClicked);
NewGameButton->OnClicked.AddUniqueDynamic(this, &UMainMenuUIWidget::PlayClickedSound);
NewGameButton->OnHovered.AddUniqueDynamic(this, &UMainMenuUIWidget::PlayHoveredSound); NewGameButton->OnHovered.AddUniqueDynamic(this, &UMainMenuUIWidget::PlayHoveredSound);
NewGameButton->OnHovered.AddUniqueDynamic(this, &UMainMenuUIWidget::NewGameTextBlockHoveredDelegate); NewGameButton->OnHovered.AddUniqueDynamic(this, &UMainMenuUIWidget::NewGameTextBlockHoveredDelegate);
@ -24,6 +25,7 @@ void UMainMenuUIWidget::NativeConstruct()
if (LoadGameButton) if (LoadGameButton)
{ {
LoadGameButton->OnClicked.AddUniqueDynamic(this, &UMainMenuUIWidget::LoadGameButtonOnClicked); LoadGameButton->OnClicked.AddUniqueDynamic(this, &UMainMenuUIWidget::LoadGameButtonOnClicked);
LoadGameButton->OnClicked.AddUniqueDynamic(this, &UMainMenuUIWidget::PlayClickedSound);
LoadGameButton->OnHovered.AddUniqueDynamic(this, &UMainMenuUIWidget::PlayHoveredSound); LoadGameButton->OnHovered.AddUniqueDynamic(this, &UMainMenuUIWidget::PlayHoveredSound);
LoadGameButton->OnHovered.AddUniqueDynamic(this, &UMainMenuUIWidget::LoadGameTextBlockHoveredDelegate); LoadGameButton->OnHovered.AddUniqueDynamic(this, &UMainMenuUIWidget::LoadGameTextBlockHoveredDelegate);
@ -35,6 +37,7 @@ void UMainMenuUIWidget::NativeConstruct()
if (OptionsButton) if (OptionsButton)
{ {
OptionsButton->OnClicked.AddUniqueDynamic(this, &UMainMenuUIWidget::OptionsButtonOnClicked); OptionsButton->OnClicked.AddUniqueDynamic(this, &UMainMenuUIWidget::OptionsButtonOnClicked);
OptionsButton->OnClicked.AddUniqueDynamic(this, &UMainMenuUIWidget::PlayClickedSound);
OptionsButton->OnHovered.AddUniqueDynamic(this, &UMainMenuUIWidget::PlayHoveredSound); OptionsButton->OnHovered.AddUniqueDynamic(this, &UMainMenuUIWidget::PlayHoveredSound);
OptionsButton->OnHovered.AddUniqueDynamic(this, &UMainMenuUIWidget::OptionsTextBlockHoveredDelegate); OptionsButton->OnHovered.AddUniqueDynamic(this, &UMainMenuUIWidget::OptionsTextBlockHoveredDelegate);
@ -46,6 +49,7 @@ void UMainMenuUIWidget::NativeConstruct()
if (QuitButton) if (QuitButton)
{ {
QuitButton->OnClicked.AddUniqueDynamic(this, &UMainMenuUIWidget::QuitButtonOnClicked); QuitButton->OnClicked.AddUniqueDynamic(this, &UMainMenuUIWidget::QuitButtonOnClicked);
QuitButton->OnClicked.AddUniqueDynamic(this, &UMainMenuUIWidget::PlayClickedSound);
QuitButton->OnHovered.AddUniqueDynamic(this, &UMainMenuUIWidget::PlayHoveredSound); QuitButton->OnHovered.AddUniqueDynamic(this, &UMainMenuUIWidget::PlayHoveredSound);
QuitButton->OnHovered.AddUniqueDynamic(this, &UMainMenuUIWidget::QuitTextBlockHoveredDelegate); QuitButton->OnHovered.AddUniqueDynamic(this, &UMainMenuUIWidget::QuitTextBlockHoveredDelegate);

View File

@ -30,3 +30,11 @@ void UNakatomiInteractiveWidget::PlayUnhoveredSound()
UGameplayStatics::PlaySound2D(GetWorld(), ButtonUnhoveredSound); UGameplayStatics::PlaySound2D(GetWorld(), ButtonUnhoveredSound);
} }
} }
void UNakatomiInteractiveWidget::PlayClickedSound()
{
if (ButtonClickedSound)
{
UGameplayStatics::PlaySound2D(GetWorld(), ButtonUnhoveredSound);
}
}

View File

@ -29,6 +29,9 @@ public:
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite) UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
USoundBase* ButtonUnhoveredSound; USoundBase* ButtonUnhoveredSound;
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
USoundBase* ButtonClickedSound;
protected: protected:
UFUNCTION() UFUNCTION()
void PlayHoveredSound(); void PlayHoveredSound();
@ -42,4 +45,7 @@ protected:
UFUNCTION() UFUNCTION()
void PlayUnhoveredSound(); void PlayUnhoveredSound();
UFUNCTION()
void PlayClickedSound();
}; };