DayZ Scripts
v1.21.156300 ยท Jun 20, 2023
 
Loading...
Searching...
No Matches
TutorialsMenu.c
Go to the documentation of this file.
1class TutorialsMenu extends UIScriptedMenu
2{
3 protected const string PATH_MOUSEKEY = "Scripts/data/PageDataTutorials.json";
4 protected const string PATH_X1_OLD = "Xbox/PageDataTutorials.json";
5 protected const string PATH_X1_NEW = "Xbox/PageDataTutorialsAlternate.json";
6 protected const string PATH_PS_OLD = "PS4/PageDataTutorials.json";
7 protected const string PATH_PS_NEW = "PS4/PageDataTutorialsAlternate.json";
8
9 protected string m_BackButtonTextID;
10
13 protected ButtonWidget m_Back;
14
15 protected ImageWidget m_ControlsLayoutImage;
16 protected const int TABS_COUNT = 4;
17 protected ImageWidget m_tab_images[TABS_COUNT];
18 protected TabberUI m_TabScript;
19 protected ref TutorialKeybinds m_KeybindsTab;
20
21 //============================================
22 // Init
23 //============================================
24 override Widget Init()
25 {
26 #ifdef PLATFORM_CONSOLE
27 layoutRoot = GetGame().GetWorkspace().CreateWidgets("gui/layouts/new_ui/tutorials/xbox/tutorials.layout");
28 #else
29 layoutRoot = GetGame().GetWorkspace().CreateWidgets("gui/layouts/new_ui/tutorials/pc/tutorials.layout");
30 #endif
31
32 m_InfoTextLeft = layoutRoot.FindAnyWidget("InfoTextLeft");
33 m_InfoTextRight = layoutRoot.FindAnyWidget("InfoTextRight");
34
35 m_Back = ButtonWidget.Cast(layoutRoot.FindAnyWidget("back"));
36
37 layoutRoot.FindAnyWidget("Tabber").GetScript(m_TabScript);
38 m_TabScript.m_OnTabSwitch.Insert(DrawConnectingLines);
39
40 #ifdef PLATFORM_CONSOLE
41 if (GetGame().GetInput().IsEnabledMouseAndKeyboard())
42 {
43 m_KeybindsTab = new TutorialKeybinds(layoutRoot.FindAnyWidget("Tab_6"), this);
44 m_TabScript.EnableTabControl(6, true);
45 }
46 #endif
47
48 m_tab_images[0] = ImageWidget.Cast(layoutRoot.FindAnyWidget("MovementTabBackdropImageWidget"));
49 m_tab_images[1] = ImageWidget.Cast(layoutRoot.FindAnyWidget("WeaponsAndActionsBackdropImageWidget"));
50 m_tab_images[2] = ImageWidget.Cast(layoutRoot.FindAnyWidget("InventoryTabBackdropImageWidget"));
51 m_tab_images[3] = ImageWidget.Cast(layoutRoot.FindAnyWidget("MenusTabBackdropImageWidget"));
52
55
56 PPERequesterBank.GetRequester(PPERequester_TutorialMenu).Start(new Param1<float>(0.6));
58
61
62 OnInputDeviceChanged(GetGame().GetInput().GetCurrentInputDevice());
63
64 return layoutRoot;
65 }
66
68 {
69 m_TabScript.m_OnTabSwitch.Remove(DrawConnectingLines);
70 PPERequesterBank.GetRequester(PPERequester_TutorialMenu).Stop();
71 }
72
73 protected void OnInputPresetChanged()
74 {
75 #ifdef PLATFORM_CONSOLE
78 #endif
79 }
80
81 protected void OnInputDeviceChanged(EInputDeviceType pInputDeviceType)
82 {
84 }
85
86 override void OnShow()
87 {
88 super.OnShow();
89
90 SetFocus(null);
91 }
92
93 void Back()
94 {
96 }
97
98 void DrawConnectingLines(int index)
99 {
100 if (index == 6)
101 {
102 m_InfoTextLeft.Show(false);
103 m_InfoTextRight.Show(false);
104 }
105 else
106 {
107 m_InfoTextLeft.Show(true);
108 m_InfoTextRight.Show(true);
111
112 map<string, ref array<int>> button_marker_groups_unflitred = new map<string, ref array<int>>;
113 map<string, ref array<int>> button_marker_groups = new map<string, ref array<int>>;
114
115 float text_widget_pos_x, text_widget_pos_y;
116 float text_widget_width, text_widget_height;
117 float dot_pos_x, dot_pos_y;
118 float dot_width, dot_height;
119 float draw_pos_x, draw_pos_y;
120
121 CanvasWidget canvas_widget = CanvasWidget.Cast(layoutRoot.FindAnyWidget("CanvasWidget_" + index));
122 canvas_widget.Clear();
123 control_mapping_info = GetControlMappingInfo();
124
125 for (int i = 0; i < m_TabScript.GetTabCount(); i++)
126 {
127 tab_array.Insert(new array<ref JsonControlMappingInfo>);
128 for (int j = 0; j < 30; j++)
129 {
130 tab_array[i].Insert(NULL);
131 }
132 }
133
134 // insert json info to array by index, so it is sorted
135 for (i = 0; i < control_mapping_info.Count(); i++)
136 {
137 JsonControlMappingInfo info = control_mapping_info.Get(i);
138 tab_array[info.m_TabID][info.m_TextWidgetID] = info;
139 }
140
141 // create group of buttons which are connected together with line
142 for (int l = 0; l < control_mapping_info.Count(); l++)
143 {
144 JsonControlMappingInfo info1 = control_mapping_info[l];
145 string button_name = info1.m_ButtonName;
146 int text_widget_id = info1.m_TextWidgetID;
147 if (info1.m_TabID != index)
148 {
149 continue;
150 }
151 if (!button_marker_groups_unflitred.Contains(button_name))
152 {
153 button_marker_groups_unflitred.Insert(button_name, new ref array<int>);
154 button_marker_groups_unflitred.Get(button_name).Insert(text_widget_id);
155 }
156 else
157 {
158 button_marker_groups_unflitred.Get(button_name).Insert(text_widget_id);
159 }
160 }
161
162 // we want groups which are bigger than 1
163 for (l = 0; l < button_marker_groups_unflitred.Count(); l++)
164 {
165 if (button_marker_groups_unflitred.GetElement(l).Count() > 1)
166 {
167 string key = button_marker_groups_unflitred.GetKey(l);
168 button_marker_groups.Insert(button_marker_groups_unflitred.GetKey(l), button_marker_groups_unflitred.Get(key));
169 }
170 }
171
172 // hide all button markers
173 Widget xbox_controls_image = layoutRoot.FindAnyWidget("Markers_" + index);
174
175 Widget panel_widget;
176 Widget button_marker_widget;
177
178 for (l = 0; l < tab_array[index].Count(); l++)
179 {
180 panel_widget = layoutRoot.FindAnyWidget("PanelWidget" + l);
181 if (tab_array[index][l] != NULL)
182 {
183 TextWidget text_widget = TextWidget.Cast(panel_widget.FindAnyWidget("TextWidget" + l));
184 button_marker_widget = layoutRoot.FindAnyWidget("button_marker_" + tab_array[index][l].m_ButtonName);
185 text_widget.SetText(tab_array[index][l].m_InfoText);
186 panel_widget.Show(true);
187 panel_widget.Update();
188
189 if (!button_marker_groups.Contains(tab_array[index][l].m_ButtonName))
190 {
191 panel_widget.GetScreenPos(text_widget_pos_x, text_widget_pos_y);
192 panel_widget.GetScreenSize(text_widget_width,text_widget_height);
193
194 button_marker_widget.GetScreenPos(dot_pos_x, dot_pos_y);
195 button_marker_widget.GetScreenSize(dot_width, dot_height);
196
197 draw_pos_y = text_widget_pos_y + text_widget_height / 2;
198
199 if (l < 15)
200 {
201 draw_pos_x = text_widget_pos_x + text_widget_width - 1;
202 }
203 else
204 {
205 draw_pos_x = text_widget_pos_x;
206 }
207
208 canvas_widget.DrawLine(draw_pos_x, draw_pos_y, dot_pos_x+dot_width/2, draw_pos_y, 2, ARGBF(0.6, 1, 1, 1));
209 canvas_widget.DrawLine(dot_pos_x+dot_width/2, draw_pos_y, dot_pos_x+dot_width/2, dot_pos_y+dot_height/2, 2, ARGBF(0.6, 1, 1, 1));
210 }
211 }
212 else
213 {
214 panel_widget.Show(false);
215 }
216 panel_widget.Update();
217 }
218
219 // draw connecting lines
220 for (l = 0; l < button_marker_groups.Count(); l++)
221 {
222 text_widget_pos_x = 0;
223 text_widget_pos_y = 0;
224 text_widget_width = 0;
225 text_widget_height = 0;
226 float group_point_x = 0, group_point_y = 0;
227 float first_x = 0, first_y = 0;
228
229 ref array<int> element = button_marker_groups.GetElement(l);
230 string key_name = button_marker_groups.GetKey(l);
231 button_marker_widget = layoutRoot.FindAnyWidget("button_marker_" + key_name);
232
233 for (int g = 0; g < element.Count(); g++)
234 {
235 panel_widget = layoutRoot.FindAnyWidget("PanelWidget" + element[g]);
236
237 panel_widget.GetScreenPos(text_widget_pos_x, text_widget_pos_y);
238 panel_widget.GetScreenSize(text_widget_width, text_widget_height);
239
240 if (g == 0)
241 {
242 if (element[0] < 15)
243 {
244 first_x = text_widget_pos_x + text_widget_width +50;
245 }
246 else
247 {
248 first_x = text_widget_pos_x - 50;
249 }
250 first_y = text_widget_pos_y + text_widget_height/2;
251
252 }
253
254 group_point_x += text_widget_pos_x;
255 group_point_y += text_widget_pos_y;
256
257 if (element[0] < 15)
258 {
259 canvas_widget.DrawLine(text_widget_pos_x + text_widget_width - 1, text_widget_pos_y + text_widget_height/2, text_widget_pos_x + text_widget_width +50, text_widget_pos_y + text_widget_height/2, 2, ARGBF(0.6, 1, 1, 1));
260 }
261 else
262 {
263 canvas_widget.DrawLine(text_widget_pos_x, text_widget_pos_y + text_widget_height/2, text_widget_pos_x - 50, text_widget_pos_y + text_widget_height/2, 2, ARGBF(0.6, 1, 1, 1));
264 }
265 }
266
267 if (element[0] < 15)
268 {
269 group_point_x = group_point_x/element.Count() + text_widget_width + 50;
270 }
271 else
272 {
273 group_point_x = group_point_x/element.Count() - 50;
274 }
275
276 group_point_y = group_point_y/element.Count() + text_widget_height/2;
277
278 button_marker_widget.GetScreenPos(dot_pos_x, dot_pos_y);
279 button_marker_widget.GetScreenSize(dot_width, dot_height);
280
281 canvas_widget.DrawLine(group_point_x, group_point_y, dot_pos_x+dot_width/2, group_point_y, 2, ARGBF(0.6, 1, 1, 1));
282 canvas_widget.DrawLine(dot_pos_x+dot_width/2, group_point_y, dot_pos_x+dot_width/2, dot_pos_y, 2, ARGBF(0.6, 1, 1, 1));
283
284 if (element[0] < 15)
285 {
286 canvas_widget.DrawLine(first_x, first_y, text_widget_pos_x + text_widget_width +50, text_widget_pos_y + text_widget_height/2, 2, ARGBF(0.6, 1, 1, 1));
287 }
288 else
289 {
290 canvas_widget.DrawLine(first_x, first_y, text_widget_pos_x - 50, text_widget_pos_y + text_widget_height/2, 2, ARGBF(0.6, 1, 1, 1));
291 }
292 }
293 }
294 }
295
297 {
299 string file_path = PATH_MOUSEKEY; //remains set for PC vatiant
300 string profile_name = "";
301 GetGame().GetInput().GetProfileName(GetGame().GetInput().GetCurrentProfile(),profile_name);
302
303#ifdef PLATFORM_CONSOLE
304 if (!GetGame().GetInput().IsEnabledMouseAndKeyboardEvenOnServer())
305 {
306 if (profile_name == "#STR_UAPRESET_0")
307 {
308 #ifdef PLATFORM_XBOX
309 file_path = PATH_X1_OLD;
310 #else
311 file_path = PATH_PS_OLD;
312 #endif
313 }
314 else if (profile_name == "#STR_UAPRESET_1")
315 {
316 #ifdef PLATFORM_XBOX
317 file_path = PATH_X1_NEW;
318 #else
319 file_path = PATH_PS_NEW;
320 #endif
321 }
322 else
323 {
324 ErrorEx("Invalid file path!");
325 file_path = "";
326 }
327 }
328#endif
329 FileHandle file_handle = OpenFile(file_path, FileMode.READ);
331
332 string js_error = "";
333 string line_content = "";
334 string content = "";
335 if (file_handle)
336 {
337 while (FGets(file_handle, line_content) >= 0)
338 {
339 content += line_content;
340 }
341 CloseFile(file_handle);
342
343 if (js.ReadFromString(control_mapping_info, content, js_error))
344 {
345 return control_mapping_info;
346 }
347 else
348 {
349 ErrorEx("JSON ERROR => [TutorialsMenu]: " + js_error);
350 }
351 }
352 else
353 {
354 ErrorEx("FILEHANDLE ERROR => [TutorialsMenu]: " + js_error);
355 }
356
357 return control_mapping_info;
358 }
359
360 override void Update(float timeslice)
361 {
362 if (GetUApi().GetInputByID(UAUITabLeft).LocalPress())
363 {
364 m_TabScript.PreviousTab();
365 }
366
367 //RIGHT BUMPER - TAB RIGHT
368 if (GetUApi().GetInputByID(UAUITabRight).LocalPress())
369 {
370 m_TabScript.NextTab();
371 }
372
373 if (GetUApi().GetInputByID(UAUIBack).LocalPress())
374 {
375 Back();
376 }
377 }
378
380 protected void LoadFooterButtonTexts()
381 {
382 TextWidget uiBackText = TextWidget.Cast(layoutRoot.FindAnyWidget("BackText"));
383
384 if (uiBackText)
385 {
386 uiBackText.SetText(m_BackButtonTextID);
387 }
388 }
390 protected void LoadTextStrings()
391 {
392 #ifdef PLATFORM_PS4
393 m_BackButtonTextID = "ps4_ingame_menu_back";
394 #else
395 m_BackButtonTextID = "STR_rootFrame_toolbar_bg_ConsoleToolbar_Back_BackText0";
396 #endif
397 }
398
399 override bool OnClick(Widget w, int x, int y, int button)
400 {
401 if (button == MouseState.LEFT)
402 {
403 if (w == m_Back)
404 {
405 Back();
406 return true;
407 }
408 }
409 return false;
410 }
411
412 override bool OnMouseEnter(Widget w, int x, int y)
413 {
414 if (IsFocusable(w))
415 {
417 return true;
418 }
419 return false;
420 }
421
422 override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
423 {
424 if (IsFocusable(w))
425 {
426 ColorNormal(w);
427 return true;
428 }
429 return false;
430 }
431
432 override bool OnFocus(Widget w, int x, int y)
433 {
434 if (IsFocusable(w))
435 {
437 return true;
438 }
439 return false;
440 }
441
442 override bool OnFocusLost(Widget w, int x, int y)
443 {
444 if (IsFocusable(w))
445 {
446 ColorNormal(w);
447 return true;
448 }
449 return false;
450 }
451
453 {
454 return (w && w == m_Back);
455 }
456
457 //Coloring functions (Until WidgetStyles are useful)
459 {
460 if (!w)
461 return;
462
463 int color_pnl = ARGB(255, 0, 0, 0);
464 int color_lbl = ARGB(255, 255, 0, 0);
465 int color_img = ARGB(255, 200, 0, 0);
466
467 #ifdef PLATFORM_CONSOLE
468 color_pnl = ARGB(255, 200, 0, 0);
469 color_lbl = ARGB(255, 255, 255, 255);
470 #endif
471
472 ButtonSetColor(w, color_pnl);
473 ButtonSetTextColor(w, color_lbl);
474 ImagenSetColor(w, color_img);
475 }
476
478 {
479 if (!w)
480 return;
481
482 int color_pnl = ARGB(0, 0, 0, 0);
483 int color_lbl = ARGB(255, 255, 255, 255);
484 int color_img = ARGB(255, 255, 255, 255);
485
486 ButtonSetColor(w, color_pnl);
487 ButtonSetTextColor(w, color_lbl);
488 ImagenSetColor(w, color_img);
489 }
490
491 void ButtonSetText(Widget w, string text)
492 {
493 if (!w)
494 return;
495
496 TextWidget label = TextWidget.Cast(w.FindWidget(w.GetName() + "_label"));
497
498 if (label)
499 {
500 label.SetText(text);
501 }
502
503 }
504
505 void ButtonSetColor(Widget w, int color)
506 {
507 if (!w)
508 return;
509
510 Widget panel = w.FindWidget(w.GetName() + "_panel");
511
512 if (panel)
513 {
514 panel.SetColor(color);
515 }
516 }
517
518 void ImagenSetColor(Widget w, int color)
519 {
520 if (!w)
521 return;
522
523 Widget panel = w.FindWidget(w.GetName() + "_image");
524
525 if (panel)
526 {
527 panel.SetColor(color);
528 }
529 }
530
531 void ButtonSetTextColor(Widget w, int color)
532 {
533 if (!w)
534 return;
535
536 TextWidget label = TextWidget.Cast(w.FindAnyWidget(w.GetName() + "_label"));
537 TextWidget text = TextWidget.Cast(w.FindAnyWidget(w.GetName() + "_text"));
538 TextWidget text2 = TextWidget.Cast(w.FindAnyWidget(w.GetName() + "_text_1"));
539
540 if (label)
541 {
542 label.SetColor(color);
543 }
544
545 if (text)
546 {
547 text.SetColor(color);
548 }
549
550 if (text2)
551 {
552 text2.SetColor(color);
553 }
554 }
555
556 protected void UpdateControlsElements()
557 {
558 #ifdef PLATFORM_CONSOLE
559 RichTextWidget toolbar_text = RichTextWidget.Cast(layoutRoot.FindAnyWidget("ContextToolbarText"));
560 if (toolbar_text)
561 {
562 string text = string.Format(" %1",InputUtils.GetRichtextButtonIconFromInputAction("UAUIBack", "#STR_settings_menu_root_toolbar_bg_ConsoleToolbar_Back_BackText0", EUAINPUT_DEVICE_CONTROLLER, InputUtils.ICON_SCALE_TOOLBAR));
563 toolbar_text.SetText(text);
564 }
565
566 RichTextWidget toolbar_b2 = RichTextWidget.Cast(layoutRoot.FindAnyWidget("BackIcon0"));
567 toolbar_b2.SetText(InputUtils.GetRichtextButtonIconFromInputAction("UAUIBack", "", EUAINPUT_DEVICE_CONTROLLER, InputUtils.ICON_SCALE_TOOLBAR));
568 #endif
569 }
570
572 {
573 bool toolbarShow = false;
574 #ifdef PLATFORM_CONSOLE
576 #endif
577
578 #ifdef PLATFORM_CONSOLE
579 layoutRoot.FindAnyWidget("toolbar_bg").Show(toolbarShow);
580 #endif
581 layoutRoot.FindAnyWidget("play_panel_root").Show(!toolbarShow);
582 }
583}
protected void OnInputDeviceChanged(EInputDeviceType pInputDeviceType)
Definition Inventory.c:164
protected void OnInputPresetChanged()
Definition Inventory.c:157
ActionInput GetInput()
protected ButtonWidget m_Back
protected TabberUI m_TabScript
class JsonControlMappingInfo m_BackButtonTextID
void DrawConnectingLines(int index)
protected const int TABS_COUNT
protected ImageWidget m_tab_images[TABS_COUNT]
Icon x
Icon y
proto native UAInputAPI GetUApi()
proto native Mission GetMission()
proto native Input GetInput()
proto native UIManager GetUIManager()
proto native WorkspaceWidget GetWorkspace()
proto int GetProfileName(int profile_index, out string name)
gets profile by index
proto native EInputDeviceType GetCurrentInputDevice()
proto native bool IsEnabledMouseAndKeyboardEvenOnServer()
static const float ICON_SCALE_TOOLBAR
Definition InputUtils.c:15
static string GetRichtextButtonIconFromInputAction(notnull UAInput pInput, string pLocalizedDescription, int pInputDeviceType=EUAINPUT_DEVICE_CONTROLLER, float pScale=ICON_SCALE_NORMAL, bool pVertical=false)
Definition InputUtils.c:167
Class for sending RPC over network.
Definition gameplay.c:50
proto bool ReadFromString(void variable_in, string jsonString, out string error)
Json string deserialization to script variable.
ScriptInvoker GetOnInputPresetChanged()
Definition gameplay.c:833
ScriptInvoker GetOnInputDeviceChanged()
Definition gameplay.c:823
proto bool Insert(func fn, int flags=EScriptInvokerInsertFlags.IMMEDIATE)
insert method to list
bool Back()
Close top window on windows stack, returns true when any window is closed.
Definition UIManager.c:64
protected void OnInputDeviceChanged(EInputDeviceType pInputDeviceType)
protected string m_BackButtonTextID
protected ButtonWidget m_Back
void ButtonSetText(Widget w, string text)
protected TabberUI m_TabScript
override void Update(float timeslice)
protected const string PATH_PS_NEW
protected array< ref JsonControlMappingInfo > GetControlMappingInfo()
override void OnShow()
override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
protected Widget m_InfoTextRight
protected void LoadTextStrings()
Set correct bottom button texts based on platform (ps4 vs xbox texts)
protected const string PATH_PS_OLD
void ~TutorialsMenu()
void ButtonSetColor(Widget w, int color)
protected const string PATH_X1_OLD
void DrawConnectingLines(int index)
protected void OnInputPresetChanged()
protected const int TABS_COUNT
protected Widget m_InfoTextLeft
void ButtonSetTextColor(Widget w, int color)
protected const string PATH_MOUSEKEY
protected void DrawConnectingLines(int index)
protected ImageWidget m_ControlsLayoutImage
protected void UpdateControlsElements()
void ColorNormal(Widget w)
protected ref TutorialKeybinds m_KeybindsTab
override Widget Init()
override bool OnFocusLost(Widget w, int x, int y)
bool IsFocusable(Widget w)
override bool OnMouseEnter(Widget w, int x, int y)
void ImagenSetColor(Widget w, int color)
Definition MainMenu.c:602
protected const string PATH_X1_NEW
void ColorHighlight(Widget w)
protected void UpdateControlsElementVisibility()
protected void LoadFooterButtonTexts()
Initial texts load for the footer buttons.
override bool OnFocus(Widget w, int x, int y)
override bool OnClick(Widget w, int x, int y, int button)
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
proto native CGame GetGame()
enum ShapeType ErrorEx
FileMode
Definition EnSystem.c:383
proto void CloseFile(FileHandle file)
Close the File.
proto int FGets(FileHandle file, string var)
Get line from file, every next call of this function returns next line.
proto FileHandle OpenFile(string name, FileMode mode)
Opens File.
int[] FileHandle
Definition EnSystem.c:390
MouseState
Definition EnSystem.c:311
proto native void SetFocus(Widget w)
proto native external Widget CreateWidgets(string layout, Widget parentWidget=NULL, bool immedUpdate=true)
Create widgets from *.layout file.
proto native void DrawLine(float x1, float y1, float x2, float y2, float width, int color)
EInputDeviceType
Definition input.c:3
int ARGB(int a, int r, int g, int b)
Definition proto.c:322
int ARGBF(float fa, float fr, float fg, float fb)
Converts <0.0, 1.0> ARGB into color.
Definition proto.c:332