DayZ 1.24
Loading...
Searching...
No Matches
KeybindingsMenu.c
Go to the documentation of this file.
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;
11 protected ButtonWidget m_Back;
15
16 protected int m_CurrentSettingKeyIndex = -1;
17 protected int m_CurrentSettingAlternateKeyIndex = -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;
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
83 {
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
96 m_Tabber.AddTab(Widget.TranslateString("#layout_pc_keybinding_unsorted"));
97 m_Tabber.DisableTabs(true);
98 }
99
101 {
102 m_GroupsContainer = new KeybindingsContainer(-1, GetGame().GetInput(), layoutRoot.FindAnyWidget("TabContentsHolder"), this);
103 }
104
106 {
107 m_GroupsContainer.SwitchSubgroup(tab_index);
108 }
109
111 {
112 ColorWhite(m_Apply, null);
113 m_Apply.ClearFlags(WidgetFlags.IGNOREPOINTER);
114 ColorWhite(m_Undo, null);
115 m_Undo.ClearFlags(WidgetFlags.IGNOREPOINTER);
116 }
117
119 {
120 ColorWhite(m_Apply, null);
121 m_Apply.ClearFlags(WidgetFlags.IGNOREPOINTER);
122 ColorWhite(m_Undo, null);
123 m_Undo.ClearFlags(WidgetFlags.IGNOREPOINTER);
124 }
125
127 {
128 m_CurrentSettingAlternateKeyIndex = -1;
129 m_CurrentSettingKeyIndex = key_index;
130 }
131
133 {
134 m_GroupsContainer.CancelEnteringKeybind();
135 m_CurrentSettingKeyIndex = -1;
136 }
137
139 {
140 m_CurrentSettingKeyIndex = -1;
141 m_CurrentSettingAlternateKeyIndex = key_index;
142 }
143
145 {
146 m_GroupsContainer.CancelEnteringAlternateKeybind();
147 m_CurrentSettingAlternateKeyIndex = -1;
148 }
149
151 {
152 m_CurrentSettingKeyIndex = -1;
153 ColorWhite(m_Apply, null);
154 m_Apply.ClearFlags(WidgetFlags.IGNOREPOINTER);
155 ColorWhite(m_Undo, null);
156 m_Undo.ClearFlags(WidgetFlags.IGNOREPOINTER);
157 }
158
160 {
161 m_CurrentSettingAlternateKeyIndex = -1;
162 ColorWhite(m_Apply, null);
163 m_Apply.ClearFlags(WidgetFlags.IGNOREPOINTER);
164 ColorWhite(m_Undo, null);
165 m_Undo.ClearFlags(WidgetFlags.IGNOREPOINTER);
166 }
167
168 override void Update(float timeslice)
169 {
170 if (GetUApi().GetInputByID(UAUIBack).LocalPress())
171 Back();
172
173 if (m_GroupsContainer)
174 m_GroupsContainer.Update(timeslice);
175 }
176
177 override bool OnClick(Widget w, int x, int y, int button)
178 {
179 if (button == MouseState.LEFT)
180 {
181 if (w == m_Apply)
182 {
183 Apply();
184 return true;
185 }
186 else if (w == m_Back)
187 {
188 Back();
189 return true;
190 }
191 else if (w == m_Undo)
192 {
193 Reset();
194 return true;
195 }
196 else if (w == m_Defaults)
197 {
198 SetToDefaults();
199 return true;
200 }
201 else if (w == m_HardReset)
202 {
203 HardReset();
204 return true;
205 }
206 }
207 return false;
208 }
209
210 void Apply()
211 {
212 ColorDisabled(m_Apply);
213 m_Apply.SetFlags(WidgetFlags.IGNOREPOINTER);
214 ColorDisabled(m_Undo);
215 m_Undo.SetFlags(WidgetFlags.IGNOREPOINTER);
216 ColorWhite(m_Defaults, null);
217 m_Defaults.ClearFlags(WidgetFlags.IGNOREPOINTER);
218
219 m_GroupsContainer.Apply();
220
221 // save input configuration
222 GetUApi().Export();
223 }
224
225 void Back()
226 {
227 if (m_CurrentSettingKeyIndex != -1)
228 {
229 CancelEnteringKeybind();
230 return;
231 }
232
233 if (m_CurrentSettingAlternateKeyIndex != -1)
234 {
235 CancelEnteringAlternateKeybind();
236 return;
237 }
238
239 bool changed = m_GroupsContainer.IsChanged();
240
241 if (changed)
242 g_Game.GetUIManager().ShowDialog("#main_menu_configure", "#main_menu_configure_desc", MODAL_ID_BACK, DBT_YESNO, DBB_YES, DMT_QUESTION, this);
243 else
244 GetGame().GetUIManager().Back();
245 }
246
248 void Reset()
249 {
250 ColorDisabled(m_Apply);
251 m_Apply.SetFlags(WidgetFlags.IGNOREPOINTER);
252 ColorDisabled(m_Undo);
253 m_Undo.SetFlags(WidgetFlags.IGNOREPOINTER);
254
255 m_GroupsContainer.Reset();
256 }
257
259 {
260 g_Game.GetUIManager().ShowDialog("#menu_default_cap", "#menu_default_desc", MODAL_ID_DEFAULT, DBT_YESNO, DBB_YES, DMT_QUESTION, this);
261 }
262
264 {
265 g_Game.GetUIManager().ShowDialog("#menu_default_cap", "#menu_default_all_desc", MODAL_ID_DEFAULT_ALL, DBT_YESNO, DBB_YES, DMT_QUESTION, this);
266 }
267
269 {
270 switch (mode)
271 {
272 case MODAL_RESULT_DEFAULT_CURRENT:
273 GetUApi().PresetReset();
274 break;
275
276 case MODAL_RESULT_DEFAULT_ALL:
277 GetUApi().Revert();
278 break;
279 }
280
281 ColorDisabled(m_Apply);
282 m_Apply.SetFlags(WidgetFlags.IGNOREPOINTER);
283 ColorDisabled(m_Undo);
284 m_Undo.SetFlags(WidgetFlags.IGNOREPOINTER);
285 GetGame().GetCallQueue(CALL_CATEGORY_GUI).Call(GetGame().GetMission().RefreshExcludes);
286 m_GroupsContainer.Reset(true);
287 }
288
289 override bool OnModalResult(Widget w, int x, int y, int code, int result)
290 {
291 if (code == MODAL_ID_BACK)
292 {
293 if (result == DBB_YES)
294 {
295 Reset();
296 GetGame().GetUIManager().Back();
297 }
298 return true;
299 }
300 else if (code == MODAL_ID_DEFAULT)
301 {
302 if (result == DBB_YES)
303 PerformSetToDefaultsExt(MODAL_RESULT_DEFAULT_CURRENT);
304 return true;
305 }
306 else if (code == MODAL_ID_DEFAULT_ALL)
307 {
308 if (result == DBB_YES)
309 PerformSetToDefaultsExt(MODAL_RESULT_DEFAULT_ALL);
310 }
311 else if (code == MODAL_ID_PRESET_CHANGE)
312 {
313 if (result == DBB_YES)
314 {
315 Reset();
316 m_PresetSelector.PerformSetOption(m_TargetPresetIndex);
317 }
318 return true;
319 }
320
321 return false;
322 }
323
324 override void Refresh()
325 {
326 string version;
327 GetGame().GetVersion(version);
328#ifdef PLATFORM_CONSOLE
329 version = "#main_menu_version" + " " + version + " (" + g_Game.GetDatabaseID() + ")";
330#else
331 version = "#main_menu_version" + " " + version;
332#endif
333 m_Version.SetText(version);
334 }
335
336 override bool OnMouseEnter(Widget w, int x, int y)
337 {
338 if (w && IsFocusable(w))
339 {
340 ColorRed(w);
341 return true;
342 }
343 return false;
344 }
345
346 override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
347 {
348 if (w && IsFocusable(w))
349 {
350 if ((w.GetFlags() & WidgetFlags.DISABLED) || (w.GetFlags() & WidgetFlags.IGNOREPOINTER))
351 ColorDisabled(w);
352 else
353 ColorWhite(w, enterW);
354 return true;
355 }
356 return false;
357 }
358
359 override bool OnMouseWheel(Widget w, int x, int y, int wheel)
360 {
361 return super.OnMouseWheel(w, x, y, wheel);
362 }
363
364 override bool OnFocus(Widget w, int x, int y)
365 {
366 if (w && IsFocusable(w))
367 {
368 ColorRed(w);
369 return true;
370 }
371 return false;
372 }
373
374 override bool OnFocusLost(Widget w, int x, int y)
375 {
376 if (w && IsFocusable(w))
377 {
378 if ((w.GetFlags() & WidgetFlags.DISABLED) || (w.GetFlags() & WidgetFlags.IGNOREPOINTER))
379 ColorDisabled(w);
380 else
381 ColorWhite(w, null);
382 return true;
383 }
384 return false;
385 }
386
388 {
389 if (w)
390 return (w == m_Apply || w == m_Back || w == m_Undo || w == m_Defaults || w == m_HardReset);
391 return false;
392 }
393
394 //Coloring functions (Until WidgetStyles are useful)
396 {
397 SetFocus(w);
398
400 if (button && button != m_Apply)
401 button.SetTextColor(ARGB(255, 200, 0, 0));
402 }
403
405 {
406#ifdef PLATFORM_WINDOWS
407 SetFocus(null);
408#endif
409
411 if (button)
412 {
413 if (button.GetFlags() & WidgetFlags.DISABLED)
415 else
417 }
418 }
419
421 {
422#ifdef PLATFORM_WINDOWS
423 SetFocus(null);
424#endif
425
427 if (button)
429 }
430
431 protected void InitInputSortingMap()
432 {
434 }
435
436 void InitPresets(int index, Widget parent, Input input)
437 {
438 Widget kb_root = parent.FindAnyWidget("keyboard_dropown");
439 if (kb_root)
440 kb_root.Show(false);
441
443 string profile_text;
444
445 for (int i = 0; i < input.GetProfilesCount(); i++)
446 {
447 input.GetProfileName(i, profile_text);
448 opt1.Insert(profile_text);
449 }
450
451 int current_idx = input.GetCurrentProfile();
452 m_OriginalPresetIndex = current_idx;
453 m_PresetSelector = new OptionSelectorMultistate(layoutRoot.FindAnyWidget("profile_setting_option"), current_idx, null, false, opt1);
454 m_PresetSelector.m_AttemptOptionChange.Insert(OnAttemptSelectPreset);
455 m_PresetSelector.m_OptionChanged.Insert(OnSelectKBPreset);
456 }
457
459 {
460 bool changed = m_GroupsContainer.IsChanged() && m_OriginalPresetIndex != index;
461 m_TargetPresetIndex = index;
462
463 if (changed)
464 g_Game.GetUIManager().ShowDialog("#main_menu_configure", "#main_menu_configure_desc", MODAL_ID_PRESET_CHANGE, DBT_YESNO, DBB_YES, DMT_QUESTION, this);
465
466 m_PresetSelector.SetCanSwitch(!changed);
467 }
468
470 {
471 m_OriginalPresetIndex = index;
472 m_GroupsContainer.OnSelectKBPreset(index);
473 string profile_text;
474 GetGame().GetInput().GetProfileName(index, profile_text);
475
476 GetGame().GetMission().GetOnInputPresetChanged().Invoke();
477 }
478
480 // OBSOLETE METHODS //
482 KeybindingsContainer GetCurrentTab()
483 {
484 return m_GroupsContainer;
485 }
486
488 {
489 }
490
493 {
494 PerformSetToDefaultsExt(MODAL_RESULT_DEFAULT_ALL);
495 }
498 {
499 }
500}
void Reset()
Definition Inventory.c:1018
ActionInput GetInput()
Definition ActionBase.c:989
ButtonWidget m_Back
void Back()
DayZGame g_Game
Definition DayZGame.c:3528
Icon x
Icon y
bool IsFocusable(Widget w)
proto native UAInputAPI GetUApi()
static int COLOR_NORMAL_TEXT
Definition ColorManager.c:5
static int COLOR_DISABLED_TEXT
Definition input.c:11
static map< int, ref array< int > > GetInputActionSortingMap()
Definition InputUtils.c:203
static bool InitInputMetadata()
Definition InputUtils.c:213
static array< int > GetUnsortedInputActions()
Definition InputUtils.c:208
override bool OnMouseEnter(Widget w, int x, int y)
void PerformSetToDefaultsExt(int mode)
ref array< int > m_SetKeybinds
ButtonWidget m_HardReset
void ClearAlternativeKeybind(int key_index)
void AddGroup(int index, Input input)
override bool OnFocus(Widget w, int x, int y)
override void Update(float timeslice)
void StartEnteringAlternateKeybind(int key_index)
override void Refresh()
void Reset()
Undoes the unsaved changes and reverts to previous state. Does not reset to defaults!
bool IsFocusable(Widget w)
ButtonWidget m_Apply
void DeferredDefaultsInit()
deprecated
override bool OnMouseWheel(Widget w, int x, int y, int wheel)
ref OptionSelectorMultistate m_PresetSelector
ref KeybindingsContainer m_GroupsContainer
void ConfirmKeybindEntry(TIntArray new_keys)
void InitPresets(int index, Widget parent, Input input)
KeybindingsContainer GetCurrentTab()
void ColorWhite(Widget w, Widget enterW)
void ClearKeybind(int key_index)
override bool OnFocusLost(Widget w, int x, int y)
override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
void CancelEnteringKeybind()
void ColorRed(Widget w)
ref array< ref KeybindingsGroup > m_Tabs
void OnSelectKBPreset(int index)
void UpdateTabContent(int tab_index)
ButtonWidget m_Defaults
ref DropdownPrefab m_KBDropdown
void StartEnteringKeybind(int key_index)
override Widget Init()
void CreateGroupContainer()
override bool OnClick(Widget w, int x, int y, int button)
override bool OnModalResult(Widget w, int x, int y, int code, int result)
void ConfirmAlternateKeybindEntry(TIntArray new_keys)
void ColorDisabled(Widget w)
void OnAttemptSelectPreset(int index)
void PerformSetToDefaults()
deprecated, resets all (as before ~1.20)
ButtonWidget m_Undo
void CancelEnteringAlternateKeybind()
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
proto native CGame GetGame()
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)
int ARGB(int a, int r, int g, int b)
Definition proto.c:322