Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_ImageFrameAnimationComponent.c
Go to the documentation of this file.
1
8{
9 // Attributes
10
11 [Attribute("30", UIWidgets.EditBox, "Animation frames per second")]
12 protected float m_fFramesPerSecond;
13
14 [Attribute("1", UIWidgets.EditBox, "Number of frames")]
15 protected int m_iNumFrames;
16
17 [Attribute("0", UIWidgets.EditBox, "Start frame of an animation")]
18 protected int m_iStartFrameId;
19
20 [Attribute("Frame_%1", UIWidgets.EditBox, "Format for image name withim imageset")]
21 protected string m_sImageNameFormat;
22
23 [Attribute("-1", UIWidgets.EditBox, "Length of integer conversion of frame Id to string. See int.ToString().")]
24 protected int m_iIntToStringLen;
25
26 [Attribute("", UIWidgets.ResourceNamePicker, "Image Set with frames", params: "imageset")]
28
29 // Internal
30
31 protected float m_fCounterMs;
32 protected float m_fMsPerFrame; // Milliseconds per frame
33 protected int m_iFrameId;
34
36
37 //------------------------------------------------------------------------------------------------
39
40 // You can Start/Stop animation, but most likely it's not needed,
41 // Because it will terminate itself when widget is hidden,
42 // And it will get reactivated when widget is shown again.
43
44 //------------------------------------------------------------------------------------------------
46 void Start()
47 {
48 if (!m_wRoot)
49 return;
50
53
54 ScriptCallQueue queue = GetGame().GetCallqueue();
55 queue.Remove(OnEachFrame);
56 queue.CallLater(OnEachFrame, 0, true);
57 }
58
59 //------------------------------------------------------------------------------------------------
61 void Stop()
62 {
63 GetGame().GetCallqueue().Remove(OnEachFrame);
64 }
65
66 //------------------------------------------------------------------------------------------------
67 override protected void HandlerAttached(Widget w)
68 {
69 m_wRoot = ImageWidget.Cast(w);
70
71 if (!m_wRoot)
72 {
73 Print("SCR_ImageFrameAnimationComponent must be attached to image widget!", LogLevel.ERROR);
74 return;
75 }
76
77 // Ensure safe value for input data
78 if (m_fFramesPerSecond <= 0.0)
79 {
80 Print("SCR_ImageFrameAnimationComponent: wrong m_fFramesPerSecond value", LogLevel.ERROR);
82 }
83 if (m_iNumFrames <= 0)
84 {
85 Print("SCR_ImageFrameAnimationComponent: wrong m_iNumFrames value", LogLevel.ERROR);
86 m_iNumFrames = 1;
87 }
88 if (m_iStartFrameId < 0)
89 {
90 Print("SCR_ImageFrameAnimationComponent: wrong m_iStartFrameId value", LogLevel.ERROR);
92 }
93
94 // Calculate run time constants
95 m_fMsPerFrame = Math.Round(1000.0 / m_fFramesPerSecond);
97
98 if (w.IsVisible())
99 Start();
100 }
101
102 //------------------------------------------------------------------------------------------------
103 override protected void HandlerDeattached(Widget w)
104 {
105 ArmaReforgerScripted game = GetGame();
106 if (game && game.GetCallqueue())
107 Stop();
108 }
109
110 //------------------------------------------------------------------------------------------------
111 protected void OnEachFrame()
112 {
113 if (!m_wRoot.IsVisibleInHierarchy())
114 {
115 Stop();
116 return;
117 }
118
119 // Increase counter until we have accumulated m_fMsPerFrame time
120 // Then skip some frames, at least one
121
122 m_fCounterMs += Math.Min(ftime, 200.0); // Limit ftime within reasonable value
123
124 float nFramesToSkip = Math.Ceil(m_fCounterMs / m_fMsPerFrame);
125
126 if (nFramesToSkip >= 1.0)
127 {
128 m_fCounterMs -= nFramesToSkip * m_fMsPerFrame;
129 m_iFrameId += nFramesToSkip;
131
133 }
134 }
135
136 //------------------------------------------------------------------------------------------------
137 protected void ShowFrame(int id)
138 {
139 string imageName = string.Format(m_sImageNameFormat, id.ToString(m_iIntToStringLen));
140 m_wRoot.LoadImageFromSet(0, m_sImageSet, imageName);
141 }
142
143 //------------------------------------------------------------------------------------------------
144 override bool OnUpdate(Widget w)
145 {
146 if (w != m_wRoot || !m_wRoot)
147 return true;
148
149 bool nowVisible = m_wRoot.IsVisibleInHierarchy();
150
151 if (nowVisible)
152 Start();
153 else
154 Stop();
155
156 return true;
157 }
158}
ref DSGameConfig game
Definition DSConfig.c:81
ArmaReforgerScripted GetGame()
Definition game.c:1398
Definition Math.c:13
ScriptCallQueue Class provide "lazy" calls - when we don't want to execute function immediately but l...
Definition tools.c:53
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
LogLevel
Enum with severity of the logging message.
Definition LogLevel.c:14
SCR_FieldOfViewSettings Attribute
proto external string ToString()
Plain C++ pointer, no weak pointers, no memory management.