mainmenu.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711
  1. class MainMenu extends UIScriptedMenu
  2. {
  3. protected ref MainMenuStats m_Stats;
  4. protected ref MainMenuVideo m_Video;
  5. protected MissionMainMenu m_Mission;
  6. protected DayZIntroScenePC m_ScenePC;
  7. protected TextWidget m_PlayerName;
  8. protected TextWidget m_Version;
  9. protected Widget m_CharacterRotationFrame;
  10. protected Widget m_Play;
  11. protected Widget m_ChooseServer;
  12. protected Widget m_CustomizeCharacter;
  13. protected Widget m_PlayVideo;
  14. protected Widget m_Tutorials;
  15. protected Widget m_TutorialButton;
  16. protected Widget m_MessageButton;
  17. protected Widget m_SettingsButton;
  18. protected Widget m_Exit;
  19. protected Widget m_NewsMain;
  20. protected Widget m_NewsSec1;
  21. protected Widget m_NewsSec2;
  22. protected Widget m_PrevCharacter;
  23. protected Widget m_NextCharacter;
  24. protected Widget m_LastPlayedTooltip;
  25. protected Widget m_LastPlayedTooltipLabel;
  26. protected TextWidget m_LastPlayedTooltipName;
  27. protected TextWidget m_LastPlayedTooltipIP;
  28. protected TextWidget m_LastPlayedTooltipPort;
  29. protected ref WidgetFadeTimer m_LastPlayedTooltipTimer;
  30. protected ref Widget m_LastFocusedButton;
  31. protected ref TextWidget m_ModdedWarning;
  32. protected ref ModsMenuSimple m_ModsSimple;
  33. protected ref ModsMenuDetailed m_ModsDetailed;
  34. protected ref ModsMenuTooltip m_ModsTooltip;
  35. protected Widget m_DlcFrame;
  36. protected ref map<string,ref ModInfo> m_AllDlcsMap;
  37. protected ref JsonDataDLCList m_DlcData;
  38. protected ref array<ref MainMenuDlcHandlerBase> m_DlcHandlers;
  39. protected ref MainMenuDlcHandlerBase m_DisplayedDlcHandler;
  40. override Widget Init()
  41. {
  42. layoutRoot = GetGame().GetWorkspace().CreateWidgets("gui/layouts/new_ui/main_menu.layout");
  43. m_Play = layoutRoot.FindAnyWidget("play");
  44. m_ChooseServer = layoutRoot.FindAnyWidget("choose_server");
  45. m_CustomizeCharacter = layoutRoot.FindAnyWidget("customize_character");
  46. m_PlayVideo = layoutRoot.FindAnyWidget("play_video");
  47. m_Tutorials = layoutRoot.FindAnyWidget("tutorials");
  48. m_TutorialButton = layoutRoot.FindAnyWidget("tutorial_button");
  49. m_MessageButton = layoutRoot.FindAnyWidget("message_button");
  50. m_SettingsButton = layoutRoot.FindAnyWidget("settings_button");
  51. m_Exit = layoutRoot.FindAnyWidget("exit_button");
  52. m_PrevCharacter = layoutRoot.FindAnyWidget("prev_character");
  53. m_NextCharacter = layoutRoot.FindAnyWidget("next_character");
  54. m_DlcFrame = layoutRoot.FindAnyWidget("dlc_Frame");
  55. m_Version = TextWidget.Cast(layoutRoot.FindAnyWidget("version"));
  56. m_ModdedWarning = TextWidget.Cast(layoutRoot.FindAnyWidget("ModdedWarning"));
  57. m_CharacterRotationFrame = layoutRoot.FindAnyWidget("character_rotation_frame");
  58. m_LastPlayedTooltip = layoutRoot.FindAnyWidget("last_server_info");
  59. m_LastPlayedTooltip.Show(false);
  60. m_LastPlayedTooltipLabel = m_LastPlayedTooltip.FindAnyWidget("last_server_info_label");
  61. m_LastPlayedTooltipName = TextWidget.Cast(m_LastPlayedTooltip.FindAnyWidget("last_server_info_name"));
  62. m_LastPlayedTooltipIP = TextWidget.Cast(m_LastPlayedTooltip.FindAnyWidget("last_server_info_ip"));
  63. m_LastPlayedTooltipPort = TextWidget.Cast(m_LastPlayedTooltip.FindAnyWidget("last_server_info_port"));
  64. m_LastPlayedTooltipTimer = new WidgetFadeTimer();
  65. m_Stats = new MainMenuStats(layoutRoot.FindAnyWidget("character_stats_root"));
  66. m_Mission = MissionMainMenu.Cast(GetGame().GetMission());
  67. m_LastFocusedButton = m_Play;
  68. m_ScenePC = m_Mission.GetIntroScenePC();
  69. if (m_ScenePC)
  70. {
  71. m_ScenePC.ResetIntroCamera();
  72. }
  73. m_PlayVideo.Show(false);
  74. m_PlayerName = TextWidget.Cast(layoutRoot.FindAnyWidget("character_name_text"));
  75. // Set Version
  76. string version;
  77. GetGame().GetVersion(version);
  78. m_Version.SetText("#main_menu_version" + " " + version);
  79. GetGame().GetUIManager().ScreenFadeOut(0);
  80. SetFocus(null);
  81. Refresh();
  82. LoadMods();
  83. PopulateDlcFrame();
  84. GetDayZGame().GetBacklit().MainMenu_OnShow();
  85. GetGame().GetMission().GetOnModMenuVisibilityChanged().Insert(ShowDlcFrame);
  86. g_Game.SetLoadState(DayZLoadState.MAIN_MENU_CONTROLLER_SELECT);
  87. return layoutRoot;
  88. }
  89. void ~MainMenu()
  90. {
  91. if (GetGame().GetMission())
  92. {
  93. GetGame().GetMission().GetOnModMenuVisibilityChanged().Remove(ShowDlcFrame);
  94. }
  95. }
  96. void LoadMods()
  97. {
  98. array<ref ModInfo> modArray = new array<ref ModInfo>();
  99. GetGame().GetModInfos(modArray);
  100. if (modArray.Count() > 0)
  101. {
  102. modArray.Remove(modArray.Count() - 1);
  103. modArray.Invert();
  104. }
  105. FilterDlcs(modArray);
  106. if (m_ModsSimple)
  107. delete m_ModsSimple;
  108. if (m_ModsDetailed)
  109. delete m_ModsDetailed;
  110. m_ModdedWarning.Show(GetGame().GetModToBeReported());
  111. if (modArray.Count() > 0)
  112. {
  113. layoutRoot.FindAnyWidget("ModsSimple").Show(true);
  114. m_ModsTooltip = new ModsMenuTooltip(layoutRoot);
  115. m_ModsDetailed = new ModsMenuDetailed(modArray, layoutRoot.FindAnyWidget("ModsDetailed"), m_ModsTooltip, this);
  116. m_ModsSimple = new ModsMenuSimple(modArray, layoutRoot.FindAnyWidget("ModsSimple"), m_ModsDetailed);
  117. }
  118. }
  119. void FilterDlcs(inout array<ref ModInfo> modArray)
  120. {
  121. if (!m_AllDlcsMap)
  122. m_AllDlcsMap = new map<string,ref ModInfo>();
  123. m_AllDlcsMap.Clear();
  124. int count = modArray.Count();
  125. ModInfo info;
  126. for (int i = count - 1; i > -1; i--)
  127. {
  128. info = modArray[i];
  129. if (info.GetIsDLC())
  130. {
  131. m_AllDlcsMap.Set(info.GetName(),info);
  132. modArray.Remove(i);
  133. }
  134. }
  135. }
  136. void ShowDlcFrame(bool show)
  137. {
  138. m_DlcFrame.Show(show);
  139. if (m_DisplayedDlcHandler)
  140. m_DisplayedDlcHandler.ShowInfoPanel(show);
  141. }
  142. void PopulateDlcFrame()
  143. {
  144. if (!m_DlcHandlers)
  145. m_DlcHandlers = new array<ref MainMenuDlcHandlerBase>();
  146. m_DlcData = DlcDataLoader.GetData();
  147. int count = m_DlcData.DLCs.Count();
  148. JsonDataDLCInfo data;
  149. ModInfo info;
  150. for (int i = 0; i < count; i++)
  151. {
  152. data = m_DlcData.DLCs[i];
  153. info = m_AllDlcsMap.Get(data.Name);
  154. MainMenuDlcHandlerBase handler = new MainMenuDlcHandlerBase(info, m_DlcFrame, data);
  155. handler.ShowInfoPanel(true);
  156. m_DisplayedDlcHandler = handler;//TODO: carousel will take care of this later
  157. m_DlcHandlers.Insert(handler);
  158. }
  159. }
  160. override bool OnMouseButtonDown(Widget w, int x, int y, int button)
  161. {
  162. if (w == m_CharacterRotationFrame)
  163. {
  164. if (m_ScenePC)
  165. m_ScenePC.CharacterRotationStart();
  166. return true;
  167. }
  168. return false;
  169. }
  170. override bool OnMouseButtonUp(Widget w, int x, int y, int button)
  171. {
  172. if (m_ScenePC)
  173. m_ScenePC.CharacterRotationStop();
  174. return false;
  175. }
  176. override bool OnClick(Widget w, int x, int y, int button)
  177. {
  178. if (button == MouseState.LEFT)
  179. {
  180. if (w == m_Play)
  181. {
  182. m_LastFocusedButton = m_Play;
  183. Play();
  184. return true;
  185. }
  186. else if (w == m_ChooseServer)
  187. {
  188. m_LastFocusedButton = m_ChooseServer;
  189. OpenMenuServerBrowser();
  190. return true;
  191. }
  192. else if (w == m_CustomizeCharacter)
  193. {
  194. OpenMenuCustomizeCharacter();
  195. return true;
  196. }
  197. else if (w == m_TutorialButton)
  198. {
  199. OpenTutorials();
  200. return true;
  201. }
  202. else if (w == m_MessageButton)
  203. {
  204. OpenCredits();
  205. return true;
  206. }
  207. else if (w == m_SettingsButton)
  208. {
  209. OpenSettings();
  210. return true;
  211. }
  212. else if (w == m_Exit)
  213. {
  214. Exit();
  215. return true;
  216. }
  217. else if (w == m_PrevCharacter)
  218. {
  219. PreviousCharacter();
  220. return true;
  221. }
  222. else if (w == m_NextCharacter)
  223. {
  224. NextCharacter();
  225. return true;
  226. }
  227. else if (w == m_PlayVideo)
  228. {
  229. m_LastFocusedButton = m_PlayVideo;
  230. PlayVideo();
  231. return true;
  232. }
  233. else if (w == m_Tutorials)
  234. {
  235. m_LastFocusedButton = m_Tutorials;
  236. OpenTutorials();
  237. return true;
  238. }
  239. }
  240. return false;
  241. }
  242. override bool OnMouseEnter(Widget w, int x, int y)
  243. {
  244. if (w == m_Play)
  245. {
  246. string ip = "";
  247. string name = "";
  248. int port = 0;
  249. if (m_ScenePC && !m_ScenePC.GetIntroCharacter().IsDefaultCharacter())
  250. {
  251. int charID = m_ScenePC.GetIntroCharacter().GetCharacterID();
  252. m_ScenePC.GetIntroCharacter().GetLastPlayedServer(charID, ip, name, port);
  253. m_LastPlayedTooltipName.SetText("#server_details_name " + name);
  254. m_LastPlayedTooltipIP.SetText("#main_menu_IP " + ip);
  255. m_LastPlayedTooltipPort.SetText("#main_menu_port " + port);
  256. m_LastPlayedTooltipTimer.FadeIn(m_LastPlayedTooltip, 0.3, true);
  257. }
  258. }
  259. if (IsFocusable(w))
  260. {
  261. ColorHighlight(w);
  262. return true;
  263. }
  264. return false;
  265. }
  266. override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
  267. {
  268. if (w == m_Play)
  269. {
  270. m_LastPlayedTooltipTimer.FadeOut(m_LastPlayedTooltip, 0.3, true);
  271. }
  272. if (IsFocusable(w))
  273. {
  274. ColorNormal(w);
  275. return true;
  276. }
  277. return false;
  278. }
  279. override bool OnFocus(Widget w, int x, int y)
  280. {
  281. if (IsFocusable(w))
  282. {
  283. ColorHighlight(w);
  284. return true;
  285. }
  286. return false;
  287. }
  288. override bool OnFocusLost(Widget w, int x, int y)
  289. {
  290. if (IsFocusable(w))
  291. {
  292. ColorNormal(w);
  293. return true;
  294. }
  295. return false;
  296. }
  297. bool IsFocusable(Widget w)
  298. {
  299. if (w)
  300. {
  301. if (w == m_Play || w == m_ChooseServer || w == m_CustomizeCharacter || w == m_TutorialButton || w == m_MessageButton || w == m_SettingsButton);
  302. {
  303. return true;
  304. }
  305. if (w == m_Exit || w == m_PlayVideo);
  306. {
  307. return true;
  308. }
  309. if (w == m_NewsMain || w == m_NewsSec1 || w == m_NewsSec2 || w == m_PrevCharacter || w == m_NextCharacter);
  310. {
  311. return true;
  312. }
  313. }
  314. return false;
  315. }
  316. override void Refresh()
  317. {
  318. string name;
  319. if (m_ScenePC && g_Game.GetGameState() == DayZGameState.MAIN_MENU)
  320. OnChangeCharacter();
  321. string version;
  322. GetGame().GetVersion(version);
  323. m_Version.SetText("#main_menu_version" + " " + version);
  324. if (m_DisplayedDlcHandler)
  325. m_DisplayedDlcHandler.UpdateAllPromotionInfo();
  326. }
  327. override void OnShow()
  328. {
  329. if (m_DisplayedDlcHandler)
  330. m_DisplayedDlcHandler.ShowInfoPanel(true);
  331. SetFocus(null);
  332. OnChangeCharacter(false);
  333. m_Stats.UpdateStats();
  334. LoadMods();
  335. return;
  336. }
  337. override void OnHide()
  338. {
  339. if (m_DisplayedDlcHandler)
  340. m_DisplayedDlcHandler.ShowInfoPanel(false);
  341. GetDayZGame().GetBacklit().MainMenu_OnHide();
  342. }
  343. override void Update(float timeslice)
  344. {
  345. super.Update(timeslice);
  346. if (GetGame() && GetUApi().GetInputByID(UAUIBack).LocalPress())
  347. {
  348. if (!GetGame().GetUIManager().IsDialogHiding())
  349. {
  350. Exit();
  351. }
  352. }
  353. }
  354. void Play()
  355. {
  356. if (!g_Game.IsNewCharacter())
  357. {
  358. GetGame().GetCallQueue(CALL_CATEGORY_GUI).CallByName(this, "ConnectLastSession");
  359. }
  360. else
  361. {
  362. GetGame().GetCallQueue(CALL_CATEGORY_GUI).CallByName(this, "ConnectBestServer");
  363. }
  364. }
  365. bool CanSaveDefaultCharacter()
  366. {
  367. if (m_ScenePC && m_ScenePC.GetIntroCharacter() && m_ScenePC.GetIntroCharacter().GetCharacterID() == -1)
  368. {
  369. return true;
  370. }
  371. return false;
  372. }
  373. void OpenMenuServerBrowser()
  374. {
  375. EnterScriptedMenu(MENU_SERVER_BROWSER);
  376. }
  377. void OpenMenuCustomizeCharacter()
  378. {
  379. EnterScriptedMenu(MENU_CHARACTER);
  380. }
  381. void NextCharacter()
  382. {
  383. if (m_ScenePC && m_ScenePC.GetIntroCharacter())
  384. {
  385. int charID = m_ScenePC.GetIntroCharacter().GetNextCharacterID();
  386. if (charID != m_ScenePC.GetIntroCharacter().GetCharacterID())
  387. {
  388. m_ScenePC.GetIntroCharacter().SetCharacterID(charID);
  389. OnChangeCharacter();
  390. }
  391. }
  392. }
  393. void PreviousCharacter()
  394. {
  395. if (m_ScenePC && m_ScenePC.GetIntroCharacter())
  396. {
  397. int charID = m_ScenePC.GetIntroCharacter().GetPrevCharacterID();
  398. if (charID != m_ScenePC.GetIntroCharacter().GetCharacterID())
  399. {
  400. m_ScenePC.GetIntroCharacter().SetCharacterID(charID);
  401. OnChangeCharacter();
  402. }
  403. }
  404. }
  405. void OnChangeCharacter(bool create_character = true)
  406. {
  407. if (m_ScenePC && m_ScenePC.GetIntroCharacter())
  408. {
  409. int charID = m_ScenePC.GetIntroCharacter().GetCharacterID();
  410. if (create_character)
  411. {
  412. m_ScenePC.GetIntroCharacter().CreateNewCharacterById(charID);
  413. }
  414. m_PlayerName.SetText(m_ScenePC.GetIntroCharacter().GetCharacterNameById(charID));
  415. Widget w = m_CustomizeCharacter.FindAnyWidget(m_CustomizeCharacter.GetName() + "_label");
  416. if (w)
  417. {
  418. TextWidget text = TextWidget.Cast(w);
  419. if (m_ScenePC.GetIntroCharacter().IsDefaultCharacter())
  420. {
  421. text.SetText("#layout_main_menu_customize_char");
  422. }
  423. else
  424. {
  425. text.SetText("#layout_main_menu_rename");
  426. }
  427. }
  428. if (m_ScenePC.GetIntroCharacter().GetCharacterObj())
  429. {
  430. if (m_ScenePC.GetIntroCharacter().GetCharacterObj().IsMale())
  431. m_ScenePC.GetIntroCharacter().SetCharacterGender(ECharGender.Male);
  432. else
  433. m_ScenePC.GetIntroCharacter().SetCharacterGender(ECharGender.Female);
  434. }
  435. //update character stats
  436. m_Stats.UpdateStats();
  437. }
  438. }
  439. void OpenStats()
  440. {
  441. }
  442. void OpenMessages()
  443. {
  444. }
  445. void OpenSettings()
  446. {
  447. EnterScriptedMenu(MENU_OPTIONS);
  448. }
  449. void PlayVideo()
  450. {
  451. EnterScriptedMenu(MENU_VIDEO);
  452. }
  453. void OpenTutorials()
  454. {
  455. EnterScriptedMenu(MENU_TUTORIAL);
  456. }
  457. void OpenCredits()
  458. {
  459. EnterScriptedMenu(MENU_CREDITS);
  460. m_Mission.OnMenuEnter(MENU_CREDITS);
  461. }
  462. void Exit()
  463. {
  464. GetGame().GetUIManager().ShowDialog("#main_menu_exit", "#main_menu_exit_desc", IDC_MAIN_QUIT, DBT_YESNO, DBB_YES, DMT_QUESTION, this);
  465. }
  466. bool TryConnectLastSession(out string ip, out int port)
  467. {
  468. if (g_Game.GetLastVisitedServer(ip, port))
  469. {
  470. return true;
  471. }
  472. return false;
  473. }
  474. void AutoConnect()
  475. {
  476. OnlineServices.AutoConnectToEmptyServer();
  477. }
  478. void ConnectLastSession()
  479. {
  480. string ip = "";
  481. string name = "";
  482. int port = 0;
  483. int steamQueryPort = 0;
  484. if (!m_ScenePC.GetIntroCharacter().IsDefaultCharacter())
  485. {
  486. int charID = m_ScenePC.GetIntroCharacter().GetCharacterID();
  487. m_ScenePC.GetIntroCharacter().GetLastPlayedServerEx(charID, ip, name, port, steamQueryPort);
  488. }
  489. if (ip.Length() > 0)
  490. {
  491. g_Game.ConnectFromServerBrowserEx(ip, port, steamQueryPort, "");
  492. }
  493. else
  494. {
  495. OpenMenuServerBrowser();
  496. }
  497. }
  498. void ConnectBestServer()
  499. {
  500. ConnectLastSession();
  501. }
  502. override bool OnModalResult(Widget w, int x, int y, int code, int result)
  503. {
  504. if (code == IDC_MAIN_QUIT)
  505. {
  506. if (result == 2)
  507. GetGame().GetCallQueue(CALL_CATEGORY_GUI).Call(g_Game.RequestExit, IDC_MAIN_QUIT);
  508. if (result == 3)
  509. ColorNormal(GetFocus());
  510. return true;
  511. }
  512. else if (code == 555)
  513. {
  514. if (result == 2)
  515. OpenTutorials();
  516. }
  517. return false;
  518. }
  519. //Coloring functions (Until WidgetStyles are useful)
  520. void ColorHighlight(Widget w)
  521. {
  522. if (!w)
  523. return;
  524. int color_pnl = ARGB(255, 0, 0, 0);
  525. int color_lbl = ARGB(255, 255, 0, 0);
  526. int color_img = ARGB(255, 200, 0, 0);
  527. ButtonSetColor(w, color_pnl);
  528. ButtonSetTextColor(w, color_lbl);
  529. ImagenSetColor(w, color_img);
  530. }
  531. void ColorNormal(Widget w)
  532. {
  533. if (!w)
  534. return;
  535. int color_pnl = ARGB(0, 0, 0, 0);
  536. int color_lbl = ARGB(255, 255, 255, 255);
  537. int color_img = ARGB(255, 255, 255, 255);
  538. ButtonSetColor(w, color_pnl);
  539. ButtonSetTextColor(w, color_lbl);
  540. ImagenSetColor(w, color_img);
  541. }
  542. void ButtonSetText(Widget w, string text)
  543. {
  544. if (!w)
  545. return;
  546. TextWidget label = TextWidget.Cast(w.FindWidget(w.GetName() + "_label"));
  547. if (label)
  548. {
  549. label.SetText(text);
  550. }
  551. }
  552. void ButtonSetColor(Widget w, int color)
  553. {
  554. if (!w)
  555. return;
  556. Widget panel = w.FindWidget(w.GetName() + "_panel");
  557. if (panel)
  558. {
  559. panel.SetColor(color);
  560. }
  561. }
  562. void ImagenSetColor(Widget w, int color)
  563. {
  564. if (!w)
  565. return;
  566. Widget panel = w.FindWidget(w.GetName() + "_image");
  567. if (panel)
  568. {
  569. panel.SetColor(color);
  570. }
  571. }
  572. void ButtonSetTextColor(Widget w, int color)
  573. {
  574. if (!w)
  575. return;
  576. TextWidget label = TextWidget.Cast(w.FindAnyWidget(w.GetName() + "_label"));
  577. TextWidget text = TextWidget.Cast(w.FindAnyWidget(w.GetName() + "_text"));
  578. TextWidget text2 = TextWidget.Cast(w.FindAnyWidget(w.GetName() + "_text_1"));
  579. if (label)
  580. {
  581. label.SetColor(color);
  582. }
  583. if (text)
  584. {
  585. text.SetColor(color);
  586. }
  587. if (text2)
  588. {
  589. text2.SetColor(color);
  590. }
  591. }
  592. }