respawndialogue.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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. if (GetUApi().GetInputByID(UAUIBack).LocalPress() || GetUApi().GetInputByID(UAUIMenu).LocalPress())
  28. Close();
  29. }
  30. override bool OnClick(Widget w, int x, int y, int button)
  31. {
  32. super.OnClick(w, x, y, button);
  33. switch (w.GetUserID())
  34. {
  35. case IDC_CANCEL:
  36. Close();
  37. return true;
  38. case ID_RESPAWN_CUSTOM:
  39. return RequestRespawn(false);
  40. case ID_RESPAWN_RANDOM:
  41. return RequestRespawn(true);
  42. }
  43. return false;
  44. }
  45. override bool OnMouseEnter(Widget w, int x, int y)
  46. {
  47. string tooltip_header = "";
  48. string tooltip_text = "";
  49. ColorHighlight(w);
  50. switch (w.GetUserID())
  51. {
  52. case ID_RESPAWN_RANDOM:
  53. tooltip_header = "#main_menu_respawn_random";
  54. tooltip_text = "#main_menu_respawn_random_tooltip";
  55. break;
  56. case ID_RESPAWN_CUSTOM:
  57. tooltip_header = "#main_menu_respawn_custom";
  58. tooltip_text = "#main_menu_respawn_custom_tooltip";
  59. break;
  60. }
  61. SetTooltipTexts(w, tooltip_header, tooltip_text);
  62. return true;
  63. }
  64. override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
  65. {
  66. ColorNormal(w);
  67. return true;
  68. }
  69. override void OnShow()
  70. {
  71. super.OnShow();
  72. SetFocus(m_CustomRespawn);
  73. }
  74. override bool OnFocus(Widget w, int x, int y)
  75. {
  76. string tooltip_header = "";
  77. string tooltip_text = "";
  78. if (IsFocusable(w))
  79. {
  80. ColorHighlight(w);
  81. switch (w.GetUserID())
  82. {
  83. case ID_RESPAWN_RANDOM:
  84. tooltip_header = "#main_menu_respawn_random";
  85. tooltip_text = "#main_menu_respawn_random_tooltip";
  86. break;
  87. case ID_RESPAWN_CUSTOM:
  88. tooltip_header = "#main_menu_respawn_custom";
  89. tooltip_text = "#main_menu_respawn_custom_tooltip";
  90. break;
  91. }
  92. SetTooltipTexts(w, tooltip_header, tooltip_text);
  93. return true;
  94. }
  95. SetTooltipTexts(w, tooltip_header, tooltip_text);
  96. return false;
  97. }
  98. override bool OnFocusLost(Widget w, int x, int y)
  99. {
  100. if (IsFocusable(w))
  101. {
  102. ColorNormal(w);
  103. return true;
  104. }
  105. return false;
  106. }
  107. bool IsFocusable(Widget w)
  108. {
  109. if (w)
  110. {
  111. if (w.GetUserID() == IDC_CANCEL || w.GetUserID() == ID_RESPAWN_CUSTOM || w.GetUserID() == ID_RESPAWN_RANDOM);
  112. return true;
  113. }
  114. return false;
  115. }
  116. protected void ColorHighlight(Widget w)
  117. {
  118. if (!w)
  119. return;
  120. if (m_CurrentlyHighlighted != w)
  121. {
  122. if (m_CurrentlyHighlighted)
  123. ColorNormal(m_CurrentlyHighlighted);
  124. m_CurrentlyHighlighted = w;
  125. }
  126. ButtonSetColor(w, ARGB(255, 0, 0, 0));
  127. ButtonSetTextColor(w, ARGB(255, 255, 0, 0));
  128. }
  129. protected void ColorNormal(Widget w)
  130. {
  131. if (!w)
  132. return;
  133. ButtonSetColor(w, ARGB(0, 0, 0, 0));
  134. ButtonSetTextColor(w, ARGB(255, 255, 255, 255));
  135. }
  136. protected void ButtonSetColor(Widget w, int color)
  137. {
  138. Widget panel = w.FindWidget(w.GetName() + "_panel");
  139. if (panel)
  140. panel.SetColor(color);
  141. }
  142. protected void ButtonSetTextColor(Widget w, int color)
  143. {
  144. TextWidget label = TextWidget.Cast(w.FindAnyWidget(w.GetName() + "_label"));
  145. if (label)
  146. label.SetColor(color);
  147. }
  148. void SetTooltipTexts(Widget w, string header = "", string desc = "")
  149. {
  150. bool show = header != "" && desc != "";
  151. m_DetailsRoot.Show(show);
  152. m_DetailsLabel.SetText(header);
  153. m_DetailsText.SetText(desc);
  154. m_DetailsText.Update();
  155. m_DetailsLabel.Update();
  156. m_DetailsRoot.Update();
  157. }
  158. bool RequestRespawn(bool random)
  159. {
  160. IngameHud.Cast(GetGame().GetMission().GetHud()).InitBadgesAndNotifiers();
  161. Man player = GetGame().GetPlayer();
  162. if (player && (player.GetPlayerState() == EPlayerStates.ALIVE && !player.IsUnconscious()))
  163. return false;
  164. #ifdef PLATFORM_CONSOLE
  165. InGameMenuXbox menu_ingame = InGameMenuXbox.Cast(GetGame().GetUIManager().FindMenu(MENU_INGAME));
  166. #else
  167. InGameMenu menu_ingame = InGameMenu.Cast(GetGame().GetUIManager().FindMenu(MENU_INGAME));
  168. #endif
  169. if (!menu_ingame)
  170. return false;
  171. menu_ingame.MenuRequestRespawn(this, random);
  172. return true;
  173. }
  174. }