Dayz Build 1.29.163047, Scripts Rev. 123548
Dayz Code Explorer by Zeroy
Loading...
Searching...
No Matches
controlsxboxnew.c
Go to the documentation of this file.
1
2//used as UserID in the layout. Values assigned for convenience here
3enum EConsoleButtonsControls
4{
5 INVALID = 0, //assumed unassigned value, ignored (dividers, formatting elements etc.)
24}
25
26typedef map<int,ref array<Widget>> TButtonPairingInfo; //<button_mask,<associated widgets on the respective side>>
27
28class ControlsXboxNew extends UIScriptedMenu
29{
30 protected string m_BackButtonTextID;
31 protected string m_NextPresetText;
32 protected int m_CurrentTabIdx = -1;
33 protected int m_CurrentPresetVariant = -1;
34
35 protected ButtonWidget m_Back;
36 protected ImageWidget m_ControlsLayoutImage;
37
38 //-------------
39 protected CanvasWidget m_CanvasWidget;
40 protected TabberUI m_TabScript;
43 protected Widget m_PlatformHolder; //controls container for selected platform
45
48 protected ref map<int,ref TButtonPairingInfo> m_AreasLR; //left/right area holders
49
50 protected const int AREA_LEFT = 1;
51 protected const int AREA_RIGHT = 2;
52 protected const int PLATFORM_ADJUST_X1 = 1000;
53 protected const int PLATFORM_ADJUST_PS = 2000;
54
55 //============================================
56 // ControlsXboxNew
57 //============================================
59 {
60 PPERequesterBank.GetRequester(PPERequesterBank.REQ_MENUEFFECTS).Stop();
61 }
62
63 protected void OnInputPresetChanged()
64 {
65 #ifdef PLATFORM_CONSOLE
68 #endif
69 }
70
71 protected void OnInputDeviceChanged(EInputDeviceType pInputDeviceType)
72 {
73 bool mk = g_Game.GetInput().IsEnabledMouseAndKeyboard();
74 bool mkServer = g_Game.GetInput().IsEnabledMouseAndKeyboardEvenOnServer();
75
76 switch (pInputDeviceType)
77 {
78 case EInputDeviceType.CONTROLLER:
79 if (mk && mkServer)
80 {
81 g_Game.GetUIManager().ShowUICursor(false);
82 }
83 break;
84
85 default:
86 if (g_Game.GetInput().IsEnabledMouseAndKeyboard())
87 {
88 g_Game.GetUIManager().ShowUICursor(true);
89 }
90 break;
91 }
92
94 }
95
96 void Back()
97 {
98 g_Game.GetUIManager().Back();
99 }
100
101 void UpdateTabContent(int tab_index)
102 {
103 Widget w;
104 //hide old
105 if (m_CurrentTabIdx != -1)
106 {
107 m_VariantWidget.Show(false);
108 while (m_VariantWidget.GetParent())
109 {
110 m_VariantWidget = m_VariantWidget.GetParent();
111 m_VariantWidget.Show(false);
112 }
113 }
114
115 //show new
117 w.Show(true);
118 m_VariantWidget = w;
119
120 while (w.GetParent())
121 {
122 w = w.GetParent();
123 w.Show(true);
124 }
125
126 DrawConnectingLines(tab_index);
127 m_CurrentTabIdx = tab_index;
128 }
129
130 protected void DrawConnectingLines(int index)
131 {
132 //disconnected for now, to be finished
133 return;
134
135 m_CanvasWidget.Clear();
136
137 //TODO drawing over nyah
140
141 Widget wid_side; //left or right area
142 Widget wid_spacer; //item in the L/R areas
143 wid_side = m_VariantWidget.GetChildren();
144 typename t = EConsoleButtonsControls;
145 int side_idx;
146 int enum_value;
147 array<Widget> items_raw;
148 array<Widget> items_filtered;
149
150 while (wid_side)
151 {
152 TButtonPairingInfo button_mapping = new TButtonPairingInfo;
153
154 side_idx = wid_side.GetUserID();
155 wid_spacer = wid_side.GetChildren(); //dig into the side first..
156
157 for (int i = 1; i < EnumTools.GetEnumSize(EConsoleButtonsControls); i++)
158 {
159 items_raw = new array<Widget>;
160 items_filtered = new array<Widget>;
161 t.GetVariableValue(null, i, enum_value); //TODO
162
163 FindAllChildrenByID(wid_spacer,enum_value,items_raw);
164 if (FilterByVisible(items_raw,items_filtered) > 0) //if there are any button-relevant items..
165 {
166 button_mapping.Insert(enum_value,items_filtered);
167 }
168 }
169 m_AreasLR.Insert(side_idx,button_mapping);
170
171 wid_side = wid_side.GetSibling();
172 }
173 }
174
175 //============================================
176 // Init
177 //============================================
178 override Widget Init()
179 {
182
183 layoutRoot = g_Game.GetWorkspace().CreateWidgets("gui/layouts/xbox/Controls_Screen.layout");
184 #ifdef PLATFORM_XBOX
185 m_ControlsImage = layoutRoot.FindAnyWidget("XboxControlsImage");
186 #else
187 #ifdef PLATFORM_MSSTORE
188 m_ControlsImage = layoutRoot.FindAnyWidget("XboxControlsImage");
189 #else
190 #ifdef PLATFORM_PS4
191 m_ControlsImage = layoutRoot.FindAnyWidget("PSControlsImage");
192 #endif
193 #endif
194 #endif
195 m_ControlsImage.Show(true);
196 m_TabberWidget = layoutRoot.FindAnyWidget("Tabber");
197 m_TabberWidget.GetScript(m_TabScript);
198 m_TabScript.m_OnTabSwitch.Insert(UpdateTabContent);
199 m_CanvasWidget = CanvasWidget.Cast(layoutRoot.FindAnyWidget("CanvasUniversal"));
200 m_Back = ButtonWidget.Cast(layoutRoot.FindAnyWidget("back"));
201
205
206 PPERequester_MenuEffects requester;
207 Class.CastTo(requester,PPERequesterBank.GetRequester(PPERequesterBank.REQ_MENUEFFECTS));
208 requester.SetVignetteIntensity(0.6);
209
210 ComposeData();
212
213 g_Game.GetMission().GetOnInputPresetChanged().Insert(OnInputPresetChanged);
214 g_Game.GetMission().GetOnInputDeviceChanged().Insert(OnInputDeviceChanged);
215
216 return layoutRoot;
217 }
218
219 override void OnShow()
220 {
221 super.OnShow();
222
223 SetFocus(null);
224 OnInputDeviceChanged(g_Game.GetInput().GetCurrentInputDevice());
225 }
226
227 override bool OnClick(Widget w, int x, int y, int button)
228 {
229 if (button == MouseState.LEFT)
230 {
231 if (w == m_Back)
232 {
233 Back();
234 return true;
235 }
236 }
237 return false;
238 }
239
240 override bool OnMouseEnter(Widget w, int x, int y)
241 {
242 if (IsFocusable(w))
243 {
245 return true;
246 }
247 return false;
248 }
249
250 override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
251 {
252 if (IsFocusable(w))
253 {
254 ColorNormal(w);
255 return true;
256 }
257 return false;
258 }
259
260 override bool OnFocus(Widget w, int x, int y)
261 {
262 if (IsFocusable(w))
263 {
265 return true;
266 }
267 return false;
268 }
269
270 override bool OnFocusLost(Widget w, int x, int y)
271 {
272 if (IsFocusable(w))
273 {
274 ColorNormal(w);
275 return true;
276 }
277 return false;
278 }
279
281 {
282 return (w && w == m_Back);
283 }
284
285 override void Update(float timeslice)
286 {
287 if (GetUApi().GetInputByID(UAUITabLeft).LocalPress())
288 {
289 m_TabScript.PreviousTab();
290 }
291
292 if (GetUApi().GetInputByID(UAUITabRight).LocalPress())
293 {
294 m_TabScript.NextTab();
295 }
296
297 if (GetUApi().GetInputByID(UAUIBack).LocalPress())
298 {
299 Back();
300 }
301
302 if (GetUApi().GetInputByID(UASwitchPreset).LocalPress())
303 {
305 m_TabScript.RefreshTab();
306 }
307 }
308
310 protected void ComposeData()
311 {
313 {
314 m_CategoryStructure = null;
316 }
317
319 {
322 }
323
324 Widget w = m_ControlsImage.GetChildren();
325 m_ImageMarkerStructure.Set(w.GetUserID(),w);
326
327 while (w.GetSibling())
328 {
329 w = w.GetSibling();
330 m_ImageMarkerStructure.Set(w.GetUserID(),w); //inits button markers with their IDs
331 }
332
334
335 #ifdef PLATFORM_MSSTORE
337 #else
338 #ifdef PLATFORM_XBOX
340 #else
342 #endif
343 #endif
344
345 //categories
346 Widget category_widget = m_PlatformHolder.GetChildren();
347 m_CategoryStructure.Set(category_widget.GetUserID(),category_widget);
348
349 while (category_widget.GetSibling())
350 {
351 category_widget = category_widget.GetSibling();
352 m_CategoryStructure.Set(category_widget.GetUserID(),category_widget);
353 }
354 }
355
356 protected void PerformSwitchPreset()
357 {
358 Print("PerformSwitchPreset - 1");
359 int index;
360 string preset_text;
361 UAInputAPI inputAPI = GetUApi();
362
363 index = inputAPI.PresetCurrent() + 1;
364 if (index >= inputAPI.PresetCount())
365 {
366 index = 0;
367 }
368
369 inputAPI.SupressNextFrame(true);
370 inputAPI.PresetSelect(index);
372
373 g_Game.GetMission().GetOnInputPresetChanged().Invoke();
374
375 #ifdef PLATFORM_WINDOWS
376 GetUApi().Export(); //works on emulated consoles (-xbox,-ps4)
377 #else
378 GetUApi().SaveInputPresetMiscData(); //default console functionality
379 #endif
380
383 }
384
385 protected void UpdateToolbarText()
386 {
387 UAInputAPI inputAPI = GetUApi();
388 int target_idx = inputAPI.PresetCurrent() + 1;
389 int count = inputAPI.PresetCount();
390 if (target_idx >= inputAPI.PresetCount())
391 {
392 target_idx = 0;
393 }
394
395 m_NextPresetText = inputAPI.PresetName(target_idx);
397 {
398 m_NextPresetText = "#STR_UAPRESET_ChangeTo_0";
399 }
401 {
402 m_NextPresetText = "#STR_UAPRESET_ChangeTo_1";
403 }
404 else
405 {
406 m_NextPresetText = "Invalid console preset name: " + m_NextPresetText;
407 }
408 }
409
411 protected Widget FindChildByID(Widget wid, int user_id)
412 {
413 Widget ret = wid.GetChildren();
414 while (ret)
415 {
416 if (ret.GetUserID() == user_id)
417 {
418 return ret;
419 }
420 ret = ret.GetSibling();
421 }
422 return ret;
423 }
424
426 protected bool FindAllChildrenByID(Widget wid, int user_id, out array<Widget> results)
427 {
428 Widget child = wid.GetChildren();
429 while (child)
430 {
431 if (child.GetUserID() == user_id)
432 {
433 results.Insert(child);
434 }
435 child = child.GetSibling();
436 }
437 return (results && results.Count() > 0);
438 }
439
441 protected int FilterByVisible(array<Widget> input, array<Widget> filtered)
442 {
443 for (int i = 0; i < input.Count(); i++)
444 {
445 if (input[i].IsVisible())
446 {
447 filtered.Insert(input[i]);
448 }
449 }
450
451 return filtered.Count();
452 }
453
455 {
456 if (!w)
457 return;
458
459 int color_pnl = ARGB(255, 0, 0, 0);
460 int color_lbl = ARGB(255, 255, 0, 0);
461
462 #ifdef PLATFORM_CONSOLE
463 color_pnl = ARGB(255, 200, 0, 0);
464 color_lbl = ARGB(255, 255, 255, 255);
465 #endif
466
467 ButtonSetColor(w, color_pnl);
468 ButtonSetTextColor(w, color_lbl);
469 }
470
472 {
473 if (!w)
474 return;
475
476 int color_pnl = ARGB(0, 0, 0, 0);
477 int color_lbl = ARGB(255, 255, 255, 255);
478
479 ButtonSetColor(w, color_pnl);
480 ButtonSetTextColor(w, color_lbl);
481 }
482
483 void ButtonSetText(Widget w, string text)
484 {
485 if (!w)
486 return;
487
488 TextWidget label = TextWidget.Cast(w.FindWidget(w.GetName() + "_label"));
489
490 if (label)
491 {
492 label.SetText(text);
493 }
494
495 }
496
497 void ButtonSetColor(Widget w, int color)
498 {
499 if (!w)
500 return;
501
502 Widget panel = w.FindWidget(w.GetName() + "_panel");
503
504 if (panel)
505 {
506 panel.SetColor(color);
507 }
508 }
509
510 void ButtonSetTextColor(Widget w, int color)
511 {
512 if (!w)
513 return;
514
515 TextWidget label = TextWidget.Cast(w.FindAnyWidget(w.GetName() + "_label"));
516 TextWidget text = TextWidget.Cast(w.FindAnyWidget(w.GetName() + "_text"));
517 TextWidget text2 = TextWidget.Cast(w.FindAnyWidget(w.GetName() + "_text_1"));
518
519 if (label)
520 {
521 label.SetColor(color);
522 }
523
524 if (text)
525 {
526 text.SetColor(color);
527 }
528
529 if (text2)
530 {
531 text2.SetColor(color);
532 }
533 }
534
535 protected void UpdateControlsElements()
536 {
537 RichTextWidget toolbar_switch = RichTextWidget.Cast(layoutRoot.FindAnyWidget("ChangePresetText"));
538 toolbar_switch.SetText(InputUtils.GetRichtextButtonIconFromInputAction("UASwitchPreset", m_NextPresetText, EUAINPUT_DEVICE_CONTROLLER, InputUtils.ICON_SCALE_TOOLBAR));
539
540 RichTextWidget toolbar_text = RichTextWidget.Cast(layoutRoot.FindAnyWidget("ContextToolbarText"));
541 string text = string.Format(" %1",InputUtils.GetRichtextButtonIconFromInputAction("UAUIBack", "#STR_settings_menu_root_toolbar_bg_ConsoleToolbar_Back_BackText0", EUAINPUT_DEVICE_CONTROLLER, InputUtils.ICON_SCALE_TOOLBAR));
542 toolbar_text.SetText(text);
543 }
544
546 {
547 bool toolbarShow = false;
548 #ifdef PLATFORM_CONSOLE
549 toolbarShow = !g_Game.GetInput().IsEnabledMouseAndKeyboardEvenOnServer() || g_Game.GetInput().GetCurrentInputDevice() == EInputDeviceType.CONTROLLER;
550 #endif
551
552 layoutRoot.FindAnyWidget("toolbar_bg").Show(toolbarShow);
553 layoutRoot.FindAnyWidget("play_panel_root").Show(!toolbarShow);
554 }
555}
Super root of all classes in Enforce script.
Definition enscript.c:11
static int GetEnumSize(typename e)
Return amount of values in enum.
Definition enconvert.c:636
static int GetConsolePresetID()
Definition inpututils.c:224
static const float ICON_SCALE_TOOLBAR
Definition inpututils.c:15
static void UpdateConsolePresetID()
Definition inpututils.c:209
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
static const string PRESET_NEW
Definition inpututils.c:5
static const string PRESET_OLD
Definition inpututils.c:4
proto native void PresetSelect(int index)
proto native int PresetCurrent()
proto native owned string PresetName(int index)
proto native void SaveInputPresetMiscData()
proto native void Export()
proto native void SupressNextFrame(bool bForce)
proto native int PresetCount()
Xbox menu.
Definition dayzgame.c:64
void OnInputPresetChanged()
string m_BackButtonTextID
void ButtonSetText(Widget w, string text)
const int PLATFORM_ADJUST_PS
bool FindAllChildrenByID(Widget wid, int user_id, out array< Widget > results)
Finds all immediate children widgets with corresponding userIDs.
void UpdateControlsElementVisibility()
override void Update(float timeslice)
void ComposeData()
Inits data structure.
int FilterByVisible(array< Widget > input, array< Widget > filtered)
returns count
override void OnShow()
override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
ImageWidget m_ControlsLayoutImage
void ButtonSetColor(Widget w, int color)
void DrawConnectingLines(int index)
CanvasWidget m_CanvasWidget
ButtonWidget m_Back
void ButtonSetTextColor(Widget w, int color)
void UpdateTabContent(int tab_index)
ref map< int, Widget > m_ImageMarkerStructure
void OnInputDeviceChanged(EInputDeviceType pInputDeviceType)
ref map< int, ref TButtonPairingInfo > m_AreasLR
void ColorNormal(Widget w)
Widget FindChildByID(Widget wid, int user_id)
Finds immediate child widget with a corresponding userID.
const int AREA_RIGHT
override Widget Init()
void UpdateControlsElements()
override bool OnFocusLost(Widget w, int x, int y)
bool IsFocusable(Widget w)
override bool OnMouseEnter(Widget w, int x, int y)
void ColorHighlight(Widget w)
override bool OnFocus(Widget w, int x, int y)
override bool OnClick(Widget w, int x, int y, int button)
const int PLATFORM_ADJUST_X1
const int AREA_LEFT
ref map< int, Widget > m_CategoryStructure
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
enum map TButtonPairingInfo
@ BUTTON_A
@ BUTTON_PAD_LEFT
@ BUTTON_TRIGGER_RIGHT
@ BUTTON_SHOULDER_RIGHT
@ BUTTON_X
@ BUTTON_PAD_UP
@ BUTTON_GROUP_PAD_COMMON
@ BUTTON_TRIGGER_LEFT
@ BUTTON_B
@ BUTTON_PAD_RIGHT
@ BUTTON_PAD_DOWN
@ BUTTON_SHOULDER_LEFT
@ BUTTON_THUMB_LEFT
@ BUTTON_MENU
@ BUTTON_VIEW
@ BUTTON_THUMB_RIGHT
@ BUTTON_GROUP_RIGHT_SIDE_COMMON
@ BUTTON_Y
DayZGame g_Game
Definition dayzgame.c:3942
proto void Print(void var)
Prints content of variable to console/log.
static proto bool CastTo(out Class to, Class from)
Try to safely down-cast base class to child class.
@ INVALID
Invalid file.
Definition ensystem.c:510
MouseState
Definition ensystem.c:311
proto native void SetFocus(Widget w)
proto native bool IsVisible()
Icon x
Icon y
EInputDeviceType
Definition input.c:3
int ARGB(int a, int r, int g, int b)
Definition proto.c:322
proto native UAInputAPI GetUApi()