Move Generic Hovered functionality to InteractiveWidget class

This commit is contained in:
baz 2024-04-03 22:58:09 +01:00
parent 4c795a3a27
commit 71889f9578
8 changed files with 41 additions and 64 deletions

View File

@ -95,21 +95,3 @@ void UMainMenuUIWidget::QuitButtonOnClicked()
// For some reason the generic version does not work the same as FWindowsPlatformMisc
FWindowsPlatformMisc::RequestExit(false);
}
void UMainMenuUIWidget::PlayHoveredSound()
{
if (ButtonHoveredSound)
{
UGameplayStatics::PlaySound2D(GetWorld(), ButtonHoveredSound);
}
}
void UMainMenuUIWidget::SetTextBlockHovered(UTextBlock* TextBlock)
{
TextBlock->SetColorAndOpacity(FSlateColor(ButtonHoveredTextColor));
}
void UMainMenuUIWidget::SetTextBlockUnhovered(UTextBlock* TextBlock)
{
TextBlock->SetColorAndOpacity(FSlateColor(ButtonUnhoveredTextColor));
}

View File

@ -54,15 +54,6 @@ public:
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
TSoftObjectPtr<UWorld> NewGameLevel;
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;
@ -86,15 +77,6 @@ private:
UFUNCTION()
void QuitButtonOnClicked();
UFUNCTION()
void PlayHoveredSound();
UFUNCTION()
void SetTextBlockHovered(UTextBlock* TextBlock);
UFUNCTION()
void SetTextBlockUnhovered(UTextBlock* TextBlock);
UFUNCTION()
void NewGameTextBlockHoveredDelegate() { SetTextBlockHovered(NewGameTextBlock); }

View File

@ -200,11 +200,3 @@ void UOptionsUIWidget::OnDynamicResolutionCheckboxChanged(bool bIsChecked)
GEngine->GameUserSettings->ApplySettings(true);
this->PlayHoveredSound();
}
void UOptionsUIWidget::PlayHoveredSound()
{
if (ButtonHoveredSound)
{
UGameplayStatics::PlaySound2D(GetWorld(), ButtonHoveredSound);
}
}

View File

@ -46,9 +46,6 @@ public:
UPROPERTY(BlueprintReadWrite, meta = (BindWidget))
UButton* ResetToDefaultsButton;
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
USoundBase* ButtonHoveredSound;
private:
UUserWidget* PreviousScreen;
@ -83,7 +80,4 @@ private:
UFUNCTION()
void OnDynamicResolutionCheckboxChanged(bool bIsChecked);
UFUNCTION()
void PlayHoveredSound();
};

View File

@ -92,11 +92,3 @@ 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

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

View File

@ -3,3 +3,22 @@
#include "../UI/NakatomiInteractiveWidget.h"
#include "Kismet/GameplayStatics.h"
void UNakatomiInteractiveWidget::PlayHoveredSound()
{
if (ButtonHoveredSound)
{
UGameplayStatics::PlaySound2D(GetWorld(), ButtonHoveredSound);
}
}
void UNakatomiInteractiveWidget::SetTextBlockHovered(UTextBlock* TextBlock)
{
TextBlock->SetColorAndOpacity(FSlateColor(ButtonHoveredTextColor));
}
void UNakatomiInteractiveWidget::SetTextBlockUnhovered(UTextBlock* TextBlock)
{
TextBlock->SetColorAndOpacity(FSlateColor(ButtonUnhoveredTextColor));
}

View File

@ -4,6 +4,7 @@
#include "CoreMinimal.h"
#include "Blueprint/UserWidget.h"
#include "Components/TextBlock.h"
#include "NakatomiInteractiveWidget.generated.h"
/**
@ -13,5 +14,26 @@ UCLASS()
class NAKATOMI_API UNakatomiInteractiveWidget : public UUserWidget
{
GENERATED_BODY()
public:
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
USoundBase* ButtonHoveredSound;
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
FLinearColor ButtonHoveredTextColor = {0, 1, 0, 1};
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
FLinearColor ButtonUnhoveredTextColor = {1, 1, 1, 1};
protected:
UFUNCTION()
void PlayHoveredSound();
UFUNCTION()
void SetTextBlockHovered(UTextBlock* TextBlock);
UFUNCTION()
void SetTextBlockUnhovered(UTextBlock* TextBlock);
};