Add VampireInteractiveWidget
This commit is contained in:
		
							parent
							
								
									f72780bb00
								
							
						
					
					
						commit
						d6b143b7b1
					
				
							
								
								
									
										58
									
								
								Source/vampires/Widgets/VampireInteractiveWidget.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										58
									
								
								Source/vampires/Widgets/VampireInteractiveWidget.cpp
									
									
									
									
									
										Normal 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(); | ||||||
|  | } | ||||||
							
								
								
									
										62
									
								
								Source/vampires/Widgets/VampireInteractiveWidget.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										62
									
								
								Source/vampires/Widgets/VampireInteractiveWidget.h
									
									
									
									
									
										Normal 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(); | ||||||
|  | }; | ||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user