Skip to content

Commit

Permalink
custom timelines for vector and linear color added
Browse files Browse the repository at this point in the history
  • Loading branch information
zompi2 committed Dec 15, 2024
1 parent 082c4d8 commit 5fa32c2
Show file tree
Hide file tree
Showing 11 changed files with 445 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ class ENHANCEDCODEFLOW_API UECFCustomTimelineBP : public UECFActionBP
FOnECFCustomTimelineBPEvent OnFinished;

UFUNCTION(BlueprintCallable, meta = (BlueprintInternalUseOnly = "true", WorldContext = "WorldContextObject", AdvancedDisplay = "Settings", ToolTip = "Adds a custom timeline defined by a float curve.", DisplayName = "ECF - Custom Timeline"), Category = "ECF")
static UECFCustomTimelineBP* ECFCustomTimeline(const UObject* WorldContextObject, UCurveFloat* CurveFloat, FECFActionSettings Settings, FECFHandleBP& Handle);
static UECFCustomTimelineBP* ECFCustomTimeline(const UObject* WorldContextObject, class UCurveFloat* CurveFloat, FECFActionSettings Settings, FECFHandleBP& Handle);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright (c) 2024 Damian Nowakowski. All rights reserved.

#include "ECFCustomTimelineLinearColorBP.h"
#include "EnhancedCodeFlow.h"

ECF_PRAGMA_DISABLE_OPTIMIZATION

UECFCustomTimelineLinearColorBP* UECFCustomTimelineLinearColorBP::ECFCustomTimelineLinearColor(const UObject* WorldContextObject, UCurveLinearColor* CurveLinearColor, FECFActionSettings Settings, FECFHandleBP& Handle)
{
UECFCustomTimelineLinearColorBP* Proxy = NewObject<UECFCustomTimelineLinearColorBP>();
if (Proxy)
{
Proxy->Init(WorldContextObject, Settings);
Proxy->Proxy_Handle = FFlow::AddCustomTimelineLinearColor(WorldContextObject, CurveLinearColor,
[Proxy](FLinearColor Value, float Time)
{
if (IsProxyValid(Proxy))
{
Proxy->OnTick.Broadcast(Value, Time, false);
}
},
[Proxy](FLinearColor Value, float Time, bool bStopped)
{
if (IsProxyValid(Proxy))
{
Proxy->OnFinished.Broadcast(Value, Time, bStopped);
Proxy->ClearAsyncBPAction();
}
},
Settings);
Handle = FECFHandleBP(Proxy->Proxy_Handle);
}

return Proxy;
}

ECF_PRAGMA_ENABLE_OPTIMIZATION
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright (c) 2024 Damian Nowakowski. All rights reserved.

#pragma once

#include "../ECFActionBP.h"
#include "ECFCustomTimelineLinearColorBP.generated.h"

DECLARE_DYNAMIC_MULTICAST_DELEGATE_ThreeParams(FOnECFCustomTimelineLinearColorBPEvent, FLinearColor, Value, float, Time, bool, bStopped);

