Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_WeaponInfoVehicle.c
Go to the documentation of this file.
2 {
3  protected TurretComponent m_Turret;
4  protected TurretControllerComponent m_TurretController;
5 
6  //------------------------------------------------------------------------------------------------
7  override void DisplayUpdate(IEntity owner, float timeSlice)
8  {
9  if (!m_wRoot || !m_WeaponState)
10  return;
11 
12  if (m_WeaponState.m_bReloading)
13  {
14  // Set weapon state change flag
15  m_eWeaponStateEvent |= EWeaponFeature.RELOADING;
16 
17  UpdateMagazineIndicator_Reloading(false);
18  }
19 
20  super.DisplayUpdate(owner, timeSlice);
21  }
22 
23  //------------------------------------------------------------------------------------------------
24  override void OnMuzzleChanged(BaseWeaponComponent weapon, BaseMuzzleComponent muzzle, BaseMuzzleComponent prevMuzzle)
25  {
26  super.OnMuzzleChanged(weapon, muzzle, prevMuzzle);
27 
28  // Auto-trigger child events
29  #ifndef WEAPON_INFO_BLOCK_WATERFALL_EVENTS
30  OnTurretReload_init(weapon);
31  #endif
32  }
33 
34  //------------------------------------------------------------------------------------------------
35  void OnTurretReload_init(BaseWeaponComponent weapon)
36  {
37  float rldTime = m_TurretController.GetReloadTime();
38 
39  if (rldTime == 0)
40  return;
41 
42  #ifdef WEAPON_INFO_DEBUG_WATERFALL_EVENTS
43  Print("OnTurretReload_init");
44  Print(string.Format(" weapon: %1", weapon));
45  Print(string.Format(" finished: %1", false));
46  #endif
47 
48  OnTurretReload(weapon, false, m_TurretController);
49  }
50  void OnTurretReload(BaseWeaponComponent weapon, bool finished, TurretControllerComponent turretController)
51  {
52  if (!m_WeaponState)
53  return;
54 
55  #ifdef WEAPON_INFO_DEBUG
56  _print("OnTurretReload");
57  _print(string.Format(" weapon: %1", weapon));
58  _print(string.Format(" finished: %1", finished));
59  _print(string.Format(" turretController: %1", turretController));
60  #endif
61 
62  if (m_TurretController != turretController)
63  return;
64 
65  m_WeaponState.m_bReloading = !finished;
66 
67  UpdateMagazineIndicator_Reloading(finished);
68  }
69 
70  //------------------------------------------------------------------------------------------------
71  protected void UpdateMagazineIndicator_Reloading(bool finished)
72  {
73  float rldProgress = 0;
74 
75  if (!finished)
76  {
77  float rldTime = m_TurretController.GetReloadTime();
78  float rldDuration = m_TurretController.GetReloadDuration();
79 
80  if (rldDuration > 0)
81  rldProgress = Math.Clamp((rldDuration - rldTime) / rldDuration, 0, 1);
82  }
83 
84  m_Widgets.m_ReloadOutline.SetMaskProgress(rldProgress);
85  m_Widgets.m_ReloadOutline.SetVisible(rldProgress > 0);
86 
87  m_Widgets.m_ReloadBackground.SetMaskProgress(rldProgress);
88  m_Widgets.m_ReloadBackground.SetVisible(rldProgress > 0);
89  }
90 
91  //------------------------------------------------------------------------------------------------
92  override bool DisplayStartDrawInit(IEntity owner)
93  {
94  if(!owner)
95  return false;
96 
97  m_Turret = TurretComponent.Cast(owner.FindComponent(TurretComponent));
98 
100  if(!m_TurretController)
101  return false;
102 
103  BaseCompartmentSlot slot = m_TurretController.GetCompartmentSlot();
104  if(!slot)
105  return false;
106 
107  ChimeraCharacter character = ChimeraCharacter.Cast(slot.GetOccupant());
108  if(!character)
109  return false;
110 
111  // Detect and store weapon manager
112  m_WeaponManager = BaseWeaponManagerComponent.Cast(owner.FindComponent(BaseWeaponManagerComponent));
113  if (!m_WeaponManager)
114  return false;
115 
116  m_MenuManager = GetGame().GetMenuManager();
117  if (!m_MenuManager)
118  return false;
119 
120  AddEventHandlers(owner);
121 
122  return true;
123  }
124 
125  //------------------------------------------------------------------------------------------------
126  override void AddEventHandlers(IEntity owner)
127  {
129  {
130  m_EventHandlerManager.RegisterScriptHandler("OnWeaponChanged", this, OnWeaponChanged);
131  m_EventHandlerManager.RegisterScriptHandler("OnMuzzleChanged", this, OnMuzzleChanged);
132  m_EventHandlerManager.RegisterScriptHandler("OnMagazineChanged", this, OnMagazineChanged);
133  m_EventHandlerManager.RegisterScriptHandler("OnMagazineCountChanged", this, OnMagazineCountChanged);
134  m_EventHandlerManager.RegisterScriptHandler("OnAmmoCountChanged", this, OnAmmoCountChanged);
135  m_EventHandlerManager.RegisterScriptHandler("OnFiremodeChanged", this, OnFiremodeChanged);
136  m_EventHandlerManager.RegisterScriptHandler("OnZeroingChanged", this, OnZeroingChanged);
137  m_EventHandlerManager.RegisterScriptHandler("OnADSChanged", this, OnADSChanged);
138  m_EventHandlerManager.RegisterScriptHandler("OnTurretReload", this, OnTurretReload);
139  }
140  }
141 
142  //------------------------------------------------------------------------------------------------
143  override void RemoveEventHandlers(IEntity owner)
144  {
146  {
147  m_EventHandlerManager.RemoveScriptHandler("OnWeaponChanged", this, OnWeaponChanged);
148  m_EventHandlerManager.RemoveScriptHandler("OnMuzzleChanged", this, OnMuzzleChanged);
149  m_EventHandlerManager.RemoveScriptHandler("OnMagazineChanged", this, OnMagazineChanged);
150  m_EventHandlerManager.RemoveScriptHandler("OnMagazineCountChanged", this, OnMagazineCountChanged);
151  m_EventHandlerManager.RemoveScriptHandler("OnAmmoCountChanged", this, OnAmmoCountChanged);
152  m_EventHandlerManager.RemoveScriptHandler("OnFiremodeChanged", this, OnFiremodeChanged);
153  m_EventHandlerManager.RemoveScriptHandler("OnZeroingChanged", this, OnZeroingChanged);
154  m_EventHandlerManager.RemoveScriptHandler("OnADSChanged", this, OnADSChanged);
155  m_EventHandlerManager.RemoveScriptHandler("OnTurretReload", this, OnTurretReload);
156  }
157  m_EventHandlerManager = null;
158  }
159 
160  //------------------------------------------------------------------------------------------------
161  override SCR_2DSightsComponent GetSights()
162  {
163  if (!m_Turret)
164  return null;
165 
166  SCR_2DSightsComponent sights = SCR_2DSightsComponent.Cast(m_Turret.FindComponent(SCR_2DSightsComponent));
167 
168  return sights;
169  }
170 };
m_wRoot
protected Widget m_wRoot
Definition: SCR_ScenarioFrameworkLayerTaskDefend.c:59
SCR_WeaponInfo
Definition: SCR_WeaponInfo.c:41
SCR_WeaponInfoVehicle
Definition: SCR_WeaponInfoVehicle.c:1
_print
void _print(string s)
Definition: SCR_ModularButtonComponent.c:665
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
EWeaponFeature
EWeaponFeature
Definition: SCR_WeaponInfo.c:24
m_Widgets
ref SCR_VoNOverlay_ElementWidgets m_Widgets
Definition: SCR_VonDisplay.c:3
m_WeaponManager
protected BaseWeaponManagerComponent m_WeaponManager
Definition: SCR_CharacterCommandHandler.c:120
m_EventHandlerManager
protected EventHandlerManagerComponent m_EventHandlerManager
Definition: SCR_InfoDisplayExtended.c:28
OnWeaponChanged
protected void OnWeaponChanged(BaseWeaponComponent newWeaponSlot)
Definition: SCR_ItemPlacementComponent.c:310
BaseWeaponComponent
Definition: BaseWeaponComponent.c:12
TurretControllerComponent
Definition: TurretControllerComponent.c:12
m_TurretController
protected TurretControllerComponent m_TurretController
Definition: SCR_2DSightsComponent.c:35
BaseMuzzleComponent
Definition: BaseMuzzleComponent.c:12
m_MenuManager
protected MenuManager m_MenuManager
Definition: SCR_InfoDisplayExtended.c:27