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)
{
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);
}
}

View File

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