Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_WeaponSwitchingHints.c
Go to the documentation of this file.
1 class SCR_WeaponSwitchingHints: ScriptedWidgetComponent
2 {
3  Widget m_wChangeAmmo;
4  Widget m_wChangeMuzzle;
5  Widget m_wSafety;
6  Widget m_wRaiseWeapon;
7  EventHandlerManagerComponent m_EventHandlerManager;
8 
9  BaseWeaponComponent m_CurrentWeapon;
10 
11  override void HandlerAttached(Widget w)
12  {
13  GetGame().GetInputManager().AddActionListener("CharacterChangeAmmo", EActionTrigger.DOWN, Action_ChangeAmmo);
14  GetGame().GetInputManager().AddActionListener("CharacterChangeMuzzle", EActionTrigger.DOWN, Action_ChangeMuzzle);
15 
16  m_wChangeAmmo = w.FindAnyWidget("ChangeAmmo");
17  m_wChangeMuzzle = w.FindAnyWidget("ChangeMuzzle");
18  m_wSafety = w.FindAnyWidget("Safety");
19  m_wRaiseWeapon = w.FindAnyWidget("RaiseWeapon");
20 
21  ChimeraCharacter character = ChimeraCharacter.Cast(SCR_PlayerController.GetLocalControlledEntity());
22  if (!character)
23  return;
24 
25  m_EventHandlerManager = EventHandlerManagerComponent.Cast(character.FindComponent(EventHandlerManagerComponent));
27  m_EventHandlerManager.RegisterScriptHandler("OnWeaponChanged", this, OnWeaponChanged, true);
28 
29  BaseWeaponManagerComponent weaponManager = BaseWeaponManagerComponent.Cast(character.FindComponent(BaseWeaponManagerComponent));
30  if (!weaponManager)
31  return;
32 
33  m_CurrentWeapon = weaponManager.GetCurrent();
34  OnWeaponChanged(m_CurrentWeapon);
35  }
36 
37  override void HandlerDeattached(Widget w)
38  {
40  m_EventHandlerManager.RemoveScriptHandler("OnWeaponChanged", this, OnWeaponChanged, true);
41  }
42 
43 
44  void OnWeaponChanged(BaseWeaponComponent weapon)
45  {
46  m_CurrentWeapon = weapon;
47 
48  // If the current item is not a weapon, hide all widgets
49  if (!weapon)
50  {
51  m_wRaiseWeapon.SetVisible(false);
52  m_wChangeMuzzle.SetVisible(false);
53  m_wChangeAmmo.SetVisible(false);
54  m_wSafety.SetVisible(false);
55  return;
56  }
57 
58  // Ammo
59  // TODO: How do I get the current ammo types???
60 
61 
62  m_wRaiseWeapon.SetVisible(true);
63 
64  // Muzzles
65  array<BaseMuzzleComponent> a;
66  int count = weapon.GetMuzzlesList(a);
67  m_wChangeMuzzle.SetVisible(count > 1);
68 
69  // Safety
70  bool hasSafetyMode = false;
71  BaseMuzzleComponent muzzle = weapon.GetCurrentMuzzle();
72  if (muzzle)
73  {
74  array<BaseFireMode> fireModes;
75  muzzle.GetFireModesList(fireModes);
76  foreach (BaseFireMode mode : fireModes)
77  {
78  if (mode.GetFiremodeType() != EWeaponFiremodeType.Safety)
79  continue;
80 
81  hasSafetyMode = true;
82  break;
83  }
84  }
85  m_wSafety.SetVisible(hasSafetyMode);
86  }
87 
88  void Action_ChangeAmmo()
89  {
90  if (!m_CurrentWeapon || !m_wChangeAmmo.IsVisible())
91  return;
92 
93  // MUST BE IMPLEMENTED BY PROGRAMMER!
94  }
95 
96  void Action_ChangeMuzzle()
97  {
98  if (!m_CurrentWeapon || !m_wChangeMuzzle.IsVisible())
99  return;
100 
101  // MUST BE IMPLEMENTED BY PROGRAMMER!
102  }
103 };
SCR_PlayerController
Definition: SCR_PlayerController.c:31
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
EWeaponFiremodeType
EWeaponFiremodeType
Definition: EWeaponFiremodeType.c:12
m_EventHandlerManager
protected EventHandlerManagerComponent m_EventHandlerManager
Definition: SCR_InfoDisplayExtended.c:28
SCR_WeaponSwitchingHints
Definition: SCR_WeaponSwitchingHints.c:1
BaseFireMode
Definition: BaseFireMode.c:12
BaseWeaponComponent
Definition: BaseWeaponComponent.c:12
BaseMuzzleComponent
Definition: BaseMuzzleComponent.c:12