4 [
Attribute(
"LoadoutList",
desc:
"List for available player's loadouts' buttons")]
5 protected string m_sLoadoutList;
6 protected GridLayoutWidget m_wLoadoutList;
9 protected string m_sLoadoutPreview;
10 protected Widget m_wLoadoutPreview;
13 protected string m_sLoadoutIcon;
14 protected ImageWidget m_wLoadoutIcon;
17 protected string m_sLoadoutName;
18 protected TextWidget m_wLoadoutName;
20 [
Attribute(
"{39D815C843414C76}UI/layouts/Menus/DeployMenu/LoadoutButton.layout",
desc:
"Layout for loadout button, has to have SCR_LoadoutButton attached to it.")]
21 protected ResourceName m_sLoadoutButton;
24 protected string m_sLoadoutSelector;
25 protected Widget m_wLoadoutSelector;
28 protected string m_sRoot;
35 protected SCR_ArsenalManagerComponent m_ArsenalManagerComp;
37 protected IEntity m_PreviewedEntity;
39 protected Widget m_wLoadouty;
40 protected Widget m_wSupplies;
41 protected RichTextWidget m_wSuppliesText;
43 protected const int LOADOUTS_PER_ROW = 2;
49 override void HandlerAttached(Widget w)
51 super.HandlerAttached(w);
52 m_wRoot = w.FindAnyWidget(m_sRoot);
54 m_LoadoutManager =
GetGame().GetLoadoutManager();
55 if (!m_LoadoutManager)
57 Print(
"Loadout manager is missing in the world! Deploy menu won't work correctly.", LogLevel.ERROR);
62 m_LoadoutManager.GetOnMappedPlayerLoadoutInfoChanged().Insert(OnLoadoutsChanged);
64 m_wLoadoutIcon = ImageWidget.Cast(w.FindAnyWidget(m_sLoadoutIcon));
65 m_wLoadoutName = TextWidget.Cast(w.FindAnyWidget(m_sLoadoutName));
66 m_wLoadoutList = GridLayoutWidget.Cast(w.FindAnyWidget(m_sLoadoutList));
68 m_wLoadouty = w.FindAnyWidget(
"Loadouty");
70 m_wExpandButtonName = TextWidget.Cast(w.FindAnyWidget(m_sExpandButtonName));
71 m_wExpandButtonIcon = ImageWidget.Cast(w.FindAnyWidget(m_sExpandButtonIcon));
74 SCR_ArsenalManagerComponent.GetArsenalManager(m_ArsenalManagerComp);
75 if (m_ArsenalManagerComp)
76 m_ArsenalManagerComp.GetOnLoadoutUpdated().Insert(UpdateLoadouts);
81 expandBtn.m_OnClicked.Insert(ToggleCollapsed);
82 GetOnListCollapse().Insert(OnListExpand);
85 m_wLoadoutSelector = w.FindAnyWidget(m_sLoadoutSelector);
86 if (m_wLoadoutSelector)
89 if (m_LoadoutSelector)
91 m_LoadoutSelector.GetOnLoadoutClicked().Insert(RequestPlayerLoadout);
92 m_LoadoutSelector.GetOnLoadoutHovered().Insert(SetLoadoutPreview);
95 m_wLoadoutPreview = w.FindAnyWidget(m_sLoadoutPreview);
96 if (m_wLoadoutPreview)
99 PlayerController pc =
GetGame().GetPlayerController();
104 if (GetPlayerLoadout())
106 if (m_wExpandButtonName)
107 m_wExpandButtonName.SetText(GetPlayerLoadout().GetLoadoutName());
108 SetLoadoutPreview(GetPlayerLoadout());
113 m_wSupplies = m_wLoadouty.FindAnyWidget(
"w_Supplies");
117 m_wSuppliesText = RichTextWidget.Cast(m_wSupplies.FindAnyWidget(
"SuppliesText"));
118 m_wSupplies.SetVisible(!m_wSuppliesText.GetText().IsEmpty());
122 protected override void ToggleCollapsed()
126 bool visible = !IsExpanded();
127 SetExpanded(visible);
128 GetOnListCollapse().Invoke(
this, visible);
132 override void SetExpanded(
bool expanded)
134 m_wLoadouty.SetVisible(expanded);
137 protected override bool IsExpanded()
139 return m_wLoadouty.IsVisible();
152 if (loadoutBtn && loadoutBtn.GetPlayerId() == component.GetPlayerId())
154 loadoutBtn.SetLoadout(component.GetLoadout());
161 void ShowAvailableLoadouts(
Faction faction)
163 if (!m_LoadoutManager)
166 ResetPlayerLoadoutPreview();
168 if (!m_LoadoutSelector)
171 m_LoadoutSelector.ClearAll();
173 array<ref SCR_BasePlayerLoadout> availableLoadouts = {};
174 m_LoadoutManager.GetPlayerLoadoutsByFaction(faction, availableLoadouts);
179 if (!
loadout.IsLoadoutAvailableClient())
185 m_LoadoutSelector.AddItem(
loadout,
loadout.IsLoadoutAvailableClient());
188 if (!availableLoadouts.IsEmpty())
190 if (arsenalLoadout && GetPlayerLoadout() != arsenalLoadout)
192 else if (!GetPlayerLoadout())
196 RefreshLoadoutPreview();
200 void ShowPlayerLoadouts(array<int> playerIds,
int slotCount = -1)
202 if (!m_wLoadoutList || !m_LoadoutManager)
205 SetListVisible(
true);
209 if (!playerIds || playerIds.IsEmpty())
212 for (
int i = 0; i < playerIds.Count(); ++i)
214 int pid = playerIds[i];
216 CreatePlayerLoadoutButton(playerLoadout, pid, i);
219 for (
int i = playerIds.Count(); i < slotCount; ++i)
226 protected void ClearLoadoutList()
228 Widget child = m_wLoadoutList.GetChildren();
231 Widget sibling = child.GetSibling();
232 child.RemoveFromHierarchy();
242 Widget name =
GetGame().GetWorkspace().CreateWidgets(m_sLoadoutButton, m_wLoadoutList);
245 buttonComp.SetLoadout(
loadout);
246 buttonComp.SetPlayer(pid);
248 buttonComp.SetEnabled(
loadout.IsLoadoutAvailableClient());
250 buttonComp.m_OnFocus.Insert(OnButtonFocused);
251 buttonComp.m_OnFocusLost.Insert(OnButtonFocusLost);
252 buttonComp.m_OnMouseEnter.Insert(OnButtonFocused);
253 buttonComp.m_OnMouseLeave.Insert(OnMouseLeft);
257 GridSlot.SetColumn(name, order % LOADOUTS_PER_ROW);
258 GridSlot.SetRow(name, order / LOADOUTS_PER_ROW);
262 protected void CreateEmptySlot(
int order)
264 Widget slot =
GetGame().GetWorkspace().CreateWidgets(m_sLoadoutButton, m_wLoadoutList);
267 handler.SetShouldUnlock(
false);
270 GridSlot.SetColumn(slot, order % LOADOUTS_PER_ROW);
271 GridSlot.SetRow(slot, order / LOADOUTS_PER_ROW);
274 protected void UpdateLoadouts(
int playerID,
bool hasValidLoadout)
276 array<ref SCR_BasePlayerLoadout> availableLoadouts = {};
277 m_LoadoutManager.GetPlayerLoadoutsByFaction(
m_PlyFactionAffilComp.GetAffiliatedFaction(), availableLoadouts);
282 loadoutBtn.SetEnabled(
loadout.IsLoadoutAvailableClient());
296 if (m_wExpandButtonName)
297 m_wExpandButtonName.SetText(
loadout.GetLoadoutName());
302 protected void OnButtonFocused(Widget w)
308 m_OnButtonFocused.Invoke();
310 if (m_OnPlayerEntryFocused)
311 m_OnPlayerEntryFocused.Invoke(loadoutBtn.GetPlayerId());
315 protected void OnButtonFocusLost(Widget w)
317 if (m_OnPlayerEntryFocusLost)
318 m_OnPlayerEntryFocusLost.Invoke(w);
324 if (!m_OnPlayerEntryFocused)
327 return m_OnPlayerEntryFocused;
333 if (!m_OnPlayerEntryFocusLost)
336 return m_OnPlayerEntryFocusLost;
340 void RequestRandomLoadout(
Faction faction)
342 array<ref SCR_BasePlayerLoadout> loadouts = {};
343 m_LoadoutManager.GetPlayerLoadoutsByFaction(faction, loadouts);
346 GetGame().GetCallqueue().CallLater(SetLoadoutPreview, 10,
false, rndLoadout);
355 loadoutBtn.SetSelected(loadoutBtn.GetPlayerId() == component.GetPlayerId());
358 if (m_LoadoutSelector)
359 m_LoadoutSelector.SetSelected(component.GetLoadout());
363 protected float GetLoadoutCost()
375 m_wLoadoutName.SetText(
loadout.GetLoadoutName());
376 m_PreviewedEntity = m_PreviewComp.SetPreviewedLoadout(
loadout);
377 m_wLoadoutPreview.SetVisible(
true);
381 float supplyCost = GetLoadoutCost();
383 m_wSupplies.SetVisible(supplyCost > 0);
389 void RefreshLoadoutPreview()
397 if (m_LoadoutSelector)
398 m_LoadoutSelector.SetSelected(
loadout);
401 m_wLoadoutName.SetText(
loadout.GetLoadoutName());
403 if (m_wExpandButtonName &&
loadout)
404 m_wExpandButtonName.SetText(
loadout.GetLoadoutName());
406 if (m_wExpandButtonIcon &&
loadout)
407 m_wExpandButtonIcon.LoadImageTexture(0, GetUIInfo(
loadout).GetIconPath());
409 if (m_wSuppliesText &&
loadout)
411 int supplyCost = GetLoadoutCost();
414 m_wSupplies.SetVisible(supplyCost > 0);
428 m_LoadoutSelector.AddItem(
loadout);
431 protected void ResetPlayerLoadoutPreview()
433 if (m_wLoadoutPreview)
434 m_wLoadoutPreview.SetVisible(
false);
437 m_wLoadoutName.SetText(
"#AR-DeployMenu_SelectLoadout");
440 void SetListVisible(
bool visible)
443 m_wLoadoutList.SetVisible(visible);
446 void ShowLoadoutSelector(
bool show)
456 Resource res = Resource.Load(
loadout.GetLoadoutResource());
457 IEntityComponentSource source =
SCR_BaseContainerTools.FindComponentSource(res,
"SCR_EditableCharacterComponent");
460 BaseContainer container = source.GetObject(
"m_UIInfo");
469 override void SetListWidget(Widget list)
477 m_wLoadoutList = GridLayoutWidget.Cast(list);
480 bool IsSelectorFocused()
482 return m_LoadoutSelector && m_LoadoutSelector.GetFocused();
490 protected string m_sPlayerName;
491 protected TextWidget m_wPlayerName;
494 protected string m_sLeaderText;
495 protected Widget m_wLeaderText;
498 protected int m_iPlayerId = -1;
501 override void HandlerAttached(Widget w)
503 super.HandlerAttached(w);
505 m_wPlayerName = TextWidget.Cast(w.FindAnyWidget(
m_sPlayerName));
506 m_wLeaderText = w.FindAnyWidget(m_sLeaderText);
507 m_wElements = w.FindAnyWidget(m_sElements);
510 SCR_AIGroup.GetOnPlayerLeaderChanged().Insert(OnLeaderChanged);
513 override void HandlerDeattached(Widget w)
515 super.HandlerDeattached(w);
517 SCR_AIGroup.GetOnPlayerLeaderChanged().Remove(OnLeaderChanged);
528 SetImage(GetUIInfo().GetIconPath());
532 void SetPlayer(
int pid)
535 SetPlayerName(
GetGame().GetPlayerManager().GetPlayerName(pid));
541 SCR_AIGroup group = groupManager.GetPlayerGroup(pid);
545 SetIsLeader(pid ==
m_iPlayerId && group.IsPlayerLeader(pid));
549 protected void OnLeaderChanged(
int groupId,
int pid)
555 SCR_AIGroup group = groupManager.FindGroup(groupId);
560 SetIsLeader(group.IsPlayerLeader(pid));
563 protected void SetIsLeader(
bool leader)
566 m_wLeaderText.SetVisible(leader);
578 protected void SetPlayerName(
string name)
581 m_wPlayerName.SetText(name);
599 Resource res = Resource.Load(m_Loadout.GetLoadoutResource());
600 IEntityComponentSource source =
SCR_BaseContainerTools.FindComponentSource(res,
"SCR_EditableCharacterComponent");
603 BaseContainer container = source.GetObject(
"m_UIInfo");