respawndialogue.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. class RespawnDialogue extends UIScriptedMenu
  2. {
  3. const int ID_RESPAWN_CUSTOM = 101;
  4. const int ID_RESPAWN_RANDOM = 102;
  5. //tooltips
  6. protected Widget m_DetailsRoot;
  7. protected TextWidget m_DetailsLabel;
  8. protected RichTextWidget m_DetailsText;
  9. protected Widget m_CustomRespawn;
  10. //helper
  11. protected Widget m_CurrentlyHighlighted;
  12. void RespawnDialogue();
  13. void ~RespawnDialogue();
  14. override Widget Init()
  15. {
  16. layoutRoot = GetGame().GetWorkspace().CreateWidgets("gui/layouts/day_z_respawn_dialogue.layout");
  17. m_DetailsRoot = layoutRoot.FindAnyWidget("menu_details_tooltip");
  18. m_DetailsLabel = TextWidget.Cast(m_DetailsRoot.FindAnyWidget("menu_details_label"));
  19. m_DetailsText = RichTextWidget.Cast(m_DetailsRoot.FindAnyWidget("menu_details_tooltip_content"));
  20. m_CustomRespawn = layoutRoot.FindAnyWidget("respawn_button_custom");
  21. SetFocus(m_CustomRespawn);
  22. return layoutRoot;
  23. }
  24. override void Update(float timeslice)
  25. {
  26. super.Update(timeslice);
  27. Man player = GetGame().GetPlayer();
  28. bool playerAlive = player && player.GetPlayerState() == EPlayerStates.ALIVE;
  29. if (playerAlive && !player.IsUnconscious())
  30. {
  31. Close();
  32. return;
  33. }
  34. if (GetUApi().GetInputByID(UAUIBack).LocalPress() || GetUApi().GetInputByID(UAUIMenu).LocalPress())
  35. Close();
  36. }
  37. override bool OnClick(Widget w, int x, int y, int button)
  38. {
  39. super.OnClick(w, x, y, button);
  40. switch (w.GetUserID())
  41. {
  42. case IDC_CANCEL:
  43. Close();
  44. return true;
  45. case ID_RESPAWN_CUSTOM:
  46. return RequestRespawn(false);
  47. case ID_RESPAWN_RANDOM:
  48. return RequestRespawn(true);
  49. }
  50. return false;
  51. }
  52. override bool OnMouseEnter(Widget w, int x, int y)
  53. {
  54. string tooltip_header = "";
  55. string tooltip_text = "";
  56. ColorHighlight(w);
  57. switch (w.GetUserID())
  58. {
  59. case ID_RESPAWN_RANDOM:
  60. tooltip_header = "#main_menu_respawn_random";
  61. tooltip_text = "#main_menu_respawn_random_tooltip";
  62. break;
  63. case ID_RESPAWN_CUSTOM:
  64. tooltip_header = "#main_menu_respawn_custom";
  65. tooltip_text = "#main_menu_respawn_custom_tooltip";
  66. break;
  67. }
  68. SetTooltipTexts(w, tooltip_header, tooltip_text);
  69. return true;
  70. }
  71. override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
  72. {
  73. ColorNormal(w);
  74. return true;
  75. }
  76. override void OnShow()
  77. {
  78. super.OnShow();
  79. SetFocus(m_CustomRespawn);
  80. }
  81. override bool OnFocus(Widget w, int x, int y)
  82. {
  83. string tooltip_header = "";
  84. string tooltip_text = "";
  85. if (IsFocusable(w))
  86. {
  87. ColorHighlight(w);
  88. switch (w.GetUserID())
  89. {
  90. case ID_RESPAWN_RANDOM:
  91. tooltip_header = "#main_menu_respawn_random";
  92. tooltip_text = "#main_menu_respawn_random_tooltip";
  93. break;
  94. case ID_RESPAWN_CUSTOM:
  95. tooltip_header = "#main_menu_respawn_custom";
  96. tooltip_text = "#main_menu_respawn_custom_tooltip";
  97. break;
  98. }
  99. SetTooltipTexts(w, tooltip_header, tooltip_text);
  100. return true;
  101. }
  102. SetTooltipTexts(w, tooltip_header, tooltip_text);
  103. return false;
  104. }
  105. override bool OnFocusLost(Widget w, int x, int y)
  106. {
  107. if (IsFocusable(w))
  108. {
  109. ColorNormal(w);
  110. return true;
  111. }
  112. return false;
  113. }
  114. bool IsFocusable(Widget w)
  115. {
  116. if (w)
  117. {
  118. if (w.GetUserID() == IDC_CANCEL || w.GetUserID() == ID_RESPAWN_CUSTOM || w.GetUserID() == ID_RESPAWN_RANDOM)
  119. return true;
  120. }
  121. return false;
  122. }
  123. protected void ColorHighlight(Widget w)
  124. {
  125. if (!w)
  126. return;
  127. if (m_CurrentlyHighlighted != w)
  128. {
  129. if (m_CurrentlyHighlighted)
  130. ColorNormal(m_CurrentlyHighlighted);
  131. m_CurrentlyHighlighted = w;
  132. }
  133. ButtonSetColor(w, ARGB(255, 0, 0, 0));
  134. ButtonSetTextColor(w, ARGB(255, 255, 0, 0));
  135. }
  136. protected void ColorNormal(Widget w)
  137. {
  138. if (!w)
  139. return;
  140. ButtonSetColor(w, ARGB(0, 0, 0, 0));
  141. ButtonSetTextColor(w, ARGB(255, 255, 255, 255));
  142. }
  143. protected void ButtonSetColor(Widget w, int color)
  144. {
  145. Widget panel = w.FindWidget(w.GetName() + "_panel");
  146. if (panel)
  147. panel.SetColor(color);
  148. }
  149. protected void ButtonSetTextColor(Widget w, int color)
  150. {
  151. TextWidget label = TextWidget.Cast(w.FindAnyWidget(w.GetName() + "_label"));
  152. if (label)
  153. label.SetColor(color);
  154. }
  155. void SetTooltipTexts(Widget w, string header = "", string desc = "")
  156. {
  157. bool show = header != "" && desc != "";
  158. m_DetailsRoot.Show(show);
  159. m_DetailsLabel.SetText(header);
  160. m_DetailsText.SetText(desc);
  161. m_DetailsText.Update();
  162. m_DetailsLabel.Update();
  163. m_DetailsRoot.Update();
  164. }
  165. bool RequestRespawn(bool random)
  166. {
  167. IngameHud.Cast(GetGame().GetMission().GetHud()).InitBadgesAndNotifiers();
  168. Man player = GetGame().GetPlayer();
  169. if (player && (player.GetPlayerState() == EPlayerStates.ALIVE && !player.IsUnconscious()))
  170. return false;
  171. #ifdef PLATFORM_CONSOLE
  172. InGameMenuXbox menu_ingame = InGameMenuXbox.Cast(GetGame().GetUIManager().FindMenu(MENU_INGAME));
  173. #else
  174. InGameMenu menu_ingame = InGameMenu.Cast(GetGame().GetUIManager().FindMenu(MENU_INGAME));
  175. #endif
  176. if (!menu_ingame)
  177. return false;
  178. menu_ingame.MenuRequestRespawn(this, random);
  179. return true;
  180. }
  181. }