Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Refactored current show locked fade overlay logic #64

Merged
merged 15 commits into from
Mar 16, 2025
Merged
Prev Previous commit
Next Next commit
drastically improved comments
  • Loading branch information
moinm3uw committed Mar 13, 2025
commit 9cb58a2b7115020fa05bcbd27c72022c75f4af81
34 changes: 16 additions & 18 deletions Source/ProgressionSystemRuntime/Private/Widgets/PSOverlayWidget.cpp
Original file line number Diff line number Diff line change
@@ -16,33 +16,31 @@
#include UE_INLINE_GENERATED_CPP_BY_NAME(PSOverlayWidget)

// Sets the visibility of the overlay elements and playing fade animation if needed
// Example: FadeIn, Active
// void UPSOverlayWidget::SetOverlayVisibility(EPSOverlayWidgetFadeStateDirection NewState)
void UPSOverlayWidget::SetOverlayVisibility(EPSOverlayWidgetFadeAnimationType NewFadeAnimationType, EPSOverlayWidgetFadeAnimationState NewFadeAnimationState)
void UPSOverlayWidget::ApplyOverlayAnimation(EPSOverlayWidgetFadeAnimation NewAnimation, EPSOverlayWidgetFadeAnimationType NewAnimationType)
{
if (NewFadeAnimationState == EPSOverlayWidgetFadeAnimationState::Finished)
if (NewAnimationType == EPSOverlayWidgetFadeAnimationType::Instant)
{
const ESlateVisibility desiredWidgetVisibility = NewFadeAnimationType == EPSOverlayWidgetFadeAnimationType::FadeIn ? ESlateVisibility::Visible : ESlateVisibility::Collapsed;
const float desiredOpacity = NewFadeAnimationType == EPSOverlayWidgetFadeAnimationType::FadeIn ? 1.0f : 0.0f;
const ESlateVisibility desiredWidgetVisibility = NewAnimation == EPSOverlayWidgetFadeAnimation::FadeIn ? ESlateVisibility::Visible : ESlateVisibility::Collapsed;
const float desiredOpacity = NewAnimation == EPSOverlayWidgetFadeAnimation::FadeIn ? 1.0f : 0.0f;
PSCOverlay->SetRenderOpacity(desiredOpacity);
StartTimeFadeAnimationInternal = 0.0f;
SetVisibility(desiredWidgetVisibility);
CurrentFadeStateInternal = NewFadeAnimationState;
CurrentAnimationStyleInternal = NewAnimationType;
return;
}

if (NewFadeAnimationType == EPSOverlayWidgetFadeAnimationType::FadeIn && CurrentFadeTypeInternal == EPSOverlayWidgetFadeAnimationType::FadeIn)
if (NewAnimation == EPSOverlayWidgetFadeAnimation::FadeIn && CurrentAnimationInternal == EPSOverlayWidgetFadeAnimation::FadeIn)
{
return;
}

if (NewFadeAnimationType == EPSOverlayWidgetFadeAnimationType::FadeIn)
if (NewAnimation == EPSOverlayWidgetFadeAnimation::FadeIn)
{
SetVisibility(ESlateVisibility::Visible);
}

CurrentFadeTypeInternal = NewFadeAnimationType;
CurrentFadeStateInternal = NewFadeAnimationState;
CurrentAnimationInternal = NewAnimation;
CurrentAnimationStyleInternal = NewAnimationType;

const UWorld* World = GetWorld();
if (!ensureMsgf(World, TEXT("ASSERT: [%i] %hs:\n'World' is not valid!"), __LINE__, __FUNCTION__))
@@ -57,8 +55,8 @@ void UPSOverlayWidget::SetOverlayVisibility(EPSOverlayWidgetFadeAnimationType Ne
void UPSOverlayWidget::NativeTick(const FGeometry& MyGeometry, float InDeltaTime)
{
Super::NativeTick(MyGeometry, InDeltaTime);
if (CurrentFadeStateInternal == EPSOverlayWidgetFadeAnimationState::None
|| CurrentFadeStateInternal == EPSOverlayWidgetFadeAnimationState::Finished)
if (CurrentAnimationStyleInternal == EPSOverlayWidgetFadeAnimationType::None
|| CurrentAnimationStyleInternal == EPSOverlayWidgetFadeAnimationType::Instant)
{
return;
}
@@ -87,14 +85,14 @@ void UPSOverlayWidget::TickPlayFadeOverlayAnimation()
return;
}

const bool bIsFadeOutAnimation = CurrentFadeTypeInternal == EPSOverlayWidgetFadeAnimationType::FadeOut;
const bool bIsFadeOutAnimation = CurrentAnimationInternal == EPSOverlayWidgetFadeAnimation::FadeOut;
const float SecondsSinceStart = GetWorld()->GetTimeSeconds() - StartTimeFadeAnimationInternal;
const float NormalizedTime = FMath::Clamp(SecondsSinceStart / FadeDuration, 0.0f, 1.0f);
const float OpacityValue = bIsFadeOutAnimation ? 1.0f - NormalizedTime : NormalizedTime;

if (SecondsSinceStart >= FadeDuration)
{
SetOverlayVisibility(CurrentFadeTypeInternal, EPSOverlayWidgetFadeAnimationState::Finished);
ApplyOverlayAnimation(CurrentAnimationInternal, EPSOverlayWidgetFadeAnimationType::Instant);
return;
}

@@ -134,8 +132,8 @@ void UPSOverlayWidget::DisplayLevelUIOverlay()
}
}

