Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_FadeInOutAnimator.c
Go to the documentation of this file.
1 
9 {
10  // Member variables
11  protected Widget m_Widget;
12  protected int m_iState;
13  protected int m_iFormerState
14  protected float m_fFadeOutWaitTime;
15  protected float m_fFadeInSpeed;
16  protected float m_fFadeOutSpeed;
17  protected bool m_bForceVisible;
18  protected float m_fTimer;
19  protected bool m_bFadeOutSetVisibleFalse; // When fade out is done, widget will be SetVisible(false)
20  protected bool m_bAutoFadeOut; // Should it fade out after the 'fadeOutWaitTime' or not (default: true)
21 
22  // States
23  const int STATE_FADE_IN = 0;
24  const int STATE_FADE_OUT_WAIT = 1;
25  const int STATE_FADE_OUT = 2;
26  const int STATE_FADING_DONE = 3;
27 
28  //invokers
29  ref ScriptInvoker<int, int> m_OnStateChanged;
30 
31  //-----------------------------------------------------
32  void SCR_FadeInOutAnimator(Widget w, float fadeInSpeed, float fadeOutSpeed, float fadeOutWaitTime, bool fadeOutSetVisibleFalse = false)
33  {
34  m_Widget = w;
35  m_fFadeOutSpeed = fadeOutSpeed;
36  m_fFadeInSpeed = fadeInSpeed;
37  m_fFadeOutWaitTime = fadeOutWaitTime;
38  m_bFadeOutSetVisibleFalse = fadeOutSetVisibleFalse;
39  m_bAutoFadeOut = true;
40 
41  m_iState = STATE_FADE_OUT_WAIT;
42  m_bForceVisible = false;
43  }
44 
45  //-----------------------------------------------------
46  void Update(float timeSlice)
47  {
48  switch (m_iState)
49  {
50  case STATE_FADING_DONE:
51 
52  if (m_bForceVisible && m_Widget.GetOpacity() < 1)
53  {
54  m_iState = STATE_FADE_IN;
55  if (m_OnStateChanged)
56  m_OnStateChanged.Invoke(STATE_FADING_DONE, m_iState);
57  }
58 
59  break;
60 
61  case STATE_FADE_IN:
62 
63  float opacity = Math.Clamp(m_Widget.GetOpacity() + timeSlice * m_fFadeInSpeed, 0 ,1);
64  m_Widget.SetOpacity(opacity);
65  m_Widget.SetVisible(true);
66 
67  if (opacity >= 1)
68  {
69  if (m_bAutoFadeOut)
70  {
71  m_fTimer = m_fFadeOutWaitTime;
72  m_iState = STATE_FADE_OUT_WAIT;
73  if (m_OnStateChanged)
74  m_OnStateChanged.Invoke(STATE_FADE_IN, m_iState);
75  }
76  else
77  {
78  m_iState = STATE_FADING_DONE;
79  if (m_OnStateChanged)
80  m_OnStateChanged.Invoke(STATE_FADE_IN, m_iState);
81  }
82  }
83 
84  break;
85 
86  case STATE_FADE_OUT_WAIT:
87 
88  if (m_bForceVisible)
89  {
90  m_fTimer = m_fFadeOutWaitTime;
91  }
92  else
93  {
94  m_fTimer -= timeSlice;
95 
96  if (m_fTimer <= 0)
97  {
98  m_iState = STATE_FADE_OUT;
99  if (m_OnStateChanged)
100  m_OnStateChanged.Invoke(STATE_FADE_OUT_WAIT, m_iState);
101  }
102  }
103  break;
104 
105  case STATE_FADE_OUT:
106 
107  if (m_bForceVisible)
108  {
109  m_iState = STATE_FADE_IN;
110  if (m_OnStateChanged)
111  m_OnStateChanged.Invoke(STATE_FADE_OUT, m_iState);
112  }
113  else
114  {
115  float opacity = Math.Clamp(m_Widget.GetOpacity() - m_fFadeOutSpeed*timeSlice, 0, 1);
116  m_Widget.SetOpacity(opacity);
117 
118  if (opacity <= 0)
119  {
120  if (m_bFadeOutSetVisibleFalse)
121  m_Widget.SetVisible(false);
122 
123  m_iState = STATE_FADING_DONE;
124  if (m_OnStateChanged)
125  m_OnStateChanged.Invoke(STATE_FADE_OUT, m_iState);
126  }
127  }
128  break;
129  }
130  }
131 
132  //-----------------------------------------------------
133  void FadeIn(bool fadeOut = true)
134  {
135  m_bAutoFadeOut = fadeOut;
136  m_iFormerState = m_iState;
137  m_iState = STATE_FADE_IN;
138  if (m_OnStateChanged)
139  m_OnStateChanged.Invoke(m_iFormerState, m_iState);
140  }
141 
142  //-----------------------------------------------------
143  void FadeOut()
144  {
145  m_iFormerState = m_iState;
146  m_iState = STATE_FADE_OUT;
147  if (m_OnStateChanged)
148  m_OnStateChanged.Invoke(m_iFormerState, m_iState);
149  }
150 
151  //-----------------------------------------------------
152  void FadeOutInstantly()
153  {
154  m_Widget.SetOpacity(0);
155  m_iFormerState = m_iState;
156  m_iState = STATE_FADE_OUT;
157  if (m_OnStateChanged)
158  m_OnStateChanged.Invoke(m_iFormerState, m_iState);
159  Update(0);
160  }
161 
162  //-----------------------------------------------------
163  void ForceVisible(bool force)
164  {
165  m_bForceVisible = force;
166  }
167 
168  //-----------------------------------------------------
170  int GetState()
171  {
172  return m_iState;
173  }
174 
175  //-----------------------------------------------------
177  bool IsRunning()
178  {
179  return m_iState != STATE_FADING_DONE;
180  }
181 
182  ScriptInvoker GetOnStateChanged()
183  {
184  if (!m_OnStateChanged)
185  m_OnStateChanged = ScriptInvoker();
186  return m_OnStateChanged;
187  }
188 };
m_fTimer
protected float m_fTimer
Definition: SCR_CampaignMilitaryBaseComponent.c:94
SCR_FadeInOutAnimator
Definition: SCR_FadeInOutAnimator.c:8
m_fFadeInSpeed
protected float m_fFadeInSpeed
Definition: SCR_TooltipManagerEditorUIComponent.c:11