DayZ 1.24
Loading...
Searching...
No Matches
InGameMenu.c
Go to the documentation of this file.
1class InGameMenu extends UIScriptedMenu
2{
4
18
23
25
27 {
28 HudShow(true);
29
30 Mission mission = g_Game.GetMission();
31 if (mission)
33 }
34
35 override Widget Init()
36 {
37 layoutRoot = GetGame().GetWorkspace().CreateWidgets("gui/layouts/day_z_ingamemenu.layout");
38
39 m_ContinueButton = layoutRoot.FindAnyWidget("continuebtn");
40 m_SeparatorPanel = layoutRoot.FindAnyWidget("separator_red");
41 m_ExitButton = layoutRoot.FindAnyWidget("exitbtn");
42 m_RestartButton = layoutRoot.FindAnyWidget("restartbtn");
43 m_RespawnButton = layoutRoot.FindAnyWidget("respawn_button");
44 m_RestartDeadRandomButton = layoutRoot.FindAnyWidget("respawn_button_random");
45 m_RestartDeadCustomButton = layoutRoot.FindAnyWidget("respawn_button_custom");
46 m_OptionsButton = layoutRoot.FindAnyWidget("optionsbtn");
47 m_ModdedWarning = TextWidget.Cast(layoutRoot.FindAnyWidget("ModdedWarning"));
48 m_HintPanel = new UiHintPanel(layoutRoot.FindAnyWidget("hint_frame"));
49 m_ServerInfoPanel = layoutRoot.FindAnyWidget("server_info");
50 m_ServerIP = TextWidget.Cast(layoutRoot.FindAnyWidget("server_ip"));
51 m_ServerPort = TextWidget.Cast(layoutRoot.FindAnyWidget("server_port"));
52 m_ServerName = TextWidget.Cast(layoutRoot.FindAnyWidget("server_name"));
53 m_FavoriteImage = layoutRoot.FindAnyWidget("favorite_image");
54 m_UnfavoriteImage = layoutRoot.FindAnyWidget("unfavorite_image");
55 m_CopyInfoButton = layoutRoot.FindAnyWidget("copy_button");
56
57 if (GetGame().IsMultiplayer())
58 ButtonSetText(m_RestartButton, "#main_menu_respawn");
59 else
60 ButtonSetText(m_RestartButton, "#main_menu_restart");
61
62 HudShow(false);
63 SetGameVersion();
64 SetServerInfoVisibility(SetServerInfo() && g_Game.GetProfileOption(EDayZProfilesOptions.SERVERINFO_DISPLAY));
65 m_ModdedWarning.Show(g_Game.ReportModded());
66
67 Mission mission = g_Game.GetMission();
68 if (mission)
69 mission.Pause();
70
71 return layoutRoot;
72 }
73
74 protected void SetGameVersion()
75 {
76 TextWidget version_widget = TextWidget.Cast(layoutRoot.FindAnyWidget("version"));
77 string version;
78 GetGame().GetVersion(version);
79 version_widget.SetText("#main_menu_version" + " " + version);
80
81#ifdef PREVIEW_BUILD
82 version_widget.SetText("THIS IS PREVIEW");
83#endif
84 }
85
86 protected bool SetServerInfo()
87 {
88 if (GetGame().IsMultiplayer())
89 {
90 MenuData menu_data = g_Game.GetMenuData();
92
93 if (info)
94 {
95 m_ServerPort.SetText(info.m_HostPort.ToString());
96 m_ServerIP.SetText(info.m_HostIp);
97 m_ServerName.SetText(info.m_Name);
98 m_UnfavoriteImage.Show(info.m_Favorite);
99 m_FavoriteImage.Show(!info.m_Favorite);
100 m_ServerInfoText = "" + info.GetIpPort();
101
102 return true;
103 }
104 //temporary, incomplete solution, OnlineServices.GetCurrentServerInfo() should be working!
105 else if (menu_data && menu_data.GetLastPlayedCharacter() != GameConstants.DEFAULT_CHARACTER_MENU_ID)
106 {
107 int char_id = menu_data.GetLastPlayedCharacter();
108 int port;
109 string address, name;
110
111 menu_data.GetLastServerAddress(char_id, address);
112 port = menu_data.GetLastServerPort(char_id);
113 menu_data.GetLastServerName(char_id, name);
114 m_ServerPort.SetText(port.ToString());
115 m_ServerIP.SetText(address);
116 m_ServerName.SetText(name);
117 m_ServerInfoText = "" + address + ":" + port;
118
119 return true;
120 }
121 else
122 g_Game.RefreshCurrentServerInfo();
123 }
124 return false;
125 }
126
127 protected void HudShow(bool show)
128 {
129 Mission mission = GetGame().GetMission();
130 if (mission)
131 {
132 IngameHud hud = IngameHud.Cast(mission.GetHud());
133 if (hud)
134 {
135 hud.ShowHudUI(g_Game.GetProfileOption(EDayZProfilesOptions.HUD) && show);
136 hud.ShowQuickbarUI(g_Game.GetProfileOption(EDayZProfilesOptions.QUICKBAR) && show);
137 }
138 }
139 }
140
141 override bool OnMouseEnter(Widget w, int x, int y)
142 {
144 return true;
145 }
146
147 override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
148 {
149 ColorNormal(w);
150 return true;
151 }
152
153 override bool OnClick(Widget w, int x, int y, int button)
154 {
155 super.OnClick(w, x, y, button);
156
157 if (w == m_ContinueButton)
158 {
159 OnClick_Continue();
160 return true;
161 }
162 else if (w == m_RestartButton)
163 {
164#ifdef DEVELOPER
165 if (GetGame().IsMultiplayer() || (GetGame().GetPlayer() && GetGame().GetPlayer().IsUnconscious()))
166 OnClick_Restart();
167 else
168 {
169 PluginDeveloper plugin = PluginDeveloper.GetInstance();
170 if (plugin)
171 plugin.ToggleMissionLoader();
172 }
173#else
174 OnClick_Restart();
175#endif
176 return true;
177 }
178 else if (w == m_RespawnButton)
179 {
180 OnClick_Respawn();
181 return true;
182 }
183 else if (w == m_OptionsButton)
184 {
185 OnClick_Options();
186 return true;
187 }
188 else if (w == m_ExitButton)
189 {
190 OnClick_Exit();
191 return true;
192 }
193 else if (w == m_CopyInfoButton)
194 GetGame().CopyToClipboard(m_ServerInfoText);
195
196 return false;
197 }
198
199 protected void OnClick_Continue()
200 {
201 GetGame().GetCallQueue(CALL_CATEGORY_GUI).Call(GetGame().GetMission().Continue);
202 }
203
204 protected void OnClick_Restart()
205 {
206 if (!GetGame().IsMultiplayer())
207 GetGame().GetCallQueue(CALL_CATEGORY_GUI).Call(GetGame().RestartMission);
208 else
209 OnClick_Respawn();
210 }
211
212 protected void OnClick_Respawn()
213 {
214 Man player = GetGame().GetPlayer();
215
216 if (player && player.IsUnconscious() && !player.IsDamageDestroyed())
217 GetGame().GetUIManager().ShowDialog("#main_menu_respawn", "#main_menu_respawn_question", IDC_INT_RETRY, DBT_YESNO, DBB_YES, DMT_QUESTION, this);
218 else
219 {
220 if (GetGame().GetMission().GetRespawnModeClient() == GameConstants.RESPAWN_MODE_CUSTOM)
221 GetGame().GetCallQueue(CALL_CATEGORY_GUI).Call(GetGame().GetUIManager().EnterScriptedMenu, MENU_RESPAWN_DIALOGUE, this);
222 else
223 GameRespawn(true);
224 }
225 }
226
227 protected void OnClick_Options()
228 {
229 EnterScriptedMenu(MENU_OPTIONS);
230 }
231
232 protected void OnClick_Exit()
233 {
234 GetGame().LogoutRequestTime();
235 GetGame().GetCallQueue(CALL_CATEGORY_GUI).Call(GetGame().GetMission().CreateLogoutMenu, this);
236 }
237
238 override bool OnModalResult(Widget w, int x, int y, int code, int result)
239 {
240 super.OnModalResult(w, x, y, code, result);
241 if (code == IDC_INT_EXIT && result == DBB_YES)
242 {
243 if (GetGame().IsMultiplayer())
244 {
245 GetGame().LogoutRequestTime();
246 GetGame().GetCallQueue(CALL_CATEGORY_GUI).Call(GetGame().GetMission().CreateLogoutMenu, this);
247 }
248 else
249 {
250 // skip logout screen in singleplayer
251 GetGame().GetMission().AbortMission();
252 }
253 g_Game.CancelLoginTimeCountdown();
254 return true;
255 }
256 else if (code == IDC_INT_EXIT && result == DBB_NO)
257 g_Game.CancelLoginTimeCountdown();
258 else if (code == IDC_INT_RETRY && result == DBB_YES && GetGame().IsMultiplayer())
259 {
260 if (GetGame().GetMission().GetRespawnModeClient() == GameConstants.RESPAWN_MODE_CUSTOM)
261 GetGame().GetCallQueue(CALL_CATEGORY_GUI).Call(GetGame().GetUIManager().EnterScriptedMenu, MENU_RESPAWN_DIALOGUE, this);
262 else
263 GameRespawn(true);
264 return true;
265 }
266
267 return false;
268 }
269
270 override void Update(float timeslice)
271 {
272 super.Update(timeslice);
273
274 UpdateGUI();
275 }
276
277 protected void UpdateGUI()
278 {
279#ifdef BULDOZER
280 m_RestartButton.Show(false);
281 m_RespawnButton.Show(false);
282#else
283 Man player = GetGame().GetPlayer();
284 bool playerAlive = player && player.GetPlayerState() == EPlayerStates.ALIVE;
285
286 if (GetGame().IsMultiplayer())
287 {
288 m_RestartButton.Show(playerAlive && player.IsUnconscious() && !CfgGameplayHandler.GetDisableRespawnInUnconsciousness());
289 m_RespawnButton.Show(!playerAlive);
290 }
291 else
292 {
293 m_RestartButton.Show(true);
294 m_RespawnButton.Show(false);
295 m_SeparatorPanel.Show(playerAlive);
296 }
297
298 m_ContinueButton.Show(playerAlive);
299#endif
300 }
301
303 {
304 if (RespawnDialogue.Cast(menu))
305 GameRespawn(random);
306 }
307
308 protected void GameRespawn(bool random)
309 {
310 GetGame().GetMenuDefaultCharacterData(false).SetRandomCharacterForced(random);
311 GetGame().RespawnPlayer();
312
314 if (player)
315 {
316 player.SimulateDeath(true);
317 GetGame().GetCallQueue(CALL_CATEGORY_GUI).Call(player.ShowDeadScreen, true, 0);
318 }
319
320 MissionGameplay missionGP = MissionGameplay.Cast(GetGame().GetMission());
321 missionGP.DestroyAllMenus();
322 missionGP.SetPlayerRespawning(true);
323 missionGP.Continue();
324
325 Close();
326 }
327
328 protected void ColorHighlight(Widget w)
329 {
330 if (!w)
331 return;
332
333 ButtonSetColor(w, ARGB(255, 0, 0, 0));
334 ButtonSetTextColor(w, ARGB(255, 255, 0, 0));
335 }
336
337 protected void ColorNormal(Widget w)
338 {
339 if (!w)
340 return;
341
342 ButtonSetColor(w, ARGB(0, 0, 0, 0));
343 ButtonSetTextColor(w, ARGB(255, 255, 255, 255));
344 }
345
346 protected void ColorDisable(Widget w)
347 {
348 if (!w)
349 return;
350
351 ButtonSetColor(w, ARGB(0, 0, 0, 0));
352 ButtonSetTextColor(w, ColorManager.COLOR_DISABLED_TEXT);
353 }
354
355 protected void ButtonSetText(Widget w, string text)
356 {
357 if (!w)
358 return;
359
360 TextWidget label = TextWidget.Cast(w.FindWidget(w.GetName() + "_label"));
361 if (label)
362 label.SetText(text);
363
364 }
365
366 protected void ButtonSetColor(Widget w, int color)
367 {
368 Widget panel = w.FindWidget(w.GetName() + "_panel");
369 if (panel)
370 panel.SetColor(color);
371 }
372
373 protected void ButtonSetTextColor(Widget w, int color)
374 {
375 TextWidget label = TextWidget.Cast(w.FindAnyWidget(w.GetName() + "_label"));
376 if (label)
377 label.SetColor(color);
378 }
379
381 {
382 m_ServerInfoPanel.Show(show);
383 }
384
387}
PlayerSpawnPresetDiscreteItemSetSlotData name
one set for cargo
ref UiHintPanelLoading m_HintPanel
Definition DayZGame.c:676
DayZGame g_Game
Definition DayZGame.c:3528
TextWidget m_ModdedWarning
Definition DayZGame.c:661
Mission mission
EDayZProfilesOptions
EPlayerStates
Icon x
Icon y
void Close()
PlayerBase GetPlayer()
void ColorNormal(Widget w)
void ColorHighlight(Widget w)
void UiHintPanel(Widget parent_widget)
static bool GetDisableRespawnInUnconsciousness()
static int COLOR_DISABLED_TEXT
Mission class.
Definition gameplay.c:668
void Pause()
Definition gameplay.c:748
void Continue()
Definition gameplay.c:749
Hud GetHud()
Definition gameplay.c:701
static void GetCurrentServerInfo(string ip, int port)
void MenuRequestRespawn(UIScriptedMenu menu, bool random)
Definition InGameMenu.c:302
override bool OnMouseEnter(Widget w, int x, int y)
Definition InGameMenu.c:141
Widget m_ExitButton
Definition InGameMenu.c:7
ref TextWidget m_ServerIP
Definition InGameMenu.c:20
void ToggleFavoriteServer()
DEPRECATED.
void ColorDisable(Widget w)
Definition InGameMenu.c:346
void OnClick_Restart()
Definition InGameMenu.c:204
bool SetServerInfo()
Definition InGameMenu.c:86
void SetServerInfoVisibility(bool show)
Definition InGameMenu.c:380
override void Update(float timeslice)
Definition InGameMenu.c:270
Widget m_RespawnButton
Definition InGameMenu.c:9
Widget m_ContinueButton
Definition InGameMenu.c:5
void ColorHighlight(Widget w)
Definition InGameMenu.c:328
Widget m_FavoriteImage
Definition InGameMenu.c:15
Widget m_SeparatorPanel
Definition InGameMenu.c:6
void OnClick_Exit()
Definition InGameMenu.c:232
Widget m_RestartButton
Definition InGameMenu.c:8
void ButtonSetText(Widget w, string text)
Definition InGameMenu.c:355
ref TextWidget m_ServerPort
Definition InGameMenu.c:21
Widget m_RestartDeadCustomButton
Definition InGameMenu.c:11
void SetGameVersion()
Definition InGameMenu.c:74
ref TextWidget m_ModdedWarning
Definition InGameMenu.c:19
Widget m_OptionsButton
Definition InGameMenu.c:12
ref TextWidget m_ServerName
Definition InGameMenu.c:22
void ~InGameMenu()
Definition InGameMenu.c:26
override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
Definition InGameMenu.c:147
void GameRespawn(bool random)
Definition InGameMenu.c:308
Widget m_ServerInfoPanel
Definition InGameMenu.c:13
void OnClick_Continue()
Definition InGameMenu.c:199
string m_ServerInfoText
Definition InGameMenu.c:3
Widget m_UnfavoriteImage
Definition InGameMenu.c:16
Widget m_FavoriteButton
Definition InGameMenu.c:14
void ButtonSetTextColor(Widget w, int color)
Definition InGameMenu.c:373
ref UiHintPanel m_HintPanel
Definition InGameMenu.c:24
override Widget Init()
Definition InGameMenu.c:35
override bool OnClick(Widget w, int x, int y, int button)
Definition InGameMenu.c:153
void ButtonSetColor(Widget w, int color)
Definition InGameMenu.c:366
void HudShow(bool show)
Definition InGameMenu.c:127
override bool OnModalResult(Widget w, int x, int y, int code, int result)
Definition InGameMenu.c:238
void OnClick_Respawn()
Definition InGameMenu.c:212
void ColorNormal(Widget w)
Definition InGameMenu.c:337
Widget m_RestartDeadRandomButton
Definition InGameMenu.c:10
Widget m_CopyInfoButton
Definition InGameMenu.c:17
void OnClick_Options()
Definition InGameMenu.c:227
proto native CGame GetGame()
const int DEFAULT_CHARACTER_MENU_ID
Definition constants.c:840
const int RESPAWN_MODE_CUSTOM
Definition constants.c:901
const int MENU_RESPAWN_DIALOGUE
Definition constants.c:199
const int MENU_OPTIONS
Definition constants.c:173
void Continue()
Timer continue when it was paused.
Definition tools.c:235
const int CALL_CATEGORY_GUI
Definition tools.c:9
const int IDC_INT_EXIT
Definition constants.c:150
const int IDC_INT_RETRY
ingame menu
Definition constants.c:148
int ARGB(int a, int r, int g, int b)
Definition proto.c:322