Arma Reforger Explorer
1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Toggle main menu visibility
Loading...
Searching...
No Matches
SCR_ImageFrameAnimationComponent.c
Go to the documentation of this file.
1
7
class
SCR_ImageFrameAnimationComponent
:
ScriptedWidgetComponent
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"
)]
27
protected
ResourceName
m_sImageSet
;
28
29
// Internal
30
31
protected
float
m_fCounterMs
;
32
protected
float
m_fMsPerFrame
;
// Milliseconds per frame
33
protected
int
m_iFrameId
;
34
35
protected
ImageWidget
m_wRoot
;
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
51
m_iFrameId
=
m_iStartFrameId
;
52
ShowFrame
(
m_iStartFrameId
);
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);
81
m_fFramesPerSecond
= 1;
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);
91
m_iStartFrameId
= 0;
92
}
93
94
// Calculate run time constants
95
m_fMsPerFrame
=
Math
.Round(1000.0 /
m_fFramesPerSecond
);
96
m_fMsPerFrame
=
Math
.Max(1.0,
m_fMsPerFrame
);
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;
130
m_iFrameId
=
m_iFrameId
%
m_iNumFrames
;
131
132
ShowFrame
(
m_iFrameId
);
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
}
game
ref DSGameConfig game
Definition
DSConfig.c:81
GetGame
ArmaReforgerScripted GetGame()
Definition
game.c:1398
params
category params
Definition
SCR_SpherePointGeneratorPreviewComponent.c:21
ImageWidget
Definition
ImageWidget.c:13
Math
Definition
Math.c:13
ResourceName
Definition
ResourceName.c:13
SCR_ImageFrameAnimationComponent
Definition
SCR_ImageFrameAnimationComponent.c:8
SCR_ImageFrameAnimationComponent::Stop
void Stop()
Definition
SCR_ImageFrameAnimationComponent.c:61
SCR_ImageFrameAnimationComponent::m_iFrameId
int m_iFrameId
Definition
SCR_ImageFrameAnimationComponent.c:33
SCR_ImageFrameAnimationComponent::m_sImageSet
ResourceName m_sImageSet
Definition
SCR_ImageFrameAnimationComponent.c:27
SCR_ImageFrameAnimationComponent::OnEachFrame
void OnEachFrame()
Definition
SCR_ImageFrameAnimationComponent.c:111
SCR_ImageFrameAnimationComponent::ShowFrame
void ShowFrame(int id)
Definition
SCR_ImageFrameAnimationComponent.c:137
SCR_ImageFrameAnimationComponent::m_iStartFrameId
int m_iStartFrameId
Definition
SCR_ImageFrameAnimationComponent.c:18
SCR_ImageFrameAnimationComponent::m_iIntToStringLen
int m_iIntToStringLen
Definition
SCR_ImageFrameAnimationComponent.c:24
SCR_ImageFrameAnimationComponent::m_wRoot
ImageWidget m_wRoot
Definition
SCR_ImageFrameAnimationComponent.c:35
SCR_ImageFrameAnimationComponent::m_fCounterMs
float m_fCounterMs
Definition
SCR_ImageFrameAnimationComponent.c:31
SCR_ImageFrameAnimationComponent::m_iNumFrames
int m_iNumFrames
Definition
SCR_ImageFrameAnimationComponent.c:15
SCR_ImageFrameAnimationComponent::OnUpdate
override bool OnUpdate(Widget w)
Definition
SCR_ImageFrameAnimationComponent.c:144
SCR_ImageFrameAnimationComponent::HandlerAttached
void HandlerAttached(Widget w)
Definition
SCR_ImageFrameAnimationComponent.c:67
SCR_ImageFrameAnimationComponent::m_fFramesPerSecond
float m_fFramesPerSecond
Definition
SCR_ImageFrameAnimationComponent.c:12
SCR_ImageFrameAnimationComponent::m_fMsPerFrame
float m_fMsPerFrame
Definition
SCR_ImageFrameAnimationComponent.c:32
SCR_ImageFrameAnimationComponent::m_sImageNameFormat
string m_sImageNameFormat
Definition
SCR_ImageFrameAnimationComponent.c:21
SCR_ImageFrameAnimationComponent::HandlerDeattached
void HandlerDeattached(Widget w)
Definition
SCR_ImageFrameAnimationComponent.c:103
SCR_ImageFrameAnimationComponent::Start
void Start()
PUBLIC API.
Definition
SCR_ImageFrameAnimationComponent.c:46
ScriptCallQueue
ScriptCallQueue Class provide "lazy" calls - when we don't want to execute function immediately but l...
Definition
tools.c:53
ScriptedWidgetComponent
Definition
ScriptedWidgetComponent.c:13
UIWidgets
Definition
attributes.c:40
Widget
Definition
Widget.c:13
Print
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
LogLevel
LogLevel
Enum with severity of the logging message.
Definition
LogLevel.c:14
Attribute
SCR_FieldOfViewSettings Attribute
Definition
SendGoalMessage.c:170
ToString
proto external string ToString()
Plain C++ pointer, no weak pointers, no memory management.
scripts
Game
Components
SCR_ImageFrameAnimationComponent.c
Generated by
1.17.0