10 protected ref set<ref Widget> m_UniqueLayouts;
12 protected ref set<int> m_RunningEffects;
13 protected ref set<int> m_RunningEffectsPrevious;
16 protected ref
array<int> m_UpdatedWidgetSetsCheck;
17 protected ref set<int> m_SuspendRequests;
20 protected float m_TimeProgBreath;
21 protected float m_BreathMultStamina;
22 protected float m_BreathResidue;
25 protected const int WIDGETSET_BREATH = 100;
28 protected int m_BreathColor;
29 protected float m_BreathAlphaVal;
30 protected float m_FlashbangCoverAlphaVal;
32 void GameplayEffectWidgets()
36 m_UniqueLayouts =
new set<ref Widget>;
38 m_RunningEffects =
new set<int>;
39 m_RunningEffectsPrevious =
new set<int>;
43 m_SuspendRequests =
new set<int>;
46 m_TimeProgBreath = 0.0;
47 m_BreathMultStamina = 1.0;
51 RegisterLayouts(
"gui/layouts/gameplay/CameraEffects.layout",CompileEffectListing());
52 RegisterLayouts(
"gui/layouts/gameplay/BleedingEffects.layout",{EffectWidgetsTypes.BLEEDING_LAYER});
54 InitWidgetSet(EffectWidgetsTypes.MASK_BREATH,
true,WIDGETSET_BREATH);
55 InitWidgetSet(EffectWidgetsTypes.HELMET_BREATH,
true,WIDGETSET_BREATH);
56 InitWidgetSet(EffectWidgetsTypes.MOTO_BREATH,
true,WIDGETSET_BREATH);
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);
66 InitWidgetSet(EffectWidgetsTypes.COVER_FLASHBANG);
68 InitWidgetSet(EffectWidgetsTypes.BLEEDING_LAYER,
true);
73 void ~GameplayEffectWidgets()
75 for (
int i = 0; i < m_Layouts.Count(); i++)
77 if (m_Layouts.GetElement(i))
78 m_Layouts.GetElement(i).Unlink();
89 m_UniqueLayouts.Insert(w);
91 foreach (
int i : types)
97 protected void PairIDToTypes()
99 m_IDToTypeMap.Insert(EffectWidgetsTypes.BLEEDING_LAYER,GameplayEffectsDataBleeding);
102 protected typename TranslateIDToType(
int typeID)
104 return m_IDToTypeMap.Get(typeID);
107 override void RegisterGameplayEffectData(
int id,
Param p)
109 if (!m_WidgetDataMap.Get(
id).DataInitialized())
111 m_WidgetDataMap.Get(
id).RegisterData(p);
125 protected void InitWidgetSet(
int type,
bool updating =
false,
int user_id_override = -1)
128 if (user_id_override != -1)
130 parent = m_Layouts.Get(type).FindAnyWidgetById(user_id_override);
134 parent = m_Layouts.Get(type).FindAnyWidgetById(type);
139 Print(
"InitWidgetSet | type: " + type +
" - parent not found!");
144 Widget w = parent.GetChildren();
157 if (parent.GetChildren())
159 typename handled_type = TranslateIDToType(type);
162 CreateHandledClass(handled_type,output,type,user_id_override);
166 if (ImageWidget.Cast(parent.GetChildren()))
178 m_UpdatingEffects.Insert(type);
182 bool CreateHandledClass(
typename handled_type,
array<ref Widget> input,
int type,
int user_override)
187 data.Init(input,type,m_Layouts.Get(type),user_override);
188 m_WidgetDataMap.Set(type, data);
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);
213 protected void UpdateVisibility()
218 int runningEffectCount = m_RunningEffects.Count();
219 bool runningEffectsPresent = runningEffectCount > 0;
221 for (
int i = 0; i < m_RunningEffectsPrevious.Count(); i++)
223 value = m_RunningEffectsPrevious.Get(i);
224 dta = m_WidgetDataMap.Get(value);
225 if (runningEffectCount < 1 || m_RunningEffects.Find(value) == -1)
227 if (dta.HasDefinedHandle())
229 dta.UpdateVisibility(
false);
233 for (
int j = 0; j < m_WidgetDataMap.Get(value).GetWidgetSet().
Count(); j++)
235 w = m_WidgetDataMap.Get(value).GetWidgetSet().Get(j);
238 w.GetParent().Show(
false);
244 if (runningEffectsPresent)
247 for (i = 0; i < runningEffectCount; i++)
249 value = m_RunningEffects.Get(i);
250 dta = m_WidgetDataMap.Get(value);
251 if (dta.HasDefinedHandle())
253 dta.m_LayoutRoot.Show(
true);
254 dta.UpdateVisibility(
true);
258 for (j = 0; j < m_WidgetDataMap.Get(value).GetWidgetSet().
Count(); j++)
260 w = m_WidgetDataMap.Get(value).GetWidgetSet().Get(j);
277 m_Root.Show(runningEffectsPresent && m_SuspendRequests.Count() < 1);
278 m_RunningEffectsPrevious.Clear();
281 override void AddActiveEffects(
array<int> effects)
283 if (effects && effects.Count() > 0)
285 m_RunningEffectsPrevious.Copy(m_RunningEffects);
288 for (
int i = 0; i < effects.Count(); i++)
290 value = effects.Get(i);
291 m_RunningEffects.Insert(value);
294 if (m_RunningEffectsPrevious.Count() != m_RunningEffects.Count())
301 override void RemoveActiveEffects(
array<int> effects)
303 if (effects && effects.Count() > 0)
305 m_RunningEffectsPrevious.Copy(m_RunningEffects);
309 for (
int i = 0; i < effects.Count(); i++)
311 value = effects.Get(i);
312 idx = m_RunningEffects.Find(value);
315 m_RunningEffects.Remove(idx);
319 if (m_RunningEffectsPrevious.Count() != m_RunningEffects.Count())
330 if (IsAnyEffectRunning())
332 int count = m_RunningEffects.Count();
334 for (
int i = 0; i < count; i++)
336 data = m_WidgetDataMap.Get(m_RunningEffects[i]);
341 m_RunningEffectsPrevious.Copy(m_RunningEffects);
342 m_RunningEffects.Clear();
346 override bool IsAnyEffectRunning()
348 return m_RunningEffects && m_RunningEffects.Count() > 0;
351 override void AddSuspendRequest(
int request_id)
353 m_SuspendRequests.Insert(request_id);
357 override void RemoveSuspendRequest(
int request_id)
359 int idx = m_SuspendRequests.Find(request_id);
362 m_SuspendRequests.Remove(idx);
367 override void ClearSuspendRequests()
369 m_SuspendRequests.Clear();
373 override int GetSuspendRequestCount()
375 return m_SuspendRequests.Count();
379 override void UpdateWidgets(
int type = -1,
float timeSlice = 0,
Param p =
null,
int handle = -1)
384 if (type == EffectWidgetsTypes.ROOT)
386 HandleWidgetRoot(timeSlice,p,handle);
390 int type_widgetset = 0;
391 for (
int i = 0; i < m_UpdatingEffects.Count(); i++)
393 if (m_RunningEffects.Find(m_UpdatingEffects.Get(i)) != -1)
395 type_widgetset = m_UpdatingEffects.Get(i);
397 dta = m_WidgetDataMap.Get(type_widgetset);
399 if (dta.HasDefinedHandle() && dta.DataInitialized())
401 dta.Update(timeSlice,p,handle);
405 CalculateValues(type_widgetset,timeSlice,p,handle);
406 widget_set = dta.GetWidgetSet();
407 foreach (
Widget w : widget_set)
409 if (w.IsVisibleHierarchy() && m_UpdatedWidgetsCheck.Find(w) == -1)
411 m_UpdatedWidgetsCheck.Insert(w);
412 ProcessWidgetUpdate(w,type_widgetset,timeSlice,p,handle);
421 if (m_RunningEffects.Find(type) != -1)
423 dta = m_WidgetDataMap.Get(type);
425 if (dta.HasDefinedHandle() && dta.DataInitialized())
427 dta.Update(timeSlice,p,handle);
431 CalculateValues(type,timeSlice,p,handle);
432 widget_set = dta.GetWidgetSet();
433 foreach (
Widget w2 : widget_set)
435 if (w2.IsVisibleHierarchy() && m_UpdatedWidgetsCheck.Find(w2) == -1)
437 m_UpdatedWidgetsCheck.Insert(w2);
438 ProcessWidgetUpdate(w2,type,timeSlice,p,handle);
445 m_UpdatedWidgetsCheck.Clear();
446 m_UpdatedWidgetSetsCheck.Clear();
450 protected void CalculateValues(
int type = -1,
float timeSlice = 0,
Param p =
null,
int handle = -1)
452 if (m_UpdatedWidgetSetsCheck.Find(m_WidgetDataMap.Get(type).GetWidgetSetID()) != -1)
460 case EffectWidgetsTypes.MOTO_BREATH:
461 case EffectWidgetsTypes.HELMET_BREATH:
462 case EffectWidgetsTypes.MASK_BREATH:
464 CalculateBreathEffect(timeSlice);
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:
474 CalculateOccluderEffect(type,timeSlice,p,handle);
478 case EffectWidgetsTypes.COVER_FLASHBANG:
480 CalculateFlashbangEffect(type,timeSlice,p,handle);
489 m_UpdatedWidgetSetsCheck.Insert(m_WidgetDataMap.Get(type).GetWidgetSetID());
492 protected void ProcessWidgetUpdate(
Widget w,
int type,
float timeSlice = 0,
Param p =
null,
int handle = -1)
496 case EffectWidgetsTypes.MOTO_BREATH:
497 case EffectWidgetsTypes.HELMET_BREATH:
498 case EffectWidgetsTypes.MASK_BREATH:
500 UpdateBreathEffect(ImageWidget.Cast(w));
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:
510 UpdateOccluderEffect(ImageWidget.Cast(w),type,timeSlice,p,handle);
514 case EffectWidgetsTypes.COVER_FLASHBANG:
516 UpdateFlashbangEffect(ImageWidget.Cast(w));
529 const float BREATH_HDR_MIN = 0.005;
530 const float BREATH_HDR_MAX = 1.0;
531 const float BREATH_COLOR_MULT_MIN = 0.5;
532 const float BREATH_COLOR_MULT_MAX = 0.8;
537 protected void CalculateBreathEffect(
float timeSlice = 0,
int type = -1,
Param p =
null)
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);
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);
553 m_BreathAlphaVal =
Math.Lerp(m_BreathAlphaVal, residue_final, timeSlice);
556 protected void UpdateBreathEffect(ImageWidget w)
558 w.SetColor(m_BreathColor);
559 w.SetAlpha(m_BreathAlphaVal);
565 protected void CalculateOccluderEffect(
int type,
float timeSlice,
Param p,
int handle)
569 protected void UpdateOccluderEffect(ImageWidget w,
int type,
float timeSlice,
Param p,
int handle)
576 protected void CalculateFlashbangEffect(
int type,
float timeSlice,
Param p,
int handle)
578 Param1<float> par = Param1<float>.Cast(p);
579 m_FlashbangCoverAlphaVal = par.param1;
588 protected void UpdateFlashbangEffect(ImageWidget w)
590 w.SetAlpha(1 - m_FlashbangCoverAlphaVal);
596 protected void HandleWidgetRoot(
float timeSlice = 0,
Param p =
null,
int handle = -1)
602 Param1<float> par = Param1<float>.Cast(p);
605 float alpha_mod =
Math.Clamp(par.param1,0.0,1.0);
607 m_Root.SetAlpha(alpha_mod);
616 override void Update(
float timeSlice)
618 if (m_SuspendRequests.Count() > 0)
623 UpdateWidgets(-1,timeSlice);
646 override void OnVoiceEvent(
float breathing_resistance01)
648 m_BreathResidue +=
Math.Lerp(0,0.35,breathing_resistance01);
649 m_BreathResidue =
Math.Clamp(m_BreathResidue,0,1);