Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_WeaponInfo.c
Go to the documentation of this file.
1 //#define WEAPON_INFO_DEBUG
2 //#define WEAPON_INFO_DEBUG_STATES
3 
4 //#define WEAPON_INFO_DEBUG_WATERFALL_EVENTS
5 //#define WEAPON_INFO_BLOCK_WATERFALL_EVENTS
6 
7 // Will enable lots of logging on every event
8 // Can define it through -scrDefine WEAPON_INFO_DEBUG
9 
11 {
12  /*UNDEFINED = 0,*/
13  FMJ = 1,
14  TRACER = 2,
15  AP = 4,
16  HE = 8,
17  HEAT = 16,
18  FRAG = 32,
19  SMOKE = 64,
20  INCENDIARY = 128,
21  SNIPER = 256
22 };
23 
25 {
26  NONE = 0,
27  ZEROING = 1,
28  FIREMODE = 2,
29  AMMOCOUNT = 4,
30  MAGAZINE = 8,
31  MUZZLE = 16,
32  WEAPON = 32,
33  ADS = 64,
35  INSPECTION = 256,
36  ZOOM = 512,
37  RELOADING = 1024,
38  MISC = 32768
39 };
40 
41 class SCR_WeaponInfo : SCR_InfoDisplayExtended
42 {
43  #ifdef WEAPON_INFO_DEBUG
44  static void _print(string str)
45  {
46  int hour, minute, second;
47  System.GetHourMinuteSecondUTC(hour, minute, second);
48  string timeStr = string.Format("%1.%2.%3", hour, minute, second);
49  Print(string.Format("%1 [Weapon Info UI] %2", timeStr, str), LogLevel.DEBUG);
50  }
51  #endif
52 
53  const float SCALE_DEFAULT = 0.6;
54  const float SCALE_FIREMODE = 0.4;
55  const float SCALE_MAGAZINE = 0.6;
56 
57  const float UPDATE_INTERVAL = 0.1;
58  const float FADED_OPACITY = 0.3;
59 
60  const ref Color COLOR_WHITE = Color.FromSRGBA(255, 255, 255, 255);
61  const ref Color COLOR_ORANGE = Color.FromSRGBA(226, 167, 79, 255);
62 
63  protected const float FADEOUT_PANEL_DELAY = 6; // Time until whole panel fades out
64  protected const float FADEOUT_OPTICS_DELAY = 6; // Time until zeroing fades out
65  protected const float FADEOUT_AMMO_TYPE_DELAY = 6; // Time until ammo type fades out
66 
67  protected BaseWeaponManagerComponent m_WeaponManager;
68  protected SCR_InventoryStorageManagerComponent m_InventoryManager;
69  protected CompartmentAccessComponent m_CompartmentAccess;
70 
71  // Members for previous states of weapon
72  protected ref SCR_WeaponState m_WeaponState;
73 
74  protected EWeaponFeature m_eWeaponStateEvent = EWeaponFeature.NONE;
75 
76  // Resources
77  protected const ResourceName DEFAULT_WEAPON_INFO_LAYOUT = "{8170DE93810F928A}UI/layouts/HUD/WeaponInfo/WeaponInfo.layout";
78  protected const ResourceName DEFAULT_MAGAZINE_INDICATOR = "{7C114BA7C59E198D}Configs/WeaponInfo/MagazineIndicators/box.conf";
79 
80  // Widgets
81  ref SCR_WeaponInfoWidgets m_Widgets;
82 
83  protected ref SCR_FadeInOutAnimator m_WeaponInfoPanelAnimator;
84  protected ref SCR_FadeInOutAnimator m_ZeroingAnimator;
85 
86  protected bool m_bFadeInOutActive = false;
87 
88  // Other
89  ref SCR_MagazinePredicate m_pMagazineSearchPredicate = new SCR_MagazinePredicate(); // Predicate for searching for magazines
90  ref SCR_PrefabDataPredicate m_pPrefabDataPredicate = new SCR_PrefabDataPredicate();
91 
92  //------------------------------------------------------------------------------------------------
93  void OnWeaponChanged(BaseWeaponComponent weapon, BaseWeaponComponent prevWeapon)
94  {
95  #ifdef WEAPON_INFO_DEBUG
96  _print("OnWeaponChanged");
97  _print(string.Format(" weapon: %1", weapon));
98  #endif
99 
100  // Set weapon state change flag
101  m_eWeaponStateEvent |= EWeaponFeature.WEAPON;
102 
103  // In case of grenades, the provided weapon is a weapon slot, with the actual grenade inside this slot
104  WeaponSlotComponent weaponSlot = WeaponSlotComponent.Cast(weapon);
105 
106  if (weaponSlot)
107  {
108  IEntity e = weaponSlot.GetWeaponEntity();
109 
110  if (e)
111  weapon = BaseWeaponComponent.Cast(e.FindComponent(BaseWeaponComponent));
112  else
113  weapon = null;
114  }
115 
116  // Initialize weapon state from our current weapon
117  if (!m_WeaponState)
118  m_WeaponState = new SCR_WeaponState();
119 
120  if (m_WeaponState.m_Weapon != weapon)
121  {
122  // Remove any possible existing "zoom-changed" invokers
123  if (m_WeaponState.m_SightsZoomFOVInfo)
124  m_WeaponState.m_SightsZoomFOVInfo.GetEventOnZoomChanged().Remove(OnZoomChanged);
125 
126  // Wipe the weapon state data
127  m_WeaponState.Init();
128  }
129 
130  // Store current weapon
131  m_WeaponState.m_Weapon = weapon;
132 
133  // Hide weapon UI if there is no weapon equipped and stop
134  Show(weapon != null);
135 
136  if (!weapon)
137  return;
138 
139  // Get weapon & grenade UI info
140  m_WeaponState.m_WeaponUI = WeaponUIInfo.Cast(weapon.GetUIInfo());
141  m_WeaponState.m_GrenadeUI = GrenadeUIInfo.Cast(m_WeaponState.m_WeaponUI);
142 
143  // If weapon is a grenade, get its type
144  if (m_WeaponState.m_GrenadeUI)
145  {
146  m_WeaponState.m_eAmmoTypeFlags = m_WeaponState.m_GrenadeUI.GetAmmoTypeFlags();
147  m_WeaponState.m_bHasSpecialAmmo = !(m_WeaponState.m_eAmmoTypeFlags == 0 || m_WeaponState.m_eAmmoTypeFlags & EAmmoType.FMJ);
148 
149  m_WeaponState.m_MagazineConfig = m_WeaponState.m_GrenadeUI.m_MagIndicator;
150  }
151 
152  // Check if weapon is a grenade
153  IEntity e = weapon.GetOwner();
154 
155  if ((e && e.FindComponent(GrenadeMoveComponent)) || SCR_MineWeaponComponent.Cast(weapon))
156  m_WeaponState.m_bIsExplosive = true;
157  else
158  m_WeaponState.m_bIsExplosive = false;
159 
160  // Check if weapon has scope sights component
161  m_WeaponState.m_Sights = GetSights();
162  m_WeaponState.m_SightsZoomFOVInfo = null;
163 
164  if (m_WeaponState.m_Sights)
165  m_WeaponState.m_SightsZoomFOVInfo = SCR_SightsZoomFOVInfo.Cast(m_WeaponState.m_Sights.GetFOVInfo());
166 
167  if (m_WeaponState.m_SightsZoomFOVInfo)
168  m_WeaponState.m_SightsZoomFOVInfo.GetEventOnZoomChanged().Insert(OnZoomChanged);
169 
170  // Auto-trigger child events
171  #ifndef WEAPON_INFO_BLOCK_WATERFALL_EVENTS
172  OnMuzzleChanged_init(weapon);
173  OnADSChanged_init(weapon);
174  #endif
175  }
176 
177  //------------------------------------------------------------------------------------------------
178  void OnMuzzleChanged_init(BaseWeaponComponent weapon)
179  {
180  BaseMuzzleComponent muzzle;
181 
182  if (weapon)
183  muzzle = weapon.GetCurrentMuzzle();
184 
185  #ifdef WEAPON_INFO_DEBUG_WATERFALL_EVENTS
186  Print("OnMuzzleChanged_init");
187  Print(string.Format(" weapon: %1", weapon));
188  Print(string.Format(" muzzle: %1", muzzle));
189  #endif
190 
191  OnMuzzleChanged(weapon, muzzle, null);
192  }
193  void OnMuzzleChanged(BaseWeaponComponent weapon, BaseMuzzleComponent muzzle, BaseMuzzleComponent prevMuzzle)
194  {
195  if (!m_WeaponState)
196  return;
197 
198  #ifdef WEAPON_INFO_DEBUG
199  _print("OnMuzzleChanged");
200  _print(string.Format(" weapon: %1", weapon));
201  _print(string.Format(" muzzle: %1", muzzle));
202  #endif
203 
204  m_eWeaponStateEvent |= EWeaponFeature.MUZZLE;
205 
206  m_WeaponState.m_Muzzle = muzzle;
207 
208  if (!muzzle)
209  {
210  // GRENADE
211 
212  m_WeaponState.m_MuzzleUI = null;
213  m_WeaponState.m_bBarrelChambered = false;
214  m_WeaponState.m_bBarrelCanBeChambered = false;
215  }
216  else
217  {
218  // NON-GRENADE
219 
220  m_WeaponState.m_MuzzleUI = MuzzleUIInfo.Cast(muzzle.GetUIInfo());
221  m_WeaponState.m_bBarrelChambered = muzzle.IsBarrelChambered(muzzle.GetCurrentBarrelIndex());
222  m_WeaponState.m_bBarrelCanBeChambered = muzzle.IsChamberingPossible();
223  }
224 
225  // Update weapon name & caliber (mostly for vehicle weapons)
226  UpdateWeaponNameAndCaliber(m_WeaponState);
227 
228  // Auto-trigger child events
229  #ifndef WEAPON_INFO_BLOCK_WATERFALL_EVENTS
230  OnFiremodeChanged_init(weapon, muzzle);
231  OnZeroingChanged_init(weapon);
232  OnMagazineChanged_init(weapon, muzzle);
233  #endif
234  }
235 
236  //------------------------------------------------------------------------------------------------
237  void OnMagazineChanged_init(BaseWeaponComponent weapon, BaseMuzzleComponent muzzle)
238  {
239  BaseMagazineComponent magazine;
240 
241  if (muzzle)
242  magazine = muzzle.GetMagazine();
243 
244  #ifdef WEAPON_INFO_DEBUG_WATERFALL_EVENTS
245  _print("OnMagazineChanged_init");
246  _print(string.Format(" weapon: %1", weapon));
247  _print(string.Format(" muzzle: %1", muzzle));
248  _print(string.Format(" magazine: %1", magazine));
249  #endif
250 
251  OnMagazineChanged(weapon, magazine, null);
252  }
253  void OnMagazineChanged(BaseWeaponComponent weapon, BaseMagazineComponent magazine, BaseMagazineComponent prevMagazine)
254  {
255  if (!m_WeaponState)
256  return;
257 
258  #ifdef WEAPON_INFO_DEBUG
259  _print("OnMagazineChanged");
260  _print(string.Format(" weapon: %1", weapon));
261  _print(string.Format(" magazine: %1", magazine));
262  #endif
263 
264  // Set weapon state change flag
265  m_eWeaponStateEvent |= EWeaponFeature.MAGAZINE;
266 
267  m_WeaponState.m_Magazine = magazine;
268 
269  if (magazine)
270  m_WeaponState.m_MagazineUI = MagazineUIInfo.Cast(magazine.GetUIInfo());
271  else
272  m_WeaponState.m_MagazineUI = null;
273 
274  if (m_WeaponState.m_MagazineUI)
275  {
276  m_WeaponState.m_eAmmoTypeFlags = m_WeaponState.m_MagazineUI.GetAmmoTypeFlags();
277  m_WeaponState.m_bHasSpecialAmmo = !(m_WeaponState.m_eAmmoTypeFlags == 0 || m_WeaponState.m_eAmmoTypeFlags & EAmmoType.FMJ);
278  }
279 
280  // Initialize the magazine icon based on magazineUi > muzzleUi > weaponUi
281  m_WeaponState.m_MagazineConfig = GetMagazineConfig(m_WeaponState);
282 
283  #ifndef WEAPON_INFO_BLOCK_WATERFALL_EVENTS
284  OnMagazineCountChanged_init(weapon, magazine);
285  OnAmmoCountChanged_init(weapon, magazine);
286  #endif
287 
288  // Update magazine texture setup
289  UpdateMagazineIndicator_Textures(m_WeaponState);
290  UpdateAmmoTypeIndicator(m_WeaponState);
291  }
292 
293  //------------------------------------------------------------------------------------------------
294  void OnMagazineCountChanged_init(BaseWeaponComponent weapon, BaseMagazineComponent magazine)
295  {
296  BaseMuzzleComponent muzzle;
297 
298  if (weapon)
299  muzzle = weapon.GetCurrentMuzzle();
300 
301  #ifdef WEAPON_INFO_DEBUG_WATERFALL_EVENTS
302  _print("OnMagazineCountChanged_init");
303  _print(string.Format(" weapon: %1", weapon));
304  _print(string.Format(" muzzle: %1", muzzle));
305  _print(string.Format(" magazine: %1", magazine));
306  #endif
307 
308  // Get the character/vehicle inventory manager
309  InventoryStorageManagerComponent invManager = SCR_WeaponInfo.GetInventoryManager();
310 
311  if (!weapon || !invManager)
312  {
313  OnMagazineCountChanged(weapon, 0, false);
314  return;
315  }
316 
317  int magazineCount = 0;
318 
319  if (muzzle)
320  {
321  // WEAPON WITH MUZZLE -> NON-GRENADE
322 
323  // Find compatible magazines for this magazine well
324  BaseMagazineWell magWell = muzzle.GetMagazineWell();
325 
326  if (magWell)
327  {
328  m_pMagazineSearchPredicate.magWellType = magWell.Type();
329  array<IEntity> magEntities = new array<IEntity>;
330  invManager.FindItems(magEntities, m_pMagazineSearchPredicate);
331  magazineCount = magEntities.Count();
332  }
333  else
334  {
335  // No magazine well, weapon is probably not reloadable
336  magazineCount = 0;
337  }
338  }
339  else
340  {
341  // WEAPON WITHOUT MUZZLE -> GRENADE
342 
343  // Find compatible weapons (same grenades for instance)
344  m_pPrefabDataPredicate.prefabData = weapon.GetOwner().GetPrefabData();
345  array<IEntity> sameWeapons = new array<IEntity>;
346  invManager.FindItems(sameWeapons, m_pPrefabDataPredicate);
347 
348  // Remaining 'mags' count text
349  magazineCount = sameWeapons.Count();
350  }
351 
352  bool isGrenade = m_WeaponState.m_bIsExplosive;
353 
354  OnMagazineCountChanged(weapon, magazineCount, isGrenade);
355  }
356  void OnMagazineCountChanged(BaseWeaponComponent weapon, int magazineCount, bool isGrenade)
357  {
358  if (!m_WeaponState || !weapon)
359  return;
360 
361  #ifdef WEAPON_INFO_DEBUG
362  _print("OnMagazineCountChanged");
363  _print(string.Format(" weapon: %1", weapon));
364  _print(string.Format(" magazineCount: %1", magazineCount));
365  _print(string.Format(" isGrenade: %1", isGrenade));
366  #endif
367 
368  BaseMagazineComponent magazine = weapon.GetCurrentMagazine();
369  m_WeaponState.m_Magazine = magazine;
370 
371  // Set weapon state change flag
372  m_eWeaponStateEvent |= EWeaponFeature.MAGAZINE_COUNT;
373 
374  m_WeaponState.m_iMagCount = magazineCount;
375  m_WeaponState.m_bIsExplosive = isGrenade;
376 
377  // Update magazine textures for rocket and grenade launchers
378  // Magazine for rocket and grenade launchers gets deleted after firing
379  if (!magazine)
380  {
381  UpdateMagazineIndicator_Textures(m_WeaponState);
382  UpdateAmmoTypeIndicator(m_WeaponState);
383  }
384 
385  UpdateMagazineIndicator_Count(m_WeaponState);
386  }
387 
388  //------------------------------------------------------------------------------------------------
389  void OnAmmoCountChanged_init(BaseWeaponComponent weapon, BaseMagazineComponent magazine)
390  {
391  BaseMuzzleComponent muzzle;
392 
393  if (weapon)
394  muzzle = weapon.GetCurrentMuzzle();
395 
396  #ifdef WEAPON_INFO_DEBUG_WATERFALL_EVENTS
397  _print("OnAmmoCountChanged_init");
398  _print(string.Format(" weapon: %1", weapon));
399  _print(string.Format(" muzzle: %1", muzzle));
400  _print(string.Format(" magazine: %1", magazine));
401  #endif
402 
403  int ammoCount = 0;
404 
405  if (magazine)
406  ammoCount = magazine.GetAmmoCount();
407 
408  bool isBarrelChambered = false;
409 
410  if (muzzle)
411  isBarrelChambered = muzzle.IsCurrentBarrelChambered();
412 
413  OnAmmoCountChanged(weapon, muzzle, magazine, ammoCount, isBarrelChambered);
414  }
415  void OnAmmoCountChanged(BaseWeaponComponent weapon, BaseMuzzleComponent muzzle, BaseMagazineComponent magazine, int ammoCount, bool isBarrelChambered)
416  {
417  if (!m_WeaponState)
418  return;
419 
420  #ifdef WEAPON_INFO_DEBUG
421  _print("OnAmmoCountChanged");
422  _print(string.Format(" weapon: %1", weapon));
423  _print(string.Format(" muzzle: %1", muzzle));
424  _print(string.Format(" magazine: %1", magazine));
425  _print(string.Format(" ammoCount: %1", ammoCount));
426  _print(string.Format(" isBarrelChambered: %1", isBarrelChambered));
427  #endif
428 
429  // Set weapon state change flag
430  m_eWeaponStateEvent |= EWeaponFeature.AMMOCOUNT;
431 
432  m_WeaponState.m_bBarrelChambered = isBarrelChambered;
433 
434  m_WeaponState.m_iMagAmmoCount = ammoCount;
435  m_WeaponState.m_iMagMaxAmmoCount = 1;
436 
437  if (magazine)
438  m_WeaponState.m_iMagMaxAmmoCount = magazine.GetMaxAmmoCount();
439 
440  if (m_WeaponState.m_iMagMaxAmmoCount == 0)
441  m_WeaponState.m_iMagMaxAmmoCount = 1;
442 
443  m_WeaponState.m_fMagAmmoPerc = m_WeaponState.m_iMagAmmoCount / m_WeaponState.m_iMagMaxAmmoCount;
444 
445  if (magazine)
446  UpdateMagazineIndicator_Progress(m_WeaponState);
447 
448  UpdateBulletInChamberIndicator(m_WeaponState);
449  }
450 
451  //------------------------------------------------------------------------------------------------
452  void OnFiremodeChanged_init(BaseWeaponComponent weapon, BaseMuzzleComponent muzzle)
453  {
454  BaseFireMode firemode;
455 
456  if (muzzle)
457  firemode = muzzle.GetCurrentFireMode();
458 
459  #ifdef WEAPON_INFO_DEBUG_WATERFALL_EVENTS
460  _print("OnFiremodeChanged_init");
461  _print(string.Format(" weapon: %1", weapon));
462  _print(string.Format(" muzzle: %1", muzzle));
463  _print(string.Format(" firemode: %1", firemode));
464  #endif
465 
466  OnFiremodeChanged(weapon, muzzle, firemode);
467  }
468 
469  void OnFiremodeChanged(BaseWeaponComponent weapon, BaseMuzzleComponent muzzle, BaseFireMode firemode)
470  {
471  if (!m_WeaponState)
472  return;
473 
474  #ifdef WEAPON_INFO_DEBUG
475  _print("OnFiremodeChanged");
476  _print(string.Format(" weapon: %1", weapon));
477  _print(string.Format(" muzzle: %1", muzzle));
478  _print(string.Format(" firemode: %1", firemode));
479  #endif
480 
481  // Set weapon state change flag
482  m_eWeaponStateEvent |= EWeaponFeature.FIREMODE;
483 
484  if (firemode)
485  m_WeaponState.m_FireModeType = firemode.GetFiremodeType();
486  else
487  m_WeaponState.m_FireModeType = EWeaponFiremodeType.Semiauto;
488 
489  UpdateFireModeIndicator(m_WeaponState);
490  }
491 
492  //------------------------------------------------------------------------------------------------
493  void OnZeroingChanged_init(BaseWeaponComponent weapon)
494  {
495  int zeroing = 0;
496 
497  if (weapon)
498  zeroing = weapon.GetCurrentSightsZeroing();
499 
500  #ifdef WEAPON_INFO_DEBUG_WATERFALL_EVENTS
501  _print("OnZeroingChanged_init");
502  _print(string.Format(" weapon: %1", weapon));
503  _print(string.Format(" zeroing: %1", zeroing));
504  #endif
505 
506  OnZeroingChanged(weapon, zeroing);
507  }
508  void OnZeroingChanged(BaseWeaponComponent weapon, int zeroing)
509  {
510  if (!m_WeaponState)
511  return;
512 
513  #ifdef WEAPON_INFO_DEBUG
514  _print("OnZeroingChanged");
515  _print(string.Format(" weapon: %1", weapon));
516  _print(string.Format(" zeroing: %1", zeroing));
517  #endif
518 
519  // Set weapon state change flag
520  m_eWeaponStateEvent |= EWeaponFeature.ZEROING;
521 
522  m_WeaponState.m_iZeroing = zeroing;
523 
524  UpdateZeroingIndicator(m_WeaponState);
525  }
526 
527  //------------------------------------------------------------------------------------------------
528  void OnADSChanged_init(BaseWeaponComponent weapon)
529  {
530  bool inADS = false;
531 
532  if (weapon)
533  inADS = weapon.IsSightADSActive();
534 
535  #ifdef WEAPON_INFO_DEBUG_WATERFALL_EVENTS
536  _print("OnADSChanged_init");
537  _print(string.Format(" weapon: %1", weapon));
538  _print(string.Format(" inADS: %1", inADS));
539  #endif
540 
541  OnADSChanged(weapon, inADS);
542  }
543  void OnADSChanged(BaseWeaponComponent weapon, bool inADS)
544  {
545  if (!m_WeaponState)
546  return;
547 
548  #ifdef WEAPON_INFO_DEBUG
549  _print("OnADSChanged");
550  _print(string.Format(" weapon: %1", weapon));
551  _print(string.Format(" inADS: %1", inADS));
552  #endif
553 
554  // Set weapon state change flag
555  m_eWeaponStateEvent |= EWeaponFeature.ADS;
556 
557  m_WeaponState.m_bInADS = inADS;
558 
559  #ifndef WEAPON_INFO_BLOCK_WATERFALL_EVENTS
560  OnZoomChanged_init(weapon);
561  #endif
562  }
563 
564  //------------------------------------------------------------------------------------------------
565  void OnZoomChanged_init(BaseWeaponComponent weapon)
566  {
567  float zoom = 0;
568 
569  if (m_WeaponState.m_SightsZoomFOVInfo)
570  zoom = m_WeaponState.m_SightsZoomFOVInfo.GetCurrentZoom();
571 
572  #ifdef WEAPON_INFO_DEBUG_WATERFALL_EVENTS
573  _print("OnZoomChanged_init");
574  _print(string.Format(" weapon: %1", weapon));
575  _print(string.Format(" zoom: %1", zoom));
576  #endif
577 
578  OnZoomChanged(zoom, -1);
579  }
580  void OnZoomChanged(float zoom, float fov)
581  {
582  if (!m_WeaponState)
583  return;
584 
585  #ifdef WEAPON_INFO_DEBUG
586  _print("OnZoomChanged");
587  _print(string.Format(" zoom: %1", zoom));
588  _print(string.Format(" fov: %1", fov));
589  #endif
590 
591  // Set weapon state change flag
592  m_eWeaponStateEvent |= EWeaponFeature.ZOOM;
593 
594  m_WeaponState.m_fZoom = zoom;
595 
596  UpdateZoomIndicator(m_WeaponState);
597  }
598 
599  //------------------------------------------------------------------------------------------------
600  void OnInspectionModeChanged(bool state)
601  {
602  if (!m_WeaponState)
603  return;
604 
605  #ifdef WEAPON_INFO_DEBUG
606  _print("OnInspectionModeChanged");
607  _print(string.Format(" state: %1", state));
608  #endif
609 
610  // Set weapon state change flag
611  m_eWeaponStateEvent |= EWeaponFeature.INSPECTION;
612 
613  m_WeaponState.m_bInInspectionMode = state;
614  }
615 
616  //------------------------------------------------------------------------------------------------
617  void OnAttachmentChanged(WeaponComponent weapon, bool isAttached, IEntity attachmentEntity)
618  {
619  if (!m_WeaponState)
620  return;
621 
622  #ifdef WEAPON_INFO_DEBUG
623  _print("OnAttachmentChanged");
624  _print(string.Format(" isAttached: %1", isAttached));
625  _print(string.Format(" attachmentEntity: %1", attachmentEntity));
626  #endif
627 
628  SCR_2DSightsComponent sights = GetSights();
629 
630  // Sights has changed
631  if (sights != m_WeaponState.m_Sights)
632  {
633  // Remove any possible existing "zoom-changed" invokers
634  if (m_WeaponState.m_SightsZoomFOVInfo)
635  m_WeaponState.m_SightsZoomFOVInfo.GetEventOnZoomChanged().Remove(OnZoomChanged);
636 
637  m_WeaponState.m_Sights = sights;
638  m_WeaponState.m_SightsZoomFOVInfo = null;
639 
640  if (m_WeaponState.m_Sights)
641  m_WeaponState.m_SightsZoomFOVInfo = SCR_SightsZoomFOVInfo.Cast(m_WeaponState.m_Sights.GetFOVInfo());
642 
643  if (m_WeaponState.m_SightsZoomFOVInfo)
644  m_WeaponState.m_SightsZoomFOVInfo.GetEventOnZoomChanged().Insert(OnZoomChanged);
645  }
646 
647  if (!sights)
648  {
649  m_WeaponState.m_Sights = null;
650  m_WeaponState.m_SightsZoomFOVInfo = null;
651  }
652  }
653 
654 
655 
656  //------------------------------------------------------------------------------------------------
657  override void DisplayUpdate(IEntity owner, float timeSlice)
658  {
659  if (!m_wRoot || !m_WeaponState || !m_WeaponState.m_Weapon)
660  return;
661 
662  if (m_eWeaponStateEvent != EWeaponFeature.NONE)
663  {
664  FadeElements();
665 
666  m_eWeaponStateEvent = EWeaponFeature.NONE;
667 
668  m_bFadeInOutActive = true;
669  };
670 
671  if (!m_bFadeInOutActive)
672  return;
673 
674  if (m_ZeroingAnimator)
675  m_ZeroingAnimator.Update(timeSlice);
676  if (m_WeaponInfoPanelAnimator)
677  m_WeaponInfoPanelAnimator.Update(timeSlice);
678 
679  // Print(string.Format("[ANIM STATES] m_WeaponInfoPanelAnimator: %1 | m_ZeroingAnimator: %2", m_WeaponInfoPanelAnimator.GetState(), m_ZeroingAnimator.GetState()));
680 
681  m_bFadeInOutActive = m_WeaponInfoPanelAnimator.IsRunning() || m_ZeroingAnimator.IsRunning();
682  }
683 
684 
685  //------------------------------------------------------------------------------------------------
686  void FadeElements()
687  {
688  // Weapon state debug
689  #ifdef WEAPON_INFO_DEBUG_STATES
690  string weaponStateDebug = "Weapon event flags: " + m_eWeaponStateEvent.ToString();
691 
692  if (m_eWeaponStateEvent & EWeaponFeature.WEAPON)
693  weaponStateDebug += "|WEAPON";
694 
695  if (m_eWeaponStateEvent & EWeaponFeature.MUZZLE)
696  weaponStateDebug += "|MUZZLE";
697 
698  if (m_eWeaponStateEvent & EWeaponFeature.MAGAZINE)
699  weaponStateDebug += "|MAGAZINE";
700 
701  if (m_eWeaponStateEvent & EWeaponFeature.AMMOCOUNT)
702  weaponStateDebug += "|AMMOCOUNT";
703 
704  if (m_eWeaponStateEvent & EWeaponFeature.FIREMODE)
705  weaponStateDebug += "|FIREMODE";
706 
707  if (m_eWeaponStateEvent & EWeaponFeature.ZEROING)
708  weaponStateDebug += "|ZEROING";
709 
710  if (m_eWeaponStateEvent & EWeaponFeature.ADS)
711  weaponStateDebug += "|ADS";
712 
713  if (m_eWeaponStateEvent & EWeaponFeature.MAGAZINE_COUNT)
714  weaponStateDebug += "|MAGAZINE_COUNT";
715 
716  if (m_eWeaponStateEvent & EWeaponFeature.INSPECTION)
717  weaponStateDebug += "|INSPECTION";
718 
719  if (m_eWeaponStateEvent & EWeaponFeature.ZOOM)
720  weaponStateDebug += "|ZOOM";
721 
722  if (m_eWeaponStateEvent & EWeaponFeature.MISC)
723  weaponStateDebug += "|MISC";
724 
725  Print(weaponStateDebug);
726  #endif
727 
728  // Get some shared states / conditions for fading
729  //bool inspectingWeapon = m_CharacterController && m_CharacterController.GetIsInspectionMode();
730  bool isGrenade = m_WeaponState && m_WeaponState.m_bIsExplosive;
731  bool inADS = m_WeaponState && m_WeaponState.m_bInADS;
732  bool inInspection = m_WeaponState && m_WeaponState.m_bInInspectionMode;
733 
734  // Main weapon UI (magazine, magazine count, firemode) fadein
735  bool panelVisibleEvent = m_eWeaponStateEvent != 0;
736  bool panelVisibleOverride = isGrenade || inADS || inInspection;
737  if (panelVisibleEvent || panelVisibleOverride)
738  m_WeaponInfoPanelAnimator.FadeIn(!panelVisibleOverride);
739 
740  // Zeroing indicator fadein
741  bool zeroingWidgetHasText = !m_Widgets.m_ZeroingText.GetText().IsEmpty();
742  bool zeroingVisibleEvent = m_eWeaponStateEvent & (EWeaponFeature.ADS | EWeaponFeature.ZEROING | EWeaponFeature.MUZZLE | EWeaponFeature.WEAPON | EWeaponFeature.INSPECTION);
743  bool zeroingVisibleOverride = inADS || inInspection;
744  if (zeroingWidgetHasText && (zeroingVisibleEvent || zeroingVisibleOverride))
745  m_ZeroingAnimator.FadeIn(!zeroingVisibleOverride);
746  }
747 
748  //------------------------------------------------------------------------------------------------
749  SCR_2DSightsComponent GetSights()
750  {
751  SightsComponent sights = m_WeaponManager.GetCurrentSights();
752 
753  if (!sights)
754  return null;
755 
756  return SCR_2DSightsComponent.Cast(sights);
757  }
758 
759  //------------------------------------------------------------------------------------------------
760  SCR_MagazineIndicatorConfiguration GetMagazineConfig(SCR_WeaponState state)
761  {
762  if (!state)
763  return null;
764 
766 
767  if (state.m_Muzzle)
768  {
769  // WEAPON WITH MUZZLE
770  if (!state.m_MuzzleUI)
771  {
772  // No muzzle UI ?! Just hide it
773  config = null;
774  }
775  else
776  {
777 
778  if (state.m_Magazine)
779  {
780  // MAGAZINE IS IN THE GUN
781  config = state.m_MagazineUI.m_MagIndicator;
782 
783  if (!config)
784  config = state.m_MuzzleUI.m_MagIndicator;
785  }
786  else
787  {
788  // NO MAGAZINE
789  // Take mag configuration from muzzle
790 
791  config = state.m_MuzzleUI.m_MagIndicator;
792  }
793  }
794  }
795  else
796  {
797  // NO MUZZLE, probably weapon must provide icon
798  if (state.m_WeaponUI)
799  {
800  config = state.m_WeaponUI.m_MagIndicator;
801  }
802  else
803  {
804  config = null;
805  }
806  }
807 
808  return config;
809  }
810 
811  //------------------------------------------------------------------------------------------------
812  protected void UpdateMagazineIndicator_Textures(SCR_WeaponState state)
813  {
814  if (!state || !m_Widgets)
815  return;
816 
817  if (!state.m_MagazineConfig)
818  state.m_MagazineConfig = GetMagazineConfig(state);
819 
820  SCR_MagazineIndicatorConfiguration config = state.m_MagazineConfig;
821 
822  if (!config)
823  {
824  m_Widgets.m_MagazineIndicator.SetVisible(false);
825  }
826  else
827  {
828  m_Widgets.m_MagazineIndicator.SetVisible(true);
829 
830  if (config.m_bProgressBar)
831  {
832  SetWidgetImage(m_Widgets.m_MagazineOutline, config.m_sImagesetIcons, config.m_sOutline, SCALE_MAGAZINE);
833  SetWidgetImage(m_Widgets.m_MagazineBackground, config.m_sImagesetIcons, config.m_sBackground, SCALE_MAGAZINE);
834  SetWidgetImage(m_Widgets.m_MagazineGlow, config.m_sImagesetGlows, config.m_sBackground, SCALE_MAGAZINE);
835  }
836  else
837  {
838  SetWidgetImage(m_Widgets.m_MagazineOutline, config.m_sImagesetIcons, config.m_sOutline, SCALE_MAGAZINE);
839  //SetWidgetImage(m_Widgets.m_MagazineBackground, config.m_sImagesetIcons, config.m_sOutline, SCALE_MAGAZINE);
840  SetWidgetImage(m_Widgets.m_MagazineGlow, config.m_sImagesetGlows, config.m_sOutline, SCALE_MAGAZINE);
841  }
842 
843  // Setup textures for reloading indicator
844  SetWidgetImage(m_Widgets.m_ReloadBackground, config.m_sImagesetIcons, config.m_sProgress, SCALE_MAGAZINE);
845  m_Widgets.m_ReloadBackground.SetVisible(false);
846  SetWidgetImage(m_Widgets.m_ReloadOutline, config.m_sImagesetIcons, config.m_sOutline, SCALE_MAGAZINE);
847  m_Widgets.m_ReloadOutline.SetVisible(false);
848 
849 
850  // Setup visibility, keep only Outline texture, if there is no progress indication
851  m_Widgets.m_MagazineProgress.SetVisible(config.m_bProgressBar && state.m_Magazine);
852  m_Widgets.m_MagazineBackground.SetVisible(config.m_bProgressBar);
853  m_Widgets.m_MagazineOutline.SetOpacity(1);
854 
855  if (state.m_Magazine)
856  {
857  if (config.m_bProgressBar)
858  {
859  SetWidgetImage(m_Widgets.m_MagazineProgress, config.m_sImagesetIcons, config.m_sProgress, SCALE_MAGAZINE);
860  m_Widgets.m_MagazineProgress.LoadMaskFromSet(config.m_sImagesetIcons, config.m_sProgressAlphaMask);
861  m_Widgets.m_MagazineProgress.SetMaskMode(ImageMaskMode.REGULAR);
862  }
863  }
864  else
865  {
866  if (!state.m_bIsExplosive)
867  m_Widgets.m_MagazineOutline.SetOpacity(FADED_OPACITY);
868  }
869 
870  //AnimateWidget_ColorFlash(m_Widgets.m_MagazineIndicator);
871  }
872  }
873 
874  //------------------------------------------------------------------------------------------------
875  protected void UpdateMagazineIndicator_Progress(SCR_WeaponState state)
876  {
877  if (!state || !m_Widgets)
878  return;
879 
880  //AnimateWidget_ColorFlash(m_Widgets.m_MagazineIndicator, EWeaponFeature.AMMOCOUNT);
881 
882  m_Widgets.m_MagazineProgress.SetMaskProgress(state.m_fMagAmmoPerc);
883  }
884 
885  //------------------------------------------------------------------------------------------------
886  protected void UpdateMagazineIndicator_Count(SCR_WeaponState state)
887  {
888  if (!state || !m_Widgets)
889  return;
890 
891  int count = state.m_iMagCount;
892 
893  // Add +1 if weapon is a grenade, so it shows the total # of grenades in possession
894  if (state.m_bIsExplosive)
895  count++;
896 
897  string countText = count.ToString();
898 
899  /*
900  if (!state.m_bIsExplosive)
901  countText = "+" + countText;
902  */
903 
904  if (count > 0)
905  m_Widgets.m_MagCountText.SetOpacity(1);
906  else
907  m_Widgets.m_MagCountText.SetOpacity(FADED_OPACITY);
908 
909  if (m_Widgets.m_MagCountText.GetText() == countText)
910  return;
911 
912  m_Widgets.m_MagCountText.SetText(countText);
913 
914  AnimateWidget_ColorFlash(m_Widgets.m_MagCountText, EWeaponFeature.MAGAZINE_COUNT);
915  AnimateWidget_TextPopUp(m_Widgets.m_MagCountText, 36, 54, EWeaponFeature.MAGAZINE_COUNT);
916  }
917 
918  //------------------------------------------------------------------------------------------------
919  protected void UpdateBulletInChamberIndicator(SCR_WeaponState state)
920  {
921  if (!state || !m_Widgets)
922  return;
923 
924  if (state.m_bBarrelChambered)
925  m_Widgets.m_FiremodeIcon.SetOpacity(1);
926  else
927  m_Widgets.m_FiremodeIcon.SetOpacity(FADED_OPACITY);
928  }
929 
930  //------------------------------------------------------------------------------------------------
931  void UpdateFireModeIndicator(SCR_WeaponState state)
932  {
933  if (!state || !m_Widgets)
934  return;
935 
936  m_Widgets.m_FiremodeIcon.SetVisible(false);
937  m_Widgets.m_FiremodeGlow.SetVisible(false);
938 
939  if (state.m_Muzzle && state.m_MuzzleUI && state.m_MuzzleUI.ShowFiremodeIcon())
940  {
941  auto fm = state.m_FireModeType;
942  string icon = state.m_MuzzleUI.GetFiremodeIconName(fm);
943 
944  if (icon != string.Empty)
945  {
946  SetWidgetImage(m_Widgets.m_FiremodeIcon, state.m_MuzzleUI.GetFiremodeIconImageset(), icon, SCALE_FIREMODE);
947  SetWidgetImage(m_Widgets.m_FiremodeGlow, state.m_MuzzleUI.GetFiremodeGlowImageset(), icon, SCALE_FIREMODE);
948 
949  m_Widgets.m_FiremodeIcon.SetVisible(true);
950  m_Widgets.m_FiremodeGlow.SetVisible(true);
951 
952  AnimateWidget_ColorFlash(m_Widgets.m_FiremodeIcon, EWeaponFeature.FIREMODE);
953  }
954  }
955  }
956 
957  //------------------------------------------------------------------------------------------------
958  void UpdateZeroingIndicator(SCR_WeaponState state)
959  {
960  if (!state || !m_Widgets)
961  return;
962 
963  int zeroing = state.m_iZeroing;
964 
965  if (zeroing <= 0)
966  {
967  m_Widgets.m_Zeroing.SetVisible(false);
968  m_Widgets.m_ZeroingText.SetText(string.Empty);
969  }
970  else
971  {
972  m_Widgets.m_Zeroing.SetVisible(true);
973  string sZeroing = string.Format("%1 m", zeroing);
974  m_Widgets.m_ZeroingText.SetText(sZeroing);
975 
976  AnimateWidget_ColorFlash(m_Widgets.m_Zeroing, EWeaponFeature.ZEROING);
977  }
978  }
979 
980  //------------------------------------------------------------------------------------------------
981  void UpdateZoomIndicator(SCR_WeaponState state)
982  {
983  if (!state || !m_Widgets)
984  return;
985 
986  float zoom = state.m_fZoom;
987 
988  if (zoom <= 0 || !state.m_bInADS)
989  {
990  m_Widgets.m_Optics.SetVisible(false);
991  m_Widgets.m_OpticsText.SetText(string.Empty);
992  }
993  else
994  {
995  string sZoom = zoom.ToString(-1,1);
996  sZoom = string.Format("%1 ×", sZoom);
997 
998  m_Widgets.m_Optics.SetVisible(true);
999  m_Widgets.m_OpticsText.SetText(sZoom);
1000 
1001  AnimateWidget_ColorFlash(m_Widgets.m_Optics, EWeaponFeature.ZOOM);
1002  }
1003  }
1004 
1005  //------------------------------------------------------------------------------------------------
1006  void UpdateAmmoTypeIndicator(SCR_WeaponState state)
1007  {
1008  if (!state || !m_Widgets)
1009  return;
1010 
1011  if (!state.m_bHasSpecialAmmo || (!state.m_MagazineUI && !state.m_GrenadeUI))
1012  {
1013  m_Widgets.m_AmmoType.SetVisible(false);
1014  return;
1015  }
1016 
1017  string sAmmoTypeText;
1018  bool bShowAmmoTypeText;
1019 
1020  if (state.m_GrenadeUI)
1021  {
1022  sAmmoTypeText = state.m_GrenadeUI.GetAmmoType();
1023  bShowAmmoTypeText = state.m_GrenadeUI.ShowAmmoTypeText();
1024  }
1025  else
1026  {
1027  sAmmoTypeText = state.m_MagazineUI.GetAmmoType();
1028  bShowAmmoTypeText = state.m_MagazineUI.ShowAmmoTypeText();
1029  }
1030 
1031  if (!bShowAmmoTypeText)
1032  sAmmoTypeText = "";
1033 
1034  m_Widgets.m_AmmoTypeText.SetText(sAmmoTypeText);
1035 
1036  m_Widgets.m_AmmoType.SetVisible(true);
1037 
1038  m_Widgets.m_AmmoType_FMJ.SetVisible(state.m_eAmmoTypeFlags & EAmmoType.FMJ);
1039  m_Widgets.m_AmmoType_AP.SetVisible(state.m_eAmmoTypeFlags & EAmmoType.AP);
1040  m_Widgets.m_AmmoType_Frag.SetVisible(state.m_eAmmoTypeFlags & EAmmoType.FRAG);
1041  m_Widgets.m_AmmoType_Smoke.SetVisible(state.m_eAmmoTypeFlags & EAmmoType.SMOKE);
1042  m_Widgets.m_AmmoType_HE.SetVisible(state.m_eAmmoTypeFlags & EAmmoType.HE);
1043  m_Widgets.m_AmmoType_HEAT.SetVisible(state.m_eAmmoTypeFlags & EAmmoType.HEAT);
1044  m_Widgets.m_AmmoType_Incendiary.SetVisible(state.m_eAmmoTypeFlags & EAmmoType.INCENDIARY);
1045  m_Widgets.m_AmmoType_Tracer.SetVisible(state.m_eAmmoTypeFlags & EAmmoType.TRACER);
1046  m_Widgets.m_AmmoType_Sniper.SetVisible(state.m_eAmmoTypeFlags & EAmmoType.SNIPER);
1047 
1048  //AnimateWidget_ColorFlash(m_Widgets.m_AmmoType);
1049  }
1050 
1051  //------------------------------------------------------------------------------------------------
1052  protected void UpdateWeaponNameAndCaliber(SCR_WeaponState state)
1053  {
1054  if (!state || !m_Widgets || !state.m_WeaponUI)
1055  return;
1056 
1057  // Update weapon name indicator
1058  bool showName = state.m_WeaponUI.ShowWeaponName();
1059 
1060  if (showName)
1061  m_Widgets.m_WeaponName.SetText(state.m_WeaponUI.GetName());
1062 
1063  m_Widgets.m_WeaponName.SetVisible(showName);
1064 
1065  // Update muzzle caliber indicator
1066  bool showCaliber;
1067 
1068  if (state.m_MuzzleUI)
1069  {
1070  showCaliber = state.m_MuzzleUI.ShowCaliber();
1071 
1072  if (showCaliber)
1073  m_Widgets.m_Caliber.SetText(state.m_MuzzleUI.GetCaliber());
1074  }
1075 
1076  m_Widgets.m_Caliber.SetVisible(showCaliber);
1077  }
1078 
1079  //------------------------------------------------------------------------------------------------
1080  void AnimateWidget_ColorFlash(Widget w, EWeaponFeature requiredFlag = -1, float speed = UIConstants.FADE_RATE_SLOW)
1081  {
1082  if (!w)
1083  return;
1084 
1085  if (requiredFlag != -1 && m_eWeaponStateEvent != requiredFlag)
1086  return;
1087 
1088  w.SetColor(COLOR_ORANGE);
1089  AnimateWidget.Color(w, COLOR_WHITE, speed);
1090  }
1091 
1092  //------------------------------------------------------------------------------------------------
1093  void AnimateWidget_TextPopUp(Widget w, float size, float sizeBoosted, EWeaponFeature requiredFlag = -1, float speed = UIConstants.FADE_RATE_SLOW)
1094  {
1095  if (!w)
1096  return;
1097 
1098  if (requiredFlag != -1 && m_eWeaponStateEvent != requiredFlag)
1099  return;
1100 
1101  float width = FrameSlot.GetSizeX(w);
1102 
1103  FrameSlot.SetSize(w, width, sizeBoosted);
1104  float widthHeight[2] = {width, size};
1105  AnimateWidget.Size(w, widthHeight, speed);
1106  }
1107 
1108  //------------------------------------------------------------------------------------------------
1109  override bool DisplayStartDrawInit(IEntity owner)
1110  {
1111  SCR_ChimeraCharacter character = SCR_ChimeraCharacter.Cast(owner);
1112  if (!character)
1113  return false;
1114 
1115  m_WeaponManager = BaseWeaponManagerComponent.Cast(character.FindComponent(BaseWeaponManagerComponent));
1116  if (!m_WeaponManager)
1117  return false;
1118 
1119  m_CompartmentAccess = CompartmentAccessComponent.Cast(owner.FindComponent(CompartmentAccessComponent));
1120  if (!m_CompartmentAccess)
1121  return false;
1122 
1123  m_MenuManager = GetGame().GetMenuManager();
1124  if (!m_MenuManager)
1125  return false;
1126 
1127  // Register weapon related weapon event handlers
1128  AddEventHandlers(owner);
1129 
1130  // Fallback in case the layout is not provided as an InfoDisplay attribute
1131  if (m_LayoutPath == string.Empty)
1132  m_LayoutPath = DEFAULT_WEAPON_INFO_LAYOUT;
1133 
1134  return true;
1135  }
1136 
1137  //------------------------------------------------------------------------------------------------
1138  override void DisplayStartDraw(IEntity owner)
1139  {
1140  if (!m_wRoot)
1141  return;
1142 
1144  m_Widgets.Init(m_wRoot);
1145 
1146  m_Widgets.m_MagazineIndicator.SetVisible(true);
1147 
1148  if (!m_WeaponInfoPanelAnimator)
1149  m_WeaponInfoPanelAnimator = new SCR_FadeInOutAnimator(m_Widgets.m_WeaponInfoPanel, UIConstants.FADE_RATE_FAST, UIConstants.FADE_RATE_SLOW, FADEOUT_PANEL_DELAY, true);
1150 
1151  if (!m_ZeroingAnimator)
1152  m_ZeroingAnimator = new SCR_FadeInOutAnimator(m_Widgets.m_Zeroing, UIConstants.FADE_RATE_FAST, UIConstants.FADE_RATE_SLOW, FADEOUT_OPTICS_DELAY, true);
1153 
1154  // Initialize the UI based on what weapon character currently has
1155  OnWeaponChanged(m_WeaponManager.GetCurrentWeapon(), null);
1156  }
1157 
1158  //------------------------------------------------------------------------------------------------
1159  override void DisplayStopDraw(IEntity owner)
1160  {
1161  if (m_WeaponState && m_WeaponState.m_SightsZoomFOVInfo)
1162  m_WeaponState.m_SightsZoomFOVInfo.GetEventOnZoomChanged().Remove(OnZoomChanged);
1163 
1164  m_WeaponState = null;
1165 
1166  // Un-register weapon related weapon event handlers
1167  RemoveEventHandlers(owner);
1168 
1169  // Destroy the animators
1170  m_WeaponInfoPanelAnimator = null;
1171  m_ZeroingAnimator = null;
1172 
1173  m_wRoot = null;
1174  }
1175 
1176  //------------------------------------------------------------------------------------------------
1177  void AddEventHandlers(IEntity owner)
1178  {
1180  {
1181  m_EventHandlerManager.RegisterScriptHandler("OnWeaponChanged", this, OnWeaponChanged);
1182  m_EventHandlerManager.RegisterScriptHandler("OnMuzzleChanged", this, OnMuzzleChanged);
1183  m_EventHandlerManager.RegisterScriptHandler("OnMagazineChanged", this, OnMagazineChanged);
1184  m_EventHandlerManager.RegisterScriptHandler("OnMagazineCountChanged", this, OnMagazineCountChanged);
1185  m_EventHandlerManager.RegisterScriptHandler("OnAmmoCountChanged", this, OnAmmoCountChanged);
1186  m_EventHandlerManager.RegisterScriptHandler("OnFiremodeChanged", this, OnFiremodeChanged);
1187  m_EventHandlerManager.RegisterScriptHandler("OnZeroingChanged", this, OnZeroingChanged);
1188  m_EventHandlerManager.RegisterScriptHandler("OnADSChanged", this, OnADSChanged);
1189  m_EventHandlerManager.RegisterScriptHandler("OnInspectionModeChanged", this, OnInspectionModeChanged);
1190  m_EventHandlerManager.RegisterScriptHandler("OnWeaponAttachmentChanged", this, OnAttachmentChanged);
1191  }
1192  }
1193 
1194  //------------------------------------------------------------------------------------------------
1195  void RemoveEventHandlers(IEntity owner)
1196  {
1198  {
1199  m_EventHandlerManager.RemoveScriptHandler("OnWeaponChanged", this, OnWeaponChanged);
1200  m_EventHandlerManager.RemoveScriptHandler("OnMuzzleChanged", this, OnMuzzleChanged);
1201  m_EventHandlerManager.RemoveScriptHandler("OnMagazineChanged", this, OnMagazineChanged);
1202  m_EventHandlerManager.RemoveScriptHandler("OnMagazineCountChanged", this, OnMagazineCountChanged);
1203  m_EventHandlerManager.RemoveScriptHandler("OnAmmoCountChanged", this, OnAmmoCountChanged);
1204  m_EventHandlerManager.RemoveScriptHandler("OnFiremodeChanged", this, OnFiremodeChanged);
1205  m_EventHandlerManager.RemoveScriptHandler("OnZeroingChanged", this, OnZeroingChanged);
1206  m_EventHandlerManager.RemoveScriptHandler("OnADSChanged", this, OnADSChanged);
1207  m_EventHandlerManager.RemoveScriptHandler("OnInspectionModeChanged", this, OnInspectionModeChanged);
1208  m_EventHandlerManager.RemoveScriptHandler("OnWeaponAttachmentChanged", this, OnAttachmentChanged);
1209  }
1210  m_EventHandlerManager = null;
1211  }
1212 
1213  //------------------------------------------------------------------------------------------------
1215  protected static InventoryStorageManagerComponent GetInventoryManager()
1216  {
1217  PlayerController pc = GetGame().GetPlayerController();
1218 
1219  if (!pc)
1220  return null;
1221 
1222  IEntity playerEntity = pc.GetControlledEntity();
1223 
1224  if (!playerEntity)
1225  return null;
1226 
1228 
1229  CompartmentAccessComponent compAccess = CompartmentAccessComponent.Cast(playerEntity.FindComponent(CompartmentAccessComponent));
1230 
1231  if (!compAccess)
1232  return invManager;
1233 
1234  BaseCompartmentSlot compSlot = compAccess.GetCompartment();
1235 
1236  if (!compSlot)
1237  return invManager;
1238 
1239  IEntity vehEntity = compSlot.GetVehicle();
1241  vehEntity.FindComponent(InventoryStorageManagerComponent));
1242 
1243  if (!vehInvMgr)
1244  {
1245  vehEntity = compSlot.GetOwner();
1246  vehInvMgr = InventoryStorageManagerComponent.Cast(vehEntity.FindComponent(InventoryStorageManagerComponent));
1247  }
1248 
1249  if (!vehInvMgr)
1250  return null;
1251 
1252  return vehInvMgr;
1253  }
1254 
1255  //------------------------------------------------------------------------------------------------
1256  protected BaseWeaponManagerComponent GetWeaponManager(IEntity owner)
1257  {
1258  SCR_ChimeraCharacter character = SCR_ChimeraCharacter.Cast(owner);
1259  if (!character)
1260  return null;
1261 
1262  // Detect and store weapon manager
1263  BaseWeaponManagerComponent weaponManager = BaseWeaponManagerComponent.Cast(character.FindComponent(BaseWeaponManagerComponent));
1264  if (!weaponManager)
1265  return null;
1266 
1267  return weaponManager;
1268  }
1269 
1270  //---------------------------------------------------------------------------------------------------------
1272  protected void SetWidgetImage(ImageWidget w, string imageOrImageset, string imageName = "", float scale = SCALE_DEFAULT)
1273  {
1274  if (!imageName.IsEmpty())
1275  {
1276  // Assume it's an image set
1277  w.LoadImageFromSet(0, imageOrImageset, imageName);
1278  }
1279  else if (!imageOrImageset.IsEmpty())
1280  {
1281  // Assume it's an image
1282  w.LoadImageTexture(0, imageOrImageset);
1283  }
1284 
1285  // Perform scaling
1286  int sx, sy;
1287  w.GetImageSize(0, sx, sy);
1288  w.SetSize(sx * scale, sy * scale);
1289  }
1290 };
HE
@ HE
Definition: SCR_WeaponInfo.c:16
m_wRoot
protected Widget m_wRoot
Definition: SCR_ScenarioFrameworkLayerTaskDefend.c:59
INCENDIARY
@ INCENDIARY
Definition: SCR_WeaponInfo.c:20
INSPECTION
@ INSPECTION
Definition: SCR_WeaponInfo.c:35
SCR_WeaponState
Definition: SCR_WeaponState.c:2
COLOR_WHITE
const ref Color COLOR_WHITE
Definition: SCR_VonDisplay.c:80
SCR_WeaponInfo
Definition: SCR_WeaponInfo.c:41
_print
void _print(string s)
Definition: SCR_ModularButtonComponent.c:665
UIConstants
Definition: Constants.c:130
MAGAZINE_COUNT
@ MAGAZINE_COUNT
Definition: SCR_WeaponInfo.c:34
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
EWeaponFiremodeType
EWeaponFiremodeType
Definition: EWeaponFiremodeType.c:12
MISC
@ MISC
Definition: SCR_WeaponInfo.c:38
MAGAZINE
@ MAGAZINE
Definition: SCR_WeaponInfo.c:30
EWeaponFeature
EWeaponFeature
Definition: SCR_WeaponInfo.c:24
FRAG
@ FRAG
Definition: SCR_WeaponInfo.c:18
WeaponSlotComponent
Definition: WeaponSlotComponent.c:12
MuzzleUIInfo
Definition: MuzzleUIInfo.c:3
SMOKE
@ SMOKE
Definition: SCR_WeaponInfo.c:19
m_Widgets
ref SCR_VoNOverlay_ElementWidgets m_Widgets
Definition: SCR_VonDisplay.c:3
FIREMODE
@ FIREMODE
Definition: SCR_WeaponInfo.c:28
m_WeaponManager
protected BaseWeaponManagerComponent m_WeaponManager
Definition: SCR_CharacterCommandHandler.c:120
m_EventHandlerManager
protected EventHandlerManagerComponent m_EventHandlerManager
Definition: SCR_InfoDisplayExtended.c:28
Show
override void Show(WorkspaceWidget pWorkspace, Widget pToolTipWidget, float desiredPosX, float desiredPosY)
Definition: SCR_ScriptedWidgetTooltip.c:55
SCR_SightsZoomFOVInfo
Definition: SCR_SightsZoomFOVInfo.c:6
InventoryStorageManagerComponent
Definition: InventoryStorageManagerComponent.c:12
SNIPER
@ SNIPER
Definition: SCR_WeaponInfo.c:21
HEAT
@ HEAT
Definition: SCR_WeaponInfo.c:17
BaseMagazineWell
Definition: BaseMagazineWell.c:12
BaseFireMode
Definition: BaseFireMode.c:12
BaseWeaponComponent
Definition: BaseWeaponComponent.c:12
ZEROING
@ ZEROING
Definition: SCR_WeaponInfo.c:27
SCR_FadeInOutAnimator
Definition: SCR_FadeInOutAnimator.c:8
GrenadeMoveComponent
Definition: GrenadeMoveComponent.c:12
MagazineUIInfo
Definition: MagazineUIInfo.c:3
WeaponUIInfo
Definition: WeaponUIInfo.c:3
AP
@ AP
Definition: SCR_WeaponInfo.c:15
ADS
@ ADS
Definition: SCR_WeaponInfo.c:33
TRACER
@ TRACER
Definition: SCR_WeaponInfo.c:14
AMMOCOUNT
@ AMMOCOUNT
Definition: SCR_WeaponInfo.c:29
SCR_WeaponInfoWidgets
Definition: SCR_WeaponInfoWidgets.c:4
NONE
@ NONE
Definition: SCR_WeaponInfo.c:26
WEAPON
@ WEAPON
Definition: SCR_WeaponInfo.c:32
MUZZLE
@ MUZZLE
Definition: SCR_WeaponInfo.c:31
EAmmoType
EAmmoType
Definition: SCR_WeaponInfo.c:10
FMJ
@ FMJ
Definition: SCR_WeaponInfo.c:13
ZOOM
@ ZOOM
Definition: SCR_WeaponInfo.c:36
RELOADING
@ RELOADING
Definition: SCR_WeaponInfo.c:37
BaseMuzzleComponent
Definition: BaseMuzzleComponent.c:12
m_MenuManager
protected MenuManager m_MenuManager
Definition: SCR_InfoDisplayExtended.c:27
SCR_MagazineIndicatorConfiguration
Definition: SCR_MagazineIndicatorConfiguration.c:4
GrenadeUIInfo
Definition: WeaponUIInfo.c:18