5 [
Attribute(
"GroupList",
desc:
"Container for available groups' buttons")]
6 protected string m_sGroupList;
7 protected Widget m_wGroupList;
9 [
Attribute(
"{848C61DDE45501B2}UI/layouts/Menus/DeployMenu/GroupButton.layout",
desc:
"Layout for group button, has to have SCR_GroupButton attached to it.")]
10 protected ResourceName m_sGroupButton;
12 [
Attribute(
"{59F46BD8645E8549}UI/layouts/Menus/DeployMenu/CreateGroupButton.layout")]
13 protected ResourceName m_sNewGroupButton;
14 protected Widget m_wNewGroupButton;
17 protected bool m_bCreateNewGroupButton;
20 protected SCR_PlayerControllerGroupComponent m_PlyGroupComp;
22 protected int m_iShownGroupId = -1;
24 protected ref ScriptInvoker<SCR_GroupButton> m_OnPlayerGroupJoined;
25 protected ref ScriptInvoker<int> m_OnLocalPlayerGroupJoined;
28 override void HandlerAttached(Widget w)
30 super.HandlerAttached(w);
33 if (!m_GroupManager || !m_GroupManager.IsActive())
39 m_wExpandButtonName = TextWidget.Cast(w.FindAnyWidget(m_sExpandButtonName));
40 m_wExpandButtonIcon = ImageWidget.Cast(w.FindAnyWidget(m_sExpandButtonIcon));
42 m_PlyGroupComp = SCR_PlayerControllerGroupComponent.GetLocalPlayerControllerGroupComponent();
46 m_GroupManager.GetOnPlayableGroupCreated().Insert(AddGroup);
47 m_GroupManager.GetOnPlayableGroupRemoved().Insert(RemoveGroup);
49 SCR_AIGroup.GetOnPlayerRemoved().Insert(UpdateGroupPlayers);
50 SCR_AIGroup.GetOnPlayerAdded().Insert(UpdateGroupPlayers);
51 SCR_AIGroup.GetOnPrivateGroupChanged().Insert(UpdateGroupPrivacy);
52 SCR_AIGroup.GetOnCustomNameChanged().Insert(UpdateGroupNames);
53 SCR_AIGroup.GetOnFrequencyChanged().Insert(UpdateGroupFrequency);
54 SCR_AIGroup.GetOnFlagSelected().Insert(UpdateGroupFlag);
56 m_PlyGroupComp.GetOnGroupChanged().Insert(UpdateLocalPlayerGroup);
58 m_wGroupList = w.FindAnyWidget(m_sGroupList);
64 expandBtn.m_OnClicked.Insert(ToggleCollapsed);
65 SetPlayerGroup(m_PlyGroupComp.GetPlayersGroup());
66 GetOnListCollapse().Insert(OnListExpand);
70 protected override void ToggleCollapsed()
74 bool visible = !IsExpanded();
76 GetOnListCollapse().Invoke(
this, visible);
80 override void SetExpanded(
bool expanded)
82 m_wGroupList.SetVisible(expanded);
85 protected override bool IsExpanded()
87 return m_wGroupList.IsVisible();
90 override void HandlerDeattached(Widget w)
94 m_GroupManager.GetOnPlayableGroupCreated().Remove(AddGroup);
95 m_GroupManager.GetOnPlayableGroupRemoved().Remove(RemoveGroup);
98 SCR_AIGroup.GetOnPlayerRemoved().Remove(UpdateGroupPlayers);
99 SCR_AIGroup.GetOnPlayerAdded().Remove(UpdateGroupPlayers);
100 SCR_AIGroup.GetOnPrivateGroupChanged().Remove(UpdateGroupPrivacy);
101 SCR_AIGroup.GetOnCustomNameChanged().Remove(UpdateGroupNames);
102 SCR_AIGroup.GetOnFrequencyChanged().Remove(UpdateGroupFrequency);
103 SCR_AIGroup.GetOnFlagSelected().Remove(UpdateGroupFlag);
106 m_PlyGroupComp.GetOnGroupChanged().Remove(UpdateLocalPlayerGroup);
110 protected void UpdateGroupPlayers(
SCR_AIGroup group,
int pid)
120 if (!canJoinGroup && group == GetPlayerGroup())
123 if (groupBtn && groupBtn.GetGroupId() == group.GetGroupID())
124 groupBtn.UpdateGroup(canJoinGroup);
126 groupBtn.UpdateButtonAvailability(m_PlyGroupComp);
129 GetOnPlayerGroupJoined().Invoke(group, pid);
130 UpdateNewGroupButton();
134 protected void UpdateLocalPlayerGroup(
int groupId)
136 m_iShownGroupId = groupId;
137 SCR_AIGroup group = m_GroupManager.FindGroup(groupId);
138 GetOnLocalPlayerGroupJoined().Invoke(group);
140 bool isPlayerGroup = (group == GetPlayerGroup());
148 if (groupBtn.GetGroupId() == groupId)
150 groupBtn.HideTooltip();
151 groupBtn.UpdateGroup();
152 groupBtn.UpdateButtonAvailability(m_PlyGroupComp);
155 groupBtn.SetSelected(groupBtn.GetGroupId() == groupId);
159 UpdateNewGroupButton();
160 GetGame().GetCallqueue().CallLater(SetPlayerGroup, 100,
false, group);
165 protected void UpdateGroupPrivacy(
int groupId,
bool isPrivate)
170 if (!groupBtn || (groupBtn.GetGroupId() != groupId))
173 groupBtn.UpdateGroupPrivacy(isPrivate);
174 groupBtn.UpdateButtonAvailability(m_PlyGroupComp);
178 UpdateNewGroupButton();
182 protected void UpdateGroupNames()
189 groupBtn.UpdateGroupName();
190 if (m_wExpandButtonName && groupBtn.GetGroup() == GetPlayerGroup())
191 SCR_GroupButton.SGetGroupName(groupBtn.GetGroup(), m_wExpandButtonName);
197 protected void UpdateGroupFrequency()
203 groupBtn.UpdateGroupFrequency();
208 protected void UpdateGroupFlag()
214 groupBtn.UpdateGroupFlag();
221 if (m_wExpandButtonName && group)
226 void ShowAvailableGroups(notnull
Faction faction)
228 if (!m_wGroupList || !m_GroupManager)
231 if (!m_wExpandButtonName)
232 m_wGroupList.SetVisible(
true);
233 m_PlyFaction = faction;
237 array<SCR_AIGroup> playableGroups = m_GroupManager.GetPlayableGroupsByFaction(faction);
240 #ifdef DEPLOY_MENU_DEBUG
241 PrintFormat(
"ShowAvailableGroups() for %1", faction.GetFactionKey());
243 int groupCount = playableGroups.Count();
245 for (
int i = 0; i < groupCount; ++i)
247 AddGroup(playableGroups[i])
250 CreateNewGroupButton();
254 void JoinGroupAutomatically()
259 SCR_AIGroup playerGroup = m_GroupManager.GetFirstNotFullForFaction(m_PlyFaction);
266 m_PlyGroupComp.SetSelectedGroupID(playerGroup.GetGroupID());
267 m_PlyGroupComp.RequestJoinGroup(m_PlyGroupComp.GetSelectedGroupID());
277 Widget child = m_wGroupList.GetChildren();
284 if (comp && comp.GetGroupId() == group.GetGroupID())
286 child.RemoveFromHierarchy();
290 child = child.GetSibling();
293 UpdateNewGroupButton();
297 protected void CreateNewGroupButton()
299 if (!m_bCreateNewGroupButton)
302 if (m_wNewGroupButton)
303 m_wNewGroupButton.RemoveFromHierarchy();
305 m_wNewGroupButton =
GetGame().GetWorkspace().CreateWidgets(m_sNewGroupButton, m_wGroupList);
307 handler.m_OnClicked.Insert(RequestNewGroup);
308 UpdateNewGroupButton();
312 protected void UpdateNewGroupButton()
314 if (m_wNewGroupButton)
315 m_wNewGroupButton.SetVisible(m_GroupManager.CanCreateNewGroup(m_PlyFaction));
319 protected void RequestNewGroup()
322 m_PlyGroupComp.SetSelectedGroupID(-1);
323 m_PlyGroupComp.RequestCreateGroup();
329 if (group.GetFaction() != m_PlyFaction)
332 UpdateNewGroupButton();
335 Widget child = m_wGroupList.GetChildren();
339 if (comp && comp.GetGroupId() == group.GetGroupID())
345 child = child.GetSibling();
351 Widget btnW =
GetGame().GetWorkspace().CreateWidgets(m_sGroupButton, m_wGroupList);
354 if (m_bUseListFromButton)
358 btnComp.SetGroup(group);
359 btnComp.SetSelected(m_PlyGroupComp.GetGroupID() == group.GetGroupID());
361 btnComp.UpdateGroup(canJoinGroup);
362 btnComp.m_OnClicked.Insert(RequestJoinGroup);
364 btnComp.m_OnFocus.Insert(OnButtonFocused);
365 btnComp.m_OnMouseEnter.Insert(OnButtonFocused);
367 btnComp.m_OnMouseLeave.Insert(OnMouseLeft);
370 UpdateNewGroupButton();
374 protected void OnButtonFocused(Widget w)
380 SCR_AIGroup group = m_GroupManager.FindGroup(btn.GetGroupId());
381 btn.SetTooltipAvailable(group != GetPlayerGroup());
382 m_OnButtonFocused.Invoke(group);
388 m_PlyGroupComp.SetSelectedGroupID(groupBtn.GetGroupId());
389 m_PlyGroupComp.RequestJoinGroup(m_PlyGroupComp.GetSelectedGroupID());
391 groupBtn.SetSelected(
true);
393 Widget child = m_wGroupList.GetChildren();
397 if (comp && comp != groupBtn)
399 comp.SetSelected(
false);
402 child = child.GetSibling();
412 if (groupBtn && groupBtn.GetGroup() == group)
420 Widget GetGroupList()
428 return m_PlyGroupComp.GetPlayersGroup();
432 override void SetListWidget(Widget list)
440 protected void ClearGroupList()
442 Widget child = m_wGroupList.GetChildren();
445 Widget sibling = child.GetSibling();
454 int GetShownGroupId()
456 return m_iShownGroupId;
460 void SetShownGroupId(
int groupId)
462 m_iShownGroupId = groupId;
465 ScriptInvoker GetOnPlayerGroupJoined()
467 if (!m_OnPlayerGroupJoined)
468 m_OnPlayerGroupJoined =
new ScriptInvoker();
470 return m_OnPlayerGroupJoined;
473 ScriptInvoker GetOnLocalPlayerGroupJoined()
475 if (!m_OnLocalPlayerGroupJoined)
476 m_OnLocalPlayerGroupJoined =
new ScriptInvoker();
478 return m_OnLocalPlayerGroupJoined;
487 protected string m_sGroupName;
488 protected TextWidget m_wGroupName;
491 protected string m_sFreq;
492 protected TextWidget m_wFreq;
495 protected string m_sPlayerCount;
496 protected TextWidget m_wPlayerCount;
499 protected string m_sPrivateGroup;
500 protected Widget m_wPrivateGroup;
503 protected string m_sFullGroup;
504 protected Widget m_wFullGroup;
507 protected string m_sArrowIcon;
508 protected ImageWidget m_wArrowIcon;
510 protected int m_iGroupId;
514 override void HandlerAttached(Widget w)
516 super.HandlerAttached(w);
518 m_wGroupName = TextWidget.Cast(w.FindAnyWidget(m_sGroupName));
519 m_wFreq = TextWidget.Cast(w.FindAnyWidget(m_sFreq));
520 m_wPlayerCount = TextWidget.Cast(w.FindAnyWidget(m_sPlayerCount));
521 m_wPrivateGroup = w.FindAnyWidget(m_sPrivateGroup);
522 m_wElements = w.FindAnyWidget(m_sElements);
523 m_wArrowIcon = ImageWidget.Cast(w.FindAnyWidget(m_sArrowIcon));
524 m_wFullGroup = w.FindAnyWidget(m_sFullGroup);
530 m_iGroupId = group.GetGroupID();
535 void UpdateGroup(
bool canJoin =
true)
539 #ifdef DEPLOY_MENU_DEBUG
540 PrintFormat(
"UpdateGroup() name: %1, group id: %2",
m_Group.GetCustomNameWithOriginal(),
m_Group.GetGroupID());
542 GetGame().GetCallqueue().CallLater(UpdateGroupName, 100,
false);
544 UpdateGroupFrequency();
545 UpdateGroupPrivacy(
m_Group.IsPrivate());
547 SetGroupFull(
m_Group.IsFull());
549 bool buttonEnabled = canJoin && !
m_Group.IsFull() && !
m_Group.IsPrivate();
551 #ifdef DEPLOY_MENU_DEBUG
552 PrintFormat(
"%1::UpdateGroup() name: %2, group id: %7, Is full: %3, IsEnabled(): %4, canJoin: %5, isPrivate: %6",
this,
m_Group.GetCustomNameWithOriginal(),
m_Group.IsFull().ToString(),
IsEnabled().ToString(), canJoin.ToString(),
m_Group.IsPrivate().ToString(),
m_Group.GetGroupID());
555 m_wPlayerCount.SetTextFormat(
"%1/%2",
m_Group.GetPlayerCount(),
m_Group.GetMaxMembers());
559 void UpdateGroupName()
561 if (
m_Group.GetCustomName().IsEmpty())
563 string company, platoon, squad, character, format;
564 m_Group.GetCallsigns(company, platoon, squad, character, format);
565 m_wGroupName.SetTextFormat(format, company, platoon, squad, character);
569 SetText(
m_Group.GetCustomName());
574 string GetGroupName()
576 return m_wGroupName.GetText();
580 static void SGetGroupName(notnull
SCR_AIGroup group, notnull TextWidget widget)
582 string freq =
string.Format(
"%1 #AR-VON_FrequencyUnits_MHz", group.GetRadioFrequency() * 0.001);
583 if (group.GetCustomName().IsEmpty())
585 string company, platoon, squad, character, format;
586 group.GetCallsigns(company, platoon, squad, character, format);
587 widget.SetTextFormat(format +
" %5", company, platoon, squad, character, freq);
591 widget.SetTextFormat(
"%1 %2", group.GetCustomName(), freq);
608 void UpdateGroupPrivacy(
bool isPrivate)
611 m_wPrivateGroup.SetVisible(isPrivate);
613 #ifdef DEPLOY_MENU_DEBUG
614 PrintFormat(
"%1::UpdateGroupPrivacy() %2, group id: %5, Is private: %3, IsEnabled(): %4",
615 this,
m_Group.GetCustomNameWithOriginal(), isPrivate.ToString(),
IsEnabled().ToString(),
m_Group.GetGroupID());
620 void UpdateButtonAvailability(SCR_PlayerControllerGroupComponent groupCtrl)
626 if (!canJoinGroup &&
m_Group == groupCtrl.GetPlayersGroup())
635 protected void SetGroupFull(
bool full)
638 m_wFullGroup.SetVisible(full);
643 m_wPlayerCount.SetColor(m_ColorWarning);
645 m_wPlayerCount.SetColor(Color.FromInt(Color.WHITE));
650 protected void SetText(
string text)
653 m_wGroupName.SetText(text);
657 void UpdateGroupFrequency()
660 m_wFreq.SetTextFormat(
"%1 #AR-VON_FrequencyUnits_MHz", (
m_Group.GetRadioFrequency() * 0.001).ToString());
664 void UpdateGroupFlag()
670 array<ResourceName> textures = {};
671 array<string> names = {};
672 ResourceName imageSet = scrFaction.GetGroupFlagImageSet();
674 scrFaction.GetGroupFlagTextures(textures);
675 scrFaction.GetFlagNames(names);
677 ResourceName flag =
m_Group.GetGroupFlag();
681 if (!imageSet.IsEmpty() && !names.IsEmpty())
685 else if (!textures.IsEmpty())
691 SetImage(scrFaction.GetFactionFlag());
696 if (
m_Group.GetFlagIsFromImageSet())
708 override void SetSelected(
bool selected)
710 super.SetSelected(selected);
715 m_wArrowIcon.SetRotation(90);
717 m_wArrowIcon.SetRotation(270);