4 protected string m_sFadeWidgetName;
7 protected float m_fFadeInOpacitytarget;
10 protected float m_fFadeInAnimationSpeed;
13 protected float m_fFadeOutAnimationSpeed;
15 [
Attribute(
"0",
desc:
"Fades the widget in on handler attached")]
16 protected bool m_bAutoFadeIn;
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;
21 protected Widget m_wFadeWidget;
23 [
Attribute(
"",
"UI Sfx is played when on fade in starts. Leave empty to play no SFX")]
24 protected string m_sOnFadeInSfx;
26 [
Attribute(
"0",
desc:
"Will terminate any other Sfx if true and played")]
27 protected bool m_bFadeInSfxHasPriority;
29 [
Attribute(
"",
"UI Sfx is played when on fade out starts. Leave empty to play no SFX")]
30 protected string m_sOnFadeOutSfx;
32 [
Attribute(
"0",
desc:
"Will terminate any other Sfx if true and played")]
33 protected bool m_bFadeOutSfxHasPriority;
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;
42 protected ref ScriptInvoker Event_OnFadeDone;
47 void FadeIn(
bool setOpacityZero =
true)
49 m_bIsWaitingForDelayedFadeIn =
false;
54 if (!setOpacityZero && m_bIsFading && m_bIsFadingIn)
57 m_bCheckingForFadeOutDestroy =
false;
60 m_wFadeWidget.SetOpacity(0);
62 AnimateWidget.Opacity(m_wFadeWidget, m_fFadeInOpacitytarget, m_fFadeInAnimationSpeed,
true);
64 if (!m_sOnFadeInSfx.IsEmpty())
67 StartListenToFadeDone(
true);
74 void DelayedFadeIn(
int delay,
bool setOpacityZero =
true)
79 m_bCheckingForFadeOutDestroy =
false;
82 m_wFadeWidget.SetOpacity(0);
84 m_bIsWaitingForDelayedFadeIn =
true;
85 GetGame().GetCallqueue().CallLater(FadeIn, delay,
false,
false);
91 void FadeOut(
bool destroyOnFadeOut)
93 m_bIsWaitingForDelayedFadeOut =
false;
98 m_bCheckingForFadeOutDestroy = destroyOnFadeOut;
100 if (m_bIsFading && !m_bIsFadingIn)
103 AnimateWidget.StopAllAnimations(m_wFadeWidget);
104 AnimateWidget.Opacity(m_wFadeWidget, 0, m_fFadeOutAnimationSpeed,
true);
106 if (!m_sOnFadeOutSfx.IsEmpty())
109 StartListenToFadeDone(
false);
117 void DelayedFadeOut(
int delay,
bool destroyOnFadeOut,
bool setOpacityTofadeInTarget =
true)
122 if (setOpacityTofadeInTarget)
123 m_wFadeWidget.SetOpacity(m_fFadeInOpacitytarget);
125 m_bIsWaitingForDelayedFadeOut =
true;
126 GetGame().GetCallqueue().CallLater(FadeOut, delay,
false, destroyOnFadeOut);
132 void CancelFade(
bool callFadeDone)
134 if (m_bIsWaitingForDelayedFadeIn)
135 GetGame().GetCallqueue().Remove(FadeIn);
137 if (m_bIsWaitingForDelayedFadeOut)
138 GetGame().GetCallqueue().Remove(FadeOut);
146 GetGame().GetCallqueue().Remove(FadeDoneCheck);
150 m_wFadeWidget.SetOpacity(m_fFadeInOpacitytarget);
151 else if (!m_bIsFadingIn)
152 m_wFadeWidget.SetOpacity(0);
154 AnimateWidget.StopAllAnimations(m_wFadeWidget);
160 void SetFadeInSpeed(
float fadeInSpeed)
162 m_fFadeInAnimationSpeed = fadeInSpeed;
168 Widget GetFadeWidget()
170 return m_wFadeWidget;
184 return m_bIsFadingIn && IsFading();
191 return !m_bIsFadingIn && IsFading();
196 float GetTargetFadeInOpacity()
198 return m_fFadeInOpacitytarget;
204 ScriptInvoker GetOnFadeDone()
206 if (!Event_OnFadeDone)
207 Event_OnFadeDone =
new ScriptInvoker();
209 return Event_OnFadeDone;
213 protected void StartListenToFadeDone(
bool isFadeIn)
215 m_bIsFadingIn = isFadeIn;
220 GetGame().GetCallqueue().CallLater(FadeDoneCheck, m_bFadeDoneUpdateSpeed * 1000,
true);
225 protected void FadeDoneCheck()
227 if (AnimateWidget.IsAnimating(m_wFadeWidget))
230 if (m_bIsFadingIn && m_wFadeWidget.GetOpacity() != m_fFadeInOpacitytarget)
232 else if (!m_bIsFadingIn && m_wFadeWidget.GetOpacity() != 0)
235 if (Event_OnFadeDone)
236 Event_OnFadeDone.Invoke(
this, m_bIsFadingIn);
239 GetGame().GetCallqueue().Remove(FadeDoneCheck);
243 if (m_bCheckingForFadeOutDestroy)
244 m_wFadeWidget.RemoveFromHierarchy();
246 m_wFadeWidget.SetVisible(
false);
251 override void HandlerAttached(Widget w)
256 if (m_sFadeWidgetName.IsEmpty())
259 m_wFadeWidget = w.FindAnyWidget(m_sFadeWidgetName);
263 Print(
string.Format(
"'SCR_FadeUIComponent' could not find widget '%1'", m_sFadeWidgetName), LogLevel.ERROR);
272 override void HandlerDeattached(Widget w)
275 GetGame().GetCallqueue().Remove(FadeDoneCheck);