Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
gameplayeffectwidgets.c
Go to the documentation of this file.
1 /*
2 TODO - doxygen formating
3 */
4 
6 class GameplayEffectWidgets extends GameplayEffectWidgets_base
7 {
8  protected ref Widget m_Root; //dummy parent node
9  protected ref map<int,ref Widget> m_Layouts;
10  protected ref set<ref Widget> m_UniqueLayouts;
11  protected ref GameplayEffectDataMap m_WidgetDataMap;
12  protected ref set<int> m_RunningEffects;
13  protected ref set<int> m_RunningEffectsPrevious;
14  protected ref array<int> m_UpdatingEffects;
15  protected ref array<ref Widget> m_UpdatedWidgetsCheck; //to make sure widgets are not updated over and over (case of multiple IDs sharing same widget set)
16  protected ref array<int> m_UpdatedWidgetSetsCheck; //to make sure sets are not updated over and over (case of multiple IDs sharing same widget set)
17  protected ref set<int> m_SuspendRequests;
18  protected ref map<int,typename> m_IDToTypeMap;
19 
20  protected float m_TimeProgBreath;
21  protected float m_BreathMultStamina;
22  protected float m_BreathResidue;
23 
24  //UserID's for widget containers that use something different from 'EffectWidgetsTypes' defaults
25  protected const int WIDGETSET_BREATH = 100;
26 
27  //effect values
28  protected int m_BreathColor;
29  protected float m_BreathAlphaVal;
30  protected float m_FlashbangCoverAlphaVal;
31 
32  void GameplayEffectWidgets()
33  {
34  m_Root = GetGame().GetWorkspace().CreateWidget(FrameWidgetTypeID,0,0,1.0,1.0,WidgetFlags.VISIBLE | WidgetFlags.HEXACTPOS | WidgetFlags.VEXACTPOS, 0xffffffff, 0);
35  m_Layouts = new map<int,ref Widget>;
36  m_UniqueLayouts = new set<ref Widget>;
37  m_WidgetDataMap = new GameplayEffectDataMap;
38  m_RunningEffects = new set<int>;
39  m_RunningEffectsPrevious = new set<int>;
40  m_UpdatingEffects = new array<int>;
41  m_UpdatedWidgetsCheck = new array<ref Widget>;
42  m_UpdatedWidgetSetsCheck = new array<int>;
43  m_SuspendRequests = new set<int>;
44  m_IDToTypeMap = new map<int,typename>;
45 
46  m_TimeProgBreath = 0.0;
47  m_BreathMultStamina = 1.0;
48 
49  PairIDToTypes();
50 
51  RegisterLayouts("gui/layouts/gameplay/CameraEffects.layout",CompileEffectListing());
52  RegisterLayouts("gui/layouts/gameplay/BleedingEffects.layout",{EffectWidgetsTypes.BLEEDING_LAYER});
53 
54  InitWidgetSet(EffectWidgetsTypes.MASK_BREATH,true,WIDGETSET_BREATH);
55  InitWidgetSet(EffectWidgetsTypes.HELMET_BREATH,true,WIDGETSET_BREATH);
56  InitWidgetSet(EffectWidgetsTypes.MOTO_BREATH,true,WIDGETSET_BREATH);
57 
58  InitWidgetSet(EffectWidgetsTypes.MASK_OCCLUDER,false,EffectWidgetsTypes.MASK_OCCLUDER);
59  InitWidgetSet(EffectWidgetsTypes.HELMET_OCCLUDER);
60  InitWidgetSet(EffectWidgetsTypes.HELMET2_OCCLUDER);
61  InitWidgetSet(EffectWidgetsTypes.MOTO_OCCLUDER);
62  InitWidgetSet(EffectWidgetsTypes.NVG_OCCLUDER,false,EffectWidgetsTypes.NVG_OCCLUDER);
63  InitWidgetSet(EffectWidgetsTypes.PUMPKIN_OCCLUDER,false,EffectWidgetsTypes.NVG_OCCLUDER);
64  InitWidgetSet(EffectWidgetsTypes.EYEPATCH_OCCLUDER);
65 
66  InitWidgetSet(EffectWidgetsTypes.COVER_FLASHBANG);
67 
68  InitWidgetSet(EffectWidgetsTypes.BLEEDING_LAYER,true);
69 
70  UpdateVisibility();
71  }
72 
73  void ~GameplayEffectWidgets()
74  {
75  for (int i = 0; i < m_Layouts.Count(); i++)
76  {
77  if (m_Layouts.GetElement(i))
78  m_Layouts.GetElement(i).Unlink();
79  }
80  }
81 
86  protected void RegisterLayouts(string path, array<int> types)
87  {
88  Widget w = GetGame().GetWorkspace().CreateWidgets(path,m_Root,false);
89  m_UniqueLayouts.Insert(w);
90  w.Show(false);
91  foreach (int i : types)
92  {
93  m_Layouts.Set(i,w);
94  }
95  }
96 
97  protected void PairIDToTypes()
98  {
99  m_IDToTypeMap.Insert(EffectWidgetsTypes.BLEEDING_LAYER,GameplayEffectsDataBleeding);
100  }
101 
102  protected typename TranslateIDToType(int typeID)
103  {
104  return m_IDToTypeMap.Get(typeID);
105  }
106 
107  override void RegisterGameplayEffectData(int id, Param p)
108  {
109  if (!m_WidgetDataMap.Get(id).DataInitialized())
110  {
111  m_WidgetDataMap.Get(id).RegisterData(p);
112  }
113  }
114 
125  protected void InitWidgetSet(int type, bool updating = false, int user_id_override = -1)
126  {
127  Widget parent = null;
128  if (user_id_override != -1)
129  {
130  parent = m_Layouts.Get(type).FindAnyWidgetById(user_id_override);
131  }
132  else
133  {
134  parent = m_Layouts.Get(type).FindAnyWidgetById(type);
135  }
136 
137  if (!parent)
138  {
139  Print("InitWidgetSet | type: " + type + " - parent not found!");
140  return;
141  }
142 
143  array<ref Widget> output;
144  Widget w = parent.GetChildren();
145  if (w)
146  {
147  output = new array<ref Widget>;
148  while (w)
149  {
150  w.Update();
151  w.Show(false,true);
152  output.Insert(w);
153 
154  w = w.GetSibling();
155  }
156 
157  if (parent.GetChildren())
158  {
159  typename handled_type = TranslateIDToType(type);
160  if ( handled_type )
161  {
162  CreateHandledClass(handled_type,output,type,user_id_override);
163  }
164  else
165  {
166  if (ImageWidget.Cast(parent.GetChildren()))
167  {
168  m_WidgetDataMap.Set(type, new GameplayEffectsDataImage(output,type,user_id_override) );
169  }
170  else
171  {
172  m_WidgetDataMap.Set(type, new GameplayEffectsData(output,type,user_id_override) );
173  }
174  }
175  }
176 
177  if (updating)
178  m_UpdatingEffects.Insert(type);
179  }
180  }
181 
182  bool CreateHandledClass(typename handled_type, array<ref Widget> input, int type, int user_override)
183  {
184  if (handled_type)
185  {
186  GameplayEffectsData data = GameplayEffectsData.Cast(handled_type.Spawn());
187  data.Init(input,type,m_Layouts.Get(type),user_override);
188  m_WidgetDataMap.Set(type, data);
189  return true;
190  }
191  return false;
192  }
193 
195  array<int> CompileEffectListing()
196  {
197  array<int> ret = new array<int>;
198  ret.Insert(EffectWidgetsTypes.MASK_OCCLUDER);
199  ret.Insert(EffectWidgetsTypes.MASK_BREATH);
200  ret.Insert(EffectWidgetsTypes.HELMET_OCCLUDER);
201  ret.Insert(EffectWidgetsTypes.HELMET_BREATH);
202  ret.Insert(EffectWidgetsTypes.MOTO_OCCLUDER);
203  ret.Insert(EffectWidgetsTypes.MOTO_BREATH);
204  ret.Insert(EffectWidgetsTypes.COVER_FLASHBANG);
205  ret.Insert(EffectWidgetsTypes.NVG_OCCLUDER);
206  ret.Insert(EffectWidgetsTypes.PUMPKIN_OCCLUDER);
207  ret.Insert(EffectWidgetsTypes.EYEPATCH_OCCLUDER);
208  ret.Insert(EffectWidgetsTypes.HELMET2_OCCLUDER);
209 
210  return ret;
211  }
212 
213  protected void UpdateVisibility()
214  {
215  Widget w;
216  //Hide diff
217  int value;
218  int runningEffectCount = m_RunningEffects.Count();
219  bool runningEffectsPresent = runningEffectCount > 0;
221  for (int i = 0; i < m_RunningEffectsPrevious.Count(); i++)
222  {
223  value = m_RunningEffectsPrevious.Get(i);
224  dta = m_WidgetDataMap.Get(value);
225  if (runningEffectCount < 1 || m_RunningEffects.Find(value) == -1)
226  {
227  if (dta.HasDefinedHandle())
228  {
229  dta.UpdateVisibility(false);
230  }
231  else
232  {
233  for (int j = 0; j < m_WidgetDataMap.Get(value).GetWidgetSet().Count(); j++)
234  {
235  w = m_WidgetDataMap.Get(value).GetWidgetSet().Get(j);
236  w.Show(false);
237  }
238  w.GetParent().Show(false);
239  }
240  }
241  }
242 
243  //Show running effects
244  if (runningEffectsPresent)
245  {
246  value = 0;
247  for (i = 0; i < runningEffectCount; i++)
248  {
249  value = m_RunningEffects.Get(i);
250  dta = m_WidgetDataMap.Get(value);
251  if (dta.HasDefinedHandle())
252  {
253  dta.m_LayoutRoot.Show(true);
254  dta.UpdateVisibility(true);
255  }
256  else
257  {
258  for (j = 0; j < m_WidgetDataMap.Get(value).GetWidgetSet().Count(); j++)
259  {
260  w = m_WidgetDataMap.Get(value).GetWidgetSet().Get(j);
261  w.Update();
262  w.Show(true);
263  }
264 
265  while (w) //dumb but necessary because of uncertain "visible" setting of the layout
266  {
267  w = w.GetParent();
268  if (w)
269  {
270  w.Show(true);
271  }
272  }
273  }
274  }
275  }
276 
277  m_Root.Show(runningEffectsPresent && m_SuspendRequests.Count() < 1);
278  m_RunningEffectsPrevious.Clear();
279  }
280 
281  override void AddActiveEffects(array<int> effects)
282  {
283  if (effects && effects.Count() > 0)
284  {
285  m_RunningEffectsPrevious.Copy(m_RunningEffects);
286 
287  int value;
288  for (int i = 0; i < effects.Count(); i++)
289  {
290  value = effects.Get(i);
291  m_RunningEffects.Insert(value);
292  }
293 
294  if (m_RunningEffectsPrevious.Count() != m_RunningEffects.Count())
295  {
296  UpdateVisibility();
297  }
298  }
299  }
300 
301  override void RemoveActiveEffects(array<int> effects)
302  {
303  if (effects && effects.Count() > 0)
304  {
305  m_RunningEffectsPrevious.Copy(m_RunningEffects);
306 
307  int value;
308  int idx;
309  for (int i = 0; i < effects.Count(); i++)
310  {
311  value = effects.Get(i);
312  idx = m_RunningEffects.Find(value);
313  if (idx != -1)
314  {
315  m_RunningEffects.Remove(idx);
316  }
317  }
318 
319  if (m_RunningEffectsPrevious.Count() != m_RunningEffects.Count())
320  {
321  UpdateVisibility();
322  }
323  }
324  }
325 
326  override void StopAllEffects()
327  {
328  m_Root.Show(false); //to avoid visual 'peeling'
329 
330  if (IsAnyEffectRunning())
331  {
332  int count = m_RunningEffects.Count();
333  GameplayEffectsData data;
334  for (int i = 0; i < count; i++) //iterates over running metadata, in case anything requires its own stop handling
335  {
336  data = m_WidgetDataMap.Get(m_RunningEffects[i]);
337  data.ForceStop();
338  }
339  }
340 
341  m_RunningEffectsPrevious.Copy(m_RunningEffects);
342  m_RunningEffects.Clear();
343  UpdateVisibility();
344  }
345 
346  override bool IsAnyEffectRunning()
347  {
348  return m_RunningEffects && m_RunningEffects.Count() > 0;
349  }
350 
351  override void AddSuspendRequest(int request_id)
352  {
353  m_SuspendRequests.Insert(request_id);
354  UpdateVisibility();
355  }
356 
357  override void RemoveSuspendRequest(int request_id)
358  {
359  int idx = m_SuspendRequests.Find(request_id);
360  if (idx != -1)
361  {
362  m_SuspendRequests.Remove(idx);
363  }
364  UpdateVisibility();
365  }
366 
367  override void ClearSuspendRequests()
368  {
369  m_SuspendRequests.Clear();
370  UpdateVisibility();
371  }
372 
373  override int GetSuspendRequestCount()
374  {
375  return m_SuspendRequests.Count();
376  }
377 
379  override void UpdateWidgets(int type = -1, float timeSlice = 0, Param p = null, int handle = -1)
380  {
382  array<ref Widget> widget_set;
383 
384  if (type == EffectWidgetsTypes.ROOT)
385  {
386  HandleWidgetRoot(timeSlice,p,handle);
387  }
388  else if (type == -1) //update stuff from the m_UpdatingEffects
389  {
390  int type_widgetset = 0;
391  for (int i = 0; i < m_UpdatingEffects.Count(); i++)
392  {
393  if (m_RunningEffects.Find(m_UpdatingEffects.Get(i)) != -1)
394  {
395  type_widgetset = m_UpdatingEffects.Get(i);
396 
397  dta = m_WidgetDataMap.Get(type_widgetset);
398 
399  if (dta.HasDefinedHandle() && dta.DataInitialized())
400  {
401  dta.Update(timeSlice,p,handle); //calculate and apply
402  }
403  else
404  {
405  CalculateValues(type_widgetset,timeSlice,p,handle);
406  widget_set = dta.GetWidgetSet();
407  foreach (Widget w : widget_set)
408  {
409  if (w.IsVisibleHierarchy() && m_UpdatedWidgetsCheck.Find(w) == -1)
410  {
411  m_UpdatedWidgetsCheck.Insert(w);
412  ProcessWidgetUpdate(w,type_widgetset,timeSlice,p,handle);
413  }
414  }
415  }
416  }
417  }
418  }
419  else //update specific widget set
420  {
421  if (m_RunningEffects.Find(type) != -1) //only do if the effect is running (FPS stonks!)
422  {
423  dta = m_WidgetDataMap.Get(type);
424 
425  if (dta.HasDefinedHandle() && dta.DataInitialized())
426  {
427  dta.Update(timeSlice,p,handle); //calculate and apply
428  }
429  else
430  {
431  CalculateValues(type,timeSlice,p,handle);
432  widget_set = dta.GetWidgetSet();
433  foreach (Widget w2 : widget_set)
434  {
435  if (w2.IsVisibleHierarchy() && m_UpdatedWidgetsCheck.Find(w2) == -1)
436  {
437  m_UpdatedWidgetsCheck.Insert(w2);
438  ProcessWidgetUpdate(w2,type,timeSlice,p,handle);
439  }
440  }
441  }
442  }
443  }
444 
445  m_UpdatedWidgetsCheck.Clear();
446  m_UpdatedWidgetSetsCheck.Clear();
447  }
448 
450  protected void CalculateValues(int type = -1, float timeSlice = 0, Param p = null, int handle = -1)
451  {
452  if (m_UpdatedWidgetSetsCheck.Find(m_WidgetDataMap.Get(type).GetWidgetSetID()) != -1)
453  {
454  //Print("skipped updating set ID " + m_WidgetDataMap.Get(type).GetWidgetSetID() + " | effect: " + type);
455  return;
456  }
457 
458  switch (type)
459  {
460  case EffectWidgetsTypes.MOTO_BREATH:
461  case EffectWidgetsTypes.HELMET_BREATH:
462  case EffectWidgetsTypes.MASK_BREATH:
463  {
464  CalculateBreathEffect(timeSlice);
465  }
466  break;
467 
468  case EffectWidgetsTypes.MOTO_OCCLUDER:
469  case EffectWidgetsTypes.EYEPATCH_OCCLUDER:
470  case EffectWidgetsTypes.HELMET_OCCLUDER:
471  case EffectWidgetsTypes.HELMET2_OCCLUDER:
472  case EffectWidgetsTypes.MASK_OCCLUDER:
473  {
474  CalculateOccluderEffect(type,timeSlice,p,handle);
475  }
476  break;
477 
478  case EffectWidgetsTypes.COVER_FLASHBANG:
479  {
480  CalculateFlashbangEffect(type,timeSlice,p,handle);
481  }
482  break;
483 
484  default:
485  return; //no need to calculate anything
486  break;
487  }
488 
489  m_UpdatedWidgetSetsCheck.Insert(m_WidgetDataMap.Get(type).GetWidgetSetID());
490  }
491 
492  protected void ProcessWidgetUpdate(Widget w, int type, float timeSlice = 0, Param p = null, int handle = -1)
493  {
494  switch (type)
495  {
496  case EffectWidgetsTypes.MOTO_BREATH:
497  case EffectWidgetsTypes.HELMET_BREATH:
498  case EffectWidgetsTypes.MASK_BREATH:
499  {
500  UpdateBreathEffect(ImageWidget.Cast(w));
501  }
502  break;
503 
504  case EffectWidgetsTypes.MOTO_OCCLUDER:
505  case EffectWidgetsTypes.EYEPATCH_OCCLUDER:
506  case EffectWidgetsTypes.HELMET_OCCLUDER:
507  case EffectWidgetsTypes.HELMET2_OCCLUDER:
508  case EffectWidgetsTypes.MASK_OCCLUDER:
509  {
510  UpdateOccluderEffect(ImageWidget.Cast(w),type,timeSlice,p,handle);
511  }
512  break;
513 
514  case EffectWidgetsTypes.COVER_FLASHBANG:
515  {
516  UpdateFlashbangEffect(ImageWidget.Cast(w));
517  }
518  break;
519 
520  default:
521  //Print("---invalid widget type to update---");
522  break;
523  }
524  }
525 
526  //-----------------------------------------
527  //specific widget 'handlers'
528 
529  const float BREATH_HDR_MIN = 0.005; //dusk?
530  const float BREATH_HDR_MAX = 1.0; //dark?
531  const float BREATH_COLOR_MULT_MIN = 0.5;
532  const float BREATH_COLOR_MULT_MAX = 0.8;
533 
534  //-----------------------------------------
535  //Breath
536  //-----------------------------------------
537  protected void CalculateBreathEffect(float timeSlice = 0, int type = -1, Param p = null)
538  {
539  float modifier = Math.Lerp(0.25, 0.5, m_BreathResidue);
540  float speed = timeSlice * modifier;
541  m_BreathResidue -= speed;
542  m_BreathResidue = Math.Clamp(m_BreathResidue,0,1);
543  float residue_final = Math.Lerp(0, 0.7, m_BreathResidue);
544 
545  float hdr_mult;
546  hdr_mult = GetSceneHDRMul(0);
547  hdr_mult = Math.Clamp(hdr_mult,BREATH_HDR_MIN,BREATH_HDR_MAX);
548  hdr_mult = Math.InverseLerp(BREATH_HDR_MIN,BREATH_HDR_MAX,hdr_mult);
549  hdr_mult = Math.Lerp(BREATH_COLOR_MULT_MAX,BREATH_COLOR_MULT_MIN,hdr_mult);
550  m_BreathColor = ARGBF(0.0,1.0 * hdr_mult,1.0 * hdr_mult,1.0 * hdr_mult); //grayscaling of the image
551 
552 
553  m_BreathAlphaVal = Math.Lerp(m_BreathAlphaVal, residue_final, timeSlice);
554  }
555 
556  protected void UpdateBreathEffect(ImageWidget w)
557  {
558  w.SetColor(m_BreathColor);
559  w.SetAlpha(m_BreathAlphaVal);
560  }
561 
562  //-----------------------------------------
563  //Occluders
564  //-----------------------------------------
565  protected void CalculateOccluderEffect(int type, float timeSlice, Param p, int handle)
566  {
567  }
568 
569  protected void UpdateOccluderEffect(ImageWidget w, int type, float timeSlice, Param p, int handle)
570  {
571  }
572 
573  //-----------------------------------------
574  //Flashbang
575  //-----------------------------------------
576  protected void CalculateFlashbangEffect(int type, float timeSlice, Param p, int handle)
577  {
578  Param1<float> par = Param1<float>.Cast(p);
579  m_FlashbangCoverAlphaVal = par.param1;
580 
581  /*if (m_FlashbangCoverAlphaVal <= 0.0)
582  {
583  RemoveActiveEffects({EffectWidgetsTypes.COVER_FLASHBANG});
584  return;
585  }*/
586  }
587 
588  protected void UpdateFlashbangEffect(ImageWidget w)
589  {
590  w.SetAlpha(1 - m_FlashbangCoverAlphaVal);
591  }
592 
593  //-----------------------------------------
594  //root handling (generic 'Widget', so mainly alpha and hiding?)
595  //-----------------------------------------
596  protected void HandleWidgetRoot(float timeSlice = 0, Param p = null, int handle = -1)
597  {
598  switch (handle)
599  {
600  default:
601  {
602  Param1<float> par = Param1<float>.Cast(p);
603  if (par)
604  {
605  float alpha_mod = Math.Clamp(par.param1,0.0,1.0);
606  //Print(alpha_mod);
607  m_Root.SetAlpha(alpha_mod);
608  }
609  }
610  break;
611  }
612  }
613 
614  //-----------------------------------------
616  override void Update(float timeSlice)
617  {
618  if (m_SuspendRequests.Count() > 0)
619  {
620  return;
621  }
622 
623  UpdateWidgets(-1,timeSlice);
624  }
625 
626  /*
627  override void SetBreathIntensityStamina(float stamina_cap, float stamina_current)
628  {
629  float stamina_normalized = Math.InverseLerp(0, stamina_cap, stamina_current);
630  stamina_normalized = Math.Clamp(stamina_normalized,0,1);
631 
632  if ( stamina_normalized < STAMINA_SOUND_TR2 )
633  {
634  m_BreathMultStamina = 2.0;
635  }
636  else if ( stamina_normalized < STAMINA_SOUND_TR1 )
637  {
638  m_BreathMultStamina = 1.5;
639  }
640  else
641  {
642  m_BreathMultStamina = 1.0;
643  }
644  }
645  */
646  override void OnVoiceEvent(float breathing_resistance01)
647  {
648  m_BreathResidue += Math.Lerp(0,0.35,breathing_resistance01);
649  m_BreathResidue = Math.Clamp(m_BreathResidue,0,1);
650  }
651 }
GetGame
proto native CGame GetGame()
Param
Base Param Class with no parameters. Used as general purpose parameter overloaded with Param1 to Para...
Definition: param.c:11
GameplayEffectsDataImage
void GameplayEffectsDataImage(array< ref Widget > input, int type, int user_override=-1)
Definition: gewidgetsmetadata.c:77
Print
proto void Print(void var)
Prints content of variable to console/log.
GetSceneHDRMul
proto native float GetSceneHDRMul(int camera)
GameplayEffectDataMap
map< int, ref GameplayEffectsData > GameplayEffectDataMap
Definition: gewidgetsmetadata.c:105
map
map
Definition: controlsxboxnew.c:3
ARGBF
int ARGBF(float fa, float fr, float fg, float fb)
Converts <0.0, 1.0> ARGB into color.
Definition: proto.c:332
array
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
Definition: isboxcollidinggeometryproxyclasses.c:27
Update
proto native volatile void Update()
Definition: playersoundmanager.c:125
WidgetFlags
WidgetFlags
Definition: enwidgets.c:57
StopAllEffects
void StopAllEffects(int mask=0)
stops all effects of a certain kind
Definition: ppemanager.c:379
GameplayEffectWidgets_base
grouped gameplay effect widgets and their handling
Definition: gameplayeffectwidgets.c:6
Widget
Definition: enwidgets.c:189
Math
Definition: enmath.c:6
m_Root
protected Widget m_Root
Definition: sizetochild.c:91
Count
@ Count
Definition: randomgeneratorsyncmanager.c:7
GameplayEffectsData
Manages all bleeding indicators and their updates.
Definition: gewidgetsmetadatableeding.c:3
path
string path
Definition: optionselectormultistate.c:135