Add OnHovered Sound2D in PauseMenuUIWidget

This commit is contained in:
baz 2024-04-03 00:24:11 +01:00
parent 16efcc8fd7
commit 2fb940610c
3 changed files with 21 additions and 2 deletions

BIN
Content/UI/Pause/PauseMenu.uasset (Stored with Git LFS)

Binary file not shown.

View File

@ -14,26 +14,31 @@ void UPauseUIWidget::NativeConstruct()
if (ResumeButton) if (ResumeButton)
{ {
ResumeButton->OnClicked.AddUniqueDynamic(this, &UPauseUIWidget::ResumeButtonOnClicked); ResumeButton->OnClicked.AddUniqueDynamic(this, &UPauseUIWidget::ResumeButtonOnClicked);
ResumeButton->OnHovered.AddUniqueDynamic(this, &UPauseUIWidget::PlayHoveredSound);
} }
if (OptionsButton) if (OptionsButton)
{ {
OptionsButton->OnClicked.AddUniqueDynamic(this, &UPauseUIWidget::OptionsButtonOnClicked); OptionsButton->OnClicked.AddUniqueDynamic(this, &UPauseUIWidget::OptionsButtonOnClicked);
OptionsButton->OnHovered.AddUniqueDynamic(this, &UPauseUIWidget::PlayHoveredSound);
} }
if (SaveButton) if (SaveButton)
{ {
SaveButton->OnClicked.AddUniqueDynamic(this, &UPauseUIWidget::SaveButtonOnClicked); SaveButton->OnClicked.AddUniqueDynamic(this, &UPauseUIWidget::SaveButtonOnClicked);
SaveButton->OnHovered.AddUniqueDynamic(this, &UPauseUIWidget::PlayHoveredSound);
} }
if (QuitButton) if (QuitButton)
{ {
QuitButton->OnClicked.AddUniqueDynamic(this, &UPauseUIWidget::QuitButtonOnClicked); QuitButton->OnClicked.AddUniqueDynamic(this, &UPauseUIWidget::QuitButtonOnClicked);
QuitButton->OnHovered.AddUniqueDynamic(this, &UPauseUIWidget::PlayHoveredSound);
} }
if (ExitGameButton) if (ExitGameButton)
{ {
ExitGameButton->OnClicked.AddUniqueDynamic(this, &UPauseUIWidget::ExitGameButtonOnClicked); ExitGameButton->OnClicked.AddUniqueDynamic(this, &UPauseUIWidget::ExitGameButtonOnClicked);
ExitGameButton->OnHovered.AddUniqueDynamic(this, &UPauseUIWidget::PlayHoveredSound);
} }
if (APlayerController* PlayerController = UGameplayStatics::GetPlayerController(GetWorld(), 0)) 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 // For some reason the generic version does not work the same as FWindowsPlatformMisc
FWindowsPlatformMisc::RequestExit(false); FWindowsPlatformMisc::RequestExit(false);
} }
void UPauseUIWidget::PlayHoveredSound()
{
if (ButtonHoveredSound)
{
UGameplayStatics::PlaySound2D(GetWorld(), ButtonHoveredSound);
}
}

View File

@ -35,6 +35,9 @@ public:
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite) UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
TSubclassOf<class UUserWidget> OptionsMenuWidget; TSubclassOf<class UUserWidget> OptionsMenuWidget;
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
USoundBase* ButtonHoveredSound;
private: private:
UOptionsUIWidget* currentOptionsMenuWidget; UOptionsUIWidget* currentOptionsMenuWidget;
@ -56,4 +59,7 @@ private:
UFUNCTION() UFUNCTION()
void ExitGameButtonOnClicked(); void ExitGameButtonOnClicked();
UFUNCTION()
void PlayHoveredSound();
}; };