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