ingamemenu.c 10 KB

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