Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_HorizontalScrollAnimationComponent.c
Go to the documentation of this file.
32
33class SCR_HorizontalScrollAnimationComponent : ScriptedWidgetComponent
34{
35 [Attribute("Content", UIWidgets.EditBox, "Name of widget which will be animated")]
36 protected string m_sAnimationContentWidget;
37
38 [Attribute("10", UIWidgets.EditBox, "Animation speed")]
40
41 [Attribute("0.5", UIWidgets.EditBox, "Wait time while animating when content is on the left")]
42 protected float m_fWaitTimeLeftSec;
43
44 [Attribute("0.5", UIWidgets.EditBox, "Wait time while animating when content is on the right")]
45 protected float m_fWaitTimeRightSec;
46
47 [Attribute("false", UIWidgets.CheckBox, "When true, content will animate to start after it has animated left. Otherwise it will jump to start instantly.")]
48 protected bool m_bAnimateBack;
49
50 [Attribute("0", UIWidgets.CheckBox, "Inwards offset from right edge of root widget to be used in calculations")]
51 protected float m_fOffsetRight;
52
53 [Attribute("0", UIWidgets.CheckBox, "Inwards offset from left edge of root widget to be used in calculations")]
54 protected float m_fOffsetLeft;
55
56 [Attribute(typename.EnumToString(SCR_EScrollAnimationState, SCR_EScrollAnimationState.NONE), UIWidgets.ComboBox, "Start state of animation", "", ParamEnumArray.FromEnum(SCR_EScrollAnimationState))]
58
60 protected Widget m_wContent;
61 protected Widget m_wRoot;
62
63 protected float m_fStartPosX;
64 protected float m_fStartPosY;
65 protected float m_fTimer;
66
67 protected float m_fTargetPosX;
68 protected float m_fTargetPosY;
69
70 protected bool m_bIsVerticalAnimation;
71
72 //------------------------------------------------------------------------------------------------
73 // P U B L I C
74
75 //------------------------------------------------------------------------------------------------
77 {
79
80 if (GetGame() && GetGame().GetCallqueue())
81 GetGame().GetCallqueue().Remove(OnFrame);
82 }
83
84 //------------------------------------------------------------------------------------------------
85 void AnimationStart(bool IsVerticalAnimation = false)
86 {
87 // If not animating, start animation
89 {
91 GetGame().GetCallqueue().CallLater(SetupValues, 0);
92 GetGame().GetCallqueue().CallLater(OnFrame, 0, true);
93
94 m_bIsVerticalAnimation = IsVerticalAnimation;
95
98 else
100 }
101
102 // Otherwise it's already animating in some state, do nothing
103 }
104
105 //------------------------------------------------------------------------------------------------
107 {
108 return m_eState != SCR_EScrollAnimationState.NONE;
109 }
110
111 //------------------------------------------------------------------------------------------------
112 protected void SetupValues()
113 {
114 float contentw, contenth, contentx, contenty, rootw, rooth, rootx, rooty;
115 m_wContent.GetScreenSize(contentw, contenth);
116 m_wContent.GetScreenPos(contentx, contenty);
117 m_wRoot.GetScreenSize(rootw, rooth);
118 m_wRoot.GetScreenPos(rootx, rooty);
119
122
123 WorkspaceWidget workspace = GetGame().GetWorkspace();
124
125 m_fTargetPosX = rootw - contentw - workspace.DPIScale(m_fOffsetLeft);
126 m_fTargetPosY = rooth - contenth + workspace.DPIScale(m_fOffsetLeft);
127 }
128
129 //------------------------------------------------------------------------------------------------
132 {
133 if (!m_wContent)
134 return;
135
138 else
140 }
141
142 //------------------------------------------------------------------------------------------------
145 {
146 if (!m_wContent)
147 return true;
148
149 float rootw, rooth, contentw, contenth;
150 m_wContent.GetScreenSize(contentw, contenth);
151 m_wRoot.GetScreenSize(rootw, rooth);
152
153 return rootw > contentw + GetGame().GetWorkspace().DPIScale(m_fOffsetLeft + m_fOffsetRight);
154 }
155
156 //------------------------------------------------------------------------------------------------
159 {
160 if (!m_wContent)
161 return true;
162
163 float rootw, rooth, contentw, contenth;
164 m_wContent.GetScreenSize(contentw, contenth);
165 m_wRoot.GetScreenSize(rootw, rooth);
166
167 return rooth > contenth + GetGame().GetWorkspace().DPIScale(m_fOffsetLeft + m_fOffsetRight);
168 }
169
170 //------------------------------------------------------------------------------------------------
171 // P R O T E C T E D
172
173 //------------------------------------------------------------------------------------------------
174 protected override void HandlerAttached(Widget w)
175 {
176 if (!GetGame().InPlayMode())
177 return;
178
179 m_wRoot = w;
180 m_wContent = w.FindAnyWidget(m_sAnimationContentWidget);
181
182 if (!m_wContent)
183 {
184 PrintFormat("[SCR_HorizontalScrollAnimationComponent] Widget %1 was not found", m_sAnimationContentWidget, level: LogLevel.ERROR);
185 return;
186 }
187
189
190 //use CallLater, it seems that Call() might not have a loop/repeat option
192 {
193 GetGame().GetCallqueue().CallLater(SetupValues, 0);
194 GetGame().GetCallqueue().CallLater(OnFrame, 0, true);
195 }
196 }
197
198 //------------------------------------------------------------------------------------------------
199 override void HandlerDeattached(Widget w)
200 {
201 if (GetGame() && GetGame().GetCallqueue())
202 GetGame().GetCallqueue().Remove(OnFrame);
203 }
204
205 //------------------------------------------------------------------------------------------------
206 protected void OnFrame()
207 {
208 float tDelta = ftime * 0.001;
209
210 switch (m_eState)
211 {
213 // Doing nothing
214 break;
215
216 case SCR_EScrollAnimationState.MOVING_LEFT:
217 {
219 {
220 m_eState = SCR_EScrollAnimationState.MOVING_LEFT_DONE_WAITING;
222 }
223
224 break;
225 }
226
227 case SCR_EScrollAnimationState.MOVING_LEFT_DONE_WAITING:
228 {
229 m_fTimer -= tDelta;
230 if (m_fTimer < 0)
231 {
232 if (m_bAnimateBack)
233 {
234 m_eState = SCR_EScrollAnimationState.MOVING_RIGHT;
235 }
236 else
237 {
240 m_eState = SCR_EScrollAnimationState.MOVING_RIGHT_DONE_WAITING;
241 }
242 }
243
244 break;
245 }
246
247 case SCR_EScrollAnimationState.MOVING_RIGHT:
248 {
249 WorkspaceWidget workspace = GetGame().GetWorkspace();
251 {
252 m_eState = SCR_EScrollAnimationState.MOVING_RIGHT_DONE_WAITING;
254 }
255
256 break;
257 }
258
259 case SCR_EScrollAnimationState.MOVING_RIGHT_DONE_WAITING:
260 {
261 m_fTimer -= tDelta;
262 if (m_fTimer < 0)
263 {
265 }
266
267 break;
268 }
269
270 case SCR_EScrollAnimationState.MOVING_TOP:
271 {
273 {
274 m_eState = SCR_EScrollAnimationState.MOVING_TOP_DONE_WAITING;
276 }
277
278 break;
279 }
280
281 case SCR_EScrollAnimationState.MOVING_TOP_DONE_WAITING:
282 {
283 m_fTimer -= tDelta;
284 if (m_fTimer < 0)
285 {
286 if (m_bAnimateBack)
287 {
288 m_eState = SCR_EScrollAnimationState.MOVING_BOTTOM;
289 }
290 else
291 {
294 m_eState = SCR_EScrollAnimationState.MOVING_BOTTOM_DONE_WAITING;
295 }
296 }
297
298 break;
299 }
300
301 case SCR_EScrollAnimationState.MOVING_BOTTOM:
302 {
303 WorkspaceWidget workspace = GetGame().GetWorkspace();
304 if (AnimateVerticalPosition(tDelta, -m_fAnimationSpeedPxPerSec, workspace.DPIScale(m_fOffsetRight)))
305 {
306 m_eState = SCR_EScrollAnimationState.MOVING_BOTTOM_DONE_WAITING;
308 }
309
310 break;
311 }
312
313 case SCR_EScrollAnimationState.MOVING_BOTTOM_DONE_WAITING:
314 {
315 m_fTimer -= tDelta;
316 if (m_fTimer < 0)
317 {
319 }
320
321 break;
322 }
323 }
324 }
325
326 //------------------------------------------------------------------------------------------------
327 protected bool AnimateHorizontalPosition(float tDelta, float speed, float target)
328 {
329 float currentPos = FrameSlot.GetPosX(m_wContent);
330 float newPos = currentPos + tDelta * speed;
331
332 if ((currentPos - target) * (newPos - target) <= 0)
333 {
334 FrameSlot.SetPosX(m_wContent, target);
335 return true; // reached destination !
336 }
337 else
338 {
339 FrameSlot.SetPosX(m_wContent, newPos);
340 return false;
341 }
342
343 return false;
344 }
345
346 //------------------------------------------------------------------------------------------------
347 protected bool AnimateVerticalPosition(float tDelta, float speed, float target)
348 {
349 float currentPos = FrameSlot.GetPosY(m_wContent);
350 float newPos = currentPos + tDelta * speed;
351
352 if ((currentPos - target) * (newPos - target) <= 0)
353 {
354 FrameSlot.SetPosY(m_wContent, target);
355 return true; // reached destination !
356 }
357 else
358 {
359 FrameSlot.SetPosY(m_wContent, newPos);
360 return false;
361 }
362 }
363
364 //------------------------------------------------------------------------------------------------
365 static SCR_HorizontalScrollAnimationComponent FindComponent(notnull Widget w)
366 {
367 return SCR_HorizontalScrollAnimationComponent.Cast(w.FindHandler(SCR_HorizontalScrollAnimationComponent));
368 }
369}
ArmaReforgerScripted GetGame()
Definition game.c:1398
EAITargetClusterState m_eState
ScriptCallQueue GetCallqueue()
Returns CallQueue of this AI. It gets updated from EvaluateBehavior, so that it's synchronous with ot...
SCR_CampaignSeizingComponent SCR_SeizingComponent EnumLinear()] enum SCR_EBaseCaptureState
Widget m_wRoot
SCR_EScrollAnimationState m_eInitialState
void AnimationStart(bool IsVerticalAnimation=false)
bool AnimateVerticalPosition(float tDelta, float speed, float target)
void ResetPosition()
Sets X position to its initial value when component was initialized.
bool GetContentFitY()
Returns true when content fits the parent widget.
bool GetContentFitX()
Returns true when content fits the parent widget.
bool AnimateHorizontalPosition(float tDelta, float speed, float target)
override void HandlerAttached(Widget w)
override void HandlerDeattached(Widget w)
override void OnFrame(IEntity owner, float timeSlice)
LogLevel
Enum with severity of the logging message.
Definition LogLevel.c:14
proto void PrintFormat(string fmt, void param1=NULL, void param2=NULL, void param3=NULL, void param4=NULL, void param5=NULL, void param6=NULL, void param7=NULL, void param8=NULL, void param9=NULL, LogLevel level=LogLevel.NORMAL)
@ NONE
When Shape is created and not initialized yet.
Definition ShapeType.c:15
SCR_FieldOfViewSettings Attribute