11 [
Attribute(
"30", UIWidgets.EditBox,
"Animation frames per second")]
12 protected float m_fFramesPerSecond;
14 [
Attribute(
"1", UIWidgets.EditBox,
"Number of frames")]
15 protected int m_iNumFrames;
17 [
Attribute(
"0", UIWidgets.EditBox,
"Start frame of an animation")]
18 protected int m_iStartFrameId;
20 [
Attribute(
"Frame_%1", UIWidgets.EditBox,
"Format for image name withim imageset")]
21 protected string m_sImageNameFormat;
23 [
Attribute(
"-1", UIWidgets.EditBox,
"Length of integer conversion of frame Id to string. See int.ToString().")]
24 protected int m_iIntToStringLen;
26 [
Attribute(
"", UIWidgets.ResourceNamePicker,
"Image Set with frames",
params:
"imageset")]
27 protected ResourceName m_sImageSet;
31 protected float m_fCounterMs;
32 protected float m_fMsPerFrame;
33 protected int m_iFrameId;
35 protected ImageWidget m_wRoot;
51 m_iFrameId = m_iStartFrameId;
52 ShowFrame(m_iStartFrameId);
54 ScriptCallQueue queue =
GetGame().GetCallqueue();
55 queue.Remove(OnEachFrame);
56 queue.CallLater(OnEachFrame, 0,
true);
63 GetGame().GetCallqueue().Remove(OnEachFrame);
67 override protected void HandlerAttached(Widget w)
73 Print(
"SCR_ImageFrameAnimationComponent must be attached to image widget!", LogLevel.ERROR);
78 if (m_fFramesPerSecond <= 0.0)
80 Print(
"SCR_ImageFrameAnimationComponent: wrong m_fFramesPerSecond value", LogLevel.ERROR);
81 m_fFramesPerSecond = 1;
83 if (m_iNumFrames <= 0)
85 Print(
"SCR_ImageFrameAnimationComponent: wrong m_iNumFrames value", LogLevel.ERROR);
88 if (m_iStartFrameId < 0)
90 Print(
"SCR_ImageFrameAnimationComponent: wrong m_iStartFrameId value", LogLevel.ERROR);
95 m_fMsPerFrame = Math.Round(1000.0 / m_fFramesPerSecond);
96 m_fMsPerFrame = Math.Max(1.0, m_fMsPerFrame);
103 override protected void HandlerDeattached(Widget w)
105 ArmaReforgerScripted game =
GetGame();
106 if (game && game.GetCallqueue())
111 protected void OnEachFrame()
113 if (!
m_wRoot.IsVisibleInHierarchy())
122 m_fCounterMs += Math.Min(ftime, 200.0);
124 float nFramesToSkip = Math.Ceil(m_fCounterMs / m_fMsPerFrame);
126 if (nFramesToSkip >= 1.0)
128 m_fCounterMs -= nFramesToSkip * m_fMsPerFrame;
129 m_iFrameId += nFramesToSkip;
130 m_iFrameId = m_iFrameId % m_iNumFrames;
132 ShowFrame(m_iFrameId);
137 protected void ShowFrame(
int id)
139 string imageName =
string.Format(m_sImageNameFormat,
id.ToString(m_iIntToStringLen));
140 m_wRoot.LoadImageFromSet(0, m_sImageSet, imageName);
144 override bool OnUpdate(Widget w)
146 if (w != m_wRoot || !m_wRoot)
149 bool nowVisible =
m_wRoot.IsVisibleInHierarchy();