Add MenuMain hover text functionality

This commit is contained in:
baz 2024-04-03 22:38:11 +01:00
parent 2fb940610c
commit a86c56fccb
3 changed files with 72 additions and 2 deletions

Binary file not shown.

View File

@ -14,24 +14,36 @@ void UMainMenuUIWidget::NativeConstruct()
{
NewGameButton->OnClicked.AddUniqueDynamic(this, &UMainMenuUIWidget::NewGameButtonOnClicked);
NewGameButton->OnHovered.AddUniqueDynamic(this, &UMainMenuUIWidget::PlayHoveredSound);
NewGameButton->OnHovered.AddUniqueDynamic(this, &UMainMenuUIWidget::NewGameTextBlockHoveredDelegate);
NewGameButton->OnUnhovered.AddUniqueDynamic(this, &UMainMenuUIWidget::NewGameTextBlockUnhoveredDelegate);
}
if (LoadGameButton)
{
LoadGameButton->OnClicked.AddUniqueDynamic(this, &UMainMenuUIWidget::LoadGameButtonOnClicked);
LoadGameButton->OnHovered.AddUniqueDynamic(this, &UMainMenuUIWidget::PlayHoveredSound);
LoadGameButton->OnHovered.AddUniqueDynamic(this, &UMainMenuUIWidget::LoadGameTextBlockHoveredDelegate);
LoadGameButton->OnUnhovered.AddUniqueDynamic(this, &UMainMenuUIWidget::LoadGameTextBlockUnhoveredDelegate);
}
if (OptionsButton)
{
OptionsButton->OnClicked.AddUniqueDynamic(this, &UMainMenuUIWidget::OptionsButtonOnClicked);
OptionsButton->OnHovered.AddUniqueDynamic(this, &UMainMenuUIWidget::PlayHoveredSound);
OptionsButton->OnHovered.AddUniqueDynamic(this, &UMainMenuUIWidget::OptionsTextBlockHoveredDelegate);
OptionsButton->OnUnhovered.AddUniqueDynamic(this, &UMainMenuUIWidget::OptionsTextBlockUnhoveredDelegate);
}
if (QuitButton)
{
QuitButton->OnClicked.AddUniqueDynamic(this, &UMainMenuUIWidget::QuitButtonOnClicked);
QuitButton->OnHovered.AddUniqueDynamic(this, &UMainMenuUIWidget::PlayHoveredSound);
QuitButton->OnHovered.AddUniqueDynamic(this, &UMainMenuUIWidget::QuitTextBlockHoveredDelegate);
QuitButton->OnUnhovered.AddUniqueDynamic(this, &UMainMenuUIWidget::QuitTextBlockUnhoveredDelegate);
}
if (APlayerController* PlayerController = UGameplayStatics::GetPlayerController(GetWorld(), 0))
@ -91,3 +103,13 @@ void UMainMenuUIWidget::PlayHoveredSound()
UGameplayStatics::PlaySound2D(GetWorld(), ButtonHoveredSound);
}
}
void UMainMenuUIWidget::SetTextBlockHovered(UTextBlock* TextBlock)
{
TextBlock->SetColorAndOpacity(FSlateColor(ButtonHoveredTextColor));
}
void UMainMenuUIWidget::SetTextBlockUnhovered(UTextBlock* TextBlock)
{
TextBlock->SetColorAndOpacity(FSlateColor(ButtonUnhoveredTextColor));
}

View File

@ -20,14 +20,26 @@ public:
UPROPERTY(BlueprintReadWrite, meta = (BindWidget))
UButton* NewGameButton;
UPROPERTY(BlueprintReadWrite, meta = (BindWidget))
UTextBlock* NewGameTextBlock;
UPROPERTY(BlueprintReadWrite, meta = (BindWidget))
UButton* LoadGameButton;
UPROPERTY(BlueprintReadWrite, meta = (BindWidget))
UTextBlock* LoadGameTextBlock;
UPROPERTY(BlueprintReadWrite, meta = (BindWidget))
UButton* OptionsButton;
UPROPERTY(BlueprintReadWrite, meta = (BindWidget))
UTextBlock* OptionsTextBlock;
UPROPERTY(BlueprintReadWrite, meta = (BindWidget))
UButton* QuitButton;
UPROPERTY(BlueprintReadWrite, meta = (BindWidget))
UTextBlock* QuitTextBlock;
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
TSubclassOf<class UUserWidget> NewGameMenuWidget;
@ -44,6 +56,12 @@ public:
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
USoundBase* ButtonHoveredSound;
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
FLinearColor ButtonHoveredTextColor = {0, 1, 0, 1};
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
FLinearColor ButtonUnhoveredTextColor = {1, 1, 1, 1};
private:
UUserWidget* currentNewGameWidget;
@ -69,4 +87,34 @@ private:
UFUNCTION()
void PlayHoveredSound();
UFUNCTION()
void SetTextBlockHovered(UTextBlock* TextBlock);
UFUNCTION()
void SetTextBlockUnhovered(UTextBlock* TextBlock);
UFUNCTION()
void NewGameTextBlockHoveredDelegate() { SetTextBlockHovered(NewGameTextBlock); }
UFUNCTION()
void NewGameTextBlockUnhoveredDelegate() { SetTextBlockUnhovered(NewGameTextBlock); }
UFUNCTION()
void LoadGameTextBlockHoveredDelegate() { SetTextBlockHovered(LoadGameTextBlock); }
UFUNCTION()
void LoadGameTextBlockUnhoveredDelegate() { SetTextBlockUnhovered(LoadGameTextBlock); }
UFUNCTION()
void OptionsTextBlockHoveredDelegate() { SetTextBlockHovered(OptionsTextBlock); }
UFUNCTION()
void OptionsTextBlockUnhoveredDelegate() { SetTextBlockUnhovered(OptionsTextBlock); }
UFUNCTION()
void QuitTextBlockHoveredDelegate() { SetTextBlockHovered(QuitTextBlock); }
UFUNCTION()
void QuitTextBlockUnhoveredDelegate() { SetTextBlockUnhovered(QuitTextBlock); }
};