DayZ Scripts
v1.21.156300 ยท Jun 20, 2023
 
Loading...
Searching...
No Matches
InGameMenu.c
Go to the documentation of this file.
1class InGameMenu extends UIScriptedMenu
2{
4
18
20 protected ref TextWidget m_ServerIP;
21 protected ref TextWidget m_ServerPort;
22 protected ref TextWidget m_ServerName;
23
24 protected ref UiHintPanel m_HintPanel;
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 {
59 ButtonSetText(m_RestartButton, "#main_menu_respawn");
60 }
61 else
62 {
63 ButtonSetText(m_RestartButton, "#main_menu_restart");
64 }
65
66 HudShow(false);
68 SetServerInfoVisibility(SetServerInfo() && g_Game.GetProfileOption(EDayZProfilesOptions.SERVERINFO_DISPLAY));
69 m_ModdedWarning.Show(g_Game.ReportModded());
70
71 Mission mission = g_Game.GetMission();
72 if (mission)
73 mission.Pause();
74
75 return layoutRoot;
76 }
77
78 protected void SetGameVersion()
79 {
80 TextWidget version_widget = TextWidget.Cast(layoutRoot.FindAnyWidget("version"));
81 string version;
82 GetGame().GetVersion(version);
83 version_widget.SetText("#main_menu_version" + " " + version);
84
85 #ifdef PREVIEW_BUILD
86 version_widget.SetText("THIS IS PREVIEW");
87 #endif
88 }
89
90 protected bool SetServerInfo()
91 {
92 if (GetGame().IsMultiplayer())
93 {
94 MenuData menu_data = g_Game.GetMenuData();
95 GetServersResultRow info = OnlineServices.GetCurrentServerInfo();
96
97 if (info)
98 {
99 m_ServerPort.SetText(info.m_HostPort.ToString());
100 m_ServerIP.SetText(info.m_HostIp);
101 m_ServerName.SetText(info.m_Name);
102 m_UnfavoriteImage.Show(info.m_Favorite);
103 m_FavoriteImage.Show(!info.m_Favorite);
104 m_ServerInfoText = "" + info.GetIpPort();
105
106 return true;
107 }
108 //temporary, incomplete solution, OnlineServices.GetCurrentServerInfo() should be working!
109 else if (menu_data && menu_data.GetLastPlayedCharacter() != GameConstants.DEFAULT_CHARACTER_MENU_ID)
110 {
111 int char_id = menu_data.GetLastPlayedCharacter();
112 int port;
113 string address,name;
114
115 menu_data.GetLastServerAddress(char_id,address);
116 port = menu_data.GetLastServerPort(char_id);
117 menu_data.GetLastServerName(char_id,name);
118 m_ServerPort.SetText(port.ToString());
119 m_ServerIP.SetText(address);
120 m_ServerName.SetText(name);
121 m_ServerInfoText = "" + address + ":" + port;
122
123 return true;
124 }
125 else
126 {
127 g_Game.RefreshCurrentServerInfo();
128 }
129 }
130 return false;
131 }
132
133 protected void HudShow(bool show)
134 {
136 if (mission)
137 {
138 IngameHud hud = IngameHud.Cast(mission.GetHud());
139 if (hud)
140 {
141 hud.ShowHudUI(g_Game.GetProfileOption(EDayZProfilesOptions.HUD) && show);
142 hud.ShowQuickbarUI(g_Game.GetProfileOption(EDayZProfilesOptions.QUICKBAR) && show);
143 }
144 }
145 }
146
147 override bool OnMouseEnter(Widget w, int x, int y)
148 {
150 return true;
151 }
152
153 override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
154 {
155 ColorNormal(w);
156 return true;
157 }
158
159 override bool OnClick(Widget w, int x, int y, int button)
160 {
161 super.OnClick(w, x, y, button);
162
163 if (w == m_ContinueButton)
164 {
166 return true;
167 }
168 else if (w == m_RestartButton)
169 {
171 return true;
172 }
173 else if (w == m_RespawnButton)
174 {
176 return true;
177 }
178 else if (w == m_OptionsButton)
179 {
181 return true;
182 }
183 else if (w == m_ExitButton)
184 {
185 OnClick_Exit();
186 return true;
187 }
188 else if (w == m_CopyInfoButton)
189 {
190 GetGame().CopyToClipboard(m_ServerInfoText);
191 }
192
193 return false;
194 }
195
196 protected void OnClick_Continue()
197 {
199 }
200
201 protected void OnClick_Restart()
202 {
203 if (!GetGame().IsMultiplayer())
204 {
206 }
207 else
208 {
210 }
211 }
212
213 protected void OnClick_Respawn()
214 {
215 Man player = GetGame().GetPlayer();
216
217 if (player && player.IsUnconscious())
218 {
219 GetGame().GetUIManager().ShowDialog("#main_menu_respawn", "#main_menu_respawn_question", IDC_INT_RETRY, DBT_YESNO, DBB_YES, DMT_QUESTION, this);
220 }
221 else
222 {
223 if (GetGame().GetMission().GetRespawnModeClient() == GameConstants.RESPAWN_MODE_CUSTOM)
224 {
225 GetGame().GetCallQueue(CALL_CATEGORY_GUI).Call(GetGame().GetUIManager().EnterScriptedMenu,MENU_RESPAWN_DIALOGUE,this);
226 }
227 else
228 {
229 GameRespawn(true);
230 }
231 }
232 }
233
234 protected void OnClick_Options()
235 {
236 EnterScriptedMenu(MENU_OPTIONS);
237 }
238
239 protected void OnClick_Exit()
240 {
242 GetGame().GetCallQueue(CALL_CATEGORY_GUI).Call(GetGame().GetMission().CreateLogoutMenu, this);
243 }
244
245 override bool OnModalResult(Widget w, int x, int y, int code, int result)
246 {
247 super.OnModalResult(w, x, y, code, result);
248 if (code == IDC_INT_EXIT && result == DBB_YES)
249 {
250 if (GetGame().IsMultiplayer())
251 {
253 GetGame().GetCallQueue(CALL_CATEGORY_GUI).Call(GetGame().GetMission().CreateLogoutMenu, this);
254 }
255 else
256 {
257 // skip logout screen in singleplayer
259 }
260 g_Game.CancelLoginTimeCountdown();
261 return true;
262 }
263 else if (code == IDC_INT_EXIT && result == DBB_NO)
264 {
265 g_Game.CancelLoginTimeCountdown();
266 }
267 else if (code == IDC_INT_RETRY && result == DBB_YES && GetGame().IsMultiplayer())
268 {
269 if (GetGame().GetMission().GetRespawnModeClient() == GameConstants.RESPAWN_MODE_CUSTOM)
270 {
271 GetGame().GetCallQueue(CALL_CATEGORY_GUI).Call(GetGame().GetUIManager().EnterScriptedMenu,MENU_RESPAWN_DIALOGUE,this);
272 }
273 else
274 {
275 GameRespawn(true);
276 }
277 return true;
278 }
279
280 return false;
281 }
282
283 override void Update(float timeslice)
284 {
285 super.Update(timeslice);
286
287 UpdateGUI();
288 }
289
290 protected void UpdateGUI()
291 {
292 #ifdef BULDOZER
293 m_RestartButton.Show(false);
294 m_RespawnButton.Show(false);
295 #else
296 Man player = GetGame().GetPlayer();
297 bool playerAlive = player && player.GetPlayerState() == EPlayerStates.ALIVE;
298
299 if (GetGame().IsMultiplayer())
300 {
301 m_RestartButton.Show(playerAlive && player.IsUnconscious());
302 m_RespawnButton.Show(!playerAlive);
303 }
304 else
305 {
306 m_RestartButton.Show(true);
307 m_RespawnButton.Show(false);
308 m_SeparatorPanel.Show(playerAlive);
309 }
310
311 m_ContinueButton.Show(playerAlive);
312 #endif
313 }
314
315 void MenuRequestRespawn(UIScriptedMenu menu, bool random)
316 {
317 if (RespawnDialogue.Cast(menu))
318 GameRespawn(random);
319 }
320
321 protected void GameRespawn(bool random)
322 {
325
326 PlayerBase player = PlayerBase.Cast(GetGame().GetPlayer());
327 if (player)
328 {
329 player.SimulateDeath(true);
330 GetGame().GetCallQueue(CALL_CATEGORY_GUI).Call(player.ShowDeadScreen, true, 0);
331 }
332
333 MissionGameplay missionGP = MissionGameplay.Cast(GetGame().GetMission());
334 missionGP.DestroyAllMenus();
335 missionGP.SetPlayerRespawning(true);
336 missionGP.Continue();
337
338 Close();
339 }
340
341 protected void ColorHighlight(Widget w)
342 {
343 if (!w)
344 return;
345
346 ButtonSetColor(w, ARGB(255, 0, 0, 0));
347 ButtonSetTextColor(w, ARGB(255, 255, 0, 0));
348 }
349
350 protected void ColorNormal(Widget w)
351 {
352 if (!w)
353 return;
354
355 ButtonSetColor(w, ARGB(0, 0, 0, 0));
356 ButtonSetTextColor(w, ARGB(255, 255, 255, 255));
357 }
358
359 protected void ColorDisable(Widget w)
360 {
361 if (!w)
362 return;
363
364 ButtonSetColor(w, ARGB(0, 0, 0, 0));
366 }
367
368 protected void ButtonSetText(Widget w, string text)
369 {
370 if (!w)
371 return;
372
373 TextWidget label = TextWidget.Cast(w.FindWidget(w.GetName() + "_label"));
374 if (label)
375 label.SetText(text);
376
377 }
378
379 protected void ButtonSetColor(Widget w, int color)
380 {
381 Widget panel = w.FindWidget(w.GetName() + "_panel");
382 if (panel)
383 panel.SetColor(color);
384 }
385
386 protected void ButtonSetTextColor(Widget w, int color)
387 {
388 TextWidget label = TextWidget.Cast(w.FindAnyWidget(w.GetName() + "_label"));
389 if (label)
390 label.SetColor(color);
391 }
392
394 {
395 m_ServerInfoPanel.Show(show);
396 }
397
400}
ref UiHintPanelLoading m_HintPanel
Definition DayZGame.c:688
DayZGame g_Game
Definition DayZGame.c:3654
TextWidget m_ModdedWarning
Definition DayZGame.c:673
Mission mission
EDayZProfilesOptions
EPlayerStates
Icon x
Icon y
void Close()
PlayerBase GetPlayer()
string name
void UiHintPanel(Widget parent_widget)
proto native void RespawnPlayer()
proto void GetVersion(out string version)
proto native Mission GetMission()
MenuDefaultCharacterData GetMenuDefaultCharacterData(bool fill_data=true)
Definition Game.c:1392
proto native void CopyToClipboard(string text)
proto native DayZPlayer GetPlayer()
override ScriptCallQueue GetCallQueue(int call_category)
Definition DayZGame.c:1153
proto native UIManager GetUIManager()
proto native void LogoutRequestTime()
Logout methods.
proto native WorkspaceWidget GetWorkspace()
static int COLOR_DISABLED_TEXT
proto native int GetLastServerPort(int index)
proto native int GetLastPlayedCharacter()
proto void GetLastServerAddress(int index, out string address)
proto void GetLastServerName(int index, out string address)
void SetRandomCharacterForced(bool state)
Definition gameplay.c:1069
Mission class.
Definition gameplay.c:670
Hud GetHud()
Definition gameplay.c:697
void AbortMission()
Definition gameplay.c:747
void Pause()
Definition gameplay.c:744
void Continue()
Definition gameplay.c:745
static void GetCurrentServerInfo(string ip, int port)
proto void Call(func fn, void param1=NULL, void param2=NULL, void param3=NULL, void param4=NULL, void param5=NULL, void param6=NULL, void param7=NULL, void param8=NULL, void param9=NULL)
adds call into the queue with given parameters and arguments (arguments are held in memory until the ...
proto native void ShowDialog(string caption, string text, int id, int butts, int def, int type, UIScriptedMenu handler)
Shows message dialog.
protected ref UiHintPanel m_HintPanel
Definition InGameMenu.c:24
protected void OnClick_Respawn()
Definition InGameMenu.c:213
protected void OnClick_Restart()
Definition InGameMenu.c:201
protected void ColorDisable(Widget w)
Definition InGameMenu.c:359
void ButtonSetText(Widget w, string text)
override void Update(float timeslice)
Definition InGameMenu.c:283
protected void SetGameVersion()
Definition InGameMenu.c:78
protected void ColorNormal(Widget w)
Definition InGameMenu.c:350
void MenuRequestRespawn(UIScriptedMenu menu, bool random)
Definition InGameMenu.c:315
string m_ServerInfoText
Definition InGameMenu.c:3
protected void OnClick_Exit()
Definition InGameMenu.c:239
protected Widget m_ExitButton
Definition InGameMenu.c:7
override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
Definition InGameMenu.c:153
void ButtonSetColor(Widget w, int color)
protected Widget m_RestartDeadRandomButton
Definition InGameMenu.c:10
protected ref TextWidget m_ServerPort
Definition InGameMenu.c:21
protected Widget m_RespawnButton
Definition InGameMenu.c:9
void ButtonSetTextColor(Widget w, int color)
protected Widget m_OptionsButton
Definition InGameMenu.c:12
protected Widget m_CopyInfoButton
Definition InGameMenu.c:17
protected void OnClick_Options()
Definition InGameMenu.c:234
protected void OnClick_Continue()
Definition InGameMenu.c:196
void ColorNormal(Widget w)
protected void ColorHighlight(Widget w)
Definition InGameMenu.c:341
protected bool SetServerInfo()
Definition InGameMenu.c:90
override Widget Init()
Definition InGameMenu.c:35
protected ref TextWidget m_ServerName
Definition InGameMenu.c:22
protected Widget m_FavoriteImage
Definition InGameMenu.c:15
protected Widget m_ContinueButton
Definition InGameMenu.c:5
protected void UpdateGUI()
Definition InGameMenu.c:290
protected void ButtonSetText(Widget w, string text)
Definition InGameMenu.c:368
protected Widget m_SeparatorPanel
Definition InGameMenu.c:6
override bool OnModalResult(Widget w, int x, int y, int code, int result)
Definition InGameMenu.c:245
protected Widget m_UnfavoriteImage
Definition InGameMenu.c:16
protected void HudShow(bool show)
Definition InGameMenu.c:133
override bool OnMouseEnter(Widget w, int x, int y)
Definition InGameMenu.c:147
void SetServerInfoVisibility(bool show)
Definition InGameMenu.c:393
protected ref TextWidget m_ModdedWarning
Definition InGameMenu.c:19
void ~InGameMenu()
Definition InGameMenu.c:26
void ToggleFavoriteServer()
DEPRECATED.
protected Widget m_RestartDeadCustomButton
Definition InGameMenu.c:11
protected ref TextWidget m_ServerIP
Definition InGameMenu.c:20
void ColorHighlight(Widget w)
protected Widget m_RestartButton
Definition InGameMenu.c:8
protected Widget m_FavoriteButton
Definition InGameMenu.c:14
override bool OnClick(Widget w, int x, int y, int button)
Definition InGameMenu.c:159
protected void ButtonSetTextColor(Widget w, int color)
Definition InGameMenu.c:386
protected void ButtonSetColor(Widget w, int color)
Definition InGameMenu.c:379
protected Widget m_ServerInfoPanel
Definition InGameMenu.c:13
protected void GameRespawn(bool random)
Definition InGameMenu.c:321
proto native CGame GetGame()
const int DEFAULT_CHARACTER_MENU_ID
Definition constants.c:825
const int RESPAWN_MODE_CUSTOM
Definition constants.c:878
const int MENU_RESPAWN_DIALOGUE
Definition constants.c:187
const int MENU_OPTIONS
Definition constants.c:161
void Continue()
Timer continue when it was paused.
Definition tools.c:246
const int CALL_CATEGORY_GUI
Definition tools.c:9
const int IDC_INT_EXIT
Definition constants.c:138
const int IDC_INT_RETRY
ingame menu
Definition constants.c:136
proto native external Widget CreateWidgets(string layout, Widget parentWidget=NULL, bool immedUpdate=true)
Create widgets from *.layout file.
int ARGB(int a, int r, int g, int b)
Definition proto.c:322