Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
MainMenuUI.c
Go to the documentation of this file.
2 {
3  protected SCR_MenuTileComponent m_FocusedTile;
4  protected DialogUI m_BannedDetectionDialog;
5 
6  protected ref array<string> m_aBannedItems = {};
7  protected static ref array<ref SCR_NewsEntry> m_aNews = {};
8  protected static ref array<ref SCR_NewsEntry> m_aNotifications = {};
9  protected ref array<ref Widget> m_aTiles = {};
10 
11  protected static bool s_bDidCheckNetwork;
12  protected static const int SERVICES_STATUS_CHECK_DELAY = 2000; // needed for backend API to prepare
13  protected bool m_bFirstLoad;
14 
15 
16 
17  //------------------------------------------------------------------------------------------------
18  protected override void OnMenuOpen()
19  {
20  super.OnMenuOpen();
21 
22  // Init common Workshop UI
23  SCR_WorkshopUiCommon.OnGameStart();
24 
25  Widget w = GetRootWidget();
26  Widget content = w.FindAnyWidget("Grid");
27  Widget descriptionRoot = w.FindAnyWidget("Description");
28  Widget footer = w.FindAnyWidget("Footer");
29  if (!content || !descriptionRoot || !footer)
30  return;
31 
32  // Listen to buttons in grid
33  Widget child = content.GetChildren();
34  while (child)
35  {
37  if (!tile)
38  break;
39 
40  if (!m_FocusedTile)
41  m_FocusedTile = tile;
42 
43  tile.m_OnClicked.Insert(OnTileClick);
44  tile.m_OnFocused.Insert(OnTileFocus);
45  child = child.GetSibling();
46  }
47 
48  // Subscribe to buttons
49  SCR_InputButtonComponent back = SCR_InputButtonComponent.GetInputButtonComponent("Back", footer);
50  if (back)
51  back.m_OnActivated.Insert(OnBack);
52 
53  // Services Status button
54  SCR_InputButtonComponent servicesStatus = SCR_InputButtonComponent.GetInputButtonComponent("ServicesStatus", footer);
55  if (servicesStatus)
56  servicesStatus.m_OnActivated.Insert(OnServicesStatus);
57 
58  SCR_InputButtonComponent feedback = SCR_InputButtonComponent.GetInputButtonComponent("Feedback", footer);
59  if (feedback)
60  feedback.m_OnActivated.Insert(OnFeedback);
61 
62  SCR_InputButtonComponent credits = SCR_InputButtonComponent.GetInputButtonComponent("Credits", footer);
63  if (credits)
64  credits.m_OnActivated.Insert(OnCredits);
65 
66  #ifdef WORKBENCH
67  GetGame().GetInputManager().AddActionListener("MenuBackWB", EActionTrigger.DOWN, OnBack);
68  #endif
69 
70  // Get the entries for the first time
71  GetNewsEntries(null);
72  GetNotificationEntries(null);
73 
74  // Check Service Statuses
75  if (!s_bDidCheckNetwork)
76  {
77  s_bDidCheckNetwork = true;
78  GetGame().GetCallqueue().CallLater(CheckServicesStatusIfFocused, SERVICES_STATUS_CHECK_DELAY);
79  }
80 
81  Widget logoWidget = w.FindAnyWidget("LogoButton");
82  if (logoWidget)
83  {
84  SCR_ModularButtonComponent logo = SCR_ModularButtonComponent.FindComponent(logoWidget);
85  if (logo)
86  logo.m_OnClicked.Insert(OnLogoClicked);
87  }
88 
89  // Check ping sites
90  GetGame().GetBackendApi().GetClientLobby().MeasureLatency(null);
91  }
92 
93  //------------------------------------------------------------------------------------------------
94  protected override void OnMenuOpened()
95  {
96  super.OnMenuOpened();
97 
98  // Opening Last menu
99  SCR_MenuLoadingComponent.LoadLastMenu();
100  SCR_MenuLoadingComponent.ClearLastMenu();
101 
102  BaseContainer cont = GetGame().GetGameUserSettings().GetModule("SCR_RecentGames");
103  if (cont)
104  {
105  cont.Get("m_bFirstTimePlay", m_bFirstLoad);
106  cont.Set("m_bFirstTimePlay", false);
107  }
108 
109  //PrintFormat("[OnMenuOpened] m_bFirstLoad: %1", m_bFirstLoad);
110 
111  // Save changes to the settings
112  GetGame().UserSettingsChanged();
113  GetGame().SaveUserSettings();
114 
115  // Check first start of session
116  bool firstLoadInSession = GameSessionStorage.s_Data["m_bMenuFirstOpening"].IsEmpty();
117  GameSessionStorage.s_Data["m_bMenuFirstOpening"] = "false";
118 
119  //PrintFormat("[OnMenuOpened] firstLoadInSession: %1", firstLoadInSession);
120 
121  if (!firstLoadInSession)
122  return;
123 
124  if (!m_bFirstLoad)
125  return;
126 
127  GetGame().GetMenuManager().OpenDialog(ChimeraMenuPreset.WelcomeDialog);
128  }
129 
130  //------------------------------------------------------------------------------------------------
131  protected override void OnMenuFocusLost()
132  {
133  GetRootWidget().SetEnabled(false);
134 
135  super.OnMenuFocusLost();
136  }
137 
138  //------------------------------------------------------------------------------------------------
139  protected override void OnMenuFocusGained()
140  {
141  GetRootWidget().SetEnabled(true);
142 
143  if (m_FocusedTile)
144  GetGame().GetWorkspace().SetFocusedWidget(m_FocusedTile.GetRootWidget(), true);
145 
146  super.OnMenuFocusGained();
147  }
148 
149  //------------------------------------------------------------------------------------------------
150  protected void OnBack()
151  {
152  if (!IsFocused())
153  return;
154 
155  TryExitGame();
156  }
157 
158  //------------------------------------------------------------------------------------------------
159  protected void OnCredits()
160  {
161  GetGame().GetMenuManager().OpenMenu(ChimeraMenuPreset.CreditsMenu);
162  }
163 
164  //------------------------------------------------------------------------------------------------
165  protected void OnTileClick(notnull SCR_MenuTileComponent comp)
166  {
167  if (!IsFocused())
168  return;
169 
170  ChimeraMenuPreset preset = comp.m_eMenuPreset;
171  if (preset == ChimeraMenuPreset.FeedbackDialog)
172  GetGame().GetMenuManager().OpenDialog(preset);
173  else if (preset == ChimeraMenuPreset.ContentBrowser)
174  SCR_WorkshopUiCommon.TryOpenWorkshop();
175  else
176  GetGame().GetMenuManager().OpenMenu(preset);
177  }
178 
179  //------------------------------------------------------------------------------------------------
180  protected void OnTileFocus(SCR_MenuTileComponent comp)
181  {
182  if (!IsFocused())
183  return;
184 
185  m_FocusedTile = comp;
186  }
187 
188  //------------------------------------------------------------------------------------------------
189  protected void OnButtonSelect()
190  {
191  if (!IsFocused())
192  return;
193 
194  if (m_FocusedTile)
195  OnTileClick(m_FocusedTile);
196  }
197 
198  //------------------------------------------------------------------------------------------------
199  void OnServicesStatus()
200  {
201  if (!IsFocused())
202  return;
203 
204  SCR_CommonDialogs.CreateServicesStatusDialog();
205  }
206 
207  //------------------------------------------------------------------------------------------------
208  protected void OnFeedback()
209  {
210  if (!IsFocused())
211  return;
212 
213  GetGame().GetMenuManager().OpenDialog(ChimeraMenuPreset.FeedbackDialog);
214  }
215 
216  //------------------------------------------------------------------------------------------------
217  protected void OnLogoClicked()
218  {
219  GetGame().GetMenuManager().OpenDialog(ChimeraMenuPreset.WelcomeDialog);
220  }
221 
222  //------------------------------------------------------------------------------------------------
223  protected void RestoreFocus()
224  {
225  if (m_FocusedTile)
226  GetGame().GetWorkspace().SetFocusedWidget(m_FocusedTile.GetRootWidget());
227  }
228 
229  //------------------------------------------------------------------------------------------------
230  static int GetNewsEntries(out array<ref SCR_NewsEntry> entries = null)
231  {
232  if (entries)
233  entries.Clear();
234 
235  m_aNews.Clear();
236 
237  // Print( "NEWS: Count - " + GetGame().GetBackendApi().GetNewsCount() );
238  for (int i, cnt = GetGame().GetBackendApi().GetNewsCount(); i < cnt; i++)
239  {
240  NewsFeedItem item = GetGame().GetBackendApi().GetNewsItem(i);
241  if (item)
242  m_aNews.Insert(new SCR_NewsEntry(item));
243  }
244 
245  if (entries)
246  entries = m_aNews;
247 
248  return m_aNews.Count();
249  }
250 
251  //------------------------------------------------------------------------------------------------
252  static int GetNotificationEntries(out array<ref SCR_NewsEntry> entries = null)
253  {
254  if (entries)
255  entries.Clear();
256 
257  m_aNotifications.Clear();
258 
259  //Print( "NOTIFICATIONS: Count - " + GetGame().GetBackendApi().GetNotifyCount() );
260  for (int i, cnt = GetGame().GetBackendApi().GetNotifyCount(); i < cnt; i++)
261  {
262  NewsFeedItem item = GetGame().GetBackendApi().GetNotifyItem(i);
263  if (item)
264  m_aNews.Insert(new SCR_NewsEntry(item));
265  }
266 
267  if (entries)
268  entries = m_aNotifications;
269 
270  return m_aNotifications.Count();
271  }
272 
273  //------------------------------------------------------------------------------------------------
274  static int GetUnreadNewsCount()
275  {
276  int count;
277  foreach (SCR_NewsEntry entry : m_aNews)
278  {
279  if (!entry.m_bRead)
280  count++;
281  }
282  return count;
283  }
284 
285  //------------------------------------------------------------------------------------------------
286  static int GetUnreadNotificationCount()
287  {
288  int count;
289  foreach (SCR_NewsEntry entry : m_aNotifications)
290  {
291  if (!entry.m_bRead)
292  count++;
293  }
294  return count;
295  }
296 
297  //------------------------------------------------------------------------------------------------
300  protected static void TryExitGame()
301  {
302  int nCompleted, nTotal;
303  SCR_DownloadManager mgr = SCR_DownloadManager.GetInstance();
304  if (mgr)
305  mgr.GetDownloadQueueState(nCompleted, nTotal);
306 
307  if (nTotal > 0)
309  else
310  new SCR_ExitGameDialog();
311  }
312 
313  //------------------------------------------------------------------------------------------------
315  protected void CheckServicesStatusIfFocused()
316  {
317  if (!IsFocused())
318  return;
319 
320  SCR_ServicesStatusDialogUI.OpenIfServicesAreNotOK();
321  }
322 }
ChimeraMenuBase
Constant variables used in various menus.
Definition: ChimeraMenuBase.c:70
SCR_MenuTileComponent
Definition: SCR_MenuTileComponent.c:1
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SCR_CommonDialogs
Definition: CommonDialogs.c:5
SCR_ExitGameDialog
class SCR_CommonDialogs SCR_ExitGameDialog()
Definition: CommonDialogs.c:72
GetRootWidget
Widget GetRootWidget()
Definition: SCR_UITaskManagerComponent.c:160
SCR_ExitGameWhileDownloadingDialog
Definition: CommonDialogs.c:85
SCR_NewsEntry
Definition: SCR_NewsSubMenu.c:2
SCR_NewsEntry
void SCR_NewsEntry(NewsFeedItem item)
Definition: SCR_NewsSubMenu.c:7
MainMenuUI
Definition: MainMenuUI.c:1
DialogUI
Definition: DialogUI.c:1
SCR_ServicesStatusDialogUI
Definition: SCR_ServicesStatusDialogUI.c:8
ChimeraMenuPreset
ChimeraMenuPreset
Menu presets.
Definition: ChimeraMenuBase.c:3
SCR_WorkshopUiCommon
Definition: SCR_WorkshopUiCommon.c:5
m_bFirstLoad
protected bool m_bFirstLoad
Definition: SCR_ContentBrowser_AddonsSubMenu.c:72
SCR_DownloadManager
Definition: SCR_DownloadManager.c:20
SCR_InputButtonComponent
Definition: SCR_InputButtonComponent.c:1