From d6b143b7b1300b1a76fe67b677835bebdfd18f95 Mon Sep 17 00:00:00 2001 From: baz Date: Wed, 7 May 2025 00:57:23 +0100 Subject: [PATCH] Add VampireInteractiveWidget --- .../Widgets/VampireInteractiveWidget.cpp | 58 +++++++++++++++++ .../Widgets/VampireInteractiveWidget.h | 62 +++++++++++++++++++ 2 files changed, 120 insertions(+) create mode 100644 Source/vampires/Widgets/VampireInteractiveWidget.cpp create mode 100644 Source/vampires/Widgets/VampireInteractiveWidget.h diff --git a/Source/vampires/Widgets/VampireInteractiveWidget.cpp b/Source/vampires/Widgets/VampireInteractiveWidget.cpp new file mode 100644 index 0000000..d0011e9 --- /dev/null +++ b/Source/vampires/Widgets/VampireInteractiveWidget.cpp @@ -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(); +} diff --git a/Source/vampires/Widgets/VampireInteractiveWidget.h b/Source/vampires/Widgets/VampireInteractiveWidget.h new file mode 100644 index 0000000..ff7c111 --- /dev/null +++ b/Source/vampires/Widgets/VampireInteractiveWidget.h @@ -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 ButtonHoveredSound; + + UPROPERTY(EditDefaultsOnly, BlueprintReadWrite) + FLinearColor ButtonHoveredTextColor = {0, 1, 0, 1}; + + UPROPERTY(EditDefaultsOnly, BlueprintReadWrite) + FLinearColor ButtonUnhoveredTextColor = {1, 1, 1, 1}; + + UPROPERTY(EditDefaultsOnly, BlueprintReadWrite) + TObjectPtr ButtonUnhoveredSound; + + UPROPERTY(EditDefaultsOnly, BlueprintReadWrite) + TObjectPtr ButtonClickedSound; + +protected: + UPROPERTY() + TObjectPtr 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(); +};