Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_DrowningScreenEffect.c
Go to the documentation of this file.
2 {
3  // Play Animation of drowningVignette
4  protected const float DROWNINGEFFECT_OPACITY_FADEOUT_1_DURATION = 0.2;
5  protected const float DROWNINGEFFECT_PROGRESSION_FADEOUT_1_DURATION = 0.2;
6 
7  // Fade out animation of drowningVignette
8  protected const float DROWNINGEFFECT_OPACITY_FADEIN_1_DURATION = 1;
9  protected const float DROWNINGEFFECT_PROGRESSION_FADEIN_1_DURATION = 4.5;
10 
11  // Play Animation of BlackoutEffect()
12  protected const float BLACKOUT_OPACITY_MULTIPLIER = 0.70;
13 
14  // Widgets
15  protected ImageWidget m_wDrowningEffect;
16  protected ImageWidget m_wBlackOut;
17 
18  // Character
19  protected ChimeraCharacter m_pCharacterEntity;
20 
21 
22  //------------------------------------------------------------------------------------------------
23  override void DisplayStartDraw(IEntity owner)
24  {
25  m_wDrowningEffect = ImageWidget.Cast(m_wRoot.FindAnyWidget("DrowningVignette"));
26  m_wBlackOut = ImageWidget.Cast(m_wRoot.FindAnyWidget("BlackOut"));
27  }
28 
29  //------------------------------------------------------------------------------------------------
30  override void DisplayControlledEntityChanged(IEntity from, IEntity to)
31  {
32  ClearEffects();
33  RemoveInvokers(from);
34 
35  m_pCharacterEntity = ChimeraCharacter.Cast(to);
36  if (!m_pCharacterEntity)
37  return;
38 
39  SCR_CharacterControllerComponent m_CharController = SCR_CharacterControllerComponent.Cast(m_pCharacterEntity.GetCharacterController());
40  if (!m_CharController)
41  return;
42 
43  if (m_CharController.m_OnPlayerDrowning)
44  m_CharController.m_OnPlayerDrowning.Insert(CreateEffect);
45  if (m_CharController.m_OnPlayerStopDrowning)
46  m_CharController.m_OnPlayerStopDrowning.Insert(ClearEffect);
47 
48  SCR_CharacterDamageManagerComponent damageMan = SCR_CharacterDamageManagerComponent.Cast(m_pCharacterEntity.GetDamageManager());
49  if (damageMan)
50  damageMan.GetOnDamageStateChanged().Insert(OnDeath);
51 
52  // In case player started drowning before invokers were established, check if already drowning
53  if (m_CharController.IsCharacterDrowning())
54  CreateEffect(10, 4);
55  }
56 
57  //------------------------------------------------------------------------------------------------
58  void CreateEffect(float maxDrowningDuration, float drowningTimeStartFX)
59  {
60  if (!m_wDrowningEffect)
61  return;
62 
63  float effectStrength = 1;
64 
65  // Add a couple seconds to drowningDuration so the widget still animates when death occurs
66  float drowningDuration = (maxDrowningDuration - drowningTimeStartFX) + 2;
67  if (drowningDuration <= 0)
68  drowningDuration = 1;
69 
70  m_wDrowningEffect.SetSaturation(1);
71  m_wDrowningEffect.SetMaskTransitionWidth(0.8);
72 
73  AnimateWidget.Opacity(m_wDrowningEffect, effectStrength, 1 / drowningDuration);
74  AnimateWidget.AlphaMask(m_wDrowningEffect, effectStrength * 0.6, 1 / drowningDuration);
75 
76  BlackoutEffect(effectStrength, drowningDuration);
77  }
78 
79  //------------------------------------------------------------------------------------------------
80  void ClearEffect()
81  {
82  AnimateWidget.Opacity(m_wDrowningEffect, 0, DROWNINGEFFECT_PROGRESSION_FADEOUT_1_DURATION);
83  AnimateWidget.AlphaMask(m_wDrowningEffect, 0, DROWNINGEFFECT_OPACITY_FADEOUT_1_DURATION);
84 
85  BlackoutEffect(0, 0);
86  }
87 
88  //------------------------------------------------------------------------------------------------
89  void BlackoutEffect(float effectStrength, float drowningDuration)
90  {
91  if (!m_wBlackOut)
92  return;
93 
94  if (effectStrength <= 0 || drowningDuration <= 0 )
95  {
96  AnimateWidget.AlphaMask(m_wBlackOut, 0, DROWNINGEFFECT_OPACITY_FADEOUT_1_DURATION);
97  return;
98  }
99 
100  m_wBlackOut.SetOpacity(1);
101  effectStrength *= BLACKOUT_OPACITY_MULTIPLIER;
102  AnimateWidget.AlphaMask(m_wBlackOut, effectStrength, 1 / drowningDuration);
103  }
104 
105  //------------------------------------------------------------------------------------------------
106  void OnDeath(EDamageState state)
107  {
108  if (state != EDamageState.DESTROYED)
109  return;
110 
111  ClearEffect();
112  }
113 
114  //------------------------------------------------------------------------------------------------
115  protected override void ClearEffects()
116  {
117  if (m_wDrowningEffect)
118  {
119  AnimateWidget.StopAllAnimations(m_wDrowningEffect);
120  m_wDrowningEffect.SetOpacity(0);
121  m_wDrowningEffect.SetMaskProgress(0);
122  }
123 
124  if (m_wBlackOut)
125  {
126  AnimateWidget.StopAllAnimations(m_wBlackOut);
127  m_wBlackOut.SetOpacity(0);
128  m_wBlackOut.SetMaskProgress(0);
129  }
130  }
131 
132  //------------------------------------------------------------------------------------------------
133  protected void RemoveInvokers(IEntity prevEntity)
134  {
135  if (!prevEntity)
136  return;
137 
138  m_pCharacterEntity = ChimeraCharacter.Cast(prevEntity);
139  if (!m_pCharacterEntity)
140  return;
141 
142  SCR_CharacterControllerComponent m_CharController = SCR_CharacterControllerComponent.Cast(m_pCharacterEntity.GetCharacterController());
143  if (!m_CharController)
144  return;
145 
146  if (m_CharController.m_OnPlayerDrowning)
147  m_CharController.m_OnPlayerDrowning.Remove(CreateEffect);
148  if (m_CharController.m_OnPlayerStopDrowning)
149  m_CharController.m_OnPlayerStopDrowning.Remove(ClearEffect);
150  }
151 };
m_CharController
protected SCR_CharacterControllerComponent m_CharController
Definition: SCR_ConsumableItemComponent.c:18
m_wRoot
protected Widget m_wRoot
Definition: SCR_ScenarioFrameworkLayerTaskDefend.c:59
SCR_BaseScreenEffect
Definition: SCR_BaseScreenEffect.c:1
EDamageState
EDamageState
Definition: EDamageState.c:12
SCR_CharacterControllerComponent
Definition: SCR_CharacterControllerComponent.c:35
SCR_CharacterDamageManagerComponent
Definition: SCR_CharacterDamageManagerComponent.c:18
SCR_DrowningScreenEffect
Definition: SCR_DrowningScreenEffect.c:1