UCLASS()
class ENHANCEDCODEFLOW_API UECFCustomTimelineLinearColorBP : public UECFActionBP
{
GENERATED_BODY()

public:

UPROPERTY(BlueprintAssignable)
FOnECFCustomTimelineLinearColorBPEvent OnTick;

UPROPERTY(BlueprintAssignable)
FOnECFCustomTimelineLinearColorBPEvent OnFinished;

UFUNCTION(BlueprintCallable, meta = (BlueprintInternalUseOnly = "true", WorldContext = "WorldContextObject", AdvancedDisplay = "Settings", ToolTip = "Adds a custom timeline defined by a float curve.", DisplayName = "ECF - Custom Timeline LinearColor"), Category = "ECF")
static UECFCustomTimelineLinearColorBP* ECFCustomTimelineLinearColor(const UObject* WorldContextObject, class UCurveLinearColor* CurveLinearColor, FECFActionSettings Settings, FECFHandleBP& Handle);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright (c) 2024 Damian Nowakowski. All rights reserved.

#include "ECFCustomTimelineVectorBP.h"
#include "EnhancedCodeFlow.h"

ECF_PRAGMA_DISABLE_OPTIMIZATION

UECFCustomTimelineVectorBP* UECFCustomTimelineVectorBP::ECFCustomTimelineVector(const UObject* WorldContextObject, UCurveVector* CurveVector, FECFActionSettings Settings, FECFHandleBP& Handle)
{
UECFCustomTimelineVectorBP* Proxy = NewObject<UECFCustomTimelineVectorBP>();
if (Proxy)
{
Proxy->Init(WorldContextObject, Settings);
Proxy->Proxy_Handle = FFlow::AddCustomTimelineVector(WorldContextObject, CurveVector,
[Proxy](FVector Value, float Time)
{
if (IsProxyValid(Proxy))
{
Proxy->OnTick.Broadcast(Value, Time, false);
}
},
[Proxy](FVector Value, float Time, bool bStopped)
{
if (IsProxyValid(Proxy))
{
Proxy->OnFinished.Broadcast(Value, Time, bStopped);
Proxy->ClearAsyncBPAction();
}
},
Settings);
Handle = FECFHandleBP(Proxy->Proxy_Handle);
}

return Proxy;
}

ECF_PRAGMA_ENABLE_OPTIMIZATION
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright (c) 2024 Damian Nowakowski. All rights reserved.

#pragma once

#include "../ECFActionBP.h"
#include "ECFCustomTimelineVectorBP.generated.h"

DECLARE_DYNAMIC_MULTICAST_DELEGATE_ThreeParams(FOnECFCustomTimelineVectorBPEvent, FVector, Value, float, Time, bool, bStopped);

UCLASS()
class ENHANCEDCODEFLOW_API UECFCustomTimelineVectorBP : public UECFActionBP
{
GENERATED_BODY()

public:

UPROPERTY(BlueprintAssignable)
FOnECFCustomTimelineVectorBPEvent OnTick;

UPROPERTY(BlueprintAssignable)
FOnECFCustomTimelineVectorBPEvent OnFinished;

UFUNCTION(BlueprintCallable, meta = (BlueprintInternalUseOnly = "true", WorldContext = "WorldContextObject", AdvancedDisplay = "Settings", ToolTip = "Adds a custom timeline defined by a float curve.", DisplayName = "ECF - Custom Timeline Vector"), Category = "ECF")
static UECFCustomTimelineVectorBP* ECFCustomTimelineVector(const UObject* WorldContextObject, class UCurveVector* CurveVector, FECFActionSettings Settings, FECFHandleBP& Handle);
};
50 changes: 50 additions & 0 deletions Source/EnhancedCodeFlow/Private/EnhancedCodeFlow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#include "CodeFlowActions/ECFTimelineVector.h"
#include "CodeFlowActions/ECFTimelineLinearColor.h"
#include "CodeFlowActions/ECFCustomTimeline.h"
#include "CodeFlowActions/ECFCustomTimelineVector.h"
#include "CodeFlowActions/ECFCustomTimelineLinearColor.h"
#include "CodeFlowActions/ECFTimeLock.h"
#include "CodeFlowActions/ECFDoOnce.h"
#include "CodeFlowActions/ECFDoNTimes.h"
Expand Down Expand Up @@ -389,6 +391,54 @@ void FFlow::RemoveAllCustomTimelines(const UObject* WorldContextObject, bool bCo
ECF->RemoveActionsOfClass<UECFCustomTimeline>(bComplete, InOwner);
}

/*^^^ Custom Timeline Vector ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/

FECFHandle FFlow::AddCustomTimelineVector(const UObject* InOwner, UCurveVector* CurveVector, TUniqueFunction<void(FVector/* Value*/, float/* Time*/)>&& InTickFunc, TUniqueFunction<void(FVector/* Value*/, float/* Time*/, bool/* bStopped*/)>&& InCallbackFunc/* = nullptr*/, const FECFActionSettings& Settings/* = {}*/)
{
if (UECFSubsystem* ECF = UECFSubsystem::Get(InOwner))
return ECF->AddAction<UECFCustomTimelineVector>(InOwner, Settings, FECFInstanceId(), CurveVector, MoveTemp(InTickFunc), MoveTemp(InCallbackFunc));
else
return FECFHandle();
}

