Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_InspectCasualtyWidget.c
Go to the documentation of this file.
1 class SCR_InspectCasualtyWidget : SCR_InfoDisplayExtended
2 {
3  const ResourceName INSPECT_CASUALTY_LAYOUT = "{11AC7D61FD4CF3F6}UI/layouts/Damage/InspectCasualtyMenu.layout";
4 
5  protected SCR_CharacterDamageManagerComponent m_CharDamageManager;
6  protected Widget m_wCasualtyInspectWidget;
7 
8  IEntity m_Target;
9 
10  protected const float UPDATE_FREQ = 0.5;
11  protected const float MAX_SHOW_DURATION = 5;
12  protected const string TARGET_BONE = "Spine4";
13  protected float m_fTimeTillUpdate;
14  protected float m_fTimeTillClose;
15  protected bool m_bShouldBeVisible;
16 
17  //------------------------------------------------------------------------------------------------
18  override void DisplayStartDraw(IEntity owner)
19  {
20  m_wCasualtyInspectWidget = GetRootWidget();
21  DisableWidget();
22  }
23 
24  //------------------------------------------------------------------------------------------------
25  override event void DisplayUpdate(IEntity owner, float timeSlice)
26  {
27  if (m_fTimeTillClose < 0)
28  DisableWidget();
29  else
30  m_fTimeTillClose -= timeSlice;
31 
32  if (m_fTimeTillUpdate > 0)
33  {
34  m_fTimeTillUpdate -= timeSlice;
35  }
36  else
37  {
38  m_fTimeTillUpdate = UPDATE_FREQ;
39  UpdateTarget();
40  }
41 
42  UpdateWidget();
43  }
44 
45  //------------------------------------------------------------------------------------------------
47  bool ShowInspectCasualtyWidget(IEntity targetCharacter)
48  {
49  if (!m_wCasualtyInspectWidget)
50  return false;
51 
52  ChimeraCharacter char = ChimeraCharacter.Cast(targetCharacter);
53  if (!char)
54  return false;
55 
56  CharacterControllerComponent targetController = char.GetCharacterController();
57  if (!targetController)
58  return false;
59 
60  UpdateTarget();
61  EnableWidget();
62 
63  return true;
64  }
65 
66  //------------------------------------------------------------------------------------------------
68  void UpdateTarget()
69  {
70  if (!m_Target)
71  {
72  DisableWidget();
73  return;
74  }
75 
76  ChimeraCharacter char = ChimeraCharacter.Cast(m_Target);
77  if (!char)
78  return;
79 
80  CharacterControllerComponent controller = char.GetCharacterController();
81  if (controller.GetLifeState() == ECharacterLifeState.DEAD)
82  {
83  DisableWidget();
84  return;
85  }
86 
87  UpdateWidgetData();
88  }
89 
90  //------------------------------------------------------------------------------------------------
92  void UpdateWidgetData()
93  {
94  if (!m_Target || !m_wCasualtyInspectWidget)
95  return;
96 
97  string sName;
98  GetCasualtyName(sName, m_Target);
99 
100  float bleedingRate;
101  int groupDamageIntensity;
102  bool regenerating, isTourniquetted, isSalineBagged, isMorphined, isArmFractured, isLegFractured;
103  string damageIntensity, damageIntensityText, bleedingIntensityText;
104  array <bool> hZGroupsBleeding = {};
105 
106  SCR_InventoryHitZonePointUI hitZonePointUI = new SCR_InventoryHitZonePointUI();
107  GetDamageInfo(hitZonePointUI, m_Target, bleedingRate, hZGroupsBleeding, groupDamageIntensity, regenerating, isTourniquetted, isSalineBagged, isMorphined);
108  hitZonePointUI.GetDamageInfoTexts(EHitZoneGroup.VIRTUAL, groupDamageIntensity, bleedingRate, damageIntensity, damageIntensityText, bleedingIntensityText);
109 
110  SCR_InventoryDamageInfoUI damageInfoUI = SCR_InventoryDamageInfoUI.Cast(m_wCasualtyInspectWidget.FindHandler(SCR_InventoryDamageInfoUI));
111  if (damageInfoUI)
112  {
113  damageInfoUI.SetName(sName);
114  damageInfoUI.SetDamageStateVisible(groupDamageIntensity, regenerating, damageIntensity, damageIntensityText);
115  damageInfoUI.SetBleedingStateVisible(bleedingRate > 0, bleedingIntensityText);
116  damageInfoUI.SetTourniquetStateVisible(isTourniquetted);
117  damageInfoUI.SetSalineBagStateVisible(isSalineBagged);
118  damageInfoUI.SetMorphineStateVisible(isMorphined);
119  damageInfoUI.SetFractureStateVisible(isArmFractured, isLegFractured);
120  }
121  }
122 
123  //------------------------------------------------------------------------------------------------
125  void UpdateWidget()
126  {
127  if (!m_Target || !m_wCasualtyInspectWidget || !m_bIsEnabled)
128  return;
129 
130  vector boneVector[4];
131  m_Target.GetAnimation().GetBoneMatrix(m_Target.GetAnimation().GetBoneIndex(TARGET_BONE), boneVector);
132 
133  vector WPPos = boneVector[3] + m_Target.GetOrigin();
134  vector pos = GetGame().GetWorkspace().ProjWorldToScreen(WPPos, GetGame().GetWorld());
135 
136  // Handle off-screen coords
137  WorkspaceWidget workspace = GetGame().GetWorkspace();
138  int winX = workspace.GetWidth();
139  int winY = workspace.GetHeight();
140  int posX = workspace.DPIScale(pos[0]);
141  int posY = workspace.DPIScale(pos[1]);
142 
143  // If widget off screen, remove widget
144  if (posX < 0 || posX > winX || posY > winY || posY < 0)
145  {
146  DisableWidget();
147  return;
148  }
149 
150  FrameSlot.SetPos(m_wCasualtyInspectWidget.GetChildren(), pos[0], pos[1]);
151 
152  float dist = vector.Distance(GetGame().GetPlayerController().GetControlledEntity().GetOrigin(), WPPos);
153  if (dist >= 4)
154  {
155  DisableWidget();
156  return;
157  }
158 
159  float opacity = 1;
160  float distanceOpacityReduction = 1;
161 
162  if (dist <= 3)
163  distanceOpacityReduction = 0;
164  else
165  distanceOpacityReduction = Math.InverseLerp(3, 4, dist);
166 
167  m_wCasualtyInspectWidget.SetOpacity(opacity - distanceOpacityReduction);
168  }
169 
170  //------------------------------------------------------------------------------------------------
171  void GetDamageInfo(SCR_InventoryHitZonePointUI hitZonePointUI, IEntity targetEntity, inout float bleedingRate, inout array <bool> hZGroupsBleeding, inout int damageIntensity, inout bool regenerating, inout bool isTourniquetted, inout bool isSalineBagged, inout bool isMorphined)
172  {
173  ChimeraCharacter character = ChimeraCharacter.Cast(targetEntity);
174  if (!character)
175  return;
176 
177  SCR_CharacterDamageManagerComponent damageMan = SCR_CharacterDamageManagerComponent.Cast( character.GetDamageManager() );
178  if (!damageMan)
179  return;
180 
181  float defaultHZHealth = damageMan.GetHealthScaled();
182  bleedingRate = damageMan.GetBloodHitZone().GetDamageOverTime(EDamageType.BLEEDING);
183  if (bleedingRate)
184  {
185  hZGroupsBleeding = {};
186  hZGroupsBleeding.Resize(damageMan.LIMB_GROUPS.Count());
187 
188  foreach (ECharacterHitZoneGroup group : damageMan.LIMB_GROUPS)
189  {
190  hZGroupsBleeding[damageMan.LIMB_GROUPS.Find(group)] = damageMan.GetGroupDamageOverTime(group, EDamageType.BLEEDING) != 0;
191  }
192  }
193 
194  array <EHitZoneGroup> limbGroups = {};
195  damageMan.GetAllLimbs(limbGroups);
196  foreach(EHitZoneGroup group : limbGroups)
197  {
198  if (!isTourniquetted)
199  isTourniquetted = damageMan.GetGroupTourniquetted(group);
200 
201  if (!isSalineBagged)
202  isSalineBagged = damageMan.GetGroupSalineBagged(group);
203 
204  if (!isMorphined)
205  {
206  SCR_CharacterHeadHitZone headHitZone = SCR_CharacterHeadHitZone.Cast(damageMan.GetHeadHitZone());
207  if (headHitZone)
208  isMorphined = headHitZone.GetDamageOverTime(EDamageType.HEALING) < 0;
209  }
210 
211  if (!regenerating)
212  regenerating = damageMan.GetGroupDamageOverTime(group, EDamageType.HEALING) != 0 || damageMan.GetGroupDamageOverTime(group, EDamageType.REGENERATION) != 0;
213  }
214 
215  if (defaultHZHealth == 1)
216  damageIntensity = 0;
217  else if (defaultHZHealth < hitZonePointUI.m_fLowDamageThreshold)
218  damageIntensity = 4;
219  else if (defaultHZHealth < hitZonePointUI.m_fMediumDamageThreshold)
220  damageIntensity = 3;
221  else if (defaultHZHealth < hitZonePointUI.m_fHighDamageThreshold)
222  damageIntensity = 2;
223  else
224  damageIntensity = 1;
225  }
226 
227  //------------------------------------------------------------------------------------------------
228  void GetCasualtyName(inout string sName, IEntity targetCharacter)
229  {
230  string sFormat, sAlias, sSurname;
231  int playerID = GetGame().GetPlayerManager().GetPlayerIdFromControlledEntity(targetCharacter);
232  if (playerID > 0)
233  {
234  PlayerManager playerMgr = GetGame().GetPlayerManager();
235  if (playerMgr)
236  sName = playerMgr.GetPlayerName(playerID);
237  }
238  else
239  {
240  SCR_CharacterIdentityComponent scrCharIdentity = SCR_CharacterIdentityComponent.Cast(targetCharacter.FindComponent(SCR_CharacterIdentityComponent));
241  if (scrCharIdentity)
242  {
243  scrCharIdentity.GetFormattedFullName(sFormat, sName, sAlias, sSurname);
244  sName = sName + " " + sSurname;
245  }
246  else
247  {
248  CharacterIdentityComponent charIdentity = CharacterIdentityComponent.Cast(targetCharacter.FindComponent(CharacterIdentityComponent));
249  if (charIdentity && charIdentity.GetIdentity())
250  sName = charIdentity.GetIdentity().GetName();
251  }
252  }
253  }
254 
255  //------------------------------------------------------------------------------------------------
256  override protected void DisplayOnSuspended()
257  {
258  DisableWidget();
259  }
260 
261  //------------------------------------------------------------------------------------------------
262  void SetTarget(IEntity target)
263  {
264  m_Target = target;
265  }
266 
267  //------------------------------------------------------------------------------------------------
268  bool IsActive()
269  {
270  return m_Target && m_wCasualtyInspectWidget && m_wCasualtyInspectWidget.GetOpacity() != 0;
271  }
272 
273  //------------------------------------------------------------------------------------------------
274  void DisableWidget()
275  {
276  if (m_wCasualtyInspectWidget)
277  m_wCasualtyInspectWidget.SetVisible(false);
278 
279  m_Target = null;
280  SetEnabled(false);
281  m_bShouldBeVisible = false;
282  m_fTimeTillClose = MAX_SHOW_DURATION;
283  }
284 
285  //------------------------------------------------------------------------------------------------
286  void EnableWidget()
287  {
288  if (m_wCasualtyInspectWidget)
289  m_wCasualtyInspectWidget.SetVisible(true);
290 
291  SetEnabled(true);
292  m_bShouldBeVisible = true;
293  }
294 
295  //------------------------------------------------------------------------------------------------
296  override void DisplayOnResumed()
297  {
298  if (!m_bShouldBeVisible && m_wCasualtyInspectWidget)
299  m_wCasualtyInspectWidget.SetVisible(false);
300  }
301 };
SCR_InventoryDamageInfoUI
Definition: SCR_InventoryDamageInfoUI.c:5
ECharacterHitZoneGroup
ECharacterHitZoneGroup
Definition: SCR_CharacterDamageManagerComponent.c:1
ECharacterLifeState
ECharacterLifeState
Definition: ECharacterLifeState.c:12
SetEnabled
void SetEnabled(bool enabled)
Definition: SCR_BaseManualCameraComponent.c:91
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
m_Target
class SCR_AIPolar m_Target
GetPlayerController
proto external PlayerController GetPlayerController()
Definition: SCR_PlayerDeployMenuHandlerComponent.c:307
GetRootWidget
Widget GetRootWidget()
Definition: SCR_UITaskManagerComponent.c:160
SCR_InspectCasualtyWidget
Definition: SCR_InspectCasualtyWidget.c:1
GetOrigin
vector GetOrigin()
Definition: SCR_AIUtilityComponent.c:279
SCR_CharacterDamageManagerComponent
Definition: SCR_CharacterDamageManagerComponent.c:18
m_bIsEnabled
protected bool m_bIsEnabled
Definition: SCR_BaseSupportStationComponent.c:97
GetControlledEntity
SCR_EditableEntityComponent GetControlledEntity()
Returns the controlled entity or null if none.
Definition: SCR_EditablePlayerDelegateComponent.c:86
EDamageType
EDamageType
Definition: EDamageType.c:12
SCR_CharacterHeadHitZone
Definition: SCR_CharacterHitZone.c:560
PlayerManager
Definition: PlayerManager.c:12