Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
respawndialogue.c
Go to the documentation of this file.
1 class RespawnDialogue extends UIScriptedMenu
2 {
3  const int ID_RESPAWN_CUSTOM = 101;
4  const int ID_RESPAWN_RANDOM = 102;
5 
6  //tooltips
7  protected Widget m_DetailsRoot;
8  protected TextWidget m_DetailsLabel;
9  protected RichTextWidget m_DetailsText;
10 
11  protected Widget m_CustomRespawn;
12 
13  //helper
14  protected Widget m_CurrentlyHighlighted;
15 
16  void RespawnDialogue();
17  void ~RespawnDialogue();
18 
19  override Widget Init()
20  {
21  layoutRoot = GetGame().GetWorkspace().CreateWidgets("gui/layouts/day_z_respawn_dialogue.layout");
22  m_DetailsRoot = layoutRoot.FindAnyWidget("menu_details_tooltip");
23  m_DetailsLabel = TextWidget.Cast(m_DetailsRoot.FindAnyWidget("menu_details_label"));
24  m_DetailsText = RichTextWidget.Cast(m_DetailsRoot.FindAnyWidget("menu_details_tooltip_content"));
25 
26  m_CustomRespawn = layoutRoot.FindAnyWidget("respawn_button_custom");
27  SetFocus(m_CustomRespawn);
28 
29  return layoutRoot;
30  }
31 
32  override void Update(float timeslice)
33  {
34  super.Update(timeslice);
35 
36  if (GetUApi().GetInputByID(UAUIBack).LocalPress() || GetUApi().GetInputByID(UAUIMenu).LocalPress())
37  Close();
38  }
39 
40  override bool OnClick(Widget w, int x, int y, int button)
41  {
42  super.OnClick(w, x, y, button);
43 
44  switch (w.GetUserID())
45  {
46  case IDC_CANCEL:
47  Close();
48  return true;
49 
50  case ID_RESPAWN_CUSTOM:
51  return RequestRespawn(false);
52 
53  case ID_RESPAWN_RANDOM:
54  return RequestRespawn(true);
55  }
56 
57  return false;
58  }
59 
60  override bool OnMouseEnter(Widget w, int x, int y)
61  {
62  string tooltip_header = "";
63  string tooltip_text = "";
64  ColorHighlight(w);
65  switch (w.GetUserID())
66  {
67  case ID_RESPAWN_RANDOM:
68  tooltip_header = "#main_menu_respawn_random";
69  tooltip_text = "#main_menu_respawn_random_tooltip";
70  break;
71 
72  case ID_RESPAWN_CUSTOM:
73  tooltip_header = "#main_menu_respawn_custom";
74  tooltip_text = "#main_menu_respawn_custom_tooltip";
75  break;
76  }
77 
78  SetTooltipTexts(w, tooltip_header, tooltip_text);
79  return true;
80  }
81 
82  override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
83  {
84  ColorNormal(w);
85  return true;
86  }
87 
88  override void OnShow()
89  {
90  super.OnShow();
91 
92  SetFocus(m_CustomRespawn);
93  }
94 
95  override bool OnFocus(Widget w, int x, int y)
96  {
97  string tooltip_header = "";
98  string tooltip_text = "";
99  if (IsFocusable(w))
100  {
101  ColorHighlight(w);
102  switch (w.GetUserID())
103  {
104  case ID_RESPAWN_RANDOM:
105  tooltip_header = "#main_menu_respawn_random";
106  tooltip_text = "#main_menu_respawn_random_tooltip";
107  break;
108 
109  case ID_RESPAWN_CUSTOM:
110  tooltip_header = "#main_menu_respawn_custom";
111  tooltip_text = "#main_menu_respawn_custom_tooltip";
112  break;
113  }
114 
115  SetTooltipTexts(w, tooltip_header, tooltip_text);
116  return true;
117  }
118 
119  SetTooltipTexts(w, tooltip_header, tooltip_text);
120  return false;
121  }
122 
123  override bool OnFocusLost(Widget w, int x, int y)
124  {
125  if (IsFocusable(w))
126  {
127  ColorNormal(w);
128  return true;
129  }
130 
131  return false;
132  }
133 
134  bool IsFocusable(Widget w)
135  {
136  if (w)
137  {
138  if (w.GetUserID() == IDC_CANCEL || w.GetUserID() == ID_RESPAWN_CUSTOM || w.GetUserID() == ID_RESPAWN_RANDOM);
139  return true;
140  }
141 
142  return false;
143  }
144 
145  protected void ColorHighlight(Widget w)
146  {
147  if (!w)
148  return;
149 
150  if (m_CurrentlyHighlighted != w)
151  {
152  if (m_CurrentlyHighlighted)
153  ColorNormal(m_CurrentlyHighlighted);
154 
155  m_CurrentlyHighlighted = w;
156  }
157 
158  ButtonSetColor(w, ARGB(255, 0, 0, 0));
159  ButtonSetTextColor(w, ARGB(255, 255, 0, 0));
160  }
161 
162  protected void ColorNormal(Widget w)
163  {
164  if (!w)
165  return;
166 
167  ButtonSetColor(w, ARGB(0, 0, 0, 0));
168  ButtonSetTextColor(w, ARGB(255, 255, 255, 255));
169  }
170 
171  protected void ButtonSetColor(Widget w, int color)
172  {
173  Widget panel = w.FindWidget(w.GetName() + "_panel");
174  if (panel)
175  panel.SetColor(color);
176  }
177 
178  protected void ButtonSetTextColor(Widget w, int color)
179  {
180  TextWidget label = TextWidget.Cast(w.FindAnyWidget(w.GetName() + "_label"));
181  if (label)
182  label.SetColor(color);
183  }
184 
185  void SetTooltipTexts(Widget w, string header = "", string desc = "")
186  {
187  bool show = header != "" && desc != "";
188  m_DetailsRoot.Show(show);
189  m_DetailsLabel.SetText(header);
190  m_DetailsText.SetText(desc);
191 
192  m_DetailsText.Update();
193  m_DetailsLabel.Update();
194  m_DetailsRoot.Update();
195  }
196 
197  bool RequestRespawn(bool random)
198  {
199  IngameHud.Cast(GetGame().GetMission().GetHud()).InitBadgesAndNotifiers();
200  Man player = GetGame().GetPlayer();
201  if (player && (player.GetPlayerState() == EPlayerStates.ALIVE && !player.IsUnconscious()))
202  return false;
203 
204  #ifdef PLATFORM_CONSOLE
205  InGameMenuXbox menu_ingame = InGameMenuXbox.Cast(GetGame().GetUIManager().FindMenu(MENU_INGAME));
206  #else
207  InGameMenu menu_ingame = InGameMenu.Cast(GetGame().GetUIManager().FindMenu(MENU_INGAME));
208  #endif
209 
210  if (!menu_ingame)
211  return false;
212 
213  menu_ingame.MenuRequestRespawn(this, random);
214  return true;
215  }
216 }
GetGame
proto native CGame GetGame()
UIScriptedMenu
Definition: dayzgame.c:63
IDC_CANCEL
const int IDC_CANCEL
Definition: constants.c:128
Close
void Close()
y
Icon y
OnMouseLeave
override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
Definition: uihintpanel.c:276
RichTextWidget
Definition: gameplay.c:315
Init
class InventoryGridController extends ScriptedWidgetEventHandler Init
Definition: uihintpanel.c:46
TextWidget
Definition: enwidgets.c:219
ColorNormal
void ColorNormal(Widget w)
Definition: serverbrowsertab.c:668
ColorHighlight
void ColorHighlight(Widget w)
Definition: serverbrowsertab.c:619
EPlayerStates
EPlayerStates
Definition: eplayerstates.c:1
OnFocusLost
override bool OnFocusLost(Widget w, int x, int y)
Definition: serverbrowsertab.c:235
Update
proto native volatile void Update()
Definition: playersoundmanager.c:125
MENU_INGAME
const int MENU_INGAME
Definition: constants.c:168
SetFocus
proto native void SetFocus(Widget w)
x
Icon x
OnFocus
override bool OnFocus(Widget w, int x, int y)
Definition: serverbrowsertab.c:217
OnShow
override void OnShow()
Definition: controlsxbox.c:349
Widget
Definition: enwidgets.c:189
GetUApi
proto native UAInputAPI GetUApi()
OnClick
override bool OnClick(Widget w, int x, int y, int button)
buttons clicks
Definition: dayzgame.c:146
OnMouseEnter
override bool OnMouseEnter(Widget w, int x, int y)
Definition: uihintpanel.c:267
ARGB
int ARGB(int a, int r, int g, int b)
Definition: proto.c:322
IsFocusable
bool IsFocusable(Widget w)
Definition: serverbrowsertab.c:284