EPSOverlayWidgetFadeAnimationType FadeAnimationType = OverlayVisibility == ESlateVisibility::Visible ? EPSOverlayWidgetFadeAnimationType::FadeIn : EPSOverlayWidgetFadeAnimationType::FadeOut;
EPSOverlayWidgetFadeAnimationState FadeAnimationState = bShouldPlayFadeAnimation ? EPSOverlayWidgetFadeAnimationState::Active : EPSOverlayWidgetFadeAnimationState::Finished;
SetOverlayVisibility(FadeAnimationType, FadeAnimationState);
EPSOverlayWidgetFadeAnimation Animation = OverlayVisibility == ESlateVisibility::Visible ? EPSOverlayWidgetFadeAnimation::FadeIn : EPSOverlayWidgetFadeAnimation::FadeOut;
EPSOverlayWidgetFadeAnimationType AnimationType = bShouldPlayFadeAnimation ? EPSOverlayWidgetFadeAnimationType::Fade : EPSOverlayWidgetFadeAnimationType::Instant;
ApplyOverlayAnimation(Animation, AnimationType);
}
}
20 changes: 10 additions & 10 deletions Source/ProgressionSystemRuntime/Public/Data/PSTypes.h
Original file line number Diff line number Diff line change
@@ -86,10 +86,10 @@ struct FPSSaveToDiskData
};

/**
* Represents the type of the overlay widget fade animation played in the menu
* Represents animations of the overlay widget animations played in the menu
*/
UENUM(BlueprintType, DisplayName = "Overlay Widget Fade Animation Type")
enum class EPSOverlayWidgetFadeAnimationType : uint8
enum class EPSOverlayWidgetFadeAnimation : uint8
{
///< Default fade no animation required
None,
@@ -100,17 +100,17 @@ enum class EPSOverlayWidgetFadeAnimationType : uint8
};

/**
* Represents the state of the overlay widget fade animation played in the menu.
* Represents type of the overlay widget animation played in the menu.
*/
UENUM(BlueprintType, DisplayName = "Overlay Widget Fade Animation State")
enum class EPSOverlayWidgetFadeAnimationState : uint8
UENUM(BlueprintType, DisplayName = "Overlay Widget Fade Animation Type")
enum class EPSOverlayWidgetFadeAnimationType : uint8
{
///< Fade to applied
///< no type to be applied
None,
///< Animation in progress
Active,
///< Animation finished
Finished,
///< Fade type animation
Fade,
///< Instant (no animation) type
Instant,
};

/**
15 changes: 8 additions & 7 deletions Source/ProgressionSystemRuntime/Public/Widgets/PSOverlayWidget.h
Original file line number Diff line number Diff line change
@@ -10,7 +10,8 @@
/**
*
* Overlay widget which is displayed for the locked/unlocked levels in the main menu
* If level is locked overlay is displayed. Is unlocked - no overlay
* If level is locked overlay is displayed. Is unlocked - no overlay.
* For transition between locked and unlocked widget has fade-in, fade-out or instant appearing effect
*/
UCLASS()
class PROGRESSIONSYSTEMRUNTIME_API UPSOverlayWidget : public UUserWidget
@@ -19,12 +20,12 @@ class PROGRESSIONSYSTEMRUNTIME_API UPSOverlayWidget : public UUserWidget

public:
/**
* Sets the visibility of the overlay elements and playing fade animation if needed
* @param NewFadeAnimationType The visibility state (e.g., Visible, Collapsed) to apply to the overlay and icon.
* @param NewFadeAnimationState Defines if the fade animation should be played after or before widget is visible
* Applies animation and requested animation style
* @param NewAnimation defines animation to be applied: e.g. FadeIn, FadeOut
* @param NewAnimationType Defines the type of animation to be played: Fade or Instant style
*/
UFUNCTION(BlueprintCallable, Category= "C++")
void SetOverlayVisibility(EPSOverlayWidgetFadeAnimationType NewFadeAnimationType, EPSOverlayWidgetFadeAnimationState NewFadeAnimationState);
void ApplyOverlayAnimation(EPSOverlayWidgetFadeAnimation NewAnimation, EPSOverlayWidgetFadeAnimationType NewAnimationType);

protected:
/** overrides NativeTick to make the user widget tickable **/
@@ -57,11 +58,11 @@ class PROGRESSIONSYSTEMRUNTIME_API UPSOverlayWidget : public UUserWidget

/** Current overlay widget fade state. */
UPROPERTY(VisibleInstanceOnly, BlueprintReadWrite, Transient, AdvancedDisplay, Category = "C++", meta = (BlueprintProtected, DisplayName = "Current Overlay Widget Fade State"))
EPSOverlayWidgetFadeAnimationState CurrentFadeStateInternal = EPSOverlayWidgetFadeAnimationState::None;
EPSOverlayWidgetFadeAnimationType CurrentAnimationStyleInternal = EPSOverlayWidgetFadeAnimationType::None;

/** Current overlay widget fade type. */
UPROPERTY(VisibleInstanceOnly, BlueprintReadWrite, Transient, AdvancedDisplay, Category = "C++", meta = (BlueprintProtected, DisplayName = "Current Overlay Widget Fade Type"))
EPSOverlayWidgetFadeAnimationType CurrentFadeTypeInternal = EPSOverlayWidgetFadeAnimationType::None;
EPSOverlayWidgetFadeAnimation CurrentAnimationInternal = EPSOverlayWidgetFadeAnimation::None;

/** Show locked level ui overlay */
UFUNCTION(BlueprintCallable, Category= "C++", meta = (BlueprintProtected))