Dayz Explorer 1.28.160049
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.)
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;
41 protected Widget m_TabberWidget;
42 protected Widget m_ControlsImage;
43 protected Widget m_PlatformHolder; //controls container for selected platform
44 protected Widget m_VariantWidget;
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 = GetGame().GetInput().IsEnabledMouseAndKeyboard();
74 bool mkServer = GetGame().GetInput().IsEnabledMouseAndKeyboardEvenOnServer();
75
76 switch (pInputDeviceType)
77 {
78 case EInputDeviceType.CONTROLLER:
79 if (mk && mkServer)
80 {
81 GetGame().GetUIManager().ShowUICursor(false);
82 }
83 break;
84
85 default:
86 if (GetGame().GetInput().IsEnabledMouseAndKeyboard())
87 {
88 GetGame().GetUIManager().ShowUICursor(true);
89 }
90 break;
91 }
92
94 }
95
96 void Back()
97 {
98 GetGame().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
116 w = FindChildByID(m_CategoryStructure[tab_index],InputUtils.GetConsolePresetID());
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
139 m_AreasLR = new map<int,ref TButtonPairingInfo>;
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 {
180 m_CategoryStructure = new map<int,Widget>;
181 m_ImageMarkerStructure = new map<int,Widget>;
182
183 layoutRoot = GetGame().GetWorkspace().CreateWidgets("gui/layouts/xbox/Controls_Screen.layout");
184 #ifdef PLATFORM_XBOX
185 m_ControlsImage = layoutRoot.FindAnyWidget("XboxControlsImage");
186 #else
187 #ifdef PLATFORM_PS4
188 m_ControlsImage = layoutRoot.FindAnyWidget("PSControlsImage");
189 #endif
190 #endif
191 m_ControlsImage.Show(true);
192 m_TabberWidget = layoutRoot.FindAnyWidget("Tabber");
193 m_TabberWidget.GetScript(m_TabScript);
194 m_TabScript.m_OnTabSwitch.Insert(UpdateTabContent);
195 m_CanvasWidget = CanvasWidget.Cast(layoutRoot.FindAnyWidget("CanvasUniversal"));
196 m_Back = ButtonWidget.Cast(layoutRoot.FindAnyWidget("back"));
197
201
202 PPERequester_MenuEffects requester;
203 Class.CastTo(requester,PPERequesterBank.GetRequester(PPERequesterBank.REQ_MENUEFFECTS));
204 requester.SetVignetteIntensity(0.6);
205
206 ComposeData();
208
209 GetGame().GetMission().GetOnInputPresetChanged().Insert(OnInputPresetChanged);
210 GetGame().GetMission().GetOnInputDeviceChanged().Insert(OnInputDeviceChanged);
211
212 return layoutRoot;
213 }
214
215 override void OnShow()
216 {
217 super.OnShow();
218
219 SetFocus(null);
220 OnInputDeviceChanged(GetGame().GetInput().GetCurrentInputDevice());
221 }
222
223 override bool OnClick(Widget w, int x, int y, int button)
224 {
225 if (button == MouseState.LEFT)
226 {
227 if (w == m_Back)
228 {
229 Back();
230 return true;
231 }
232 }
233 return false;
234 }
235
236 override bool OnMouseEnter(Widget w, int x, int y)
237 {
238 if (IsFocusable(w))
239 {
241 return true;
242 }
243 return false;
244 }
245
246 override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
247 {
248 if (IsFocusable(w))
249 {
250 ColorNormal(w);
251 return true;
252 }
253 return false;
254 }
255
256 override bool OnFocus(Widget w, int x, int y)
257 {
258 if (IsFocusable(w))
259 {
261 return true;
262 }
263 return false;
264 }
265
266 override bool OnFocusLost(Widget w, int x, int y)
267 {
268 if (IsFocusable(w))
269 {
270 ColorNormal(w);
271 return true;
272 }
273 return false;
274 }
275
276 bool IsFocusable(Widget w)
277 {
278 return (w && w == m_Back);
279 }
280
281 override void Update(float timeslice)
282 {
283 if (GetUApi().GetInputByID(UAUITabLeft).LocalPress())
284 {
285 m_TabScript.PreviousTab();
286 }
287
288 if (GetUApi().GetInputByID(UAUITabRight).LocalPress())
289 {
290 m_TabScript.NextTab();
291 }
292
293 if (GetUApi().GetInputByID(UAUIBack).LocalPress())
294 {
295 Back();
296 }
297
298 if (GetUApi().GetInputByID(UASwitchPreset).LocalPress())
299 {
301 m_TabScript.RefreshTab();
302 }
303 }
304
306 protected void ComposeData()
307 {
308 if (m_CategoryStructure)
309 {
310 m_CategoryStructure = null;
311 m_CategoryStructure = new map<int,Widget>;
312 }
313
314 if (m_ImageMarkerStructure)
315 {
316 m_ImageMarkerStructure = null;
317 m_ImageMarkerStructure = new map<int,Widget>;
318 }
319
320 Widget w = m_ControlsImage.GetChildren();
321 m_ImageMarkerStructure.Set(w.GetUserID(),w);
322
323 while (w.GetSibling())
324 {
325 w = w.GetSibling();
326 m_ImageMarkerStructure.Set(w.GetUserID(),w); //inits button markers with their IDs
327 }
328
330
331 #ifdef PLATFORM_XBOX
332 m_PlatformHolder = FindChildByID(layoutRoot,PLATFORM_ADJUST_X1);
333 #else
334 m_PlatformHolder = FindChildByID(layoutRoot,PLATFORM_ADJUST_PS);
335 #endif
336
337 //categories
338 Widget category_widget = m_PlatformHolder.GetChildren();
339 m_CategoryStructure.Set(category_widget.GetUserID(),category_widget);
340
341 while (category_widget.GetSibling())
342 {
343 category_widget = category_widget.GetSibling();
344 m_CategoryStructure.Set(category_widget.GetUserID(),category_widget);
345 }
346 }
347
348 protected void PerformSwitchPreset()
349 {
350 Print("PerformSwitchPreset - 1");
351 int index;
352 string preset_text;
353 UAInputAPI inputAPI = GetUApi();
354
355 index = inputAPI.PresetCurrent() + 1;
356 if (index >= inputAPI.PresetCount())
357 {
358 index = 0;
359 }
360
361 inputAPI.SupressNextFrame(true);
362 inputAPI.PresetSelect(index);
364
365 GetGame().GetMission().GetOnInputPresetChanged().Invoke();
366
367 #ifdef PLATFORM_WINDOWS
368 GetUApi().Export(); //works on emulated consoles (-xbox,-ps4)
369 #else
370 GetUApi().SaveInputPresetMiscData(); //default console functionality
371 #endif
372
375 }
376
377 protected void UpdateToolbarText()
378 {
379 UAInputAPI inputAPI = GetUApi();
380 int target_idx = inputAPI.PresetCurrent() + 1;
381 int count = inputAPI.PresetCount();
382 if (target_idx >= inputAPI.PresetCount())
383 {
384 target_idx = 0;
385 }
386
387 m_NextPresetText = inputAPI.PresetName(target_idx);
388 if (m_NextPresetText == InputUtils.PRESET_OLD)
389 {
390 m_NextPresetText = "#STR_UAPRESET_ChangeTo_0";
391 }
392 else if (m_NextPresetText == InputUtils.PRESET_NEW)
393 {
394 m_NextPresetText = "#STR_UAPRESET_ChangeTo_1";
395 }
396 else
397 {
398 m_NextPresetText = "Invalid console preset name: " + m_NextPresetText;
399 }
400 }
401
403 protected Widget FindChildByID(Widget wid, int user_id)
404 {
405 Widget ret = wid.GetChildren();
406 while (ret)
407 {
408 if (ret.GetUserID() == user_id)
409 {
410 return ret;
411 }
412 ret = ret.GetSibling();
413 }
414 return ret;
415 }
416
418 protected bool FindAllChildrenByID(Widget wid, int user_id, out array<Widget> results)
419 {
420 Widget child = wid.GetChildren();
421 while (child)
422 {
423 if (child.GetUserID() == user_id)
424 {
425 results.Insert(child);
426 }
427 child = child.GetSibling();
428 }
429 return (results && results.Count() > 0);
430 }
431
433 protected int FilterByVisible(array<Widget> input, array<Widget> filtered)
434 {
435 for (int i = 0; i < input.Count(); i++)
436 {
437 if (input[i].IsVisible())
438 {
439 filtered.Insert(input[i]);
440 }
441 }
442
443 return filtered.Count();
444 }
445
446 void ColorHighlight(Widget w)
447 {
448 if (!w)
449 return;
450
451 int color_pnl = ARGB(255, 0, 0, 0);
452 int color_lbl = ARGB(255, 255, 0, 0);
453
454 #ifdef PLATFORM_CONSOLE
455 color_pnl = ARGB(255, 200, 0, 0);
456 color_lbl = ARGB(255, 255, 255, 255);
457 #endif
458
459 ButtonSetColor(w, color_pnl);
460 ButtonSetTextColor(w, color_lbl);
461 }
462
463 void ColorNormal(Widget w)
464 {
465 if (!w)
466 return;
467
468 int color_pnl = ARGB(0, 0, 0, 0);
469 int color_lbl = ARGB(255, 255, 255, 255);
470
471 ButtonSetColor(w, color_pnl);
472 ButtonSetTextColor(w, color_lbl);
473 }
474
475 void ButtonSetText(Widget w, string text)
476 {
477 if (!w)
478 return;
479
480 TextWidget label = TextWidget.Cast(w.FindWidget(w.GetName() + "_label"));
481
482 if (label)
483 {
484 label.SetText(text);
485 }
486
487 }
488
489 void ButtonSetColor(Widget w, int color)
490 {
491 if (!w)
492 return;
493
494 Widget panel = w.FindWidget(w.GetName() + "_panel");
495
496 if (panel)
497 {
498 panel.SetColor(color);
499 }
500 }
501
502 void ButtonSetTextColor(Widget w, int color)
503 {
504 if (!w)
505 return;
506
507 TextWidget label = TextWidget.Cast(w.FindAnyWidget(w.GetName() + "_label"));
508 TextWidget text = TextWidget.Cast(w.FindAnyWidget(w.GetName() + "_text"));
509 TextWidget text2 = TextWidget.Cast(w.FindAnyWidget(w.GetName() + "_text_1"));
510
511 if (label)
512 {
513 label.SetColor(color);
514 }
515
516 if (text)
517 {
518 text.SetColor(color);
519 }
520
521 if (text2)
522 {
523 text2.SetColor(color);
524 }
525 }
526
527 protected void UpdateControlsElements()
528 {
529 RichTextWidget toolbar_switch = RichTextWidget.Cast(layoutRoot.FindAnyWidget("ChangePresetText"));
530 toolbar_switch.SetText(InputUtils.GetRichtextButtonIconFromInputAction("UASwitchPreset", m_NextPresetText, EUAINPUT_DEVICE_CONTROLLER, InputUtils.ICON_SCALE_TOOLBAR));
531
532 RichTextWidget toolbar_text = RichTextWidget.Cast(layoutRoot.FindAnyWidget("ContextToolbarText"));
533 string text = string.Format(" %1",InputUtils.GetRichtextButtonIconFromInputAction("UAUIBack", "#STR_settings_menu_root_toolbar_bg_ConsoleToolbar_Back_BackText0", EUAINPUT_DEVICE_CONTROLLER, InputUtils.ICON_SCALE_TOOLBAR));
534 toolbar_text.SetText(text);
535
536 RichTextWidget toolbar_b2 = RichTextWidget.Cast(layoutRoot.FindAnyWidget("BackIcon0"));
537 toolbar_b2.SetText(InputUtils.GetRichtextButtonIconFromInputAction("UAUIBack", "", EUAINPUT_DEVICE_CONTROLLER, InputUtils.ICON_SCALE_TOOLBAR));
538 }
539
541 {
542 bool toolbarShow = false;
543 #ifdef PLATFORM_CONSOLE
544 toolbarShow = !GetGame().GetInput().IsEnabledMouseAndKeyboardEvenOnServer() || GetGame().GetInput().GetCurrentInputDevice() == EInputDeviceType.CONTROLLER;
545 #endif
546
547 layoutRoot.FindAnyWidget("toolbar_bg").Show(toolbarShow);
548 layoutRoot.FindAnyWidget("play_panel_root").Show(!toolbarShow);
549 }
550}
void OnInputPresetChanged()
Definition inventory.c:168
void OnInputDeviceChanged(EInputDeviceType pInputDeviceType)
Definition inventory.c:175
Super root of all classes in Enforce script.
Definition enscript.c:11
static int GetConsolePresetID()
Definition inpututils.c:224
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 void UpdateConsolePresetID()
Definition inpututils.c:209
static const float ICON_SCALE_TOOLBAR
Definition inpututils.c:15
void UpdateControlsElementVisibility()
override bool OnMouseEnter(Widget w, int x, int y)
override void OnShow()
void ComposeData()
Inits data structure.
override bool OnFocus(Widget w, int x, int y)
override void Update(float timeslice)
CanvasWidget m_CanvasWidget
Widget FindChildByID(Widget wid, int user_id)
Finds immediate child widget with a corresponding userID.
int FilterByVisible(array< Widget > input, array< Widget > filtered)
returns count
string m_BackButtonTextID
void ColorHighlight(Widget w)
bool IsFocusable(Widget w)
void OnInputDeviceChanged(EInputDeviceType pInputDeviceType)
void ButtonSetText(Widget w, string text)
ref map< int, ref TButtonPairingInfo > m_AreasLR
ImageWidget m_ControlsLayoutImage
ref map< int, Widget > m_ImageMarkerStructure
override bool OnFocusLost(Widget w, int x, int y)
override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
void DrawConnectingLines(int index)
void UpdateTabContent(int tab_index)
void UpdateControlsElements()
ref map< int, Widget > m_CategoryStructure
void ButtonSetTextColor(Widget w, int color)
ButtonWidget m_Back
override Widget Init()
override bool OnClick(Widget w, int x, int y, int button)
void ButtonSetColor(Widget w, int color)
bool FindAllChildrenByID(Widget wid, int user_id, out array< Widget > results)
Finds all immediate children widgets with corresponding userIDs.
void ColorNormal(Widget w)
void OnInputPresetChanged()
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
TabberUI m_TabScript
ButtonWidget m_Back
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
@ INVALID
@ BUTTON_THUMB_RIGHT
@ BUTTON_GROUP_RIGHT_SIDE_COMMON
@ BUTTON_Y
proto native CGame GetGame()
proto void Print(void var)
Prints content of variable to console/log.
MouseState
Definition ensystem.c:311
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()