Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_UnconsciousScreenEffect.c
Go to the documentation of this file.
2 {
3  // Play Animation of UnconsciousnessEffect()
4  protected const float UNCONSCIOUS_EFFECT_DURATION = 0.5;
5  protected const float UNCONSCIOUS_FADEOUT_DURATION = 0.8;
6  protected const float UNCONSCIOUS_OSCILIATION_OVERSHOOT = 0.2;
7  protected const float UNCONSCIOUS_ALPHAMASK_MIN = 0.4;
8  protected const float UNCONSCIOUS_ALPHAMASK_MAX = 0.7;
9  protected const float UNCONSCIOUS_OPACITY_DIFF = 0.05;
10 
11  // Widgets
12  protected bool m_bOverUnder;
13  protected WidgetAnimationBase m_UnconMaskAnim;
14  protected ImageWidget m_wDeath;
15 
16  //Character
17  protected SCR_CharacterDamageManagerComponent m_pDamageManager;
18  protected ChimeraCharacter m_pCharacterEntity;
19 
20  [Attribute("0", UIWidgets.ComboBox, "Which curve shape should be used for lerping the effect in", "", ParamEnumArray.FromEnum(EAnimationCurve)) ]
21  EAnimationCurve m_eUnconsciousEffectAnimIn;
22 
23  [Attribute("0", UIWidgets.ComboBox, "Which curve shape should be used for lerping the effect out", "", ParamEnumArray.FromEnum(EAnimationCurve)) ]
24  EAnimationCurve m_eUnconsciousEffectAnimOut;
25 
26  //------------------------------------------------------------------------------------------------
27  override void DisplayStartDraw(IEntity owner)
28  {
29  m_pCharacterEntity = ChimeraCharacter.Cast(owner);
30  m_wDeath = ImageWidget.Cast(m_wRoot.FindAnyWidget("DeathOverlay"));
31  }
32 
33  //------------------------------------------------------------------------------------------------
34  override void DisplayControlledEntityChanged(IEntity from, IEntity to)
35  {
36  ClearEffects();
37 
38  m_pCharacterEntity = ChimeraCharacter.Cast(to);
39  if (!m_pCharacterEntity)
40  return;
41 
42  m_pDamageManager = SCR_CharacterDamageManagerComponent.Cast(m_pCharacterEntity.GetDamageManager());
43 
44  // In case player became unconscious before invokers were established, check if already bleeding
45  CharacterControllerComponent controller = m_pCharacterEntity.GetCharacterController();
46  if (controller && controller.GetLifeState() == ECharacterLifeState.INCAPACITATED)
47  DisplayConsciousnessChanged(false);
48  }
49 
50  //------------------------------------------------------------------------------------------------
51  protected override void DisplayConsciousnessChanged(bool conscious, bool init = false)
52  {
53  UnconsciousnessEffect(conscious);
54  }
55 
56  //------------------------------------------------------------------------------------------------
57  protected void UnconsciousnessEffect(bool conscious)
58  {
59  if (!conscious)
60  PlayUnconAnim(UNCONSCIOUS_EFFECT_DURATION);
61  else
62  StopUnconAnim();
63  }
64 
65  //------------------------------------------------------------------------------------------------
66  protected void PlayUnconAnim(float speed)
67  {
68  if (!m_wDeath || !m_CharacterController)
69  return;
70 
71  if (m_CharacterController.IsDead())
72  return;
73 
74  m_wDeath.SetVisible(true);
75  m_bOverUnder = !m_bOverUnder;
76 
77  float unconProgress = 1 - GetUnconProgress();
78  float targetProgress;
79  EAnimationCurve curve;
80 
81  if (m_bOverUnder)
82  {
83  curve = m_eUnconsciousEffectAnimIn;
84  targetProgress = unconProgress + (unconProgress * UNCONSCIOUS_OSCILIATION_OVERSHOOT);
85  AnimateWidget.Opacity(m_wDeath, 1, speed);
86  }
87  else
88  {
89  curve = m_eUnconsciousEffectAnimOut;
90  targetProgress = unconProgress - (unconProgress * UNCONSCIOUS_OSCILIATION_OVERSHOOT);
91  AnimateWidget.Opacity(m_wDeath, 1 - UNCONSCIOUS_OPACITY_DIFF, speed);
92  }
93 
94  m_UnconMaskAnim = AnimateWidget.AlphaMask(m_wDeath, Math.Lerp(UNCONSCIOUS_ALPHAMASK_MIN, UNCONSCIOUS_ALPHAMASK_MAX, targetProgress), speed);
95  m_UnconMaskAnim.SetCurve(curve);
96 
97  if (m_UnconMaskAnim)
98  m_UnconMaskAnim.GetOnCompleted().Insert(OnAnimCycleComplete);
99  }
100 
101  //------------------------------------------------------------------------------------------------
102  protected void OnAnimCycleComplete(WidgetAnimationBase anim)
103  {
104  if (anim)
105  {
106  anim.Stop();
107  anim.GetOnCycleCompleted().Remove(OnAnimCycleComplete);
108  }
109 
110  GetGame().GetCallqueue().CallLater(PlayUnconAnim, param1: UNCONSCIOUS_EFFECT_DURATION);
111  }
112 
113  //------------------------------------------------------------------------------------------------
114  protected float GetUnconProgress()
115  {
116  if (!m_pDamageManager)
117  return 0;
118 
119  SCR_CharacterResilienceHitZone resilience = SCR_CharacterResilienceHitZone.Cast(m_pDamageManager.GetResilienceHitZone());
120  if (!resilience)
121  return 0;
122 
123  SCR_CharacterBloodHitZone blood = SCR_CharacterBloodHitZone.Cast(m_pDamageManager.GetBloodHitZone());
124  if (blood && blood.GetHealthScaled() < blood.GetDamageStateThreshold(ECharacterBloodState.UNCONSCIOUS))
125  return 0;
126 
127  return Math.Lerp(0, resilience.GetDamageStateThreshold(ECharacterResilienceState.WEAKENED), resilience.GetHealthScaled());
128  }
129 
130  //------------------------------------------------------------------------------------------------
131  protected void StopUnconAnim()
132  {
133  if (m_UnconMaskAnim)
134  m_UnconMaskAnim.GetOnCycleCompleted().Remove(OnAnimCycleComplete);
135 
136  if (!m_wDeath)
137  return;
138 
139  AnimateWidget.AlphaMask(m_wDeath, 0, UNCONSCIOUS_FADEOUT_DURATION);
140  AnimateWidget.Opacity(m_wDeath, 0, UNCONSCIOUS_FADEOUT_DURATION);
141  }
142 
143  //------------------------------------------------------------------------------------------------
144  protected override void ClearEffects()
145  {
146  if (m_UnconMaskAnim)
147  m_UnconMaskAnim.GetOnCycleCompleted().Remove(OnAnimCycleComplete);
148 
149  if (m_wDeath)
150  {
151  AnimateWidget.StopAllAnimations(m_wDeath);
152  m_wDeath.SetOpacity(0);
153  m_wDeath.SetMaskProgress(0);
154  }
155  }
156 };
m_wRoot
protected Widget m_wRoot
Definition: SCR_ScenarioFrameworkLayerTaskDefend.c:59
SCR_BaseScreenEffect
Definition: SCR_BaseScreenEffect.c:1
SCR_UnconsciousScreenEffect
Definition: SCR_UnconsciousScreenEffect.c:1
ECharacterLifeState
ECharacterLifeState
Definition: ECharacterLifeState.c:12
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
m_CharacterController
SCR_CharacterPerceivableComponentClass m_CharacterController
SCR_CharacterBloodHitZone
Blood - does not receive damage directly, only via scripted events.
Definition: SCR_CharacterHitZone.c:480
Attribute
typedef Attribute
Post-process effect of scripted camera.
SCR_CharacterDamageManagerComponent
Definition: SCR_CharacterDamageManagerComponent.c:18
ECharacterResilienceState
ECharacterResilienceState
Definition: SCR_CharacterHitZone.c:20
ECharacterBloodState
ECharacterBloodState
Definition: SCR_CharacterHitZone.c:13