-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Vector and LinearColor timelines added
- Loading branch information
Showing
8 changed files
with
350 additions
and
4 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
Source/EnhancedCodeFlow/Private/BP/Actions/ECFTimelineLinearColorBP.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright (c) 2024 Damian Nowakowski. All rights reserved. | ||
|
||
#include "ECFTimelineLinearColorBP.h" | ||
#include "EnhancedCodeFlow.h" | ||
|
||
ECF_PRAGMA_DISABLE_OPTIMIZATION | ||
|
||
UECFTimelineLinearColorBP* UECFTimelineLinearColorBP::ECFTimelineLinearColor(const UObject* WorldContextObject, FLinearColor StartValue, FLinearColor StopValue, float Time, FECFActionSettings Settings, FECFHandleBP& Handle, EECFBlendFunc BlendFunc /*= EECFBlendFunc::ECFBlend_Linear*/, float BlendExp /*= 1.f*/) | ||
{ | ||
UECFTimelineLinearColorBP* Proxy = NewObject<UECFTimelineLinearColorBP>(); | ||
if (Proxy) | ||
{ | ||
Proxy->Init(WorldContextObject, Settings); | ||
Proxy->Proxy_Handle = FFlow::AddTimelineLinearColor(WorldContextObject, | ||
StartValue, StopValue, Time, | ||
[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, false); | ||
Proxy->ClearAsyncBPAction(); | ||
} | ||
}, | ||
BlendFunc, BlendExp, Settings); | ||
Handle = FECFHandleBP(Proxy->Proxy_Handle); | ||
} | ||
|
||
return Proxy; | ||
} | ||
|
||
ECF_PRAGMA_ENABLE_OPTIMIZATION |
26 changes: 26 additions & 0 deletions
26
Source/EnhancedCodeFlow/Private/BP/Actions/ECFTimelineLinearColorBP.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Copyright (c) 2024 Damian Nowakowski. All rights reserved. | ||
|
||
#pragma once | ||
|
||
#include "../ECFActionBP.h" | ||
#include "ECFTypes.h" | ||
#include "ECFTimelineLinearColorBP.generated.h" | ||
|
||
DECLARE_DYNAMIC_MULTICAST_DELEGATE_ThreeParams(FOnECFTimelineLinearColorBPEvent, FLinearColor, Value, float, Time, bool, bStopped); | ||
|
||
UCLASS() | ||
class ENHANCEDCODEFLOW_API UECFTimelineLinearColorBP : public UECFActionBP | ||
{ | ||
GENERATED_BODY() | ||
|
||
public: | ||
|
||
UPROPERTY(BlueprintAssignable) | ||
FOnECFTimelineLinearColorBPEvent OnTick; | ||
|
||
UPROPERTY(BlueprintAssignable) | ||
FOnECFTimelineLinearColorBPEvent OnFinished; | ||
|
||
UFUNCTION(BlueprintCallable, meta = (BlueprintInternalUseOnly = "true", WorldContext = "WorldContextObject", AdvancedDisplay = "Settings, BlendFunc, BlendExp", ToolTip = "Adds a simple LinearColor timeline that runs in a given range during a given time.", DisplayName = "ECF - Timeline LinearColor"), Category = "ECF") | ||
static UECFTimelineLinearColorBP* ECFTimelineLinearColor(const UObject* WorldContextObject, FLinearColor StartValue, FLinearColor StopValue, float Time, FECFActionSettings Settings, FECFHandleBP& Handle, EECFBlendFunc BlendFunc = EECFBlendFunc::ECFBlend_Linear, float BlendExp = 1.f); | ||
}; |
38 changes: 38 additions & 0 deletions
38
Source/EnhancedCodeFlow/Private/BP/Actions/ECFTimelineVectorBP.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Copyright (c) 2024 Damian Nowakowski. All rights reserved. | ||
|
||
#include "ECFTimelineVectorBP.h" | ||
#include "EnhancedCodeFlow.h" | ||
|
||
ECF_PRAGMA_DISABLE_OPTIMIZATION | ||
|
||
UECFTimelineVectorBP* UECFTimelineVectorBP::ECFTimelineVector(const UObject* WorldContextObject, FVector StartValue, FVector StopValue, float Time, FECFActionSettings Settings, FECFHandleBP& Handle, EECFBlendFunc BlendFunc /*= EECFBlendFunc::ECFBlend_Linear*/, float BlendExp /*= 1.f*/) | ||
{ | ||
UECFTimelineVectorBP* Proxy = NewObject<UECFTimelineVectorBP>(); | ||
if (Proxy) | ||
{ | ||
Proxy->Init(WorldContextObject, Settings); | ||
Proxy->Proxy_Handle = FFlow::AddTimelineVector(WorldContextObject, | ||
StartValue, StopValue, Time, | ||
[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, false); | ||
Proxy->ClearAsyncBPAction(); | ||
} | ||
}, | ||
BlendFunc, BlendExp, Settings); | ||
Handle = FECFHandleBP(Proxy->Proxy_Handle); | ||
} | ||
|
||
return Proxy; | ||
} | ||
|
||
ECF_PRAGMA_ENABLE_OPTIMIZATION |
26 changes: 26 additions & 0 deletions
26
Source/EnhancedCodeFlow/Private/BP/Actions/ECFTimelineVectorBP.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Copyright (c) 2024 Damian Nowakowski. All rights reserved. | ||
|
||
#pragma once | ||
|
||
#include "../ECFActionBP.h" | ||
#include "ECFTypes.h" | ||
#include "ECFTimelineVectorBP.generated.h" | ||
|
||
DECLARE_DYNAMIC_MULTICAST_DELEGATE_ThreeParams(FOnECFTimelineVectorBPEvent, FVector, Value, float, Time, bool, bStopped); | ||
|
||
UCLASS() | ||
class ENHANCEDCODEFLOW_API UECFTimelineVectorBP : public UECFActionBP | ||
{ | ||
GENERATED_BODY() | ||
|
||
public: | ||
|
||
UPROPERTY(BlueprintAssignable) | ||
FOnECFTimelineVectorBPEvent OnTick; | ||
|
||
UPROPERTY(BlueprintAssignable) | ||
FOnECFTimelineVectorBPEvent OnFinished; | ||
|
||
UFUNCTION(BlueprintCallable, meta = (BlueprintInternalUseOnly = "true", WorldContext = "WorldContextObject", AdvancedDisplay = "Settings, BlendFunc, BlendExp", ToolTip = "Adds a simple vector timeline that runs in a given range during a given time.", DisplayName = "ECF - Timeline Vector"), Category = "ECF") | ||
static UECFTimelineVectorBP* ECFTimelineVector(const UObject* WorldContextObject, FVector StartValue, FVector StopValue, float Time, FECFActionSettings Settings, FECFHandleBP& Handle, EECFBlendFunc BlendFunc = EECFBlendFunc::ECFBlend_Linear, float BlendExp = 1.f); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 115 additions & 0 deletions
115
Source/EnhancedCodeFlow/Public/CodeFlowActions/ECFTimelineLinearColor.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
// Copyright (c) 2024 Damian Nowakowski. All rights reserved. | ||
|
||
#pragma once | ||
|
||
#include "ECFActionBase.h" | ||
#include "ECFTypes.h" | ||
#include "ECFTimelineLinearColor.generated.h" | ||
|
||
ECF_PRAGMA_DISABLE_OPTIMIZATION | ||
|
||
UCLASS() | ||
class ENHANCEDCODEFLOW_API UECFTimelineLinearColor: 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; | ||
FLinearColor StartValue; | ||
FLinearColor StopValue; | ||
float Time; | ||
EECFBlendFunc BlendFunc; | ||
float BlendExp; | ||
|
||
float CurrentTime; | ||
FLinearColor CurrentValue; | ||
|
||
bool Setup(FLinearColor InStartValue, FLinearColor InStopValue, float InTime, TUniqueFunction<void(FLinearColor, float)>&& InTickFunc, TUniqueFunction<void(FLinearColor, float, bool)>&& InCallbackFunc, EECFBlendFunc InBlendFunc, float InBlendExp) | ||
{ | ||
StartValue = InStartValue; | ||
StopValue = InStopValue; | ||
Time = InTime; | ||
|
||
TickFunc = MoveTemp(InTickFunc); | ||
CallbackFunc = MoveTemp(InCallbackFunc); | ||
|
||
BlendFunc = InBlendFunc; | ||
BlendExp = InBlendExp; | ||
|
||
if (TickFunc && Time > 0 && BlendExp != 0 && StartValue != StopValue) | ||
{ | ||
SetMaxActionTime(Time); | ||
CurrentTime = 0.f; | ||
return true; | ||
} | ||
else | ||
{ | ||
ensureMsgf(false, TEXT("ECF - Timeline Linear Color failed to start. Are you sure the Ticking time is greater than 0 and Ticking Function are set properly? /n Remember, that BlendExp must be different than zero and StartValue and StopValue must not be the same!")); | ||
return false; | ||
} | ||
} | ||
|
||
bool Setup(FLinearColor InStartValue, FLinearColor InStopValue, float InTime, TUniqueFunction<void(FLinearColor, float)>&& InTickFunc, TUniqueFunction<void(FLinearColor, float)>&& InCallbackFunc, EECFBlendFunc InBlendFunc, float InBlendExp) | ||
{ | ||
CallbackFunc_NoStopped = MoveTemp(InCallbackFunc); | ||
return Setup(InStartValue, InStopValue, InTime, MoveTemp(InTickFunc), [this](FLinearColor FwdValue, float FwdTime, bool bStopped) | ||
{ | ||
if (CallbackFunc_NoStopped) | ||
{ | ||
CallbackFunc_NoStopped(FwdValue, FwdTime); | ||
} | ||
}, InBlendFunc, InBlendExp); | ||
} | ||
|
||
void Tick(float DeltaTime) override | ||
{ | ||
#if STATS | ||
DECLARE_SCOPE_CYCLE_COUNTER(TEXT("Timeline Linear Color - Tick"), STAT_ECFDETAILS_TIMELINE, STATGROUP_ECFDETAILS); | ||
#endif | ||
CurrentTime = FMath::Clamp(CurrentTime + DeltaTime, 0.f, Time); | ||
|
||
const float LerpValue = CurrentTime / Time; | ||
|
||
switch (BlendFunc) | ||
{ | ||
case EECFBlendFunc::ECFBlend_Linear: | ||
CurrentValue = FMath::Lerp(StartValue, StopValue, LerpValue); | ||
break; | ||
case EECFBlendFunc::ECFBlend_Cubic: | ||
CurrentValue = FMath::CubicInterp(StartValue, FLinearColor::Black, StopValue, FLinearColor::Black, LerpValue); | ||
break; | ||
case EECFBlendFunc::ECFBlend_EaseIn: | ||
CurrentValue = FMath::Lerp(StartValue, StopValue, FMath::Pow(LerpValue, BlendExp)); | ||
break; | ||
case EECFBlendFunc::ECFBlend_EaseOut: | ||
CurrentValue = FMath::Lerp(StartValue, StopValue, FMath::Pow(LerpValue, 1.f / BlendExp)); | ||
break; | ||
case EECFBlendFunc::ECFBlend_EaseInOut: | ||
CurrentValue = FMath::InterpEaseInOut(StartValue, StopValue, LerpValue, BlendExp); | ||
break; | ||
} | ||
|
||
TickFunc(CurrentValue, CurrentTime); | ||
|
||
if (LerpValue >= 1.f) | ||
{ | ||
Complete(false); | ||
MarkAsFinished(); | ||
} | ||
} | ||
|
||
void Complete(bool bStopped) override | ||
{ | ||
if (CallbackFunc) | ||
{ | ||
CallbackFunc(CurrentValue, CurrentTime, bStopped); | ||
} | ||
} | ||
}; | ||
|
||
ECF_PRAGMA_ENABLE_OPTIMIZATION |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.