Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_GroupSubMenu.c
Go to the documentation of this file.
2 {
3  protected Faction m_PlayerFaction;
4  protected SCR_ChatPanel m_ChatPanelComponent;
5  protected static SCR_PlayerControllerGroupComponent s_PlayerGroupController;
6 
7  protected static ref ScriptInvoker s_OnJoinGroupRequestSent;
8 
9  //------------------------------------------------------------------------------------------------
10  override void OnTabCreate(Widget menuRoot, ResourceName buttonsLayout, int index)
11  {
12  super.OnTabCreate(menuRoot, buttonsLayout, index);
13 
14  m_GroupManager = SCR_GroupsManagerComponent.GetInstance();
15  CreateAddGroupButton();
16  CreateJoinGroupButton();
17  CreateAcceptInviteButton();
18  CreateGroupSettingsButton();
19  SetupNameChangeButton();
20  SetupPrivateChecker();
21 
22  SCR_FactionManager factionManager = SCR_FactionManager.Cast(GetGame().GetFactionManager());
23  if (factionManager)
24  m_PlayerFaction = SCR_Faction.Cast(factionManager.GetLocalPlayerFaction());
25  else
26  m_PlayerFaction = null;
27 
28  Widget chatPanel = menuRoot.FindAnyWidget("ChatPanel");
29  if (!chatPanel)
30  return;
31 
32  m_ChatPanelComponent = SCR_ChatPanel.Cast(chatPanel.FindHandler(SCR_ChatPanel));
33  }
34 
35  //------------------------------------------------------------------------------------------------
36  override void OnTabShow()
37  {
38  super.OnTabShow();
39 
40  UpdateGroupsMenu();
41 
42  if (m_ChatPanelComponent)
43  {
44  m_ChatPanelComponent.GetOnChatOpen().Insert(OnChatOpen);
45  m_ChatPanelComponent.GetOnChatClosed().Insert(OnChatClosed);
46  if (m_ChatPanelComponent.IsOpen())
47  OnChatOpen();
48 
49  if (m_ChatPanelComponent.GetFadeOut() == false)
50  {
51  Widget chatContent = m_wMenuRoot.FindAnyWidget("ChatContent");
52  if (chatContent)
53  chatContent.SetVisible(true);
54 
55  SCR_FadeInOutAnimator chatAnimator = m_ChatPanelComponent.GetFadeInOutAnimator();
56  if (chatAnimator)
57  chatAnimator.GetOnStateChanged().Insert(OnAnimatorStateChanged);
58  }
59  }
60 
61  m_GroupManager.GetOnPlayableGroupRemoved().Insert(UpdateGroupsMenu);
62  m_GroupManager.GetOnPlayableGroupCreated().Insert(UpdateGroupsMenu);
63  m_GroupManager.GetOnNewGroupsAllowedChanged().Insert(UpdateGroupsMenu);
64  SCR_AIGroup.GetOnPlayerAdded().Insert(UpdateGroupsMenu);
65  SCR_AIGroup.GetOnPlayerRemoved().Insert(UpdateGroupsMenu);
66  SCR_AIGroup.GetOnPlayerLeaderChanged().Insert(UpdateGroupsMenu);
67  SCR_AIGroup.GetOnPrivateGroupChanged().Insert(UpdateGroupsMenu);
68  SCR_AIGroup.GetOnCustomNameChanged().Insert(UpdateGroupsMenu);
69  SCR_AIGroup.GetOnCustomDescriptionChanged().Insert(UpdateGroupsMenu);
70  SCR_AIGroup.GetOnFlagSelected().Insert(UpdateGroupsMenu);
71  SCR_AIGroup.GetOnFrequencyChanged().Insert(UpdateGroupsMenu);
72  SCR_GroupTileButton.GetOnGroupTileClicked().Insert(UpdateGroupsMenu);
73  SetAcceptButtonStatus();
74  }
75 
76  static void Init()
77  {
78  if (!s_PlayerGroupController)
79  s_PlayerGroupController = SCR_PlayerControllerGroupComponent.GetLocalPlayerControllerGroupComponent();
80  }
81 
82  //------------------------------------------------------------------------------------------------
83  static ScriptInvoker GetOnJoingGroupRequestSent()
84  {
85  if (!s_OnJoinGroupRequestSent)
86  s_OnJoinGroupRequestSent = new ScriptInvoker();
87 
88  return s_OnJoinGroupRequestSent;
89  }
90 
91  //------------------------------------------------------------------------------------------------
92  void UpdateGroupsMenu()
93  {
94  m_wGridWidget = m_wMenuRoot.FindAnyWidget("GroupList");
95  if (!m_wGridWidget || !m_AddGroupButton || !m_ButtonLayout || !m_GroupSettingsButton)
96  return;
97 
98  SetAcceptButtonStatus();
99  InitGroups(s_PlayerGroupController);
100 
101  SCR_GroupMenu groupMenu = SCR_GroupMenu.Cast(m_wMenuRoot.FindHandler(SCR_GroupMenu));
102  if (!groupMenu)
103  return;
104 
105  groupMenu.UpdateTabs();
106  }
107 
108  //------------------------------------------------------------------------------------------------
109  override void OnTabHide()
110  {
111  super.OnTabHide();
112 
113  m_GroupManager = SCR_GroupsManagerComponent.GetInstance();
114  if (m_GroupManager)
115  {
116  m_GroupManager.GetOnPlayableGroupRemoved().Remove(UpdateGroupsMenu);
117  m_GroupManager.GetOnPlayableGroupCreated().Remove(UpdateGroupsMenu);
118  m_GroupManager.GetOnNewGroupsAllowedChanged().Remove(UpdateGroupsMenu);
119  }
120 
121  if (m_ChatPanelComponent)
122  {
123  m_ChatPanelComponent.GetOnChatOpen().Remove(OnChatOpen);
124  m_ChatPanelComponent.GetOnChatClosed().Remove(OnChatClosed);
125  }
126 
127  SCR_AIGroup.GetOnPlayerAdded().Remove(UpdateGroupsMenu);
128  SCR_AIGroup.GetOnPlayerRemoved().Remove(UpdateGroupsMenu);
129  SCR_AIGroup.GetOnPlayerLeaderChanged().Remove(UpdateGroupsMenu);
130  SCR_AIGroup.GetOnPrivateGroupChanged().Remove(UpdateGroupsMenu);
131  SCR_AIGroup.GetOnCustomNameChanged().Remove(UpdateGroupsMenu);
132  SCR_AIGroup.GetOnCustomDescriptionChanged().Remove(UpdateGroupsMenu);
133  SCR_AIGroup.GetOnFlagSelected().Remove(UpdateGroupsMenu);
134  SCR_AIGroup.GetOnFrequencyChanged().Remove(UpdateGroupsMenu);
135  SCR_GroupTileButton.GetOnGroupTileClicked().Remove(UpdateGroupsMenu);
136  if (s_PlayerGroupController)
137  s_PlayerGroupController.GetOnInviteReceived().Remove(SetAcceptButtonStatus);
138 
139  SetNavigationButtonVisibile(m_GroupSettingsButton, false);
140  }
141 
142  //------------------------------------------------------------------------------------------------
143  protected void CreateAddGroupButton()
144  {
145  m_AddGroupButton = CreateNavigationButton("MenuAddGroup", CREATE_GROUP, true);
146  if (!m_AddGroupButton)
147  return;
148  m_AddGroupButton.GetRootWidget().SetZOrder(0);
149  m_AddGroupButton.m_OnActivated.Insert(CreateNewGroup);
150  }
151 
152  //------------------------------------------------------------------------------------------------
153  protected void CreateJoinGroupButton()
154  {
155  m_JoinGroupButton = CreateNavigationButton("MenuJoinGroup", JOIN_GROUP, true);
156  if (!m_JoinGroupButton)
157  return;
158  m_JoinGroupButton.GetRootWidget().SetZOrder(0);
159  m_JoinGroupButton.m_OnActivated.Insert(JoinSelectedGroup);
160  }
161 
162  //------------------------------------------------------------------------------------------------
163  protected void CreateAcceptInviteButton()
164  {
165  m_AcceptInviteButton = CreateNavigationButton("GroupAcceptInvite", ACCEPT_INVITE, true);
166  if (!m_AcceptInviteButton)
167  return;
168  m_AcceptInviteButton.GetRootWidget().SetZOrder(0);
169  m_AcceptInviteButton.m_OnActivated.Insert(AcceptInvite);
170  s_PlayerGroupController.GetOnInviteReceived().Insert(SetAcceptButtonStatus);
171  SetAcceptButtonStatus()
172  }
173 
174  //------------------------------------------------------------------------------------------------
175  protected void CreateGroupSettingsButton()
176  {
177  m_GroupSettingsButton = CreateNavigationButton("MenuSettingsGroup", "#AR-Player_Groups_Settings", true, false);
178  if (!m_GroupSettingsButton)
179  return;
180  m_GroupSettingsButton.GetRootWidget().SetZOrder(0);
181  m_GroupSettingsButton.m_OnActivated.Insert(OpenGroupSettingsDialog);
182  }
183 
184  //------------------------------------------------------------------------------------------------
185  protected void ChangeGroupPublicState()
186  {
187  SCR_PlayerControllerGroupComponent playerComponent = SCR_PlayerControllerGroupComponent.GetLocalPlayerControllerGroupComponent();
188  if (!playerComponent)
189  return;
190  SCR_GroupsManagerComponent groupsManager = SCR_GroupsManagerComponent.GetInstance();
191  if (!groupsManager)
192  return;
193  SCR_AIGroup playerGroup = groupsManager.FindGroup(playerComponent.GetGroupID());
194  playerComponent.RequestPrivateGroupChange(playerComponent.GetPlayerID() , !playerGroup.IsPrivate());
195  }
196 
197  //------------------------------------------------------------------------------------------------
198  protected void OpenGroupSettingsDialog()
199  {
200  GetGame().GetMenuManager().OpenDialog(ChimeraMenuPreset.GroupSettingsDialog);
201  }
202 
203  //------------------------------------------------------------------------------------------------
204  protected static void CreateNewGroup()
205  {
206  if (!s_PlayerGroupController)
207  return;
208  //we reset the actual group so the menu goes to players actual group, in this case newly created one
209  s_PlayerGroupController.SetSelectedGroupID(-1);
210  s_PlayerGroupController.RequestCreateGroup();
211  }
212 
213  //------------------------------------------------------------------------------------------------
214  static void JoinSelectedGroup()
215  {
216  if (!s_PlayerGroupController)
217  return;
218 
219  s_PlayerGroupController.RequestJoinGroup(s_PlayerGroupController.GetSelectedGroupID());
220  }
221 
222  //------------------------------------------------------------------------------------------------
223  static void RequestJoinPrivateGroup()
224  {
225  SCR_GroupsManagerComponent groupManager = SCR_GroupsManagerComponent.GetInstance();
226 
227  SCR_AIGroup group = groupManager.FindGroup(s_PlayerGroupController.GetSelectedGroupID());
228  if (!group)
229  return;
230 
231  if (s_PlayerGroupController)
232  {
233  s_PlayerGroupController.PlayerRequestToJoinPrivateGroup(s_PlayerGroupController.GetPlayerID(), Replication.FindId(group));
234  SCR_NotificationsComponent.SendToPlayer(s_PlayerGroupController.GetPlayerID(), ENotification.GROUPS_REQUEST_SENT, group.GetGroupID());
235  if (s_OnJoinGroupRequestSent)
236  GetOnJoingGroupRequestSent().Invoke();
237  }
238  }
239 
240  //------------------------------------------------------------------------------------------------
241  static void SetSelectedGroup(int groupID)
242  {
243  s_PlayerGroupController.SetSelectedGroupID(groupID);
244  }
245 
246  //------------------------------------------------------------------------------------------------
247  void AcceptInvite()
248  {
249  s_PlayerGroupController.AcceptInvite();
250  SetAcceptButtonStatus();
251  }
252 
253  //------------------------------------------------------------------------------------------------
254  void SetAcceptButtonStatus()
255  {
256  if (s_PlayerGroupController.GetGroupInviteID() == -1)
257  {
258  m_AcceptInviteButton.SetEnabled(false);
259  }
260  else
261  {
262  SCR_AIGroup group = m_GroupManager.FindGroup(s_PlayerGroupController.GetGroupInviteID());
263 
264  if (!group)
265  {
266  m_AcceptInviteButton.SetEnabled(false);
267  s_PlayerGroupController.SetGroupInviteID(-1);
268  return;
269  }
270  m_AcceptInviteButton.SetEnabled(true);
271  }
272  }
273 
274  //------------------------------------------------------------------------------------------------
275  private void OnConfirm()
276  {
277  //dont assign group if player already has one
278  if (s_PlayerGroupController.GetGroupID() != -1)
279  return;
280 
281  SCR_AIGroup newPlayerGroup = m_GroupManager.GetFirstNotFullForFaction(m_PlayerFaction, null, true);
282  if (!newPlayerGroup)
283  {
284  //we return here, because creationg of the group automatically moves player to the group
285  s_PlayerGroupController.RequestCreateGroup();
286  return;
287  }
288  s_PlayerGroupController.RequestJoinGroup(newPlayerGroup.GetGroupID());
289  }
290 
291  //------------------------------------------------------------------------------------------------
292  protected void OnChatOpen()
293  {
294  Widget chatContent = m_wMenuRoot.FindAnyWidget("ChatContent");
295  if (chatContent)
296  chatContent.SetVisible(true);
297  }
298 
299  //------------------------------------------------------------------------------------------------
300  protected void OnChatClosed()
301  {
302  if (SCR_ChatPanelManager.GetInstance().GetMessages().Count() == 0)
303  {
304  Widget chatContent = m_wMenuRoot.FindAnyWidget("ChatContent");
305  if (chatContent)
306  chatContent.SetVisible(false);
307  return;
308  }
309  SCR_FadeInOutAnimator chatAnimator = m_ChatPanelComponent.GetFadeInOutAnimator();
310  if (!chatAnimator)
311  return;
312  chatAnimator.GetOnStateChanged().Insert(OnAnimatorStateChanged);
313  }
314 
315  //------------------------------------------------------------------------------------------------
316  protected void OnAnimatorStateChanged(int formerState, int actualState)
317  {
318  if (formerState == 2 && actualState == 3)
319  {
320  Widget chatContent = m_wMenuRoot.FindAnyWidget("ChatContent");
321  if (chatContent)
322  chatContent.SetVisible(false);
323  m_ChatPanelComponent.GetFadeInOutAnimator().GetOnStateChanged().Remove(OnAnimatorStateChanged);
324  }
325  }
326 
327  //------------------------------------------------------------------------------------------------
328  protected void SetupNameChangeButton()
329  {
330  ButtonWidget nameChangeButton = ButtonWidget.Cast(GetRootWidget().FindAnyWidget("ChangeNameButton"));
331  if (!nameChangeButton)
332  return;
333 
334  SCR_ButtonImageComponent buttonComp = SCR_ButtonImageComponent.Cast(nameChangeButton.FindHandler(SCR_ButtonImageComponent));
335  if (!buttonComp)
336  return;
337 
338  buttonComp.m_OnClicked.Insert(OpenGroupSettingsDialog);
339  }
340 
341  //------------------------------------------------------------------------------------------------
342  protected void SetupPrivateChecker()
343  {
344  ButtonWidget privateChecker = ButtonWidget.Cast(GetRootWidget().FindAnyWidget("PrivateChecker"));
345  if (!privateChecker)
346  return;
347 
348  SCR_ButtonCheckerComponent buttonComp = SCR_ButtonCheckerComponent.Cast(privateChecker.FindHandler(SCR_ButtonCheckerComponent));
349  if (!buttonComp)
350  return;
351 
352  buttonComp.m_OnClicked.Insert(OnPrivateCheckerClicked);
353  }
354 
355  //------------------------------------------------------------------------------------------------
356  protected void OnPrivateCheckerClicked()
357  {
358  SCR_AIGroup group = m_GroupManager.FindGroup(s_PlayerGroupController.GetGroupID());
359  if (!group)
360  return;
361 
362  s_PlayerGroupController.RequestPrivateGroupChange(s_PlayerGroupController.GetPlayerID() , !group.IsPrivate());
363  }
364 
365  //------------------------------------------------------------------------------------------------
366  // In case the method was called from playerlist while skipping deployscreen try to get the group controller
367  static void UpdatePlayerGroupController()
368  {
369  if (!s_PlayerGroupController)
370  s_PlayerGroupController = SCR_PlayerControllerGroupComponent.GetLocalPlayerControllerGroupComponent();
371  }
372 }
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
m_PlayerFaction
protected SCR_CampaignFaction m_PlayerFaction
Definition: SCR_CampaignFastTravelComponent.c:44
SCR_ChatPanelManager
Definition: SCR_ChatPanelManager.c:12
SCR_GroupMenu
Definition: SCR_GroupMenu.c:1
GetRootWidget
Widget GetRootWidget()
Definition: SCR_UITaskManagerComponent.c:160
ENotification
ENotification
Definition: ENotification.c:4
SCR_GroupSubMenu
Definition: SCR_GroupSubMenu.c:1
SCR_ChatPanel
Definition: SCR_ChatPanel.c:6
SCR_FadeInOutAnimator
Definition: SCR_FadeInOutAnimator.c:8
SCR_GroupSubMenuBase
Definition: SCR_GroupSubMenuBase.c:1
Faction
Definition: Faction.c:12
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_FactionManager
void SCR_FactionManager(IEntitySource src, IEntity parent)
Definition: SCR_FactionManager.c:461
SCR_ButtonImageComponent
Definition: SCR_ButtonImageComponent.c:2
SCR_Faction
Definition: SCR_Faction.c:6
SCR_GroupTileButton
Definition: SCR_GroupTileButton.c:106