24 protected ResourceName m_sConfig =
"{6409EA8EA4BFF7E6}Configs/PlayMenu/PlayMenuEntries.conf";
25 protected ref Resource m_Config;
26 protected BaseContainer m_ConfigEntries;
28 const string TYPE_FEATURED =
"m_aFeaturedScenarios";
29 const string TYPE_RECOMMENDED =
"m_aRecommendedScenarios";
35 protected ref array<MissionWorkshopItem> m_aScenariosFeatured = {};
36 protected ref array<MissionWorkshopItem> m_aScenariosRecommended = {};
37 protected ref array<MissionWorkshopItem> m_aScenariosRecent = {};
39 protected ref array<ref SCR_PlayMenuEntry> m_aEntriesFeatured = {};
40 protected ref array<ref SCR_PlayMenuEntry> m_aEntriesRecommended = {};
41 protected ref array<ref SCR_PlayMenuEntry> m_aEntriesRecent = {};
43 protected ref MissionWorkshopItem m_ItemTutorial;
44 protected WorkshopApi m_WorkshopAPI;
46 protected Widget m_wRoot;
47 protected bool m_bTutorialPlayed;
48 protected bool m_bShowPlayTutorialDialog;
49 protected int m_iPlayTutorialShowCount;
50 protected int m_iPlayTutorialShowMax;
52 const int THRESHOLD_RECENTLY_PLAYED = 3600 * 24 * 30;
54 protected Widget m_wFooter;
62 protected ref array<SCR_InputButtonComponent> m_aRightFooterButtons = {};
66 protected MissionWorkshopItem m_SelectedScenario;
71 override void OnMenuOpen()
80 m_wFooter =
m_wRoot.FindWidget(
"MenuBase1.SizeBase.VerticalLayout0.SizeFooter.Footer");
85 footer.GetOnButtonActivated().Insert(OnInteractionButtonPressed);
88 m_Scenarios = footer.FindButton(
"Scenarios");
89 m_Play = footer.FindButton(SCR_ScenarioEntryHelper.BUTTON_PLAY);
90 m_Continue = footer.FindButton(SCR_ScenarioEntryHelper.BUTTON_CONTINUE);
91 m_Restart = footer.FindButton(SCR_ScenarioEntryHelper.BUTTON_RESTART);
92 m_Host = footer.FindButton(SCR_ScenarioEntryHelper.BUTTON_HOST);
93 m_FindServer = footer.FindButton(SCR_ScenarioEntryHelper.BUTTON_FIND_SERVERS);
99 if (m_ActionsComponent)
100 m_ActionsComponent.GetOnAction().Insert(OnActionTriggered);
106 WorkshopApi workshop =
GetGame().GetBackendApi().GetWorkshop();
109 if (workshop.NeedScan())
110 workshop.ScanOfflineItems();
113 m_Config = BaseContainerTools.LoadContainer(
m_sConfig);
117 m_ConfigEntries = m_Config.GetResource().ToBaseContainer();
118 if (!m_ConfigEntries)
122 ResourceName tutorial;
123 m_ConfigEntries.Get(
"m_TutorialScenario", tutorial);
127 m_bTutorialPlayed = m_ItemTutorial.GetTimeSinceLastPlay() > -1;
130 BaseContainer settings =
GetGame().GetGameUserSettings().GetModule(
"SCR_RecentGames");
134 settings.Get(
"m_iPlayTutorialShowCount", m_iPlayTutorialShowCount);
135 settings.Get(
"m_iPlayTutorialShowMax", m_iPlayTutorialShowMax);
138 m_bShowPlayTutorialDialog = !m_bTutorialPlayed && m_iPlayTutorialShowCount < m_iPlayTutorialShowMax;
149 CreateMenuEntries(m_aEntriesRecommended, m_aScenariosRecommended,
EPlayMenuContentType.RECOMMENDED);
152 SetupSectionTiles(m_Featured, m_aEntriesFeatured);
153 SetupSectionTiles(m_Recommended, m_aEntriesRecommended);
154 SetupSectionTiles(m_Recent, m_aEntriesRecent);
157 if (m_aEntriesRecommended.Count() > 0)
158 m_Recommended.SetFocusedItem(0);
162 override void OnMenuClose()
170 override void OnMenuShow()
174 if (m_ActionsComponent)
175 m_ActionsComponent.ActivateActions();
179 override void OnMenuFocusGained()
181 super.OnMenuFocusGained();
183 if (m_ActionsComponent)
184 m_ActionsComponent.ActivateActions();
197 m_Recent.SetFocusedItem(0);
201 protected void SetupSectionTiles(
SCR_PlayMenuComponent section, array<ref SCR_PlayMenuEntry> entries)
203 ref array<Widget> widgets = section.GetWidgets();
206 if (entries.Count() > widgets.Count())
207 entries.Resize(widgets.Count());
212 Widget w = widgets.Get(i);
221 entry.m_wRoot = tile.m_wRoot;
223 tile.GetOnMouseInteractionButtonClicked().Insert(OnInteractionButtonPressed);
225 tile.m_OnFocused.Insert(OnTileFocused);
226 tile.m_OnFocusLost.Insert(OnTileFocusLost);
228 tile.Setup(entry.m_Item, entry.m_eContentType);
233 void CreateMenuEntries(out array<ref SCR_PlayMenuEntry> entries, array<MissionWorkshopItem> scenarios,
EPlayMenuContentType type)
235 foreach (MissionWorkshopItem scenario : scenarios)
246 GetRecentScenarios(scenarios);
250 array<ResourceName> aResources = {};
253 m_ConfigEntries.Get(TYPE_FEATURED, aResources);
255 m_ConfigEntries.Get(TYPE_RECOMMENDED, aResources);
257 foreach (ResourceName sResource : aResources)
259 MissionWorkshopItem scenario =
m_WorkshopAPI.GetInGameScenario(sResource);
261 if (scenario && !IsMissingDependency(scenario))
262 scenarios.Insert(scenario);
267 void GetRecentScenarios(out array<MissionWorkshopItem> scenarios)
272 int count = scenarios.Count();
274 MissionWorkshopItem scenario;
277 for (
int i = count - 1; i >= 0; i--)
279 scenario = scenarios[i];
280 elapsed = scenario.GetTimeSinceLastPlay();
290 SCR_Sorting<MissionWorkshopItem, SCR_CompareMissionTimeSinceLastPlay>.HeapSort(scenarios,
false);
303 protected bool IsMissingDependency(MissionWorkshopItem scenario)
305 WorkshopItem addon = scenario.GetOwner();
311 array<Dependency> dependencies = {};
312 addon.GetActiveRevision().GetDependencies(dependencies);
315 foreach (Dependency dependency : dependencies)
317 if (!dependency.IsOffline())
325 protected bool IsUnique(MissionWorkshopItem item, array<ref SCR_PlayMenuEntry> entries)
332 if (!entry || !entry.m_Item)
335 if (item == entry.m_Item)
344 protected void OnActionTriggered(
string action,
float multiplier)
347 if (
GetGame().
GetInputManager().GetLastUsedInputDevice() != EInputDeviceType.MOUSE || !GetTileUnderCursor())
350 MissionWorkshopItem scenario = GetSelectedScenario();
354 case SCR_ScenarioEntryHelper.ACTION_DOUBLE_CLICK: OnTileClickInteraction(multiplier);
break;
355 case SCR_ScenarioEntryHelper.ACTION_RESTART: Restart(scenario);
break;
356 case SCR_ScenarioEntryHelper.ACTION_FIND_SERVERS: Join(scenario);
break;
357 case SCR_ScenarioEntryHelper.ACTION_HOST: Host(scenario);
break;
362 protected void OnInteractionButtonPressed(
string action)
364 SwitchOnButton(action, GetSelectedScenario());
373 SwitchOnButton(tag, dialog.GetScenario());
377 protected void SwitchOnButton(
string tag, MissionWorkshopItem scenario)
382 case SCR_ScenarioEntryHelper.BUTTON_PLAY: Play(scenario);
break;
383 case SCR_ScenarioEntryHelper.BUTTON_CONTINUE: Continue(scenario);
break;
384 case SCR_ScenarioEntryHelper.BUTTON_RESTART: Restart(scenario);
break;
385 case SCR_ScenarioEntryHelper.BUTTON_FIND_SERVERS: Join(scenario);
break;
386 case SCR_ScenarioEntryHelper.BUTTON_HOST: Host(scenario);
break;
387 case "Scenarios": OnScenarios();
break;
388 case "Back": OnBack();
break;
395 protected void OnTileClickInteraction(
float multiplier)
400 if (!tile || !GetTileUnderCursor())
403 MissionWorkshopItem scenario = tile.m_Item;
407 switch (Math.Floor(multiplier))
409 case 1: OnClickInteraction(scenario);
break;
410 case 2: OnDoubleClickInteraction(scenario);
break;
413 m_ClickedTile =
null;
417 protected void OnClickInteraction(MissionWorkshopItem scenario)
421 if (!scenarioConfirmationDialog)
423 OnPlayInteraction(scenario);
428 scenarioConfirmationDialog.m_OnButtonPressed.Insert(OnConfirmationDialogButtonPressed);
432 protected void OnDoubleClickInteraction(MissionWorkshopItem scenario)
437 OnPlayInteraction(scenario);
449 protected void OnPlayInteraction(MissionWorkshopItem scenario)
459 bool canBeLoaded = header &&
GetGame().GetSaveManager().HasLatestSave(header);
467 protected void OnBack()
473 protected void OnScenarios()
481 protected void Play(MissionWorkshopItem scenario)
486 m_SelectedScenario = scenario;
488 if (m_bShowPlayTutorialDialog && m_ItemTutorial && m_ItemTutorial !=
m_CurrentTile.m_Item)
490 BaseContainer settings =
GetGame().GetGameUserSettings().GetModule(
"SCR_RecentGames");
494 m_iPlayTutorialShowCount++;
496 settings.Set(
"m_iPlayTutorialShowCount", m_iPlayTutorialShowCount);
497 GetGame().UserSettingsChanged();
504 dialog.m_OnConfirm.Insert(OnPlayTutorial);
505 dialog.m_OnCancel.Insert(PlayCurrentScenario);
510 PlayCurrentScenario();
517 protected void Continue(MissionWorkshopItem scenario)
522 m_SelectedScenario = scenario;
525 if (header && !header.GetSaveFileName().IsEmpty())
526 GetGame().GetSaveManager().SetFileNameToLoad(header);
528 GetGame().GetSaveManager().ResetFileNameToLoad();
530 PlayCurrentScenario();
536 protected void Restart(MissionWorkshopItem scenario)
541 m_SelectedScenario = scenario;
544 dialog.m_OnConfirm.Insert(OnRestartConfirmed);
548 protected void OnRestartConfirmed()
550 GetGame().GetSaveManager().ResetFileNameToLoad();
551 PlayCurrentScenario();
557 protected void Host(MissionWorkshopItem scenario)
560 if (!scenario || !SCR_ScenarioEntryHelper.IsMultiplayer(scenario) || SCR_ScenarioEntryHelper.IsInErrorState(state))
563 m_SelectedScenario = scenario;
565 HostCurrentScenario();
571 protected void Join(MissionWorkshopItem scenario)
574 if (!scenario || !SCR_ScenarioEntryHelper.IsMultiplayer(scenario) || SCR_ScenarioEntryHelper.IsInErrorState(state))
577 m_SelectedScenario = scenario;
579 FindCurrentScenarioServers();
589 UpdateNavigationButtons();
591 tile.m_OnClicked.Insert(OnTileMouseClick);
597 UpdateNavigationButtons(
false);
599 tile.m_OnClicked.Remove(OnTileMouseClick);
603 protected void UpdateNavigationButtons(
bool show =
true)
608 show = show && GetSelectedTile() &&
GetGame().GetInputManager().GetLastUsedInputDevice() != EInputDeviceType.MOUSE;
613 void TryPlayScenario(MissionWorkshopItem scenario)
622 protected void PlayCurrentScenario()
624 if (m_SelectedScenario)
625 TryPlayScenario(m_SelectedScenario);
629 protected void FindCurrentScenarioServers()
631 if (m_SelectedScenario)
636 protected void HostCurrentScenario()
638 if (!m_SelectedScenario)
646 dialog.SelectScenario(m_SelectedScenario);
650 protected void OnPlayTutorial()
652 TryPlayScenario(m_ItemTutorial);
659 Widget wfocused =
GetGame().GetWorkspace().GetFocusedWidget();
664 EInputDeviceType inputDevice =
GetGame().GetInputManager().GetLastUsedInputDevice();
667 if (inputDevice == EInputDeviceType.MOUSE && (GetTileUnderCursor() || isCursorOnInnerButton))
676 Widget w = WidgetManager.GetWidgetUnderCursor();
685 protected MissionWorkshopItem GetSelectedScenario()
696 protected void OnCommStatusCheckFinished(
SCR_ECommStatus status,
float responseTime,
float lastSuccessTime,
float lastFailTime)
698 UpdateNavigationButtons();