Dayz Build 1.29.163047, Scripts Rev. 123548
Dayz Code Explorer by Zeroy
Loading...
Searching...
No Matches
keybindingsmenu.c
Go to the documentation of this file.
1class KeybindingsMenu extends UIScriptedMenu
2{
3 protected TabberUI m_Tabber;
4 protected ref DropdownPrefab m_KBDropdown; //DEPRECATED
5 protected ref OptionSelectorMultistate m_PresetSelector;
6 protected ref KeybindingsContainer m_GroupsContainer;
7 protected ref array<ref KeybindingsGroup> m_Tabs; //DEPRECATED
8
9 protected TextWidget m_Version;
10 protected ButtonWidget m_Apply;
11 protected ButtonWidget m_Back;
12 protected ButtonWidget m_Undo;
13 protected ButtonWidget m_Defaults;
14 protected ButtonWidget m_HardReset;
15
16 protected int m_CurrentSettingKeyIndex = -1;
18 protected int m_OriginalPresetIndex;
19 protected int m_TargetPresetIndex;
21
22 const int MODAL_ID_BACK = 1337;
23 const int MODAL_ID_DEFAULT = 100;
24 const int MODAL_ID_DEFAULT_ALL = 101;
25 const int MODAL_ID_PRESET_CHANGE = 200;
28
29 override Widget Init()
30 {
31 Input input = g_Game.GetInput();
32 #ifdef PLATFORM_MSSTORE
33 layoutRoot = g_Game.GetWorkspace().CreateWidgets("gui/layouts/new_ui/options/msstore/keybinding_menu.layout", null);
34 #else
35 layoutRoot = g_Game.GetWorkspace().CreateWidgets("gui/layouts/new_ui/options/pc/keybinding_menu.layout", null);
36 #endif
37
38 m_Version = TextWidget.Cast(layoutRoot.FindAnyWidget("version"));
39 m_Apply = ButtonWidget.Cast(layoutRoot.FindAnyWidget("apply"));
40 m_Back = ButtonWidget.Cast(layoutRoot.FindAnyWidget("back"));
41 m_Undo = ButtonWidget.Cast(layoutRoot.FindAnyWidget("undo"));
42 m_Defaults = ButtonWidget.Cast(layoutRoot.FindAnyWidget("reset"));
43 m_HardReset = ButtonWidget.Cast(layoutRoot.FindAnyWidget("reset_all"));
44
45 layoutRoot.FindAnyWidget("Tabber").GetScript(m_Tabber);
46
47 string version;
48 g_Game.GetVersion(version);
49 #ifdef PLATFORM_CONSOLE
50 version = "#main_menu_version" + " " + version + " (" + g_Game.GetDatabaseID() + ")";
51 #else
52 version = "#main_menu_version" + " " + version;
53 #endif
54 m_Version.SetText(version);
55
56 #ifdef PLATFORM_PS4
57 string back = "circle";
58 if (g_Game.GetInput().GetEnterButton() != GamepadButton.A)
59 back = "cross";
60
61 ImageWidget toolbar_b = ImageWidget.Cast(layoutRoot.FindAnyWidget("BackIcon"));
62 toolbar_b.LoadImageFile(0, "set:playstation_buttons image:" + back);
63 #endif
64
66 CreateTabs();
68
69 InitPresets(-1, layoutRoot.FindAnyWidget("group_header"), input);
70 m_Tabber.m_OnTabSwitch.Insert(UpdateTabContent);
71 m_Tabber.SelectTabControl(0);
72 m_Tabber.SelectTabPanel(0);
73 g_Game.SetKeyboardHandle(this);
74 m_Tabber.RefreshTab(true);
75
77 m_Apply.SetFlags(WidgetFlags.IGNOREPOINTER);
79 m_Undo.SetFlags(WidgetFlags.IGNOREPOINTER);
81 m_Defaults.ClearFlags(WidgetFlags.IGNOREPOINTER);
82
83 return layoutRoot;
84 }
85
87 {
88 int sort_count = InputUtils.GetInputActionSortingMap().Count();
89 for (int i = 0; i < sort_count; i++)
90 {
91 if (InputUtils.GetInputActionSortingMap().GetElement(i) && InputUtils.GetInputActionSortingMap().GetElement(i).Count() > 0)
92 {
93 string group_name = GetUApi().SortingLocalization(InputUtils.GetInputActionSortingMap().GetKey(i));
94 group_name = Widget.TranslateString("#" + group_name); //oof
95 m_Tabber.AddTab(group_name);
96 }
97 }
98
100 {
101 m_Tabber.AddTab(Widget.TranslateString("#layout_pc_keybinding_unsorted"));
102 }
103 m_Tabber.DisableTabs(true);
104 }
105
107 {
108 m_GroupsContainer = new KeybindingsContainer(-1,g_Game.GetInput(),layoutRoot.FindAnyWidget("TabContentsHolder"),this);
109 }
110
111 void UpdateTabContent(int tab_index)
112 {
113 m_GroupsContainer.SwitchSubgroup(tab_index);
114 }
115
116 void ClearKeybind(int key_index)
117 {
118 ColorWhite(m_Apply, null);
119 m_Apply.ClearFlags(WidgetFlags.IGNOREPOINTER);
120 ColorWhite(m_Undo, null);
121 m_Undo.ClearFlags(WidgetFlags.IGNOREPOINTER);
122 }
123
124 void ClearAlternativeKeybind(int key_index)
125 {
126 ColorWhite(m_Apply, null);
127 m_Apply.ClearFlags(WidgetFlags.IGNOREPOINTER);
128 ColorWhite(m_Undo, null);
129 m_Undo.ClearFlags(WidgetFlags.IGNOREPOINTER);
130 }
131
132 void StartEnteringKeybind(int key_index)
133 {
135 m_CurrentSettingKeyIndex = key_index;
136 }
137
139 {
140 m_GroupsContainer.CancelEnteringKeybind();
142 }
143
145 {
148 }
149
151 {
152 m_GroupsContainer.CancelEnteringAlternateKeybind();
154 }
155
157 {
159 ColorWhite(m_Apply, null);
160 m_Apply.ClearFlags(WidgetFlags.IGNOREPOINTER);
161 ColorWhite(m_Undo, null);
162 m_Undo.ClearFlags(WidgetFlags.IGNOREPOINTER);
163 }
164
166 {
168 ColorWhite(m_Apply, null);
169 m_Apply.ClearFlags(WidgetFlags.IGNOREPOINTER);
170 ColorWhite(m_Undo, null);
171 m_Undo.ClearFlags(WidgetFlags.IGNOREPOINTER);
172 }
173
174 override void Update(float timeslice)
175 {
176 if (GetUApi().GetInputByID(UAUITabLeft).LocalPress())
177 {
178 m_Tabber.PreviousTab();
179 }
180
181 if (GetUApi().GetInputByID(UAUITabRight).LocalPress())
182 {
183 m_Tabber.NextTab();
184 }
185
186 if (GetUApi().GetInputByID(UAUIBack).LocalPress())
187 {
188 Back();
189 }
190
192 {
193 m_GroupsContainer.Update(timeslice);
194 }
195 }
196
197 override bool OnClick(Widget w, int x, int y, int button)
198 {
199 #ifndef PLATFORM_MSSTORE
200 if (button == MouseState.LEFT)
201 #endif
202 {
203 if (w == m_Apply)
204 {
205 Apply();
206 return true;
207 }
208 else if (w == m_Back)
209 {
210 Back();
211 return true;
212 }
213 else if (w == m_Undo)
214 {
215 Reset();
216 return true;
217 }
218 else if (w == m_Defaults)
219 {
221 return true;
222 }
223 else if (w == m_HardReset)
224 {
225 HardReset();
226 return true;
227 }
228 }
229 return false;
230 }
231
232 void Apply()
233 {
235 m_Apply.SetFlags(WidgetFlags.IGNOREPOINTER);
237 m_Undo.SetFlags(WidgetFlags.IGNOREPOINTER);
238 ColorWhite(m_Defaults, null);
239 m_Defaults.ClearFlags(WidgetFlags.IGNOREPOINTER);
240
241 m_GroupsContainer.Apply();
242
243 // save input configuration
244 GetUApi().Export();
245 }
246
247 void Back()
248 {
249 if (m_CurrentSettingKeyIndex != -1)
250 {
252 return;
253 }
254
256 {
258 return;
259 }
260
261 bool changed = m_GroupsContainer.IsChanged();
262
263 if (changed)
264 {
265 g_Game.GetUIManager().ShowDialog("#main_menu_configure", "#main_menu_configure_desc", MODAL_ID_BACK, DBT_YESNO, DBB_YES, DMT_QUESTION, this);
266 }
267 else
268 {
269 g_Game.GetUIManager().Back();
270 }
271 }
272
274 void Reset()
275 {
277 m_Apply.SetFlags(WidgetFlags.IGNOREPOINTER);
279 m_Undo.SetFlags(WidgetFlags.IGNOREPOINTER);
280
281 m_GroupsContainer.Reset();
282 }
283
285 {
286 g_Game.GetUIManager().ShowDialog("#menu_default_cap", "#menu_default_desc", MODAL_ID_DEFAULT, DBT_YESNO, DBB_YES, DMT_QUESTION, this);
287 }
288
290 {
291 g_Game.GetUIManager().ShowDialog("#menu_default_cap", "#menu_default_all_desc", MODAL_ID_DEFAULT_ALL, DBT_YESNO, DBB_YES, DMT_QUESTION, this);
292 }
293
295 {
296 switch (mode)
297 {
300 break;
301
303 GetUApi().Revert();
304 break;
305 }
306
308 m_Apply.SetFlags(WidgetFlags.IGNOREPOINTER);
310 m_Undo.SetFlags(WidgetFlags.IGNOREPOINTER);
311 g_Game.GetCallQueue(CALL_CATEGORY_GUI).Call(g_Game.GetMission().RefreshExcludes);
312 m_GroupsContainer.Reset(true);
313 }
314
315 override bool OnModalResult(Widget w, int x, int y, int code, int result)
316 {
317 if (code == MODAL_ID_BACK)
318 {
319 if (result == DBB_YES)
320 {
321 Reset();
322 g_Game.GetUIManager().Back();
323 }
324 return true;
325 }
326 else if (code == MODAL_ID_DEFAULT)
327 {
328 if (result == DBB_YES)
329 {
331 }
332 return true;
333 }
334 else if (code == MODAL_ID_DEFAULT_ALL)
335 {
336 if (result == DBB_YES)
337 {
339 }
340 }
341 else if (code == MODAL_ID_PRESET_CHANGE)
342 {
343 if (result == DBB_YES)
344 {
345 Reset();
346 m_PresetSelector.PerformSetOption(m_TargetPresetIndex);
347 }
348 return true;
349 }
350
351 return false;
352 }
353
354 override void Refresh()
355 {
356 string version;
357 g_Game.GetVersion(version);
358 #ifdef PLATFORM_CONSOLE
359 version = "#main_menu_version" + " " + version + " (" + g_Game.GetDatabaseID() + ")";
360 #else
361 version = "#main_menu_version" + " " + version;
362 #endif
363 m_Version.SetText(version);
364 }
365
366 override bool OnMouseEnter(Widget w, int x, int y)
367 {
368 if (w && IsFocusable(w))
369 {
370 ColorRed(w);
371 return true;
372 }
373 return false;
374 }
375
376 override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
377 {
378 if (w && IsFocusable(w))
379 {
380 if ((w.GetFlags() & WidgetFlags.DISABLED) || (w.GetFlags() & WidgetFlags.IGNOREPOINTER))
381 {
382 ColorDisabled(w);
383 }
384 else
385 {
386 ColorWhite(w, enterW);
387 }
388 return true;
389 }
390 return false;
391 }
392
393 override bool OnMouseWheel(Widget w, int x, int y, int wheel)
394 {
395 return super.OnMouseWheel(w, x, y, wheel);
396 }
397
398 override bool OnFocus(Widget w, int x, int y)
399 {
400 if (w && IsFocusable(w))
401 {
402 ColorRed(w);
403 return true;
404 }
405 return false;
406 }
407
408 override bool OnFocusLost(Widget w, int x, int y)
409 {
410 if (w && IsFocusable(w))
411 {
412 if ((w.GetFlags() & WidgetFlags.DISABLED) || (w.GetFlags() & WidgetFlags.IGNOREPOINTER))
413 {
414 ColorDisabled(w);
415 }
416 else
417 {
418 ColorWhite(w, null);
419 }
420 return true;
421 }
422 return false;
423 }
424
426 {
427 if (w)
428 {
429 return (w == m_Apply || w == m_Back || w == m_Undo || w == m_Defaults || w == m_HardReset);
430 }
431 return false;
432 }
433
434 //Coloring functions (Until WidgetStyles are useful)
436 {
437 SetFocus(w);
438
439 ButtonWidget button = ButtonWidget.Cast(w);
440 if (button && button != m_Apply)
441 {
442 button.SetTextColor(ARGB(255, 200, 0, 0));
443 }
444 }
445
446 void ColorWhite(Widget w, Widget enterW)
447 {
448 #ifdef PLATFORM_WINDOWS
449 SetFocus(null);
450 #endif
451
452 ButtonWidget button = ButtonWidget.Cast(w);
453 if (button)
454 {
455 if (button.GetFlags() & WidgetFlags.DISABLED)
456 {
457 button.SetTextColor(ColorManager.COLOR_DISABLED_TEXT);
458 }
459 else
460 {
461 button.SetTextColor(ColorManager.COLOR_NORMAL_TEXT);
462 }
463 }
464 }
465
467 {
468 #ifdef PLATFORM_WINDOWS
469 SetFocus(null);
470 #endif
471
472 ButtonWidget button = ButtonWidget.Cast(w);
473 if (button)
474 {
475 button.SetTextColor(ColorManager.COLOR_DISABLED_TEXT);
476 }
477 }
478
479 protected void InitInputSortingMap()
480 {
482 }
483
484 void InitPresets(int index, Widget parent, Input input)
485 {
486 Widget kb_root = parent.FindAnyWidget("keyboard_dropown");
487 if (kb_root)
488 {
489 kb_root.Show(false);
490 }
491
492 array<string> opt1 = new array<string>;
493 string profile_text;
494
495 for (int i = 0; i < input.GetProfilesCount(); i++)
496 {
497 input.GetProfileName(i, profile_text);
498 opt1.Insert(profile_text);
499 }
500
501 int current_idx = input.GetCurrentProfile();
502 m_OriginalPresetIndex = current_idx;
503 m_PresetSelector = new OptionSelectorMultistate(layoutRoot.FindAnyWidget("profile_setting_option"), current_idx, null, false, opt1);
504 m_PresetSelector.m_AttemptOptionChange.Insert(OnAttemptSelectPreset);
505 m_PresetSelector.m_OptionChanged.Insert(OnSelectKBPreset);
506 }
507
508 void OnAttemptSelectPreset(int index)
509 {
510 bool changed = m_GroupsContainer.IsChanged() && m_OriginalPresetIndex != index;
511 m_TargetPresetIndex = index;
512
513 if (changed)
514 {
515 g_Game.GetUIManager().ShowDialog("#main_menu_configure", "#main_menu_configure_desc", MODAL_ID_PRESET_CHANGE, DBT_YESNO, DBB_YES, DMT_QUESTION, this);
516 }
517
518 m_PresetSelector.SetCanSwitch(!changed);
519 }
520
521 void OnSelectKBPreset(int index)
522 {
523 m_OriginalPresetIndex = index;
524 m_GroupsContainer.OnSelectKBPreset(index);
525 string profile_text;
526 g_Game.GetInput().GetProfileName(index, profile_text);
527
528 g_Game.GetMission().GetOnInputPresetChanged().Invoke();
529 }
530
532// OBSOLETE METHODS //
534 KeybindingsContainer GetCurrentTab()
535 {
536 return m_GroupsContainer;
537 }
538
539 void AddGroup(int index, Input input)
540 {
541 }
542
548
550 {
551 }
552}
static int COLOR_DISABLED_TEXT
static int COLOR_NORMAL_TEXT
Definition colormanager.c:5
Definition input.c:11
proto native int GetCurrentProfile()
gets currently selected profile
proto int GetProfileName(int profile_index, out string name)
gets profile by index
proto native int GetProfilesCount()
gets profile by name
static bool InitInputMetadata()
Definition inpututils.c:239
static array< int > GetUnsortedInputActions()
Definition inpututils.c:234
static map< int, ref array< int > > GetInputActionSortingMap()
Definition inpututils.c:229
proto native owned string SortingLocalization(int index)
proto native void Export()
proto native void PresetReset()
Resets current 'main' preset without reverting anything else ('softer' Revert).
proto native void Revert()
Xbox menu.
Definition dayzgame.c:64
void StartEnteringAlternateKeybind(int key_index)
void ColorRed(Widget w)
void ColorDisabled(Widget w)
const int MODAL_ID_PRESET_CHANGE
override void Update(float timeslice)
const int MODAL_RESULT_DEFAULT_CURRENT
void CancelEnteringKeybind()
void ClearAlternativeKeybind(int key_index)
const int MODAL_ID_DEFAULT_ALL
ref DropdownPrefab m_KBDropdown
override void Refresh()
void Reset()
Undoes the unsaved changes and reverts to previous state. Does not reset to defaults!
int m_CurrentSettingAlternateKeyIndex
override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
void CancelEnteringAlternateKeybind()
ref OptionSelectorMultistate m_PresetSelector
KeybindingsContainer GetCurrentTab()
ButtonWidget m_Undo
void ConfirmKeybindEntry(TIntArray new_keys)
const int MODAL_ID_DEFAULT
const int MODAL_ID_BACK
const int MODAL_RESULT_DEFAULT_ALL
ref array< int > m_SetKeybinds
void PerformSetToDefaults()
deprecated, resets all (as before ~1.20)
TextWidget m_Version
void Apply()
renames character
ButtonWidget m_Back
void CreateGroupContainer()
void UpdateTabContent(int tab_index)
void PerformSetToDefaultsExt(int mode)
ref array< ref KeybindingsGroup > m_Tabs
void AddGroup(int index, Input input)
ButtonWidget m_HardReset
void ColorWhite(Widget w, Widget enterW)
ButtonWidget m_Defaults
void StartEnteringKeybind(int key_index)
void OnSelectKBPreset(int index)
void ConfirmAlternateKeybindEntry(TIntArray new_keys)
override Widget Init()
override bool OnModalResult(Widget w, int x, int y, int code, int result)
void DeferredDefaultsInit()
deprecated
override bool OnFocusLost(Widget w, int x, int y)
bool IsFocusable(Widget w)
void InitPresets(int index, Widget parent, Input input)
override bool OnMouseEnter(Widget w, int x, int y)
override bool OnMouseWheel(Widget w, int x, int y, int wheel)
override bool OnFocus(Widget w, int x, int y)
override bool OnClick(Widget w, int x, int y, int button)
void OnAttemptSelectPreset(int index)
ref KeybindingsContainer m_GroupsContainer
void ClearKeybind(int key_index)
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
DayZGame g_Game
Definition dayzgame.c:3942
array< int > TIntArray
Definition enscript.c:714
GamepadButton
Definition ensystem.c:341
MouseState
Definition ensystem.c:311
const int CALL_CATEGORY_GUI
Definition tools.c:9
WidgetFlags
Definition enwidgets.c:58
proto native void SetFocus(Widget w)
Icon x
Icon y
int ARGB(int a, int r, int g, int b)
Definition proto.c:322
proto native UAInputAPI GetUApi()