DayZ Scripts
v1.21.156300 ยท Jun 20, 2023
 
Loading...
Searching...
No Matches
MainMenu.c
Go to the documentation of this file.
1class MainMenu extends UIScriptedMenu
2{
3 protected ref MainMenuStats m_Stats;
4 protected ref MainMenuVideo m_Video;
5
6 protected MissionMainMenu m_Mission;
8
10 protected TextWidget m_Version;
11
13
14 protected Widget m_Play;
22 protected Widget m_Exit;
23 protected Widget m_NewsMain;
24 protected Widget m_NewsSec1;
25 protected Widget m_NewsSec2;
28
34
35 protected ref WidgetFadeTimer m_LastPlayedTooltipTimer;
37
38 protected ref TextWidget m_ModdedWarning;
39 protected ref ModsMenuSimple m_ModsSimple;
40 protected ref ModsMenuDetailed m_ModsDetailed;
41 protected ref ModsMenuTooltip m_ModsTooltip;
42
43 override Widget Init()
44 {
45 layoutRoot = GetGame().GetWorkspace().CreateWidgets("gui/layouts/new_ui/main_menu.layout");
46
47 m_Play = layoutRoot.FindAnyWidget("play");
48 m_ChooseServer = layoutRoot.FindAnyWidget("choose_server");
49 m_CustomizeCharacter = layoutRoot.FindAnyWidget("customize_character");
50 m_PlayVideo = layoutRoot.FindAnyWidget("play_video");
51 m_Tutorials = layoutRoot.FindAnyWidget("tutorials");
52 m_TutorialButton = layoutRoot.FindAnyWidget("tutorial_button");
53 m_MessageButton = layoutRoot.FindAnyWidget("message_button");
54 m_SettingsButton = layoutRoot.FindAnyWidget("settings_button");
55 m_Exit = layoutRoot.FindAnyWidget("exit_button");
56 m_PrevCharacter = layoutRoot.FindAnyWidget("prev_character");
57 m_NextCharacter = layoutRoot.FindAnyWidget("next_character");
58
59 m_Version = TextWidget.Cast(layoutRoot.FindAnyWidget("version"));
60 m_ModdedWarning = TextWidget.Cast(layoutRoot.FindAnyWidget("ModdedWarning"));
61 m_CharacterRotationFrame = layoutRoot.FindAnyWidget("character_rotation_frame");
62
63 m_LastPlayedTooltip = layoutRoot.FindAnyWidget("last_server_info");
64 m_LastPlayedTooltip.Show(false);
65 m_LastPlayedTooltipLabel = m_LastPlayedTooltip.FindAnyWidget("last_server_info_label");
66 m_LastPlayedTooltipName = TextWidget.Cast(m_LastPlayedTooltip.FindAnyWidget("last_server_info_name"));
67 m_LastPlayedTooltipIP = TextWidget.Cast(m_LastPlayedTooltip.FindAnyWidget("last_server_info_ip"));
68 m_LastPlayedTooltipPort = TextWidget.Cast(m_LastPlayedTooltip.FindAnyWidget("last_server_info_port"));
69
70 m_LastPlayedTooltipTimer = new WidgetFadeTimer();
71
72 m_Stats = new MainMenuStats(layoutRoot.FindAnyWidget("character_stats_root"));
73
74 m_Mission = MissionMainMenu.Cast(GetGame().GetMission());
75
76 m_LastFocusedButton = m_Play;
77
78 m_ScenePC = m_Mission.GetIntroScenePC();
79
80 if (m_ScenePC)
81 {
82 m_ScenePC.ResetIntroCamera();
83 }
84
85 m_PlayVideo.Show(false);
86
87 m_PlayerName = TextWidget.Cast(layoutRoot.FindAnyWidget("character_name_text"));
88
89 // Set Version
90 string version;
91 GetGame().GetVersion(version);
92 m_Version.SetText("#main_menu_version" + " " + version);
93
95
96 SetFocus(null);
97
98 Refresh();
99
100 LoadMods();
101
102 GetDayZGame().GetBacklit().MainMenu_OnShow();
103
104 g_Game.SetLoadState(DayZLoadState.MAIN_MENU_CONTROLLER_SELECT);
105
106 return layoutRoot;
107 }
108
110 {
111
112 }
113
114 void LoadMods()
115 {
117 GetGame().GetModInfos(modArray);
118
119 if (modArray.Count() > 0)
120 {
121 modArray.Remove(modArray.Count() - 1);
122 modArray.Invert();
123 }
124
125 if (m_ModsSimple)
126 delete m_ModsSimple;
127 if (m_ModsDetailed)
128 delete m_ModsDetailed;
129
130 m_ModdedWarning.Show(GetGame().GetModToBeReported());
131
132 if (modArray.Count() > 0)
133 {
134 layoutRoot.FindAnyWidget("ModsSimple").Show(true);
135 m_ModsTooltip = new ModsMenuTooltip(layoutRoot);
136
137 m_ModsDetailed = new ModsMenuDetailed(modArray, layoutRoot.FindAnyWidget("ModsDetailed"), m_ModsTooltip, this);
138
139 m_ModsSimple = new ModsMenuSimple(modArray, layoutRoot.FindAnyWidget("ModsSimple"), m_ModsDetailed);
140 }
141 }
142
143 override bool OnMouseButtonDown(Widget w, int x, int y, int button)
144 {
145 if (w == m_CharacterRotationFrame)
146 {
147 if (m_ScenePC)
148 m_ScenePC.CharacterRotationStart();
149 return true;
150 }
151
152 return false;
153 }
154
155 override bool OnMouseButtonUp(Widget w, int x, int y, int button)
156 {
157 if (m_ScenePC)
158 m_ScenePC.CharacterRotationStop();
159 return false;
160 }
161
162 override bool OnClick(Widget w, int x, int y, int button)
163 {
164 if (button == MouseState.LEFT)
165 {
166 if (w == m_Play)
167 {
168 m_LastFocusedButton = m_Play;
169 Play();
170 return true;
171 }
172 else if (w == m_ChooseServer)
173 {
174 m_LastFocusedButton = m_ChooseServer;
176 return true;
177 }
178 else if (w == m_CustomizeCharacter)
179 {
181 return true;
182 }
183 else if (w == m_TutorialButton)
184 {
186 return true;
187 }
188 else if (w == m_MessageButton)
189 {
190 OpenCredits();
191 return true;
192 }
193 else if (w == m_SettingsButton)
194 {
195 OpenSettings();
196 return true;
197 }
198 else if (w == m_Exit)
199 {
200 Exit();
201 return true;
202 }
203 else if (w == m_PrevCharacter)
204 {
206 return true;
207 }
208 else if (w == m_NextCharacter)
209 {
211 return true;
212 }
213 else if (w == m_PlayVideo)
214 {
215 m_LastFocusedButton = m_PlayVideo;
216 PlayVideo();
217 return true;
218 }
219 else if (w == m_Tutorials)
220 {
221 m_LastFocusedButton = m_Tutorials;
223 return true;
224 }
225 }
226 return false;
227 }
228
229 override bool OnMouseEnter(Widget w, int x, int y)
230 {
231 if (w == m_Play)
232 {
233 string ip = "";
234 string name = "";
235 int port = 0;
236
237 if (m_ScenePC && !m_ScenePC.GetIntroCharacter().IsDefaultCharacter())
238 {
239 int charID = m_ScenePC.GetIntroCharacter().GetCharacterID();
240 m_ScenePC.GetIntroCharacter().GetLastPlayedServer(charID, ip, name, port);
241
242 m_LastPlayedTooltipName.SetText("#server_details_name " + name);
243 m_LastPlayedTooltipIP.SetText("#main_menu_IP " + ip);
244 m_LastPlayedTooltipPort.SetText("#main_menu_port " + port);
245
246 m_LastPlayedTooltipTimer.FadeIn(m_LastPlayedTooltip, 0.3, true);
247 }
248 }
249
250 if (IsFocusable(w))
251 {
253 return true;
254 }
255 return false;
256 }
257
258 override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
259 {
260 if (w == m_Play)
261 {
262 m_LastPlayedTooltipTimer.FadeOut(m_LastPlayedTooltip, 0.3, true);
263 }
264
265 if (IsFocusable(w))
266 {
267 ColorNormal(w);
268 return true;
269 }
270 return false;
271 }
272
273 override bool OnFocus(Widget w, int x, int y)
274 {
275 if (IsFocusable(w))
276 {
278 return true;
279 }
280 return false;
281 }
282
283 override bool OnFocusLost(Widget w, int x, int y)
284 {
285 if (IsFocusable(w))
286 {
287 ColorNormal(w);
288 return true;
289 }
290 return false;
291 }
292
294 {
295 if (w)
296 {
297 if (w == m_Play || w == m_ChooseServer || w == m_CustomizeCharacter || w == m_TutorialButton || w == m_MessageButton || w == m_SettingsButton);
298 {
299 return true;
300 }
301
302 if (w == m_Exit || w == m_PlayVideo);
303 {
304 return true;
305 }
306
307 if (w == m_NewsMain || w == m_NewsSec1 || w == m_NewsSec2 || w == m_PrevCharacter || w == m_NextCharacter);
308 {
309 return true;
310 }
311 }
312 return false;
313 }
314
315 override void Refresh()
316 {
317 string name;
318
319 if (m_ScenePC)
320 {
322 }
323
324 string version;
325 GetGame().GetVersion(version);
326 m_Version.SetText("#main_menu_version" + " " + version);
327 }
328
329 override void OnShow()
330 {
331 if (g_Game.GetGameState() != DayZGameState.MAIN_MENU)
332 return;
333
334 SetFocus(null);
335 OnChangeCharacter(false);
336 LoadMods();
337 return;
338 }
339
340 override void OnHide()
341 {
342 GetDayZGame().GetBacklit().MainMenu_OnHide();
343 }
344
345 override void Update(float timeslice)
346 {
347 super.Update(timeslice);
348
349 if (GetGame() && GetUApi().GetInputByID(UAUIBack).LocalPress())
350 {
351 Exit();
352 }
353 }
354
355 void Play()
356 {
357 if (!g_Game.IsNewCharacter())
358 {
359 GetGame().GetCallQueue(CALL_CATEGORY_GUI).CallByName(this, "ConnectLastSession");
360 }
361 else
362 {
363 GetGame().GetCallQueue(CALL_CATEGORY_GUI).CallByName(this, "ConnectBestServer");
364 }
365 }
366
368 {
369 if (m_ScenePC && m_ScenePC.GetIntroCharacter() && m_ScenePC.GetIntroCharacter().GetCharacterID() == -1)
370 {
371 return true;
372 }
373 return false;
374 }
375
377 {
378 EnterScriptedMenu(MENU_SERVER_BROWSER);
379 }
380
382 {
383 EnterScriptedMenu(MENU_CHARACTER);
384 }
385
387 {
388 if (m_ScenePC && m_ScenePC.GetIntroCharacter())
389 {
390 int charID = m_ScenePC.GetIntroCharacter().GetNextCharacterID();
391 if (charID != m_ScenePC.GetIntroCharacter().GetCharacterID())
392 {
393 m_ScenePC.GetIntroCharacter().SetCharacterID(charID);
395 }
396 }
397 }
398
400 {
401 if (m_ScenePC && m_ScenePC.GetIntroCharacter())
402 {
403 int charID = m_ScenePC.GetIntroCharacter().GetPrevCharacterID();
404 if (charID != m_ScenePC.GetIntroCharacter().GetCharacterID())
405 {
406 m_ScenePC.GetIntroCharacter().SetCharacterID(charID);
408 }
409 }
410 }
411
412 void OnChangeCharacter(bool create_character = true)
413 {
414 if (m_ScenePC && m_ScenePC.GetIntroCharacter())
415 {
416 int charID = m_ScenePC.GetIntroCharacter().GetCharacterID();
417 if (create_character)
418 {
419 m_ScenePC.GetIntroCharacter().CreateNewCharacterById(charID);
420 }
421 m_PlayerName.SetText(m_ScenePC.GetIntroCharacter().GetCharacterNameById(charID));
422
423 Widget w = m_CustomizeCharacter.FindAnyWidget(m_CustomizeCharacter.GetName() + "_label");
424
425 if (w)
426 {
427 TextWidget text = TextWidget.Cast(w);
428
429 if (m_ScenePC.GetIntroCharacter().IsDefaultCharacter())
430 {
431 text.SetText("#layout_main_menu_customize_char");
432 }
433 else
434 {
435 text.SetText("#layout_main_menu_rename");
436 }
437 }
438 if (m_ScenePC.GetIntroCharacter().GetCharacterObj())
439 {
440 if (m_ScenePC.GetIntroCharacter().GetCharacterObj().IsMale())
441 m_ScenePC.GetIntroCharacter().SetCharacterGender(ECharGender.Male);
442 else
443 m_ScenePC.GetIntroCharacter().SetCharacterGender(ECharGender.Female);
444 }
445
446 //update character stats
447 m_Stats.UpdateStats();
448 }
449 }
450
452 {
453
454 }
455
457 {
458
459 }
460
462 {
463 EnterScriptedMenu(MENU_OPTIONS);
464 }
465
467 {
468 EnterScriptedMenu(MENU_VIDEO);
469 }
470
472 {
473 EnterScriptedMenu(MENU_TUTORIAL);
474 }
475
477 {
478 EnterScriptedMenu(MENU_CREDITS);
479 m_Mission.OnMenuEnter(MENU_CREDITS);
480 }
481
482 void Exit()
483 {
484 GetGame().GetUIManager().ShowDialog("#main_menu_exit", "#main_menu_exit_desc", IDC_MAIN_QUIT, DBT_YESNO, DBB_YES, DMT_QUESTION, this);
485 }
486
487 bool TryConnectLastSession(out string ip, out int port)
488 {
489 if (g_Game.GetLastVisitedServer(ip, port))
490 {
491 return true;
492 }
493 return false;
494 }
495
497 {
499 }
500
502 {
503 string ip = "";
504 string name = "";
505 int port = 0;
506
507 if (!m_ScenePC.GetIntroCharacter().IsDefaultCharacter())
508 {
509 int charID = m_ScenePC.GetIntroCharacter().GetCharacterID();
510 m_ScenePC.GetIntroCharacter().GetLastPlayedServer(charID,ip,name,port);
511 }
512
513 if (ip.Length() > 0)
514 {
515 g_Game.ConnectFromServerBrowser(ip, port, "");
516 }
517 else
518 {
520 }
521 }
522
524 {
526 }
527
528 override bool OnModalResult(Widget w, int x, int y, int code, int result)
529 {
530 if (code == IDC_MAIN_QUIT)
531 {
532 if (result == 2)
534 if (result == 3)
536 return true;
537 }
538 else if (code == 555)
539 {
540 if (result == 2)
542 }
543 return false;
544 }
545
546 //Coloring functions (Until WidgetStyles are useful)
548 {
549 if (!w)
550 return;
551
552 int color_pnl = ARGB(255, 0, 0, 0);
553 int color_lbl = ARGB(255, 255, 0, 0);
554 int color_img = ARGB(255, 200, 0, 0);
555
556 ButtonSetColor(w, color_pnl);
557 ButtonSetTextColor(w, color_lbl);
558 ImagenSetColor(w, color_img);
559 }
560
562 {
563 if (!w)
564 return;
565
566 int color_pnl = ARGB(0, 0, 0, 0);
567 int color_lbl = ARGB(255, 255, 255, 255);
568 int color_img = ARGB(255, 255, 255, 255);
569
570 ButtonSetColor(w, color_pnl);
571 ButtonSetTextColor(w, color_lbl);
572 ImagenSetColor(w, color_img);
573 }
574
575 void ButtonSetText(Widget w, string text)
576 {
577 if (!w)
578 return;
579
580 TextWidget label = TextWidget.Cast(w.FindWidget(w.GetName() + "_label"));
581
582 if (label)
583 {
584 label.SetText(text);
585 }
586
587 }
588
589 void ButtonSetColor(Widget w, int color)
590 {
591 if (!w)
592 return;
593
594 Widget panel = w.FindWidget(w.GetName() + "_panel");
595
596 if (panel)
597 {
598 panel.SetColor(color);
599 }
600 }
601
602 void ImagenSetColor(Widget w, int color)
603 {
604 if (!w)
605 return;
606
607 Widget panel = w.FindWidget(w.GetName() + "_image");
608
609 if (panel)
610 {
611 panel.SetColor(color);
612 }
613 }
614
615 void ButtonSetTextColor(Widget w, int color)
616 {
617 if (!w)
618 return;
619
620 TextWidget label = TextWidget.Cast(w.FindAnyWidget(w.GetName() + "_label"));
621 TextWidget text = TextWidget.Cast(w.FindAnyWidget(w.GetName() + "_text"));
622 TextWidget text2 = TextWidget.Cast(w.FindAnyWidget(w.GetName() + "_text_1"));
623
624 if (label)
625 {
626 label.SetColor(color);
627 }
628
629 if (text)
630 {
631 text.SetColor(color);
632 }
633
634 if (text2)
635 {
636 text2.SetColor(color);
637 }
638 }
639}
DayZGame g_Game
Definition DayZGame.c:3654
TextWidget m_ModdedWarning
Definition DayZGame.c:673
DayZGame GetDayZGame()
Definition DayZGame.c:3656
protected Mission m_Mission
ECharGender
Definition ECharGender.c:2
Icon x
Icon y
string name
ref array< ref StatDebugObject > m_Stats
proto native UAInputAPI GetUApi()
proto void GetVersion(out string version)
override ScriptCallQueue GetCallQueue(int call_category)
Definition DayZGame.c:1153
proto native void GetModInfos(notnull out array< ref ModInfo > modArray)
proto native UIManager GetUIManager()
proto native WorkspaceWidget GetWorkspace()
IntroSceneCharacter GetIntroCharacter()
static void AutoConnectToEmptyServer()
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 void CallByName(Class obj, string fnName, Param params=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.
proto native void ScreenFadeOut(float duration)
bool TryConnectLastSession(out string ip, out int port)
Definition MainMenu.c:487
void ButtonSetText(Widget w, string text)
Definition MainMenu.c:575
protected ref Widget m_LastFocusedButton
Definition MainMenu.c:36
override void Update(float timeslice)
Definition MainMenu.c:345
bool CanSaveDefaultCharacter()
Definition MainMenu.c:367
protected Widget m_CustomizeCharacter
Definition MainMenu.c:16
protected TextWidget m_LastPlayedTooltipIP
Definition MainMenu.c:32
void OpenStats()
Definition MainMenu.c:451
void OpenMenuServerBrowser()
Definition MainMenu.c:376
protected Widget m_SettingsButton
Definition MainMenu.c:21
override void Refresh()
void OnChangeCharacter(bool create_character=true)
Definition MainMenu.c:412
protected ref ModsMenuDetailed m_ModsDetailed
Definition MainMenu.c:40
protected TextWidget m_LastPlayedTooltipName
Definition MainMenu.c:31
protected Widget m_TutorialButton
Definition MainMenu.c:19
override void OnShow()
Definition MainMenu.c:329
override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
Definition MainMenu.c:258
protected ref ModsMenuSimple m_ModsSimple
Definition MainMenu.c:39
void ConnectLastSession()
Definition MainMenu.c:501
protected TextWidget m_LastPlayedTooltipPort
Definition MainMenu.c:33
protected Widget m_CharacterRotationFrame
protected ref MainMenuStats m_Stats
Definition MainMenu.c:3
protected TextWidget m_PlayerName
Definition MainMenu.c:9
protected DayZIntroScenePC m_ScenePC
Definition MainMenu.c:7
void ButtonSetColor(Widget w, int color)
protected Widget m_LastPlayedTooltip
Definition MainMenu.c:29
void OpenSettings()
Definition MainMenu.c:461
protected Widget m_Tutorials
Definition MainMenu.c:18
protected Widget m_PrevCharacter
Definition MainMenu.c:26
void PreviousCharacter()
Definition MainMenu.c:399
void ButtonSetTextColor(Widget w, int color)
void LoadMods()
Definition MainMenu.c:114
void OpenTutorials()
Definition MainMenu.c:471
void ColorNormal(Widget w)
protected ref MainMenuVideo m_Video
Definition MainMenu.c:4
override void OnHide()
Definition MainMenu.c:340
void ~MainMenu()
Definition MainMenu.c:109
protected Widget m_MessageButton
Definition MainMenu.c:20
void OpenMenuCustomizeCharacter()
Definition MainMenu.c:381
void AutoConnect()
Definition MainMenu.c:496
void ConnectBestServer()
Definition MainMenu.c:523
void OpenMessages()
Definition MainMenu.c:456
override Widget Init()
Definition MainMenu.c:43
protected Widget m_NewsSec2
Definition MainMenu.c:25
protected ref WidgetFadeTimer m_LastPlayedTooltipTimer
Definition MainMenu.c:35
override bool OnModalResult(Widget w, int x, int y, int code, int result)
Definition MainMenu.c:528
protected Widget m_NextCharacter
Definition MainMenu.c:27
protected TextWidget m_Version
override bool OnFocusLost(Widget w, int x, int y)
Definition MainMenu.c:283
bool IsFocusable(Widget w)
override bool OnMouseEnter(Widget w, int x, int y)
Definition MainMenu.c:229
override bool OnMouseButtonDown(Widget w, int x, int y, int button)
Definition MainMenu.c:143
protected ref TextWidget m_ModdedWarning
Definition InGameMenu.c:19
protected Widget m_NewsMain
Definition MainMenu.c:23
protected Widget m_ChooseServer
Definition MainMenu.c:15
protected Widget m_PlayVideo
Definition MainMenu.c:17
void ImagenSetColor(Widget w, int color)
Definition MainMenu.c:602
protected Widget m_Play
Definition MainMenu.c:14
void ColorHighlight(Widget w)
void PlayVideo()
Definition MainMenu.c:466
override bool OnFocus(Widget w, int x, int y)
Definition MainMenu.c:273
protected ref ModsMenuTooltip m_ModsTooltip
Definition MainMenu.c:41
void OpenCredits()
Definition MainMenu.c:476
void NextCharacter()
Definition MainMenu.c:386
override bool OnClick(Widget w, int x, int y, int button)
Definition MainMenu.c:162
override bool OnMouseButtonUp(Widget w, int x, int y, int button)
Definition MainMenu.c:155
protected Widget m_Exit
Definition MainMenu.c:22
protected MissionMainMenu m_Mission
Definition MainMenu.c:6
protected Widget m_LastPlayedTooltipLabel
Definition MainMenu.c:30
protected Widget m_NewsSec1
Definition MainMenu.c:24
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
proto native CGame GetGame()
const int MENU_TUTORIAL
Definition constants.c:182
const int MENU_SERVER_BROWSER
Definition constants.c:178
const int MENU_OPTIONS
Definition constants.c:161
const int MENU_CREDITS
Definition constants.c:183
const int MENU_CHARACTER
Definition constants.c:152
const int MENU_VIDEO
Definition constants.c:180
MouseState
Definition EnSystem.c:311
proto native int Length()
Returns length of string.
const int CALL_CATEGORY_GUI
Definition tools.c:9
const int IDC_MAIN_QUIT
Definition constants.c:124
proto native Widget GetFocus()
proto native void SetFocus(Widget w)
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