From a78d861a7a06e6dfafd70b2c9ed8ff9f15aa08e4 Mon Sep 17 00:00:00 2001 From: Jamie Greunbaum Date: Sat, 6 May 2023 14:46:38 -0400 Subject: [PATCH] Moved all code to C++. --- .../Private/LoadingScreenWidget.cpp | 18 ++++++++++++++++++ .../Public/LoadingScreenWidget.h | 8 +++++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/Source/CommonLoadingScreen/Private/LoadingScreenWidget.cpp b/Source/CommonLoadingScreen/Private/LoadingScreenWidget.cpp index 458f649..55003ef 100644 --- a/Source/CommonLoadingScreen/Private/LoadingScreenWidget.cpp +++ b/Source/CommonLoadingScreen/Private/LoadingScreenWidget.cpp @@ -3,15 +3,33 @@ #include "LoadingScreenWidget.h" +void ULoadingScreenWidget::NativePreConstruct() +{ + FWidgetAnimationDynamicEvent LoadScreenOpened; + LoadScreenOpened.BindUFunction(this, TEXT("LoadScreenOpened")); + this->BindToAnimationFinished(this->Fade, LoadScreenOpened); + + this->PlayAnimationForward(this->Fade); +} void ULoadingScreenWidget::LoadScreenOpened() { + this->UnbindAllFromAnimationFinished(this->Fade); #if !WITH_EDITOR this->OnLoadScreenOpened.ExecuteIfBound(); #endif } +void ULoadingScreenWidget::BeginFadeOut_Implementation() +{ + FWidgetAnimationDynamicEvent LoadScreenClosed; + LoadScreenClosed.BindUFunction(this, TEXT("LoadScreenClosed")); + this->BindToAnimationFinished(this->Fade, LoadScreenClosed); + + this->PlayAnimationReverse(this->Fade); +} void ULoadingScreenWidget::LoadScreenClosed() { + this->UnbindAllFromAnimationFinished(this->Fade); #if !WITH_EDITOR this->OnLoadScreenClosed.ExecuteIfBound(); #endif diff --git a/Source/CommonLoadingScreen/Public/LoadingScreenWidget.h b/Source/CommonLoadingScreen/Public/LoadingScreenWidget.h index 5eedef6..98a57bf 100644 --- a/Source/CommonLoadingScreen/Public/LoadingScreenWidget.h +++ b/Source/CommonLoadingScreen/Public/LoadingScreenWidget.h @@ -18,15 +18,21 @@ class COMMONLOADINGSCREEN_API ULoadingScreenWidget : public UUserWidget GENERATED_BODY() public: + virtual void NativePreConstruct() override; + UFUNCTION(BlueprintCallable) void LoadScreenOpened(); UFUNCTION(BlueprintCallable) void LoadScreenClosed(); - UFUNCTION(BlueprintImplementableEvent) + UFUNCTION(BlueprintNativeEvent) void BeginFadeOut(); DECLARE_DELEGATE(FOnLoadScreenEvent) FOnLoadScreenEvent OnLoadScreenOpened; FOnLoadScreenEvent OnLoadScreenClosed; + +protected: + UPROPERTY(Transient, BlueprintReadOnly, meta=(BindWidgetAnim)) + TObjectPtr Fade; };