Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
mainmenuconsoles.c
Go to the documentation of this file.
1 class MainMenuConsole extends UIScriptedMenu
2 {
3  protected ref MainMenuVideo m_Video;
4 
5  protected MissionMainMenu m_Mission;
6  protected DayZIntroScenePC m_ScenePC;
7 
8  protected TextWidget m_PlayerName;
9  protected TextWidget m_Version;
10 
11  protected Widget m_ChangeAccount;
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 
22  protected ref array<ref ModInfo> m_AllDLCs;
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 
76  void ~MainMenuConsole()
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 
88  void OnDLCChange(EDLCId dlcId)
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 
115  void FilterDLCs(inout array<ref ModInfo> modArray)
116  {
117  if (!m_AllDlcsMap)
118  m_AllDlcsMap = new map<string,ref ModInfo>;
119 
120  m_AllDlcsMap.Clear();
121  ModInfo info;
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 
133  void PopulateDlcFrame()
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();
146  JsonDataDLCInfo data;
147  ModInfo info;
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 
169  protected void OnInputDeviceChanged(EInputDeviceType pInputDeviceType)
170  {
173  }
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  {
230  ColorHighlight(w);
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  {
263  m_Mission.PlayMusic();
264  }
265  }
266  }
267 
268  override void OnShow()
269  {
270  GetDayZGame().GetBacklit().MainMenu_OnShow();
271 
272  SetFocus(m_LastFocusedButton);
273 
274  LoadMods();
275  Refresh();
276 
277  if (m_ScenePC && m_ScenePC.GetIntroCamera())
278  {
279  m_ScenePC.GetIntroCamera().LookAt(m_ScenePC.GetIntroCharacter().GetPosition() + Vector(0, 1, 0));
280  }
281  if (m_DisplayedDlcHandler)
282  m_DisplayedDlcHandler.ShowInfoPanel(true);
283 
284  super.OnShow();
285  #ifdef PLATFORM_CONSOLE
286  #ifndef PLATFORM_PS4
287  layoutRoot.FindAnyWidget("choose_account").Show(GetGame().GetInput().IsEnabledMouseAndKeyboard());
288  #endif
289  layoutRoot.FindAnyWidget("ButtonHolderCredits").Show(GetGame().GetInput().IsEnabledMouseAndKeyboard());
292  #endif
293  }
294 
295  override void OnHide()
296  {
297  if (m_DisplayedDlcHandler)
298  m_DisplayedDlcHandler.ShowInfoPanel(false);
299  GetDayZGame().GetBacklit().MainMenu_OnHide();
300  }
301 
302  override void Update(float timeslice)
303  {
304  super.Update(timeslice);
305 
306  if (g_Game.GetLoadState() != DayZGameState.CONNECTING && !GetGame().GetUIManager().IsDialogVisible())
307  {
308  #ifndef PLATFORM_CONSOLE
309  if (GetUApi().GetInputByID(UAUIBack).LocalPress())
310  {
311  Exit();
312  }
313  #else
314  if (GetUApi().GetInputByID(UAUICredits).LocalPress())
315  {
316  OpenCredits();
317  }
318  #endif
319  }
320 
321  #ifdef PLATFORM_XBOX
322  if (GetUApi().GetInputByID(UAUICtrlY).LocalPress())
323  {
324  ChangeAccount();
325  }
326  #endif
327  if (GetUApi().GetInputByID(UAUICtrlX).LocalPress())
328  {
329  if (CanStoreBeOpened())
330  {
331  m_DisplayedDlcHandler.GetModInfo().GoToStore();
332  }
333  }
334  }
335 
336  bool CanStoreBeOpened()
337  {
338  return m_DisplayedDlcHandler != null;
339  }
340 
341  void OpenMenuServerBrowser()
342  {
343  EnterScriptedMenu(MENU_SERVER_BROWSER);
344  }
345 
346  void OpenMenuControls()
347  {
348  EnterScriptedMenu(MENU_XBOX_CONTROLS);
349  }
350 
351  void OpenMenuOptions()
352  {
353  EnterScriptedMenu(MENU_OPTIONS);
354  }
355 
356  void OpenMenuPlayVideo()
357  {
358  EnterScriptedMenu(MENU_VIDEO);
359  }
360 
361  void OpenMenuTutorials()
362  {
363  EnterScriptedMenu(MENU_TUTORIAL);
364  }
365 
366  void OpenMenuCustomizeCharacter()
367  {
368  EnterScriptedMenu(MENU_CHARACTER);
369  }
370 
371  void OpenCredits()
372  {
373  EnterScriptedMenu(MENU_CREDITS);
374  m_Mission.OnMenuEnter(MENU_CREDITS);
375  }
376 
377  void ChangeAccount()
378  {
379  BiosUserManager user_manager = GetGame().GetUserManager();
380  if (user_manager)
381  {
382  g_Game.SetLoadState(DayZLoadState.MAIN_MENU_START);
383  #ifndef PLATFORM_WINDOWS
384  user_manager.SelectUserEx(null);
385  #endif
386  GetGame().GetUIManager().Back();
387  }
388  }
389 
390  void Exit()
391  {
392  GetGame().GetUIManager().ShowDialog("#main_menu_exit", "#main_menu_exit_desc", IDC_MAIN_QUIT, DBT_YESNO, DBB_YES, DMT_QUESTION, this);
393  }
394 
395  //Coloring functions (Until WidgetStyles are useful)
396  void ColorHighlight(Widget w)
397  {
398  if (!w)
399  return;
400 
401  int color_pnl = ARGB(255, 200, 0, 0);
402  int color_lbl = ARGB(255, 255, 255, 255);
403 
404  ButtonSetColor(w, color_pnl);
405  ButtonSetAlphaAnim(w);
406  ButtonSetTextColor(w, color_lbl);
407  }
408 
409  void ColorNormal(Widget w)
410  {
411  if (!w)
412  return;
413 
414  int color_pnl = ARGB(0, 0, 0, 0);
415  int color_lbl = ARGB(255, 255, 255, 255);
416 
417  ButtonSetColor(w, color_pnl);
418  ButtonSetAlphaAnim(null);
419  ButtonSetTextColor(w, color_lbl);
420  }
421 
422  override bool OnModalResult(Widget w, int x, int y, int code, int result)
423  {
424  if (code == IDC_MAIN_QUIT)
425  {
426  if (result == 2)
427  {
428  GetGame().GetCallQueue(CALL_CATEGORY_GUI).Call(g_Game.RequestExit, IDC_MAIN_QUIT);
429  }
430 
431  return true;
432  }
433  else if (code == 555)
434  {
435  if (result == 2)
436  {
437  OpenMenuTutorials();
438  }
439  }
440  return false;
441  }
442 
443  void ButtonSetText(Widget w, string text)
444  {
445  if (!w)
446  return;
447 
448  TextWidget label = TextWidget.Cast(w.FindWidget(w.GetName() + "_label"));
449 
450  if (label)
451  {
452  label.SetText(text);
453  }
454 
455  }
456 
457  void ButtonSetColor(Widget w, int color)
458  {
459  if (!w)
460  return;
461 
462  Widget panel = w.FindWidget(w.GetName() + "_panel");
463 
464  if (panel)
465  {
466  panel.SetColor(color);
467  }
468  }
469 
470  void ButtonSetAlphaAnim(Widget w)
471  {
472  if (!w)
473  return;
474 
475  Widget panel = w.FindWidget(w.GetName() + "_panel");
476 
477  if (panel)
478  {
479  SetWidgetAnimAlpha(panel);
480  }
481  }
482 
483  void ButtonSetTextColor(Widget w, int color)
484  {
485  if (!w)
486  return;
487 
488  TextWidget label = TextWidget.Cast(w.FindAnyWidget(w.GetName() + "_label"));
489  TextWidget text = TextWidget.Cast(w.FindAnyWidget(w.GetName() + "_text"));
490  TextWidget text2 = TextWidget.Cast(w.FindAnyWidget(w.GetName() + "_text_1"));
491 
492  if (label)
493  {
494  label.SetColor(color);
495  }
496 
497  if (text)
498  {
499  text.SetColor(color);
500  }
501 
502  if (text2)
503  {
504  text2.SetColor(color);
505  }
506  }
507 
508  protected void UpdateControlsElements()
509  {
510  RichTextWidget toolbar_text = RichTextWidget.Cast(layoutRoot.FindAnyWidget("ContextToolbarText"));
511  string context = InputUtils.GetRichtextButtonIconFromInputAction("UAUICredits", "#menu_credits", EUAINPUT_DEVICE_CONTROLLER, InputUtils.ICON_SCALE_TOOLBAR);
512 
513 #ifndef PLATFORM_PS4
514  context += string.Format(" %1",InputUtils.GetRichtextButtonIconFromInputAction("UAUICtrlY", "#layout_xbox_main_menu_toolbar_account", EUAINPUT_DEVICE_CONTROLLER, InputUtils.ICON_SCALE_TOOLBAR));
515 #endif
516  context += string.Format(" %1",InputUtils.GetRichtextButtonIconFromInputAction("UAUISelect", "#layout_xbox_main_menu_toolbar_select", EUAINPUT_DEVICE_CONTROLLER, InputUtils.ICON_SCALE_TOOLBAR));
517 
518  toolbar_text.SetText(context);
519  }
520 
521  protected void UpdateControlsElementVisibility()
522  {
523  bool toolbarShow = false;
524  #ifdef PLATFORM_CONSOLE
525  toolbarShow = !GetGame().GetInput().IsEnabledMouseAndKeyboard() || GetGame().GetInput().GetCurrentInputDevice() == EInputDeviceType.CONTROLLER;
526  #endif
527 
528  layoutRoot.FindAnyWidget("toolbar_bg").Show(toolbarShow);
529  }
530 }
GetGame
proto native CGame GetGame()
UIScriptedMenu
Definition: dayzgame.c:63
InputUtils
Definition: inpututils.c:1
MENU_SERVER_BROWSER
const int MENU_SERVER_BROWSER
Definition: constants.c:190
ModInfo
Definition: modinfo.c:1
GetDayZGame
DayZGame GetDayZGame()
Definition: dayzgame.c:3729
Exit
proto native void Exit()
UpdateControlsElements
protected void UpdateControlsElements()
Definition: itemdropwarningmenu.c:92
OnHide
override void OnHide()
Definition: inventorymenu.c:141
y
Icon y
MENU_CHARACTER
const int MENU_CHARACTER
Definition: constants.c:164
EDLCId
EDLCId
Definition: contentdlc.c:3
Refresh
void Refresh()
Definition: sizetochild.c:108
JsonDataDLCInfo
Definition: jsondatadlcinfo.c:6
OnInputDeviceChanged
protected void OnInputDeviceChanged(EInputDeviceType pInputDeviceType)
Definition: inventory.c:167
CALL_CATEGORY_GUI
const int CALL_CATEGORY_GUI
Definition: tools.c:9
JsonDataDLCList
Definition: jsondatadlcinfo.c:1
EInputDeviceType
EInputDeviceType
Definition: input.c:2
RichTextWidget
Definition: gameplay.c:315
IDC_MAIN_QUIT
const int IDC_MAIN_QUIT
Definition: constants.c:136
map
map
Definition: controlsxboxnew.c:3
Init
class InventoryGridController extends ScriptedWidgetEventHandler Init
Definition: uihintpanel.c:46
TextWidget
Definition: enwidgets.c:219
ColorNormal
void ColorNormal(Widget w)
Definition: serverbrowsertab.c:668
UpdateControlsElementVisibility
protected void UpdateControlsElementVisibility()
Definition: itemdropwarningmenu.c:100
DayZIntroScenePC
Definition: dayzintroscenepc.c:1
m_Mission
protected Mission m_Mission
Definition: dayzplayermeleefightlogic_lightheavy.c:23
g_Game
DayZGame g_Game
Definition: dayzgame.c:3727
ColorHighlight
void ColorHighlight(Widget w)
Definition: serverbrowsertab.c:619
MENU_CREDITS
const int MENU_CREDITS
Definition: constants.c:195
OnFocusLost
override bool OnFocusLost(Widget w, int x, int y)
Definition: serverbrowsertab.c:235
BiosUserManager
Definition: biosusermanager.c:16
MENU_XBOX_CONTROLS
const int MENU_XBOX_CONTROLS
Definition: constants.c:187
MENU_OPTIONS
const int MENU_OPTIONS
Definition: constants.c:173
m_Controls
ref PluginDayzPlayerDebug_Ctrl m_Controls
Definition: plugindayzplayerdebug.c:269
OnDLCChange
void OnDLCChange(EDLCId dlcId)
Definition: serverbrowsertab.c:113
array< ref ModInfo >
Update
proto native volatile void Update()
Definition: playersoundmanager.c:125
SetFocus
proto native void SetFocus(Widget w)
name
PlayerSpawnPresetDiscreteItemSetSlotData name
one set for cargo
x
Icon x
DlcDataLoader
Definition: dlcdataloader.c:1
OnInputPresetChanged
protected void OnInputPresetChanged()
Definition: inventory.c:160
OnFocus
override bool OnFocus(Widget w, int x, int y)
Definition: serverbrowsertab.c:217
MENU_VIDEO
const int MENU_VIDEO
Definition: constants.c:192
OnShow
override void OnShow()
Definition: controlsxbox.c:349
Widget
Definition: enwidgets.c:189
GetUApi
proto native UAInputAPI GetUApi()
GetInput
ActionInput GetInput()
Definition: actionbase.c:1066
OnClick
override bool OnClick(Widget w, int x, int y, int button)
buttons clicks
Definition: dayzgame.c:146
Vector
proto native vector Vector(float x, float y, float z)
Vector constructor from components.
ARGB
int ARGB(int a, int r, int g, int b)
Definition: proto.c:322
MENU_TUTORIAL
const int MENU_TUTORIAL
Definition: constants.c:194