connectiondialogue.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. class ConnectionDialogue extends UIScriptedMenu
  2. {
  3. protected bool m_DebugMonitorHidden;
  4. protected MultilineTextWidget m_Description;
  5. protected ButtonWidget m_DisconnectBtn;
  6. #ifdef PLATFORM_CONSOLE
  7. protected RichTextWidget m_DisconnectBtnLabel;
  8. protected Widget m_ConsoleToolbar;
  9. #endif
  10. void ConnectionDialogue() {}
  11. void ~ConnectionDialogue()
  12. {
  13. #ifdef PLATFORM_CONSOLE
  14. if (GetGame().GetMission())
  15. {
  16. GetGame().GetMission().GetOnInputDeviceChanged().Remove(OnInputDeviceChanged);
  17. }
  18. #endif
  19. }
  20. override Widget Init()
  21. {
  22. layoutRoot = GetGame().GetWorkspace().CreateWidgets("gui/layouts/day_z_connection_dialogue.layout");
  23. m_DisconnectBtn = ButtonWidget.Cast(layoutRoot.FindAnyWidget("DCButton"));
  24. #ifdef PLATFORM_CONSOLE
  25. m_DisconnectBtnLabel = RichTextWidget.Cast(layoutRoot.FindAnyWidget("DCButtonLabel"));
  26. m_ConsoleToolbar = layoutRoot.FindAnyWidget("ConsoleToolbar");
  27. #endif
  28. #ifdef PLATFORM_CONSOLE
  29. if (GetGame().GetMission())
  30. {
  31. GetGame().GetMission().GetOnInputDeviceChanged().Insert(OnInputDeviceChanged);
  32. }
  33. #endif
  34. RichTextWidget toolbar_text = RichTextWidget.Cast(layoutRoot.FindAnyWidget("ContextToolbarText"));
  35. string context = string.Format(" %1",InputUtils.GetRichtextButtonIconFromInputAction("UAUISelect", "#main_menu_exit", EUAINPUT_DEVICE_CONTROLLER, InputUtils.ICON_SCALE_TOOLBAR));
  36. toolbar_text.SetText(context);
  37. #ifdef PLATFORM_CONSOLE
  38. OnInputDeviceChanged(GetGame().GetInput().GetCurrentInputDevice());
  39. #endif
  40. return layoutRoot;
  41. }
  42. #ifdef PLATFORM_CONSOLE
  43. protected void OnInputDeviceChanged(EInputDeviceType pInputDeviceType)
  44. {
  45. switch (pInputDeviceType)
  46. {
  47. case EInputDeviceType.CONTROLLER:
  48. {
  49. GetGame().GetUIManager().ShowUICursor(false);
  50. m_DisconnectBtnLabel.SetText("#main_menu_exit");
  51. SetFocus(m_DisconnectBtn);
  52. }
  53. break;
  54. default:
  55. {
  56. if (GetGame().GetInput().IsEnabledMouseAndKeyboard())
  57. {
  58. GetGame().GetUIManager().ShowUICursor(true);
  59. m_DisconnectBtnLabel.SetText(string.Format(" %1",InputUtils.GetRichtextButtonIconFromInputAction("UAUISelect", "#main_menu_exit", EUAINPUT_DEVICE_CONTROLLER, InputUtils.ICON_SCALE_NORMAL)));
  60. SetFocus(null);
  61. }
  62. }
  63. break;
  64. }
  65. UpdateControlsElementVisibility();
  66. }
  67. protected void UpdateControlsElementVisibility()
  68. {
  69. bool toolbarShow = !GetGame().GetInput().IsEnabledMouseAndKeyboard() || GetGame().GetInput().GetCurrentInputDevice() == EInputDeviceType.CONTROLLER;
  70. m_ConsoleToolbar.Show(toolbarShow);
  71. }
  72. override bool OnFocus(Widget w, int x, int y)
  73. {
  74. if (w == m_DisconnectBtn)
  75. {
  76. m_DisconnectBtn.SetColor(ARGB(255, 255, 0, 0));
  77. return true;
  78. }
  79. return false;
  80. }
  81. override bool OnFocusLost(Widget w, int x, int y)
  82. {
  83. if (w == m_DisconnectBtn)
  84. {
  85. m_DisconnectBtn.SetColor(ARGB(0, 0, 0, 0));
  86. return true;
  87. }
  88. return false;
  89. }
  90. #endif
  91. override bool OnClick(Widget w, int x, int y, int button)
  92. {
  93. super.OnClick(w, x, y, button);
  94. if (w == m_DisconnectBtn)
  95. {
  96. CloseDialog();
  97. }
  98. return false;
  99. }
  100. override bool OnMouseEnter(Widget w, int x, int y)
  101. {
  102. if (w == m_DisconnectBtn)
  103. {
  104. m_DisconnectBtn.SetColor(ARGB(255, 255, 0, 0));
  105. return true;
  106. }
  107. return false;
  108. }
  109. override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
  110. {
  111. if (w == m_DisconnectBtn)
  112. {
  113. m_DisconnectBtn.SetColor(ARGB(0, 0, 0, 0));
  114. return true;
  115. }
  116. return false;
  117. }
  118. override void OnShow()
  119. {
  120. super.OnShow();
  121. SetFocus(null);
  122. PPERequesterBank.GetRequester(PPERequester_LatencyBlur).Start();
  123. MissionGameplay mission = MissionGameplay.Cast(GetGame().GetMission());
  124. if (mission)
  125. {
  126. mission.GetHud().ShowHud(false);
  127. mission.GetHud().ShowQuickBar(false);
  128. mission.AddActiveInputExcludes({"menu"});
  129. mission.AddActiveInputRestriction(EInputRestrictors.INVENTORY);
  130. GetUApi().SupressNextFrame(true);
  131. //! Hide debug monitor if it is shown
  132. if (mission && mission.m_DebugMonitor && mission.m_DebugMonitor.IsVisible())
  133. {
  134. mission.m_DebugMonitor.Hide();
  135. m_DebugMonitorHidden = true;
  136. }
  137. }
  138. if (GetDayZGame())
  139. {
  140. GetDayZGame().SetConnectivityStatState(EConnectivityStatType.CONN_LOST, EConnectivityStatLevel.LEVEL1);
  141. }
  142. #ifdef PLATFORM_PS4
  143. OnlineServices.SetMultiplayState(false);
  144. #endif
  145. }
  146. override void OnHide()
  147. {
  148. super.OnHide();
  149. PPERequesterBank.GetRequester(PPERequester_LatencyBlur).Stop();
  150. MissionGameplay mission = MissionGameplay.Cast(GetGame().GetMission());
  151. if (mission)
  152. {
  153. // make sure certain input restrictions are removed if present
  154. mission.RemoveActiveInputExcludes({"menu"}, true);
  155. mission.RemoveActiveInputRestriction(EInputRestrictors.INVENTORY);
  156. mission.GetHud().ShowHud(true);
  157. mission.GetHud().ShowQuickBar(true);
  158. //! Show debug monitor again if it was shown before
  159. if (m_DebugMonitorHidden)
  160. {
  161. if (mission.m_DebugMonitor)
  162. {
  163. mission.m_DebugMonitor.Show();
  164. }
  165. m_DebugMonitorHidden = false;
  166. }
  167. }
  168. if (GetDayZGame())
  169. {
  170. GetDayZGame().SetConnectivityStatState(EConnectivityStatType.CONN_LOST, EConnectivityStatLevel.OFF);
  171. }
  172. #ifdef PLATFORM_PS4
  173. OnlineServices.SetMultiplayState(true);
  174. #endif
  175. }
  176. override void Update(float timeslice)
  177. {
  178. #ifdef PLATFORM_CONSOLE
  179. if (GetUApi().GetInputByID(UAUISelect).LocalValue())
  180. {
  181. CloseDialog();
  182. return;
  183. }
  184. #endif
  185. }
  186. void CloseDialog()
  187. {
  188. if (GetGame())
  189. {
  190. GetGame().GetUIManager().CloseMenu(MENU_CONNECTION_DIALOGUE);
  191. g_Game.GetCallQueue(CALL_CATEGORY_SYSTEM).Call(GetGame().DisconnectSessionForce);
  192. }
  193. }
  194. }