Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_FadeUIComponent.c
Go to the documentation of this file.
1 class SCR_FadeUIComponent : ScriptedWidgetComponent
2 {
3  [Attribute("", desc: "Leave empty if root is faded")]
4  protected string m_sFadeWidgetName;
5 
6  [Attribute("1", desc: "The Opacitity target of the widget on fade in", params: "0 1")]
7  protected float m_fFadeInOpacitytarget;
8 
9  [Attribute("2", params: "0 50")]
10  protected float m_fFadeInAnimationSpeed;
11 
12  [Attribute("2", params: "0 50")]
13  protected float m_fFadeOutAnimationSpeed;
14 
15  [Attribute("0", desc: "Fades the widget in on handler attached")]
16  protected bool m_bAutoFadeIn;
17 
18  [Attribute("0.1", desc: "In seconds, Delay between each call que to check if animation is done", params: "0 10")]
19  protected float m_bFadeDoneUpdateSpeed;
20 
21  protected Widget m_wFadeWidget;
22 
23  [Attribute("", "UI Sfx is played when on fade in starts. Leave empty to play no SFX")]
24  protected string m_sOnFadeInSfx;
25 
26  [Attribute("0", desc: "Will terminate any other Sfx if true and played")]
27  protected bool m_bFadeInSfxHasPriority;
28 
29  [Attribute("", "UI Sfx is played when on fade out starts. Leave empty to play no SFX")]
30  protected string m_sOnFadeOutSfx;
31 
32  [Attribute("0", desc: "Will terminate any other Sfx if true and played")]
33  protected bool m_bFadeOutSfxHasPriority;
34 
35  //state
36  protected bool m_bIsWaitingForDelayedFadeIn;
37  protected bool m_bIsWaitingForDelayedFadeOut;
38  protected bool m_bIsFading;
39  protected bool m_bIsFadingIn;
40  protected bool m_bCheckingForFadeOutDestroy = false;
41 
42  protected ref ScriptInvoker Event_OnFadeDone; //Var SCR_FadeUIComponent, Bool isFadeIn
43 
44  //------------------------------------------------------------------------------------------------
47  void FadeIn(bool setOpacityZero = true)
48  {
49  m_bIsWaitingForDelayedFadeIn = false;
50 
51  if (!m_wFadeWidget)
52  return;
53 
54  if (!setOpacityZero && m_bIsFading && m_bIsFadingIn)
55  return;
56 
57  m_bCheckingForFadeOutDestroy = false;
58 
59  if (setOpacityZero)
60  m_wFadeWidget.SetOpacity(0);
61 
62  AnimateWidget.Opacity(m_wFadeWidget, m_fFadeInOpacitytarget, m_fFadeInAnimationSpeed, true);
63 
64  if (!m_sOnFadeInSfx.IsEmpty())
65  SCR_UISoundEntity.SoundEvent(m_sOnFadeInSfx, m_bFadeInSfxHasPriority);
66 
67  StartListenToFadeDone(true);
68  }
69 
70  //------------------------------------------------------------------------------------------------
74  void DelayedFadeIn(int delay, bool setOpacityZero = true)
75  {
76  if (!m_wFadeWidget)
77  return;
78 
79  m_bCheckingForFadeOutDestroy = false;
80 
81  if (setOpacityZero)
82  m_wFadeWidget.SetOpacity(0);
83 
84  m_bIsWaitingForDelayedFadeIn = true;
85  GetGame().GetCallqueue().CallLater(FadeIn, delay, false, false);
86  }
87 
88  //------------------------------------------------------------------------------------------------
91  void FadeOut(bool destroyOnFadeOut)
92  {
93  m_bIsWaitingForDelayedFadeOut = false;
94 
95  if (!m_wFadeWidget)
96  return;
97 
98  m_bCheckingForFadeOutDestroy = destroyOnFadeOut;
99 
100  if (m_bIsFading && !m_bIsFadingIn)
101  return;
102 
103  AnimateWidget.StopAllAnimations(m_wFadeWidget);
104  AnimateWidget.Opacity(m_wFadeWidget, 0, m_fFadeOutAnimationSpeed, true);
105 
106  if (!m_sOnFadeOutSfx.IsEmpty())
107  SCR_UISoundEntity.SoundEvent(m_sOnFadeOutSfx, m_bFadeOutSfxHasPriority);
108 
109  StartListenToFadeDone(false);
110  }
111 
112  //------------------------------------------------------------------------------------------------
117  void DelayedFadeOut(int delay, bool destroyOnFadeOut, bool setOpacityTofadeInTarget = true)
118  {
119  if (!m_wFadeWidget)
120  return;
121 
122  if (setOpacityTofadeInTarget)
123  m_wFadeWidget.SetOpacity(m_fFadeInOpacitytarget);
124 
125  m_bIsWaitingForDelayedFadeOut = true;
126  GetGame().GetCallqueue().CallLater(FadeOut, delay, false, destroyOnFadeOut);
127  }
128 
129  //------------------------------------------------------------------------------------------------
132  void CancelFade(bool callFadeDone)
133  {
134  if (m_bIsWaitingForDelayedFadeIn)
135  GetGame().GetCallqueue().Remove(FadeIn);
136 
137  if (m_bIsWaitingForDelayedFadeOut)
138  GetGame().GetCallqueue().Remove(FadeOut);
139 
140  if (!m_bIsFading)
141  return;
142 
143  if (!callFadeDone)
144  {
145  m_bIsFading = false;
146  GetGame().GetCallqueue().Remove(FadeDoneCheck);
147  }
148 
149  if (m_bIsFadingIn)
150  m_wFadeWidget.SetOpacity(m_fFadeInOpacitytarget);
151  else if (!m_bIsFadingIn)
152  m_wFadeWidget.SetOpacity(0);
153 
154  AnimateWidget.StopAllAnimations(m_wFadeWidget);
155  }
156 
157  //------------------------------------------------------------------------------------------------
160  void SetFadeInSpeed(float fadeInSpeed)
161  {
162  m_fFadeInAnimationSpeed = fadeInSpeed;
163  }
164 
165  //------------------------------------------------------------------------------------------------
168  Widget GetFadeWidget()
169  {
170  return m_wFadeWidget;
171  }
172 
173  //------------------------------------------------------------------------------------------------
175  bool IsFading()
176  {
177  return m_bIsFading;
178  }
179 
180  //------------------------------------------------------------------------------------------------
182  bool IsFadingIn()
183  {
184  return m_bIsFadingIn && IsFading();
185  }
186 
187  //------------------------------------------------------------------------------------------------
189  bool IsFadingOut()
190  {
191  return !m_bIsFadingIn && IsFading();
192  }
193 
194  //------------------------------------------------------------------------------------------------
196  float GetTargetFadeInOpacity()
197  {
198  return m_fFadeInOpacitytarget;
199  }
200 
201  //------------------------------------------------------------------------------------------------
204  ScriptInvoker GetOnFadeDone()
205  {
206  if (!Event_OnFadeDone)
207  Event_OnFadeDone = new ScriptInvoker();
208 
209  return Event_OnFadeDone;
210  }
211 
212  //------------------------------------------------------------------------------------------------
213  protected void StartListenToFadeDone(bool isFadeIn)
214  {
215  m_bIsFadingIn = isFadeIn;
216 
217  if (!m_bIsFading)
218  {
219  m_bIsFading = true;
220  GetGame().GetCallqueue().CallLater(FadeDoneCheck, m_bFadeDoneUpdateSpeed * 1000, true);
221  }
222  }
223 
224  //------------------------------------------------------------------------------------------------
225  protected void FadeDoneCheck()
226  {
227  if (AnimateWidget.IsAnimating(m_wFadeWidget))
228  return;
229 
230  if (m_bIsFadingIn && m_wFadeWidget.GetOpacity() != m_fFadeInOpacitytarget)
231  return;
232  else if (!m_bIsFadingIn && m_wFadeWidget.GetOpacity() != 0)
233  return;
234 
235  if (Event_OnFadeDone)
236  Event_OnFadeDone.Invoke(this, m_bIsFadingIn);
237 
238  m_bIsFading = false;
239  GetGame().GetCallqueue().Remove(FadeDoneCheck);
240 
241  if (!m_bIsFadingIn)
242  {
243  if (m_bCheckingForFadeOutDestroy)
244  m_wFadeWidget.RemoveFromHierarchy();
245  else
246  m_wFadeWidget.SetVisible(false);
247  }
248  }
249 
250  //------------------------------------------------------------------------------------------------
251  override void HandlerAttached(Widget w)
252  {
253  if (SCR_Global.IsEditMode())
254  return;
255 
256  if (m_sFadeWidgetName.IsEmpty())
257  m_wFadeWidget = w;
258  else
259  m_wFadeWidget = w.FindAnyWidget(m_sFadeWidgetName);
260 
261  if (!m_wFadeWidget)
262  {
263  Print(string.Format("'SCR_FadeUIComponent' could not find widget '%1'", m_sFadeWidgetName), LogLevel.ERROR);
264  return;
265  }
266 
267  if (m_bAutoFadeIn)
268  FadeIn();
269  }
270 
271  //------------------------------------------------------------------------------------------------
272  override void HandlerDeattached(Widget w)
273  {
274  if (m_bIsFading && GetGame())
275  GetGame().GetCallqueue().Remove(FadeDoneCheck);
276  }
277 }
SCR_FadeUIComponent
Definition: SCR_FadeUIComponent.c:1
SCR_UISoundEntity
Definition: SCR_UISoundEntity.c:7
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
Attribute
typedef Attribute
Post-process effect of scripted camera.
SCR_Global
Definition: Functions.c:6
params
Configs ServerBrowser KickDialogs params
Definition: SCR_NotificationSenderComponent.c:24