Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_GroupSubMenuPlayerlist.c
Go to the documentation of this file.
2 {
3  protected SCR_InputButtonComponent m_ViewProfileButton;
4  protected SCR_PlayerControllerGroupComponent m_PlayerGroupController;
5 
6  protected int m_iLastSelectedPlayerId;
7 
8  //------------------------------------------------------------------------------------------------
9  override void OnMenuUpdate(float tDelta)
10  {
11  GetGame().GetInputManager().ActivateContext("GroupMenuContext");
12  }
13 
14  //------------------------------------------------------------------------------------------------
15  override void OnTabCreate(Widget menuRoot, ResourceName buttonsLayout, int index)
16  {
17  super.OnTabCreate(menuRoot, buttonsLayout, index);
18 
19  m_GroupManager = SCR_GroupsManagerComponent.GetInstance();
20  m_PlayerGroupController = SCR_PlayerControllerGroupComponent.GetLocalPlayerControllerGroupComponent();
21  if (!m_PlayerGroupController)
22  return;
23 
24  CreateAddGroupButton();
25  CreateJoinGroupButton();
26  CreateAcceptInviteButton();
27  CreateGroupSettingsButton();
28  CreateViewProfileButton();
29  SetupNameChangeButton();
30  SetupPrivateChecker();
31  }
32 
33  //------------------------------------------------------------------------------------------------
34  override void OnTabShow()
35  {
36  super.OnTabShow();
37 
38  UpdateViewProfileButton(true);
39 
40  //todo:mku this is a temporary solution because of how playerlist is implemented right now
41  OverlayWidget header = OverlayWidget.Cast(m_wMenuRoot.FindAnyWidget("SortHeader"));
42  if (header)
43  header.SetVisible(false);
44  ScrollLayoutWidget scrollWidget = ScrollLayoutWidget.Cast(m_wMenuRoot.FindAnyWidget("ScrollLayout0"));
45  if (scrollWidget)
46  scrollWidget.SetVisible(false);
47  HorizontalLayoutWidget footerLeft = HorizontalLayoutWidget.Cast(m_wMenuRoot.FindAnyWidget("FooterLeft"));
48  if (footerLeft)
49  footerLeft.SetVisible(false);
50 
51  UpdateGroupsMenu();
52 
53  if (m_GroupManager)
54  {
55  m_GroupManager.GetOnPlayableGroupRemoved().Insert(UpdateGroupsMenu);
56  m_GroupManager.GetOnPlayableGroupCreated().Insert(UpdateGroupsMenu);
57  }
58 
59  SCR_AIGroup.GetOnPlayerAdded().Insert(UpdateGroupsMenu);
60  SCR_AIGroup.GetOnPlayerRemoved().Insert(UpdateGroupsMenu);
61  SCR_AIGroup.GetOnPlayerLeaderChanged().Insert(UpdateGroupsMenu);
62  SCR_AIGroup.GetOnPrivateGroupChanged().Insert(UpdateGroupsMenu);
63  SCR_AIGroup.GetOnCustomNameChanged().Insert(UpdateGroupsMenu);
64  SCR_AIGroup.GetOnFlagSelected().Insert(UpdateGroupsMenu);
65  SCR_AIGroup.GetOnCustomDescriptionChanged().Insert(UpdateGroupsMenu);
66  SCR_GroupTileButton.GetOnGroupTileClicked().Insert(UpdateGroupsMenu);
67  SCR_GroupTileButton.GetOnPlayerTileFocus().Insert(OnPlayerTileFocus);
68  SCR_GroupTileButton.GetOnPlayerTileFocusLost().Insert(OnPlayerTileFocusLost);
69  SetAcceptButtonStatus();
70  }
71 
72  //------------------------------------------------------------------------------------------------
73  void UpdateGroupsMenu()
74  {
76  if (!playerController || !m_wMenuRoot)
77  return;
78 
79  SetAcceptButtonStatus();
80 
81  m_wGridWidget = m_wMenuRoot.FindAnyWidget("GroupList");
82  InitGroups(m_PlayerGroupController);
83  }
84 
85  //------------------------------------------------------------------------------------------------
86  override void OnTabHide()
87  {
88  super.OnTabHide();
89 
90  SCR_GroupTileButton.GetOnPlayerTileFocus().Remove(OnPlayerTileFocus);
91  SCR_GroupTileButton.GetOnPlayerTileFocusLost().Remove(OnPlayerTileFocusLost);
92  }
93 
94  //------------------------------------------------------------------------------------------------
95  override void OnTabRemove()
96  {
97  super.OnTabRemove();
98  SCR_GroupsManagerComponent groupManager = SCR_GroupsManagerComponent.GetInstance();
99  if (m_GroupManager)
100  {
101  m_GroupManager.GetOnPlayableGroupRemoved().Remove(UpdateGroupsMenu);
102  m_GroupManager.GetOnPlayableGroupCreated().Remove(UpdateGroupsMenu);
103  }
104 
105  SCR_AIGroup.GetOnPlayerAdded().Remove(UpdateGroupsMenu);
106  SCR_AIGroup.GetOnPlayerRemoved().Remove(UpdateGroupsMenu);
107  SCR_AIGroup.GetOnPlayerLeaderChanged().Remove(UpdateGroupsMenu);
108  SCR_AIGroup.GetOnCustomNameChanged().Remove(UpdateGroupsMenu);
109  SCR_AIGroup.GetOnFlagSelected().Remove(UpdateGroupsMenu);
110  SCR_AIGroup.GetOnCustomDescriptionChanged().Remove(UpdateGroupsMenu);
111  m_PlayerGroupController.GetOnInviteReceived().Remove(SetAcceptButtonStatus);
112 
113  //todo:mku this is a temporary solution because of how playerlist is implemented right now
114  OverlayWidget header = OverlayWidget.Cast(m_wMenuRoot.FindAnyWidget("SortHeader"));
115  if (header)
116  header.SetVisible(true);
117  ScrollLayoutWidget scrollWidget = ScrollLayoutWidget.Cast(m_wMenuRoot.FindAnyWidget("ScrollLayout0"));
118  if (scrollWidget)
119  scrollWidget.SetVisible(true);
120  HorizontalLayoutWidget footerLeft = HorizontalLayoutWidget.Cast(m_wMenuRoot.FindAnyWidget("FooterLeft"));
121  if (footerLeft)
122  footerLeft.SetVisible(true);
123 
124  SCR_GroupTileButton.GetOnPlayerTileFocus().Remove(OnPlayerTileFocus);
125  SCR_GroupTileButton.GetOnPlayerTileFocusLost().Remove(OnPlayerTileFocusLost);
126  }
127 
128  //------------------------------------------------------------------------------------------------
129  protected void CreateNewGroup()
130  {
131  if (!m_PlayerGroupController)
132  return;
133  //we reset the selected group so the menu goes to players actual group, in this case newly created one
134  m_PlayerGroupController.SetSelectedGroupID(-1);
135  m_PlayerGroupController.RequestCreateGroup();
136  }
137 
138  //------------------------------------------------------------------------------------------------
139  protected void JoinSelectedGroup()
140  {
141  if (!m_PlayerGroupController)
142  return;
143  m_PlayerGroupController.RequestJoinGroup(m_PlayerGroupController.GetSelectedGroupID());
144  }
145 
146  //------------------------------------------------------------------------------------------------
147  void AcceptInvite()
148  {
149  m_PlayerGroupController.AcceptInvite();
150  SetAcceptButtonStatus();
151  }
152 
153  //------------------------------------------------------------------------------------------------
154  void SetAcceptButtonStatus()
155  {
156  if (!m_AcceptInviteButton)
157  return;
158 
159  if (m_PlayerGroupController.GetGroupInviteID() == -1)
160  {
161  m_AcceptInviteButton.SetEnabled(false);
162  }
163  else
164  {
165  SCR_AIGroup group = m_GroupManager.FindGroup(m_PlayerGroupController.GetGroupInviteID());
166 
167  if (!group)
168  {
169  m_AcceptInviteButton.SetEnabled(false);
170  m_PlayerGroupController.SetGroupInviteID(-1);
171  return;
172  }
173  m_AcceptInviteButton.SetEnabled(true);
174  }
175  }
176 
177  //------------------------------------------------------------------------------------------------
178  protected void CreateAddGroupButton()
179  {
180  m_AddGroupButton = CreateNavigationButton("MenuAddGroup", CREATE_GROUP, true);
181  if (!m_AddGroupButton)
182  return;
183  m_AddGroupButton.GetRootWidget().SetZOrder(0);
184  m_AddGroupButton.m_OnActivated.Insert(CreateNewGroup);
185  }
186 
187  //------------------------------------------------------------------------------------------------
188  protected void CreateJoinGroupButton()
189  {
190  m_JoinGroupButton = CreateNavigationButton("MenuJoinGroup", JOIN_GROUP, true);
191  if (!m_JoinGroupButton)
192  return;
193  m_JoinGroupButton.GetRootWidget().SetZOrder(0);
194  m_JoinGroupButton.m_OnActivated.Insert(JoinSelectedGroup);
195  }
196 
197  //------------------------------------------------------------------------------------------------
198  protected void CreateAcceptInviteButton()
199  {
200  m_AcceptInviteButton = CreateNavigationButton("GroupAcceptInvite", ACCEPT_INVITE, true);
201  if (!m_AcceptInviteButton)
202  return;
203  m_AcceptInviteButton.GetRootWidget().SetZOrder(0);
204  m_AcceptInviteButton.m_OnActivated.Insert(AcceptInvite);
205  m_PlayerGroupController.GetOnInviteReceived().Insert(SetAcceptButtonStatus);
206  SetAcceptButtonStatus();
207  }
208 
209  //------------------------------------------------------------------------------------------------
210  protected void CreateGroupSettingsButton()
211  {
212  m_GroupSettingsButton = CreateNavigationButton("MenuSettingsGroup", "#AR-Player_Groups_Settings", true, false);
213  if (!m_GroupSettingsButton)
214  return;
215  m_GroupSettingsButton.GetRootWidget().SetZOrder(0);
216  m_GroupSettingsButton.m_OnActivated.Insert(OpenGroupSettingsDialog);
217  }
218 
219  //------------------------------------------------------------------------------------------------
220  protected void CreateViewProfileButton()
221  {
222  m_ViewProfileButton = CreateNavigationButton("MenuViewProfile", "", true);
223  if (!m_ViewProfileButton)
224  return;
225 
226  // Dynamically add the component to update the button label dpending on platform. TODO: allow sub menus to create different layouts of buttons
228  if (!handler)
229  return;
230 
231  m_ViewProfileButton.GetRootWidget().AddHandler(handler);
232  handler.Init();
233 
234  UpdateViewProfileButton(true);
235 
236  m_ViewProfileButton.GetRootWidget().SetZOrder(0);
237  m_ViewProfileButton.m_OnActivated.Insert(OnViewProfile);
238  }
239 
240  //------------------------------------------------------------------------------------------------
241  protected void UpdateViewProfileButton(bool forceHidden = false)
242  {
243  if (!m_ViewProfileButton)
244  return;
245 
246  SetNavigationButtonVisibile(m_ViewProfileButton, !forceHidden && GetGame().GetPlayerManager().IsUserProfileAvailable(m_iLastSelectedPlayerId));
247  }
248 
249  //------------------------------------------------------------------------------------------------
250  protected void OnPlayerTileFocus(int id)
251  {
252  m_iLastSelectedPlayerId = id;
253  UpdateViewProfileButton();
254  }
255 
256  //------------------------------------------------------------------------------------------------
257  protected void OnPlayerTileFocusLost(int id)
258  {
259  UpdateViewProfileButton(true);
260  }
261 
262  //------------------------------------------------------------------------------------------------
263  protected void OnViewProfile()
264  {
265  GetGame().GetPlayerManager().ShowUserProfile(m_iLastSelectedPlayerId);
266  }
267 
268  //------------------------------------------------------------------------------------------------
269  protected void ChangeGroupPublicState()
270  {
271  SCR_PlayerControllerGroupComponent playerComponent = SCR_PlayerControllerGroupComponent.GetLocalPlayerControllerGroupComponent();
272  if (!playerComponent)
273  return;
274  SCR_GroupsManagerComponent groupsManager = SCR_GroupsManagerComponent.GetInstance();
275  if (!groupsManager)
276  return;
277  SCR_AIGroup playerGroup = groupsManager.FindGroup(playerComponent.GetGroupID());
278  playerComponent.RequestPrivateGroupChange(playerComponent.GetPlayerID() , !playerGroup.IsPrivate());
279  }
280 
281  //------------------------------------------------------------------------------------------------
282  protected void OpenGroupSettingsDialog()
283  {
284  GetGame().GetMenuManager().OpenDialog(ChimeraMenuPreset.GroupSettingsDialog);
285  }
286 
287  protected void SetupNameChangeButton()
288  {
289  ButtonWidget nameChangeButton = ButtonWidget.Cast(GetRootWidget().FindAnyWidget("ChangeNameButton"));
290  if (!nameChangeButton)
291  return;
292 
293  SCR_ButtonImageComponent buttonComp = SCR_ButtonImageComponent.Cast(nameChangeButton.FindHandler(SCR_ButtonImageComponent));
294  if (!buttonComp)
295  return;
296 
297  buttonComp.m_OnClicked.Insert(OpenGroupSettingsDialog);
298  }
299 
300  //------------------------------------------------------------------------------------------------
301  protected void SetupPrivateChecker()
302  {
303  ButtonWidget privateChecker = ButtonWidget.Cast(GetRootWidget().FindAnyWidget("PrivateChecker"));
304  if (!privateChecker)
305  return;
306 
307  SCR_ButtonCheckerComponent buttonComp = SCR_ButtonCheckerComponent.Cast(privateChecker.FindHandler(SCR_ButtonCheckerComponent));
308  if (!buttonComp)
309  return;
310 
311  buttonComp.m_OnClicked.Insert(OnPrivateCheckerClicked);
312 
313  }
314 
315  //------------------------------------------------------------------------------------------------
316  protected void OnPrivateCheckerClicked()
317  {
318  SCR_AIGroup group = m_GroupManager.FindGroup(m_PlayerGroupController.GetGroupID());
319  if (!group)
320  return;
321 
322  m_PlayerGroupController.RequestPrivateGroupChange(m_PlayerGroupController.GetPlayerID() , !group.IsPrivate());
323  }
324 };
SCR_PlayerController
Definition: SCR_PlayerController.c:31
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
GetPlayerController
proto external PlayerController GetPlayerController()
Definition: SCR_PlayerDeployMenuHandlerComponent.c:307
GetRootWidget
Widget GetRootWidget()
Definition: SCR_UITaskManagerComponent.c:160
SCR_GroupSubMenuPlayerlist
Definition: SCR_GroupSubMenuPlayerlist.c:1
SCR_GroupSubMenuBase
Definition: SCR_GroupSubMenuBase.c:1
SCR_GroupsManagerComponent
void SCR_GroupsManagerComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
Definition: SCR_GroupsManagerComponent.c:1320
index
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
Definition: SCR_DestructionSynchronizationComponent.c:17
SCR_ButtonCheckerComponent
Definition: SCR_ButtonCheckerComponent.c:2
ChimeraMenuPreset
ChimeraMenuPreset
Menu presets.
Definition: ChimeraMenuBase.c:3
SCR_AIGroup
Definition: SCR_AIGroup.c:68
SCR_ViewProfileButtonComponent
Definition: SCR_ViewProfileButtonComponent.c:2
SCR_ButtonImageComponent
Definition: SCR_ButtonImageComponent.c:2
SCR_GroupTileButton
Definition: SCR_GroupTileButton.c:106
SCR_InputButtonComponent
Definition: SCR_InputButtonComponent.c:1