DayZ 1.24
Loading...
Searching...
No Matches
MainMenuConsoles.c
Go to the documentation of this file.
2{
3 protected ref MainMenuVideo m_Video;
4
6 protected DayZIntroScenePC m_ScenePC;
7
8 protected TextWidget m_PlayerName;
9 protected TextWidget m_Version;
10
12 protected Widget m_CustomizeCharacter;
13 protected Widget m_PlayVideo;
14 protected Widget m_Tutorials;
15 protected Widget m_Options;
16 protected Widget m_Controls;
17 protected Widget m_Play;
18 protected Widget m_MessageButton;
19
20 protected ref Widget m_LastFocusedButton;
21
23 protected Widget m_DlcFrame;
24 protected ref map<string, ref ModInfo> m_AllDlcsMap;
25 protected ref JsonDataDLCList m_DlcData;
26 protected ref array<ref MainMenuDlcHandlerBase> m_DlcHandlers;
27 protected ref MainMenuDlcHandlerBase m_DisplayedDlcHandler;
28
29 override Widget Init()
30 {
31 layoutRoot = GetGame().GetWorkspace().CreateWidgets("gui/layouts/new_ui/main_menu_console.layout");
32
33 m_PlayerName = TextWidget.Cast(layoutRoot.FindAnyWidget("character_name_xbox"));
34
35 m_ChangeAccount = layoutRoot.FindAnyWidget("choose_account");
36 m_CustomizeCharacter = layoutRoot.FindAnyWidget("customize_character");
37 m_PlayVideo = layoutRoot.FindAnyWidget("play_video");
38 m_Tutorials = layoutRoot.FindAnyWidget("tutorials");
39 m_Options = layoutRoot.FindAnyWidget("options");
40 m_Controls = layoutRoot.FindAnyWidget("controls");
41 m_Play = layoutRoot.FindAnyWidget("play");
42 m_MessageButton = layoutRoot.FindAnyWidget("message_button");
43
44 m_DlcFrame = layoutRoot.FindAnyWidget("dlc_Frame");
45 m_Version = TextWidget.Cast(layoutRoot.FindAnyWidget("version"));
46 m_Mission = MissionMainMenu.Cast(GetGame().GetMission());
47 m_LastFocusedButton = m_Play;
48
49 GetGame().GetUIManager().ScreenFadeOut(1);
50
51 string launch_done;
52 if (!GetGame().GetProfileString("FirstLaunchDone", launch_done) || launch_done != "true")
53 {
54 GetGame().SetProfileString("FirstLaunchDone", "true");
55 GetGame().GetUIManager().ShowDialog("#main_menu_tutorial", "#main_menu_tutorial_desc", 555, DBT_YESNO, DBB_YES, DMT_QUESTION, this);
56 GetGame().SaveProfile();
57 }
58
60 LoadMods();
61 Refresh();
62
63 if (GetGame().GetMission())
64 {
65 GetGame().GetMission().GetOnInputPresetChanged().Insert(OnInputPresetChanged);
66 GetGame().GetMission().GetOnInputDeviceChanged().Insert(OnInputDeviceChanged);
67 }
68
69 OnInputDeviceChanged(GetGame().GetInput().GetCurrentInputDevice());
70
71 GetGame().GetContentDLCService().m_OnChange.Insert(OnDLCChange);
72
73 return layoutRoot;
74 }
75
77 {
78 if (GetGame().GetMission())
79 {
80 GetGame().GetMission().GetOnInputPresetChanged().Remove(OnInputPresetChanged);
81 GetGame().GetMission().GetOnInputDeviceChanged().Remove(OnInputDeviceChanged);
82 }
83
84 if (GetGame().GetContentDLCService())
85 GetGame().GetContentDLCService().m_OnChange.Remove(OnDLCChange);
86 }
87
89 {
90 m_AllDLCs = null;
91 LoadMods();
92 }
93
94 void LoadMods()
95 {
96 if (m_AllDLCs != null)
97 return;
98
99 m_AllDLCs = new array<ref ModInfo>;
100
101 GetGame().GetModInfos(m_AllDLCs);
102 if (m_AllDLCs.Count() > 0)
103 {
104 m_AllDLCs.Remove(m_AllDLCs.Count() - 1);
105 m_AllDLCs.Invert();
106 }
107
108 FilterDLCs(m_AllDLCs);
109 PopulateDlcFrame();
110
112 }
113
116 {
117 if (!m_AllDlcsMap)
118 m_AllDlcsMap = new map<string, ref ModInfo>;
119
120 m_AllDlcsMap.Clear();
122 int count = modArray.Count();
123 for (int i = count - 1; i >= 0; i--)
124 {
125 info = modArray[i];
126 if (!info.GetIsDLC())
127 modArray.Remove(i);
128 else
129 m_AllDlcsMap.Set(info.GetName(), info);
130 }
131 }
132
134 {
135 if (!m_DlcHandlers)
136 m_DlcHandlers = new array<ref MainMenuDlcHandlerBase>();
137 else
138 {
139 // TODO: Would be better to update the parts that need updating instead of full recreation
140 // Destroying and then reloading the same video is quite wasteful
141 m_DlcHandlers.Clear();
142 }
143
144 m_DlcData = DlcDataLoader.GetData();
145 int count = m_DlcData.DLCs.Count();
148
149 for (int i = 0; i < count; i++)
150 {
151 data = m_DlcData.DLCs[i];
152 info = m_AllDlcsMap.Get(data.Name);
153 MainMenuDlcHandlerBase handler = new MainMenuDlcHandlerBase(info, m_DlcFrame, data);
154
155 handler.ShowInfoPanel(true);
156 m_DisplayedDlcHandler = handler;//TODO: carousel will take care of this later
157
158 m_DlcHandlers.Insert(handler);
159 }
160 }
161
162 protected void OnInputPresetChanged()
163 {
164#ifdef PLATFORM_CONSOLE
166#endif
167 }
168
174
175 override bool OnClick(Widget w, int x, int y, int button)
176 {
177 if (w == m_Play)
178 {
179 m_LastFocusedButton = m_Play;
180 OpenMenuServerBrowser();
181 return true;
182 }
183 else if (w == m_Options)
184 {
185 m_LastFocusedButton = m_Options;
186 OpenMenuOptions();
187 return true;
188 }
189 else if (w == m_PlayVideo)
190 {
191 m_Mission.StopMusic();
192 m_LastFocusedButton = m_PlayVideo;
193 OpenMenuPlayVideo();
194 return true;
195 }
196 else if (w == m_Tutorials)
197 {
198 m_LastFocusedButton = m_Tutorials;
199 OpenMenuTutorials();
200 return true;
201 }
202 else if (w == m_Controls)
203 {
204 m_LastFocusedButton = m_Controls;
205 OpenMenuControls();
206 return true;
207 }
208 else if (w == m_CustomizeCharacter)
209 {
210 m_LastFocusedButton = m_CustomizeCharacter;
211 OpenMenuCustomizeCharacter();
212 return true;
213 }
214 else if (w == m_ChangeAccount)
215 {
216 m_LastFocusedButton = m_ChangeAccount;
217 ChangeAccount();
218 return true;
219 }
220 else if (w == m_MessageButton)
221 {
222 OpenCredits();
223 return true;
224 }
225 return false;
226 }
227
228 override bool OnFocus(Widget w, int x, int y)
229 {
231 return true;
232 }
233
234 override bool OnFocusLost(Widget w, int x, int y)
235 {
236 ColorNormal(w);
237 return true;
238 }
239
240 override void Refresh()
241 {
242 string name;
243
244 if (GetGame().GetUserManager() && GetGame().GetUserManager().GetSelectedUser())
245 {
246 name = GetGame().GetUserManager().GetSelectedUser().GetName();
247 if (name.LengthUtf8() > 18)
248 {
249 name = name.SubstringUtf8(0, 18);
250 name += "...";
251 }
252 }
253 m_PlayerName.SetText(name);
254
255 string version;
256 GetGame().GetVersion(version);
257 m_Version.SetText("#main_menu_version" + " " + version + " (" + g_Game.GetDatabaseID() + ")");
258
259 if (GetGame().GetMission() != null) // if missionMainMenu still exist
260 {
261 if (m_Mission && !m_Mission.GetMenuMusic())
262 m_Mission.PlayMusic();
263 }
264 }
265
266 override void OnShow()
267 {
268 GetDayZGame().GetBacklit().MainMenu_OnShow();
269
270 SetFocus(m_LastFocusedButton);
271
272 LoadMods();
273 Refresh();
274
275 if (m_ScenePC && m_ScenePC.GetIntroCamera())
276 m_ScenePC.GetIntroCamera().LookAt(m_ScenePC.GetIntroCharacter().GetPosition() + Vector(0, 1, 0));
277 if (m_DisplayedDlcHandler)
278 m_DisplayedDlcHandler.ShowInfoPanel(true);
279
280 super.OnShow();
281#ifdef PLATFORM_CONSOLE
282#ifndef PLATFORM_PS4
283 layoutRoot.FindAnyWidget("choose_account").Show(GetGame().GetInput().IsEnabledMouseAndKeyboard());
284#endif
285 layoutRoot.FindAnyWidget("ButtonHolderCredits").Show(GetGame().GetInput().IsEnabledMouseAndKeyboard());
288#endif
289 }
290
291 override void OnHide()
292 {
293 if (m_DisplayedDlcHandler)
294 m_DisplayedDlcHandler.ShowInfoPanel(false);
295 GetDayZGame().GetBacklit().MainMenu_OnHide();
296 }
297
298 override void Update(float timeslice)
299 {
300 super.Update(timeslice);
301
302 if (g_Game.GetLoadState() != DayZGameState.CONNECTING && !GetGame().GetUIManager().IsDialogVisible())
303 {
304#ifndef PLATFORM_CONSOLE
305 if (GetUApi().GetInputByID(UAUIBack).LocalPress())
306 Exit();
307#else
308 if (GetUApi().GetInputByID(UAUICredits).LocalPress())
309 OpenCredits();
310#endif
311 }
312
313#ifdef PLATFORM_XBOX
314 if (GetUApi().GetInputByID(UAUICtrlY).LocalPress())
315 ChangeAccount();
316#endif
317 if (GetUApi().GetInputByID(UAUICtrlX).LocalPress())
318 {
319 if (CanStoreBeOpened())
320 m_DisplayedDlcHandler.GetModInfo().GoToStore();
321 }
322 }
323
325 {
326 return m_DisplayedDlcHandler != null;
327 }
328
330 {
331 EnterScriptedMenu(MENU_SERVER_BROWSER);
332 }
333
335 {
336 EnterScriptedMenu(MENU_XBOX_CONTROLS);
337 }
338
340 {
341 EnterScriptedMenu(MENU_OPTIONS);
342 }
343
345 {
346 EnterScriptedMenu(MENU_VIDEO);
347 }
348
350 {
351 EnterScriptedMenu(MENU_TUTORIAL);
352 }
353
355 {
356 EnterScriptedMenu(MENU_CHARACTER);
357 }
358
360 {
361 EnterScriptedMenu(MENU_CREDITS);
362 m_Mission.OnMenuEnter(MENU_CREDITS);
363 }
364
366 {
367 BiosUserManager user_manager = GetGame().GetUserManager();
368 if (user_manager)
369 {
370 g_Game.SetLoadState(DayZLoadState.MAIN_MENU_START);
371#ifndef PLATFORM_WINDOWS
372 user_manager.SelectUserEx(null);
373#endif
374 GetGame().GetUIManager().Back();
375 }
376 }
377
378 void Exit()
379 {
380 GetGame().GetUIManager().ShowDialog("#main_menu_exit", "#main_menu_exit_desc", IDC_MAIN_QUIT, DBT_YESNO, DBB_YES, DMT_QUESTION, this);
381 }
382
383 //Coloring functions (Until WidgetStyles are useful)
385 {
386 if (!w)
387 return;
388
389 int color_pnl = ARGB(255, 200, 0, 0);
390 int color_lbl = ARGB(255, 255, 255, 255);
391
392 ButtonSetColor(w, color_pnl);
393 ButtonSetAlphaAnim(w);
394 ButtonSetTextColor(w, color_lbl);
395 }
396
398 {
399 if (!w)
400 return;
401
402 int color_pnl = ARGB(0, 0, 0, 0);
403 int color_lbl = ARGB(255, 255, 255, 255);
404
405 ButtonSetColor(w, color_pnl);
406 ButtonSetAlphaAnim(null);
407 ButtonSetTextColor(w, color_lbl);
408 }
409
410 override bool OnModalResult(Widget w, int x, int y, int code, int result)
411 {
412 if (code == IDC_MAIN_QUIT)
413 {
414 if (result == 2)
415 GetGame().GetCallQueue(CALL_CATEGORY_GUI).Call(g_Game.RequestExit, IDC_MAIN_QUIT);
416
417 return true;
418 }
419 else if (code == 555)
420 {
421 if (result == 2)
422 OpenMenuTutorials();
423 }
424 return false;
425 }
426
428 {
429 if (!w)
430 return;
431
432 TextWidget label = TextWidget.Cast(w.FindWidget(w.GetName() + "_label"));
433
434 if (label)
435 label.SetText(text);
436
437 }
438
440 {
441 if (!w)
442 return;
443
444 Widget panel = w.FindWidget(w.GetName() + "_panel");
445
446 if (panel)
447 panel.SetColor(color);
448 }
449
451 {
452 if (!w)
453 return;
454
455 Widget panel = w.FindWidget(w.GetName() + "_panel");
456
457 if (panel)
458 SetWidgetAnimAlpha(panel);
459 }
460
462 {
463 if (!w)
464 return;
465
466 TextWidget label = TextWidget.Cast(w.FindAnyWidget(w.GetName() + "_label"));
467 TextWidget text = TextWidget.Cast(w.FindAnyWidget(w.GetName() + "_text"));
468 TextWidget text2 = TextWidget.Cast(w.FindAnyWidget(w.GetName() + "_text_1"));
469
470 if (label)
471 label.SetColor(color);
472
473 if (text)
474 text.SetColor(color);
475
476 if (text2)
477 text2.SetColor(color);
478 }
479
480 protected void UpdateControlsElements()
481 {
482 RichTextWidget toolbar_text = RichTextWidget.Cast(layoutRoot.FindAnyWidget("ContextToolbarText"));
484
485#ifndef PLATFORM_PS4
486 context += string.Format(" %1", InputUtils.GetRichtextButtonIconFromInputAction("UAUICtrlY", "#layout_xbox_main_menu_toolbar_account", EUAINPUT_DEVICE_CONTROLLER, InputUtils.ICON_SCALE_TOOLBAR));
487#endif
488 context += string.Format(" %1", InputUtils.GetRichtextButtonIconFromInputAction("UAUISelect", "#layout_xbox_main_menu_toolbar_select", EUAINPUT_DEVICE_CONTROLLER, InputUtils.ICON_SCALE_TOOLBAR));
489
490 toolbar_text.SetText(context);
491 }
492
494 {
495 bool toolbarShow = false;
496#ifdef PLATFORM_CONSOLE
497 toolbarShow = !GetGame().GetInput().IsEnabledMouseAndKeyboard() || GetGame().GetInput().GetCurrentInputDevice() == EInputDeviceType.CONTROLLER;
498#endif
499
500 layoutRoot.FindAnyWidget("toolbar_bg").Show(toolbarShow);
501 }
502}
void OnInputPresetChanged()
Definition Inventory.c:160
void OnInputDeviceChanged(EInputDeviceType pInputDeviceType)
Definition Inventory.c:167
ActionInput GetInput()
Definition ActionBase.c:989
PlayerSpawnPresetDiscreteItemSetSlotData name
one set for cargo
EDLCId
Definition ContentDLC.c:4
DayZGame g_Game
Definition DayZGame.c:3528
DayZGame GetDayZGame()
Definition DayZGame.c:3530
Icon x
Icon y
void UpdateControlsElementVisibility()
void UpdateControlsElements()
ref PluginDayzPlayerDebug_Ctrl m_Controls
void ColorNormal(Widget w)
void ColorHighlight(Widget w)
void OnDLCChange(EDLCId dlcId)
void Refresh()
proto native UAInputAPI GetUApi()
IntroSceneCharacter GetIntroCharacter()
Camera GetIntroCamera()
static JsonDataDLCList GetData()
static string GetRichtextButtonIconFromInputAction(notnull UAInput pInput, string pLocalizedDescription, int pInputDeviceType=EUAINPUT_DEVICE_CONTROLLER, float pScale=ICON_SCALE_NORMAL, bool pVertical=false)
Definition InputUtils.c:151
static const float ICON_SCALE_TOOLBAR
Definition InputUtils.c:15
void UpdateControlsElementVisibility()
override void OnShow()
override bool OnFocus(Widget w, int x, int y)
override void Update(float timeslice)
void OnDLCChange(EDLCId dlcId)
override void Refresh()
ref array< ref ModInfo > m_AllDLCs
void OpenMenuCustomizeCharacter()
void ColorHighlight(Widget w)
void OnInputDeviceChanged(EInputDeviceType pInputDeviceType)
void ButtonSetText(Widget w, string text)
void ButtonSetAlphaAnim(Widget w)
override void OnHide()
override bool OnFocusLost(Widget w, int x, int y)
void FilterDLCs(inout array< ref ModInfo > modArray)
leaves ONLY DLCs
void UpdateControlsElements()
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)
override bool OnModalResult(Widget w, int x, int y, int code, int result)
void ColorNormal(Widget w)
proto native CGame GetGame()
proto native vector Vector(float x, float y, float z)
Vector constructor from components.
const int MENU_TUTORIAL
Definition constants.c:194
const int MENU_XBOX_CONTROLS
Definition constants.c:187
const int MENU_SERVER_BROWSER
Definition constants.c:190
const int MENU_OPTIONS
Definition constants.c:173
const int MENU_CREDITS
Definition constants.c:195
const int MENU_CHARACTER
Definition constants.c:164
const int MENU_VIDEO
Definition constants.c:192
const int CALL_CATEGORY_GUI
Definition tools.c:9
const int IDC_MAIN_QUIT
Definition constants.c:136
proto native void SetFocus(Widget w)
proto native void Exit()
EInputDeviceType
Definition input.c:3
int ARGB(int a, int r, int g, int b)
Definition proto.c:322