logoutmenu.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. class LogoutMenu extends UIScriptedMenu
  2. {
  3. private TextWidget m_LogoutTimeText;
  4. private TextWidget m_DescriptionText;
  5. private ButtonWidget m_bLogoutNow;
  6. private ButtonWidget m_bCancel;
  7. #ifdef PLATFORM_CONSOLE
  8. private ButtonWidget m_bCancelConsole;
  9. #endif
  10. private int m_iTime;
  11. private ref FullTimeData m_FullTime;
  12. void LogoutMenu()
  13. {
  14. m_iTime = 0;
  15. g_Game.SetKeyboardHandle(this);
  16. m_FullTime = new FullTimeData();
  17. }
  18. void ~LogoutMenu()
  19. {
  20. g_Game.SetKeyboardHandle(null);
  21. if (GetGame().GetMission())
  22. Cancel(); //cancels request on irregular close (player death, suicide, some mass-menu closure...)
  23. m_FullTime = null;
  24. #ifdef PLATFORM_CONSOLE
  25. if (GetGame().GetMission())
  26. {
  27. GetGame().GetMission().GetOnInputDeviceChanged().Remove(OnInputDeviceChanged);
  28. }
  29. #endif
  30. }
  31. override Widget Init()
  32. {
  33. layoutRoot = GetGame().GetWorkspace().CreateWidgets("gui/layouts/day_z_logout_dialog.layout");
  34. m_LogoutTimeText = TextWidget.Cast(layoutRoot.FindAnyWidget("txtLogoutTime"));
  35. m_DescriptionText = TextWidget.Cast(layoutRoot.FindAnyWidget("txtDescription"));
  36. m_bLogoutNow = ButtonWidget.Cast(layoutRoot.FindAnyWidget("bLogoutNow"));
  37. m_bCancel = ButtonWidget.Cast(layoutRoot.FindAnyWidget("bCancel"));
  38. #ifdef PLATFORM_CONSOLE
  39. m_bCancelConsole = ButtonWidget.Cast(layoutRoot.FindAnyWidget("bCancelConsole"));
  40. m_bCancel.Show(false);
  41. m_bLogoutNow.Show(false);
  42. #else
  43. m_bCancel.Show(true);
  44. m_bLogoutNow.Show(true);
  45. layoutRoot.FindAnyWidget("toolbar_bg").Show(false);
  46. #endif
  47. UpdateInfo();
  48. // player should sit down if possible
  49. PlayerBase player = PlayerBase.Cast(GetGame().GetPlayer());
  50. if (player.GetEmoteManager() && !player.IsRestrained() && !player.IsUnconscious())
  51. {
  52. player.GetEmoteManager().CreateEmoteCBFromMenu(EmoteConstants.ID_EMOTE_SITA);
  53. player.GetEmoteManager().GetEmoteLauncher().SetForced(EmoteLauncher.FORCE_DIFFERENT);
  54. }
  55. #ifdef PLATFORM_CONSOLE
  56. if (GetGame().GetMission())
  57. {
  58. GetGame().GetMission().GetOnInputDeviceChanged().Insert(OnInputDeviceChanged);
  59. }
  60. OnInputDeviceChanged(GetGame().GetInput().GetCurrentInputDevice());
  61. #endif
  62. return layoutRoot;
  63. }
  64. void Show()
  65. {
  66. if (layoutRoot)
  67. layoutRoot.Show(true);
  68. }
  69. void Hide()
  70. {
  71. if (layoutRoot)
  72. layoutRoot.Show(false);
  73. }
  74. override bool OnClick(Widget w, int x, int y, int button)
  75. {
  76. super.OnClick(w, x, y, button);
  77. if (w == m_bLogoutNow)
  78. {
  79. GetGame().GetMission().AbortMission();
  80. return true;
  81. }
  82. #ifdef PLATFORM_CONSOLE
  83. else if (w == m_bCancelConsole)
  84. #else
  85. else if (w == m_bCancel)
  86. #endif
  87. {
  88. Hide();
  89. Cancel();
  90. return true;
  91. }
  92. return false;
  93. }
  94. override void Update(float timeslice)
  95. {
  96. if (GetUApi().GetInputByID(UAUIBack).LocalPress())
  97. {
  98. Hide();
  99. Cancel();
  100. }
  101. }
  102. void SetLogoutTime()
  103. {
  104. m_LogoutTimeText.SetText(" ");
  105. }
  106. void SetTime(int time)
  107. {
  108. m_iTime = time;
  109. string text = "#layout_logout_dialog_until_logout_";
  110. TimeConversions.ConvertSecondsToFullTime(time, m_FullTime);
  111. if (m_FullTime.m_Days > 0)
  112. text += "dhms";
  113. else if (m_FullTime.m_Hours > 0)
  114. text += "hms";
  115. else if (m_FullTime.m_Minutes > 0)
  116. text += "ms";
  117. else
  118. text += "s";
  119. text = Widget.TranslateString(text);
  120. text = string.Format(text, m_FullTime.m_Seconds, m_FullTime.m_Minutes, m_FullTime.m_Hours, m_FullTime.m_Days);
  121. m_LogoutTimeText.SetText(text);
  122. }
  123. void UpdateTime()
  124. {
  125. if (m_iTime > 0)
  126. {
  127. SetTime(--m_iTime);
  128. }
  129. else
  130. {
  131. Exit();
  132. }
  133. }
  134. void UpdateInfo()
  135. {
  136. PlayerBase player = PlayerBase.Cast(GetGame().GetPlayer());
  137. if (player.IsRestrained() || player.IsUnconscious())
  138. {
  139. // display killInfo
  140. m_DescriptionText.SetText("#layout_logout_dialog_note_killed");
  141. }
  142. else
  143. {
  144. // hide killInfo
  145. m_DescriptionText.SetText("#layout_logout_dialog_note");
  146. }
  147. }
  148. void Exit()
  149. {
  150. // exit menu and logout screen
  151. GetGame().GetMission().Continue();
  152. // stop updating of logout screen
  153. GetGame().GetCallQueue(CALL_CATEGORY_SYSTEM).Remove(this.UpdateTime);
  154. // go back to main menu
  155. GetGame().GetMission().AbortMission();
  156. }
  157. void Cancel()
  158. {
  159. GetGame().GetMission().Continue();
  160. GetGame().GetCallQueue(CALL_CATEGORY_SYSTEM).Remove(this.UpdateTime);
  161. // request logout cancel from server
  162. GetGame().LogoutRequestCancel();
  163. }
  164. #ifdef PLATFORM_CONSOLE
  165. protected void OnInputDeviceChanged(EInputDeviceType pInputDeviceType)
  166. {
  167. UpdateControlsElementVisibility();
  168. }
  169. protected void UpdateControlsElementVisibility()
  170. {
  171. bool toolbarShow = false;
  172. toolbarShow = !GetGame().GetInput().IsEnabledMouseAndKeyboard() || GetGame().GetInput().GetCurrentInputDevice() == EInputDeviceType.CONTROLLER;
  173. layoutRoot.FindAnyWidget("toolbar_bg").Show(toolbarShow);
  174. m_bCancelConsole.Show(!toolbarShow);
  175. if (toolbarShow)
  176. {
  177. RichTextWidget toolbar_b = RichTextWidget.Cast(layoutRoot.FindAnyWidget("BackIcon"));
  178. toolbar_b.SetText(InputUtils.GetRichtextButtonIconFromInputAction("UAUIBack", "", EUAINPUT_DEVICE_CONTROLLER, InputUtils.ICON_SCALE_TOOLBAR));
  179. }
  180. }
  181. #endif
  182. }