logoutmenu.c 4.0 KB

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