Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_RoleSelectionMenu.c
Go to the documentation of this file.
3 {
4  protected SCR_DeployMenuHandler m_MenuHandler;
5 
6  protected SCR_FactionRequestUIComponent m_FactionRequestUIHandler;
7  protected SCR_LoadoutRequestUIComponent m_LoadoutRequestUIHandler;
8  protected SCR_GroupRequestUIComponent m_GroupRequestUIHandler;
9 
10  protected SCR_FactionManager m_FactionManager;
11  protected SCR_FactionPlayerList m_FactionPlayerList;
12 
13  protected SCR_BaseGameMode m_GameMode;
14  protected SCR_PlayerFactionAffiliationComponent m_PlyFactionAffilComp;
15  protected SCR_PlayerLoadoutComponent m_PlyLoadoutComp;
16 
17  protected SCR_InputButtonComponent m_ContinueButton;
18  protected SCR_InputButtonComponent m_GroupOpenButton;
19  protected SCR_InputButtonComponent m_ViewProfileButton;
20 
21  protected Widget m_wPersistentFaction;
22  protected TextWidget m_wScenarioTimeElapsed;
23  protected TextWidget m_wPlayerCount;
24  protected TextWidget m_wServerName;
25 
26  protected int m_iMaxPlayerCount;
27  protected float m_fTimer = 0;
28 
29  protected int m_iLastFocusedEntryPlayerId;
30 
31  //------------------------------------------------------------------------------------------------
32  override void OnMenuOpen()
33  {
34  super.OnMenuOpen();
35 
36  m_MapEntity = SCR_MapEntity.GetMapInstance();
37  m_FactionManager = SCR_FactionManager.Cast(GetGame().GetFactionManager());
40 
41  m_wPersistentFaction = GetRootWidget().FindAnyWidget("PermanentFaction");
42  if (m_wPersistentFaction)
43  m_wPersistentFaction.SetVisible(!SCR_RespawnSystemComponent.GetInstance().IsFactionChangeAllowed());
44 
45  m_wScenarioTimeElapsed = TextWidget.Cast(GetRootWidget().FindAnyWidget("TimeElapsed"));
46  m_wServerName = TextWidget.Cast(GetRootWidget().FindAnyWidget("ServerName"));
47  SCR_MissionHeader header = SCR_MissionHeader.Cast(GetGame().GetMissionHeader());
48  if (header)
49  {
50  if (m_wServerName)
51  m_wServerName.SetText(header.m_sName);
52 
53  m_iMaxPlayerCount = header.m_iPlayerCount;
54  }
55 
56  if (!m_MenuHandler)
57  {
58  Print("SCR_DeployMenuHandler is missing on root widget of " + this, LogLevel.ERROR);
59  return;
60  }
61 
62  PlayerController pc = GetGame().GetPlayerController();
64  if (!m_PlyFactionAffilComp)
65  {
66  Print("Cannot find player faction affiliation component!", LogLevel.ERROR);
67  }
68 
70  if (!m_PlyLoadoutComp)
71  {
72  Print("Cannot find player loadout component!", LogLevel.ERROR);
73  }
74 
75  m_wPlayerCount = TextWidget.Cast(GetRootWidget().FindAnyWidget("PlayerCount"));
76  m_FactionPlayerList = m_MenuHandler.GetFactionPlayerList();
77 
78  UpdateElapsedTime();
79  UpdatePlayerCount();
80 
81  FindRequestHandlers();
82  HookEvents();
83 
84  m_ContinueButton = SCR_InputButtonComponent.GetInputButtonComponent("CloseButton", GetRootWidget());
85  if (m_ContinueButton)
86  {
87  m_ContinueButton.m_OnActivated.Insert(Close);
88  m_ContinueButton.SetEnabled(CanContinue());
89  }
90 
91  m_GroupOpenButton = SCR_InputButtonComponent.GetInputButtonComponent("GroupMenu", GetRootWidget());
92  if (m_GroupOpenButton)
93  {
94  m_GroupOpenButton.m_OnActivated.Insert(OpenGroupMenu);
95  m_GroupOpenButton.SetEnabled(CanOpenGroupMenu());
96  }
97 
98  m_ViewProfileButton = SCR_InputButtonComponent.GetInputButtonComponent("ViewProfile", GetRootWidget());
99  if (m_ViewProfileButton)
100  {
101  UpdateViewProfileButton(true);
102  m_ViewProfileButton.m_OnActivated.Insert(OnViewProfile);
103  }
104 
105  Widget chat = GetRootWidget().FindAnyWidget("ChatPanel");
106  if (chat)
107  m_ChatPanel = SCR_ChatPanel.Cast(chat.FindHandler(SCR_ChatPanel));
108 
109  m_ChatButton = SCR_InputButtonComponent.GetInputButtonComponent("ChatButton", GetRootWidget());
110  if (m_ChatButton)
111  m_ChatButton.m_OnActivated.Insert(OnChatToggle);
112 
113  m_PauseButton = SCR_InputButtonComponent.GetInputButtonComponent("PauseButton", GetRootWidget());
114  if (m_PauseButton)
115  m_PauseButton.m_OnActivated.Insert(OnPauseMenu);
116  InitMapPlain();
117  }
118 
119  override void OnMenuOpened()
120  {
121  super.OnMenuOpened();
122 
123  if (m_FactionRequestUIHandler)
124  {
125  SCR_FactionButton btn = SCR_FactionButton.Cast(m_FactionRequestUIHandler.GetFirstValidButton());
126  if (btn)
127  btn.SetFocused();
128  }
129  }
130 
131  override void OnMenuUpdate(float tDelta)
132  {
133  super.OnMenuUpdate(tDelta);
134 
135  GetGame().GetInputManager().ActivateContext("DeployMenuContext");
136 
137  if (m_ChatPanel)
138  m_ChatPanel.OnUpdateChat(tDelta);
139 
140  m_fTimer -= tDelta;
141  if (m_fTimer < 0)
142  UpdateElapsedTime();
143  }
144 
145  override void OnMenuFocusGained()
146  {
147  SCR_EditorManagerEntity editorManager = SCR_EditorManagerEntity.GetInstance();
148  if (editorManager)
149  editorManager.AutoInit();
150 
151  GetGame().GetInputManager().AddActionListener("ShowScoreboard", EActionTrigger.DOWN, OpenPlayerList);
152 
153  super.OnMenuFocusGained();
154  }
155 
156  override void OnMenuFocusLost()
157  {
158  GetGame().GetInputManager().RemoveActionListener("ShowScoreboard", EActionTrigger.DOWN, OpenPlayerList);
159 
160  super.OnMenuFocusLost();
161  }
162 
164  protected void FindRequestHandlers()
165  {
166  m_FactionRequestUIHandler = m_MenuHandler.GetFactionRequestHandler();
167  m_LoadoutRequestUIHandler = m_MenuHandler.GetLoadoutRequestHandler();
168  m_GroupRequestUIHandler = m_MenuHandler.GetGroupRequestHandler();
169  }
170 
172  protected void HookEvents()
173  {
174  m_PlyFactionAffilComp.GetOnPlayerFactionRequestInvoker_O().Insert(OnPlayerFactionRequest);
175  m_PlyFactionAffilComp.GetOnPlayerFactionResponseInvoker_O().Insert(OnPlayerFactionResponse);
176 
177  m_PlyLoadoutComp.GetOnPlayerLoadoutRequestInvoker_O().Insert(OnPlayerLoadoutRequest);
178  m_PlyLoadoutComp.GetOnPlayerLoadoutResponseInvoker_O().Insert(OnPlayerLoadoutResponse);
179 
180  m_FactionRequestUIHandler.GetOnButtonFocused().Insert(ShowFactionPlayerList);
181  m_FactionRequestUIHandler.GetOnFactionRequested().Insert(OnPlayerFactionResponse);
182 
183  m_LoadoutRequestUIHandler.GetOnButtonFocused().Insert(ShowLoadoutList);
184  m_LoadoutRequestUIHandler.GetOnMouseLeft().Insert(OnMouseLeft);
185  m_LoadoutRequestUIHandler.GetOnPlayerEntryFocused().Insert(OnPlayerEntryFocused);
186  m_LoadoutRequestUIHandler.GetOnPlayerEntryFocusLost().Insert(OnPlayerEntryFocusLost);
187 
188  m_GroupRequestUIHandler.GetOnMouseLeft().Insert(OnMouseLeft);
189  m_GroupRequestUIHandler.GetOnButtonFocused().Insert(ShowLoadoutList);
190 
191  m_GroupRequestUIHandler.GetOnPlayerGroupJoined().Insert(OnPlayerGroupJoined);
192  m_GroupRequestUIHandler.GetOnLocalPlayerGroupJoined().Insert(OnLocalGroupJoined);
193  }
194 
196  protected void UpdateElapsedTime()
197  {
198  m_fTimer = 1;
199  string timeElapsed = SCR_FormatHelper.FormatTime(m_GameMode.GetElapsedTime());
200 
201  if (m_wScenarioTimeElapsed)
202  m_wScenarioTimeElapsed.SetText(timeElapsed);
203 
204  UpdatePlayerCount();
205  }
206 
208  protected void InitMapPlain()
209  {
210  ResourceName conf = "{A786DD4868598F15}Configs/Map/MapPlain.conf";
211  m_MapEntity.OpenMap(m_MapEntity.SetupMapConfig(EMapEntityMode.PLAIN, conf, GetRootWidget()));
212  }
213 
214  /*
215  Determine which widget should be shown on the right side of the role selection screen
216  when user hovers their mouse cursor off a button on the left side of the screen.
217  */
218  protected void OnMouseLeft()
219  {
220  bool hasFaction = (m_PlyFactionAffilComp.GetAffiliatedFaction() != null);
221  bool hasGroup = true;
222 
223  if (!hasFaction)
224  {
225  SCR_FactionButton btn = SCR_FactionButton.Cast(m_FactionRequestUIHandler.GetFirstValidButton());
226  ShowFactionPlayerList(btn.GetFaction());
227  return;
228  }
229 
230  ShowLoadoutList();
231  }
232 
234  protected void ShowFactionPlayerList(Faction faction = null)
235  {
236  if (m_FactionPlayerList)
237  {
238  m_FactionPlayerList.SetFaction(faction);
239  m_FactionPlayerList.ShowPlayerList(true);
240  }
241 
242  m_LoadoutRequestUIHandler.ShowLoadoutSelector(false);
243  }
244 
246  protected void ShowLoadoutList()
247  {
248  if (m_FactionPlayerList)
249  m_FactionPlayerList.ShowPlayerList(false);
250 
251  m_LoadoutRequestUIHandler.ShowLoadoutSelector(true);
252  }
253 
255  protected void UpdatePlayerCount()
256  {
257  if (m_iMaxPlayerCount > 0)
258  m_wPlayerCount.SetTextFormat("%1/%2", GetGame().GetPlayerManager().GetPlayerCount().ToString(), m_iMaxPlayerCount);
259  else
260  m_wPlayerCount.SetText(GetGame().GetPlayerManager().GetPlayerCount().ToString());
261  }
262 
264  protected bool CanContinue()
265  {
266  if (!m_PlyFactionAffilComp || !m_PlyLoadoutComp)
267  return false;
268 
269  bool canContinue = m_PlyFactionAffilComp.GetAffiliatedFaction() && m_PlyLoadoutComp.GetLoadout();
270  if (m_GroupRequestUIHandler && m_GroupRequestUIHandler.IsEnabled())
271  {
272  canContinue = canContinue && (m_GroupRequestUIHandler.GetPlayerGroup() != null);
273  }
274 
275  return canContinue;
276  }
277 
279  protected bool CanOpenGroupMenu()
280  {
281  return m_PlyFactionAffilComp && m_PlyFactionAffilComp.GetAffiliatedFaction();
282  }
283 
284  protected void OpenGroupMenu()
285  {
286  GetGame().GetMenuManager().OpenDialog(ChimeraMenuPreset.GroupMenu);
287  }
288 
289  //------------------------------------------------------------------------------------------------
290  protected void OnPlayerFactionRequest(SCR_PlayerFactionAffiliationComponent component, int factionIndex)
291  {
292  }
293 
295  protected void OnPlayerFactionResponse(SCR_PlayerFactionAffiliationComponent component, int factionIndex, bool response)
296  {
297  if (response)
298  {
299  m_FactionRequestUIHandler.OnPlayerFactionAssigned(component.GetAffiliatedFaction());
300  if (factionIndex == -1)
301  {
302  m_GroupRequestUIHandler.SetExpanded(false);
303  m_FactionRequestUIHandler.SetExpanded(false);
304  }
305  else
306  {
307  // If groups are enabled, update them first, otherwise just show players assigned to the faction
308  if (m_GroupRequestUIHandler && m_GroupRequestUIHandler.IsEnabled())
309  {
310  Widget list = m_FactionRequestUIHandler.GetFactionButton(factionIndex).GetList();;
311  m_GroupRequestUIHandler.SetListWidget(list);
312  m_GroupRequestUIHandler.ShowAvailableGroups(component.GetAffiliatedFaction());
313  m_LoadoutRequestUIHandler.ShowAvailableLoadouts(component.GetAffiliatedFaction());
314  }
315  else
316  {
317  Widget list = m_FactionRequestUIHandler.GetFactionButton(factionIndex).GetGridList();
318  m_LoadoutRequestUIHandler.SetListWidget(list);
319  m_LoadoutRequestUIHandler.ShowAvailableLoadouts(component.GetAffiliatedFaction());
320 
321  array<int> players = {};
322  GetGame().GetPlayerManager().GetPlayers(players);
323  foreach (int pid : players)
324  {
325  if (SCR_Faction.Cast(SCR_FactionManager.SGetPlayerFaction(pid)) != component.GetAffiliatedFaction())
326  players.RemoveItem(pid);
327  }
328 
329  m_LoadoutRequestUIHandler.ShowPlayerLoadouts(players);
330  }
331  }
332 
333  m_GroupOpenButton.SetEnabled(CanOpenGroupMenu());
334  m_ContinueButton.SetEnabled(CanContinue());
335  if (m_wPersistentFaction)
336  m_wPersistentFaction.SetVisible(false);
337  }
338 
339  m_FactionRequestUIHandler.Unlock();
340  }
341 
343  protected void OnPlayerGroupJoined(SCR_AIGroup group, int pid = -1)
344  {
345  if (!group || group.GetGroupID() != m_GroupRequestUIHandler.GetShownGroupId())
346  return;
347 
348  SCR_GroupButton groupBtn = m_GroupRequestUIHandler.GetGroupButton(group);
349  if (!groupBtn)
350  return;
351 
352  Widget list = m_GroupRequestUIHandler.GetGroupButton(group).GetList();
353  array<int> players = group.GetPlayerIDs();
354 
355  m_LoadoutRequestUIHandler.SetListWidget(list);
356  m_LoadoutRequestUIHandler.ShowPlayerLoadouts(players, group.GetMaxMembers());
357  }
358 
360  protected void OnLocalGroupJoined(SCR_AIGroup group)
361  {
362  if (!group)
363  {
364  m_LoadoutRequestUIHandler.SetListVisible(false);
365  return;
366  }
367 
368  OnPlayerGroupJoined(group);
369 
370  m_ContinueButton.SetEnabled(CanContinue());
371  }
372 
373  protected void OnPlayerLoadoutRequest(SCR_PlayerLoadoutComponent component, int loadoutIndex)
374  {
375  }
376 
378  protected void OnPlayerLoadoutResponse(SCR_PlayerLoadoutComponent component, int loadoutIndex, bool response)
379  {
380  if (response)
381  {
382  m_LoadoutRequestUIHandler.OnPlayerLoadoutAssigned(component);
383  m_LoadoutRequestUIHandler.SetSelected(component);
384  m_LoadoutRequestUIHandler.RefreshLoadoutPreview();
385  }
386 
387  m_ContinueButton.SetEnabled(CanContinue());
388  m_LoadoutRequestUIHandler.Unlock();
389  }
390 
391  protected void OnChatToggle()
392  {
393  if (!m_ChatPanel)
394  {
395  Widget chat = GetRootWidget().FindAnyWidget("ChatPanel");
396  if (chat)
397  m_ChatPanel = SCR_ChatPanel.Cast(chat.FindHandler(SCR_ChatPanel));
398  }
399 
400  if (!m_ChatPanel || m_ChatPanel.IsOpen())
401  return;
402 
403  SCR_ChatPanelManager.GetInstance().ToggleChatPanel(m_ChatPanel);
404  }
405 
406  protected void OnPauseMenu()
407  {
408  UpdateViewProfileButton(true);
409  GetGame().OpenPauseMenu(false, true);
410  }
411 
412  override void OnMenuClose()
413  {
414  super.OnMenuClose();
415 
416  if (m_MapEntity && m_MapEntity.IsOpen())
417  m_MapEntity.CloseMap();
418  }
419 
420  //------------------------------------------------------------------------------------------------
421  protected void OnPlayerEntryFocused(int id)
422  {
423  m_iLastFocusedEntryPlayerId = id;
424  UpdateViewProfileButton();
425  }
426 
427  //------------------------------------------------------------------------------------------------
428  protected void OnPlayerEntryFocusLost(Widget w)
429  {
430  UpdateViewProfileButton(true);
431  }
432 
433  //------------------------------------------------------------------------------------------------
434  protected void OnViewProfile()
435  {
436  GetGame().GetPlayerManager().ShowUserProfile(m_iLastFocusedEntryPlayerId);
437  }
438 
439  //------------------------------------------------------------------------------------------------
440  protected void UpdateViewProfileButton(bool forceHidden = false)
441  {
442  if (!m_ViewProfileButton)
443  return;
444 
445  m_ViewProfileButton.SetVisible(!forceHidden && GetGame().GetPlayerManager().IsUserProfileAvailable(m_iLastFocusedEntryPlayerId), false);
446  }
447 
448  //------------------------------------------------------------------------------------------------
453  static SCR_RoleSelectionMenu OpenRoleSelectionMenu()
454  {
455  if (!GetRoleSelectionMenu())
456  GetGame().GetMenuManager().OpenMenu(ChimeraMenuPreset.RoleSelectionDialog);
457 
458  return GetRoleSelectionMenu();
459  }
460 
462  static void CloseRoleSelectionMenu()
463  {
464  GetGame().GetMenuManager().CloseMenuByPreset(ChimeraMenuPreset.RoleSelectionDialog);
465  }
466 
471  static SCR_RoleSelectionMenu GetRoleSelectionMenu()
472  {
473  return SCR_RoleSelectionMenu.Cast(GetGame().GetMenuManager().FindMenuByPreset(ChimeraMenuPreset.RoleSelectionDialog));
474  }
475 };
SCR_PlayerLoadoutComponent
Definition: SCR_PlayerLoadoutComponent.c:16
SCR_LoadoutRequestUIComponent
Component responsible for requesting and visualization of available loadouts in deploy menu.
Definition: SCR_LoadoutRequestUIComponent.c:2
m_GroupOpenButton
protected SCR_InputButtonComponent m_GroupOpenButton
Definition: SCR_DeployMenuBase.c:150
SCR_BaseGameMode
Definition: SCR_BaseGameMode.c:137
m_MapEntity
protected SCR_MapEntity m_MapEntity
Definition: SCR_MapGadgetComponent.c:14
m_LoadoutRequestUIHandler
protected SCR_LoadoutRequestUIComponent m_LoadoutRequestUIHandler
Definition: SCR_DeployMenuBase.c:104
SCR_FormatHelper
Definition: SCR_FormatHelper.c:1
SCR_FactionPlayerList
Definition: SCR_FactionPlayerList.c:57
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SCR_ChatPanelManager
Definition: SCR_ChatPanelManager.c:12
SCR_DeployMenuHandler
Definition: SCR_DeployMenuHandler.c:6
conf
Configs ServerBrowser KickDialogs conf
Definition: SCR_NotificationSenderComponent.c:23
m_fTimer
protected float m_fTimer
Definition: SCR_CampaignMilitaryBaseComponent.c:94
m_PlyFactionAffilComp
protected SCR_PlayerFactionAffiliationComponent m_PlyFactionAffilComp
Definition: SCR_DeployMenuBase.c:119
GetRootWidget
Widget GetRootWidget()
Definition: SCR_UITaskManagerComponent.c:160
GetGameMode
SCR_BaseGameMode GetGameMode()
Definition: SCR_BaseGameModeComponent.c:15
m_PlyLoadoutComp
protected SCR_PlayerLoadoutComponent m_PlyLoadoutComp
Definition: SCR_DeployMenuBase.c:121
m_FactionManager
protected SCR_FactionManager m_FactionManager
Definition: SCR_NotificationSenderComponent.c:28
SCR_ChatPanel
Definition: SCR_ChatPanel.c:6
SCR_RoleSelectionMenu
Role selection menu for setting up player faction, group and loadout.
Definition: SCR_RoleSelectionMenu.c:2
SCR_DeployMenuBase
Base deploy menu class.
Definition: SCR_DeployMenuBase.c:3
m_GameMode
protected SCR_BaseGameMode m_GameMode
Definition: SCR_DeployMenuBase.c:111
SCR_MapEntity
Map entity.
Definition: SCR_MapEntity.c:20
SCR_FactionButton
Definition: SCR_FactionRequestUIComponent.c:249
Faction
Definition: Faction.c:12
SCR_PlayerFactionAffiliationComponent
Definition: SCR_PlayerFactionAffiliationComponent.c:16
SCR_GroupRequestUIComponent
Component responsible for handling group requests and visualization in deploy menu.
Definition: SCR_GroupRequestUIComponent.c:3
ChimeraMenuPreset
ChimeraMenuPreset
Menu presets.
Definition: ChimeraMenuBase.c:3
SCR_AIGroup
Definition: SCR_AIGroup.c:68
SCR_FactionRequestUIComponent
Definition: SCR_FactionRequestUIComponent.c:5
m_MenuHandler
SCR_DeployMenuBase m_MenuHandler
Main deploy menu with the map present.
SCR_FactionManager
void SCR_FactionManager(IEntitySource src, IEntity parent)
Definition: SCR_FactionManager.c:461
EMapEntityMode
EMapEntityMode
Mode of the map.
Definition: SCR_MapConstants.c:28
GetPlayerCount
int GetPlayerCount()
Definition: SCR_Faction.c:365
SCR_Faction
Definition: SCR_Faction.c:6
m_GroupRequestUIHandler
protected SCR_GroupRequestUIComponent m_GroupRequestUIHandler
Definition: SCR_DeployMenuBase.c:105
SCR_MissionHeader
Definition: SCR_MissionHeader.c:1
SCR_InputButtonComponent
Definition: SCR_InputButtonComponent.c:1
SCR_GroupButton
Component attached to the group button.
Definition: SCR_GroupRequestUIComponent.c:484
SCR_EditorManagerEntity
Definition: SCR_EditorManagerEntity.c:26