Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_PlayerController.c
Go to the documentation of this file.
4
5//------------------------------------------------------------------------------------------------
8typedef ScriptInvokerBase<OnControlledEntityChangedPlayerController> OnControlledEntityChangedPlayerControllerInvoker;
9
10//------------------------------------------------------------------------------------------------
11void OwnershipChangedDelegate(bool isChanging, bool becameOwner);
13typedef ScriptInvokerBase<OwnershipChangedDelegate> OnOwnershipChangedInvoker;
14
15//------------------------------------------------------------------------------------------------
18typedef ScriptInvokerBase<OnDestroyedPlayerController> OnDestroyedPlayerControllerInvoker;
19
20//------------------------------------------------------------------------------------------------
21void OnPossessed(IEntity entity);
23typedef ScriptInvokerBase<OnPossessed> OnPossessedInvoker;
24
25//------------------------------------------------------------------------------------------------
28typedef ScriptInvokerBase<OnBeforePossessed> OnBeforePossessedInvoker;
29
30class SCR_PlayerController : PlayerController
31{
32 static SCR_PlayerController s_pLocalPlayerController;
33 protected static const float WALK_SPEED = 0.5;
34 protected static const float FOCUS_ACTIVATION = 0.1;
35 protected static const float FOCUS_DEACTIVATION = 0.05;
36 protected static const float FOCUS_TIMEOUT = 0.3;
37 protected static const float FOCUS_TOLERANCE = 0.005;
38 protected static const float FOCUS_ANALOGUE_SCALE = 3.0;
39 protected static float s_fADSFocus = 0.5;
40 protected static float s_fPIPFocus = 1;
41 protected static float s_fFocusTimeout;
42 protected static float s_fFocusAnalogue;
43 protected static bool s_bWasADS;
44
45 protected CharacterControllerComponent m_CharacterController;
47 protected bool m_bIsPaused;
48 protected bool m_bIsBinocularsZoomed;
50 protected bool m_bGadgetFocus;
52 protected float m_fCharacterSpeed;
53
54
55 [RplProp(onRplName: "OnRplMainEntityFromID")]
58
59 [RplProp()]
60 protected bool m_bIsPossessing;
61
62 ref OnBeforePossessedInvoker m_OnBeforePossess = new OnBeforePossessedInvoker(); // Before an entity becomes possesed.
63 ref OnPossessedInvoker m_OnPossessed = new OnPossessedInvoker(); // when entity becomes possessed or control returns to the main entity
67 //------------------------------------------------------------------------------------------------
75
76 //------------------------------------------------------------------------------------------------
80 protected override void OnOwnershipChanged(bool changing, bool becameOwner)
81 {
82 super.OnOwnershipChanged(changing, becameOwner);
83
84 if (becameOwner)
85 {
86 SocialComponent socialComp = SocialComponent.Cast(FindComponent(SocialComponent));
87 if (socialComp)
88 socialComp.m_OnBlockedPlayerJoinedInvoker.Insert(OnBlockedPlayerJoined);
89
90 if (!changing)
91 {
93 managerCore.Event_OnEditorManagerInitOwner.Insert(OnPlayerRegistered);
94 }
95
96 // registering own local player controller to local MarkerManager
97 const SCR_BaseGameMode gameMode = SCR_BaseGameMode.Cast(GetGame().GetGameMode());
98 if (gameMode && !gameMode.IsMaster())
99 {
100 SCR_MapMarkerManagerComponent markerManager = SCR_MapMarkerManagerComponent.Cast(gameMode.FindComponent(SCR_MapMarkerManagerComponent));
101 if (markerManager)
102 markerManager.RegisterLocalController(this);
103 }
104 }
105
106 SCR_DamageSufferingSystem.GetInstance().StartObservingControlledEntityChanges(this, changing, becameOwner);
107
108 m_OnOwnershipChangedInvoker.Invoke(changing, becameOwner);
109 }
110
111 //------------------------------------------------------------------------------------------------
112 override protected void OnInit(IEntity owner)
113 {
114 if (!GetGame().InPlayMode())
115 return;
116
117 if (Replication.IsServer()) // this is here because listen server or SP client will not call OnOwnershipChanged as there is no transfer of ownership
119 }
120
121 //------------------------------------------------------------------------------------------------
123 {
125 managerCore.Event_OnEditorManagerInitOwner.Remove(OnPlayerRegistered);
126
127 // Register for blocklist update and request it
128 GameBlocklist blocklist = GetGame().GetGameBlocklist();
129 blocklist.OnBlockListUpdateInvoker.Insert(OnBlockedListUpdated);
130 blocklist.UpdateBlockList();
131 }
132
133 //------------------------------------------------------------------------------------------------
134 void OnBlockedListUpdated(bool success)
135 {
136 if (!success)
137 {
138 // Some logging would be nice
139 return;
140 }
141
142 // Remove only when it succeeds
143 GameBlocklist blocklist = GetGame().GetGameBlocklist();
144 blocklist.OnBlockListUpdateInvoker.Remove(OnBlockedListUpdated);
145
146 // Request all the authors
148 if (!core)
149 return;
150
152 core.RequestAllAuthors();
153 }
154
155 //------------------------------------------------------------------------------------------------
156 void OnAuthorsRequestFinished(set<SCR_EditableEntityAuthor> activeUGCAuthors)
157 {
159 if (!core)
160 return;
161
163
164 PrintFormat("SCR_PlayerController::OnAuthorsRequestFinished - Number of UGC Authors: %1", activeUGCAuthors.Count(), level: LogLevel.VERBOSE);
165
166 GameBlocklist blocklist = GetGame().GetGameBlocklist();
167
168 array<string> identityIDs = {};
169 foreach (SCR_EditableEntityAuthor author : activeUGCAuthors)
170 {
171 identityIDs.Insert(author.m_sAuthorUID);
172 }
173 PlayerManager.s_OnPlayerNameCacheUpdateInvoker.Insert(OnPlayerNameCacheUpdate);
174 PlayerManager.RequestPlayerNameCacheUpdate(identityIDs);
175
176 bool isBlockedAuthorPresent;
177 foreach (SCR_EditableEntityAuthor author : activeUGCAuthors)
178 {
179 const bool isBlocked = blocklist.IsBlockedIdentity(author.m_sAuthorUID, author.m_ePlatform, author.m_sAuthorPlatformID);
180 if (isBlocked)
181 {
183 "Blocked user left UGC in this world {identity: %1; account: %2; platform: %3}",
184 author.m_sAuthorUID,
185 author.m_sAuthorPlatformID,
186 author.m_ePlatform,
187 level: LogLevel.VERBOSE
188 );
189 isBlockedAuthorPresent = true;
190 break;
191 }
192 }
193
194 if (isBlockedAuthorPresent)
195 {
196 SCR_ConfigurableDialogUi dialog = SCR_ConfigurableDialogUi.CreateFromPreset(SCR_CommonDialogs.DIALOGS_CONFIG, "blocked_ugc_present");
197 dialog.m_OnCancel.Insert(DisconnectFromGame);
198 }
199 }
200
201 //------------------------------------------------------------------------------------------------
202 void OnPlayerNameCacheUpdate(bool success)
203 {
204 Print("SCR_PlayerController - Name Cache Updated!", LogLevel.VERBOSE);
205 PlayerManager.s_OnPlayerNameCacheUpdateInvoker.Remove(OnPlayerNameCacheUpdate);
206 }
207
208 //------------------------------------------------------------------------------------------------
210 {
211 ChimeraWorld world = GetGame().GetWorld();
212 world.PauseGameTime(false);
213
214 GameStateTransitions.RequestGameplayEndTransition();
215 }
216
217 //------------------------------------------------------------------------------------------------
218 void OnBlockedPlayerJoined(int playerID)
219 {
220 SCR_NotificationsComponent.SendLocal(ENotification.PLAYER_ON_BLOCKLIST_JOINED, playerID);
221 }
222
223 //------------------------------------------------------------------------------------------------
225 {
226 m_OnControlledEntityChanged.Invoke(from, to);
227
228 ChimeraCharacter character = ChimeraCharacter.Cast(to);
229 if (character)
230 m_CharacterController = character.GetCharacterController();
231 else
233
235
237 SCR_AimSensitivitySettings.SetAimSensitivitySettings();
238 SCR_HeadTrackingSettings.SetHeadTrackingSettings();
239 SCR_ControllerSettings.SetControllerSettings();
240 }
241
243 {
244 ChimeraCharacter abandonedCharacter = ChimeraCharacter.Cast(from);
245 SCR_CompartmentAccessComponent compartmentAccessComp;
246 SCR_FireModeManagerComponent fireModeMgr;
247 if (abandonedCharacter)
248 {
249 compartmentAccessComp = SCR_CompartmentAccessComponent.Cast(abandonedCharacter.GetCompartmentAccessComponent());
250 fireModeMgr = compartmentAccessComp.GetControlledFireModeManager();
251 if (fireModeMgr)
252 fireModeMgr.RemoveActionListeners();
253 }
254
255 ChimeraCharacter possessedCharacter = ChimeraCharacter.Cast(to);
256 if (!possessedCharacter)
257 return;
258
259 compartmentAccessComp = SCR_CompartmentAccessComponent.Cast(possessedCharacter.GetCompartmentAccessComponent());
260 fireModeMgr = compartmentAccessComp.GetControlledFireModeManager();
261 if (fireModeMgr)
262 fireModeMgr.SetUpAllActionListeners(possessedCharacter);
263 }
264
265 //------------------------------------------------------------------------------------------------
267 {
268 BaseContainer gameplaySettings = GetGame().GetGameUserSettings().GetModule("SCR_GameplaySettings");
269
271 {
272 bool stickyADS;
273 if (gameplaySettings.Get("m_bStickyADS", stickyADS))
274 CharacterControllerComponent.SetStickyADS(stickyADS);
275
276 bool stickyGadgets;
277 if (gameplaySettings.Get("m_bStickyGadgets", stickyGadgets))
278 CharacterControllerComponent.SetStickyGadget(stickyGadgets);
279
280 bool mouseControlAircraft;
281 if (gameplaySettings.Get("m_bMouseControlAircraft", mouseControlAircraft))
282 CharacterControllerComponent.SetMouseControlAircraft(mouseControlAircraft);
283
284 bool gamepadFreelookInAircraft;
285 if (gameplaySettings.Get("m_bGamepadFreelookInAircraft", gamepadFreelookInAircraft))
286 CharacterControllerComponent.SetGamepadControlAircraft(!gamepadFreelookInAircraft);
287
288 EVehicleDrivingAssistanceMode drivingAssistance;
289 if (gameplaySettings.Get("m_eDrivingAssistance", drivingAssistance))
290 VehicleControllerComponent.SetDrivingAssistanceMode(drivingAssistance);
291 }
292
293 BaseContainer fovSettings = GetGame().GetGameUserSettings().GetModule("SCR_FieldOfViewSettings");
294 if (fovSettings)
295 {
296 float focusInADS;
297 if (fovSettings.Get("m_fFocusInADS", focusInADS))
298 s_fADSFocus = focusInADS;
299
300 float focusInPIP;
301 if (fovSettings.Get("m_fFocusInPIP", focusInPIP))
302 s_fPIPFocus = focusInPIP;
303 }
304 }
305
306 //------------------------------------------------------------------------------------------------
313 {
314 if (!m_bIsPossessing)
315 {
316 if (entity)
317 {
318 m_OnBeforePossess.Invoke(entity);
319 //--- Start posessing
320 m_bIsPossessing = true;
321
322 //--- Remember previously controlled entity
323 IEntity controlledEntity = GetControlledEntity();
324 m_MainEntityID = RplId.Invalid();
325 if (controlledEntity)
326 {
327 RplComponent rpl = RplComponent.Cast(controlledEntity.FindComponent(RplComponent));
328 if (rpl)
329 {
330 rpl.GiveExt(RplIdentity.Local(), false);
331 m_MainEntityID = rpl.Id();
332 }
333 }
334
335 OnRplMainEntityFromID(); //--- ToDo: Remove? BumpMe should call it automatically.
336 Replication.BumpMe();
337
338 //-- Tell manager we're possessing an entity
339 SCR_PossessingManagerComponent possessingManager = SCR_PossessingManagerComponent.GetInstance();
340 if (possessingManager)
341 possessingManager.SetMainEntity(GetPlayerId(), entity, controlledEntity, m_bIsPossessing);
342
343 //--- Switch control
344 RplComponent rpl = RplComponent.Cast(entity.FindComponent(RplComponent));
345 if (rpl)
346 rpl.GiveExt(GetRplIdentity(), false);
347 SetAIActivation(entity, false);
348 SetControlledEntity(entity);
349 m_OnPossessed.Invoke(entity);
350 }
351 }
352 else
353 {
354 if (!entity)
355 {
356 //--- Stop possessing
357 m_bIsPossessing = false;
358
359 //--- Forget main entity
360 m_MainEntityID = RplId.Invalid();
361 OnRplMainEntityFromID(); //--- ToDo: Remove?
362 Replication.BumpMe();
363
364 SCR_PossessingManagerComponent possessingManager = SCR_PossessingManagerComponent.GetInstance();
365 if (possessingManager)
366 possessingManager.SetMainEntity(GetPlayerId(), GetControlledEntity(), m_MainEntity, m_bIsPossessing);
367
368 //--- Switch control
369 IEntity controlledEntity = GetControlledEntity();
370 if (controlledEntity)
371 {
372 RplComponent rpl = RplComponent.Cast(controlledEntity.FindComponent(RplComponent));
373 if (rpl)
374 rpl.GiveExt(RplIdentity.Local(), false);
375
376 SetAIActivation(controlledEntity, true);
377 }
378
379 //--- Switch control
380 if (m_MainEntity)
381 {
382 RplComponent rpl = RplComponent.Cast(m_MainEntity.FindComponent(RplComponent));
383 if (rpl)
384 rpl.GiveExt(GetRplIdentity(), false);
385 }
388
389 //--- SetControlledEntity(null) doesn't work yet. ToDo: Remove this check once it's implemented
391 Print(string.Format("Error when switching control back to m_MainEntity = %1!", m_MainEntity), LogLevel.WARNING);
392 }
393 else
394 {
395 //--- Switch possessing
396 SetPossessedEntity(null);
397 SetPossessedEntity(entity);
398 m_OnPossessed.Invoke(entity);
399 }
400 }
401 }
402
403 //------------------------------------------------------------------------------------------------
408 void SetInitialMainEntity(notnull IEntity entity)
409 {
410 RplComponent rpl = RplComponent.Cast(entity.FindComponent(RplComponent));
411 if (!rpl)
412 return;
413
414 m_MainEntityID = rpl.Id();
416 Replication.BumpMe();
417
418 SCR_PossessingManagerComponent possessingManager = SCR_PossessingManagerComponent.GetInstance();
419 if (possessingManager)
420 possessingManager.SetMainEntity(GetPlayerId(), GetControlledEntity(), entity, m_bIsPossessing);
421
422 rpl.GiveExt(GetRplIdentity(), false); // transfer ownership
423 SetAIActivation(entity, false);
424 SetControlledEntity(entity);
425
426 m_OnPossessed.Invoke(entity);
427 }
428
429 //------------------------------------------------------------------------------------------------
435 {
436 return m_bIsPossessing;
437 }
438
439 //------------------------------------------------------------------------------------------------
447 {
448 if (m_bIsPossessing)
449 return m_MainEntity;
450 else
451 return GetControlledEntity();
452 }
453
454 //------------------------------------------------------------------------------------------------
455 protected void OnRplMainEntityFromID()
456 {
457 //m_MainEntity = IEntity.Cast(Replication.FindItem(m_MainEntityID));
458 RplComponent rpl = RplComponent.Cast(Replication.FindItem(m_MainEntityID));
459 if (rpl)
460 m_MainEntity = rpl.GetEntity();
461 }
462
463 //------------------------------------------------------------------------------------------------
464 protected void SetAIActivation(IEntity entity, bool activate)
465 {
466 if (!entity)
467 return;
468
469 AIControlComponent aiControl = AIControlComponent.Cast(entity.FindComponent(AIControlComponent));
470 if (!aiControl)
471 return;
472
473 if (activate)
474 aiControl.ActivateAI();
475 else
476 aiControl.DeactivateAI();
477 }
478
479 //------------------------------------------------------------------------------------------------
481 static int GetLocalPlayerId()
482 {
483 PlayerController pPlayerController = GetGame().GetPlayerController();
484 if (!pPlayerController)
485 return 0;
486
487 return pPlayerController.GetPlayerId();
488 }
489
490 //------------------------------------------------------------------------------------------------
496 {
497 PlayerController pPlayerController = GetGame().GetPlayerController();
498 if (pPlayerController)
499 return pPlayerController.GetControlledEntity();
500
501 return null;
502 }
503
504 //------------------------------------------------------------------------------------------------
512 {
514 if (playerController)
515 return playerController.GetMainEntity();
516 else
517 return null;
518 }
519
520 //---- REFACTOR NOTE START: This code will need to be refactored as current implementation is not conforming to the standards ----
521 // TODO: Use getter for faction affiliation component
522 //------------------------------------------------------------------------------------------------
528 {
529 PlayerController playerController = GetGame().GetPlayerController();
530 if (!playerController)
531 return null;
532
533 IEntity controlledEntity = playerController.GetControlledEntity();
534 if (!controlledEntity)
535 return null;
536
537 FactionAffiliationComponent factionAffiliation = FactionAffiliationComponent.Cast(controlledEntity.FindComponent(FactionAffiliationComponent));
538 if (factionAffiliation)
539 return factionAffiliation.GetAffiliatedFaction();
540 else
541 return null;
542 }
543
544 //------------------------------------------------------------------------------------------------
552 {
554 if (!playerController)
555 return null;
556
557 IEntity controlledEntity = playerController.GetMainEntity();
558 if (!controlledEntity)
559 return null;
560
561 FactionAffiliationComponent factionAffiliation = FactionAffiliationComponent.Cast(controlledEntity.FindComponent(FactionAffiliationComponent));
562 if (factionAffiliation)
563 return factionAffiliation.GetAffiliatedFaction();
564 else
565 return null;
566 }
567 //---- REFACTOR NOTE END ----
568
569 //------------------------------------------------------------------------------------------------
570 override void OnDestroyed(notnull Instigator killer)
571 {
572 super.OnDestroyed(killer);
573 IEntity killerEntity = killer.GetInstigatorEntity();
574 m_OnDestroyed.Invoke(killer, killerEntity);
575 }
576
577 //------------------------------------------------------------------------------------------------
578 override void OnUpdate(float timeSlice)
579 {
580 if (!s_pLocalPlayerController)
582
584 {
586 //UpdateUI();
587 }
588 }
589
590 //------------------------------------------------------------------------------------------------
593 {
594 m_bIsLocalPlayerController = this == GetGame().GetPlayerController();
596 return;
597
598 s_pLocalPlayerController = this;
599 InputManager inputManager = GetGame().GetInputManager();
600 if (!inputManager)
601 return;
602
603 inputManager.AddActionListener("WeaponChangeMagnification", EActionTrigger.VALUE, ChangeMagnification);
604 inputManager.AddActionListener("CharacterWalk", EActionTrigger.DOWN, OnWalk);
605 inputManager.AddActionListener("CharacterWalk", EActionTrigger.UP, OnEndWalk);
606 inputManager.AddActionListener("FocusToggle", EActionTrigger.DOWN, ActionFocusToggle);
607 inputManager.AddActionListener("FocusToggleVehicle", EActionTrigger.DOWN, ActionFocusToggleVehicle);
608 inputManager.AddActionListener("FocusToggleUnarmed", EActionTrigger.DOWN, ActionFocusToggleUnarmed);
609 inputManager.AddActionListener("Inventory", EActionTrigger.DOWN, ActionOpenInventory);
610 inputManager.AddActionListener("TacticalPing", EActionTrigger.DOWN, ActionGesturePing);
611 inputManager.AddActionListener("TacticalPingHold", EActionTrigger.DOWN, ActionGesturePingHold);
612 inputManager.AddActionListener("TacticalPingHold", EActionTrigger.UP, ActionGesturePingHold);
613 inputManager.AddActionListener("WeaponSwitchOptics", EActionTrigger.UP, ChangeWeaponOptics);
614 }
615
616 //------------------------------------------------------------------------------------------------
618 protected void UpdateControls()
619 {
620 bool disableControls = GetGame().GetMenuManager().IsAnyMenuOpen();
621 if (m_bIsPaused != disableControls)
622 {
623 m_bIsPaused = disableControls;
624 SetDisableControls(disableControls);
625 }
626 }
627
628 //---- REFACTOR NOTE START: This code will need to be refactored as current implementation is not conforming to the standards ----
629 // TODO: This is obsolete
630 //------------------------------------------------------------------------------------------------
631 protected void UpdateUI()
632 {
634 if (!char)
635 return;
636 CharacterAnimationComponent animComp = char.GetAnimationComponent();
637 if (!animComp)
638 return;
639 // Command ladder is present only when character is using ladder
640 CharacterCommandLadder ladderCMD = animComp.GetCommandHandler().GetCommandLadder();
641 if (!ladderCMD)
642 return;
643 int lrExitState = ladderCMD.CanExitLR();
644 if (lrExitState & 0x1)
645 {
646 Print("Can exit right");
647 }
648 if (lrExitState & 0x2)
649 {
650 Print("Can exit left");
651 }
652 }
653 //---- REFACTOR NOTE END ----
654
655 //------------------------------------------------------------------------------------------------
656 protected void ChangeMagnification(float value)
657 {
659 if (characterController)
660 characterController.SetNextSightsFOVInfo(value);
661 }
662
663 //------------------------------------------------------------------------------------------------
664 protected void ChangeWeaponOptics()
665 {
667 if (characterController)
668 characterController.SetNextSights();
669 }
670
671 //------------------------------------------------------------------------------------------------
673 {
675 if (!char)
676 return null;
677
679 }
680
681 //------------------------------------------------------------------------------------------------
682 // Parameter value:
683 // TRUE: Disables the controls
684 // FALSE: Enables the controls
685 private void SetDisableControls(bool value)
686 {
688 if (!characterController)
689 return;
690
691 characterController.SetDisableViewControls(value);
692 characterController.SetDisableWeaponControls(value);
693 characterController.SetDisableMovementControls(value)
694 }
695
696 //------------------------------------------------------------------------------------------------
702 float GetFocusValue(float adsProgress = 0, float dt = -1)
703 {
705
706 return 0;
707 float focus;
708
709 // Autofocus
710 if (adsProgress > 0)
711 {
712 // PIPCQB Separate slider
713 if (SCR_2DPIPSightsComponent.IsPIPActive())
714 focus = Math.Lerp(s_fADSFocus, 1, s_fPIPFocus);
715 else
716 focus = s_fADSFocus;
717
718 focus *= Math.Min(adsProgress, 1);
719
720 if (m_CharacterController.IsFreeLookEnabled())
721 {
722 // Freelook angle effect on ADS focus
723 CharacterHeadAimingComponent headAiming = m_CharacterController.GetHeadAimingComponent();
724 if (headAiming)
725 {
726 float freelookAngle = headAiming.GetAimingRotation().Length();
727 float freelookFocus = 1 - Math.InverseLerp(1, 6, freelookAngle);
728 focus *= Math.Clamp(freelookFocus, 0, 1);
729 }
730 }
731 }
732
733 InputManager inputManager = GetGame().GetInputManager();
734
735 // Cancel toggled focus when focus is held
736 bool inputDigital = inputManager.GetActionTriggered("Focus");
737 if (inputDigital && m_eFocusToggle != SCR_EFocusToggleMode.DISABLED)
739
740 // Conditions must be consistent with ActionFocusToggle and ActionFocusToggleUnarmed
741 ChimeraCharacter character = m_CharacterController.GetCharacter();
742 if (character && character.IsInVehicle())
743 {
744 // Vehicle focus toggle mode
746 {
747 // Cancel toggle focus when in vehicle and aiming through gadget (binocular, compass)
748 if (m_bGadgetFocus)
750
751 // Cancel toggle focus when in vehicle and not in forced freelook
752 if (!m_CharacterController.IsFreeLookEnabled() && !m_CharacterController.GetFreeLookInput())
754 }
755 }
756 else
757 {
758 // Unarmed focus toggle mode
760 {
761 // Cancel toggle focus when not in vehicle and holding item in hands
762 if (m_CharacterController.GetCurrentItemInHands())
764
765 // Cancel toggle focus when not in vehicle and holding gadget
766 if (m_CharacterController.IsGadgetInHands())
768 }
769 }
770
771 // Vehicles have different focus action to prevent conflict with brakes
772 bool isVehicleContextActive = inputManager.IsContextActive("CarContext") || inputManager.IsContextActive("TrackedContext") || inputManager.IsContextActive("HelicopterContext");
773 float inputAnalogue;
774 if (!isVehicleContextActive)
775 {
776 // Square root input to focus mapping results in linear change of picture area
777 float focusAnalogue = Math.Sqrt(FOCUS_ANALOGUE_SCALE * inputManager.GetActionValue("FocusAnalog"));
778
779 // Tolerance to prevent jittering
780 if (focusAnalogue < FOCUS_DEACTIVATION)
782 else if (!float.AlmostEqual(s_fFocusAnalogue, focusAnalogue, FOCUS_TOLERANCE))
783 s_fFocusAnalogue = focusAnalogue;
784
785 inputAnalogue = s_fFocusAnalogue;
786 }
787
788 bool isADS = m_CharacterController.GetWeaponADSInput();
789
790 // Check gadget ADS
791 if (!isADS && m_CharacterController.IsGadgetInHands())
792 isADS = m_CharacterController.IsGadgetRaisedModeWanted();
793
794 // Verify turrets
795 if (!isADS && character)
796 {
797 CompartmentAccessComponent compartmentAccess = character.GetCompartmentAccessComponent();
798
799 BaseCompartmentSlot compartment;
800 if (compartmentAccess)
801 compartment = compartmentAccess.GetCompartment();
802
803 TurretControllerComponent turretController;
804 if (compartment)
805 turretController = TurretControllerComponent.Cast(compartment.GetController());
806
807 if (turretController)
808 isADS = turretController.IsWeaponADS();
809 }
810
811 // Prevent focus warping back while toggling ADS on controller
812 // analogue: track timeout as we have no input filter that has thresholds or delays and returns axis value yet
813 if (inputAnalogue < FOCUS_DEACTIVATION)
814 s_fFocusTimeout = FOCUS_TIMEOUT; // Below deactivation threshold
815 else if (s_bWasADS != isADS && s_fFocusTimeout > 0)
816 s_fFocusTimeout = FOCUS_TIMEOUT; // ADS toggled
817 else if (inputAnalogue < FOCUS_ACTIVATION && s_fFocusTimeout > 0)
818 s_fFocusTimeout = FOCUS_TIMEOUT; // Below activation threshold and not active
819 else if (s_fFocusTimeout > dt)
820 s_fFocusTimeout -= dt; // Not yet active, decrementing
821 else
822 s_fFocusTimeout = 0; // Activated
823
824 // Cancel toggle focus with analogue input
827
828 s_bWasADS = isADS;
829
830 // Combine all valid input sources
831 float input;
832 if (m_eFocusToggle != SCR_EFocusToggleMode.DISABLED || inputDigital)
833 input = 1;
834 else if (s_fFocusTimeout == 0)
835 input = inputAnalogue;
836
837 if (input > 0)
838 focus = Math.Max(focus, input);
839
840 // Ensure return value always within 0-1
841 focus = Math.Clamp(focus, 0, 1);
842 return focus;
843 }
844
845 //------------------------------------------------------------------------------------------------
847 void SetIsBinocularsZoomed(bool value)
848 {
849 m_bIsBinocularsZoomed = value;
850 }
851
852 //------------------------------------------------------------------------------------------------
854 bool GetIsBinocularsZoomed()
855 {
857 }
858
859 //------------------------------------------------------------------------------------------------
861 void SetGadgetFocus(bool gadgetFocus)
862 {
863 m_bGadgetFocus = gadgetFocus;
864 }
865
866 //------------------------------------------------------------------------------------------------
868 bool GetGadgetFocus()
869 {
870 return m_bGadgetFocus;
871 }
872
873 //---- REFACTOR NOTE START: This code will need to be refactored as current implementation is not conforming to the standards ----
875 //------------------------------------------------------------------------------------------------
876 void ActionFocusToggle(float value = 0.0, EActionTrigger reason = 0)
877 {
878 // If focus toggle was in different mode, it should be disabled first
879 if (m_eFocusToggle == SCR_EFocusToggleMode.DISABLED)
881 else
883 }
884
885 //------------------------------------------------------------------------------------------------
886 void ActionFocusToggleVehicle(float value = 0.0, EActionTrigger reason = 0)
887 {
889 return;
890
891 // Conditions must be consistent with GetFocusValue logic
892 ChimeraCharacter character = m_CharacterController.GetCharacter();
893 if (character && !character.IsInVehicle())
894 return;
895
896 // Cancel toggle focus when in vehicle and aiming through gadget (binocular, compass)
897 if (m_bGadgetFocus)
898 return;
899
900 // Cancel toggle focus when in vehicle and not in forced freelook
901 if (!m_CharacterController.IsFreeLookEnabled() && !m_CharacterController.GetFreeLookInput())
902 return;
903
904 // If focus toggle was in different mode, it should be disabled first
905 if (m_eFocusToggle == SCR_EFocusToggleMode.DISABLED)
907 else
909 }
910
911 //------------------------------------------------------------------------------------------------
912 void ActionFocusToggleUnarmed(float value = 0.0, EActionTrigger reason = 0)
913 {
915 return;
916
917 // Conditions must be consistent with GetFocusValue logic
918 ChimeraCharacter character = m_CharacterController.GetCharacter();
919 if (character && character.IsInVehicle())
920 return;
921
922 // Cancel toggle focus when not in vehicle and holding item in hands
923 if (m_CharacterController.GetCurrentItemInHands())
924 return;
925
926 // Cancel toggle focus when not in vehicle and holding gadget
927 if (m_CharacterController.IsGadgetInHands())
928 return;
929
930 // Allow cancelling unarmed focus while picking up items
931 // Disallow enabling unarmed focus while picking up items, as it may become irreleant quickly
932 // Reason is player may want to enter ADS before ready, while intent is unclear
933 if (m_eFocusToggle == SCR_EFocusToggleMode.DISABLED && m_CharacterController.IsPlayingItemGesture())
934 return;
935
936 // If focus toggle was in different mode, it should be disabled first
937 if (m_eFocusToggle == SCR_EFocusToggleMode.DISABLED)
939 else
941 }
942
943 //------------------------------------------------------------------------------------------------
944 void OnWalk()
945 {
946 if (!m_CharacterController || m_CharacterController.GetDynamicSpeed() == WALK_SPEED)
947 return;
948
949 m_fCharacterSpeed = m_CharacterController.GetDynamicSpeed();
950 m_CharacterController.SetDynamicSpeed(WALK_SPEED);
951 m_CharacterController.SetShouldApplyDynamicSpeedOverride(true);
952 }
953
954 //------------------------------------------------------------------------------------------------
955 void OnEndWalk()
956 {
958 return;
959
961 m_CharacterController.SetShouldApplyDynamicSpeedOverride(false);
962 }
963
964 //------------------------------------------------------------------------------------------------
965 void ActionOpenInventory()
966 {
967 IEntity entity = s_pLocalPlayerController.GetControlledEntity();
968 if (!entity)
969 return;
970
971 SCR_InventoryStorageManagerComponent inventory = SCR_InventoryStorageManagerComponent.Cast(entity.FindComponent(SCR_InventoryStorageManagerComponent));
972 if (inventory)
973 inventory.Action_OpenInventory();
974 }
975
976 //------------------------------------------------------------------------------------------------
977 void ActionGesturePing(float value = 0.0, EActionTrigger reason = 0)
978 {
980 return;
981
982 // Press and forget variant... eg press comma once - character will point with it's finger for 1 second (including blending time from animation graph ~300ms)
983 m_CharacterController.TryStartCharacterGesture(ECharacterGestures.POINT_WITH_FINGER, 1500);
984 }
985
986 //------------------------------------------------------------------------------------------------
987 void ActionGesturePingHold(float value = 0.0, EActionTrigger reason = 0)
988 {
990 return;
991
992 // Hold key variant... hold period - character will point with it's finger until period key is released
993 if (reason == EActionTrigger.DOWN)
994 {
995 m_CharacterController.TryStartCharacterGesture(ECharacterGestures.POINT_WITH_FINGER);
996 } else if (reason == EActionTrigger.UP)
997 {
998 m_CharacterController.StopCharacterGesture();
999 }
1000 }
1001 //---- REFACTOR NOTE END ----
1002
1003 //------------------------------------------------------------------------------------------------
1004 // Set the correct platfrom icon to the provided Image Widget
1011 bool SetPlatformImageTo(int playerID, notnull ImageWidget image, ImageWidget glow = null, bool setVisible = true, bool showOnPC = false, bool showOnXbox = false)
1012 {
1013 PlayerManager playerMgr = GetGame().GetPlayerManager();
1014 if (!playerMgr)
1015 return false;
1016
1017 PlatformKind targetPlatformKind = playerMgr.GetPlatformKind(playerID);
1018 PlatformKind ownPlatformKind = playerMgr.GetPlatformKind(GetLocalPlayerId());
1019
1020 // Always show on PSN
1021 if (ownPlatformKind == PlatformKind.PSN )
1022 SetPlatformImagePSN(targetPlatformKind, image, glow, setVisible);
1023 else if (!showOnPC && !showOnXbox)
1024 return false;
1025
1026 switch (ownPlatformKind)
1027 {
1028 case PlatformKind.STEAM:
1029 if (showOnPC)
1030 SetPlatformImagePC(targetPlatformKind, image, glow, setVisible);
1031 break;
1032
1033 case PlatformKind.XBOX:
1034 if (showOnXbox)
1035 SetPlatformImageXbox(targetPlatformKind, image, glow, setVisible);
1036 break;
1037
1038 case PlatformKind.NONE:
1039 if (showOnPC)
1040 SetPlatformImagePC(targetPlatformKind, image, glow, setVisible);
1041 break;
1042 }
1043
1044 return true;
1045 }
1046
1047 //------------------------------------------------------------------------------------------------
1048 // Set the correct platfrom icon to the provided Image Widget based on PlatformKind
1055 bool SetPlatformImageToKind(PlatformKind targetPlatform, notnull ImageWidget image, ImageWidget glow = null, bool setVisible = true, bool showOnPC = false, bool showOnXbox = false)
1056 {
1057 PlatformKind ownPlatformKind = GetGame().GetPlayerManager().GetPlatformKind(GetLocalPlayerId());
1058
1059 // Always show on PSN
1060 if (ownPlatformKind == PlatformKind.PSN)
1061 SetPlatformImagePSN(targetPlatform, image, glow, setVisible);
1062
1063 if (!showOnPC && !showOnXbox)
1064 return true;
1065
1066 switch (ownPlatformKind)
1067 {
1068 case PlatformKind.STEAM:
1069 if (showOnPC)
1070 SetPlatformImagePC(targetPlatform, image, glow, setVisible);
1071 break;
1072
1073 case PlatformKind.XBOX:
1074 if (showOnXbox)
1075 SetPlatformImageXbox(targetPlatform, image, glow, setVisible);
1076 break;
1077
1078 case PlatformKind.NONE:
1079 if (showOnPC)
1080 SetPlatformImagePC(targetPlatform, image, glow, setVisible);
1081 break;
1082 }
1083
1084 return true;
1085 }
1086
1087 //------------------------------------------------------------------------------------------------
1088 protected void SetPlatformImagePSN(PlatformKind targetPlatformKind, notnull ImageWidget image, ImageWidget glow = null, bool setVisible = true)
1089 {
1090 if (targetPlatformKind == PlatformKind.PSN)
1091 {
1092 image.LoadImageFromSet(0, UIConstants.ICONS_IMAGE_SET, UIConstants.PLATFROM_PLAYSTATION_ICON_NAME);
1093
1094 if (glow)
1095 glow.LoadImageFromSet(0, UIConstants.ICONS_GLOW_IMAGE_SET, UIConstants.PLATFROM_PLAYSTATION_ICON_NAME);
1096 }
1097 else
1098 {
1099 image.LoadImageFromSet(0, UIConstants.ICONS_IMAGE_SET, UIConstants.PLATFROM_GENERIC_ICON_NAME);
1100
1101 if (glow)
1102 glow.LoadImageFromSet(0, UIConstants.ICONS_GLOW_IMAGE_SET, UIConstants.PLATFROM_GENERIC_ICON_NAME);
1103 }
1104
1105 if (!setVisible)
1106 return;
1107
1108 image.SetVisible(true);
1109 if (glow)
1110 glow.SetVisible(true);
1111 }
1112
1113 //------------------------------------------------------------------------------------------------
1114 protected void SetPlatformImagePC(PlatformKind targetPlatformKind, notnull ImageWidget image, ImageWidget glow = null, bool setVisible = true)
1115 {
1116 string icon;
1117 switch (targetPlatformKind)
1118 {
1119 case PlatformKind.STEAM:
1120 icon = UIConstants.PLATFROM_PC_ICON_NAME;
1121 break;
1122 case PlatformKind.XBOX:
1123 icon = UIConstants.PLATFROM_XBOX_ICON_NAME;
1124 break;
1125 case PlatformKind.PSN:
1126 icon = UIConstants.PLATFROM_PLAYSTATION_ICON_NAME;
1127 break;
1128 case PlatformKind.NONE:
1129 icon = UIConstants.PLATFROM_PC_ICON_NAME;
1130 break;
1131 }
1132
1133 image.LoadImageFromSet(0, UIConstants.ICONS_IMAGE_SET, icon);
1134 if (glow)
1135 glow.LoadImageFromSet(0, UIConstants.ICONS_GLOW_IMAGE_SET, icon);
1136
1137 if (!setVisible)
1138 return;
1139
1140 image.SetVisible(true);
1141 if (glow)
1142 glow.SetVisible(true);
1143 }
1144
1145 //------------------------------------------------------------------------------------------------
1146 protected void SetPlatformImageXbox(PlatformKind targetPlatformKind, notnull ImageWidget image, ImageWidget glow = null, bool setVisible = true)
1147 {
1148 string icon;
1149 switch (targetPlatformKind)
1150 {
1151 case PlatformKind.STEAM:
1152 icon = UIConstants.PLATFROM_PC_ICON_NAME;
1153 break;
1154 case PlatformKind.XBOX:
1155 icon = UIConstants.PLATFROM_XBOX_ICON_NAME;
1156 break;
1157 case PlatformKind.PSN:
1158 icon = UIConstants.PLATFROM_PLAYSTATION_ICON_NAME;
1159 break;
1160 case PlatformKind.NONE:
1161 icon = UIConstants.PLATFROM_PC_ICON_NAME;
1162 break;
1163 }
1164
1165 image.LoadImageFromSet(0, UIConstants.ICONS_IMAGE_SET, icon);
1166 if (glow)
1167 glow.LoadImageFromSet(0, UIConstants.ICONS_GLOW_IMAGE_SET, icon);
1168
1169 if (!setVisible)
1170 return;
1171
1172 image.SetVisible(true);
1173 if (glow)
1174 glow.SetVisible(true);
1175 }
1176}
ENotification
ArmaReforgerScripted GetGame()
Definition game.c:1398
PlatformKind
Definition PlatformKind.c:8
SCR_BaseGameMode GetGameMode()
SCR_CacheNoteComponentClass ScriptComponentClass RplProp()] protected ref array< string > m_aLines
SCR_EFocusToggleMode
void SCR_EditorManagerEntity(IEntitySource src, IEntity parent)
SCR_HelicopterControllerComponentClass gameplaySettings
func OnDestroyedPlayerController
ScriptInvokerBase< OnBeforePossessed > OnBeforePossessedInvoker
func OnBeforePossessed
ScriptInvokerBase< OnDestroyedPlayerController > OnDestroyedPlayerControllerInvoker
func OnControlledEntityChangedPlayerController
func OnPossessed
ScriptInvokerBase< OnPossessed > OnPossessedInvoker
ScriptInvokerBase< OwnershipChangedDelegate > OnOwnershipChangedInvoker
ScriptInvokerBase< OnControlledEntityChangedPlayerController > OnControlledEntityChangedPlayerControllerInvoker
func OwnershipChangedDelegate
enum EVehicleType IEntity
proto external Managed FindComponent(typename typeName)
Input management system for user interactions.
Main replication API.
Definition Replication.c:14
Replication item identifier.
Definition RplId.c:14
Replication connection identity.
Definition RplIdentity.c:14
sealed bool IsMaster()
void SetNextSightsFOVInfo(int direction=1, bool allowCycling=false)
SCR_FireModeManagerComponent GetControlledFireModeManager()
static SCR_ConfigurableDialogUi CreateFromPreset(ResourceName presetsResourceName, string tag, SCR_ConfigurableDialogUi customDialogObj=null)
Creates a dialog from preset.
void StartObservingControlledEntityChanges(notnull SCR_PlayerController controller, bool changing, bool becameOwner)
ref ScriptInvoker_AuthorRequestedFinishedEvent Event_OnAuthorsRegisteredFinished
Core component to manage SCR_EditorManagerEntity.
ref OnPossessedInvoker m_OnPossessed
ref OnDestroyedPlayerControllerInvoker m_OnDestroyed
void SetPossessedEntity(IEntity entity)
static int GetLocalPlayerId()
Returns either a valid ID of local player or 0.
static const float FOCUS_ACTIVATION
static const float FOCUS_ANALOGUE_SCALE
static const float FOCUS_DEACTIVATION
void OnPlayerRegistered(SCR_EditorManagerEntity managerEntity)
OnOwnershipChangedInvoker GetOnOwnershipChangedInvoker()
void OnPlayerNameCacheUpdate(bool success)
static const float WALK_SPEED
static const float FOCUS_TOLERANCE
override void OnOwnershipChanged(bool changing, bool becameOwner)
ref OnOwnershipChangedInvoker m_OnOwnershipChangedInvoker
void OnBlockedPlayerJoined(int playerID)
static const float FOCUS_TIMEOUT
static Faction GetLocalControlledEntityFaction()
void UpdateLocalPlayerController()
Find if this is local player controller. We assume that this never changes during scenario.
ref OnBeforePossessedInvoker m_OnBeforePossess
void SetPlatformImagePC(PlatformKind targetPlatformKind, notnull ImageWidget image, ImageWidget glow=null, bool setVisible=true)
override void OnDestroyed(notnull Instigator killer)
override void OnControlledEntityChanged(IEntity from, IEntity to)
void OnInit(IEntity owner)
void OnAuthorsRequestFinished(set< SCR_EditableEntityAuthor > activeUGCAuthors)
void UpdateControls()
Update disabling of character controls in menus.
CharacterControllerComponent m_CharacterController
SCR_EFocusToggleMode m_eFocusToggle
ref OnControlledEntityChangedPlayerControllerInvoker m_OnControlledEntityChanged
override void OnUpdate(float timeSlice)
static IEntity GetLocalControlledEntity()
static Faction GetLocalMainEntityFaction()
void OnBlockedListUpdated(bool success)
static IEntity GetLocalMainEntity()
void SetInitialMainEntity(notnull IEntity entity)
void SetAIActivation(IEntity entity, bool activate)
void ChangeMagnification(float value)
void SetPlatformImageXbox(PlatformKind targetPlatformKind, notnull ImageWidget image, ImageWidget glow=null, bool setVisible=true)
SCR_CharacterControllerComponent GetCharacterController()
void SetPlatformImagePSN(PlatformKind targetPlatformKind, notnull ImageWidget image, ImageWidget glow=null, bool setVisible=true)
void UpdateTurretFireModeControlls(IEntity from, IEntity to)
SCR_EditableEntityComponent GetControlledEntity()
EVehicleDrivingAssistanceMode
Player vehicle driving assistance modes. Individual features may become separate options in future.
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
LogLevel
Enum with severity of the logging message.
Definition LogLevel.c:14
proto void PrintFormat(string fmt, void param1=NULL, void param2=NULL, void param3=NULL, void param4=NULL, void param5=NULL, void param6=NULL, void param7=NULL, void param8=NULL, void param9=NULL, LogLevel level=LogLevel.NORMAL)
proto external PlayerController GetPlayerController()
EActionTrigger
void SetControlledEntity(IEntity controlledEntity)
proto external int GetPlayerId()
proto external int GetRplIdentity()