Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_GadgetComponent.c
Go to the documentation of this file.
1 [EntityEditorProps(category: "GameScripted/Gadgets", description: "Gadget base", color: "0 0 255 255")]
3 {
4 }
5 
6 //------------------------------------------------------------------------------------------------
8 enum EGadgetType
9 {
10  NONE = 1,
11  MAP = 1 << 1,
12  COMPASS = 1 << 2,
13  BINOCULARS = 1 << 3,
14  FLASHLIGHT = 1 << 4,
15  RADIO = 1 << 5,
16  RADIO_BACKPACK = 1 << 6,
17  WRISTWATCH = 1 << 7,
18  CONSUMABLE = 1 << 8,
19  BUILDING_TOOL = 1 << 9,
20  SPECIALIST_ITEM = 1 << 10,
21  NIGHT_VISION = 1 << 11,
22 }
23 
25 enum EGadgetMode
26 {
27  ON_GROUND = 0, // ground
28  IN_STORAGE, // within storage but not slotted
29  IN_SLOT, // in equipment slot
30  IN_HAND, // held in left hand
31  LAST
32 }
33 
34 // @NOTE(Leo) : short term animation solution
35 // from conversation with @Théo Escamez: //for now we have 4 items> compass adrianov, compass SY183, Radio ANPRC68 and Radio R148
37 enum EGadgetAnimVariable
38 {
39  NONE = 0,
40  ADRIANOV = 1,
41  SY183 = 2,
42  ANPRC68 = 3,
43  R148 = 4,
44  MX991 = 5,
46  M22 = 7,
47  B12 = 8,
48  MAP = 9
49 }
50 
52 class SCR_GadgetComponent : ScriptGameComponent
53 {
54  [Attribute("", UIWidgets.ComboBox, enums: ParamEnumArray.FromEnum(EGadgetAnimVariable), desc: "Gadget anim variable", category: "Gadget")]
55  protected EGadgetAnimVariable m_eAnimVariable;
56 
57  [Attribute("0 0 0", UIWidgets.Coords, desc: "Adjusted position of prefab within equipment slot, for when items placed intto a same slot have different sizes like flashlights", category: "Gadget")]
58  protected vector m_vEquipmentSlotOffset;
59 
60  bool m_bFocused;
61  protected bool m_bActivated = false; // current state if the gadget can be toggled on
62  protected EGadgetMode m_iMode = EGadgetMode.ON_GROUND; // curent gadget mode
63  protected IEntity m_CharacterOwner; // current entity in posession of this gadget
64 
65  //------------------------------------------------------------------------------------------------
67  EGadgetAnimVariable GetAnimVariable()
68  {
69  return m_eAnimVariable;
70  }
71 
72  //------------------------------------------------------------------------------------------------
75  bool IsToggledOn()
76  {
77  return m_bActivated;
78  }
79 
80  //------------------------------------------------------------------------------------------------
83  void OnToggleActive(bool state);
84 
85  //------------------------------------------------------------------------------------------------
87  void OnParentSlotChanged(InventoryStorageSlot oldSlot, InventoryStorageSlot newSlot)
88  {
89  if (newSlot == null) // ground
90  {
91  IEntity parentOwner, owner;
92 
93  BaseInventoryStorageComponent storageComp = oldSlot.GetStorage();
94  if (storageComp)
95  parentOwner = storageComp.GetOwner();
96  else
97  parentOwner = oldSlot.GetOwner(); // LoadoutSlotInfo wont return storage comp
98 
99  owner = parentOwner;
100 
101  while (owner != null)
102  {
103  parentOwner = owner;
104  owner = owner.GetParent();
105  }
106 
107  if ( !SCR_ChimeraCharacter.Cast(parentOwner) ) // remove from char is currently handled by gadget manager
108  SCR_GadgetManagerComponent.SetGadgetModeStashed(this, EGadgetMode.ON_GROUND);
109  }
110  else if (oldSlot == null)
111  {
112  IEntity parentOwner, owner;
113 
114  BaseInventoryStorageComponent storageComp = newSlot.GetStorage();
115  if (storageComp)
116  parentOwner = storageComp.GetOwner();
117  else
118  parentOwner = newSlot.GetOwner(); // LoadoutSlotInfo wont return storage comp
119 
120  owner = parentOwner;
121 
122  while (owner != null)
123  {
124  parentOwner = owner;
125  owner = owner.GetParent();
126  }
127 
128 
129  if ( !SCR_ChimeraCharacter.Cast(parentOwner) ) // add to char is currently handled by gadget manager
130  SCR_GadgetManagerComponent.SetGadgetModeStashed(this, EGadgetMode.IN_STORAGE);
131  }
132  }
133 
134  //------------------------------------------------------------------------------------------------
138  void OnModeChanged(EGadgetMode mode, IEntity charOwner)
139  {
140  // Clear last mode
141  ModeClear(m_iMode);
142 
143  // Update current mode
144  m_iMode = mode;
145 
146  // Set new mode
147  ModeSwitch(mode, charOwner);
148  }
149 
150  //------------------------------------------------------------------------------------------------
154  protected void ModeSwitch(EGadgetMode mode, IEntity charOwner)
155  {
156  UpdateVisibility(mode);
157 
158  // if removing from inventory
159  if (mode == EGadgetMode.ON_GROUND)
160  m_CharacterOwner = null;
161  else
162  m_CharacterOwner = charOwner;
163  }
164 
165  //------------------------------------------------------------------------------------------------
168  protected void ModeClear(EGadgetMode mode)
169  {
170  }
171 
172  //------------------------------------------------------------------------------------------------
174  void ActivateGadgetUpdate()
175  {
176  ConnectToGadgetsSystem();
177  }
178 
179  //------------------------------------------------------------------------------------------------
182  {
183  DisconnectFromGadgetsSystem();
184  }
185 
186 
187  //------------------------------------------------------------------------------------------------
189  // \param[in] inHand states whether the gadget is currently held in hand
190  void UpdateVisibility(EGadgetMode mode)
191  {
192  // mode1
193  InventoryItemComponent itemComponent = InventoryItemComponent.Cast(GetOwner().FindComponent(InventoryItemComponent));
194  if (!itemComponent)
195  return;
196 
197  // if in hand or visible while slotted
198  if ( mode == EGadgetMode.IN_HAND || (mode == EGadgetMode.IN_SLOT && IsVisibleEquipped()) )
199  {
200  // slotted, Set positioning of visible slotted gadgets on character -> configured in item prefab to allow gadgets of different sizes
201  if (mode != EGadgetMode.IN_HAND)
202  {
203  InventoryStorageSlot slot = itemComponent.GetParentSlot();
204  ItemAnimationAttributes animAttr = ItemAnimationAttributes.Cast(itemComponent.FindAttribute(ItemAnimationAttributes));
205  if (slot && animAttr)
206  {
207  vector matLS[4];
208  animAttr.GetAdditiveTransformLS(matLS);
209  matLS[3] = matLS[3] + m_vEquipmentSlotOffset;
210  slot.SetAdditiveTransformLS(matLS);
211  }
212 
213  EquipmentStorageSlot equipSlot = EquipmentStorageSlot.Cast(slot);
214  if (equipSlot && equipSlot.IsOccluded())
215  {
216  itemComponent.HideOwner(); // slotted but occluded
217  return;
218  }
219  }
220 
221  itemComponent.ShowOwner();
222  }
223  // if slotted and not visible or not slotted
224  else
225  {
226  if (mode == EGadgetMode.ON_GROUND)
227  itemComponent.ShowOwner();
228  else
229  itemComponent.HideOwner();
230  }
231  }
232 
233  //------------------------------------------------------------------------------------------------
236  void ToggleActive(bool state)
237  {
238  if (!m_CharacterOwner)
239  return;
240 
241  RplComponent rplComponent = RplComponent.Cast(m_CharacterOwner.FindComponent(RplComponent));
242  if (!rplComponent || !rplComponent.IsOwner())
243  return; // NOT owner of the character in possession of this gadget
244 
245  // Client side
246  rplComponent = RplComponent.Cast(GetOwner().FindComponent(RplComponent));
247  if (rplComponent && rplComponent.IsProxy())
248  OnToggleActive(state); // activate client side to avoid server delay
249 
250  // Sync
251  if (m_CharacterOwner)
252  SCR_GadgetManagerComponent.GetGadgetManager(m_CharacterOwner).AskToggleGadget(this, state);
253  }
254 
255  //------------------------------------------------------------------------------------------------
257  void ActivateAction();
258 
259  //------------------------------------------------------------------------------------------------
262  void ToggleFocused(bool enable)
263  {
264  m_bFocused = enable;
265 
266  if (m_CharacterOwner != SCR_PlayerController.GetLocalControlledEntity())
267  return;
268 
270  if (controller)
271  controller.SetGadgetFocus(enable);
272  }
273 
274  //------------------------------------------------------------------------------------------------
277  IEntity GetCharacterOwner()
278  {
279  return m_CharacterOwner;
280  }
281 
282  //------------------------------------------------------------------------------------------------
285  EGadgetType GetType()
286  {
287  return EGadgetType.NONE;
288  }
289 
290  //------------------------------------------------------------------------------------------------
293  EGadgetMode GetMode()
294  {
295  return m_iMode;
296  }
297 
298  //------------------------------------------------------------------------------------------------
301  bool CanBeHeld()
302  {
303  return true;
304  }
305 
306  //------------------------------------------------------------------------------------------------
309  bool CanBeToggled()
310  {
311  return false;
312  }
313 
314  //------------------------------------------------------------------------------------------------
317  bool CanBeRaised()
318  {
319  return false;
320  }
321 
322  //------------------------------------------------------------------------------------------------
325  bool IsUsingADSControls()
326  {
327  return false;
328  }
329 
330  //------------------------------------------------------------------------------------------------
333  bool IsVisibleEquipped()
334  {
335  return false;
336  }
337 
338  //------------------------------------------------------------------------------------------------
341  //Called by Gadgets system
342  void Update(float timeSlice);
343 
344  //------------------------------------------------------------------------------------------------
346  protected void ConnectToGadgetsSystem()
347  {
348  World world = GetOwner().GetWorld();
349  GadgetsSystem gadgetSystem = GadgetsSystem.Cast(world.FindSystem(GadgetsSystem));
350  if (!gadgetSystem)
351  return;
352 
353  gadgetSystem.Register(this);
354  }
355 
356  //------------------------------------------------------------------------------------------------
357  protected void DisconnectFromGadgetsSystem()
358  {
359  World world = GetOwner().GetWorld();
360  GadgetsSystem gadgetSystem = GadgetsSystem.Cast(world.FindSystem(GadgetsSystem));
361  if (!gadgetSystem)
362  return;
363 
364  gadgetSystem.Unregister(this);
365  }
366 
367  //------------------------------------------------------------------------------------------------
368  override bool RplSave(ScriptBitWriter writer)
369  {
370  writer.WriteIntRange(m_iMode, 0, EGadgetMode.LAST-1);
371 
372  return true;
373  }
374 
375  //------------------------------------------------------------------------------------------------
376  override bool RplLoad(ScriptBitReader reader)
377  {
378  reader.ReadIntRange(m_iMode, 0, EGadgetMode.LAST-1);
379 
380  UpdateVisibility(m_iMode);
381 
382  return true;
383  }
384 
385  //------------------------------------------------------------------------------------------------
386  override void OnDelete(IEntity owner)
387  {
388  DisconnectFromGadgetsSystem();
389 
390  super.OnDelete(owner);
391  }
392 
393  //------------------------------------------------------------------------------------------------
394  override void OnPostInit(IEntity owner)
395  {
396  SetEventMask( owner, EntityEvent.INIT);
397 
399  if (invComp)
400  invComp.m_OnParentSlotChangedInvoker.Insert(OnParentSlotChanged);
401  }
402 }
CONSUMABLE
SCR_GadgetComponentClass CONSUMABLE
IN_SLOT
SCR_GadgetComponentClass IN_SLOT
NIGHT_VISION
SCR_GadgetComponentClass NIGHT_VISION
SCR_PlayerController
Definition: SCR_PlayerController.c:31
GetType
override EGadgetType GetType()
Definition: SCR_CampaignBuildingGadgetToolComponent.c:52
EntityEditorProps
enum EQueryType EntityEditorProps(category:"GameScripted/Sound", description:"THIS IS THE SCRIPT DESCRIPTION.", color:"0 0 255 255")
Definition: SCR_AmbientSoundsComponent.c:12
GadgetsSystem
Definition: GadgetsSystem.c:1
ItemAnimationAttributes
Definition: ItemAnimationAttributes.c:12
ActivateAction
override void ActivateAction()
Definition: SCR_ConsumableItemComponent.c:188
ModeClear
override void ModeClear(EGadgetMode mode)
Definition: SCR_BinocularsComponent.c:63
InventoryStorageSlot
Definition: InventoryStorageSlot.c:12
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SCR_GadgetManagerComponent
Definition: SCR_GadgetManagerComponent.c:138
ScriptGameComponentClass
Definition: ScriptGameComponent.c:12
BINOCULARS
SCR_GadgetComponentClass BINOCULARS
SCR_GadgetComponentClass
Definition: SCR_GadgetComponent.c:2
ModeSwitch
override void ModeSwitch(EGadgetMode mode, IEntity charOwner)
Definition: SCR_CampaignBuildingGadgetToolComponent.c:68
EquipmentStorageSlot
Definition: EquipmentStorageSlot.c:7
FLASHLIGHT_SOVIET_01
SCR_GadgetComponentClass FLASHLIGHT_SOVIET_01
OnDelete
override void OnDelete(IEntity owner)
Definition: SCR_CampaignBuildingCompositionComponent.c:538
NONE
SCR_GadgetComponentClass NONE
Gadget type.
ADRIANOV
SCR_GadgetComponentClass ADRIANOV
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
RplLoad
override bool RplLoad(ScriptBitReader reader)
Definition: SCR_AIGroupInfoComponent.c:106
GetPlayerController
proto external PlayerController GetPlayerController()
Definition: SCR_PlayerDeployMenuHandlerComponent.c:307
COMPASS
SCR_GadgetComponentClass COMPASS
DeactivateGadgetUpdate
override void DeactivateGadgetUpdate()
Definition: SCR_WristwatchComponent.c:161
RplSave
override bool RplSave(ScriptBitWriter writer)
Definition: SCR_CampaignBuildingCompositionComponent.c:490
RADIO_BACKPACK
SCR_GadgetComponentClass RADIO_BACKPACK
IsVisibleEquipped
override bool IsVisibleEquipped()
Definition: SCR_BinocularsComponent.c:106
Attribute
typedef Attribute
Post-process effect of scripted camera.
ActivateGadgetUpdate
override void ActivateGadgetUpdate()
Definition: SCR_WristwatchComponent.c:151
RADIO
SCR_GadgetComponentClass RADIO
m_CharacterOwner
SCR_RplTestComponentClass m_CharacterOwner
IN_STORAGE
SCR_GadgetComponentClass IN_STORAGE
Update
override void Update(float timeSlice)
Definition: SCR_CampaignBuildingGadgetToolComponent.c:28
OnPostInit
override void OnPostInit(IEntity owner)
Called on PostInit when all components are added.
Definition: SCR_AIConfigComponent.c:72
BUILDING_TOOL
SCR_GadgetComponentClass BUILDING_TOOL
GetOwner
IEntity GetOwner()
Owner entity of the fuel tank.
Definition: SCR_FuelNode.c:128
UpdateVisibility
private void UpdateVisibility()
Definition: SCR_InfoDisplayExtended.c:384
SY183
SCR_GadgetComponentClass SY183
InventoryItemComponent
Definition: InventoryItemComponent.c:12
B12
SCR_GadgetComponentClass B12
ON_GROUND
SCR_GadgetComponentClass ON_GROUND
Gadget mode.
ToggleFocused
override void ToggleFocused(bool enable)
Definition: SCR_BinocularsComponent.c:80
IsUsingADSControls
override bool IsUsingADSControls()
Definition: SCR_BinocularsComponent.c:100
MAP
SCR_GadgetComponentClass MAP
OnToggleActive
override void OnToggleActive(bool state)
Definition: SCR_CampaignBuildingGadgetToolComponent.c:41
WRISTWATCH
SCR_GadgetComponentClass WRISTWATCH
MX991
SCR_GadgetComponentClass MX991
ANPRC68
SCR_GadgetComponentClass ANPRC68
LAST
SCR_AIGroupInfoComponentClass LAST
FLASHLIGHT
SCR_GadgetComponentClass FLASHLIGHT
CanBeToggled
override bool CanBeToggled()
Definition: SCR_ConsumableItemComponent.c:239
IN_HAND
SCR_GadgetComponentClass IN_HAND
R148
SCR_GadgetComponentClass R148
CanBeRaised
override bool CanBeRaised()
Definition: SCR_BinocularsComponent.c:94
SPECIALIST_ITEM
SCR_GadgetComponentClass SPECIALIST_ITEM
M22
SCR_GadgetComponentClass M22
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180
ToggleActive
void ToggleActive()
Toggle map light.
Definition: SCR_MapLightUI.c:58