mainmenuconsoles.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662
  1. class MainMenuConsole extends UIScriptedMenu
  2. {
  3. protected ref MainMenuVideo m_Video;
  4. protected MissionMainMenu m_Mission;
  5. protected DayZIntroScenePC m_ScenePC;
  6. protected TextWidget m_PlayerName;
  7. protected TextWidget m_Version;
  8. protected Widget m_MainMenuPanel;
  9. protected Widget m_DialogPanel;
  10. protected Widget m_ChangeAccount;
  11. protected Widget m_CustomizeCharacter;
  12. protected Widget m_PlayVideo;
  13. protected Widget m_Tutorials;
  14. protected Widget m_Options;
  15. protected Widget m_Controls;
  16. protected Widget m_Play;
  17. protected Widget m_MessageButton;
  18. protected Widget m_ShowFeedback;
  19. protected ImageWidget m_FeedbackQRCode;
  20. protected ImageWidget m_FeedbackPlatformIcon;
  21. protected ButtonWidget m_FeedbackClose;
  22. protected RichTextWidget m_FeedbackCloseLabel;
  23. protected ref Widget m_LastFocusedButton;
  24. protected ref array<ref ModInfo> m_AllDLCs;
  25. protected Widget m_DlcFrame;
  26. protected ref map<string,ref ModInfo> m_AllDlcsMap;
  27. protected ref JsonDataDLCList m_DlcData;
  28. protected ref array<ref MainMenuDlcHandlerBase> m_DlcHandlers;
  29. protected ref MainMenuDlcHandlerBase m_DisplayedDlcHandler;
  30. override Widget Init()
  31. {
  32. layoutRoot = GetGame().GetWorkspace().CreateWidgets("gui/layouts/new_ui/main_menu_console.layout");
  33. m_MainMenuPanel = layoutRoot.FindAnyWidget("main_menu_panel");
  34. m_PlayerName = TextWidget.Cast(layoutRoot.FindAnyWidget("character_name_xbox"));
  35. m_ChangeAccount = layoutRoot.FindAnyWidget("choose_account");
  36. m_CustomizeCharacter = layoutRoot.FindAnyWidget("customize_character");
  37. m_PlayVideo = layoutRoot.FindAnyWidget("play_video");
  38. m_Tutorials = layoutRoot.FindAnyWidget("tutorials");
  39. m_Options = layoutRoot.FindAnyWidget("options");
  40. m_Controls = layoutRoot.FindAnyWidget("controls");
  41. m_Play = layoutRoot.FindAnyWidget("play");
  42. m_MessageButton = layoutRoot.FindAnyWidget("message_button");
  43. m_DlcFrame = layoutRoot.FindAnyWidget("dlc_Frame");
  44. m_Version = TextWidget.Cast(layoutRoot.FindAnyWidget("version"));
  45. m_Mission = MissionMainMenu.Cast(GetGame().GetMission());
  46. m_ShowFeedback = layoutRoot.FindAnyWidget("feedback");
  47. m_FeedbackQRCode = ImageWidget.Cast(layoutRoot.FindAnyWidget("qr_image"));
  48. m_FeedbackClose = ButtonWidget.Cast(layoutRoot.FindAnyWidget("close_button"));
  49. m_FeedbackCloseLabel = RichTextWidget.Cast(layoutRoot.FindAnyWidget("close_button_label"));
  50. m_DialogPanel = layoutRoot.FindAnyWidget("main_menu_dialog");
  51. m_LastFocusedButton = m_Play;
  52. GetGame().GetUIManager().ScreenFadeOut(1);
  53. string launch_done;
  54. if (!GetGame().GetProfileString("FirstLaunchDone", launch_done) || launch_done != "true")
  55. {
  56. GetGame().SetProfileString("FirstLaunchDone", "true");
  57. GetGame().GetUIManager().ShowDialog("#main_menu_tutorial", "#main_menu_tutorial_desc", 555, DBT_YESNO, DBB_YES, DMT_QUESTION, this);
  58. GetGame().SaveProfile();
  59. }
  60. UpdateControlsElementVisibility();
  61. LoadMods();
  62. Refresh();
  63. if (GetGame().GetMission())
  64. {
  65. GetGame().GetMission().GetOnInputPresetChanged().Insert(OnInputPresetChanged);
  66. GetGame().GetMission().GetOnInputDeviceChanged().Insert(OnInputDeviceChanged);
  67. }
  68. OnInputDeviceChanged(GetGame().GetInput().GetCurrentInputDevice());
  69. GetGame().GetContentDLCService().m_OnChange.Insert(OnDLCChange);
  70. #ifdef PLATFORM_CONSOLE
  71. #ifndef PLATFORM_PS4
  72. m_ChangeAccount.Show(GetGame().GetInput().IsEnabledMouseAndKeyboard());
  73. m_FeedbackQRCode.LoadImageFile(0, "gui/textures/feedback_qr_xbox.edds");
  74. #else
  75. m_FeedbackQRCode.LoadImageFile(0, "gui/textures/feedback_qr_ps.edds");
  76. #endif
  77. #endif
  78. return layoutRoot;
  79. }
  80. void ~MainMenuConsole()
  81. {
  82. if (GetGame().GetMission())
  83. {
  84. GetGame().GetMission().GetOnInputPresetChanged().Remove(OnInputPresetChanged);
  85. GetGame().GetMission().GetOnInputDeviceChanged().Remove(OnInputDeviceChanged);
  86. }
  87. if (GetGame().GetContentDLCService())
  88. GetGame().GetContentDLCService().m_OnChange.Remove(OnDLCChange);
  89. }
  90. void OnDLCChange(EDLCId dlcId)
  91. {
  92. m_AllDLCs = null;
  93. LoadMods();
  94. }
  95. void LoadMods()
  96. {
  97. if (m_AllDLCs != null)
  98. return;
  99. m_AllDLCs = new array<ref ModInfo>;
  100. GetGame().GetModInfos(m_AllDLCs);
  101. if (m_AllDLCs.Count() > 0)
  102. {
  103. m_AllDLCs.Remove(m_AllDLCs.Count() - 1);
  104. m_AllDLCs.Invert();
  105. }
  106. FilterDLCs(m_AllDLCs);
  107. PopulateDlcFrame();
  108. UpdateControlsElements();
  109. }
  110. //! leaves ONLY DLCs
  111. void FilterDLCs(inout array<ref ModInfo> modArray)
  112. {
  113. if (!m_AllDlcsMap)
  114. m_AllDlcsMap = new map<string,ref ModInfo>;
  115. m_AllDlcsMap.Clear();
  116. ModInfo info;
  117. int count = modArray.Count();
  118. for (int i = count - 1; i >= 0; i--)
  119. {
  120. info = modArray[i];
  121. if (!info.GetIsDLC())
  122. modArray.Remove(i);
  123. else
  124. m_AllDlcsMap.Set(info.GetName(), info);
  125. }
  126. }
  127. void PopulateDlcFrame()
  128. {
  129. if (!m_DlcHandlers)
  130. m_DlcHandlers = new array<ref MainMenuDlcHandlerBase>();
  131. else
  132. {
  133. // TODO: Would be better to update the parts that need updating instead of full recreation
  134. // Destroying and then reloading the same video is quite wasteful
  135. m_DlcHandlers.Clear();
  136. }
  137. m_DlcData = DlcDataLoader.GetData();
  138. int count = m_DlcData.DLCs.Count();
  139. JsonDataDLCInfo data;
  140. ModInfo info;
  141. for (int i = 0; i < count; i++)
  142. {
  143. data = m_DlcData.DLCs[i];
  144. info = m_AllDlcsMap.Get(data.Name);
  145. MainMenuDlcHandlerBase handler = new MainMenuDlcHandlerBase(info, m_DlcFrame, data);
  146. handler.ShowInfoPanel(true);
  147. m_DisplayedDlcHandler = handler;//TODO: carousel will take care of this later
  148. m_DlcHandlers.Insert(handler);
  149. }
  150. }
  151. protected void OnInputPresetChanged()
  152. {
  153. #ifdef PLATFORM_CONSOLE
  154. UpdateControlsElements();
  155. #endif
  156. }
  157. protected void OnInputDeviceChanged(EInputDeviceType pInputDeviceType)
  158. {
  159. switch (pInputDeviceType)
  160. {
  161. case EInputDeviceType.CONTROLLER:
  162. if (GetGame().GetInput().IsEnabledMouseAndKeyboard())
  163. {
  164. GetGame().GetUIManager().ShowUICursor(false);
  165. #ifdef PLATFORM_CONSOLE
  166. if (m_LastFocusedButton == m_ShowFeedback || !GetFocus() || GetFocus() == m_FeedbackClose)
  167. {
  168. SetFocus(m_Play);
  169. }
  170. m_FeedbackClose.Show(false);
  171. m_ShowFeedback.Show(false);
  172. #ifndef PLATFORM_PS4
  173. m_ChangeAccount.Show(false);
  174. if (m_LastFocusedButton == m_ChangeAccount)
  175. {
  176. SetFocus(m_Play);
  177. }
  178. #endif
  179. #endif
  180. }
  181. break;
  182. default:
  183. if (GetGame().GetInput().IsEnabledMouseAndKeyboard())
  184. {
  185. GetGame().GetUIManager().ShowUICursor(true);
  186. #ifdef PLATFORM_CONSOLE
  187. m_ShowFeedback.Show(true);
  188. m_FeedbackClose.Show(true);
  189. m_FeedbackCloseLabel.SetText(string.Format("%1",InputUtils.GetRichtextButtonIconFromInputAction("UAUIBack", "#close", EUAINPUT_DEVICE_CONTROLLER, InputUtils.ICON_SCALE_NORMAL)));
  190. #ifndef PLATFORM_PS4
  191. m_ChangeAccount.Show(true);
  192. #endif
  193. #endif
  194. }
  195. break;
  196. }
  197. UpdateControlsElements();
  198. UpdateControlsElementVisibility();
  199. }
  200. override bool OnClick(Widget w, int x, int y, int button)
  201. {
  202. if (!FeedbackDialogVisible())
  203. {
  204. if (w == m_Play)
  205. {
  206. m_LastFocusedButton = m_Play;
  207. OpenMenuServerBrowser();
  208. return true;
  209. }
  210. else if (w == m_Options)
  211. {
  212. m_LastFocusedButton = m_Options;
  213. OpenMenuOptions();
  214. return true;
  215. }
  216. else if (w == m_PlayVideo)
  217. {
  218. m_LastFocusedButton = m_PlayVideo;
  219. OpenMenuPlayVideo();
  220. return true;
  221. }
  222. else if (w == m_Tutorials)
  223. {
  224. m_LastFocusedButton = m_Tutorials;
  225. OpenMenuTutorials();
  226. return true;
  227. }
  228. else if (w == m_Controls)
  229. {
  230. m_LastFocusedButton = m_Controls;
  231. OpenMenuControls();
  232. return true;
  233. }
  234. else if (w == m_CustomizeCharacter)
  235. {
  236. m_LastFocusedButton = m_CustomizeCharacter;
  237. OpenMenuCustomizeCharacter();
  238. return true;
  239. }
  240. else if (w == m_ChangeAccount)
  241. {
  242. m_LastFocusedButton = m_ChangeAccount;
  243. ChangeAccount();
  244. return true;
  245. }
  246. else if (w == m_MessageButton)
  247. {
  248. OpenCredits();
  249. return true;
  250. }
  251. }
  252. if (w == m_ShowFeedback || w == m_FeedbackClose)
  253. {
  254. m_LastFocusedButton = w;
  255. ToggleFeedbackDialog();
  256. return true;
  257. }
  258. return false;
  259. }
  260. override bool OnFocus(Widget w, int x, int y)
  261. {
  262. ColorHighlight(w);
  263. if (ButtonWidget.Cast(w))
  264. {
  265. m_LastFocusedButton = w;
  266. }
  267. return true;
  268. }
  269. override bool OnFocusLost(Widget w, int x, int y)
  270. {
  271. ColorNormal(w);
  272. return true;
  273. }
  274. override bool OnMouseEnter(Widget w, int x, int y)
  275. {
  276. if (w == m_FeedbackClose)
  277. {
  278. ColorHighlight(w);
  279. return true;
  280. }
  281. return false;
  282. }
  283. override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
  284. {
  285. if (w == m_FeedbackClose)
  286. {
  287. ColorNormal(w);
  288. return true;
  289. }
  290. return true;
  291. }
  292. override void Refresh()
  293. {
  294. string name;
  295. if (GetGame().GetUserManager() && GetGame().GetUserManager().GetSelectedUser())
  296. {
  297. name = GetGame().GetUserManager().GetSelectedUser().GetName();
  298. if (name.LengthUtf8() > 18)
  299. {
  300. name = name.SubstringUtf8(0, 18);
  301. name += "...";
  302. }
  303. }
  304. m_PlayerName.SetText(name);
  305. string version;
  306. GetGame().GetVersion(version);
  307. m_Version.SetText("#main_menu_version" + " " + version + " (" + g_Game.GetDatabaseID() + ")");
  308. if (m_DisplayedDlcHandler)
  309. m_DisplayedDlcHandler.UpdateAllPromotionInfo();
  310. }
  311. override void OnShow()
  312. {
  313. GetDayZGame().GetBacklit().MainMenu_OnShow();
  314. SetFocus(m_LastFocusedButton);
  315. LoadMods();
  316. Refresh();
  317. if (m_ScenePC && m_ScenePC.GetIntroCamera())
  318. {
  319. m_ScenePC.GetIntroCamera().LookAt(m_ScenePC.GetIntroCharacter().GetPosition() + Vector(0, 1, 0));
  320. }
  321. if (m_DisplayedDlcHandler)
  322. m_DisplayedDlcHandler.ShowInfoPanel(true);
  323. super.OnShow();
  324. #ifdef PLATFORM_CONSOLE
  325. layoutRoot.FindAnyWidget("ButtonHolderCredits").Show(GetGame().GetInput().IsEnabledMouseAndKeyboard());
  326. OnInputDeviceChanged(GetGame().GetInput().GetCurrentInputDevice());
  327. #endif
  328. }
  329. override void OnHide()
  330. {
  331. if (m_DisplayedDlcHandler)
  332. m_DisplayedDlcHandler.ShowInfoPanel(false);
  333. GetDayZGame().GetBacklit().MainMenu_OnHide();
  334. }
  335. override void Update(float timeslice)
  336. {
  337. super.Update(timeslice);
  338. if (g_Game.GetLoadState() != DayZGameState.CONNECTING && !GetGame().GetUIManager().IsDialogVisible())
  339. {
  340. #ifndef PLATFORM_CONSOLE
  341. if (GetUApi().GetInputByID(UAUIBack).LocalPress())
  342. {
  343. if (!GetGame().GetUIManager().IsDialogHiding())
  344. Exit();
  345. }
  346. #else
  347. if (GetUApi().GetInputByID(UAUIBack).LocalPress())
  348. {
  349. if (FeedbackDialogVisible())
  350. {
  351. ToggleFeedbackDialog();
  352. }
  353. else
  354. {
  355. EnterScriptedMenu(MENU_MAIN);
  356. }
  357. }
  358. if (GetUApi().GetInputByID(UAUICredits).LocalPress())
  359. OpenCredits();
  360. #endif
  361. }
  362. #ifdef PLATFORM_XBOX
  363. if (GetUApi().GetInputByID(UAUICtrlY).LocalPress())
  364. ChangeAccount();
  365. #endif
  366. if (GetUApi().GetInputByID(UAUICtrlX).LocalPress())
  367. {
  368. if (CanStoreBeOpened())
  369. m_DisplayedDlcHandler.GetModInfo().GoToStore();
  370. }
  371. if (GetUApi().GetInputByID(UAUIThumbRight).LocalPress())
  372. {
  373. ToggleFeedbackDialog();
  374. }
  375. }
  376. protected void ToggleFeedbackDialog()
  377. {
  378. bool dialogVisible = FeedbackDialogVisible();
  379. m_DialogPanel.Show(!dialogVisible);
  380. m_MainMenuPanel.Show(dialogVisible);
  381. if (!dialogVisible)
  382. {
  383. PPERequesterBank.GetRequester(PPERequester_FeedbackBlur).Start();
  384. }
  385. else
  386. {
  387. PPERequesterBank.GetRequester(PPERequester_FeedbackBlur).Stop();
  388. }
  389. SetFocus(m_LastFocusedButton);
  390. UpdateControlsElements();
  391. }
  392. bool FeedbackDialogVisible()
  393. {
  394. return m_DialogPanel.IsVisible();
  395. }
  396. bool CanStoreBeOpened()
  397. {
  398. return m_DisplayedDlcHandler != null;
  399. }
  400. void OpenMenuServerBrowser()
  401. {
  402. EnterScriptedMenu(MENU_SERVER_BROWSER);
  403. }
  404. void OpenMenuControls()
  405. {
  406. EnterScriptedMenu(MENU_XBOX_CONTROLS);
  407. }
  408. void OpenMenuOptions()
  409. {
  410. EnterScriptedMenu(MENU_OPTIONS);
  411. }
  412. void OpenMenuPlayVideo()
  413. {
  414. EnterScriptedMenu(MENU_VIDEO);
  415. }
  416. void OpenMenuTutorials()
  417. {
  418. EnterScriptedMenu(MENU_TUTORIAL);
  419. }
  420. void OpenMenuCustomizeCharacter()
  421. {
  422. EnterScriptedMenu(MENU_CHARACTER);
  423. }
  424. void OpenCredits()
  425. {
  426. EnterScriptedMenu(MENU_CREDITS);
  427. m_Mission.OnMenuEnter(MENU_CREDITS);
  428. }
  429. void ChangeAccount()
  430. {
  431. BiosUserManager user_manager = GetGame().GetUserManager();
  432. if (user_manager)
  433. {
  434. g_Game.SetLoadState(DayZLoadState.MAIN_MENU_START);
  435. #ifndef PLATFORM_WINDOWS
  436. user_manager.SelectUserEx(null);
  437. #endif
  438. GetGame().GetUIManager().Back();
  439. }
  440. }
  441. void Exit()
  442. {
  443. GetGame().GetUIManager().ShowDialog("#main_menu_exit", "#main_menu_exit_desc", IDC_MAIN_QUIT, DBT_YESNO, DBB_YES, DMT_QUESTION, this);
  444. }
  445. //Coloring functions (Until WidgetStyles are useful)
  446. void ColorHighlight(Widget w)
  447. {
  448. if (!w)
  449. return;
  450. int color_pnl = ARGB(255, 200, 0, 0);
  451. int color_lbl = ARGB(255, 255, 255, 255);
  452. ButtonSetColor(w, color_pnl);
  453. ButtonSetAlphaAnim(w);
  454. ButtonSetTextColor(w, color_lbl);
  455. }
  456. void ColorNormal(Widget w)
  457. {
  458. if (!w)
  459. return;
  460. int color_pnl = ARGB(0, 0, 0, 0);
  461. int color_lbl = ARGB(255, 255, 255, 255);
  462. ButtonSetColor(w, color_pnl);
  463. ButtonSetAlphaAnim(null);
  464. ButtonSetTextColor(w, color_lbl);
  465. }
  466. override bool OnModalResult(Widget w, int x, int y, int code, int result)
  467. {
  468. if (code == IDC_MAIN_QUIT)
  469. {
  470. if (result == 2)
  471. {
  472. GetGame().GetCallQueue(CALL_CATEGORY_GUI).Call(g_Game.RequestExit, IDC_MAIN_QUIT);
  473. }
  474. return true;
  475. }
  476. else if (code == 555)
  477. {
  478. if (result == 2)
  479. {
  480. OpenMenuTutorials();
  481. }
  482. }
  483. return false;
  484. }
  485. void ButtonSetText(Widget w, string text)
  486. {
  487. if (!w)
  488. return;
  489. TextWidget label = TextWidget.Cast(w.FindWidget(w.GetName() + "_label"));
  490. if (label)
  491. {
  492. label.SetText(text);
  493. }
  494. }
  495. void ButtonSetColor(Widget w, int color)
  496. {
  497. if (!w)
  498. return;
  499. Widget panel = w.FindWidget(w.GetName() + "_panel");
  500. if (panel)
  501. {
  502. panel.SetColor(color);
  503. }
  504. }
  505. void ButtonSetAlphaAnim(Widget w)
  506. {
  507. if (!w)
  508. return;
  509. Widget panel = w.FindWidget(w.GetName() + "_panel");
  510. if (panel)
  511. {
  512. SetWidgetAnimAlpha(panel);
  513. }
  514. }
  515. void ButtonSetTextColor(Widget w, int color)
  516. {
  517. if (!w)
  518. return;
  519. TextWidget label = TextWidget.Cast(w.FindAnyWidget(w.GetName() + "_label"));
  520. TextWidget text = TextWidget.Cast(w.FindAnyWidget(w.GetName() + "_text"));
  521. TextWidget text2 = TextWidget.Cast(w.FindAnyWidget(w.GetName() + "_text_1"));
  522. if (label)
  523. {
  524. label.SetColor(color);
  525. }
  526. if (text)
  527. {
  528. text.SetColor(color);
  529. }
  530. if (text2)
  531. {
  532. text2.SetColor(color);
  533. }
  534. }
  535. protected void UpdateControlsElements()
  536. {
  537. RichTextWidget toolbar_text = RichTextWidget.Cast(layoutRoot.FindAnyWidget("ContextToolbarText"));
  538. string context;
  539. if (!FeedbackDialogVisible())
  540. {
  541. context = InputUtils.GetRichtextButtonIconFromInputAction("UAUICredits", "#menu_credits", EUAINPUT_DEVICE_CONTROLLER, InputUtils.ICON_SCALE_TOOLBAR);
  542. #ifndef PLATFORM_PS4
  543. context += string.Format(" %1",InputUtils.GetRichtextButtonIconFromInputAction("UAUICtrlY", "#layout_xbox_main_menu_toolbar_account", EUAINPUT_DEVICE_CONTROLLER, InputUtils.ICON_SCALE_TOOLBAR));
  544. #endif
  545. context += string.Format(" %1",InputUtils.GetRichtextButtonIconFromInputAction("UAUISelect", "#layout_xbox_main_menu_toolbar_select", EUAINPUT_DEVICE_CONTROLLER, InputUtils.ICON_SCALE_TOOLBAR));
  546. context += string.Format(" %1",InputUtils.GetRichtextButtonIconFromInputAction("UAUIThumbRight", "#layout_main_menu_feedback", EUAINPUT_DEVICE_CONTROLLER, InputUtils.ICON_SCALE_TOOLBAR));
  547. }
  548. else
  549. {
  550. context = InputUtils.GetRichtextButtonIconFromInputAction("UAUIBack", "#close", EUAINPUT_DEVICE_CONTROLLER, InputUtils.ICON_SCALE_TOOLBAR);
  551. }
  552. toolbar_text.SetText(context);
  553. }
  554. protected void UpdateControlsElementVisibility()
  555. {
  556. bool toolbarShow = false;
  557. #ifdef PLATFORM_CONSOLE
  558. toolbarShow = !GetGame().GetInput().IsEnabledMouseAndKeyboard() || GetGame().GetInput().GetCurrentInputDevice() == EInputDeviceType.CONTROLLER;
  559. #endif
  560. layoutRoot.FindAnyWidget("toolbar_bg").Show(toolbarShow);
  561. }
  562. }