Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_WeaponAction.c
Go to the documentation of this file.
2 {
4 };
5 
7 {
9  [Attribute( uiwidget: UIWidgets.CheckBox, defvalue: "1", desc: "Should action behave as a toggle")]
10  protected bool m_bIsToggle;
11 
13  [Attribute( uiwidget: UIWidgets.CheckBox, defvalue: "1", desc: "Target state of the action, ignored if toggle")]
14  protected bool m_bTargetState;
15 
17  [Attribute( uiwidget: UIWidgets.Auto, defvalue: "#AR-UserAction_State_On", desc: "Description of action to toggle on")]
18  protected string m_sActionStateOn;
19 
21  [Attribute( uiwidget: UIWidgets.Auto, defvalue: "#AR-UserAction_State_Off", desc: "Description of action to toggle off")]
22  protected string m_sActionStateOff;
23 
24  [Attribute("1", UIWidgets.ComboBox, "", "", ParamEnumArray.FromEnum(EWeaponActionType) )]
25  protected EWeaponActionType m_WeaponActionType;
26 
27  protected BaseWeaponComponent m_Weapon;
28 
29  override void Init(IEntity pOwnerEntity, GenericComponent pManagerComponent)
30  {
31  m_Weapon = WeaponComponent.Cast(pOwnerEntity.FindComponent(WeaponComponent));
32  }
33 
34  //------------------------------------------------------------------------------------------------
35  override bool CanBeShownScript(IEntity user)
36  {
37  if (!m_Weapon)
38  return false;
39 
40  ChimeraCharacter character = ChimeraCharacter.Cast(user);
41  if (!character)
42  return false;
43 
44  CharacterControllerComponent controller = character.GetCharacterController();
45  if (!controller)
46  return false;
47 
48  if (!controller.GetInspect())
49  return false;
50 
51  if (m_WeaponActionType == EWeaponActionType.Bipod)
52  return m_Weapon && m_Weapon.HasBipod();
53 
54  return true;
55  }
56 
57  //------------------------------------------------------------------------------------------------
58  override bool CanBePerformedScript(IEntity user)
59  {
60  return m_bIsToggle || (GetState() != m_bTargetState);
61  }
62 
63  //------------------------------------------------------------------------------------------------
65  bool GetState()
66  {
67  if (!m_Weapon)
68  return false;
69 
70  if (m_WeaponActionType == EWeaponActionType.Bipod)
71  return m_Weapon.GetBipod();
72 
73  return false;
74  }
75 
76  //------------------------------------------------------------------------------------------------
78  void SetState(bool enable)
79  {
80  if (!m_Weapon)
81  return;
82 
83  if (m_WeaponActionType == EWeaponActionType.Bipod)
84  m_Weapon.SetBipod(enable);
85  }
86 
87  //------------------------------------------------------------------------------------------------
89  override void PerformAction(IEntity pOwnerEntity, IEntity pUserEntity)
90  {
91  if (m_bIsToggle)
92  SetState(!GetState());
93  else
94  SetState(m_bTargetState);
95  }
96 
97  //------------------------------------------------------------------------------------------------
98  override bool GetActionNameScript(out string outName)
99  {
100  if (m_WeaponActionType == EWeaponActionType.Bipod)
101  {
102  if (GetState())
103  outName = "#AR-Keybind_BipodRetract";
104  else
105  outName = "#AR-Keybind_Bipod";
106 
107  return true;
108  }
109 
110  UIInfo uiInfo = GetUIInfo();
111  string prefix;
112  if (uiInfo)
113  prefix = uiInfo.GetName();
114 
115  if (!prefix.IsEmpty() && m_bIsToggle)
116  {
117  prefix += " ";
118  if (GetState())
119  outName = prefix + m_sActionStateOff;
120  else
121  outName = prefix + m_sActionStateOn;
122  }
123  else
124  outName = prefix;
125  return true;
126  }
127 
128  //------------------------------------------------------------------------------------------------
129  override bool HasLocalEffectOnlyScript()
130  {
131  return true;
132  }
133 };
Bipod
@ Bipod
Definition: SCR_WeaponAction.c:3
m_Weapon
IEntity m_Weapon
Definition: SCR_MeleeComponent.c:9
UIInfo
UIInfo - declare object, allows to define UI elements.
Definition: UIInfo.c:13
ScriptedUserAction
Definition: ScriptedUserAction.c:12
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
GetUIInfo
SCR_UIInfo GetUIInfo()
Definition: SCR_EditableEntityCampaignBuildingModeLabelSetting.c:27
EWeaponActionType
EWeaponActionType
Definition: SCR_WeaponAction.c:1
Attribute
typedef Attribute
Post-process effect of scripted camera.
BaseWeaponComponent
Definition: BaseWeaponComponent.c:12
SCR_WeaponAction
Definition: SCR_WeaponAction.c:6