invitemenu.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. class InviteMenu extends UIScriptedMenu
  2. {
  3. private TextWidget m_LogoutTimeText;
  4. private MultilineTextWidget m_DescriptionText;
  5. private ButtonWidget m_bCancel;
  6. private ButtonWidget m_bCancelConsole;
  7. private int m_iTime;
  8. private ref FullTimeData m_FullTime;
  9. void InviteMenu()
  10. {
  11. m_iTime = 15;
  12. m_FullTime = new FullTimeData();
  13. if (GetGame().GetMission())
  14. {
  15. GetGame().GetMission().AddActiveInputExcludes({"menu"});
  16. GetGame().GetMission().GetHud().ShowHudUI(false);
  17. GetGame().GetMission().GetHud().ShowQuickbarUI(false);
  18. }
  19. }
  20. void ~InviteMenu()
  21. {
  22. if (GetGame() && GetGame().GetMission())
  23. {
  24. GetGame().GetMission().RemoveActiveInputExcludes({"menu"},true);
  25. GetGame().GetMission().GetHud().ShowHudUI(true);
  26. GetGame().GetMission().GetHud().ShowQuickbarUI(true);
  27. GetGame().GetMission().GetOnInputPresetChanged().Remove(OnInputPresetChanged);
  28. GetGame().GetMission().GetOnInputDeviceChanged().Remove(OnInputDeviceChanged);
  29. }
  30. }
  31. override Widget Init()
  32. {
  33. layoutRoot = GetGame().GetWorkspace().CreateWidgets("gui/layouts/day_z_invite_dialog.layout");
  34. m_LogoutTimeText = TextWidget.Cast(layoutRoot.FindAnyWidget("txtLogoutTime"));
  35. m_DescriptionText = MultilineTextWidget.Cast(layoutRoot.FindAnyWidget("txtDescription"));
  36. m_bCancel = ButtonWidget.Cast(layoutRoot.FindAnyWidget("bCancel"));
  37. m_DescriptionText.SetText("#layout_logout_dialog_note_invite");
  38. m_DescriptionText.Update();
  39. // player should sit down if possible
  40. PlayerBase player = PlayerBase.Cast(GetGame().GetPlayer());
  41. if (player && player.GetEmoteManager() && !player.IsRestrained() && !player.IsUnconscious())
  42. {
  43. player.GetEmoteManager().CreateEmoteCBFromMenu(EmoteConstants.ID_EMOTE_SITA);
  44. player.GetEmoteManager().GetEmoteLauncher().SetForced(EmoteLauncher.FORCE_DIFFERENT);
  45. }
  46. if (GetGame().GetMission())
  47. {
  48. GetGame().GetMission().GetOnInputPresetChanged().Insert(OnInputPresetChanged);
  49. GetGame().GetMission().GetOnInputDeviceChanged().Insert(OnInputDeviceChanged);
  50. }
  51. OnInputDeviceChanged(GetGame().GetInput().GetCurrentInputDevice());
  52. SetTime(m_iTime);
  53. GetGame().GetCallQueue(CALL_CATEGORY_SYSTEM).CallLater(UpdateTime, 1000, true);
  54. return layoutRoot;
  55. }
  56. override void Update(float timeslice)
  57. {
  58. if (GetUApi().GetInputByID(UAUIBack).LocalPress())
  59. Cancel();
  60. if (m_iTime <= 0)
  61. {
  62. GetGame().GetCallQueue(CALL_CATEGORY_SYSTEM).Remove(this.UpdateTime);
  63. string ip;
  64. int port;
  65. OnlineServices.GetInviteServerInfo(ip, port);
  66. GetGame().GetCallQueue(CALL_CATEGORY_SYSTEM).Call(g_Game.ConnectFromJoin, ip, port);
  67. }
  68. }
  69. override bool OnClick(Widget w, int x, int y, int button)
  70. {
  71. super.OnClick(w, x, y, button);
  72. if (w.GetUserID() == IDC_CANCEL)
  73. {
  74. Cancel();
  75. return true;
  76. }
  77. return false;
  78. }
  79. void SetTime(int time)
  80. {
  81. m_iTime = time;
  82. string text = "#layout_logout_dialog_until_logout_";
  83. TimeConversions.ConvertSecondsToFullTime(time, m_FullTime);
  84. if (m_FullTime.m_Days > 0)
  85. text += "dhms";
  86. else if (m_FullTime.m_Hours > 0)
  87. text += "hms";
  88. else if (m_FullTime.m_Minutes > 0)
  89. text += "ms";
  90. else
  91. text += "s";
  92. text = Widget.TranslateString(text);
  93. text = string.Format(text, m_FullTime.m_Seconds, m_FullTime.m_Minutes, m_FullTime.m_Hours, m_FullTime.m_Days);
  94. m_LogoutTimeText.SetText(text);
  95. }
  96. void UpdateTime()
  97. {
  98. if (m_iTime > 0)
  99. {
  100. m_iTime -= 1;
  101. SetTime(m_iTime);
  102. }
  103. }
  104. void Cancel()
  105. {
  106. GetGame().GetCallQueue(CALL_CATEGORY_SYSTEM).Remove(this.UpdateTime);
  107. g_Game.SetGameState(DayZGameState.IN_GAME);
  108. g_Game.SetLoadState(DayZLoadState.CONNECT_CONTROLLER_SELECT);
  109. Close();
  110. }
  111. protected void OnInputPresetChanged()
  112. {
  113. #ifdef PLATFORM_CONSOLE
  114. UpdateControlsElements();
  115. #endif
  116. }
  117. protected void OnInputDeviceChanged(EInputDeviceType pInputDeviceType)
  118. {
  119. UpdateControlsElements();
  120. UpdateControlsElementVisibility();
  121. }
  122. protected void UpdateControlsElements()
  123. {
  124. RichTextWidget toolbarText = RichTextWidget.Cast(layoutRoot.FindAnyWidget("ContextToolbarText"));
  125. string context = string.Format(" %1", InputUtils.GetRichtextButtonIconFromInputAction("UAUIBack", "#dialog_cancel", EUAINPUT_DEVICE_CONTROLLER, InputUtils.ICON_SCALE_TOOLBAR));
  126. toolbarText.SetText(context);
  127. }
  128. protected void UpdateControlsElementVisibility()
  129. {
  130. bool toolbarShow = false;
  131. #ifdef PLATFORM_CONSOLE
  132. toolbarShow = !GetGame().GetInput().IsEnabledMouseAndKeyboard() || GetGame().GetInput().GetCurrentInputDevice() == EInputDeviceType.CONTROLLER;
  133. #endif
  134. layoutRoot.FindAnyWidget("BottomConsoleToolbar").Show(toolbarShow);
  135. m_bCancel.Show(!toolbarShow);
  136. }
  137. }