ingamemenu.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  1. class InGameMenu extends UIScriptedMenu
  2. {
  3. string m_ServerInfoText;
  4. protected Widget m_ContinueButton;
  5. protected Widget m_SeparatorPanel;
  6. protected Widget m_ExitButton;
  7. protected Widget m_RestartButton;
  8. protected Widget m_RespawnButton;
  9. protected Widget m_RestartDeadRandomButton;
  10. protected Widget m_RestartDeadCustomButton;
  11. protected Widget m_OptionsButton;
  12. protected Widget m_ServerInfoPanel;
  13. protected Widget m_FavoriteButton;
  14. protected Widget m_FavoriteImage;
  15. protected Widget m_UnfavoriteImage;
  16. protected Widget m_CopyInfoButton;
  17. protected Widget m_FeedbackButton;
  18. protected ref TextWidget m_ModdedWarning;
  19. protected ref TextWidget m_ServerIP;
  20. protected ref TextWidget m_ServerPort;
  21. protected ref TextWidget m_ServerName;
  22. protected ref UiHintPanel m_HintPanel;
  23. void ~InGameMenu()
  24. {
  25. HudShow(true);
  26. Mission mission = g_Game.GetMission();
  27. if (mission)
  28. mission.Continue();
  29. }
  30. override Widget Init()
  31. {
  32. layoutRoot = GetGame().GetWorkspace().CreateWidgets("gui/layouts/day_z_ingamemenu.layout");
  33. m_ContinueButton = layoutRoot.FindAnyWidget("continuebtn");
  34. m_SeparatorPanel = layoutRoot.FindAnyWidget("separator_red");
  35. m_ExitButton = layoutRoot.FindAnyWidget("exitbtn");
  36. m_RestartButton = layoutRoot.FindAnyWidget("restartbtn");
  37. m_RespawnButton = layoutRoot.FindAnyWidget("respawn_button");
  38. m_RestartDeadRandomButton = layoutRoot.FindAnyWidget("respawn_button_random");
  39. m_RestartDeadCustomButton = layoutRoot.FindAnyWidget("respawn_button_custom");
  40. m_OptionsButton = layoutRoot.FindAnyWidget("optionsbtn");
  41. m_ModdedWarning = TextWidget.Cast(layoutRoot.FindAnyWidget("ModdedWarning"));
  42. m_HintPanel = new UiHintPanel(layoutRoot.FindAnyWidget("hint_frame"));
  43. m_ServerInfoPanel = layoutRoot.FindAnyWidget("server_info");
  44. m_ServerIP = TextWidget.Cast(layoutRoot.FindAnyWidget("server_ip"));
  45. m_ServerPort = TextWidget.Cast(layoutRoot.FindAnyWidget("server_port"));
  46. m_ServerName = TextWidget.Cast(layoutRoot.FindAnyWidget("server_name"));
  47. m_FavoriteImage = layoutRoot.FindAnyWidget("favorite_image");
  48. m_UnfavoriteImage = layoutRoot.FindAnyWidget("unfavorite_image");
  49. m_CopyInfoButton = layoutRoot.FindAnyWidget("copy_button");
  50. m_FeedbackButton = layoutRoot.FindAnyWidget("feedbackbtn");
  51. if (GetGame().IsMultiplayer())
  52. {
  53. ButtonSetText(m_RestartButton, "#main_menu_respawn");
  54. }
  55. else
  56. {
  57. ButtonSetText(m_RestartButton, "#main_menu_restart");
  58. }
  59. HudShow(false);
  60. SetGameVersion();
  61. SetServerInfoVisibility(SetServerInfo() && g_Game.GetProfileOption(EDayZProfilesOptions.SERVERINFO_DISPLAY));
  62. m_ModdedWarning.Show(g_Game.ReportModded());
  63. Mission mission = g_Game.GetMission();
  64. if (mission)
  65. mission.Pause();
  66. return layoutRoot;
  67. }
  68. protected void SetGameVersion()
  69. {
  70. TextWidget version_widget = TextWidget.Cast(layoutRoot.FindAnyWidget("version"));
  71. string version;
  72. GetGame().GetVersion(version);
  73. version_widget.SetText("#main_menu_version" + " " + version);
  74. #ifdef PREVIEW_BUILD
  75. version_widget.SetText("THIS IS PREVIEW");
  76. #endif
  77. }
  78. protected bool SetServerInfo()
  79. {
  80. if (GetGame().IsMultiplayer())
  81. {
  82. MenuData menu_data = g_Game.GetMenuData();
  83. GetServersResultRow info = OnlineServices.GetCurrentServerInfo();
  84. if (info)
  85. {
  86. m_ServerPort.SetText(info.m_HostPort.ToString());
  87. m_ServerIP.SetText(info.m_HostIp);
  88. m_ServerName.SetText(info.m_Name);
  89. m_UnfavoriteImage.Show(info.m_Favorite);
  90. m_FavoriteImage.Show(!info.m_Favorite);
  91. m_ServerInfoText = "" + info.GetIpPort();
  92. return true;
  93. }
  94. //temporary, incomplete solution, OnlineServices.GetCurrentServerInfo() should be working!
  95. else if (menu_data && menu_data.GetLastPlayedCharacter() != GameConstants.DEFAULT_CHARACTER_MENU_ID)
  96. {
  97. int char_id = menu_data.GetLastPlayedCharacter();
  98. int port;
  99. string address,name;
  100. menu_data.GetLastServerAddress(char_id,address);
  101. port = menu_data.GetLastServerPort(char_id);
  102. menu_data.GetLastServerName(char_id,name);
  103. m_ServerPort.SetText(port.ToString());
  104. m_ServerIP.SetText(address);
  105. m_ServerName.SetText(name);
  106. m_ServerInfoText = "" + address + ":" + port;
  107. return true;
  108. }
  109. else
  110. {
  111. g_Game.RefreshCurrentServerInfo();
  112. }
  113. }
  114. return false;
  115. }
  116. protected void HudShow(bool show)
  117. {
  118. Mission mission = GetGame().GetMission();
  119. if (mission)
  120. {
  121. IngameHud hud = IngameHud.Cast(mission.GetHud());
  122. if (hud)
  123. {
  124. hud.ShowHudUI(g_Game.GetProfileOption(EDayZProfilesOptions.HUD) && show);
  125. hud.ShowQuickbarUI(g_Game.GetProfileOption(EDayZProfilesOptions.QUICKBAR) && show);
  126. }
  127. }
  128. }
  129. override bool OnMouseEnter(Widget w, int x, int y)
  130. {
  131. ColorHighlight(w);
  132. return true;
  133. }
  134. override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
  135. {
  136. ColorNormal(w);
  137. return true;
  138. }
  139. override bool OnClick(Widget w, int x, int y, int button)
  140. {
  141. super.OnClick(w, x, y, button);
  142. if (w == m_ContinueButton)
  143. {
  144. OnClick_Continue();
  145. return true;
  146. }
  147. else if (w == m_RestartButton)
  148. {
  149. #ifdef DEVELOPER
  150. if (GetGame().IsMultiplayer() || (GetGame().GetPlayer() && GetGame().GetPlayer().IsUnconscious()))
  151. OnClick_Restart();
  152. else
  153. {
  154. PluginDeveloper plugin = PluginDeveloper.GetInstance();
  155. if (plugin)
  156. plugin.ToggleMissionLoader();
  157. }
  158. #else
  159. OnClick_Restart();
  160. #endif
  161. return true;
  162. }
  163. else if (w == m_RespawnButton)
  164. {
  165. OnClick_Respawn();
  166. return true;
  167. }
  168. else if (w == m_OptionsButton)
  169. {
  170. OnClick_Options();
  171. return true;
  172. }
  173. else if (w == m_ExitButton)
  174. {
  175. OnClick_Exit();
  176. return true;
  177. }
  178. else if (w == m_CopyInfoButton)
  179. {
  180. GetGame().CopyToClipboard(m_ServerInfoText);
  181. }
  182. else if (w == m_FeedbackButton)
  183. {
  184. OpenFeedback();
  185. }
  186. return false;
  187. }
  188. protected void OnClick_Continue()
  189. {
  190. GetGame().GetCallQueue(CALL_CATEGORY_GUI).Call(GetGame().GetMission().Continue);
  191. }
  192. protected void OnClick_Restart()
  193. {
  194. if (!GetGame().IsMultiplayer())
  195. {
  196. GetGame().GetCallQueue(CALL_CATEGORY_GUI).Call(GetGame().RestartMission);
  197. }
  198. else
  199. {
  200. OnClick_Respawn();
  201. }
  202. }
  203. protected void OnClick_Respawn()
  204. {
  205. Man player = GetGame().GetPlayer();
  206. if (player && player.IsUnconscious() && !player.IsDamageDestroyed())
  207. {
  208. GetGame().GetUIManager().ShowDialog("#main_menu_respawn", "#main_menu_respawn_question", IDC_INT_RETRY, DBT_YESNO, DBB_YES, DMT_QUESTION, this);
  209. }
  210. else
  211. {
  212. if (GetGame().GetMission().GetRespawnModeClient() == GameConstants.RESPAWN_MODE_CUSTOM)
  213. {
  214. GetGame().GetCallQueue(CALL_CATEGORY_GUI).Call(GetGame().GetUIManager().EnterScriptedMenu,MENU_RESPAWN_DIALOGUE,this);
  215. }
  216. else
  217. {
  218. GameRespawn(true);
  219. }
  220. }
  221. }
  222. protected void OnClick_Options()
  223. {
  224. EnterScriptedMenu(MENU_OPTIONS);
  225. }
  226. protected void OnClick_Exit()
  227. {
  228. GetGame().LogoutRequestTime();
  229. GetGame().GetCallQueue(CALL_CATEGORY_GUI).Call(GetGame().GetMission().CreateLogoutMenu, this);
  230. }
  231. override bool OnModalResult(Widget w, int x, int y, int code, int result)
  232. {
  233. super.OnModalResult(w, x, y, code, result);
  234. if (code == IDC_INT_EXIT && result == DBB_YES)
  235. {
  236. if (GetGame().IsMultiplayer())
  237. {
  238. GetGame().LogoutRequestTime();
  239. GetGame().GetCallQueue(CALL_CATEGORY_GUI).Call(GetGame().GetMission().CreateLogoutMenu, this);
  240. }
  241. else
  242. {
  243. // skip logout screen in singleplayer
  244. GetGame().GetMission().AbortMission();
  245. }
  246. g_Game.CancelLoginTimeCountdown();
  247. return true;
  248. }
  249. else if (code == IDC_INT_EXIT && result == DBB_NO)
  250. {
  251. g_Game.CancelLoginTimeCountdown();
  252. }
  253. else if (code == IDC_INT_RETRY && result == DBB_YES && GetGame().IsMultiplayer())
  254. {
  255. if (GetGame().GetMission().GetRespawnModeClient() == GameConstants.RESPAWN_MODE_CUSTOM)
  256. {
  257. GetGame().GetCallQueue(CALL_CATEGORY_GUI).Call(GetGame().GetUIManager().EnterScriptedMenu,MENU_RESPAWN_DIALOGUE,this);
  258. }
  259. else
  260. {
  261. GameRespawn(true);
  262. }
  263. return true;
  264. }
  265. return false;
  266. }
  267. override void Update(float timeslice)
  268. {
  269. super.Update(timeslice);
  270. UpdateGUI();
  271. }
  272. protected void UpdateGUI()
  273. {
  274. #ifdef BULDOZER
  275. m_RestartButton.Show(false);
  276. m_RespawnButton.Show(false);
  277. #else
  278. Man player = GetGame().GetPlayer();
  279. bool playerAlive = player && player.GetPlayerState() == EPlayerStates.ALIVE;
  280. if (GetGame().IsMultiplayer())
  281. {
  282. m_RestartButton.Show(playerAlive && player.IsUnconscious() && !CfgGameplayHandler.GetDisableRespawnInUnconsciousness());
  283. m_RespawnButton.Show(!playerAlive);
  284. }
  285. else
  286. {
  287. m_RestartButton.Show(true);
  288. m_RespawnButton.Show(false);
  289. m_SeparatorPanel.Show(playerAlive);
  290. }
  291. m_ContinueButton.Show(playerAlive);
  292. #endif
  293. }
  294. void MenuRequestRespawn(UIScriptedMenu menu, bool random)
  295. {
  296. if (RespawnDialogue.Cast(menu))
  297. GameRespawn(random);
  298. }
  299. protected void GameRespawn(bool random)
  300. {
  301. GetGame().GetMenuDefaultCharacterData(false).SetRandomCharacterForced(random);
  302. GetGame().RespawnPlayer();
  303. PlayerBase player = PlayerBase.Cast(GetGame().GetPlayer());
  304. if (player)
  305. {
  306. player.SimulateDeath(true);
  307. GetGame().GetCallQueue(CALL_CATEGORY_GUI).Call(player.ShowDeadScreen, true, 0);
  308. }
  309. MissionGameplay missionGP = MissionGameplay.Cast(GetGame().GetMission());
  310. missionGP.DestroyAllMenus();
  311. missionGP.SetPlayerRespawning(true);
  312. missionGP.Continue();
  313. Close();
  314. }
  315. protected void ColorHighlight(Widget w)
  316. {
  317. if (!w)
  318. return;
  319. ButtonSetColor(w, ARGB(255, 0, 0, 0));
  320. ButtonSetTextColor(w, ARGB(255, 255, 0, 0));
  321. }
  322. protected void ColorNormal(Widget w)
  323. {
  324. if (!w)
  325. return;
  326. ButtonSetColor(w, ARGB(0, 0, 0, 0));
  327. ButtonSetTextColor(w, ARGB(255, 255, 255, 255));
  328. }
  329. protected void ColorDisable(Widget w)
  330. {
  331. if (!w)
  332. return;
  333. ButtonSetColor(w, ARGB(0, 0, 0, 0));
  334. ButtonSetTextColor(w, ColorManager.COLOR_DISABLED_TEXT);
  335. }
  336. protected void ButtonSetText(Widget w, string text)
  337. {
  338. if (!w)
  339. return;
  340. TextWidget label = TextWidget.Cast(w.FindWidget(w.GetName() + "_label"));
  341. if (label)
  342. label.SetText(text);
  343. }
  344. protected void ButtonSetColor(Widget w, int color)
  345. {
  346. Widget panel = w.FindWidget(w.GetName() + "_panel");
  347. if (panel)
  348. panel.SetColor(color);
  349. }
  350. protected void ButtonSetTextColor(Widget w, int color)
  351. {
  352. TextWidget label = TextWidget.Cast(w.FindAnyWidget(w.GetName() + "_label"));
  353. if (label)
  354. label.SetColor(color);
  355. }
  356. void SetServerInfoVisibility(bool show)
  357. {
  358. m_ServerInfoPanel.Show(show);
  359. }
  360. protected void OpenFeedback()
  361. {
  362. GetGame().OpenURL("https://feedback.bistudio.com/project/view/2/");
  363. }
  364. //! DEPRECATED
  365. void ToggleFavoriteServer();
  366. }