Add VampireInteractiveWidget

This commit is contained in:
baz 2025-05-07 00:57:23 +01:00
parent f72780bb00
commit d6b143b7b1
2 changed files with 120 additions and 0 deletions

View File

@ -0,0 +1,58 @@
// Louis Hobbs | 2024-2025
#include "VampireInteractiveWidget.h"
#include "Components/TextBlock.h"
#include "GameFramework/GameUserSettings.h"
#include "Kismet/GameplayStatics.h"
void UVampireInteractiveWidget::SetReturnScreen(UUserWidget* userWidget)
{
if (userWidget)
{
PreviousScreen = userWidget;
}
}
void UVampireInteractiveWidget::PlayHoveredSound()
{
if (ButtonHoveredSound)
{
UGameplayStatics::PlaySound2D(GetWorld(), ButtonHoveredSound);
}
}
void UVampireInteractiveWidget::SetTextBlockHovered(UTextBlock* TextBlock)
{
TextBlock->SetColorAndOpacity(FSlateColor(ButtonHoveredTextColor));
}
void UVampireInteractiveWidget::SetTextBlockUnhovered(UTextBlock* TextBlock)
{
TextBlock->SetColorAndOpacity(FSlateColor(ButtonUnhoveredTextColor));
}
void UVampireInteractiveWidget::PlayUnhoveredSound()
{
if (ButtonUnhoveredSound)
{
UGameplayStatics::PlaySound2D(GetWorld(), ButtonUnhoveredSound);
}
}
void UVampireInteractiveWidget::PlayClickedSound()
{
if (ButtonClickedSound)
{
UGameplayStatics::PlaySound2D(GetWorld(), ButtonClickedSound);
}
}
void UVampireInteractiveWidget::ReturnToPreviousScreen()
{
GEngine->GameUserSettings->ApplySettings(false);
this->RemoveFromParent();
PreviousScreen->AddToViewport();
}

View File

@ -0,0 +1,62 @@
// Louis Hobbs | 2024-2025
#pragma once
#include "CoreMinimal.h"
#include "Blueprint/UserWidget.h"
#include "VampireInteractiveWidget.generated.h"
class UTextBlock;
/**
*
*/
UCLASS()
class VAMPIRES_API UVampireInteractiveWidget : public UUserWidget
{
GENERATED_BODY()
public:
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
TObjectPtr<USoundBase> ButtonHoveredSound;
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
FLinearColor ButtonHoveredTextColor = {0, 1, 0, 1};
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
FLinearColor ButtonUnhoveredTextColor = {1, 1, 1, 1};
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
TObjectPtr<USoundBase> ButtonUnhoveredSound;
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
TObjectPtr<USoundBase> ButtonClickedSound;
protected:
UPROPERTY()
TObjectPtr<UUserWidget> PreviousScreen;
public:
UFUNCTION()
void SetReturnScreen(UUserWidget* userWidget);
protected:
UFUNCTION()
void PlayHoveredSound();
UFUNCTION()
void SetTextBlockHovered(UTextBlock* TextBlock);
UFUNCTION()
void SetTextBlockUnhovered(UTextBlock* TextBlock);
UFUNCTION()
void PlayUnhoveredSound();
UFUNCTION()
void PlayClickedSound();
UFUNCTION()
void ReturnToPreviousScreen();
};