Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_LoadoutRequestUIComponent.c
Go to the documentation of this file.
1
2 //------------------------------------------------------------------------------------------------
5
6 //------------------------------------------------------------------------------------------------
9
10 //------------------------------------------------------------------------------------------------
15{
16 [Attribute("LoadoutList", desc: "List for available player's loadouts' buttons")]
17 protected string m_sLoadoutList;
19
20 [Attribute("LoadoutPreview")]
21 protected string m_sLoadoutPreview;
23
24 [Attribute("LoadoutIcon")]
25 protected string m_sLoadoutIcon;
27
28 [Attribute("LoadoutName")]
29 protected string m_sLoadoutName;
31
32 [Attribute("Dawn")]
33 protected string m_sDTDawn;
34
35 [Attribute("Forenoon")]
36 protected string m_sDTForenoon;
37
38 [Attribute("Afternoon")]
39 protected string m_sDTAfternoon;
40
41 [Attribute("Dusk")]
42 protected string m_sDTDusk;
43
44 [Attribute("Evening")]
45 protected string m_sDTEvening;
46
47 [Attribute("Night")]
48 protected string m_sDTNight;
49
50 [Attribute("#AR-Loadout_Free_Supply_Cost")]
51 protected string m_sFreeLoadout;
52
54
55 [Attribute("{39D815C843414C76}UI/layouts/Menus/DeployMenu/LoadoutButton.layout", desc: "Layout for loadout button, has to have SCR_LoadoutButton attached to it.")]
57
58 [Attribute("Selector")]
59 protected string m_sLoadoutSelector;
61
62 [Attribute("LoadoutSelectorRoot")]
63 protected string m_sRoot;
64
66
70 protected SCR_ArsenalManagerComponent m_ArsenalManagerComp;
72 protected SCR_PlayerControllerGroupComponent m_PlayerControllerGroupComponent;
75
83 protected string m_sMSARSuppliesName = "MSAR_Supplies";
84
85 protected const int LOADOUTS_PER_ROW = 2;
86 protected const int EXTRA_ROWS_FOR_INFINITE_GROUP = 2;
87
90
91 protected SCR_UIInfo uiInfo;
92 protected string m_sLoadoutImageName;
93 protected string m_sDayModifier;
94 protected string m_sWeatherModifier;
95
96 //------------------------------------------------------------------------------------------------
97 override void HandlerAttached(Widget w)
98 {
99 super.HandlerAttached(w);
100 m_wRoot = w.FindAnyWidget(m_sRoot);
101
102 m_LoadoutManager = GetGame().GetLoadoutManager();
103 if (!m_LoadoutManager)
104 {
105 Print("Loadout manager is missing in the world! Deploy menu won't work correctly.", LogLevel.ERROR);
106 return;
107 }
108
110 m_LoadoutManager.GetOnMappedPlayerLoadoutInfoChanged().Insert(OnLoadoutsChanged); // todo@lk: update loadout list
111
112 m_wLoadoutIcon = ImageWidget.Cast(w.FindAnyWidget(m_sLoadoutIcon));
113 m_wLoadoutName = TextWidget.Cast(w.FindAnyWidget(m_sLoadoutName));
114 m_wLoadoutList = GridLayoutWidget.Cast(w.FindAnyWidget(m_sLoadoutList));
115
116 m_wLoadouty = w.FindAnyWidget("Loadouty");
117
118 m_wExpandButtonName = TextWidget.Cast(w.FindAnyWidget(m_sExpandButtonName));
119 m_wExpandButtonIcon = ImageWidget.Cast(w.FindAnyWidget(m_sExpandButtonIcon));
120 m_wExpandButton = w.FindAnyWidget(m_sExpandButton);
121
122 if (SCR_ArsenalManagerComponent.GetArsenalManager(m_ArsenalManagerComp))
123 {
124 m_ArsenalManagerComp.GetOnLoadoutUpdated().Insert(UpdateLoadouts);
125 m_ArsenalManagerComp.GetOnLoadoutSpawnSupplyCostMultiplierChanged().Insert(OnLoadoutSpawnCostMultiplierChanged);
126 }
127
128 if (m_wExpandButton && m_wExpandButton.IsVisible())
129 {
131 expandBtn.m_OnClicked.Insert(ToggleCollapsed);
133 }
134
135 m_wLoadoutSelector = w.FindAnyWidget(m_sLoadoutSelector);
138
140 {
141 m_LoadoutSelector.GetOnLoadoutClicked().Insert(OnRequestPlayerLoadout);
142 m_LoadoutSelector.GetOnLoadoutHovered().Insert(SetLoadoutPreview);
143 }
144
145 m_wLoadoutPreview = w.FindAnyWidget(m_sLoadoutPreview);
148
149 PlayerController pc = GetGame().GetPlayerController();
150 if (pc)
151 {
154 if (GetPlayerLoadout())
155 {
157 m_wExpandButtonName.SetText(GetPlayerLoadout().GetLoadoutName());
159 }
160 }
161
162 if (m_wLoadouty)
163 m_wSupplies = m_wLoadouty.FindAnyWidget("w_Supplies");
164 if (m_wSupplies)
165 {
166 m_wSuppliesText = RichTextWidget.Cast(m_wSupplies.FindAnyWidget("SuppliesText"));
167 m_wLoadoutNameText = RichTextWidget.Cast(m_wSupplies.FindAnyWidget("LoadoutNameText"));
168 }
169
170 m_wMSARSupplies = w.FindAnyWidget(m_sMSARSuppliesName);
171 if (m_wMSARSupplies)
173
174 m_PlayerControllerGroupComponent = SCR_PlayerControllerGroupComponent.GetLocalPlayerControllerGroupComponent();
176 m_PlayerControllerGroupComponent.GetOnGroupChanged().Insert(OnGroupChanged);
177 }
178
179 //------------------------------------------------------------------------------------------------
180 override void HandlerDeattached(Widget w)
181 {
182 super.HandlerDeattached(w);
183
185 {
186 m_ArsenalManagerComp.GetOnLoadoutUpdated().Remove(UpdateLoadouts);
187 m_ArsenalManagerComp.GetOnLoadoutSpawnSupplyCostMultiplierChanged().Remove(OnLoadoutSpawnCostMultiplierChanged);
188 }
189
191 m_PlayerControllerGroupComponent.GetOnGroupChanged().Remove(OnGroupChanged);
192 }
193
194 //------------------------------------------------------------------------------------------------
195 protected override void ToggleCollapsed()
196 {
197 if (m_wExpandButton && m_wExpandButton.IsVisible())
198 {
199 bool visible = !IsExpanded();
200 SetExpanded(visible);
201 GetOnListCollapse().Invoke(this, visible);
202 }
203 }
204
205 //------------------------------------------------------------------------------------------------
206 override void SetExpanded(bool expanded)
207 {
208 m_wLoadouty.SetVisible(expanded);
209 }
210
211 //------------------------------------------------------------------------------------------------
212 protected override bool IsExpanded()
213 {
214 return m_wLoadouty.IsVisible();
215 }
216
217 //------------------------------------------------------------------------------------------------
218 protected void OnLoadoutsChanged(SCR_BasePlayerLoadout loadout, int newCount)
219 {
220 }
221
222 //------------------------------------------------------------------------------------------------
225 {
226 foreach (SCR_DeployButtonBase btn : m_aButtons)
227 {
228 SCR_LoadoutButton loadoutBtn = SCR_LoadoutButton.Cast(btn);
229 if (loadoutBtn && loadoutBtn.GetPlayerId() == component.GetPlayerId())
230 {
231 loadoutBtn.SetLoadout(component.GetLoadout());
232 break;
233 }
234 }
235 }
236
237 //------------------------------------------------------------------------------------------------
238 protected void OnGroupChanged(int groupId)
239 {
241 return;
242
243 ShowAvailableLoadouts(m_PlyFactionAffilComp.GetAffiliatedFaction());
244 }
245
246 //------------------------------------------------------------------------------------------------
249 {
250 if (!m_LoadoutManager)
251 return;
252
254
256 return;
257
258 m_LoadoutSelector.ClearAll();
259
260 array<ref SCR_BasePlayerLoadout> availableLoadouts = {};
261
262 PlayerController pc = GetGame().GetPlayerController();
263 SCR_PlayerControllerGroupComponent pcGroupComponent = SCR_PlayerControllerGroupComponent.Cast(pc.FindComponent(SCR_PlayerControllerGroupComponent));
264 if (!pcGroupComponent)
265 return;
266
267 SCR_Faction scrFaction = SCR_Faction.Cast(faction);
268 if (!scrFaction)
269 return;
270
271 SCR_AIGroup group = pcGroupComponent.GetPlayersGroup();
272 if (group && scrFaction.IsGroupRolesConfigured())
273 {
274 m_LoadoutManager.GetPlayerLoadoutsByGroup(group, faction, availableLoadouts);
275 }
276 else
277 {
278 // default behavior
279 m_LoadoutManager.GetPlayerLoadoutsByFaction(faction, availableLoadouts);
280 }
281
282 SCR_PlayerArsenalLoadout arsenalLoadout = null;
283 foreach (SCR_BasePlayerLoadout loadout : availableLoadouts)
284 {
285 if (!loadout.IsLoadoutAvailableClient())
286 continue;
287
288 if (loadout.IsInherited(SCR_PlayerArsenalLoadout))
289 arsenalLoadout = SCR_PlayerArsenalLoadout.Cast(loadout);
290
291 m_LoadoutSelector.AddItem(loadout, loadout.IsLoadoutAvailableClient());
292 }
293
294 if (!availableLoadouts.IsEmpty())
295 {
296 SCR_BasePlayerLoadout selectedLoadout = GetPlayerLoadout();
297
298 if (arsenalLoadout && selectedLoadout != arsenalLoadout)
299 {
300 m_PlyLoadoutComp.RequestLoadout(arsenalLoadout);
301 }
302 else if (!selectedLoadout || !availableLoadouts.Contains(selectedLoadout))
303 {
304 // need request every time when group is changed
305 foreach (SCR_BasePlayerLoadout loadout : availableLoadouts)
306 {
307 if (loadout.IsLoadoutAvailableClient())
308 {
309 m_PlyLoadoutComp.RequestLoadout(loadout);
310 break;
311 }
312 }
313 }
314 }
315
316 GetGame().GetCallqueue().CallLater(RefreshLoadoutPreview, 0, false); // delayed refresh call helps with performance
317 }
318
319 //------------------------------------------------------------------------------------------------
321 void ShowPlayerLoadouts(array<int> playerIds, SCR_AIGroup group = null)
322 {
324 return;
325
326 SetListVisible(true);
327
329
330 if (!playerIds || playerIds.IsEmpty())
331 return;
332
333 for (int i = 0; i < playerIds.Count(); ++i)
334 {
335 int pid = playerIds[i];
336 SCR_BasePlayerLoadout playerLoadout = m_LoadoutManager.GetPlayerLoadout(pid);
337 CreatePlayerLoadoutButton(playerLoadout, pid, i);
338 }
339
340 if (!group)
341 return;
342
343 int playerCount = playerIds.Count();
344 int slotCount = group.GetMaxMembers();
345
346 if (!group.IsMaxMembersLimited()) // get max members is technically 0, so here we are adding extra empty slots so the infinite group
347 { // looks like it has space in it! We limit the amount to make sure it doesnt fill the screen
348 slotCount = playerCount - (playerCount % LOADOUTS_PER_ROW) + ((EXTRA_ROWS_FOR_INFINITE_GROUP + 1) * LOADOUTS_PER_ROW);
349 }
350
351 for (int i = playerCount; i < slotCount; ++i)
352 {
354 }
355 }
356
357 //------------------------------------------------------------------------------------------------
359 protected void ClearLoadoutList()
360 {
361 Widget child = m_wLoadoutList.GetChildren();
362 while (child)
363 {
364 Widget sibling = child.GetSibling();
365 child.RemoveFromHierarchy();
366 child = sibling;
367 }
368
369 m_aButtons.Clear();
370 }
371
372 //------------------------------------------------------------------------------------------------
373 // Create a non-interactive loadout button with player's name.
374 protected void CreatePlayerLoadoutButton(SCR_BasePlayerLoadout loadout, int pid, int order)
375 {
376 Widget name = GetGame().GetWorkspace().CreateWidgets(m_sLoadoutButton, m_wLoadoutList);
377 if (!name)
378 return;
379
380 SCR_LoadoutButton buttonComp = SCR_LoadoutButton.Cast(name.FindHandler(SCR_LoadoutButton));
381 if (!buttonComp)
382 return;
383
384 buttonComp.SetLoadout(loadout);
385 buttonComp.SetPlayer(pid);
386 buttonComp.SetSelected(pid == GetGame().GetPlayerController().GetPlayerId());
387 buttonComp.SetEnabled(!loadout || loadout.IsLoadoutAvailableClient());
388
389 buttonComp.m_OnFocus.Insert(OnButtonFocused);
390 buttonComp.m_OnFocusLost.Insert(OnButtonFocusLost);
391 buttonComp.m_OnMouseEnter.Insert(OnButtonFocused);
392 buttonComp.m_OnMouseLeave.Insert(OnMouseLeft);
393
394 int cnt = m_aButtons.Insert(buttonComp);
395
396 GridSlot.SetColumn(name, order % LOADOUTS_PER_ROW);
397 GridSlot.SetRow(name, order / LOADOUTS_PER_ROW);
398 }
399
400 //------------------------------------------------------------------------------------------------
402 protected void CreateEmptySlot(int order)
403 {
404 Widget slot = GetGame().GetWorkspace().CreateWidgets(m_sLoadoutButton, m_wLoadoutList);
405 SCR_DeployButtonBase handler = SCR_DeployButtonBase.Cast(slot.FindHandler(SCR_DeployButtonBase));
406
407 handler.SetShouldUnlock(false);
408 m_aButtons.Insert(handler);
409
410 GridSlot.SetColumn(slot, order % LOADOUTS_PER_ROW);
411 GridSlot.SetRow(slot, order / LOADOUTS_PER_ROW);
412 }
413
414 //------------------------------------------------------------------------------------------------
415 protected void UpdateLoadouts(int playerID, bool hasValidLoadout)
416 {
417 array<ref SCR_BasePlayerLoadout> availableLoadouts = {};
418 m_LoadoutManager.GetPlayerLoadoutsByFaction(m_PlyFactionAffilComp.GetAffiliatedFaction(), availableLoadouts);
419 foreach (SCR_BasePlayerLoadout loadout : availableLoadouts)
420 {
421 SCR_LoadoutButton loadoutBtn = m_LoadoutSelector.GetButtonForLoadout(loadout);
422 if (loadoutBtn)
423 loadoutBtn.SetEnabled(loadout.IsLoadoutAvailableClient());
424 }
425 }
426
427 //------------------------------------------------------------------------------------------------
429 protected void OnRequestPlayerLoadout(SCR_LoadoutButton loadoutBtn)
430 {
432 if (!loadout)
433 return;
434
435 Lock(loadoutBtn);
437 }
438
439 //------------------------------------------------------------------------------------------------
441 {
443
445 m_wExpandButtonName.SetText(loadout.GetLoadoutName());
446
447 m_PlyLoadoutComp.RequestLoadout(loadout);
448 }
449
450 //------------------------------------------------------------------------------------------------
451 protected void OnButtonFocused(Widget w)
452 {
453 SCR_LoadoutButton loadoutBtn = SCR_LoadoutButton.Cast(w.FindHandler(SCR_LoadoutButton));
454 if (!loadoutBtn)
455 return;
456
457 m_OnButtonFocused.Invoke();
458
460 m_OnPlayerEntryFocused.Invoke(loadoutBtn.GetPlayerId());
461 }
462
463 //------------------------------------------------------------------------------------------------
464 protected void OnButtonFocusLost(Widget w)
465 {
467 m_OnPlayerEntryFocusLost.Invoke(w);
468 }
469
470 //------------------------------------------------------------------------------------------------
478
479 //------------------------------------------------------------------------------------------------
487
488 //---- REFACTOR NOTE START: This code will need to be refactored as current implementation is not conforming to the standards ----
489 //------------------------------------------------------------------------------------------------
492 {
493 array<ref SCR_BasePlayerLoadout> loadouts = {};
494 m_LoadoutManager.GetPlayerLoadoutsByFaction(faction, loadouts);
495 SCR_BasePlayerLoadout rndLoadout = loadouts.GetRandomElement();
496 m_PlyLoadoutComp.RequestLoadout(loadouts.GetRandomElement());
497 GetGame().GetCallqueue().CallLater(SetLoadoutPreview, 10, false, rndLoadout);
498 }
499 //---- REFACTOR NOTE END ----
500
501 //------------------------------------------------------------------------------------------------
503 {
504 foreach (SCR_DeployButtonBase btn : m_aButtons)
505 {
506 SCR_LoadoutButton loadoutBtn = SCR_LoadoutButton.Cast(btn);
507 if (loadoutBtn)
508 loadoutBtn.SetSelected(loadoutBtn.GetPlayerId() == component.GetPlayerId());
509 }
510
512 m_LoadoutSelector.SetSelected(component.GetLoadout());
513 }
514
515 //------------------------------------------------------------------------------------------------
516 protected void OnSpawnPointChanged(RplId id)
517 {
519 }
520
521 //------------------------------------------------------------------------------------------------
522 protected void OnLoadoutSpawnCostMultiplierChanged(float newMultiplier)
523 {
525 }
526
527 //------------------------------------------------------------------------------------------------
529 {
530 invoker.Insert(OnSpawnPointChanged);
531 }
532
533 //---- REFACTOR NOTE START: This code will need to be refactored as current implementation is not conforming to the standards ----
534 //------------------------------------------------------------------------------------------------
536 {
537 IEntity spawnPoint;
538
539 //~ TODO: Get loadout refresh should be called on spawnpoint selection changed
540 //~ Get selected spawnpoint
541 SCR_DeployMenuMain deployMenu = SCR_DeployMenuMain.GetDeployMenu();
542 if (deployMenu)
543 {
544 SCR_SpawnPointRequestUIComponent spawnPointRequest = deployMenu.GetSpawnPointRequestHandler();
545 if (spawnPointRequest)
546 {
547 RplComponent rplComp = RplComponent.Cast(Replication.FindItem(spawnPointRequest.GetCurrentRplId()));
548 if (rplComp)
549 spawnPoint = rplComp.GetEntity();
550 }
551 }
552
553 if (loadout)
554 return SCR_ArsenalManagerComponent.GetLoadoutCalculatedSupplyCost(loadout, true, -1, SCR_Faction.Cast(m_PlyFactionAffilComp.GetAffiliatedFaction()), spawnPoint);
555 else
556 return SCR_ArsenalManagerComponent.GetLoadoutCalculatedSupplyCost(m_PlyLoadoutComp.GetLoadout(), true, -1, SCR_Faction.Cast(m_PlyFactionAffilComp.GetAffiliatedFaction()), spawnPoint);
557 }
558
559 //------------------------------------------------------------------------------------------------
562 {
563 InputManager inputManager = GetGame().GetInputManager();
564
565 if (inputManager && inputManager.GetLastUsedInputDevice() == EInputDeviceType.KEYBOARD)
566 return;
567
568 if (m_PreviewComp && loadout)
569 {
570 if (m_wLoadoutName)
571 m_wLoadoutName.SetText(loadout.GetLoadoutName());
572 m_PreviewedEntity = m_PreviewComp.SetPreviewedLoadout(loadout);
573 m_wLoadoutPreview.SetVisible(true);
574
575 if (m_wSuppliesText)
576 {
577 int supplyCost = GetLoadoutCost(loadout);
578
579 SCR_ArsenalManagerComponent arsenalManager;
580
581 // Don't show supply cost outside of Deploy Menu
582 if (supplyCost < 0 || !SCR_DeployMenuMain.GetDeployMenu() || !SCR_ArsenalManagerComponent.GetArsenalManager(arsenalManager) || arsenalManager.GetLoadoutSpawnSupplyCostMultiplier() == 0 || !SCR_ResourceSystemHelper.IsGlobalResourceTypeEnabled())
583 {
584 m_wSupplies.SetVisible(false);
585 }
586 else
587 {
588 m_wSupplies.SetVisible(true);
589 m_wSuppliesText.SetText(SCR_ResourceSystemHelper.SuppliesToString(supplyCost));
590 }
591 }
592
593 if (m_wMSARSupplies && m_PlayerSupplyAllocationUI && SCR_ArsenalManagerComponent.IsMilitarySupplyAllocationEnabled())
594 m_PlayerSupplyAllocationUI.OnLoadoutSelected(loadout);
595
596 if (m_wLoadoutNameText && m_wSupplies.IsVisible())
597 m_wLoadoutNameText.SetText(loadout.GetLoadoutName());
598
600 m_wExpandButtonName.SetText(loadout.GetLoadoutName());
601
603 {
605 entityUIInfo.SetIconTo(m_wExpandButtonIcon);
606 }
607 }
608 }
609
610 //------------------------------------------------------------------------------------------------
613 {
615 if (!loadout)
616 return;
617
619
621 m_LoadoutSelector.SetSelected(loadout);
622
623 if (m_wLoadoutName && loadout)
624 m_wLoadoutName.SetText(loadout.GetLoadoutName());
625
627 m_wExpandButtonName.SetText(loadout.GetLoadoutName());
628
630 {
632
633 entityUIInfo.SetIconTo(m_wExpandButtonIcon);
634 }
635
637 {
638 int supplyCost = GetLoadoutCost();
639
640 SCR_ArsenalManagerComponent arsenalManager;
641
642 // Don't show supply cost outside of Deploy Menu
643 if (supplyCost < 0 || !SCR_DeployMenuMain.GetDeployMenu() || !SCR_ArsenalManagerComponent.GetArsenalManager(arsenalManager) || arsenalManager.GetLoadoutSpawnSupplyCostMultiplier() == 0 || !SCR_ResourceSystemHelper.IsGlobalResourceTypeEnabled())
644 {
645 m_wSupplies.SetVisible(false);
646 }
647 else
648 {
649 m_wSupplies.SetVisible(true);
650 m_wSuppliesText.SetText(SCR_ResourceSystemHelper.SuppliesToString(supplyCost));
651 }
652 }
653
654 if (m_wMSARSupplies && loadout && m_PlayerSupplyAllocationUI && SCR_ArsenalManagerComponent.IsMilitarySupplyAllocationEnabled())
655 m_PlayerSupplyAllocationUI.OnLoadoutSelected(loadout);
656
657 if (m_wLoadoutNameText && loadout && m_wSupplies.IsVisible())
658 m_wLoadoutNameText.SetText(loadout.GetLoadoutName());
659
660 ImageWidget LoadoutBackground = ImageWidget.Cast((m_wLoadoutSelector.GetParent()).GetParent().FindAnyWidget("Background"));
661
662 ChimeraWorld world = GetGame().GetWorld();
663 if (!world)
664 return;
665
666 TimeAndWeatherManagerEntity tmwManager = world.GetTimeAndWeatherManager();
667 if (!tmwManager)
668 return;
669
670 int dayTime = tmwManager.GetCurrentDayTimeUIInfo(uiInfo);
671 SCR_Faction faction = SCR_Faction.Cast(m_PlyFactionAffilComp.GetAffiliatedFaction());
672 WeatherStateTransitionManager transitionManager = WeatherStateTransitionManager.Cast(tmwManager.GetTransitionManager());
673 m_sWeatherModifier = transitionManager.GetCurrentState().GetStateName();
674
675 if (!m_sDayModifierStrings.IsIndexValid(dayTime))
676 return;
677
679
680 if (!faction)
681 return;
682
684
685 if (m_sWeatherModifier == "Rainy")
687 else
689
690 LoadoutBackground.LoadImageFromSet(0, m_sLoadoutImageSet, m_sLoadoutImageName);
691 }
692 //---- REFACTOR NOTE END ----
693 //------------------------------------------------------------------------------------------------
696 {
697 return m_PlyLoadoutComp.GetAssignedLoadout();
698 }
699
700 //------------------------------------------------------------------------------------------------
703 {
704 if (loadout)
705 m_LoadoutSelector.AddItem(loadout);
706 }
707
708 //------------------------------------------------------------------------------------------------
710 {
712 m_wLoadoutPreview.SetVisible(false);
713
714 if (m_wLoadoutName)
715 m_wLoadoutName.SetText("#AR-DeployMenu_SelectLoadout");
716 }
717
718 //------------------------------------------------------------------------------------------------
719 void SetListVisible(bool visible)
720 {
721 if (m_wLoadoutList)
722 m_wLoadoutList.SetVisible(visible);
723 }
724
725 //------------------------------------------------------------------------------------------------
726 void ShowLoadoutSelector(bool show)
727 {
728 m_wRoot.SetVisible(show);
729 }
730
731 //------------------------------------------------------------------------------------------------
733 {
734 if (!loadout)
735 return null;
736
737 Resource res = Resource.Load(loadout.GetLoadoutResource());
738 IEntityComponentSource source = SCR_BaseContainerTools.FindComponentSource(res, "SCR_EditableCharacterComponent");
739 if (source)
740 {
741 BaseContainer container = source.GetObject("m_UIInfo");
742 SCR_EditableEntityUIInfo info = SCR_EditableEntityUIInfo.Cast(BaseContainerTools.CreateInstanceFromContainer(container));
743
744 return info;
745 }
746
747 return null;
748 }
749
750 //------------------------------------------------------------------------------------------------
751 override void SetListWidget(Widget list)
752 {
753 if (m_wLoadoutList)
754 {
755// SetListVisible(false);
757 }
758
759 m_wLoadoutList = GridLayoutWidget.Cast(list);
760 }
761
762 //------------------------------------------------------------------------------------------------
764 {
765 return m_LoadoutSelector && m_LoadoutSelector.GetFocused();
766 }
767};
768
769//------------------------------------------------------------------------------------------------
771{
772 [Attribute("PlayerName")]
773 protected string m_sPlayerName;
774
775 [Attribute("Leader")]
776 protected string m_sLeaderText;
777
778 [Attribute("PlatformIcon")]
779 protected string m_sPlatformIconName;
780
781 [Attribute("Badge")]
782 protected string m_sBadgeWidgetName;
783
784 [Attribute("SuppliesLoadoutText")]
785 protected string m_sSuppliesLoadoutText;
786
788
793
795 protected int m_iPlayerId = -1;
796 protected bool m_bIsSelected;
797
798 //------------------------------------------------------------------------------------------------
799 override void HandlerAttached(Widget w)
800 {
801 super.HandlerAttached(w);
802
803 m_wPlayerName = TextWidget.Cast(w.FindAnyWidget(m_sPlayerName));
804 m_wLeaderText = w.FindAnyWidget(m_sLeaderText);
805 m_wElements = w.FindAnyWidget(m_sElements);
806 m_wPlatformIcon = ImageWidget.Cast(w.FindAnyWidget(m_sPlatformIconName));
807 m_wBadge = SizeLayoutWidget.Cast(w.FindAnyWidget(m_sBadgeWidgetName));
809
810 if (m_wLeaderText)
812 }
813
814 //------------------------------------------------------------------------------------------------
815 override void HandlerDeattached(Widget w)
816 {
817 super.HandlerDeattached(w);
818
820 }
821
822 //------------------------------------------------------------------------------------------------
823 override bool OnFocus(Widget w, int x, int y)
824 {
826 m_bShowBorderOnFocus = false;
827
828 if(!GetGame().GetInputManager().IsUsingMouseAndKeyboard() || m_bIsSelected)
829 ShowBorder(true, true);
830 else
831 ShowBorder(false, true);
832
833 return super.OnFocus(w, x, y);
834 }
835
836 //------------------------------------------------------------------------------------------------
837 override bool OnFocusLost(Widget w, int x, int y)
838 {
839 if(!GetGame().GetInputManager().IsUsingMouseAndKeyboard() && !m_bIsSelected)
840 ShowBorder(false, true);
841
842 if(m_bIsSelected)
843 ShowBorder(true, false);
844
845 return super.OnFocusLost(w, x, y);
846 }
847
848 //------------------------------------------------------------------------------------------------
851 {
853 if (!loadout)
854 return;
855
856 SCR_EditableEntityUIInfo entityUIInfo = GetUIInfo();
857
858 if (entityUIInfo)
859 {
860 string iconPath = entityUIInfo.GetIconPath();
861 if (iconPath.IsEmpty())
862 SetImage(entityUIInfo.GetImageSetPath(), entityUIInfo.GetIconSetName());
863 else
864 SetImage(iconPath);
865
866 if (!m_wBadge)
867 return;
868
869 m_wBadge.SetOpacity(1.00);
870 m_wBadge.SetColor(entityUIInfo.GetFaction().GetFactionColor());
871 }
872 }
873
874 //------------------------------------------------------------------------------------------------
876 void SetPlayer(int pid)
877 {
878 m_iPlayerId = pid;
879 SetPlayerName(SCR_PlayerNamesFilterCache.GetInstance().GetPlayerDisplayName(pid));
880
881 if (m_wPlatformIcon)
883
884 SCR_GroupsManagerComponent groupManager = SCR_GroupsManagerComponent.GetInstance();
885 if (!groupManager)
886 return;
887
888 SCR_AIGroup group = groupManager.GetPlayerGroup(pid);
889 if (!group)
890 return;
891
892 SetIsLeader(pid == m_iPlayerId && group.IsPlayerLeader(pid));
893 }
894
895 //------------------------------------------------------------------------------------------------
897 protected void OnLeaderChanged(int groupId, int pid)
898 {
899 SCR_GroupsManagerComponent groupManager = SCR_GroupsManagerComponent.GetInstance();
900 if (!groupManager)
901 return;
902
903 SCR_AIGroup group = groupManager.FindGroup(groupId);
904 if (!group)
905 return;
906
907 if (pid == m_iPlayerId)
908 SetIsLeader(group.IsPlayerLeader(pid));
909 }
910
911 //------------------------------------------------------------------------------------------------
912 protected void SetIsLeader(bool leader)
913 {
914 if (m_wLeaderText)
915 m_wLeaderText.SetVisible(leader);
916 }
917
918 //------------------------------------------------------------------------------------------------
920 {
921 return m_iPlayerId;
922 }
923
924 //------------------------------------------------------------------------------------------------
926 {
927 return m_bIsSelected;
928 }
929
930 //------------------------------------------------------------------------------------------------
931 override void SetSelected(bool selected)
932 {
933 super.SetSelected(selected);
934
935 m_bIsSelected = selected;
936
937 ShowBorder(selected, true);
938 }
939
940 //------------------------------------------------------------------------------------------------
941 protected void SetPlayerName(string name)
942 {
943 if (m_wPlayerName)
944 m_wPlayerName.SetText(name);
945 }
946
947 //------------------------------------------------------------------------------------------------
950 {
951 return m_Loadout;
952 }
953
954 //------------------------------------------------------------------------------------------------
957 {
958 Resource res = Resource.Load(m_Loadout.GetLoadoutResource());
959 IEntityComponentSource source = SCR_BaseContainerTools.FindComponentSource(res, "SCR_EditableCharacterComponent");
960 if (source)
961 {
962 BaseContainer container = source.GetObject("m_UIInfo");
963
964 SCR_EditableEntityUIInfo info = SCR_EditableEntityUIInfo.Cast(BaseContainerTools.CreateInstanceFromContainer(container));
965
966 return info;
967 }
968
969 return null;
970 }
971};
ArmaReforgerScripted GetGame()
Definition game.c:1398
InputManager GetInputManager()
ScriptInvokerBase< OnSpawnPointRplIdSet > OnSpawnPointRplIdSetInvoker
void SCR_GroupsManagerComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
void SCR_LoadoutManager(IEntitySource src, IEntity parent)
Widget GetRootWidget()
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
ScriptInvokerBase< ScriptInvokerWidgetMethod > ScriptInvokerWidget
ScriptInvokerBase< ScriptInvokerIntMethod > ScriptInvokerInt
Input management system for user interactions.
Main replication API.
Definition Replication.c:14
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)
static ScriptInvoker GetOnPlayerLeaderChanged()
Base class for any button, regardless its own content.
void ShowBorder(bool show, bool animate=true)
void SetShouldUnlock(bool shouldUnlock)
Marks if the buttons should be unlocked when calling the Unlock() method.
ref array< SCR_DeployButtonBase > m_aButtons
void Lock(SCR_DeployButtonBase btn)
Lock this component's buttons from processing any further requests. Unlock() should be called once yo...
void OnListExpand(SCR_DeployRequestUIBaseComponent component, bool expanded)
bool IsGroupRolesConfigured()
ResourceName GetFactionBackground()
void OnLeaderChanged(int groupId, int pid)
Update visuals when group leader changes.
override bool OnFocusLost(Widget w, int x, int y)
void SetPlayer(int pid)
Set player id associated with this button and update the visuals.
override void SetSelected(bool selected)
override void HandlerAttached(Widget w)
SCR_EditableEntityUIInfo GetUIInfo()
override bool OnFocus(Widget w, int x, int y)
SCR_BasePlayerLoadout m_Loadout
SCR_BasePlayerLoadout GetLoadout()
return player loadout
void SetLoadout(SCR_BasePlayerLoadout loadout)
Assign loadout associated with this button.
override void HandlerDeattached(Widget w)
Component responsible for requesting and visualization of available loadouts in deploy menu.
void ClearLoadoutList()
Removed all buttons from the loadout list.
void RefreshLoadoutPreview()
Refreshes current loadout preview widget.
void RequestPlayerLoadout(SCR_BasePlayerLoadout loadout)
void RegisterOnSpawnPointInvoker(notnull OnSpawnPointRplIdSetInvoker invoker)
void CreateEmptySlot(int order)
Create an empty slot in the loadout grid.
SCR_EditableEntityUIInfo GetUIInfo(SCR_BasePlayerLoadout loadout)
SCR_PlayerFactionAffiliationComponent m_PlyFactionAffilComp
void RequestRandomLoadout(Faction faction)
Send a request to assign a random faction loadout.
float GetLoadoutCost(SCR_BasePlayerLoadout loadout=null)
SCR_PlayerSupplyAllocationUI m_PlayerSupplyAllocationUI
SCR_LoadoutPreviewComponent m_PreviewComp
void AddLoadout(SCR_BasePlayerLoadout loadout)
Add a loadout into the loadout selector.
void OnPlayerLoadoutAssigned(SCR_PlayerLoadoutComponent component)
Called from deploy menu when player's loadout is assigned.
void SetSelected(SCR_PlayerLoadoutComponent component)
void ShowAvailableLoadouts(Faction faction)
Show available loadouts in the loadout selector.
void SetLoadoutPreview(SCR_BasePlayerLoadout loadout)
Set a loadout shown in the preview widget.
SCR_ArsenalManagerComponent m_ArsenalManagerComp
SCR_PlayerControllerGroupComponent m_PlayerControllerGroupComponent
void OnRequestPlayerLoadout(SCR_LoadoutButton loadoutBtn)
Send a loadout request when clicking on a loadout button.
void OnLoadoutsChanged(SCR_BasePlayerLoadout loadout, int newCount)
void OnLoadoutSpawnCostMultiplierChanged(float newMultiplier)
void UpdateLoadouts(int playerID, bool hasValidLoadout)
void CreatePlayerLoadoutButton(SCR_BasePlayerLoadout loadout, int pid, int order)
SCR_BasePlayerLoadout GetPlayerLoadout()
Get local player's assigned loadout.
SCR_PlayerLoadoutComponent m_PlyLoadoutComp
void ShowPlayerLoadouts(array< int > playerIds, SCR_AIGroup group=null)
Fill the loadout list with players' loadouts.
int GetCurrentDayTimeUIInfo(out SCR_UIInfo uiInfo)
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
SCR_FieldOfViewSettings Attribute
proto external PlayerController GetPlayerController()
proto external int GetPlayerId()