Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_FlashlightComponent.c
Go to the documentation of this file.
3{
4 [Attribute(uiwidget: UIWidgets.EditBox, desc: "Lense type", category: "Flashlight")]
5 string m_sDescription;
6
7 [Attribute("1 1 1", UIWidgets.ColorPicker, desc: "Lense color", category: "Flashlight")]
8 vector m_vLenseColor;
9
10 [Attribute("5.0", UIWidgets.Slider, desc: "Light Value", "-8.0 20 1", category: "Flashlight")]
11 float m_fLightValue;
12}
13
14[EntityEditorProps(category: "GameScripted/Gadgets", description: "Flashlight", color: "0 0 255 255")]
15class SCR_FlashlightComponentClass : SCR_GadgetComponentClass
17}
18
19class SCR_FlashlightComponent : SCR_GadgetComponent
20{
21 [Attribute("50", UIWidgets.EditBox, desc: "Intensity of the emmissive texture", params: "0 1000", category: "Flashlight")]
22 protected float m_fEmissiveIntensity;
23
24 [Attribute(uiwidget: UIWidgets.Object, desc: "Array of lense colors", category: "Flashlight")]
25 protected ref array<ref SCR_LenseColor> m_aLenseArray;
26
27 [Attribute("0.5", UIWidgets.EditBox, desc: "In meters, light ignores objects up to set distance to avoid unwanted shadows", params: "0.1 5", category: "Light near plane")]
28 protected float m_fLightNearPlaneHand;
29
30 [Attribute("1.2", UIWidgets.EditBox, desc: "In meters, light ignores objects up to set distance to avoid unwanted shadows", params: "0.1 5", category: "Light near plane")]
32
33 [Attribute("0.1", UIWidgets.EditBox, desc: "In meters, light ignores objects up to set distance to avoid unwanted shadows", params: "0.1 5", category: "Light near plane")]
34 protected float m_fLightNearPlaneVehicle;
35
36 [Attribute("0 0 -0.03", UIWidgets.EditBox, desc: "When strapped light entity is being aligned with weapon to adjust light angle, this entity is offset to avoid it visibly floating", category: "Flashlight")]
38
39 protected bool m_bLastLightState; // remember the last light state for cases where you put your flashlight into storage but there is no slot available -> true = active
40 protected bool m_bIsSlottedVehicle; // char owner is in vehicle while flashlight is slotted
41 protected bool m_bIsOccluded;
42 protected int m_iCurrentLenseColor;
43 protected vector m_vAnglesCurrent; // current local angles
44 protected vector m_vAnglesTarget; // target local angles used to align flashlight with aiming angles while strapped
45 protected vector m_ItemMat[4]; // owner transformation matrix
46 protected LightEntity m_Light;
50
51 //------------------------------------------------------------------------------------------------
52 override void OnToggleActive(bool state)
53 {
54 m_bActivated = state;
55
56 if (m_bActivated)
57 SCR_SoundManagerModule.CreateAndPlayAudioSource(GetOwner(), SCR_SoundEvent.SOUND_FLASHLIGHT_ON);
58 else
59 SCR_SoundManagerModule.CreateAndPlayAudioSource(GetOwner(), SCR_SoundEvent.SOUND_FLASHLIGHT_OFF);
60
62 }
63
64 //------------------------------------------------------------------------------------------------
66 protected void UpdateLightState()
67 {
68 if (m_bActivated)
70 else
72 }
73
74 //------------------------------------------------------------------------------------------------
77 {
78 if (!m_aLenseArray)
79 return 0;
80
81 return m_aLenseArray.Count();
82 }
83
84 //------------------------------------------------------------------------------------------------
88 {
89 int lastLensId = GetNumberOfAvailableLenses() - 1;
90 if (lastLensId < 1)
91 return;
92
93 if (direction)
95 else
97
99 SwitchLenses(lastLensId);
100 else if (m_iCurrentLenseColor > lastLensId)
101 SwitchLenses(0);
102 else
104 }
105
106 //------------------------------------------------------------------------------------------------
109 protected void SwitchLenses(int filter)
110 {
111 m_iCurrentLenseColor = filter;
112
116 m_EmissiveMaterial.SetEmissiveColor(lightColor.PackToInt());
117 }
118
119 //------------------------------------------------------------------------------------------------
121 protected void EnableLight()
122 {
123 if (m_Light)
124 m_Light.SetEnabled(true);
125
127 m_EmissiveMaterial.SetEmissiveMultiplier(m_fEmissiveIntensity);
128
130
131 if (m_iMode == EGadgetMode.IN_SLOT)
132 SetShadowNearPlane(true);
133 else if (m_iMode == EGadgetMode.IN_HAND)
134 SetShadowNearPlane(false);
135 }
136
137 //------------------------------------------------------------------------------------------------
139 protected void DisableLight()
140 {
141 if (m_Light)
142 m_Light.SetEnabled(false);
143
145 m_EmissiveMaterial.SetEmissiveMultiplier(0);
146
148 }
149
150 //------------------------------------------------------------------------------------------------
154 protected void SetShadowNearPlane(bool state, bool isLeavingVehicle = false)
155 {
156 float nearPlane;
157 m_bIsSlottedVehicle = false;
158
159 if (state) // strapped mode
160 {
161 nearPlane = m_fLightNearPlaneStrapped;
162 if (m_CompartmentComp && m_CompartmentComp.IsInCompartment() && !isLeavingVehicle)
163 {
164 nearPlane = m_fLightNearPlaneVehicle;
165 m_bIsSlottedVehicle = true;
167 }
168 else if (m_bActivated)
169 {
171 }
172 }
173 else // in hand mode
174 {
175 nearPlane = m_fLightNearPlaneHand;
176 }
177
178 if (m_Light)
179 m_Light.SetNearPlane(nearPlane);
180 }
181
182 //------------------------------------------------------------------------------------------------
183 protected void AdjustTransform(vector offset = vector.Zero)
184 {
185 InventoryItemComponent inventoryItemComp = InventoryItemComponent.Cast(GetOwner().FindComponent(InventoryItemComponent));
186 if (inventoryItemComp)
187 {
188 InventoryStorageSlot slot = inventoryItemComp.GetParentSlot();
189 ItemAnimationAttributes animAttr = ItemAnimationAttributes.Cast(inventoryItemComp.FindAttribute(ItemAnimationAttributes));
190 if (slot && animAttr)
191 {
192 vector matLS[4];
193 animAttr.GetAdditiveTransformLS(matLS);
194 matLS[3] = matLS[3] + m_vEquipmentSlotOffset + offset;
195 slot.SetAdditiveTransformLS(matLS);
196 }
197 }
198 }
199
200 //------------------------------------------------------------------------------------------------
202 protected void OnOwnerLifeStateChanged(ECharacterLifeState previousLifeState, ECharacterLifeState newLifeState)
203 {
204 if (newLifeState == ECharacterLifeState.ALIVE)
206 else
208 }
209
210 //------------------------------------------------------------------------------------------------
212 protected void OnCompartmentEntered(IEntity targetEntity, BaseCompartmentManagerComponent manager, int mgrID, int slotID, bool move)
213 {
214 if (!m_bActivated)
215 return;
216
217 BaseCompartmentSlot compSlot = manager.FindCompartment(slotID, mgrID);
218 IEntity occupant = compSlot.GetOccupant();
219 if (occupant == m_CharacterOwner)
220 {
221 SetShadowNearPlane(true);
222
223 if (PilotCompartmentSlot.Cast(compSlot))
224 ToggleActive(false, SCR_EUseContext.FROM_ACTION);
225 }
226 }
227
228 //------------------------------------------------------------------------------------------------
230 protected void OnCompartmentLeft(IEntity targetEntity, BaseCompartmentManagerComponent manager, int mgrID, int slotID, bool move)
231 {
232 if (!m_bActivated)
233 return;
234
235 BaseCompartmentSlot compSlot = manager.FindCompartment(slotID, mgrID);
236 IEntity occupant = compSlot.GetOccupant();
237 if (occupant == m_CharacterOwner)
238 SetShadowNearPlane(true, true);
239 }
240
241 //------------------------------------------------------------------------------------------------
242 override void OnSlotOccludedStateChanged(bool occluded)
243 {
244 m_bIsOccluded = occluded;
245 if (m_bActivated && !m_bIsOccluded)
246 EnableLight();
247 else
248 DisableLight();
249 }
250
251 //------------------------------------------------------------------------------------------------
252 override protected void ModeSwitch(EGadgetMode mode, IEntity charOwner)
253 {
254 super.ModeSwitch(mode, charOwner);
255
256 InventoryItemComponent inventoryItemComp = InventoryItemComponent.Cast(GetOwner().FindComponent(InventoryItemComponent));
257 if (!inventoryItemComp)
258 return;
259
260 if (!charOwner)
261 {
263 m_CharController.m_OnLifeStateChanged.Remove(OnOwnerLifeStateChanged);
264
265 m_CharController = null;
266 }
267 else
268 {
271
273 m_CharController.m_OnLifeStateChanged.Insert(OnOwnerLifeStateChanged);
274 }
275
276 inventoryItemComp.SetTraceable(mode != EGadgetMode.IN_SLOT);
277
278 if (m_bActivated && (mode == EGadgetMode.IN_STORAGE || mode == EGadgetMode.ON_GROUND))
279 {
280 m_bLastLightState = m_bActivated;
281 OnToggleActive(false);//direct call since ToggleActive requries m_CharacterOwner to not be null as he then asks for propagation of the change
282 }
283 else if (mode == EGadgetMode.IN_SLOT || mode == EGadgetMode.IN_HAND)
284 {
285 if (m_bLastLightState && (!m_bActivated || m_Light && !m_Light.IsEnabled())) // LightEntity is disabled in EOnDeactivate aka when its dropped on the ground
287
288 SetShadowNearPlane(mode != EGadgetMode.IN_HAND);
289 }
290
291 if (mode == EGadgetMode.IN_SLOT)
292 {
293 SCR_EquipmentStorageSlot parentSlot = SCR_EquipmentStorageSlot.Cast(inventoryItemComp.GetParentSlot());
294 if (parentSlot && parentSlot.IsOccluded())
295 {
296 m_bIsOccluded = true;
297 DisableLight();
298 }
299
302 {
303 m_CompartmentComp.GetOnCompartmentEntered().Insert(OnCompartmentEntered);
304 m_CompartmentComp.GetOnCompartmentLeft().Insert(OnCompartmentLeft);
305 }
306 }
307 }
308
309 //------------------------------------------------------------------------------------------------
310 override protected void ModeClear(EGadgetMode mode)
311 {
312 if (mode == EGadgetMode.IN_SLOT)
313 {
314 m_bIsOccluded = false;
316 {
317 m_CompartmentComp.GetOnCompartmentEntered().Remove(OnCompartmentEntered);
318 m_CompartmentComp.GetOnCompartmentLeft().Remove(OnCompartmentLeft);
319 }
320
321 SetShadowNearPlane(false);
322 }
323
324 super.ModeClear(mode);
325 }
326
327 //------------------------------------------------------------------------------------------------
328 override protected void ToggleActive(bool state, SCR_EUseContext context)
329 {
330 if (m_iMode == EGadgetMode.IN_STORAGE && !m_bActivated) // trying to activate flashlight hidden in inventory
331 return;
332
333 // trying to activate flashlight while driving
334 if (!m_bActivated && m_CompartmentComp && PilotCompartmentSlot.Cast(m_CompartmentComp.GetCompartment()))
335 return;
336
337 super.ToggleActive(state, context);
338 }
339
340 //------------------------------------------------------------------------------------------------
341 override void ActivateAction()
342 {
343 if (m_CharController && m_CharController.GetLifeState() != ECharacterLifeState.ALIVE) // if in chars inventory && char is dead/uncon
344 return;
345
346 ToggleActive(!m_bActivated, SCR_EUseContext.FROM_ACTION);
347 }
348
349 //------------------------------------------------------------------------------------------------
350 override protected void ActivateGadgetUpdate()
351 {
352 super.ActivateGadgetUpdate();
353
355 }
356
357 //------------------------------------------------------------------------------------------------
358 override protected void DeactivateGadgetUpdate()
359 {
360 super.DeactivateGadgetUpdate();
361
362 if (m_iMode == EGadgetMode.IN_SLOT) // reset slot position of the gadget back to its default
364 }
365
366 //------------------------------------------------------------------------------------------------
367 override EGadgetType GetType()
368 {
369 return EGadgetType.FLASHLIGHT;
370 }
371
372 //------------------------------------------------------------------------------------------------
373 override bool IsVisibleEquipped()
374 {
375 return true;
376 }
377
378 //------------------------------------------------------------------------------------------------
379 override bool RplSave(ScriptBitWriter writer)
380 {
381 if (!super.RplSave(writer))
382 return false;
383
384 writer.WriteBool(m_bActivated);
385 writer.WriteInt(m_iCurrentLenseColor);
386
387 return true;
388 }
389
390 //------------------------------------------------------------------------------------------------
391 override bool RplLoad(ScriptBitReader reader)
392 {
393 if (!super.RplLoad(reader))
394 return false;
395
396 reader.ReadBool(m_bActivated);
397 reader.ReadInt(m_iCurrentLenseColor);
398
400
401 return true;
402 }
403
404 //------------------------------------------------------------------------------------------------
405 override bool OnTicksOnRemoteProxy()
406 {
407 return true; // proxies will only tick on owners without this
408 }
409
410 //------------------------------------------------------------------------------------------------
411 override void Update(float timeSlice)
412 {
413 if (!m_CharController)
414 {
416 return;
417 }
418
419 // adjust angle of the flashlight to provide usable angle within various poses
420 m_Light.GetTransform(m_ItemMat);
421 m_vAnglesCurrent = m_Light.GetLocalYawPitchRoll();
422 m_vAnglesTarget = (Math.RAD2DEG * m_CharController.GetInputContext().GetAimingAngles() - Math3D.MatrixToAngles(m_ItemMat)) + m_vAnglesCurrent; // diff between WS aiming and item angles, add local to the result
424 m_vAnglesTarget[1] = Math.Clamp(m_vAnglesTarget[1], 0, 30); // only need too offset upwards, also avoid glitches with some stances
425 m_vAnglesTarget[2] = 0; // no roll
426
427 m_vAnglesTarget[0] = Math.Lerp(m_vAnglesCurrent[0], m_vAnglesTarget[0], timeSlice* 4);
428 m_vAnglesTarget[1] = Math.Lerp(m_vAnglesCurrent[1], m_vAnglesTarget[1], timeSlice* 4);
429 m_Light.SetYawPitchRoll(m_vAnglesTarget); // sets local angles
430 }
431
432 //------------------------------------------------------------------------------------------------
433 override void EOnInit(IEntity owner)
434 {
435 m_Light = LightEntity.Cast(owner.GetChildren());
437
438 // Insert default entry if none are set
439 if (m_aLenseArray.Count() == 0)
440 {
441 SCR_LenseColor defColor = new SCR_LenseColor();
442 defColor.m_sDescription = "CONFIGURE ME";
443 m_aLenseArray.Insert(defColor);
444 }
445 }
446}
SCR_RplTestComponentClass m_CharacterOwner
SCR_AIAnimation_Loitering BaseContainerProps
Commanding menu commanding element class.
vector direction
SCR_EUseContext
float m_fLightValue
vector m_vLenseColor
class SCR_LenseColor EntityEditorProps(category:"GameScripted/Gadgets", description:"Flashlight", color:"0 0 255 255")
class SCR_KeyBindingFilter BaseContainerCustomTitleField("m_sBindString")
void ToggleActive()
Toggle map light.
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition Color.c:13
proto external Managed FindComponent(typename typeName)
proto external IEntity GetChildren()
Definition Math.c:13
SCR_CompartmentAccessComponent m_CompartmentComp
override bool RplSave(ScriptBitWriter writer)
override void OnSlotOccludedStateChanged(bool occluded)
void OnCompartmentEntered(IEntity targetEntity, BaseCompartmentManagerComponent manager, int mgrID, int slotID, bool move)
SCR_CompartmentAccessComponent event.
void ModeClear(EGadgetMode mode)
ParametricMaterialInstanceComponent m_EmissiveMaterial
void UpdateLightState()
Update state of light ON/OFF.
void EnableLight()
Spawn light entity.
override void Update(float timeSlice)
ref array< ref SCR_LenseColor > m_aLenseArray
SCR_CharacterControllerComponent m_CharController
override EGadgetType GetType()
void SetShadowNearPlane(bool state, bool isLeavingVehicle=false)
override bool RplLoad(ScriptBitReader reader)
override void OnToggleActive(bool state)
void OnCompartmentLeft(IEntity targetEntity, BaseCompartmentManagerComponent manager, int mgrID, int slotID, bool move)
SCR_CompartmentAccessComponent event.
void AdjustTransform(vector offset=vector.Zero)
void ToggleActive(bool state, SCR_EUseContext context)
void OnOwnerLifeStateChanged(ECharacterLifeState previousLifeState, ECharacterLifeState newLifeState)
SCR_CompartmentAccessComponent event.
void CycleThroughLenses(bool direction)
override void EOnInit(IEntity owner)
void ModeSwitch(EGadgetMode mode, IEntity charOwner)
static float FixAngle(float angle, float units=Math.PI)
Definition SCR_Math.c:280
IEntity GetOwner()
Owner entity of the fuel tank.
ECharacterLifeState
SCR_FieldOfViewSettings Attribute