Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_EntityConditionTooltipDetail.c
Go to the documentation of this file.
3 {
4  [Attribute("{01E150D909447632}Configs/Damage/DamageStateConfig.conf", desc: "Config to get visual data from", params: "conf class=SCR_DamageStateConfig")]
5  protected ref SCR_DamageStateConfig m_DamageStateConfig;
6 
7  [Attribute("{19A8157C2CA02EFB}UI/layouts/Damage/DamageStateIcon.layout", desc: "Layout to create and apply visuals to", params: "layout")]
8  protected ResourceName m_sStateIconLayout;
9 
10  [Attribute("32", desc: "Size of condition icons")]
11  protected float m_fConditionIconSize;
12 
13  [Attribute("0", desc: "If true show death icon rather then destroy icon")]
14  protected bool m_bDiesOnDestroy;
15 
16  //~ Ref
17  protected Widget m_ConditionHolder;
18  protected ref array<EDamageType> m_aActiveDamageTypes = {};
19 
20  //~ States
21  protected ref array<ref SCR_DamageStateInfo> m_aDamageStateUiInfo = {};
22  protected bool m_bIsDestroyed = false;
23  protected bool m_bIsUnconscious = false;
24  protected bool m_bHasNoConditions = false;
25 
26  protected Widget m_wLabel;
27 
28  protected DamageManagerComponent m_DamageManager;
29 
30  //------------------------------------------------------------------------------------------------
31  override bool CreateDetail(SCR_EditableEntityComponent entity, Widget parent, TextWidget label, bool setFrameslot = true)
32  {
33  m_wLabel = label;
34 
35  return super.CreateDetail(entity, parent, label, setFrameslot);
36  }
37 
38  //------------------------------------------------------------------------------------------------
39  override bool NeedUpdate()
40  {
41  return m_ConditionHolder && m_DamageManager && (m_DamageManager.GetState() != EDamageState.DESTROYED || (m_DamageManager.GetState() == EDamageState.DESTROYED && !m_bIsDestroyed) && !m_aDamageStateUiInfo.IsEmpty());// && m_MultiLineTextWidget;
42  }
43 
44  //------------------------------------------------------------------------------------------------
45  override void UpdateDetail(SCR_EditableEntityComponent entity)
46  {
47  bool isDestroyed, isUnconscious, conditionChanged;
48  array<EDamageType> activeCondition = {};
49 
50  //~ If has no conditions but is active hide it
51  if (!HasConditions(isDestroyed, isUnconscious, activeCondition, conditionChanged))
52  {
53  //~ Already hidden
54  if (m_bHasNoConditions)
55  return;
56 
57  m_wLabel.SetVisible(false);
58  m_ConditionHolder.SetVisible(false);
59  m_bHasNoConditions = true;
60  return;
61  }
62  //~ Show again
63  else if (m_bHasNoConditions)
64  {
65  m_wLabel.SetVisible(true);
66  m_ConditionHolder.SetVisible(true);
67  m_bHasNoConditions = false;
68  }
69 
70  //~ If destroyed
71  if (isDestroyed)
72  {
73  //~ Already set is destroyed
74  if (m_bIsDestroyed)
75  return;
76 
77  m_bIsDestroyed = true;
78 
79  CreateDestroyIcon();
80  }
81  else
82  {
83  m_bIsDestroyed = false;
84  }
85 
86  //~ Conditions still the same
87  if (!conditionChanged && m_bIsUnconscious == isUnconscious)
88  return;
89 
90  m_bIsUnconscious = isUnconscious;
91 
92  CreateConditionIcons(activeCondition, m_bIsUnconscious);
93  }
94 
95  //------------------------------------------------------------------------------------------------
96  protected void CreateConditionIcons(array<EDamageType> activeCondition, bool isUnconscious)
97  {
98  ClearConditionHolder();
99  Widget damageStateWidget;
100  SCR_DamageStateUIComponent damageStateUIComponent;
101 
102  if (isUnconscious)
103  {
104  damageStateWidget = GetGame().GetWorkspace().CreateWidgets(m_sStateIconLayout, m_ConditionHolder);
105  if (!damageStateWidget)
106  {
107  Print("'SCR_EntityConditionTooltipDetail' Unable to create icon widget!",LogLevel.ERROR);
108  return;
109  }
110 
111  damageStateUIComponent = SCR_DamageStateUIComponent.Cast(damageStateWidget.FindHandler(SCR_DamageStateUIComponent));
112  if (!damageStateUIComponent)
113  {
114  Print("'SCR_EntityConditionTooltipDetail' Unable to create find SCR_DamageStateUIComponent on entry!",LogLevel.ERROR);
115  return;
116  }
117 
118  damageStateUIComponent.SetSize(m_fConditionIconSize);
119  damageStateUIComponent.SetVisuals(m_DamageStateConfig.GetUnconciousStateUiInfo());
120  }
121 
122  //~ Todo: Currently all icons are on one line. This might cause an overflow if more conditions are added. Make sure that the m_Layout used is a vertical instead of a horizontal then add horizontal for each x amount and use the horizontal for m_ConditionHolder
123 
124  foreach (EDamageType damageType: activeCondition)
125  {
126  damageStateWidget = GetGame().GetWorkspace().CreateWidgets(m_sStateIconLayout, m_ConditionHolder);
127 
128  if (!damageStateWidget)
129  {
130  Print("'SCR_EntityConditionTooltipDetail' Unable to create icon widget!",LogLevel.ERROR);
131  return;
132  }
133 
134  damageStateUIComponent = SCR_DamageStateUIComponent.Cast(damageStateWidget.FindHandler(SCR_DamageStateUIComponent));
135  if (!damageStateUIComponent)
136  {
137  Print("'SCR_EntityConditionTooltipDetail' Unable to create find SCR_DamageStateUIComponent on entry!",LogLevel.ERROR);
138  return;
139  }
140 
141  damageStateUIComponent.SetSize(m_fConditionIconSize);
142  damageStateUIComponent.SetVisuals(damageType);
143  }
144  }
145 
146  //------------------------------------------------------------------------------------------------
147  protected void CreateDestroyIcon()
148  {
149  ClearConditionHolder();
150 
151  Widget damageStateWidget = GetGame().GetWorkspace().CreateWidgets(m_sStateIconLayout, m_ConditionHolder);
152  if (!damageStateWidget)
153  {
154  Print("'SCR_EntityConditionTooltipDetail' Unable to create icon widget!",LogLevel.ERROR);
155  return;
156  }
157 
158  SCR_DamageStateUIComponent damageStateUIComponent = SCR_DamageStateUIComponent.Cast(damageStateWidget.FindHandler(SCR_DamageStateUIComponent));
159  if (!damageStateUIComponent)
160  {
161  Print("'SCR_EntityConditionTooltipDetail' Unable to create find SCR_DamageStateUIComponent on entry!",LogLevel.ERROR);
162  return;
163  }
164 
165  damageStateUIComponent.SetSize(m_fConditionIconSize);
166 
167  if (!m_bDiesOnDestroy)
168  damageStateUIComponent.SetVisuals(m_DamageStateConfig.GetDestroyedStateUiInfo());
169  else
170  damageStateUIComponent.SetVisuals(m_DamageStateConfig.GetDeathStateUiInfo());
171  }
172 
173 // //------------------------------------------------------------------------------------------------
174 // protected void CreateConditionText(LocalizedString text)
175 // {
176 // ClearConditionHolder();
177 //
178 // TextWidget textWidget = TextWidget.Cast(GetGame().GetWorkspace().CreateWidgets(m_sStateTextOnlyLayout, m_ConditionHolder));
179 // if (!textWidget)
180 // {
181 // Print("'SCR_EntityConditionTooltipDetail' Unable to create text widget!",LogLevel.ERROR);
182 // return;
183 // }
184 //
185 // textWidget.SetText(text);
186 // }
187 
188  //------------------------------------------------------------------------------------------------
189  protected void ClearConditionHolder()
190  {
191  Widget child = m_ConditionHolder.GetChildren();
192  Widget childtemp;
193  while (child)
194  {
195  childtemp = child;
196  child = child.GetSibling();
197  childtemp.RemoveFromHierarchy();
198  }
199  }
200 
201  //------------------------------------------------------------------------------------------------
202  override bool InitDetail(SCR_EditableEntityComponent entity, Widget widget)
203  {
204  if (!widget || !m_DamageStateConfig || m_sStateIconLayout.IsEmpty())
205  return false;
206 
207  m_ConditionHolder = widget;
208 
209  m_DamageManager = DamageManagerComponent.Cast(entity.GetOwner().FindComponent(DamageManagerComponent));
210  if (!m_DamageManager)
211  return false;
212 
213  if (m_DamageStateConfig.GetDamageStateInfoArray(m_aDamageStateUiInfo) <= 0)
214  return false;
215 
216  bool isDestroyed, isUnconscious, conditionChanged;
217  array<EDamageType> activeCondition = {};
218 
219  if (HasConditions(isDestroyed, isUnconscious, activeCondition, conditionChanged, true))
220  {
221  UpdateDetail(entity);
222  return true;
223  }
224 
225  return false;
226  }
227 
228  //------------------------------------------------------------------------------------------------
229  protected bool HasConditions(out bool isDestroyed, out bool isUnconscious, out notnull array<EDamageType> activeCondition, out bool conditionChanged, bool onlyCheckOneTrue = false)
230  {
231  bool hasCondition = false;
232 
233  //~ Always return if destroyed as no need to check the other conditions
234  if (m_DamageManager.GetState() == EDamageState.DESTROYED)
235  {
236  isDestroyed = true;
237  return true;
238  }
239 
240  ChimeraCharacter char = ChimeraCharacter.Cast(m_DamageManager.GetOwner());
241  if (char)
242  {
243  CharacterControllerComponent controller = CharacterControllerComponent.Cast(char.GetCharacterController());
244  if (controller.GetLifeState() == ECharacterLifeState.INCAPACITATED)
245  {
246  isUnconscious = true;
247 
248  if (onlyCheckOneTrue)
249  return true;
250  else
251  hasCondition = true;
252  }
253  }
254 
255  foreach (SCR_DamageStateInfo damageStateInfo: m_aDamageStateUiInfo)
256  {
257  if (m_DamageManager.IsDamagedOverTime(damageStateInfo.m_eDamageType))
258  {
259  activeCondition.Insert(damageStateInfo.m_eDamageType);
260 
261  if (onlyCheckOneTrue)
262  {
263  return true;
264  }
265  else
266  {
267  if (!m_aActiveDamageTypes.Contains(damageStateInfo.m_eDamageType))
268  conditionChanged = true;
269 
270  hasCondition = true;
271  }
272  }
273  }
274 
275  if (activeCondition.Count() != m_aActiveDamageTypes.Count())
276  conditionChanged = true;
277 
278  if (conditionChanged)
279  m_aActiveDamageTypes.Copy(activeCondition);
280 
281  return hasCondition;
282  }
283 }
m_bIsUnconscious
protected bool m_bIsUnconscious
Definition: SCR_UITaskManagerComponent.c:33
GetCharacterController
protected SCR_CharacterControllerComponent GetCharacterController(IEntity from)
Definition: SCR_ItemPlacementComponent.c:50
ECharacterLifeState
ECharacterLifeState
Definition: ECharacterLifeState.c:12
SCR_DamageStateInfo
Definition: SCR_DamageStateConfig.c:89
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
EDamageState
EDamageState
Definition: EDamageState.c:12
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
SCR_EntityConditionTooltipDetail
Definition: SCR_EntityConditionTooltipDetail.c:2
SCR_DamageStateUIComponent
Definition: SCR_DamageStateUIComponent.c:1
SCR_DamageStateConfig
Definition: SCR_DamageStateConfig.c:2
BaseContainerCustomTitleField
class SCR_KeyBindingFilter BaseContainerCustomTitleField("m_sBindString")
Definition: SCR_KeyBindingMenuConfig.c:113
Attribute
typedef Attribute
Post-process effect of scripted camera.
SCR_EntityTooltipDetail
Definition: SCR_EntityTooltipDetail.c:2
SCR_EditableEntityComponent
Definition: SCR_EditableEntityComponent.c:13
EDamageType
EDamageType
Definition: EDamageType.c:12
params
Configs ServerBrowser KickDialogs params
Definition: SCR_NotificationSenderComponent.c:24
DamageManagerComponent
Definition: DamageManagerComponent.c:12
m_DamageManager
DamageManagerComponent m_DamageManager
Definition: SCR_AITargetInfo.c:19
BaseContainerProps
SCR_AIGoalReaction_Follow BaseContainerProps
Handles insects that are supposed to be spawned around selected prefabs defined in prefab names array...
Definition: SCR_AIGoalReaction.c:468