Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_PlayMenu.c
Go to the documentation of this file.
7
8class SCR_PlayMenuEntry : Managed
9{
12
18}
19
21{
22 protected ResourceName m_sConfig = "{6409EA8EA4BFF7E6}Configs/PlayMenu/PlayMenuEntries.conf";
23 protected ref Resource m_Config;
25
26 const string TYPE_FEATURED = "m_aFeaturedScenarios";
27 const string TYPE_RECOMMENDED = "m_aRecommendedScenarios";
28
32
33 protected ref array<MissionWorkshopItem> m_aScenariosFeatured = {};
34 protected ref array<MissionWorkshopItem> m_aScenariosRecommended = {};
35 protected ref array<MissionWorkshopItem> m_aScenariosRecent = {};
36
37 protected ref array<ref SCR_PlayMenuEntry> m_aEntriesFeatured = {};
38 protected ref array<ref SCR_PlayMenuEntry> m_aEntriesRecommended = {};
39 protected ref array<ref SCR_PlayMenuEntry> m_aEntriesRecent = {};
40
44 protected Widget m_wRoot;
45 protected bool m_bTutorialPlayed;
49
50 const int THRESHOLD_RECENTLY_PLAYED = 3600 * 24 * 30;
51
52 protected ref array<SCR_InputButtonComponent> m_aRightFooterButtons = {};
53
54 protected SCR_PlayMenuTileComponent m_ClickedTile; // Cache last clicked line to trigger the correct dialog after the double click window
55
57
59
60 //------------------------------------------------------------------------------------------------
61 override void OnMenuOpen()
62 {
63 super.OnMenuOpen();
68 m_WorkshopAPI = GetGame().GetBackendApi().GetWorkshop();
69
73 footer.GetOnButtonActivated().Insert(OnInteractionButtonPressed);
74
75 m_aRightFooterButtons = footer.GetButtonsInFooter(SCR_EDynamicFooterButtonAlignment.RIGHT);
76
80 m_ActionsComponent.GetOnAction().Insert(OnActionTriggered);
81
84
85 // Backend
86 WorkshopApi workshop = GetGame().GetBackendApi().GetWorkshop();
87
88 // Scan offline items if needed
89 if (workshop.NeedAddonsScan())
90 workshop.ScanOfflineItems();
91
92 // Read the PlayMenu config
93 m_Config = BaseContainerTools.LoadContainer(m_sConfig);
94 if (!m_Config)
95 return;
96
97 m_ConfigEntries = m_Config.GetResource().ToBaseContainer();
98 if (!m_ConfigEntries)
99 return;
100
101 // Get tutorial
102 ResourceName tutorial;
103 m_ConfigEntries.Get("m_TutorialScenario", tutorial);
104 m_ItemTutorial = m_WorkshopAPI.GetInGameScenario(tutorial);
105
106 if (m_ItemTutorial)
107 m_bTutorialPlayed = m_ItemTutorial.GetTimeSinceLastPlay() > -1;
108
109 // Check how many times "Play tutorial" dialog was shown
110 BaseContainer settings = GetGame().GetGameUserSettings().GetModule("SCR_RecentGames");
111
112 if (settings)
113 {
114 settings.Get("m_iPlayTutorialShowCount", m_iPlayTutorialShowCount);
115 settings.Get("m_iPlayTutorialShowMax", m_iPlayTutorialShowMax);
116 }
117
119
120 //PrintFormat("[OnMenuOpen] m_bShowPlayTutorialDialog: %1 | m_bTutorialPlayed: %2 | m_iPlayTutorialShowCount: %3", m_bShowPlayTutorialDialog, m_bTutorialPlayed, m_iPlayTutorialShowCount);
121
122 // Get scenarios
126
127 // Get menu entries
131
135
136 // Set starting focused tile
137 if (m_aEntriesRecommended.Count() > 0)
138 m_Recommended.SetFocusedItem(0);
139
140 // Hide news menu button (top right corner) on PS
141 if (GetGame().GetPlatformService().GetLocalPlatformKind() == PlatformKind.PSN)
142 {
143 Widget newsButton = GetRootWidget().FindAnyWidget("NewsButton");
144 if (newsButton)
145 {
146 newsButton.SetVisible(false);
147 newsButton.SetEnabled(false);
148 }
149 }
150 }
151
152 //------------------------------------------------------------------------------------------------
153 override void OnMenuClose()
154 {
155 super.OnMenuClose();
156
158 }
159
160 //------------------------------------------------------------------------------------------------
161 override void OnMenuHide()
162 {
163 super.OnMenuHide();
164
165 //SCR_AnalyticsApplication.GetInstance().ClosePlayMenu();
166 }
167
168 //------------------------------------------------------------------------------------------------
169 override void OnMenuShow()
170 {
171 super.OnMenuShow();
172
174 m_ActionsComponent.ActivateActions();
175
176 //SCR_AnalyticsApplication.GetInstance().OpenPlayMenu();
177 }
178
179 //------------------------------------------------------------------------------------------------
180 override void OnMenuFocusGained()
181 {
182 super.OnMenuFocusGained();
183
185 m_ActionsComponent.ActivateActions();
186
188
189 // Restore focus to the last accessed tile
190 if (m_CurrentTile)
191 {
192 GetGame().GetWorkspace().SetFocusedWidget(m_CurrentTile.GetRootWidget());
193 return;
194 }
195
196 // Fallback to the 1st item in the *recent items* list
197 if (m_Recent)
198 m_Recent.SetFocusedItem(0);
199 }
200
201 //------------------------------------------------------------------------------------------------
202 protected void SetupSectionTiles(SCR_PlayMenuComponent section, array<ref SCR_PlayMenuEntry> entries)
203 {
204 ref array<Widget> widgets = section.GetWidgets();
205
206 // Remove entries that do not fit into the layout
207 if (entries.Count() > widgets.Count())
208 entries.Resize(widgets.Count());
209
210 // Setup grid tiles
211 foreach (int i, SCR_PlayMenuEntry entry : entries)
212 {
213 Widget w = widgets.Get(i);
214 if (!w)
215 continue;
216
218 if (!tile)
219 continue;
220
222
223 tile.m_OnFocused.Insert(OnTileFocused);
224 tile.m_OnFocusLost.Insert(OnTileFocusLost);
225
226 tile.Setup(entry.m_Item, entry.m_eContentType);
227 }
228 }
229
230 //------------------------------------------------------------------------------------------------
231 protected void CreateMenuEntries(out array<ref SCR_PlayMenuEntry> entries, array<MissionWorkshopItem> scenarios, EPlayMenuContentType type)
232 {
233 foreach (MissionWorkshopItem scenario : scenarios)
234 {
235 entries.Insert(new SCR_PlayMenuEntry(scenario, type));
236 }
237 }
238
239 //------------------------------------------------------------------------------------------------
240 protected void GetScenarios(out array<MissionWorkshopItem> scenarios, EPlayMenuContentType type)
241 {
242 if (type == EPlayMenuContentType.RECENT)
243 {
244 GetRecentScenarios(scenarios);
245 return;
246 }
247
248 array<ResourceName> aResources = {};
249
250 if (type == EPlayMenuContentType.FEATURED)
251 m_ConfigEntries.Get(TYPE_FEATURED, aResources);
252 else
253 m_ConfigEntries.Get(TYPE_RECOMMENDED, aResources);
254
255 foreach (ResourceName sResource : aResources)
256 {
257 MissionWorkshopItem scenario = m_WorkshopAPI.GetInGameScenario(sResource);
258
259 if (scenario && !SCR_ScenarioUICommon.IsMissingDependencies(scenario))
260 scenarios.Insert(scenario);
261 }
262 }
263
264 //------------------------------------------------------------------------------------------------
265 protected void GetRecentScenarios(out array<MissionWorkshopItem> scenarios)
266 {
267 // Get missions from Workshop API
268 m_WorkshopAPI.GetPageScenarios(scenarios, 0, SCR_WorkshopUiCommon.PAGE_SCENARIOS);
269
270 int count = scenarios.Count();
271 int elapsed;
272 MissionWorkshopItem scenario;
273
274 // Remove scenarios from disabled addons
275 for (int i = count - 1; i >= 0; i--)
276 {
277 scenario = scenarios[i];
278 elapsed = scenario.GetTimeSinceLastPlay();
279
280 if (elapsed == -1 || elapsed > THRESHOLD_RECENTLY_PLAYED || SCR_ScenarioUICommon.IsMissingDependencies(scenario))
281 {
282 //PrintFormat("[GetRecentScenarios] removed: %1 | last played: %2 | missing dependency: %3", scenario.Name(), elapsed, SCR_ScenarioUICommon.IsMissingDependencies(scenario));
283 scenarios.Remove(i);
284 continue;
285 }
286 };
287
288 SCR_Sorting<MissionWorkshopItem, SCR_CompareMissionTimeSinceLastPlay>.HeapSort(scenarios, false);
289 }
290
292 //------------------------------------------------------------------------------------------------
293 protected void OnActionTriggered(string action, float multiplier)
294 {
296 if (GetGame().GetInputManager().GetLastUsedInputDevice() != EInputDeviceType.MOUSE || !GetTileUnderCursor())
297 return;
298
300
301 switch (action)
302 {
303 case UIConstants.MENU_ACTION_DOUBLE_CLICK: OnTileClickInteraction(multiplier); break;
304 case SCR_ScenarioUICommon.ACTION_RESTART: Restart(scenario); break;
305 case SCR_ScenarioUICommon.ACTION_FIND_SERVERS: Join(scenario); break;
306 case SCR_ScenarioUICommon.ACTION_HOST: Host(scenario); break;
307 }
308 }
309
310 //------------------------------------------------------------------------------------------------
311 protected void OnInteractionButtonPressed(string action)
312 {
314 }
315
316 //------------------------------------------------------------------------------------------------
318 {
319 if (!dialog)
320 return;
321
322 SwitchOnButton(tag, dialog.GetScenario());
323 }
324
325 //------------------------------------------------------------------------------------------------
326 protected void SwitchOnButton(string tag, MissionWorkshopItem scenario)
327 {
328 switch (tag)
329 {
330 case SCR_ConfigurableDialogUi.BUTTON_CONFIRM: Play(scenario); break;
331 case SCR_ScenarioUICommon.BUTTON_PLAY: Play(scenario); break;
332 case SCR_ScenarioUICommon.BUTTON_CONTINUE: Continue(scenario); break;
333 case SCR_ScenarioUICommon.BUTTON_RESTART: Restart(scenario); break;
334 case SCR_ScenarioUICommon.BUTTON_FIND_SERVERS: Join(scenario); break;
335 case SCR_ScenarioUICommon.BUTTON_HOST: Host(scenario); break;
336 case SCR_ScenarioUICommon.BUTTON_SCENARIOS: OnScenarios(); break;
337 case UIConstants.BUTTON_BACK: OnBack(); break;
338 }
339 }
340
341 // CLICKS
342 //------------------------------------------------------------------------------------------------
343 //------------------------------------------------------------------------------------------------
344 protected void OnTileClickInteraction(float multiplier)
345 {
347
349 if (!tile || !GetTileUnderCursor())
350 return;
351
352 MissionWorkshopItem scenario = tile.m_Item;
353 if (!scenario)
354 return;
355
356 switch (Math.Floor(multiplier))
357 {
358 case 1: OnClickInteraction(scenario); break;
359 case 2: OnDoubleClickInteraction(scenario); break;
360 }
361
362 m_ClickedTile = null;
363 }
364
365 //------------------------------------------------------------------------------------------------
367 {
370 if (!scenarioConfirmationDialog)
371 {
372 OnPlayInteraction(scenario);
373 return;
374 }
375
377 scenarioConfirmationDialog.m_OnButtonPressed.Insert(OnConfirmationDialogButtonPressed);
378 }
379
380 //------------------------------------------------------------------------------------------------
382 {
383 if (!scenario)
384 return;
385
386 OnPlayInteraction(scenario);
387 }
388
389 // BUTTONS
390 //------------------------------------------------------------------------------------------------
395
396 // INTERACTIONS
397 //------------------------------------------------------------------------------------------------
398 protected void OnPlayInteraction(MissionWorkshopItem scenario)
399 {
400 if (scenario)
401 Continue(scenario);
402 }
403
404 //------------------------------------------------------------------------------------------------
405 protected void OnBack()
406 {
407 Close();
408 }
409
410 //------------------------------------------------------------------------------------------------
411 protected void OnScenarios()
412 {
413 SCR_MenuLoadingComponent.SaveLastMenu(ChimeraMenuPreset.PlayMenu);
414
415 GetGame().GetMenuManager().OpenMenu(ChimeraMenuPreset.ScenarioMenu);
416 }
417
418 //------------------------------------------------------------------------------------------------
419 protected void Play(MissionWorkshopItem scenario)
420 {
421 if (!scenario || !SCR_ScenarioUICommon.CanPlay(scenario))
422 return;
423
424 m_SelectedScenario = scenario;
425
427 {
428 BaseContainer settings = GetGame().GetGameUserSettings().GetModule("SCR_RecentGames");
429
430 if (settings)
431 {
433
434 settings.Set("m_iPlayTutorialShowCount", m_iPlayTutorialShowCount);
435 GetGame().UserSettingsChanged();
436 }
437
438 // Tutorial confirmation dialog
439 SCR_ConfigurableDialogUi dialog = SCR_CommonDialogs.CreateTutorialDialog();
440 if (dialog)
441 {
442 dialog.m_OnConfirm.Insert(OnPlayTutorial);
443 dialog.m_OnCancel.Insert(PlayCurrentScenario);
444 }
445 }
446 else
447 {
449 }
450
451 SCR_MenuLoadingComponent.SaveLastMenu(ChimeraMenuPreset.PlayMenu);
452 }
453
454 //------------------------------------------------------------------------------------------------
455 protected void Continue(MissionWorkshopItem scenario)
456 {
457 m_SelectedScenario = scenario;
458 SCR_ScenarioUICommon.LoadSave(scenario, m_CurrentTile.m_Header, ChimeraMenuPreset.PlayMenu);
459 }
460
461 //------------------------------------------------------------------------------------------------
462 protected void Restart(MissionWorkshopItem scenario)
463 {
464 if (!scenario || !SCR_ScenarioUICommon.CanPlay(scenario))
465 return;
466
467 m_SelectedScenario = scenario;
468
469 SCR_ConfigurableDialogUi dialog = SCR_CommonDialogs.CreateDialog(SCR_ScenarioUICommon.DIALOG_RESTART);
470 dialog.m_OnConfirm.Insert(OnRestartConfirmed);
471 }
472
473 //------------------------------------------------------------------------------------------------
474 protected void OnRestartConfirmed()
475 {
477 SCR_MenuLoadingComponent.SaveLastMenu(ChimeraMenuPreset.PlayMenu);
478 }
479
480 //------------------------------------------------------------------------------------------------
481 protected void Host(MissionWorkshopItem scenario)
482 {
483 if (!scenario || !SCR_ScenarioUICommon.CanHost(scenario))
484 return;
485
486 m_SelectedScenario = scenario;
487
489
490 SCR_MenuLoadingComponent.SaveLastMenu(ChimeraMenuPreset.PlayMenu);
491 }
492
493 //------------------------------------------------------------------------------------------------
494 protected void Join(MissionWorkshopItem scenario)
495 {
496 if (!scenario || !SCR_ScenarioUICommon.CanJoin(scenario))
497 return;
498
499 m_SelectedScenario = scenario;
500
502
503 SCR_MenuLoadingComponent.SaveLastMenu(ChimeraMenuPreset.PlayMenu);
504 }
505
506 //------------------------------------------------------------------------------------------------
508 {
509 m_CurrentTile = tile;
510
512
513 tile.m_OnClick.Insert(OnTileMouseClick);
514 }
515
516 //------------------------------------------------------------------------------------------------
518 {
520
521 tile.m_OnClick.Remove(OnTileMouseClick);
522 }
523
524 //------------------------------------------------------------------------------------------------
525 protected void UpdateNavigationButtons(bool show = true)
526 {
527 if (!m_CurrentTile)
528 return;
529
530 show = show && GetSelectedTile() && GetGame().GetInputManager().GetLastUsedInputDevice() != EInputDeviceType.MOUSE;
532 }
533
534 //------------------------------------------------------------------------------------------------
535 protected void PlayCurrentScenario()
536 {
538 }
539
540 //------------------------------------------------------------------------------------------------
546
547 //------------------------------------------------------------------------------------------------
548 protected void HostCurrentScenario()
549 {
551 return;
552
553 ServerHostingUI dialog = SCR_CommonDialogs.CreateServerHostingDialog();
554
555 if (!dialog)
556 return;
557
558 dialog.SelectScenario(m_SelectedScenario);
559 }
560
561 //------------------------------------------------------------------------------------------------
562 protected void OnPlayTutorial()
563 {
564 SCR_ScenarioUICommon.TryPlayScenario(m_ItemTutorial);
565 }
566
567 //------------------------------------------------------------------------------------------------
569 {
570 // We are not over a line, use currently focused line
571 Widget wfocused = GetGame().GetWorkspace().GetFocusedWidget();
573 if (wfocused)
574 comp = SCR_PlayMenuTileComponent.Cast(wfocused.FindHandler(SCR_PlayMenuTileComponent));
575
576 EInputDeviceType inputDevice = GetGame().GetInputManager().GetLastUsedInputDevice();
577 bool isCursorOnInnerButton = m_CurrentTile && m_CurrentTile.m_bIsMouseInteraction;
578
579 if (inputDevice == EInputDeviceType.MOUSE && (GetTileUnderCursor() || isCursorOnInnerButton))
580 return m_CurrentTile;
581 else
582 return comp;
583 }
584
585 //------------------------------------------------------------------------------------------------
587 {
588 Widget w = WidgetManager.GetWidgetUnderCursor();
589
590 if (!w)
591 return null;
592
593 return SCR_PlayMenuTileComponent.Cast(w.FindHandler(SCR_PlayMenuTileComponent));
594 }
595
596 //------------------------------------------------------------------------------------------------
598 {
600
601 if (!comp)
602 return null;
603
604 return comp.m_Item;
605 }
606
607 //------------------------------------------------------------------------------------------------
608 protected void OnCommStatusCheckFinished(SCR_ECommStatus status, float responseTime, float lastSuccessTime, float lastFailTime)
609 {
611 }
612}
ChimeraMenuPreset
Menu presets.
ArmaReforgerScripted GetGame()
Definition game.c:1398
PlatformKind
Definition PlatformKind.c:8
InputManager GetInputManager()
void UpdateNavigationButtons()
EDamageType type
Widget GetRootWidget()
NewsFeedItem m_Item
enum EPlayMenuContentType m_eContentType
EPlayMenuContentType
Definition SCR_PlayMenu.c:2
@ RECENT
Definition SCR_PlayMenu.c:5
@ FEATURED
Definition SCR_PlayMenu.c:3
@ RECOMMENDED
Definition SCR_PlayMenu.c:4
void SCR_PlayMenuEntry(MissionWorkshopItem item, EPlayMenuContentType type)
void SCR_ScenarioConfirmationDialogUi(MissionWorkshopItem scenario, ScriptInvokerBool onFavoritesResponse=null)
SCR_ECommStatus
This class may become obsolete on BackendAPI update.
proto native void Close()
Definition Math.c:13
SCR_DynamicFooterComponent GetFooterComponent()
Object holding reference to resource. In destructor release the resource.
Definition Resource.c:25
static SCR_MenuActionsComponent FindComponent(Widget w)
static SCR_PlayMenuComponent GetComponent(string name, Widget parent, bool searchAllChildren=true)
ResourceName m_sConfig
const string TYPE_FEATURED
void OnDoubleClickInteraction(MissionWorkshopItem scenario)
void Continue(MissionWorkshopItem scenario)
void OnActionTriggered(string action, float multiplier)
Input Events.
override void OnMenuShow()
void GetScenarios(out array< MissionWorkshopItem > scenarios, EPlayMenuContentType type)
void SwitchOnButton(string tag, MissionWorkshopItem scenario)
void CreateMenuEntries(out array< ref SCR_PlayMenuEntry > entries, array< MissionWorkshopItem > scenarios, EPlayMenuContentType type)
SCR_PlayMenuComponent m_Recommended
ref array< ref SCR_PlayMenuEntry > m_aEntriesFeatured
void OnPlayTutorial()
SCR_PlayMenuComponent m_Recent
void GetRecentScenarios(out array< MissionWorkshopItem > scenarios)
void OnRestartConfirmed()
void FindCurrentScenarioServers()
void OnTileFocused(SCR_PlayMenuTileComponent tile)
void Restart(MissionWorkshopItem scenario)
ref array< ref SCR_PlayMenuEntry > m_aEntriesRecent
const string TYPE_RECOMMENDED
void Play(MissionWorkshopItem scenario)
void UpdateNavigationButtons(bool show=true)
SCR_PlayMenuTileComponent m_ClickedTile
void OnTileFocusLost(SCR_PlayMenuTileComponent tile)
BaseContainer m_ConfigEntries
WorkshopApi m_WorkshopAPI
ref MissionWorkshopItem m_ItemTutorial
ref array< MissionWorkshopItem > m_aScenariosFeatured
const int THRESHOLD_RECENTLY_PLAYED
SCR_PlayMenuTileComponent GetSelectedTile()
void OnClickInteraction(MissionWorkshopItem scenario)
ref Resource m_Config
ref array< ref SCR_PlayMenuEntry > m_aEntriesRecommended
MissionWorkshopItem GetSelectedScenario()
void OnConfirmationDialogButtonPressed(SCR_ScenarioConfirmationDialogUi dialog, string tag)
override void OnMenuOpen()
override void OnMenuFocusGained()
void OnPlayInteraction(MissionWorkshopItem scenario)
bool m_bTutorialPlayed
void Join(MissionWorkshopItem scenario)
void OnTileMouseClick(SCR_ScriptedWidgetComponent tile)
override void OnMenuClose()
void Host(MissionWorkshopItem scenario)
int m_iPlayTutorialShowMax
void OnInteractionButtonPressed(string action)
void PlayCurrentScenario()
void OnCommStatusCheckFinished(SCR_ECommStatus status, float responseTime, float lastSuccessTime, float lastFailTime)
int m_iPlayTutorialShowCount
ref array< SCR_InputButtonComponent > m_aRightFooterButtons
override void OnMenuHide()
void OnTileClickInteraction(float multiplier)
SCR_PlayMenuTileComponent GetTileUnderCursor()
SCR_PlayMenuComponent m_Featured
void SetupSectionTiles(SCR_PlayMenuComponent section, array< ref SCR_PlayMenuEntry > entries)
bool m_bShowPlayTutorialDialog
void OnScenarios()
MissionWorkshopItem m_SelectedScenario
ref array< MissionWorkshopItem > m_aScenariosRecent
SCR_PlayMenuTileComponent m_CurrentTile
SCR_MenuActionsComponent m_ActionsComponent
ref array< MissionWorkshopItem > m_aScenariosRecommended
void HostCurrentScenario()
void Setup(notnull MissionWorkshopItem item, EPlayMenuContentType contentType)
ScriptInvokerString GetOnMouseInteractionButtonClicked()
static SCR_ScenarioConfirmationDialogUi CreateScenarioConfirmationDialog(MissionWorkshopItem scenario, ScriptInvokerBool onFavoritesResponse=null)
static void UpdateInputButtons(MissionWorkshopItem mission, array< SCR_InputButtonComponent > buttons, bool visible=true)
static bool CanJoin(MissionWorkshopItem mission)
static bool IsMissingDependencies(MissionWorkshopItem mission)
static bool CanHost(MissionWorkshopItem mission)
static bool CanPlay(MissionWorkshopItem mission)
static ScriptInvokerCommStatus GetOnCommStatusCheckFinished()
static void TryOpenServerBrowserWithScenarioFilter(MissionWorkshopItem mission)
Workshop Api instance.
Definition WorkshopApi.c:14
bool Play()
Start playing the animation. Call 'Prepare' first if you need to change the setup of a component!