FECFHandle FFlow::AddCustomTimelineVector(const UObject* InOwner, UCurveVector* CurveVector, TUniqueFunction<void(FVector/* Value*/, float/* Time*/)>&& InTickFunc, TUniqueFunction<void(FVector/* Value*/, float/* Time*/)>&& InCallbackFunc/* = nullptr*/, const FECFActionSettings& Settings/* = {}*/)
{
if (UECFSubsystem* ECF = UECFSubsystem::Get(InOwner))
return ECF->AddAction<UECFCustomTimelineVector>(InOwner, Settings, FECFInstanceId(), CurveVector, MoveTemp(InTickFunc), MoveTemp(InCallbackFunc));
else
return FECFHandle();
}

void FFlow::RemoveAllCustomTimelinesVector(const UObject* WorldContextObject, bool bComplete/* = false*/, UObject* InOwner/* = nullptr*/)
{
if (UECFSubsystem* ECF = UECFSubsystem::Get(WorldContextObject))
ECF->RemoveActionsOfClass<UECFCustomTimelineVector>(bComplete, InOwner);
}

/*^^^ Custom Timeline Linear Color ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/

FECFHandle FFlow::AddCustomTimelineLinearColor(const UObject* InOwner, UCurveLinearColor* CurveLinearColor, TUniqueFunction<void(FLinearColor/* Value*/, float/* Time*/)>&& InTickFunc, TUniqueFunction<void(FLinearColor/* Value*/, float/* Time*/, bool/* bStopped*/)>&& InCallbackFunc/* = nullptr*/, const FECFActionSettings& Settings/* = {}*/)
{
if (UECFSubsystem* ECF = UECFSubsystem::Get(InOwner))
return ECF->AddAction<UECFCustomTimelineLinearColor>(InOwner, Settings, FECFInstanceId(), CurveLinearColor, MoveTemp(InTickFunc), MoveTemp(InCallbackFunc));
else
return FECFHandle();
}

FECFHandle FFlow::AddCustomTimelineLinearColor(const UObject* InOwner, UCurveLinearColor* CurveLinearColor, TUniqueFunction<void(FLinearColor/* Value*/, float/* Time*/)>&& InTickFunc, TUniqueFunction<void(FLinearColor/* Value*/, float/* Time*/)>&& InCallbackFunc/* = nullptr*/, const FECFActionSettings& Settings/* = {}*/)
{
if (UECFSubsystem* ECF = UECFSubsystem::Get(InOwner))
return ECF->AddAction<UECFCustomTimelineLinearColor>(InOwner, Settings, FECFInstanceId(), CurveLinearColor, MoveTemp(InTickFunc), MoveTemp(InCallbackFunc));
else
return FECFHandle();
}

void FFlow::RemoveAllCustomTimelinesLinearColor(const UObject* WorldContextObject, bool bComplete/* = false*/, UObject* InOwner/* = nullptr*/)
{
if (UECFSubsystem* ECF = UECFSubsystem::Get(WorldContextObject))
ECF->RemoveActionsOfClass<UECFCustomTimelineLinearColor>(bComplete, InOwner);
}

