Add Unhovered Sound Stuff

This commit is contained in:
baz 2024-04-03 23:24:33 +01:00
parent 71889f9578
commit 2981ca4f79
3 changed files with 22 additions and 0 deletions

View File

@ -13,37 +13,45 @@ void UMainMenuUIWidget::NativeConstruct()
if (NewGameButton) if (NewGameButton)
{ {
NewGameButton->OnClicked.AddUniqueDynamic(this, &UMainMenuUIWidget::NewGameButtonOnClicked); NewGameButton->OnClicked.AddUniqueDynamic(this, &UMainMenuUIWidget::NewGameButtonOnClicked);
NewGameButton->OnHovered.AddUniqueDynamic(this, &UMainMenuUIWidget::PlayHoveredSound); NewGameButton->OnHovered.AddUniqueDynamic(this, &UMainMenuUIWidget::PlayHoveredSound);
NewGameButton->OnHovered.AddUniqueDynamic(this, &UMainMenuUIWidget::NewGameTextBlockHoveredDelegate); NewGameButton->OnHovered.AddUniqueDynamic(this, &UMainMenuUIWidget::NewGameTextBlockHoveredDelegate);
NewGameButton->OnUnhovered.AddUniqueDynamic(this, &UMainMenuUIWidget::NewGameTextBlockUnhoveredDelegate); NewGameButton->OnUnhovered.AddUniqueDynamic(this, &UMainMenuUIWidget::NewGameTextBlockUnhoveredDelegate);
NewGameButton->OnUnhovered.AddUniqueDynamic(this, &UMainMenuUIWidget::PlayUnhoveredSound);
} }
if (LoadGameButton) if (LoadGameButton)
{ {
LoadGameButton->OnClicked.AddUniqueDynamic(this, &UMainMenuUIWidget::LoadGameButtonOnClicked); LoadGameButton->OnClicked.AddUniqueDynamic(this, &UMainMenuUIWidget::LoadGameButtonOnClicked);
LoadGameButton->OnHovered.AddUniqueDynamic(this, &UMainMenuUIWidget::PlayHoveredSound); LoadGameButton->OnHovered.AddUniqueDynamic(this, &UMainMenuUIWidget::PlayHoveredSound);
LoadGameButton->OnHovered.AddUniqueDynamic(this, &UMainMenuUIWidget::LoadGameTextBlockHoveredDelegate); LoadGameButton->OnHovered.AddUniqueDynamic(this, &UMainMenuUIWidget::LoadGameTextBlockHoveredDelegate);
LoadGameButton->OnUnhovered.AddUniqueDynamic(this, &UMainMenuUIWidget::LoadGameTextBlockUnhoveredDelegate); LoadGameButton->OnUnhovered.AddUniqueDynamic(this, &UMainMenuUIWidget::LoadGameTextBlockUnhoveredDelegate);
LoadGameButton->OnUnhovered.AddUniqueDynamic(this, &UMainMenuUIWidget::PlayUnhoveredSound);
} }
if (OptionsButton) if (OptionsButton)
{ {
OptionsButton->OnClicked.AddUniqueDynamic(this, &UMainMenuUIWidget::OptionsButtonOnClicked); OptionsButton->OnClicked.AddUniqueDynamic(this, &UMainMenuUIWidget::OptionsButtonOnClicked);
OptionsButton->OnHovered.AddUniqueDynamic(this, &UMainMenuUIWidget::PlayHoveredSound); OptionsButton->OnHovered.AddUniqueDynamic(this, &UMainMenuUIWidget::PlayHoveredSound);
OptionsButton->OnHovered.AddUniqueDynamic(this, &UMainMenuUIWidget::OptionsTextBlockHoveredDelegate); OptionsButton->OnHovered.AddUniqueDynamic(this, &UMainMenuUIWidget::OptionsTextBlockHoveredDelegate);
OptionsButton->OnUnhovered.AddUniqueDynamic(this, &UMainMenuUIWidget::OptionsTextBlockUnhoveredDelegate); OptionsButton->OnUnhovered.AddUniqueDynamic(this, &UMainMenuUIWidget::OptionsTextBlockUnhoveredDelegate);
OptionsButton->OnUnhovered.AddUniqueDynamic(this, &UMainMenuUIWidget::PlayUnhoveredSound);
} }
if (QuitButton) if (QuitButton)
{ {
QuitButton->OnClicked.AddUniqueDynamic(this, &UMainMenuUIWidget::QuitButtonOnClicked); QuitButton->OnClicked.AddUniqueDynamic(this, &UMainMenuUIWidget::QuitButtonOnClicked);
QuitButton->OnHovered.AddUniqueDynamic(this, &UMainMenuUIWidget::PlayHoveredSound); QuitButton->OnHovered.AddUniqueDynamic(this, &UMainMenuUIWidget::PlayHoveredSound);
QuitButton->OnHovered.AddUniqueDynamic(this, &UMainMenuUIWidget::QuitTextBlockHoveredDelegate); QuitButton->OnHovered.AddUniqueDynamic(this, &UMainMenuUIWidget::QuitTextBlockHoveredDelegate);
QuitButton->OnUnhovered.AddUniqueDynamic(this, &UMainMenuUIWidget::QuitTextBlockUnhoveredDelegate); QuitButton->OnUnhovered.AddUniqueDynamic(this, &UMainMenuUIWidget::QuitTextBlockUnhoveredDelegate);
QuitButton->OnUnhovered.AddUniqueDynamic(this, &UMainMenuUIWidget::PlayUnhoveredSound);
} }
if (APlayerController* PlayerController = UGameplayStatics::GetPlayerController(GetWorld(), 0)) if (APlayerController* PlayerController = UGameplayStatics::GetPlayerController(GetWorld(), 0))

View File

@ -22,3 +22,11 @@ void UNakatomiInteractiveWidget::SetTextBlockUnhovered(UTextBlock* TextBlock)
{ {
TextBlock->SetColorAndOpacity(FSlateColor(ButtonUnhoveredTextColor)); TextBlock->SetColorAndOpacity(FSlateColor(ButtonUnhoveredTextColor));
} }
void UNakatomiInteractiveWidget::PlayUnhoveredSound()
{
if (ButtonUnhoveredSound)
{
UGameplayStatics::PlaySound2D(GetWorld(), ButtonUnhoveredSound);
}
}

View File

@ -26,6 +26,9 @@ public:
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite) UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
FLinearColor ButtonUnhoveredTextColor = {1, 1, 1, 1}; FLinearColor ButtonUnhoveredTextColor = {1, 1, 1, 1};
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
USoundBase* ButtonUnhoveredSound;
protected: protected:
UFUNCTION() UFUNCTION()
void PlayHoveredSound(); void PlayHoveredSound();
@ -36,4 +39,7 @@ protected:
UFUNCTION() UFUNCTION()
void SetTextBlockUnhovered(UTextBlock* TextBlock); void SetTextBlockUnhovered(UTextBlock* TextBlock);
UFUNCTION()
void PlayUnhoveredSound();
}; };