Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
WidgetAnimation.c
Go to the documentation of this file.
1//---- REFACTOR NOTE START: This code will need to be refactored as current implementation is not conforming to the standards ----
2// Incomplete: lacks support for custom curves (workbench even has an editor to visualize them), looping, flip flop, stop & resume/revert from reached value
3
4//------------------------------------------------------------------------------------------------
36
37//------------------------------------------------------------------------------------------------
39{
40 // Constants for easing calculations
41 protected static const float C1 = 1.70158;
42 protected static const float C2 = C1 * 1.525;
43 protected static const float C3 = C1 + 1;
44 protected static const float C4 = (2 * Math.PI) / 3;
45 protected static const float C5 = (2 * Math.PI) / 4.5;
46 protected static const float N1 = 7.5625;
47 protected static const float D1 = 2.75;
48
49 protected bool m_bRepeat;
50 protected float m_fSpeed;
51 protected float m_fCurrentProgress;
52 protected float m_fValue;
53
54 protected Widget m_wWidget;
56
59 protected ref ScriptInvoker m_OnCycleCompleted; // When repeat cycle is done
60
61 //------------------------------------------------------------------------------------------------
62 float GetProgressValue(float t)
63 {
64 switch (m_eCurve)
65 {
66 case EAnimationCurve.LINEAR:
67 return t;
68 case EAnimationCurve.EASE_IN_SINE:
69 return 1 - Math.Cos((t * Math.PI) / 2);
70 case EAnimationCurve.EASE_IN_QUAD:
71 return t * t;
72 case EAnimationCurve.EASE_IN_CUBIC:
73 return t * t * t;
74 case EAnimationCurve.EASE_IN_QUART:
75 return t * t * t * t;
76 case EAnimationCurve.EASE_IN_EXPO:
77 if (t == 0)
78 return 0;
79 return Math.Pow(2, 10 * t - 10);
80 case EAnimationCurve.EASE_IN_BACK:
81 return C3 * t * t * t - C1 * t * t;
82 case EAnimationCurve.EASE_IN_CIRC:
83 return 1 - Math.Sqrt(1 - Math.Pow(t, 2));
84 case EAnimationCurve.EASE_IN_ELASTIC:
85 if (t == 0)
86 return 0;
87 if (t == 1)
88 return 1;
89 return -Math.Pow(2, 10 * t - 10) * Math.Sin((t * 10 - 10.75) * C4);
90 case EAnimationCurve.EASE_IN_BOUNCE:
91 return Math.Pow(2, 6 * (t - 1)) * Math.AbsFloat(Math.Sin( t * Math.PI * 3.5 ));
92 case EAnimationCurve.EASE_OUT_SINE:
93 return Math.Sin((t * Math.PI) / 2);
94 case EAnimationCurve.EASE_OUT_QUAD:
95 return 1 - (1 - t) * (1 - t);
96 case EAnimationCurve.EASE_OUT_CUBIC:
97 return 1 - Math.Pow(1 - t, 3);
98 case EAnimationCurve.EASE_OUT_QUART:
99 return 1 - Math.Pow(1 - t, 4);
100 case EAnimationCurve.EASE_OUT_EXPO:
101 if (t == 1)
102 return 1;
103 return 1 - Math.Pow(2, -10 * t);
104 case EAnimationCurve.EASE_OUT_BACK:
105 return 1 + C3 * Math.Pow(t - 1, 3) + C1 * Math.Pow(t - 1, 2);
106 case EAnimationCurve.EASE_OUT_CIRC:
107 return Math.Sqrt(1 - Math.Pow(t - 1, 2));
108 case EAnimationCurve.EASE_OUT_ELASTIC:
109 if (t == 0)
110 return 0;
111 if (t == 1)
112 return 1;
113 return Math.Pow(2, -10 * t) * Math.Sin((t * 10 - 0.75) * C4) + 1;
114 case EAnimationCurve.EASE_OUT_BOUNCE:
115 return 1 - Math.Pow(2, -6 * t) * Math.AbsFloat(Math.Cos(t * Math.PI * 3.5));
116 case EAnimationCurve.EASE_IN_OUT_SINE:
117 return -(Math.Cos(Math.PI * t) - 1) / 2;
118 case EAnimationCurve.EASE_IN_OUT_QUAD:
119 if (t < 0.5)
120 return 2 * t * t;
121 return 1 - Math.Pow(-2 * t + 2, 2) / 2;
122 case EAnimationCurve.EASE_IN_OUT_CUBIC:
123 if (t < 0.5)
124 return 4 * t * t * t;
125 return 1 - Math.Pow(-2 * t + 2, 3) / 2;
126 case EAnimationCurve.EASE_IN_OUT_QUART:
127 if (t < 0.5)
128 return 8 * t * t * t * t;
129 return 1 - Math.Pow(-2 * t + 2, 4) / 2;
130 case EAnimationCurve.EASE_IN_OUT_EXPO:
131 if (t == 0)
132 return 0;
133 if (t == 1)
134 return 1;
135 if (t < 0.5)
136 return Math.Pow(2, 20 * t - 10) / 2;
137 return (2 - Math.Pow(2, -20 * t + 10)) / 2;
138 case EAnimationCurve.EASE_IN_OUT_BACK:
139 if (t < 0.5)
140 return (Math.Pow(2 * t, 2) * ((C2 + 1) * 2 * t - C2)) / 2;
141 return (Math.Pow(2 * t - 2, 2) * ((C2 + 1) * (t * 2 - 2) + C2) + 2) / 2;
142 case EAnimationCurve.EASE_IN_OUT_CIRC:
143 if (t < 0.5)
144 return (1 - Math.Sqrt(1 - Math.Pow(2 * t, 2))) / 2;
145 return (Math.Sqrt(1 - Math.Pow(-2 * t + 2, 2)) + 1) / 2;
146 case EAnimationCurve.EASE_IN_OUT_ELASTIC:
147 if (t == 0)
148 return 0;
149 if (t == 1)
150 return 1;
151 if (t < 0.5)
152 return -(Math.Pow(2, 20 * t - 10) * Math.Sin((20 * t - 11.125) * C5)) / 2;
153 return (Math.Pow(2, -20 * t + 10) * Math.Sin((20 * t - 11.125) * C5)) / 2 + 1;
154 case EAnimationCurve.EASE_IN_OUT_BOUNCE:
155 if (t < 0.5)
156 return 8 * Math.Pow(2, 8 * (t - 1)) * Math.AbsFloat(Math.Sin(t * Math.PI * 7));
157 else
158 return 1 - 8 * Math.Pow(2, -8 * t) * Math.AbsFloat(Math.Sin(t * Math.PI * 7));
159 }
160 return t;
161 }
162
163 //------------------------------------------------------------------------------------------------
164 // Overridden by other animations
165 protected void ReverseDirection();
166
167 // Public API
168
169 //------------------------------------------------------------------------------------------------
170 void SetRepeat(bool repeat)
171 {
172 m_bRepeat = repeat;
173 }
174
175 //------------------------------------------------------------------------------------------------
177 {
178 return m_bRepeat;
179 }
180
181 //------------------------------------------------------------------------------------------------
182 void Stop()
183 {
184 if (m_OnStopped)
185 m_OnStopped.Invoke(this);
186 }
187
188 //------------------------------------------------------------------------------------------------
189 float GetValue()
190 {
191 return m_fValue;
192 }
193
194 //------------------------------------------------------------------------------------------------
196 {
197 if (!m_OnStopped)
199 return m_OnStopped;
200 }
201
202 //------------------------------------------------------------------------------------------------
204 {
205 if (!m_OnCompleted)
207 return m_OnCompleted;
208 }
209
210 //------------------------------------------------------------------------------------------------
217
218 //------------------------------------------------------------------------------------------------
220 {
221 m_eCurve = curve;
222 }
223
224 //------------------------------------------------------------------------------------------------
225 void SetDelay(float delay)
226 {
227 m_fCurrentProgress -= delay * m_fSpeed;
228 }
229
230 //------------------------------------------------------------------------------------------------
231 float GetDelay()
232 {
233 if (m_fCurrentProgress >= 0)
234 return 0;
235
237 }
238
239 //------------------------------------------------------------------------------------------------
240 void SetSpeed(float speed)
241 {
242 if (speed > 0)
243 m_fSpeed = speed;
244 }
245
246 //------------------------------------------------------------------------------------------------
247 float GetSpeed()
248 {
249 return m_fSpeed;
250 }
251
252 //------------------------------------------------------------------------------------------------
254 {
255 return m_wWidget;
256 }
257
258 // Events
259 //------------------------------------------------------------------------------------------------
260 bool OnUpdate(float timeSlice)
261 {
262 m_fCurrentProgress += timeSlice * m_fSpeed;
263 if (m_fCurrentProgress > 1)
265
266 if (m_fCurrentProgress < 0)
267 return false;
268
270
271 // Perform widget animation
273
274 if (m_fCurrentProgress < 1)
275 return false;
276
277 if (m_bRepeat)
278 {
281
283 {
284 m_OnCycleCompleted.Invoke(this);
285 return false;
286 }
287
288 // simply stop - item is not supposed to hang here forever without callback
289 m_bRepeat = false;
290 }
291
292 // Invoke subscribed changes
293 if (m_OnCompleted)
294 m_OnCompleted.Invoke(this);
295 if (m_OnStopped)
296 m_OnStopped.Invoke(this);
297
298 return true;
299 }
300
301 // Interface method for widget animation
302 //------------------------------------------------------------------------------------------------
303 protected void Animate(bool finished)
304 {
305 }
306
307 //------------------------------------------------------------------------------------------------
308 void WidgetAnimationBase(Widget w, float speed)
309 {
310 m_wWidget = w;
311 m_fSpeed = speed;
312 }
313};
314
315//---- REFACTOR NOTE END ----
override void OnUpdate()
Widget GetWidget()
override int GetValue()
void ReverseDirection()
void Animate(bool finished)
float GetProgressValue(float t)
void SetRepeat(bool repeat)
Widget m_wWidget
enum EAnimationCurve C1
ScriptInvoker GetOnCycleCompleted()
float m_fCurrentProgress
float GetDelay()
void SetSpeed(float speed)
ref ScriptInvoker m_OnCompleted
void WidgetAnimationBase(Widget w, float speed)
bool IsRepeating()
float m_fSpeed
float GetSpeed()
void SetCurve(EAnimationCurve curve)
ScriptInvoker GetOnStopped()
ScriptInvoker GetOnCompleted()
void SetDelay(float delay)
bool m_bRepeat
EAnimationCurve
@ EASE_IN_OUT_QUART
@ EASE_OUT_EXPO
@ EASE_IN_OUT_QUAD
@ EASE_IN_SINE
@ EASE_OUT_BOUNCE
@ EASE_IN_QUAD
@ EASE_IN_ELASTIC
@ EASE_IN_QUART
@ EASE_IN_EXPO
@ EASE_IN_BACK
@ EASE_OUT_BACK
@ EASE_IN_BOUNCE
@ EASE_IN_OUT_BOUNCE
@ EASE_IN_CIRC
@ EASE_IN_OUT_EXPO
@ EASE_IN_OUT_CUBIC
@ EASE_IN_OUT_BACK
@ EASE_IN_CUBIC
@ EASE_OUT_QUAD
@ EASE_OUT_CUBIC
@ EASE_OUT_ELASTIC
@ EASE_OUT_CIRC
@ EASE_IN_OUT_CIRC
@ EASE_IN_OUT_SINE
@ EASE_OUT_QUART
@ EASE_IN_OUT_ELASTIC
@ EASE_OUT_SINE
EAnimationCurve m_eCurve
ref ScriptInvoker m_OnStopped
ref ScriptInvoker m_OnCycleCompleted
Definition Math.c:13
void Stop()
Stop tracking time in this menu, prepare for sending data.
@ LINEAR
linear interpolation
ScriptInvokerBase< func > ScriptInvoker
Definition tools.c:134