-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathBUITween.cpp
More file actions
96 lines (74 loc) · 2.23 KB
/
Copy pathBUITween.cpp
File metadata and controls
96 lines (74 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include "BUITween.h"
TArray< FBUITweenInstance > UBUITween::ActiveInstances = TArray< FBUITweenInstance >();
TArray< FBUITweenInstance > UBUITween::InstancesToAdd = TArray< FBUITweenInstance >();
bool UBUITween::bIsInitialized = false;
void UBUITween::Startup()
{
bIsInitialized = true;
ActiveInstances.Empty();
InstancesToAdd.Empty();
}
void UBUITween::Shutdown()
{
ActiveInstances.Empty();
InstancesToAdd.Empty();
bIsInitialized = false;
}
FBUITweenInstance& UBUITween::Create( UWidget* pInWidget, float InDuration, float InDelay, bool bIsAdditive )
{
// By default let's kill any existing tweens
if ( !bIsAdditive )
{
Clear( pInWidget );
}
FBUITweenInstance Instance( pInWidget, InDuration, InDelay );
InstancesToAdd.Add( Instance );
return InstancesToAdd.Last();
}
int32 UBUITween::Clear( UWidget* pInWidget )
{
int32 NumRemoved = 0;
auto DoesTweenMatchWidgetFn = [pInWidget](const FBUITweenInstance& CurTweenInstance) -> bool {
return ( CurTweenInstance.GetWidget().IsValid() && CurTweenInstance.GetWidget() == pInWidget );
};
NumRemoved += ActiveInstances.RemoveAll(DoesTweenMatchWidgetFn);
NumRemoved += InstancesToAdd.RemoveAll(DoesTweenMatchWidgetFn);
return NumRemoved;
}
void UBUITween::Update( float DeltaTime )
{
// Reverse it so we can remove
for ( int32 i = ActiveInstances.Num()-1; i >= 0; --i )
{
FBUITweenInstance& Inst = ActiveInstances[ i ];
Inst.Update( DeltaTime );
if ( Inst.IsComplete() )
{
FBUITweenInstance CompleteInst = Inst;
ActiveInstances.RemoveAtSwap( i );
// We do this here outside of the instance update and after removing from active instances because we
// don't know if the callback in the cleanup is going to trigger adding more events
CompleteInst.DoCompleteCleanup();
}
}
ActiveInstances.Append(MoveTemp(InstancesToAdd));
InstancesToAdd.Empty();
}
bool UBUITween::GetIsTweening( UWidget* pInWidget )
{
for ( int32 i = 0; i < ActiveInstances.Num(); ++i )
{
if ( ActiveInstances[ i ].GetWidget() == pInWidget )
{
return true;
}
}
return false;
}
void UBUITween::CompleteAll()
{
// Very hacky way to make sure all Tweens complete immediately.
// First Update clears ActiveTweens, second clears "InstancesToAdd".
Update( 100000 );
Update( 100000 );
}