ingamemenuxbox.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905
  1. class InGameMenuXbox extends UIScriptedMenu
  2. {
  3. // Widgets texts id
  4. protected string m_MuteButtonTextID;
  5. protected string m_UnmuteButtonTextID;
  6. protected string m_BackButtonTextID;
  7. protected string m_SelectButtonTextID;
  8. protected string m_OpenGameCardButtonTextID;
  9. protected string m_CurrentMuteButtonText;
  10. protected bool m_SelectAvailable;
  11. protected bool m_MuteAvailable;
  12. protected bool m_BackAvailable;
  13. protected bool m_GamercardAvailable;
  14. protected bool m_PlayerAlive;
  15. protected ref PlayerListScriptedWidget m_ServerInfoPanel;
  16. protected Widget m_OnlineMenu;
  17. protected Widget m_IngameMenuPanel;
  18. protected Widget m_DialogPanel;
  19. protected ButtonWidget m_ContinueButton;
  20. protected ButtonWidget m_ExitButton;
  21. protected ButtonWidget m_RestartDeadButton;
  22. protected ButtonWidget m_RestartButton;
  23. protected ButtonWidget m_OptionsButton;
  24. protected ButtonWidget m_InviteButton;
  25. protected ButtonWidget m_ControlsButton;
  26. protected ButtonWidget m_OnlineButton;
  27. protected ButtonWidget m_TutorialsButton;
  28. protected TextWidget m_Version;
  29. protected ButtonWidget m_ShowFeedback;
  30. protected ImageWidget m_FeedbackQRCode;
  31. protected ImageWidget m_FeedbackPlatformIcon;
  32. protected ButtonWidget m_FeedbackClose;
  33. protected RichTextWidget m_FeedbackCloseLabel;
  34. const int BUTTON_XBOX_CONTROLS = 201;
  35. void InGameMenuXbox()
  36. {
  37. GetGame().GetMission().GetOnInputPresetChanged().Insert(OnInputPresetChanged);
  38. GetGame().GetMission().GetOnInputDeviceChanged().Insert(OnInputDeviceChanged);
  39. }
  40. void ~InGameMenuXbox()
  41. {
  42. ClientData.SyncEvent_OnPlayerListUpdate.Remove(SyncEvent_OnRecievedPlayerList);
  43. OnlineServices.m_PermissionsAsyncInvoker.Remove(OnPermissionsUpdate);
  44. Mission mission = GetGame().GetMission();
  45. if (mission)
  46. {
  47. IngameHud hud = IngameHud.Cast(mission.GetHud());
  48. if (hud)
  49. {
  50. hud.ShowHudUI(true);
  51. hud.ShowQuickbarUI(true);
  52. }
  53. mission.Continue();
  54. }
  55. PPERequesterBank.GetRequester(PPERequester_MenuEffects).Stop();
  56. }
  57. protected void OnInputPresetChanged()
  58. {
  59. #ifdef PLATFORM_CONSOLE
  60. UpdateControlsElements();
  61. #endif
  62. }
  63. protected void OnInputDeviceChanged(EInputDeviceType pInputDeviceType)
  64. {
  65. bool mk = GetGame().GetInput().IsEnabledMouseAndKeyboard();
  66. bool mkServer = GetGame().GetInput().IsEnabledMouseAndKeyboardEvenOnServer();
  67. switch (pInputDeviceType)
  68. {
  69. case EInputDeviceType.CONTROLLER:
  70. if (mk && mkServer)
  71. {
  72. GetGame().GetUIManager().ShowUICursor(false);
  73. if (!GetFocus() || GetFocus() == m_FeedbackClose)
  74. {
  75. UpdateMenuFocus();
  76. }
  77. m_FeedbackClose.Show(false);
  78. m_ShowFeedback.Show(false);
  79. }
  80. break;
  81. default:
  82. if (mk && mkServer)
  83. {
  84. GetGame().GetUIManager().ShowUICursor(true);
  85. m_ShowFeedback.Show(true);
  86. m_FeedbackClose.Show(true);
  87. m_FeedbackCloseLabel.SetText(string.Format("%1",InputUtils.GetRichtextButtonIconFromInputAction("UAUIBack", "#close", EUAINPUT_DEVICE_CONTROLLER, InputUtils.ICON_SCALE_NORMAL)));
  88. }
  89. break;
  90. }
  91. UpdateControlsElements();
  92. }
  93. override Widget Init()
  94. {
  95. layoutRoot = GetGame().GetWorkspace().CreateWidgets("gui/layouts/xbox/day_z_ingamemenu_xbox.layout");
  96. m_OnlineMenu = GetGame().GetWorkspace().CreateWidgets("gui/layouts/xbox/ingamemenu_xbox/online_info_menu.layout", layoutRoot);
  97. m_OnlineMenu.Show(false);
  98. m_IngameMenuPanel = layoutRoot.FindAnyWidget("ingame_menu_panel");
  99. m_ContinueButton = ButtonWidget.Cast(layoutRoot.FindAnyWidget("continuebtn"));
  100. m_RestartDeadButton = ButtonWidget.Cast(layoutRoot.FindAnyWidget("restartbtn_dead"));
  101. m_ExitButton = ButtonWidget.Cast(layoutRoot.FindAnyWidget("exitbtn"));
  102. m_RestartButton = ButtonWidget.Cast(layoutRoot.FindAnyWidget("restartbtn"));
  103. m_OptionsButton = ButtonWidget.Cast(layoutRoot.FindAnyWidget("optionsbtn"));
  104. m_InviteButton = ButtonWidget.Cast(layoutRoot.FindAnyWidget("invitebtn"));
  105. m_ControlsButton = ButtonWidget.Cast(layoutRoot.FindAnyWidget("controlsbtn"));
  106. m_OnlineButton = ButtonWidget.Cast(layoutRoot.FindAnyWidget("onlinebtn"));
  107. m_TutorialsButton = ButtonWidget.Cast(layoutRoot.FindAnyWidget("tutorialsbtn"));
  108. m_Version = TextWidget.Cast(layoutRoot.FindAnyWidget("version"));
  109. m_ShowFeedback = ButtonWidget.Cast(layoutRoot.FindAnyWidget("feedbackbtn"));
  110. m_FeedbackQRCode = ImageWidget.Cast(layoutRoot.FindAnyWidget("qr_image"));
  111. m_FeedbackClose = ButtonWidget.Cast(layoutRoot.FindAnyWidget("close_button"));
  112. m_FeedbackCloseLabel = RichTextWidget.Cast(layoutRoot.FindAnyWidget("close_button_label"));
  113. m_DialogPanel = layoutRoot.FindAnyWidget("ingame_menu_dialog");
  114. m_SelectAvailable = true;
  115. m_MuteAvailable = false;
  116. m_GamercardAvailable = false;
  117. m_BackAvailable = true;
  118. PlayerBase player = PlayerBase.Cast(GetGame().GetPlayer());
  119. if (player)
  120. {
  121. m_PlayerAlive = player.GetPlayerState() == EPlayerStates.ALIVE;
  122. if (!m_PlayerAlive)
  123. m_BackAvailable = false;
  124. player.GetOnUnconsciousStart().Insert(UpdateGUI);
  125. player.GetOnUnconsciousStart().Insert(UpdateMenuFocus);
  126. player.GetOnUnconsciousStop().Insert(UpdateGUI);
  127. player.GetOnUnconsciousStop().Insert(UpdateMenuFocus);
  128. player.GetOnDeathStart().Insert(UpdateGUI);
  129. player.GetOnDeathStart().Insert(UpdateMenuFocus);
  130. }
  131. string version;
  132. GetGame().GetVersion(version);
  133. #ifdef PLATFORM_CONSOLE
  134. version = "#main_menu_version" + " " + version + " (" + g_Game.GetDatabaseID() + ")";
  135. #else
  136. version = "#main_menu_version" + " " + version;
  137. #endif
  138. m_Version.SetText(version);
  139. if (GetGame().IsMultiplayer())
  140. {
  141. m_OnlineButton.Show(true);
  142. TextWidget w_text = TextWidget.Cast(m_OnlineMenu.FindAnyWidget("OnlineTextWidget"));
  143. w_text.SetText(g_Game.GetHostName());
  144. m_ServerInfoPanel = new PlayerListScriptedWidget(m_OnlineMenu.FindAnyWidget("ServerInfoPanel"));
  145. OnlineServices.m_PermissionsAsyncInvoker.Insert(OnPermissionsUpdate);
  146. ClientData.SyncEvent_OnPlayerListUpdate.Insert(SyncEvent_OnRecievedPlayerList);
  147. m_ServerInfoPanel.Reload(ClientData.m_PlayerList);
  148. m_ServerInfoPanel.ReloadLocal(OnlineServices.GetMuteList());
  149. string uid = m_ServerInfoPanel.FindPlayerByWidget(GetFocus());
  150. if (uid != "")
  151. {
  152. if (IsLocalPlayer(uid) || m_ServerInfoPanel.IsEmpty())
  153. {
  154. m_MuteAvailable = false;
  155. m_GamercardAvailable = false;
  156. }
  157. else
  158. {
  159. m_MuteAvailable = !GetGame().GetWorld().IsDisabledReceivingVoN();
  160. #ifndef PLATFORM_PS4
  161. m_GamercardAvailable = true;
  162. #endif
  163. SetMuteButtonText(OnlineServices.IsPlayerMuted(uid));
  164. }
  165. if (m_ServerInfoPanel.IsGloballyMuted(uid))
  166. {
  167. m_MuteAvailable = false;
  168. }
  169. }
  170. }
  171. else
  172. {
  173. layoutRoot.FindAnyWidget("onlinebtn").Show(false);
  174. layoutRoot.FindAnyWidget("invitebtn").Show(false);
  175. }
  176. //RESPAWN & RESTART
  177. if (GetGame().IsMultiplayer())
  178. {
  179. m_RestartButton.SetText("#main_menu_respawn");
  180. }
  181. else
  182. {
  183. m_RestartButton.SetText("#main_menu_restart");
  184. }
  185. if (!ShouldRestartBeVisible(player))
  186. {
  187. //m_RestartButton.Enable(false);
  188. m_RestartButton.Show(false);
  189. }
  190. Mission mission = GetGame().GetMission();
  191. if (mission)
  192. {
  193. IngameHud hud = IngameHud.Cast(mission.GetHud());
  194. if (hud)
  195. {
  196. hud.ShowHudUI(false);
  197. hud.ShowQuickbarUI(false);
  198. }
  199. mission.Pause();
  200. }
  201. PPERequester_MenuEffects requester;
  202. Class.CastTo(requester,PPERequesterBank.GetRequester(PPERequester_MenuEffects));
  203. requester.SetVignetteIntensity(0.6);
  204. LoadTextStrings();
  205. LoadFooterButtonTexts();
  206. #ifdef PLATFORM_PS4
  207. m_FeedbackQRCode.LoadImageFile(0, "gui/textures/feedback_qr_ps.edds");
  208. #else
  209. m_FeedbackQRCode.LoadImageFile(0, "gui/textures/feedback_qr_xbox.edds");
  210. #endif
  211. return layoutRoot;
  212. }
  213. override bool OnClick(Widget w, int x, int y, int button)
  214. {
  215. super.OnClick(w, x, y, button);
  216. if (!FeedbackDialogVisible())
  217. {
  218. switch (w.GetUserID())
  219. {
  220. case IDC_MAIN_CONTINUE:
  221. {
  222. GetGame().GetCallQueue(CALL_CATEGORY_GUI).Call(GetGame().GetMission().Continue);
  223. return true;
  224. }
  225. case IDC_MAIN_OPTIONS:
  226. {
  227. EnterScriptedMenu(MENU_OPTIONS);
  228. return true;
  229. }
  230. case BUTTON_XBOX_CONTROLS:
  231. {
  232. EnterScriptedMenu(MENU_XBOX_CONTROLS);
  233. return true;
  234. }
  235. case IDC_MAIN_QUIT:
  236. {
  237. GetGame().GetUIManager().ShowDialog("#main_menu_exit", "#main_menu_exit_desc", IDC_INT_EXIT, DBT_YESNO, DBB_YES, DMT_QUESTION, NULL);
  238. return true;
  239. }
  240. case IDC_INT_RETRY:
  241. {
  242. if (!GetGame().IsMultiplayer())
  243. {
  244. GetGame().GetUIManager().ShowDialog("#main_menu_restart", "Are you sure you want to restart?", IDC_INT_RETRY, DBT_YESNO, DBB_YES, DMT_QUESTION, this);
  245. }
  246. else
  247. {
  248. GetGame().GetUIManager().ShowDialog("#main_menu_respawn", "#main_menu_respawn_question", IDC_INT_RETRY, DBT_YESNO, DBB_YES, DMT_QUESTION, this);
  249. }
  250. return true;
  251. }
  252. case IDC_MAIN_ONLINE:
  253. {
  254. m_OnlineMenu.Show(true);
  255. m_SelectAvailable = false;
  256. UpdateControlsElements();
  257. m_ServerInfoPanel.FocusFirst();
  258. return true;
  259. }
  260. case IDC_MAIN_TUTORIAL:
  261. {
  262. EnterScriptedMenu(MENU_TUTORIAL);
  263. return true;
  264. }
  265. case IDC_MULTI_INVITE:
  266. {
  267. OnlineServices.ShowInviteScreen();
  268. return true;
  269. }
  270. }
  271. if (w == layoutRoot.FindAnyWidget("backbtn"))
  272. {
  273. CloseOnline();
  274. }
  275. else if (w == m_RestartDeadButton)
  276. {
  277. if (GetGame().GetMission().GetRespawnModeClient() == GameConstants.RESPAWN_MODE_CUSTOM)
  278. {
  279. GetGame().GetCallQueue(CALL_CATEGORY_GUI).Call(GetGame().GetUIManager().EnterScriptedMenu,MENU_RESPAWN_DIALOGUE,this);
  280. }
  281. else
  282. {
  283. GameRetry(true);
  284. }
  285. return true;
  286. }
  287. }
  288. else
  289. {
  290. if (w == m_FeedbackClose)
  291. {
  292. ToggleFeedbackDialog();
  293. return true;
  294. }
  295. }
  296. if (w.GetUserID() == IDC_MAIN_FEEDBACK && !IsOnlineOpen())
  297. {
  298. ToggleFeedbackDialog();
  299. return true;
  300. }
  301. return false;
  302. }
  303. protected void ToggleFeedbackDialog()
  304. {
  305. bool dialogVisible = FeedbackDialogVisible();
  306. m_DialogPanel.Show(!dialogVisible);
  307. m_IngameMenuPanel.Show(dialogVisible);
  308. if (!dialogVisible)
  309. {
  310. PPERequesterBank.GetRequester(PPERequester_FeedbackBlur).Start();
  311. }
  312. else
  313. {
  314. PPERequesterBank.GetRequester(PPERequester_FeedbackBlur).Stop();
  315. }
  316. UpdateMenuFocus();
  317. UpdateControlsElements();
  318. }
  319. bool FeedbackDialogVisible()
  320. {
  321. return m_DialogPanel.IsVisible();
  322. }
  323. override bool OnModalResult(Widget w, int x, int y, int code, int result)
  324. {
  325. super.OnModalResult(w, x, y, code, result);
  326. if (code == IDC_INT_EXIT && result == DBB_YES)
  327. {
  328. if (GetGame().IsMultiplayer())
  329. {
  330. GetGame().LogoutRequestTime();
  331. GetGame().GetCallQueue(CALL_CATEGORY_GUI).Call(GetGame().GetMission().CreateLogoutMenu, this);
  332. }
  333. else
  334. {
  335. // skip logout screen in singleplayer
  336. GetGame().GetMission().AbortMission();
  337. }
  338. g_Game.CancelLoginTimeCountdown();
  339. return true;
  340. }
  341. else if (code == IDC_INT_EXIT && result == DBB_NO)
  342. {
  343. g_Game.CancelLoginTimeCountdown();
  344. }
  345. else if (code == IDC_INT_RETRY)
  346. {
  347. if (result == DBB_YES)
  348. {
  349. if (GetGame().GetMission().GetRespawnModeClient() == GameConstants.RESPAWN_MODE_CUSTOM)
  350. {
  351. GetGame().GetCallQueue(CALL_CATEGORY_GUI).Call(GetGame().GetUIManager().EnterScriptedMenu,MENU_RESPAWN_DIALOGUE,this);
  352. }
  353. else
  354. {
  355. GameRetry(true);
  356. return true;
  357. }
  358. }
  359. else
  360. {
  361. UpdateMenuFocus();
  362. }
  363. }
  364. return false;
  365. }
  366. void GameRetry(bool random)
  367. {
  368. if (GetGame().IsMultiplayer())
  369. {
  370. //GetGame().GetUIManager().CloseAll();
  371. GetGame().GetMenuDefaultCharacterData(false).SetRandomCharacterForced(random);
  372. GetGame().RespawnPlayer();
  373. PlayerBase player = PlayerBase.Cast(GetGame().GetPlayer());
  374. if (player)
  375. {
  376. player.SimulateDeath(true);
  377. GetGame().GetCallQueue(CALL_CATEGORY_GUI).Call(player.ShowDeadScreen, true, 0);
  378. }
  379. MissionGameplay missionGP = MissionGameplay.Cast(GetGame().GetMission());
  380. missionGP.DestroyAllMenus();
  381. missionGP.SetPlayerRespawning(true);
  382. missionGP.Continue();
  383. Close();
  384. }
  385. else
  386. GetGame().RestartMission();
  387. }
  388. void MenuRequestRespawn(UIScriptedMenu menu, bool random)
  389. {
  390. if (RespawnDialogue.Cast(menu))
  391. GameRetry(random);
  392. }
  393. bool IsLocalPlayer(string uid)
  394. {
  395. PlayerBase player = PlayerBase.Cast(GetGame().GetPlayer());
  396. string local_uid;
  397. if (GetGame().GetUserManager())
  398. local_uid = GetGame().GetUserManager().GetSelectedUser().GetUid();
  399. return (uid == local_uid);
  400. }
  401. SyncPlayerList CreateFakePlayerList(int player_count)
  402. {
  403. SyncPlayerList player_list = new SyncPlayerList;
  404. player_list.m_PlayerList = new array<ref SyncPlayer>;
  405. for (int i = 0; i < player_count; i++)
  406. {
  407. SyncPlayer sync_player = new SyncPlayer;
  408. sync_player.m_UID = "uid" + i;
  409. sync_player.m_PlayerName = "Player " + i;
  410. player_list.m_PlayerList.Insert(sync_player);
  411. }
  412. return player_list;
  413. }
  414. override void Update(float timeslice)
  415. {
  416. super.Update(timeslice);
  417. if (GetUApi().GetInputByID(UAUIThumbRight).LocalPress() && !IsOnlineOpen() || FeedbackDialogVisible() && GetUApi().GetInputByID(UAUIBack).LocalPress())
  418. {
  419. ToggleFeedbackDialog();
  420. }
  421. if (GetGame().IsMultiplayer() && layoutRoot.FindAnyWidget("OnlineInfo").IsVisible())
  422. {
  423. PlayerListEntryScriptedWidget selected;
  424. if (m_ServerInfoPanel)
  425. selected = m_ServerInfoPanel.GetSelectedPlayer();
  426. if (GetUApi().GetInputByID(UAUICtrlX).LocalPress())
  427. {
  428. if (selected)
  429. m_ServerInfoPanel.ToggleMute(selected.GetUID());
  430. Refresh();
  431. }
  432. #ifndef PLATFORM_PS4
  433. if (GetUApi().GetInputByID(UAUICtrlY).LocalPress())
  434. {
  435. if (selected)
  436. OnlineServices.ShowUserProfile(selected.GetUID());
  437. }
  438. #endif
  439. }
  440. }
  441. bool ShouldRestartBeVisible(Man player)
  442. {
  443. PlayerBase p = PlayerBase.Cast(player);
  444. return p && p.IsUnconsciousStateOnly() && !CfgGameplayHandler.GetDisableRespawnInUnconsciousness();
  445. }
  446. void UpdateGUI()
  447. {
  448. bool shouldUpdateMenuFocus = false;
  449. Man player = GetGame().GetPlayer();
  450. if (player)
  451. m_PlayerAlive = player.GetPlayerState() == EPlayerStates.ALIVE;
  452. if (m_PlayerAlive)
  453. {
  454. bool showRestartBtn = ShouldRestartBeVisible(player);
  455. m_RestartButton.Show(showRestartBtn);
  456. }
  457. else
  458. {
  459. m_RestartButton.Show(false);
  460. m_BackAvailable = false;
  461. }
  462. m_ContinueButton.Show(m_PlayerAlive);
  463. m_RestartDeadButton.Show(!m_PlayerAlive);
  464. UpdateMenuFocus();
  465. }
  466. bool IsOnlineOpen()
  467. {
  468. return m_OnlineMenu.IsVisible();
  469. }
  470. void CloseOnline()
  471. {
  472. m_OnlineMenu.Show(false);
  473. m_SelectAvailable = true;
  474. m_MuteAvailable = false;
  475. m_GamercardAvailable = false;
  476. UpdateControlsElements();
  477. SetFocus(m_OnlineButton);
  478. }
  479. void SelectServer()
  480. {
  481. if (m_ServerInfoPanel)
  482. {
  483. m_ServerInfoPanel.FocusFirst();
  484. Refresh();
  485. }
  486. }
  487. override bool OnItemSelected(Widget w, int x, int y, int row, int column, int oldRow, int oldColumn)
  488. {
  489. return false;
  490. }
  491. void SyncEvent_OnRecievedPlayerList(SyncPlayerList player_list)
  492. {
  493. m_ServerInfoPanel.Reload(player_list);
  494. Refresh();
  495. }
  496. void OnPermissionsUpdate(BiosPrivacyUidResultArray result_list)
  497. {
  498. m_ServerInfoPanel.Reload(result_list);
  499. Refresh();
  500. }
  501. override void OnShow()
  502. {
  503. super.OnShow();
  504. #ifdef PLATFORM_CONSOLE
  505. bool mk = GetGame().GetInput().IsEnabledMouseAndKeyboard();
  506. bool mk_server = GetGame().GetInput().IsEnabledMouseAndKeyboardEvenOnServer();
  507. TextWidget warning = TextWidget.Cast(layoutRoot.FindAnyWidget("MouseAndKeyboardWarning"));
  508. if (mk)
  509. {
  510. if (mk_server)
  511. {
  512. warning.SetText("#str_mouse_and_keyboard_server_warning");
  513. }
  514. else
  515. {
  516. warning.SetText("#str_controller_server_warning");
  517. }
  518. }
  519. warning.Show(mk);
  520. #endif
  521. UpdateGUI();
  522. UpdateMenuFocus();
  523. OnInputDeviceChanged(GetGame().GetInput().GetCurrentInputDevice());
  524. }
  525. override bool OnMouseEnter(Widget w, int x, int y)
  526. {
  527. if (IsFocusable(w))
  528. {
  529. ColorHighlight(w);
  530. return true;
  531. }
  532. return false;
  533. }
  534. override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
  535. {
  536. if (IsFocusable(w))
  537. {
  538. ColorNormal(w);
  539. return true;
  540. }
  541. return false;
  542. }
  543. override bool OnFocus(Widget w, int x, int y)
  544. {
  545. if (IsFocusable(w))
  546. {
  547. ColorHighlight(w);
  548. return true;
  549. }
  550. return false;
  551. }
  552. override bool OnFocusLost(Widget w, int x, int y)
  553. {
  554. if (IsFocusable(w))
  555. {
  556. ColorNormal(w);
  557. return true;
  558. }
  559. return false;
  560. }
  561. bool IsFocusable(Widget w)
  562. {
  563. if (w)
  564. {
  565. if (w == m_ContinueButton || w == m_RestartDeadButton || w == m_ExitButton || w == m_RestartButton || w == m_OptionsButton || w == m_InviteButton || w == m_ControlsButton || w == m_OnlineButton || w == m_TutorialsButton || w == m_ShowFeedback)
  566. return true;
  567. }
  568. return false;
  569. }
  570. override void Refresh()
  571. {
  572. string version;
  573. GetGame().GetVersion(version);
  574. #ifdef PLATFORM_CONSOLE
  575. version = "#main_menu_version" + " " + version + " (" + g_Game.GetDatabaseID() + ")";
  576. #else
  577. version = "#main_menu_version" + " " + version;
  578. #endif
  579. m_Version.SetText(version);
  580. m_MuteAvailable = false;
  581. m_GamercardAvailable = false;
  582. if (GetGame().IsMultiplayer() && layoutRoot.FindAnyWidget("OnlineInfo").IsVisible() && m_ServerInfoPanel)
  583. {
  584. PlayerListEntryScriptedWidget selected = m_ServerInfoPanel.GetSelectedPlayer();
  585. if (selected && !selected.IsLocalPlayer())
  586. {
  587. m_MuteAvailable = !GetGame().GetWorld().IsDisabledReceivingVoN() && !selected.IsGloballyMuted();
  588. #ifndef PLATFORM_PS4
  589. m_GamercardAvailable = true;
  590. #endif
  591. SetMuteButtonText(selected.IsMuted());
  592. }
  593. }
  594. UpdateControlsElements();
  595. }
  596. void ColorDisable(Widget w)
  597. {
  598. #ifdef PLATFORM_WINDOWS
  599. SetFocus(null);
  600. #endif
  601. ButtonWidget button = ButtonWidget.Cast(w);
  602. if (button && button != m_ContinueButton)
  603. {
  604. button.SetTextColor(ARGB(255, 255, 255, 255));
  605. }
  606. ButtonSetColor(w, ARGB(0, 0, 0, 0));
  607. ButtonSetTextColor(w, ARGB(60, 0, 0, 0));
  608. }
  609. void ColorHighlight(Widget w)
  610. {
  611. if (!w)
  612. return;
  613. int color_pnl = ARGB(255, 0, 0, 0);
  614. int color_lbl = ARGB(255, 255, 0, 0);
  615. #ifdef PLATFORM_CONSOLE
  616. color_pnl = ARGB(255, 200, 0, 0);
  617. color_lbl = ARGB(255, 255, 255, 255);
  618. #endif
  619. ButtonSetColor(w, color_pnl);
  620. ButtonSetTextColor(w, color_lbl);
  621. }
  622. void ColorNormal(Widget w)
  623. {
  624. if (!w)
  625. return;
  626. int color_pnl = ARGB(0, 0, 0, 0);
  627. int color_lbl = ARGB(255, 255, 255, 255);
  628. ButtonSetColor(w, color_pnl);
  629. ButtonSetTextColor(w, color_lbl);
  630. }
  631. void ButtonSetText(Widget w, string text)
  632. {
  633. if (!w)
  634. return;
  635. TextWidget label = TextWidget.Cast(w.FindWidget(w.GetName() + "_label"));
  636. if (label)
  637. {
  638. label.SetText(text);
  639. }
  640. }
  641. void ButtonSetColor(Widget w, int color)
  642. {
  643. if (!w)
  644. return;
  645. Widget panel = w.FindWidget(w.GetName() + "_panel");
  646. if (panel)
  647. {
  648. panel.SetColor(color);
  649. }
  650. }
  651. void ButtonSetTextColor(Widget w, int color)
  652. {
  653. if (!w)
  654. return;
  655. TextWidget label = TextWidget.Cast(w.FindAnyWidget(w.GetName() + "_label"));
  656. TextWidget text = TextWidget.Cast(w.FindAnyWidget(w.GetName() + "_text"));
  657. TextWidget text2 = TextWidget.Cast(w.FindAnyWidget(w.GetName() + "_text_1"));
  658. if (label)
  659. {
  660. label.SetColor(color);
  661. }
  662. if (text)
  663. {
  664. text.SetColor(color);
  665. }
  666. if (text2)
  667. {
  668. text2.SetColor(color);
  669. }
  670. }
  671. /// Set mute text button text (mute / unmute)
  672. protected void SetMuteButtonText(bool isMuted)
  673. {
  674. if (isMuted)
  675. {
  676. m_CurrentMuteButtonText = m_UnmuteButtonTextID;
  677. }
  678. else
  679. {
  680. m_CurrentMuteButtonText = m_MuteButtonTextID;
  681. }
  682. }
  683. /// Set correct bottom button texts based on platform (ps4 vs xbox texts)
  684. protected void LoadTextStrings()
  685. {
  686. #ifdef PLATFORM_PS4
  687. m_MuteButtonTextID = "#ps4_ingame_menu_mute";
  688. m_UnmuteButtonTextID = "#ps4_ingame_menu_unmute";
  689. m_BackButtonTextID = "#ps4_ingame_menu_back";
  690. m_SelectButtonTextID = "#ps4_ingame_menu_select";
  691. m_OpenGameCardButtonTextID = "#ps4_ingame_menu_opencard";
  692. #else
  693. m_MuteButtonTextID = "#xbox_ingame_menu_mute";
  694. m_UnmuteButtonTextID = "#xbox_ingame_menu_unmute";
  695. m_BackButtonTextID = "#STR_rootFrame_toolbar_bg_ConsoleToolbar_Back_BackText0";
  696. m_SelectButtonTextID = "#layout_xbox_ingame_menu_select";
  697. m_OpenGameCardButtonTextID = "#layout_xbox_ingame_menu_gamecard";
  698. #endif
  699. }
  700. /// Initial texts load for the footer buttons
  701. protected void LoadFooterButtonTexts()
  702. {
  703. TextWidget uiGamecardText = TextWidget.Cast(layoutRoot.FindAnyWidget("GamercardText"));
  704. TextWidget uiBackText = TextWidget.Cast(layoutRoot.FindAnyWidget("BackText"));
  705. TextWidget uiSelectText = TextWidget.Cast(layoutRoot.FindAnyWidget("SelectText"));
  706. if (uiGamecardText)
  707. {
  708. uiGamecardText.SetText(m_OpenGameCardButtonTextID);
  709. }
  710. if (uiBackText)
  711. {
  712. uiBackText.SetText(m_BackButtonTextID);
  713. }
  714. if (uiSelectText)
  715. {
  716. uiSelectText.SetText(m_SelectButtonTextID);
  717. }
  718. }
  719. void UpdateMenuFocus()
  720. {
  721. Man player = GetGame().GetPlayer();
  722. if (m_PlayerAlive)
  723. {
  724. if (ShouldRestartBeVisible(player))
  725. SetFocus(m_RestartButton);
  726. else
  727. SetFocus(m_ContinueButton);
  728. }
  729. else
  730. {
  731. SetFocus(m_RestartDeadButton);
  732. }
  733. }
  734. protected void UpdateControlsElements()
  735. {
  736. bool toolbarShow = false;
  737. #ifdef PLATFORM_CONSOLE
  738. toolbarShow = !GetGame().GetInput().IsEnabledMouseAndKeyboardEvenOnServer() || GetGame().GetInput().GetCurrentInputDevice() == EInputDeviceType.CONTROLLER;
  739. #endif
  740. if (toolbarShow)
  741. {
  742. RichTextWidget toolbar_text = RichTextWidget.Cast(layoutRoot.FindAnyWidget("ContextToolbarText"));
  743. string text = "";
  744. if (!FeedbackDialogVisible())
  745. {
  746. if (m_SelectAvailable)
  747. text += string.Format(" %1",InputUtils.GetRichtextButtonIconFromInputAction("UAUISelect", m_SelectButtonTextID, EUAINPUT_DEVICE_CONTROLLER, InputUtils.ICON_SCALE_TOOLBAR));
  748. if (m_MuteAvailable)
  749. text += string.Format(" %1",InputUtils.GetRichtextButtonIconFromInputAction("UAUICtrlX", m_CurrentMuteButtonText, EUAINPUT_DEVICE_CONTROLLER, InputUtils.ICON_SCALE_TOOLBAR));
  750. if (m_BackAvailable)
  751. text += string.Format(" %1",InputUtils.GetRichtextButtonIconFromInputAction("UAUIBack", m_BackButtonTextID, EUAINPUT_DEVICE_CONTROLLER, InputUtils.ICON_SCALE_TOOLBAR));
  752. if (m_GamercardAvailable)
  753. text += string.Format(" %1",InputUtils.GetRichtextButtonIconFromInputAction("UAUICtrlY", m_OpenGameCardButtonTextID, EUAINPUT_DEVICE_CONTROLLER, InputUtils.ICON_SCALE_TOOLBAR));
  754. if (!IsOnlineOpen())
  755. text += string.Format(" %1",InputUtils.GetRichtextButtonIconFromInputAction("UAUIThumbRight", "#layout_main_menu_feedback", EUAINPUT_DEVICE_CONTROLLER, InputUtils.ICON_SCALE_TOOLBAR));
  756. }
  757. else
  758. {
  759. text = InputUtils.GetRichtextButtonIconFromInputAction("UAUIBack", "#close", EUAINPUT_DEVICE_CONTROLLER, InputUtils.ICON_SCALE_TOOLBAR);
  760. }
  761. toolbar_text.SetText(text);
  762. }
  763. RichTextWidget toolbar_b2 = RichTextWidget.Cast(layoutRoot.FindAnyWidget("BackIcon0"));
  764. toolbar_b2.SetText(InputUtils.GetRichtextButtonIconFromInputAction("UAUIBack", "", EUAINPUT_DEVICE_CONTROLLER));
  765. bool onlineOpen = IsOnlineOpen();
  766. layoutRoot.FindAnyWidget("toolbar_bg").Show(toolbarShow);
  767. layoutRoot.FindAnyWidget("play_panel_root").Show(!onlineOpen);
  768. layoutRoot.FindAnyWidget("play_panel_root2").Show(onlineOpen && !toolbarShow);
  769. layoutRoot.FindAnyWidget("dayz_logo").Show(!onlineOpen);
  770. }
  771. override void OnHide()
  772. {
  773. super.OnHide();
  774. if (FeedbackDialogVisible())
  775. {
  776. ToggleFeedbackDialog();
  777. }
  778. }
  779. }