Dayz Explorer 1.28.160049
Loading...
Searching...
No Matches
respawndialogue.c
Go to the documentation of this file.
1class 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;
10
11 protected Widget m_CustomRespawn;
12
13 //helper
14 protected Widget m_CurrentlyHighlighted;
15
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 Man player = GetGame().GetPlayer();
37 bool playerAlive = player && player.GetPlayerState() == EPlayerStates.ALIVE;
38 if (playerAlive && !player.IsUnconscious())
39 {
40 Close();
41 return;
42 }
43
44 if (GetUApi().GetInputByID(UAUIBack).LocalPress() || GetUApi().GetInputByID(UAUIMenu).LocalPress())
45 Close();
46 }
47
48 override bool OnClick(Widget w, int x, int y, int button)
49 {
50 super.OnClick(w, x, y, button);
51
52 switch (w.GetUserID())
53 {
54 case IDC_CANCEL:
55 Close();
56 return true;
57
58 case ID_RESPAWN_CUSTOM:
59 return RequestRespawn(false);
60
61 case ID_RESPAWN_RANDOM:
62 return RequestRespawn(true);
63 }
64
65 return false;
66 }
67
68 override bool OnMouseEnter(Widget w, int x, int y)
69 {
70 string tooltip_header = "";
71 string tooltip_text = "";
73 switch (w.GetUserID())
74 {
75 case ID_RESPAWN_RANDOM:
76 tooltip_header = "#main_menu_respawn_random";
77 tooltip_text = "#main_menu_respawn_random_tooltip";
78 break;
79
80 case ID_RESPAWN_CUSTOM:
81 tooltip_header = "#main_menu_respawn_custom";
82 tooltip_text = "#main_menu_respawn_custom_tooltip";
83 break;
84 }
85
86 SetTooltipTexts(w, tooltip_header, tooltip_text);
87 return true;
88 }
89
90 override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
91 {
92 ColorNormal(w);
93 return true;
94 }
95
96 override void OnShow()
97 {
98 super.OnShow();
99
100 SetFocus(m_CustomRespawn);
101 }
102
103 override bool OnFocus(Widget w, int x, int y)
104 {
105 string tooltip_header = "";
106 string tooltip_text = "";
107 if (IsFocusable(w))
108 {
110 switch (w.GetUserID())
111 {
112 case ID_RESPAWN_RANDOM:
113 tooltip_header = "#main_menu_respawn_random";
114 tooltip_text = "#main_menu_respawn_random_tooltip";
115 break;
116
117 case ID_RESPAWN_CUSTOM:
118 tooltip_header = "#main_menu_respawn_custom";
119 tooltip_text = "#main_menu_respawn_custom_tooltip";
120 break;
121 }
122
123 SetTooltipTexts(w, tooltip_header, tooltip_text);
124 return true;
125 }
126
127 SetTooltipTexts(w, tooltip_header, tooltip_text);
128 return false;
129 }
130
131 override bool OnFocusLost(Widget w, int x, int y)
132 {
133 if (IsFocusable(w))
134 {
135 ColorNormal(w);
136 return true;
137 }
138
139 return false;
140 }
141
142 bool IsFocusable(Widget w)
143 {
144 if (w)
145 {
146 if (w.GetUserID() == IDC_CANCEL || w.GetUserID() == ID_RESPAWN_CUSTOM || w.GetUserID() == ID_RESPAWN_RANDOM)
147 return true;
148 }
149
150 return false;
151 }
152
153 protected void ColorHighlight(Widget w)
154 {
155 if (!w)
156 return;
157
158 if (m_CurrentlyHighlighted != w)
159 {
160 if (m_CurrentlyHighlighted)
161 ColorNormal(m_CurrentlyHighlighted);
162
163 m_CurrentlyHighlighted = w;
164 }
165
166 ButtonSetColor(w, ARGB(255, 0, 0, 0));
167 ButtonSetTextColor(w, ARGB(255, 255, 0, 0));
168 }
169
170 protected void ColorNormal(Widget w)
171 {
172 if (!w)
173 return;
174
175 ButtonSetColor(w, ARGB(0, 0, 0, 0));
176 ButtonSetTextColor(w, ARGB(255, 255, 255, 255));
177 }
178
179 protected void ButtonSetColor(Widget w, int color)
180 {
181 Widget panel = w.FindWidget(w.GetName() + "_panel");
182 if (panel)
183 panel.SetColor(color);
184 }
185
186 protected void ButtonSetTextColor(Widget w, int color)
187 {
188 TextWidget label = TextWidget.Cast(w.FindAnyWidget(w.GetName() + "_label"));
189 if (label)
190 label.SetColor(color);
191 }
192
193 void SetTooltipTexts(Widget w, string header = "", string desc = "")
194 {
195 bool show = header != "" && desc != "";
196 m_DetailsRoot.Show(show);
197 m_DetailsLabel.SetText(header);
198 m_DetailsText.SetText(desc);
199
200 m_DetailsText.Update();
201 m_DetailsLabel.Update();
202 m_DetailsRoot.Update();
203 }
204
205 bool RequestRespawn(bool random)
206 {
207 IngameHud.Cast(GetGame().GetMission().GetHud()).InitBadgesAndNotifiers();
208 Man player = GetGame().GetPlayer();
209 if (player && (player.GetPlayerState() == EPlayerStates.ALIVE && !player.IsUnconscious()))
210 return false;
211
212 #ifdef PLATFORM_CONSOLE
213 InGameMenuXbox menu_ingame = InGameMenuXbox.Cast(GetGame().GetUIManager().FindMenu(MENU_INGAME));
214 #else
215 InGameMenu menu_ingame = InGameMenu.Cast(GetGame().GetUIManager().FindMenu(MENU_INGAME));
216 #endif
217
218 if (!menu_ingame)
219 return false;
220
221 menu_ingame.MenuRequestRespawn(this, random);
222 return true;
223 }
224}
void ~RespawnDialogue()
RichTextWidget m_DetailsText
bool RequestRespawn(bool random)
override bool OnMouseEnter(Widget w, int x, int y)
override void OnShow()
override bool OnFocus(Widget w, int x, int y)
override void Update(float timeslice)
void ColorHighlight(Widget w)
bool IsFocusable(Widget w)
void SetTooltipTexts(Widget w, string header="", string desc="")
override bool OnFocusLost(Widget w, int x, int y)
override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
Widget m_CurrentlyHighlighted
void RespawnDialogue()
void ButtonSetTextColor(Widget w, int color)
override Widget Init()
override bool OnClick(Widget w, int x, int y, int button)
void ButtonSetColor(Widget w, int color)
void ColorNormal(Widget w)
EPlayerStates
proto native CGame GetGame()
const int MENU_INGAME
Definition constants.c:178
const int IDC_CANCEL
Definition constants.c:136
Icon x
Icon y
void Close()
int ARGB(int a, int r, int g, int b)
Definition proto.c:322
Widget m_DetailsRoot
proto native UAInputAPI GetUApi()