/*^^^ Time Lock ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/

FECFHandle FEnhancedCodeFlow::TimeLock(const UObject* InOwner, float InLockTime, TUniqueFunction<void()>&& InExecFunc, const FECFInstanceId& InstanceId, const FECFActionSettings& Settings /*= {}*/)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
// Copyright (c) 2024 Damian Nowakowski. All rights reserved.

#pragma once

#include "ECFActionBase.h"
#include "Components/TimelineComponent.h"
#include "Curves/CurveLinearColor.h"
#include "ECFCustomTimelineLinearColor.generated.h"

ECF_PRAGMA_DISABLE_OPTIMIZATION

UCLASS()
class ENHANCEDCODEFLOW_API UECFCustomTimelineLinearColor : public UECFActionBase
{
GENERATED_BODY()

friend class UECFSubsystem;

protected:

TUniqueFunction<void(FLinearColor, float)> TickFunc;
TUniqueFunction<void(FLinearColor, float, bool)> CallbackFunc;
TUniqueFunction<void(FLinearColor, float)> CallbackFunc_NoStopped;
FTimeline MyTimeline;

FLinearColor CurrentValue = FLinearColor::Black;
float CurrentTime = 0.f;

UPROPERTY(Transient)
UCurveLinearColor* CurveLinearColor = nullptr;

bool Setup(UCurveLinearColor* InCurveLinearColor, TUniqueFunction<void(FLinearColor, float)>&& InTickFunc, TUniqueFunction<void(FLinearColor, float, bool)>&& InCallbackFunc = nullptr)
{
TickFunc = MoveTemp(InTickFunc);
CallbackFunc = MoveTemp(InCallbackFunc);
CurveLinearColor = InCurveLinearColor;

if (TickFunc && CurveLinearColor)
{
FOnTimelineLinearColor ProgressFunction;
ProgressFunction.BindUFunction(this, FName("HandleProgress"));
MyTimeline.AddInterpLinearColor(CurveLinearColor, ProgressFunction);

FOnTimelineEvent FinishFunction;
FinishFunction.BindUFunction(this, FName("HandleFinish"));
MyTimeline.SetTimelineFinishedFunc(FinishFunction);

MyTimeline.PlayFromStart();

return true;
}
else
{
ensureMsgf(false, TEXT("ECF - custom timeline LinearColor failed to start. Are you sure Tick Function and Curve are set properly?"));
return false;
}
}

bool Setup(UCurveLinearColor* InCurveLinearColor, TUniqueFunction<void(FLinearColor, float)>&& InTickFunc, TUniqueFunction<void(FLinearColor, float)>&& InCallbackFunc = nullptr)
{
CallbackFunc_NoStopped = MoveTemp(InCallbackFunc);
return Setup(InCurveLinearColor, MoveTemp(InTickFunc), [this](FLinearColor Value, float Time, bool bStopped)
{
if (CallbackFunc_NoStopped)
{
CallbackFunc_NoStopped(Value, Time);
}
});
}

void Tick(float DeltaTime) override
{
#if STATS
DECLARE_SCOPE_CYCLE_COUNTER(TEXT("CustomTimelineLinearColor - Tick"), STAT_ECFDETAILS_CUSTOMTIMELINELINEARCOLOR, STATGROUP_ECFDETAILS);
#endif
MyTimeline.TickTimeline(DeltaTime);
}

void Complete(bool bStopped) override
{
if (CallbackFunc)
{
CallbackFunc(CurrentValue, CurrentTime, bStopped);
}
}

private:

UFUNCTION()
void HandleProgress(FLinearColor Value)
{
CurrentValue = Value;
CurrentTime = MyTimeline.GetPlaybackPosition();
if (HasValidOwner())
{
TickFunc(CurrentValue, CurrentTime);
}
}

UFUNCTION()
void HandleFinish()
{
if (HasValidOwner())
{
Complete(false);
}
MarkAsFinished();
}
};

ECF_PRAGMA_ENABLE_OPTIMIZATION
Loading

0 comments on commit 5fa32c2

Please sign in to comment.