mainmenuconsoles.c 12 KB

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