DayZ 1.27
DayZ Explorer by KGB
 
Загрузка...
Поиск...
Не найдено
ControlsXboxNew.c
См. документацию.
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 {
75
76 switch (pInputDeviceType)
77 {
78 case EInputDeviceType.CONTROLLER:
79 if (mk && mkServer)
80 {
82 }
83 break;
84
85 default:
86 if (GetGame().GetInput().IsEnabledMouseAndKeyboard())
87 {
89 }
90 break;
91 }
92
94 }
95
96 void Back()
97 {
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 = 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
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
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 {
309 {
310 m_CategoryStructure = null;
312 }
313
315 {
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
333 #else
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
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);
389 {
390 m_NextPresetText = "#STR_UAPRESET_ChangeTo_0";
391 }
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
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
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
545 #endif
546
547 layoutRoot.FindAnyWidget("toolbar_bg").Show(toolbarShow);
548 layoutRoot.FindAnyWidget("play_panel_root").Show(!toolbarShow);
549 }
550}
enum map TButtonPairingInfo
map
Определения ControlsXboxNew.c:4
@ BUTTON_A
Определения ControlsXboxNew.c:8
@ BUTTON_PAD_LEFT
Определения ControlsXboxNew.c:14
@ BUTTON_TRIGGER_RIGHT
Определения ControlsXboxNew.c:21
@ BUTTON_SHOULDER_RIGHT
Определения ControlsXboxNew.c:17
@ BUTTON_X
Определения ControlsXboxNew.c:10
@ BUTTON_PAD_UP
Определения ControlsXboxNew.c:12
@ BUTTON_GROUP_PAD_COMMON
Определения ControlsXboxNew.c:23
@ BUTTON_TRIGGER_LEFT
Определения ControlsXboxNew.c:20
@ BUTTON_B
Определения ControlsXboxNew.c:9
@ BUTTON_PAD_RIGHT
Определения ControlsXboxNew.c:15
@ BUTTON_PAD_DOWN
Определения ControlsXboxNew.c:13
@ BUTTON_SHOULDER_LEFT
Определения ControlsXboxNew.c:16
@ BUTTON_THUMB_LEFT
Определения ControlsXboxNew.c:18
@ BUTTON_MENU
Определения ControlsXboxNew.c:6
@ BUTTON_VIEW
Определения ControlsXboxNew.c:7
@ BUTTON_THUMB_RIGHT
Определения ControlsXboxNew.c:19
@ BUTTON_GROUP_RIGHT_SIDE_COMMON
Определения ControlsXboxNew.c:22
@ BUTTON_Y
Определения ControlsXboxNew.c:11
Icon x
Icon y
proto native UAInputAPI GetUApi()
proto native UIManager GetUIManager()
proto native WorkspaceWidget GetWorkspace()
proto native Input GetInput()
proto native Mission GetMission()
Super root of all classes in Enforce script.
Определения EnScript.c:11
static int GetEnumSize(typename e)
Return amount of values in enum.
Определения EnConvert.c:623
Определения EnConvert.c:590
proto native EInputDeviceType GetCurrentInputDevice()
proto native bool IsEnabledMouseAndKeyboard()
proto native bool IsEnabledMouseAndKeyboardEvenOnServer()
static const string PRESET_NEW
Определения InputUtils.c:5
static const string PRESET_OLD
Определения InputUtils.c:4
static int GetConsolePresetID()
Определения InputUtils.c:224
static string GetRichtextButtonIconFromInputAction(notnull UAInput pInput, string pLocalizedDescription, int pInputDeviceType=EUAINPUT_DEVICE_CONTROLLER, float pScale=ICON_SCALE_NORMAL, bool pVertical=false)
Определения InputUtils.c:167
static void UpdateConsolePresetID()
Определения InputUtils.c:209
static const float ICON_SCALE_TOOLBAR
Определения InputUtils.c:15
Определения InputUtils.c:2
ScriptInvoker GetOnInputDeviceChanged()
Определения gameplay.c:851
ScriptInvoker GetOnInputPresetChanged()
Определения gameplay.c:859
Определения gameplay.c:317
proto void Invoke(void param1=NULL, void param2=NULL, void param3=NULL, void param4=NULL, void param5=NULL, void param6=NULL, void param7=NULL, void param8=NULL, void param9=NULL)
invoke call on all inserted methods with given arguments
proto bool Insert(func fn, int flags=EScriptInvokerInsertFlags.IMMEDIATE)
insert method to list
Определения EnWidgets.c:220
proto native void SaveInputPresetMiscData()
proto native owned string PresetName(int index)
proto native void SupressNextFrame(bool bForce)
proto native int PresetCurrent()
proto native void PresetSelect(int index)
proto native int PresetCount()
proto native void Export()
Определения UAInput.c:166
void ShowUICursor(bool visible)
Определения UIManager.c:244
bool Back()
Close top window on windows stack, returns true when any window is closed.
Определения UIManager.c:62
void UpdateControlsElementVisibility()
Определения ControlsXboxNew.c:540
const int AREA_RIGHT
Определения ControlsXboxNew.c:51
override bool OnMouseEnter(Widget w, int x, int y)
Определения ControlsXboxNew.c:236
override void OnShow()
Определения ControlsXboxNew.c:215
const int PLATFORM_ADJUST_X1
Определения ControlsXboxNew.c:52
void ComposeData()
Inits data structure.
Определения ControlsXboxNew.c:306
override bool OnFocus(Widget w, int x, int y)
Определения ControlsXboxNew.c:256
Widget m_TabberWidget
Определения ControlsXboxNew.c:41
Widget m_PlatformHolder
Определения ControlsXboxNew.c:43
override void Update(float timeslice)
Определения ControlsXboxNew.c:281
CanvasWidget m_CanvasWidget
Определения ControlsXboxNew.c:39
Widget FindChildByID(Widget wid, int user_id)
Finds immediate child widget with a corresponding userID.
Определения ControlsXboxNew.c:403
TabberUI m_TabScript
Определения ControlsXboxNew.c:40
const int PLATFORM_ADJUST_PS
Определения ControlsXboxNew.c:53
int FilterByVisible(array< Widget > input, array< Widget > filtered)
returns count
Определения ControlsXboxNew.c:433
string m_BackButtonTextID
Определения ControlsXboxNew.c:30
Widget m_VariantWidget
Определения ControlsXboxNew.c:44
void ColorHighlight(Widget w)
Определения ControlsXboxNew.c:446
bool IsFocusable(Widget w)
Определения CameraToolsMenu.c:960
void UpdateToolbarText()
Определения ControlsXboxNew.c:377
void OnInputDeviceChanged(EInputDeviceType pInputDeviceType)
Определения ControlsXboxNew.c:71
void ButtonSetText(Widget w, string text)
Определения ControlsXboxNew.c:475
ref map< int, ref TButtonPairingInfo > m_AreasLR
Определения ControlsXboxNew.c:48
ImageWidget m_ControlsLayoutImage
Определения ControlsXboxNew.c:36
ref map< int, Widget > m_ImageMarkerStructure
Определения ControlsXboxNew.c:46
override bool OnFocusLost(Widget w, int x, int y)
Определения ControlsXboxNew.c:266
override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
Определения ControlsXboxNew.c:246
void Back()
Определения ControlsXboxNew.c:96
void DrawConnectingLines(int index)
Определения ControlsXboxNew.c:130
string m_NextPresetText
Определения ControlsXboxNew.c:31
void UpdateTabContent(int tab_index)
Определения ControlsXboxNew.c:101
void ~ControlsXboxNew()
Определения ControlsXboxNew.c:58
void UpdateControlsElements()
Определения ControlsXboxNew.c:527
void PerformSwitchPreset()
Определения ControlsXboxNew.c:348
ref map< int, Widget > m_CategoryStructure
Определения ControlsXboxNew.c:47
void ButtonSetTextColor(Widget w, int color)
Определения ControlsXboxNew.c:502
ButtonWidget m_Back
Определения ControlsXboxNew.c:35
override Widget Init()
Определения ControlsXboxNew.c:178
int m_CurrentTabIdx
Определения ControlsXboxNew.c:32
override bool OnClick(Widget w, int x, int y, int button)
Определения ControlsXboxNew.c:223
void ButtonSetColor(Widget w, int color)
Определения ControlsXboxNew.c:489
bool FindAllChildrenByID(Widget wid, int user_id, out array< Widget > results)
Finds all immediate children widgets with corresponding userIDs.
Определения ControlsXboxNew.c:418
Widget m_ControlsImage
Определения ControlsXboxNew.c:42
void ColorNormal(Widget w)
Определения ControlsXboxNew.c:463
int m_CurrentPresetVariant
Определения ControlsXboxNew.c:33
const int AREA_LEFT
Определения ControlsXboxNew.c:50
void OnInputPresetChanged()
Определения ControlsXboxNew.c:63
Определения DayZGame.c:64
Определения EnWidgets.c:190
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
proto native CGame GetGame()
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.
Определения EnSystem.c:510
MouseState
Определения EnSystem.c:311
proto native external Widget CreateWidgets(string layout, Widget parentWidget=NULL, bool immedUpdate=true)
Create widgets from *.layout file.
proto native void SetFocus(Widget w)
proto native bool IsVisible()
EInputDeviceType
Определения input.c:3
int ARGB(int a, int r, int g, int b)
Определения proto.c:322