ingamemenuxbox.c 24 KB

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