Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_PlayerControllerCommandingComponent.c
Go to the documentation of this file.
1[EntityEditorProps(category: "GameScripted/Commanding", description: "This component should be attached to player controller and is used by commanding to send requests to server.")]
5
6class SCR_PlayerControllerCommandingComponent : ScriptComponent
7{
8 [Attribute(desc: "Config of pairs of actions and commanding menu configs to decide which action opens which menu")]
9 protected ResourceName m_sCommandingConfigActionPair;
10
11 [Attribute("{2FFBD92174DDF3E0}Configs/Commanding/CommandingMapMenu.conf")]
13
14 [Attribute()]
16
18
22
24
27 protected SCR_InfoDisplayExtended m_CurrentShownCommand;
28 protected SCR_InfoDisplayExtended m_CurrentShownCommandPreview;
29
30 protected string m_sExecutedCommandName;
31
32 protected ref array<ref Shape> m_aShapes = {};
33
34 protected bool m_bIsCommandExecuting = false;
35 protected bool m_bSlaveGroupRequested = false;
36 protected bool m_bIsCommandSelected;
38
39 protected string m_sSelectedCommandEntry;
40
42 protected static const float ABOVE_TERRAIN_OFFSET = 0.5;
43
45 protected static const float COMMANDING_VISUAL_RANGE = 10000;
46
47 //------------------------------------------------------------------------------------------------
50 static SCR_PlayerControllerCommandingComponent GetPlayerControllerCommandingComponent(int playerID)
51 {
52 PlayerController playerController = GetGame().GetPlayerManager().GetPlayerController(playerID);
53 if (!playerController)
54 return null;
55
56 return SCR_PlayerControllerCommandingComponent.Cast(playerController.FindComponent(SCR_PlayerControllerCommandingComponent));
57 }
58
59 //------------------------------------------------------------------------------------------------
61 static SCR_PlayerControllerCommandingComponent GetLocalPlayerControllerCommandingComponent()
62 {
63 SCR_PlayerController playerController = SCR_PlayerController.Cast(GetGame().GetPlayerController());
64 if (!playerController)
65 return null;
66
67 return SCR_PlayerControllerCommandingComponent.Cast(playerController.FindComponent(SCR_PlayerControllerCommandingComponent));
68 }
69
70 //------------------------------------------------------------------------------------------------
71 override protected void OnPostInit(IEntity owner)
72 {
73 super.OnPostInit(owner);
74 SetEventMask(owner, EntityEvent.INIT);
75
76 SCR_GroupsManagerComponent groupManager = SCR_GroupsManagerComponent.GetInstance();
78
79 Resource holder = BaseContainerTools.LoadContainer(m_sCommandingConfigActionPair);
80 if (!holder)
81 return;
82
83 BaseContainer container = holder.GetResource().ToBaseContainer();
84 m_CommandingMenuPairsConfig = SCR_PlayerCommandingMenuActionsSetup.Cast(BaseContainerTools.CreateInstanceFromContainer(container));
85
87 return;
88
89 m_RadialMenuController.GetOnTakeControl().Insert(OnControllerTakeControl);
90 m_RadialMenuController.GetOnControllerChanged().Insert(OnControllerLostControl);
91
92 SCR_PlayerController playerContr = SCR_PlayerController.Cast(owner);
93 //Warning: OnPostInit is in hosted server triggered for each player controller,
94 //that joins the session BUT the host executes this also for the components of the other players,
95 //that is why we need to check if we lost ownership of the component
97
98 InputManager input = GetGame().GetInputManager();
99 foreach (SCR_PlayerCommandingConfigActionPair actionConfigPair : m_CommandingMenuPairsConfig.m_aActionConfigPairs)
100 {
101 if (!actionConfigPair)
102 continue;
103
104 input.AddActionListener(actionConfigPair.GetActionName(), EActionTrigger.DOWN, OpenCommandingMenu);
105 }
106
109
110 m_PhysicsHelper.InitPhysicsHelper();
111 }
112
113 //------------------------------------------------------------------------------------------------
114 protected void OnOwnershipChanged(bool isChanging, bool becameOwner)
115 {
116 if (isChanging || becameOwner)
117 return;
118
119 InputManager input = GetGame().GetInputManager();
120 foreach (SCR_PlayerCommandingConfigActionPair actionConfigPair : m_CommandingMenuPairsConfig.m_aActionConfigPairs)
121 {
122 if (!actionConfigPair)
123 continue;
124
125 input.RemoveActionListener(actionConfigPair.GetActionName(), EActionTrigger.DOWN, OpenCommandingMenu);
126 }
127 }
128
129 //------------------------------------------------------------------------------------------------
131 {
132 if (m_RadialMenuController.IsMenuOpen())
133 {
134 m_RadialMenuController.CloseMenu();
135 return;
136 }
137
138 ResourceName configPath;
139
140 foreach (SCR_PlayerCommandingConfigActionPair actionConfigPair : m_CommandingMenuPairsConfig.m_aActionConfigPairs)
141 {
142 if (!actionConfigPair || !GetGame().GetInputManager().GetActionTriggered(actionConfigPair.GetActionName()))
143 continue;
144
145 configPath = actionConfigPair.GetConfig();
146 break;
147 }
148
149 Resource holder = BaseContainerTools.LoadContainer(configPath);
150 if (!holder || !holder.IsValid())
151 return;
152
153 BaseContainer container = holder.GetResource().ToBaseContainer();
154 m_CommandingMenuConfig = SCR_PlayerCommandingMenuConfig.Cast(BaseContainerTools.CreateInstanceFromContainer(container));
155
157 return;
158
159 m_RadialMenuController.OnInputOpen();
160 }
161
162 //------------------------------------------------------------------------------------------------
164 {
166 return;
167
168 // Send/update entries in radial menu when control is gained
169 controller.UpdateMenuData();
171 }
172
173 //------------------------------------------------------------------------------------------------
175 protected void OnControllerLostControl(SCR_RadialMenuController controller, bool hasControl)
176 {
177 if (!hasControl)
179 }
180
181 //------------------------------------------------------------------------------------------------
184 {
186 if (!mapMenu)
187 return;
188
190 }
191
192 //------------------------------------------------------------------------------------------------
195 {
197 if (!mapMenu)
198 return;
199
201 }
202
203 //------------------------------------------------------------------------------------------------
206 {
207 BaseGameMode gameMode = GetGame().GetGameMode();
208 if (!gameMode)
209 return;
210
212 if (!m_RadialMenu)
213 return;
214
215 m_RadialMenu.GetOnBeforeOpen().Insert(OnPlayerRadialMenuBeforeOpen);
216 m_RadialMenu.GetOnOpen().Insert(OnPlayerRadialMenuOpen);
217 m_RadialMenu.GetOnClose().Insert(OnPlayerRadialMenuClose);
218 m_RadialMenu.GetOnPerform().Insert(OnRadialMenuPerformed);
219 m_RadialMenu.GetOnSelect().Insert(OnRadialMenuSelected);
220 m_RadialMenu.GetOnOpenFailed().Insert(OnRadialMenuOpenFailed);
221 }
222
223 //------------------------------------------------------------------------------------------------
226 {
227 BaseGameMode gameMode = GetGame().GetGameMode();
228 if (!gameMode)
229 return;
230
231 if (!m_RadialMenu)
232 return;
233
234 m_RadialMenu.GetOnBeforeOpen().Remove(OnPlayerRadialMenuBeforeOpen);
235 m_RadialMenu.GetOnOpen().Remove(OnPlayerRadialMenuOpen);
236 m_RadialMenu.GetOnClose().Remove(OnPlayerRadialMenuClose);
237 m_RadialMenu.GetOnPerform().Remove(OnRadialMenuPerformed);
238 m_RadialMenu.GetOnSelect().Remove(OnRadialMenuSelected);
239 m_RadialMenu.GetOnOpenFailed().Remove(OnRadialMenuOpenFailed);
240 }
241
242 //------------------------------------------------------------------------------------------------
245 {
248 return;
249
250 m_MapContextualMenu.GetOnMenuInitInvoker().Insert(SetupMapRadialMenu);
251 m_MapContextualMenu.GetOnEntryPerformedInvoker().Insert(OnMapCommandPerformed);
252 }
253
254 //------------------------------------------------------------------------------------------------
257 {
259 return;
260
261 m_MapContextualMenu.GetOnMenuInitInvoker().Remove(SetupMapRadialMenu);
262 m_MapContextualMenu.GetOnEntryPerformedInvoker().Remove(OnMapCommandPerformed);
263 }
264
265 //------------------------------------------------------------------------------------------------
268 {
270 return;
271
273 if (!holder || !holder.IsValid())
274 return;
275
276 BaseContainer container = holder.GetResource().ToBaseContainer();
277 m_CommandingMapMenuConfig = SCR_PlayerCommandingMenuConfig.Cast(BaseContainerTools.CreateInstanceFromContainer(container));
278
280 if (!rootCategory)
281 return;
282
283 AddElementsFromCategoryToMap(rootCategory);
284 }
285
286 //------------------------------------------------------------------------------------------------
289 void OnMapCommandPerformed(SCR_SelectionMenuEntry element, float[] worldPos)
290 {
292 if (!mapEntry)
293 return;
294
295 float height = GetGame().GetWorld().GetSurfaceY(worldPos[0], worldPos[1]);
296
298 position[0] = worldPos[0];
299 position[1] = height + ABOVE_TERRAIN_OFFSET;
300 position[2] = worldPos[1];
301
302 PrepareExecuteCommand(mapEntry.GetEntryIdentifier(), position);
303 }
304
305 //------------------------------------------------------------------------------------------------
308 void OnGroupLeaderChanged(int groupID, int playerID)
309 {
310 SCR_PlayerControllerGroupComponent playerGroupController = SCR_PlayerControllerGroupComponent.GetLocalPlayerControllerGroupComponent();
311 if (!playerGroupController)
312 return;
313
314 //we do not care if it's outside of our group
315 if (playerGroupController.GetGroupID() != groupID)
316 return;
317
318 bool enabled = playerID == GetGame().GetPlayerController().GetPlayerId();
319 }
320
321 //------------------------------------------------------------------------------------------------
323 void OnGroupChanged(int groupID)
324 {
325 //check if player is the new leader of the group
326 SCR_PlayerControllerGroupComponent playerGroupController = SCR_PlayerControllerGroupComponent.GetLocalPlayerControllerGroupComponent();
327 if (!playerGroupController)
328 return;
329
330 SCR_GroupsManagerComponent groupsManager = SCR_GroupsManagerComponent.GetInstance();
331 if (!groupsManager)
332 return;
333
334 SCR_AIGroup playersGroup = groupsManager.FindGroup(groupID);
335 if (!playersGroup)
336 return;
337
338 bool enabled = playerGroupController.IsPlayerLeader(GetGame().GetPlayerController().GetPlayerId(), playersGroup);
339 }
340
341 //------------------------------------------------------------------------------------------------
343 protected void DeleteShownCommand()
344 {
346 return;
347
349 if (!hudManager)
350 return;
351
352 hudManager.StopDrawing(m_CurrentShownCommand);
354 }
355
356 //------------------------------------------------------------------------------------------------
359 {
360 m_bIsCommandSelected = false;
361
363 return;
364
366 if (!hudManager)
367 return;
368
369 hudManager.StopDrawing(m_CurrentShownCommandPreview);
371 }
372
373 //------------------------------------------------------------------------------------------------
376 void ShowCommandPreview(string commandName)
377 {
380
381 if (commandName.IsEmpty())
382 return;
383
384 m_sSelectedCommandEntry = commandName;
386
387 SCR_CommandingManagerComponent commandingManager = SCR_CommandingManagerComponent.GetInstance();
388 if (!commandingManager)
389 return;
390
391 SCR_BaseGroupCommand command = SCR_BaseGroupCommand.Cast(commandingManager.FindCommand(m_sSelectedCommandEntry));
392 if (!command || !command.CanShowPreview())
393 return;
394
395 command.VisualizeCommandPreview(vector.Zero);
396
398 return;
399
401 if (commandInfo)
402 commandInfo.SetCanUpdatePosition(true);
403 }
404
405 //------------------------------------------------------------------------------------------------
412 protected bool GetWorldToScreenPosition(BaseWorld world, vector worldPosition, out float posX, out float posY, int cameraIndex = -1)
413 {
414 vector screenPosition = GetGame().GetWorkspace().ProjWorldToScreen(worldPosition, world, cameraIndex);
415 posX = screenPosition[0];
416 posY = screenPosition[1];
417
418 return false;
419 }
420
421 //------------------------------------------------------------------------------------------------
424 protected void PhysicsCommandTrace(float range = COMMANDING_VISUAL_RANGE)
425 {
426 PlayerController controller = GetGame().GetPlayerController();
427 PlayerCamera camera = PlayerCamera.Cast(GetGame().GetCameraManager().CurrentCamera());
428 if (!camera)
429 return;
430
431 IEntity controlledEntity = controller.GetControlledEntity();
432
433 vector mat[4];
434 camera.GetTransform(mat);
435 vector end = mat[3] + mat[2] * range;
436 array<IEntity> excludeArray = {};
437 excludeArray.Insert(controlledEntity);
438
439 ChimeraCharacter playerCharacter = ChimeraCharacter.Cast(controlledEntity);
440 if (playerCharacter && playerCharacter.IsInVehicle())
441 {
442 CompartmentAccessComponent compartmentComp = playerCharacter.GetCompartmentAccessComponent();
443 if (compartmentComp)
444 {
445 IEntity vehicleIn = compartmentComp.GetVehicleIn(playerCharacter);
446 if (vehicleIn)
447 excludeArray.Insert(vehicleIn);
448 }
449 }
450
452 m_PhysicsHelper.TraceSegmented(mat[3], end, TraceFlags.ENTS | TraceFlags.WORLD | TraceFlags.ANY_CONTACT, EPhysicsLayerDefs.Projectile, excludeArray);
453 }
454
455 //------------------------------------------------------------------------------------------------
459 {
460 m_bIsCommandSelected = false;
461 string entryId;
462 if (entry)
463 entryId = entry.GetId();
464
465 if (entryId == string.Empty)
466 {
468 return;
469 }
470
471 ShowCommandPreview(entryId);
472 }
473
474 //------------------------------------------------------------------------------------------------
478 {
479 if (!entry)
480 return;
481
482 m_bIsCommandSelected = false;
483
486 }
487
488 //------------------------------------------------------------------------------------------------
490 {
491 //for now we handle the empty same as player not being leader since we dont have member commands yet
492 //todo: change this when member commands get implemented
493 switch (reason)
494 {
495 case SCR_ESelectionMenuFailReason.MENU_EMPTY: SCR_NotificationsComponent.SendLocal(ENotification.COMMANDING_NO_RIGHTS); break;
496 default: break;
497 }
498 }
499
500 //------------------------------------------------------------------------------------------------
503 void PrepareExecuteCommand(string commandName, vector targetPosition = "0 0 0")
504 {
505 //if another command is waiting for trace, do nothing
506 if (m_bIsCommandExecuting || commandName.IsEmpty())
507 return;
508
509 m_sExecutedCommandName = commandName;
510
511 if (targetPosition != vector.Zero)
512 {
513 ExecuteCommand(targetPosition, null);
514 return;
515 }
516
518
519 if (m_PhysicsHelper)
520 {
521 m_PhysicsHelper.GetOnTraceFinished().Insert(ExecuteCommand);
522
523 //prevent other commands being executed while this one is waiting for trace
524 //todo:kuceramar: after radialmenurework, make radial menu elements disabled when this is true
526 }
527 }
528
529 //------------------------------------------------------------------------------------------------
533 void ExecuteCommand(vector targetPosition, IEntity tracedEntity)
534 {
535 m_bIsCommandExecuting = false;
536 if (m_PhysicsHelper)
537 {
538 m_PhysicsHelper.GetOnTraceFinished().Remove(ExecuteCommand);
539 m_PhysicsHelper = null;
540 }
541
542 SCR_CommandingManagerComponent commandingManager = SCR_CommandingManagerComponent.GetInstance();
543 if (!commandingManager)
544 return;
545
546 int playerID = SCR_PlayerController.GetLocalPlayerId();
547
548 SCR_PlayerControllerGroupComponent groupController = SCR_PlayerControllerGroupComponent.GetLocalPlayerControllerGroupComponent();
549 SCR_GroupsManagerComponent groupManager = SCR_GroupsManagerComponent.GetInstance();
550 if (!groupController || !groupManager)
551 return;
552
553 SCR_AIGroup playersGroup = groupManager.FindGroup(groupController.GetGroupID());
554 if (!playersGroup)
555 return;
556
557 RplComponent rplComp;
558 if (!m_bSlaveGroupRequested && !playersGroup.GetSlave())
559 {
560 rplComp = RplComponent.Cast(playersGroup.FindComponent(RplComponent));
561 groupController.RequestCreateSlaveGroup(rplComp.Id());
563 }
564
565 SCR_AIGroup slaveGroup = playersGroup.GetSlave();
566 //todo:mour Unlink this, only AI commands should be reliant on slave group, so commands should have that as option, not for all commands
567 if (!slaveGroup)
568 {
569 //if there is not slaveGroup, we try to execute the command later because newly created group takes a bit of time to replicate
570 GetGame().GetCallqueue().CallLater(ExecuteCommand, 100, false, targetPosition, tracedEntity);
571 return;
572 }
573
575 rplComp = RplComponent.Cast(slaveGroup.FindComponent(RplComponent));
576 RplId groupRplID = rplComp.Id();
577 RplId cursorTargetRplID;
578
579 int commandIndex = commandingManager.FindCommandIndex(m_sExecutedCommandName);
580
582 {
583 rplComp = RplComponent.Cast(m_SelectedEntity.FindComponent(RplComponent));
584 if (rplComp)
585 cursorTargetRplID = rplComp.Id();
586 }
587
588 SCR_BaseRadialCommand command = commandingManager.FindCommand(m_sExecutedCommandName);
589 if (command)
590 {
592 command.VisualizeCommand(targetPosition);
593 }
594
595 Rpc(RPC_RequestExecuteCommand, commandIndex, cursorTargetRplID, groupRplID, targetPosition, playerID);
596 }
597
598 //------------------------------------------------------------------------------------------------
605 [RplRpc(RplChannel.Reliable, RplRcver.Server)]
606 void RPC_RequestExecuteCommand(int commandIndex, RplId cursorTargetID, RplId groupRplID, vector targetPoisition, int playerID)
607 {
608 SCR_CommandingManagerComponent commandingManager = SCR_CommandingManagerComponent.GetInstance();
609 if (!commandingManager)
610 return;
611
612 //generate random seed for voiceline
613 float soundEventSeed = Math.RandomFloatInclusive(0, 1);
614 commandingManager.RequestCommandExecution(commandIndex, cursorTargetID, groupRplID, targetPoisition, playerID, soundEventSeed);
615 }
616
617 //------------------------------------------------------------------------------------------------
620 void CommandExecutedCallback(int commandIndex)
621 {
622 Rpc(RPC_CommandExecutedCallback, commandIndex);
623 }
624
625 //------------------------------------------------------------------------------------------------
628 [RplRpc(RplChannel.Reliable, RplRcver.Owner)]
629 void RPC_CommandExecutedCallback(int commandIndex)
630 {
631 PlayCommandGesture(commandIndex);
632 }
633
634 //------------------------------------------------------------------------------------------------
637 void PlayCommandGesture(int commandIndex)
638 {
639 if (commandIndex <= 0)
640 return;
641
643
644 //skip the commanding gesture if player has map open
645 if (mapEntity && mapEntity.IsOpen())
646 return;
647
648 SCR_BaseGroupCommand command = SCR_BaseGroupCommand.Cast(m_CommandingManager.FindCommand(m_CommandingManager.FindCommandNameFromIndex(commandIndex)));
649 if (!command)
650 return;
651
652 int gestureID = command.GetCommandGestureID();
653
654 IEntity playerControlledEntity = GetGame().GetPlayerController().GetControlledEntity();
655
656 if (!playerControlledEntity)
657 return;
658
660 if (!characterComponent)
661 return;
662
663 if (characterComponent.IsWeaponADS())
664 return;
665
666 characterComponent.TryStartCharacterGesture(gestureID, 3000);
667 }
668
669 //------------------------------------------------------------------------------------------------
673 void UpdateRadialMenu(IEntity owner, bool isOpen)
674 {
675 if (!m_RadialMenu || !m_CommandingMenuConfig || !isOpen)
676 return;
677
678 PlayerCamera camera = PlayerCamera.Cast(GetGame().GetCameraManager().CurrentCamera());
679 if (!camera)
680 return;
681
682 m_SelectedEntity = camera.GetCursorTarget();
683
685 if (!rootCategory)
686 return;
687
688 AddElementsFromCategory(rootCategory);
689 }
690
691 //------------------------------------------------------------------------------------------------
697 {
698 array<ref SCR_PlayerCommandingMenuBaseElement> elements = category.GetCategoryElements();
699
701 SCR_SelectionMenuCategoryEntry createdCategory;
702
703 bool canBeShown;
704 bool canThisCategoryBeShown;
705 foreach (SCR_PlayerCommandingMenuBaseElement element : elements)
706 {
707 elementCategory = SCR_PlayerCommandingMenuCategoryElement.Cast(element);
708 if (elementCategory)
709 {
710 createdCategory = SCR_SelectionMenuCategoryEntry.Cast(AddRadialMenuElement(elementCategory, rootCategory));
711 if (!createdCategory)
712 continue;
713
714 canThisCategoryBeShown = AddElementsFromCategory(elementCategory, createdCategory);
715 if (!canThisCategoryBeShown)
716 {
717 if (rootCategory)
718 rootCategory.RemoveEntry(createdCategory);
719 else
720 m_RadialMenu.RemoveEntry(createdCategory);
721 }
722
723 canBeShown = canThisCategoryBeShown || canBeShown;
724 }
725 else
726 {
727 canBeShown = AddRadialMenuElement(element, rootCategory) || canBeShown;
728 }
729 }
730
731 return canBeShown;
732 }
733
734 //------------------------------------------------------------------------------------------------
739 {
740 SCR_SelectionMenuCategoryEntry mapEntryCategory = m_MapContextualMenu.AddRadialCategory(category.GetCategoryDisplayText(), parentCategory); // add map category entry
741
742 array<ref SCR_PlayerCommandingMenuBaseElement> elements = category.GetCategoryElements();
744 bool canBeShown;
745 foreach (SCR_PlayerCommandingMenuBaseElement element : elements)
746 {
747 elementCategory = SCR_PlayerCommandingMenuCategoryElement.Cast(element);
748 if (elementCategory)
749 {
750 if (elementCategory.GetCanShowOnMap())
751 canBeShown = AddElementsFromCategoryToMap(elementCategory, mapEntryCategory) || canBeShown;
752 }
753 else
754 {
755 canBeShown = InsertElementToMapRadial(element, category, mapEntryCategory) || canBeShown;
756 }
757 }
758
759 if (!canBeShown)
760 {
761 if (parentCategory)
762 parentCategory.RemoveEntry(mapEntryCategory);
763 else
764 m_MapContextualMenu.RemoveRadialEntry(mapEntryCategory);
765
766 return canBeShown;
767 }
768
769 ResourceName imagesetName = category.GetIconImageset();
770 string iconName = category.GetIconName();
771 if (mapEntryCategory && !imagesetName.IsEmpty() && !iconName.IsEmpty())
772 mapEntryCategory.SetIcon(imagesetName, iconName);
773
774 return canBeShown;
775 }
776
777 //------------------------------------------------------------------------------------------------
783 {
784 SCR_CommandingManagerComponent commandingManager = SCR_CommandingManagerComponent.GetInstance();
785 if (!commandingManager)
786 return null;
787
788 SCR_ChimeraCharacter user = SCR_ChimeraCharacter.Cast(SCR_PlayerController.GetLocalControlledEntity());
789 if (!user)
790 return null;
791
792 SCR_PlayerCommandingMenuCommand commandElement = SCR_PlayerCommandingMenuCommand.Cast(element);
793 if (!commandingManager.CanShowOnMap(commandElement.GetCommandName()))
794 return null;
795
796 SCR_BaseRadialCommand command = commandingManager.FindCommand(commandElement.GetCommandName());
797 if (!command)
798 return null;
799
800 SCR_MapMenuCommandingEntry mapEntry = new SCR_MapMenuCommandingEntry(commandElement.GetCommandName());
801 mapEntry.SetName(commandingManager.GetCommandDisplayTextByName(commandElement.GetCommandName()));
802 mapEntry.SetIcon(command.GetIconImageset(), command.GetIconName());
803
804 bool canPerform = command.CanBePerformed(user);
805 mapEntry.Enable(canPerform);
806 if (!canPerform)
807 mapEntry.SetDescription(command.GetCannotPerformReason());
808
809 m_MapContextualMenu.InsertCustomRadialEntry(mapEntry, mapCategory);
810 return mapEntry;
811 }
812
813 //------------------------------------------------------------------------------------------------
819 {
820 SCR_PlayerCommandingMenuCommand commandElement = SCR_PlayerCommandingMenuCommand.Cast(newElement);
821 if (commandElement)
822 return AddCommandElement(commandElement, parentCategory);
823
825 if (categoryElement)
826 return AddCategoryElement(categoryElement, parentCategory);
827
828 return null;
829 }
830
831 //------------------------------------------------------------------------------------------------
837 {
839
840 string id;
841 if (parentCategory)
842 id = parentCategory.GetId() + SCR_StringHelper.UNDERSCORE + parentCategory.GetEntries().Count().ToString();
843 else
844 id = m_RadialMenu.GetEntries().Count().ToString();
845
846 newCategory.SetId(id);
847 newCategory.SetName(category.GetCategoryDisplayText());
848
849 ResourceName imagesetName = category.GetIconImageset();
850 string iconName = category.GetIconName();
851 if (!imagesetName.IsEmpty() && !iconName.IsEmpty())
852 newCategory.SetIcon(imagesetName, iconName);
853
854 if (!parentCategory)
855 {
856 m_RadialMenu.AddCategoryEntry(newCategory);
857 return newCategory;
858 }
859
860 parentCategory.AddEntry(newCategory);
861
862 return newCategory;
863 }
864
865 //------------------------------------------------------------------------------------------------
870 SCR_SelectionMenuEntry AddCommandElement(SCR_PlayerCommandingMenuCommand command, SCR_SelectionMenuCategoryEntry parentCategory = null)
871 {
872 SCR_CommandingManagerComponent commandingManager = SCR_CommandingManagerComponent.GetInstance();
873 if (!commandingManager)
874 return null;
875
876 SCR_ChimeraCharacter user = SCR_ChimeraCharacter.Cast(SCR_PlayerController.GetLocalControlledEntity());
877 if (!user)
878 return null;
879
880 if (!commandingManager.CanShowCommand(command.GetCommandName()))
881 return null;
882
883 SCR_BaseRadialCommand groupCommand = commandingManager.FindCommand(command.GetCommandName());
884
886
887 string displayName = command.GetCommandCustomName();
888 if (displayName.IsEmpty())
889 displayName = commandingManager.GetCommandDisplayTextByName(command.GetCommandName());
890
891 //entry.SetName(displayName);
892 bool canExecute;
893 bool canPerform = groupCommand.CanBePerformed(user);
894
895 if (canPerform)
896 {
897 canExecute = groupCommand.CanBeExecuted(m_SelectedEntity);
898 }
899
900 entry.SetId(command.GetCommandName());
901 entry.SetIcon(groupCommand.GetIconImageset(), groupCommand.GetIconName());
902 entry.Enable(canPerform && canExecute);
903 entry.SetCommandText(displayName);
904 if (!canPerform)
905 entry.SetDescription(groupCommand.GetCannotPerformReason());
906 else if (!canExecute)
907 entry.SetDescription(groupCommand.GetCannotExecuteReason());
908
909 if (parentCategory)
910 parentCategory.AddEntry(entry);
911 else
912 m_RadialMenu.AddEntry(entry);
913
914 return entry;
915 }
916
917 //------------------------------------------------------------------------------------------------
920 {
922 return;
923
924 m_RadialMenu.ClearEntries();
925
926 PlayerCamera camera = PlayerCamera.Cast(GetGame().GetCameraManager().CurrentCamera());
927 if (!camera)
928 return;
929
930 m_SelectedEntity = camera.GetCursorTarget();
931
933 if (!rootCategory)
934 return;
935
936 AddElementsFromCategory(rootCategory);
937
938 GetGame().GetInputManager().AddActionListener("BindQuickslot4", EActionTrigger.DOWN, OnQuickslotBind4);
939 GetGame().GetInputManager().AddActionListener("BindQuickslot5", EActionTrigger.DOWN, OnQuickslotBind5);
940 GetGame().GetInputManager().AddActionListener("BindQuickslot6", EActionTrigger.DOWN, OnQuickslotBind6);
941 GetGame().GetInputManager().AddActionListener("BindQuickslot7", EActionTrigger.DOWN, OnQuickslotBind7);
942 GetGame().GetInputManager().AddActionListener("BindQuickslot8", EActionTrigger.DOWN, OnQuickslotBind8);
943 GetGame().GetInputManager().AddActionListener("BindQuickslot9", EActionTrigger.DOWN, OnQuickslotBind9);
944
945 m_bIsCommandSelected = false;
946 }
947 //------------------------------------------------------------------------------------------------
954 //------------------------------------------------------------------------------------------------
956 {
957 GetGame().GetInputManager().RemoveActionListener("BindQuickslot4", EActionTrigger.DOWN, OnQuickslotBind4);
958 GetGame().GetInputManager().RemoveActionListener("BindQuickslot5", EActionTrigger.DOWN, OnQuickslotBind5);
959 GetGame().GetInputManager().RemoveActionListener("BindQuickslot6", EActionTrigger.DOWN, OnQuickslotBind6);
960 GetGame().GetInputManager().RemoveActionListener("BindQuickslot7", EActionTrigger.DOWN, OnQuickslotBind7);
961 GetGame().GetInputManager().RemoveActionListener("BindQuickslot8", EActionTrigger.DOWN, OnQuickslotBind8);
962 GetGame().GetInputManager().RemoveActionListener("BindQuickslot9", EActionTrigger.DOWN, OnQuickslotBind9);
963
965
967 if (baseUI)
968 baseUI.CloseQuickSlots();
969
970 m_bIsCommandSelected = false;
971 }
972
973 //------------------------------------------------------------------------------------------------
980
981 //------------------------------------------------------------------------------------------------
983 void BindToQuickslot(int slotIndex)
984 {
985 SCR_SelectionMenuEntryCommand commandEntry = SCR_SelectionMenuEntryCommand.Cast(m_RadialMenu.GetSelectionEntry());
986 if (!commandEntry)
987 return;
988
989 if (!commandEntry.IsEnabled())
990 return;
991
993 if (!character)
994 return;
995
997 if (!characterController)
998 return;
999
1000 SCR_InventoryStorageManagerComponent storageManager = SCR_InventoryStorageManagerComponent.Cast(characterController.GetInventoryStorageManager());
1001 if (!storageManager)
1002 return;
1003
1004 SCR_CharacterInventoryStorageComponent characterStorage = storageManager.GetCharacterStorage();
1005 if (!characterStorage)
1006 return;
1007
1008 SCR_QuickslotCommandContainer commandContainer = new SCR_QuickslotCommandContainer(commandEntry.GetId());
1009
1010 characterStorage.InsertContainerIntoQuickslot(commandContainer, slotIndex);
1011
1013 }
1014
1015 //------------------------------------------------------------------------------------------------
1017 {
1018 if (!m_RadialMenu)
1019 return false;
1020
1021 return m_RadialMenu.IsOpened();
1022 }
1023
1024 //------------------------------------------------------------------------------------------------
1026 {
1027 return m_bIsCommandSelected;
1028 }
1029
1030 //------------------------------------------------------------------------------------------------
1031 void SetShownCommand(SCR_InfoDisplayExtended infoDisplay)
1032 {
1033 m_CurrentShownCommand = infoDisplay;
1034 }
1035
1036 //------------------------------------------------------------------------------------------------
1037 void SetShownCommandPreview(SCR_InfoDisplayExtended infoDisplay)
1038 {
1039 m_CurrentShownCommandPreview = infoDisplay;
1040 }
1041
1042 //------------------------------------------------------------------------------------------------
1044 void DrawWaypointVisualization(vector targetPosition, float wpRadius, bool deletePrevious = true)
1045 {
1046 if (deletePrevious)
1047 m_aShapes.Clear();
1048
1049 //Shape shape = Shape.CreateSphere(Color.WHITE, ShapeFlags.VISIBLE | ShapeFlags.WIREFRAME, targetPosition, wpRadius);
1050 //m_aShapes.Insert(shape);
1051 }
1052}
1053
AddonBuildInfoTool id
ENotification
ArmaReforgerScripted GetGame()
Definition game.c:1398
InputManager GetInputManager()
void OnMapClose(MapConfiguration config)
void OnMapOpen(MapConfiguration config)
void SCR_CommandingManagerComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
enum SCR_ECompassType EntityEditorProps(category:"GameScripted/Gadgets", description:"Compass", color:"0 0 255 255")
Prefab data class for compass component.
vector position
void SCR_GroupsManagerComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
void CommandExecutedCallback(int commandIndex)
void RPC_CommandExecutedCallback(int commandIndex)
@ BRIEF
shows the command visualization only for few seconds
@ LONGLASTING
shows the command visualization for as long as the command is active
@ PERMANENT
shows the command visualization permanently, use for debug purposes
void PhysicsCommandTrace(float range=COMMANDING_VISUAL_RANGE)
void RPC_RequestExecuteCommand(int commandIndex, RplId cursorTargetID, RplId groupRplID, vector targetPoisition, int playerID)
void OnGroupChanged(int groupID)
void OnControllerTakeControl(SCR_RadialMenuController controller)
void PlayCommandGesture(int commandIndex)
void ExecuteCommand(vector targetPosition, IEntity tracedEntity)
void DrawWaypointVisualization(vector targetPosition, float wpRadius, bool deletePrevious=true)
ref SCR_PlayerCommandingMenuConfig m_CommandingMapMenuConfig
SCR_SelectionMenuEntry AddCommandElement(SCR_PlayerCommandingMenuCommand command, SCR_SelectionMenuCategoryEntry parentCategory=null)
ref SCR_RadialMenuController m_RadialMenuController
void ShowCommandPreview(string commandName)
void OnRadialMenuSelected(SCR_SelectionMenu menu, SCR_SelectionMenuEntry entry)
ref array< ref Shape > m_aShapes
void SetShownCommandPreview(SCR_InfoDisplayExtended infoDisplay)
SCR_InfoDisplayExtended m_CurrentShownCommandPreview
ref SCR_PhysicsHelper m_PhysicsHelper
void OnRadialMenuPerformed(SCR_SelectionMenu menu, SCR_SelectionMenuEntry entry)
bool AddElementsFromCategoryToMap(notnull SCR_PlayerCommandingMenuCategoryElement category, SCR_SelectionMenuCategoryEntry parentCategory=null)
SCR_MapMenuCommandingEntry InsertElementToMapRadial(SCR_PlayerCommandingMenuBaseElement element, notnull SCR_PlayerCommandingMenuCategoryElement category, SCR_SelectionMenuCategoryEntry mapCategory)
void OnControllerLostControl(SCR_RadialMenuController controller, bool hasControl)
void DeleteShownCommand()
If a command is currently being displayed, hide/delete it.
void BindToQuickslot(int slotIndex)
void UpdateRadialMenu(IEntity owner, bool isOpen)
void PrepareExecuteCommand(string commandName, vector targetPosition="0 0 0")
void SetShownCommand(SCR_InfoDisplayExtended infoDisplay)
ResourceName m_sCommandingMapMenuConfigPath
SCR_MapRadialUI m_MapContextualMenu
void HideCommandPreview()
Hide command preview.
ref SCR_PlayerCommandingMenuActionsSetup m_CommandingMenuPairsConfig
bool AddElementsFromCategory(SCR_PlayerCommandingMenuCategoryElement category, SCR_SelectionMenuCategoryEntry rootCategory=null)
void OnRadialMenuOpenFailed(SCR_SelectionMenu menu, SCR_ESelectionMenuFailReason reason)
SCR_SelectionMenuEntry AddRadialMenuElement(SCR_PlayerCommandingMenuBaseElement newElement, SCR_SelectionMenuCategoryEntry parentCategory=null)
SCR_SelectionMenuEntry AddCategoryElement(SCR_PlayerCommandingMenuCategoryElement category, SCR_SelectionMenuCategoryEntry parentCategory=null)
void OnGroupLeaderChanged(int groupID, int playerID)
SCR_RadialMenu m_RadialMenu
ref SCR_PlayerCommandingMenuConfig m_CommandingMenuConfig
SCR_CommandingManagerComponent m_CommandingManager
void OnMapCommandPerformed(SCR_SelectionMenuEntry element, float[] worldPos)
SCR_InfoDisplayExtended m_CurrentShownCommand
bool GetWorldToScreenPosition(BaseWorld world, vector worldPosition, out float posX, out float posY, int cameraIndex=-1)
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
SCR_ESelectionMenuFailReason
Enum of reason why the menu did not open.
proto external int SetEventMask(notnull IEntity owner, int mask)
void Rpc(func method, void p0=NULL, void p1=NULL, void p2=NULL, void p3=NULL, void p4=NULL, void p5=NULL, void p6=NULL, void p7=NULL)
proto external Managed FindComponent(typename typeName)
Input management system for user interactions.
Definition Math.c:13
Object holding reference to resource. In destructor release the resource.
Definition Resource.c:25
Replication item identifier.
Definition RplId.c:14
bool IsPlayerLeader(int playerID)
SCR_AIGroup GetSlave()
override void VisualizeCommandPreview(vector targetPosition)
bool CanBeExecuted(IEntity target)
LocalizedString GetCannotExecuteReason()
LocalizedString GetCannotPerformReason()
bool CanBePerformed(notnull SCR_ChimeraCharacter user)
void VisualizeCommand(vector targetPosition)
void InsertContainerIntoQuickslot(SCR_QuickslotBaseContainer container, int slotIndex)
static SCR_HUDManagerComponent GetHUDManager()
static ScriptInvokerBase< MapConfigurationInvoker > GetOnMapClose()
Get on map close invoker.
bool IsOpen()
Check if the map is opened.
static ScriptInvokerBase< MapConfigurationInvoker > GetOnMapOpen()
Get on map open invoker.
static SCR_MapEntity GetMapInstance()
Get map entity instance.
2D map radial menu UI
ScriptInvokerMenuEntryPerformed GetOnEntryPerformedInvoker()
static SCR_MapRadialUI GetInstance()
Commanding menus config to setup different menus to different keybinds.
Commanding menu base element class.
Commanding menu base element class.
static int GetLocalPlayerId()
Returns either a valid ID of local player or 0.
OnOwnershipChangedInvoker GetOnOwnershipChangedInvoker()
static IEntity GetLocalControlledEntity()
static SCR_RadialMenu GlobalRadialMenu()
Find and get reference to global redial menu.
void AddEntry(SCR_SelectionMenuEntry entry=null)
void SetCommandText(string text)
string GetId()
static void RefreshQuickSlots(int id=-1)
static SCR_WeaponSwitchingBaseUI GetWeaponSwitchingBaseUI()
proto external GenericEntity GetOwner()
Get owner entity.
CameraManagerClass GenericEntityClass CurrentCamera()
Returns the current camera.
SCR_FieldOfViewSettings Attribute
EntityEvent
Various entity events.
Definition EntityEvent.c:14
proto external PlayerController GetPlayerController()
EActionTrigger
proto external int GetPlayerId()
void OnOwnershipChanged(bool changing, bool becameOwner)
void RplRpc(RplChannel channel, RplRcver rcver, RplCondition condition=RplCondition.None, string customConditionName="")
Definition EnNetwork.c:95
RplRcver
Definition RplRcver.c:59
RplChannel
Communication channel. Reliable is guaranteed to be delivered. Unreliable not.
Definition RplChannel.c:14
TraceFlags
Definition TraceFlags.c:13