Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_KeybindSettingsSubMenu.c
Go to the documentation of this file.
2{
4
5 // Resources
6 protected static const string ACTION_ROW_LAYOUT_PATH = "{75B1F7B766CA8C91}UI/layouts/Menus/SettingsMenu/BindingMenu/KeybindRow.layout";
7 protected static const string SEPARATOR_LAYOUT_PATH = "{01D9FD7791700ADA}UI/layouts/Menus/SettingsMenu/BindingMenu/KeybindSeparator.layout";
8 protected static const string DESCRIPTION_ACTION_ROW_LAYOUT_PATH = "{929E92CB72FBE8DD}UI/layouts/Menus/SettingsMenu/BindingMenu/KeybindsSettingsDescriptionActionRow.layout";
9 protected static const string KEY_BINDING_CONFIG = "{4EE7794C9A3F11EF}Configs/System/keyBindingMenu.conf";
10
11 // Separator
12 protected const float FIRST_SEPARATOR_PADDING = 20;
13
14 // Widgets
17
18 // Bindings
19 protected ref InputBinding m_Binding;
20 protected static const string PRIMARY_PRESET_PREFIX = "";
21
22 // Rows
25 protected float m_fLastSliderY;
26
32
33 protected ref array<Widget> m_aRowWidgets = {};
34 protected ref array<SCR_InputButtonComponent> m_aRowFooterButtons = {};
35
36 // Description
42
43 protected ref array<Widget> m_aDescriptionActionRows = {};
44
45 // Footer
48
50
51 // Actions
53
54 protected const string DESCRIPTION = "#AR-Settings_Keybind_DetailsPanel_Description";
55 protected const string DESCRIPTION_ADVANCED_BINDINGS = "#AR-Settings_Keybind_DetailsPanel_Description_AdvancedBindings";
56
57 protected static const string ACTION_RESET_SINGLE = "MenuResetKeybind";
58 protected static const string ACTION_RESET_ALL = "MenuResetAllKeybind";
59 protected static const string ACTION_CALIBRATE_MC = "MenuCalibrateMotionControl";
60 protected static const string ACTION_UNBIND = "MenuUnbindKeybind";
61 protected static const string ACTION_ADVANCED_KEYBIND = "MenuAdvancedKeybind";
62
63 //------------------------------------------------------------------------------------------------
64 override void OnTabCreate(Widget menuRoot, ResourceName buttonsLayout, int index)
65 {
66 super.OnTabCreate(menuRoot, buttonsLayout, index);
67
68 m_wActionsLayout = VerticalLayoutWidget.Cast(GetRootWidget().FindAnyWidget("ActionRowsContent"));
70 return;
71
72 m_wActionsScrollLayout = ScrollLayoutWidget.Cast(GetRootWidget().FindAnyWidget("ActionRowScroll"));
74 return;
75
78 return;
79
80 m_Binding = m_SettingsKeybindModule.GetInputBindings();
81
82 // Description
83 m_wDescriptionHeader = TextWidget.Cast(GetRootWidget().FindAnyWidget("DescriptionHeader"));
84 m_wDescription = RichTextWidget.Cast(GetRootWidget().FindAnyWidget("Description"));
85 m_wDescriptionNL = RichTextWidget.Cast(GetRootWidget().FindAnyWidget("DescriptionNL"));
86 m_wDescriptionActionRowsContainer = GetRootWidget().FindAnyWidget("DescriptionActionRows");
87 m_wDescriptionScroll = ScrollLayoutWidget.Cast(GetRootWidget().FindAnyWidget("DescriptionScroll"));
88
90 {
91 m_wDescription.SetVisible(false);
92 m_wDescriptionNL.SetVisible(false);
93 string action = string.Format(
94 "<action name='%1', scale='%2', state = '%3'/>",
96 UIConstants.ACTION_DISPLAY_ICON_SCALE_BIG,
97 UIConstants.GetActionDisplayStateAttribute(SCR_EActionDisplayState.NON_INTERACTABLE_HINT)
98 );
99
101 m_wDescriptionNL.SetTextFormat(DESCRIPTION_ADVANCED_BINDINGS, action);
102 }
103
104 // Footer Buttons
110
111 PlatformService ps = GetGame().GetPlatformService();
112 if (ps && ps.GetLocalPlatformKind() == PlatformKind.PSN)
114
115 // Actions
118 m_ActionsComponent.GetOnAction().Insert(OnActionTriggered);
119
120 // Read the categories and actions from KEY_BINDING_CONFIG
121 Resource holder = BaseContainerTools.LoadContainer(KEY_BINDING_CONFIG);
122 BaseContainer container = holder.GetResource().ToBaseContainer();
123 m_KeybindConfig = SCR_KeyBindingMenuConfig.Cast(BaseContainerTools.CreateInstanceFromContainer(container));
125
126 GetGame().OnInputDeviceUserChangedInvoker().Insert(OnInputDeviceChange);
127 }
128
129 //------------------------------------------------------------------------------------------------
130 override void OnMenuUpdate(float tDelta)
131 {
132 super.OnMenuUpdate(tDelta);
133
134 //TODO: change this to use events insetad of tick
136 }
137
138 //------------------------------------------------------------------------------------------------
139 override void OnTabShow()
140 {
141 super.OnTabShow();
142
144
146
148 m_ActionsComponent.ActivateActions();
149
151 }
152
153 //------------------------------------------------------------------------------------------------
154 override void OnTabHide()
155 {
156 super.OnTabHide();
157
159 {
160 m_CategoriesSpinBox.SetKeepActionListeners(false);
161 m_CategoriesSpinBox.RemoveActionListeners();
162 }
163
165 m_ActionsComponent.DeactivateActions();
166 }
167
168 //------------------------------------------------------------------------------------------------
169 override void OnMenuFocusGained()
170 {
171 super.OnMenuFocusGained();
172
174 {
175 m_CategoriesSpinBox.SetKeepActionListeners(true);
176 m_CategoriesSpinBox.AddActionListeners();
177 }
178 }
179
180 //------------------------------------------------------------------------------------------------
181 override void OnMenuFocusLost()
182 {
183 super.OnMenuFocusLost();
184
186 {
187 m_CategoriesSpinBox.SetKeepActionListeners(false);
188 m_CategoriesSpinBox.RemoveActionListeners();
189 }
190 }
191
192 //------------------------------------------------------------------------------------------------
193 override void OnMenuShow()
194 {
195 super.OnMenuShow();
196
198 m_ActionsComponent.ActivateActions();
199 }
200
201 // --- Protected ---
202 //------------------------------------------------------------------------------------------------
203 // Setup rows
205 {
206 Widget spinBox = GetRootWidget().FindAnyWidget("CategoriesBox");
207 bool firstSeparator = true;
208 if (!spinBox)
209 return;
210
211 m_CategoriesSpinBox = SCR_SpinBoxComponent.Cast(spinBox.GetHandler(0));
213 return;
214
215 // Allow category switching with gamepad from anywere in this menu.
216 // Otherwise the player will need to scroll all the way back to the spin box
217 m_CategoriesSpinBox.SetKeepActionListeners(true);
218 m_CategoriesSpinBox.AddActionListeners();
219
220 SCR_KeyBindingCategory category = m_KeybindConfig.m_KeyBindingCategories.Get(m_CategoriesSpinBox.GetCurrentIndex());
221 if (!category)
222 return;
223
224 // Delete rows
225 foreach (Widget row : m_aRowWidgets)
226 {
227 row.RemoveFromHierarchy();
228 }
229
230 m_aRowWidgets.Clear();
231
232 // Fill the menu
233 Widget rowWidget;
234 SCR_KeybindRowComponent component;
235 SCR_LabelComponent separatorText;
236 Widget keybindTitle;
237 Widget gamepadTitle;
238 EPlatform platform = System.GetPlatform();
239
240 foreach (SCR_KeyBindingEntry entry : category.m_KeyBindingEntries)
241 {
242 // Platform specific actions
243 if (!entry.m_aPlatforms.IsEmpty() && !entry.m_aPlatforms.Contains(platform))
244 continue;
245
246 // Action row
247 if (entry.m_sActionName != "separator")
248 {
249 rowWidget = GetGame().GetWorkspace().CreateWidgets(ACTION_ROW_LAYOUT_PATH ,m_wActionsLayout);
250 if (!rowWidget)
251 continue;
252
253 m_aRowWidgets.Insert(rowWidget);
254
255 component = SCR_KeybindRowComponent.FindComponent(rowWidget);
256 if (!component)
257 continue;
258
259 component.Init(m_Binding, entry);
260 component.GetOnFocus().Insert(OnRowFocus);
261 component.GetOnFocusLost().Insert(OnRowFocusLost);
262 component.GetOnKeyCaptured().Insert(OnKeyCaptured);
263 component.GetOnInlineButton().Insert(OnRowInlineButton);
264
265 continue;
266 }
267
268 // Separator
269 rowWidget = GetGame().GetWorkspace().CreateWidgets(SEPARATOR_LAYOUT_PATH ,m_wActionsLayout);
270 if (!rowWidget)
271 continue;
272
273 m_aRowWidgets.Insert(rowWidget);
274
275 separatorText = SCR_LabelComponent.GetComponent("SettingsTitle", rowWidget);
276 if (!separatorText)
277 continue;
278
279 separatorText.SetVisible(!entry.m_sDisplayName.IsEmpty());
280 separatorText.SetText(entry.m_sDisplayName);
281
282 if (!firstSeparator)
283 {
284 separatorText.ResetTopPadding();
285 continue;
286 }
287
288 // First separator
289 keybindTitle = rowWidget.FindAnyWidget("Keybind");
290 if (keybindTitle)
291 keybindTitle.SetVisible(!GetGame().IsPlatformGameConsole() || GetGame().GetHasKeyboard());
292
293 gamepadTitle = rowWidget.FindAnyWidget("Gamepad");
294 if (gamepadTitle)
295 gamepadTitle.SetVisible(true);
296
298
299 firstSeparator = false;
300 }
301
302 // Delayed position display update, to give enough time for all entries to be initialized
304 GetGame().GetCallqueue().CallLater(UpdateListSelectionDisplay, 100, false, m_iLastSelectedRowIndex);
305 else
307 }
308
309 //------------------------------------------------------------------------------------------------
311 {
312 GetGame().GetCallqueue().Remove(UpdateListSelectionDisplay);
313
315 return;
316
317 float sliderTarget;
318 if (index > 0)
319 sliderTarget = m_fLastSliderY;
320
321 Widget focusTarget;
322 if (!m_aRowWidgets.IsEmpty() && m_aRowWidgets.IsIndexValid(index))
323 focusTarget = m_aRowWidgets[index];
324
325 m_wActionsScrollLayout.SetSliderPos(0, sliderTarget);
326
327 if (GetGame().GetInputManager().GetLastUsedInputDevice() != EInputDeviceType.MOUSE || !focusTarget)
328 UpdateFocusedWidget(focusTarget);
329 }
330
331 //------------------------------------------------------------------------------------------------
332 protected void UpdateFocusedWidget(Widget w)
333 {
334 if (!GetShown())
335 return;
336
337 if (w)
338 GetGame().GetWorkspace().SetFocusedWidget(w);
339 else if (m_CategoriesSpinBox)
340 GetGame().GetWorkspace().SetFocusedWidget(m_CategoriesSpinBox.GetRootWidget());
341 }
342
343 //------------------------------------------------------------------------------------------------
345 {
346 Widget spinBox = GetRootWidget().FindAnyWidget("CategoriesBox");
347 if (!spinBox)
348 return;
349
350 SCR_SpinBoxComponent spinBoxComponent = SCR_SpinBoxComponent.Cast(spinBox.GetHandler(0));
351 if (!spinBoxComponent)
352 return;
353
354 spinBoxComponent.ClearAll();
355
356 int total = m_KeybindConfig.m_KeyBindingCategories.Count();
357 foreach (int i, SCR_KeyBindingCategory category : m_KeybindConfig.m_KeyBindingCategories)
358 spinBoxComponent.AddItem(category.m_sDisplayName, i == total - 1);
359
360 spinBoxComponent.SetCurrentItem(0);
361
362 spinBoxComponent.m_OnChanged.Insert(OnComboBoxChange);
363 }
364
365 //------------------------------------------------------------------------------------------------
371
372 //------------------------------------------------------------------------------------------------
377
378 //------------------------------------------------------------------------------------------------
380 {
382 return;
383
384 m_SelectedRowComponent.ResetAction();
385 }
386
387 //------------------------------------------------------------------------------------------------
389 {
390 EInputDeviceType device = GetGame().GetInputManager().GetLastUsedInputDevice();
391
392 m_SettingsKeybindModule.ResetAllActions(device);
394 }
395
396 // --- Footer buttons ---
397 // -- Global --
398 //------------------------------------------------------------------------------------------------
400 {
401 m_ResetAllButton = CreateNavigationButton(ACTION_RESET_ALL, "#AR-Settings_Keybind_ResetEveryKeybind", true);
402 m_ResetAllButton.m_OnActivated.Insert(ResetKeybindsToDefault);
403 }
404
405 //------------------------------------------------------------------------------------------------
407 {
408 m_CalibrateMCButton = CreateNavigationButton(ACTION_CALIBRATE_MC, "#AR-Settings_Calibrate_Motion_Control", true);
409 m_CalibrateMCButton.m_OnActivated.Insert(CalibrateMotionControl);
410 }
411
412 // -- Row --
413 //------------------------------------------------------------------------------------------------
415 {
416 m_ResetSingleButton = CreateNavigationButton(ACTION_RESET_SINGLE, "#AR-Settings_Keybind_ResetAllKeybinds", true);
418
420 }
421
422 //------------------------------------------------------------------------------------------------
424 {
425 m_UnbindSingleActionButton = CreateNavigationButton(ACTION_UNBIND, "#AR-Settings_Keybind_UnbindOne", true);
428 }
429
430 //------------------------------------------------------------------------------------------------
431 // Visual only Enter button. Interaction is handled by the row buttons themselves
433 {
434 m_SimpleBindingButton = CreateNavigationButton(UIConstants.MENU_ACTION_SELECT, "#AR-Settings_Keybind_Assign", true);
436 }
437
438 //------------------------------------------------------------------------------------------------
440 {
441 m_AdvancedBindingButton = CreateNavigationButton(ACTION_ADVANCED_KEYBIND, "#AR_Settings_KeybindAdvanced_Title", true);
444 }
445
446 //------------------------------------------------------------------------------------------------
447 protected void UnbindSingleAction()
448 {
450 return;
451
452 m_SelectedRowComponent.Unbind();
453 }
454
455 //------------------------------------------------------------------------------------------------
457 {
459 return;
460
462 m_SelectedRowComponent.GetEntry(),
463 m_SelectedRowComponent.GetDisplayName(),
464 m_SelectedRowComponent.GetActionName(),
466 m_SelectedRowComponent.GetActionPrefixType()
467 );
468
469 if (keybindDialog)
470 keybindDialog.m_OnCancel.Insert(ListActionsFromCurrentCategory);
471 }
472
473 //------------------------------------------------------------------------------------------------
474 protected void UpdateButtons()
475 {
476 bool consoleController = GetGame().IsPlatformGameConsole() && !GetGame().GetHasKeyboard();
477 bool usingMouse = GetGame().GetInputManager().GetLastUsedInputDevice() == EInputDeviceType.MOUSE;
478 bool usingKeyboard = GetGame().GetInputManager().GetLastUsedInputDevice() == EInputDeviceType.KEYBOARD;
479 bool show = !usingMouse && m_SelectedRowComponent;
480
482 m_ResetSingleButton.SetVisible(m_bShown && show, false);
483
485 m_UnbindSingleActionButton.SetVisible(m_bShown && show, false);
486
488 m_SimpleBindingButton.SetVisible(m_bShown && show && !m_SelectedRowComponent.GetActionPreset().IsEmpty(), false);
489
491 m_AdvancedBindingButton.SetVisible(m_bShown && show && !consoleController && usingKeyboard, false);
492 }
493
494 //------------------------------------------------------------------------------------------------
495 protected void UpdateDescription()
496 {
498 m_wDescriptionScroll.SetSliderPos(0, 0);
499
500 // --- Update Visibility ---
501 string actionName;
502 string actionPreset;
503
505 {
506 actionName = m_SelectedRowComponent.GetActionName();
507 actionPreset = m_SelectedRowComponent.GetActionPreset();
508 }
509
510 EInputDeviceType device = GetGame().GetInputManager().GetLastUsedInputDevice();
511 if (device != EInputDeviceType.GAMEPAD)
512 device = EInputDeviceType.KEYBOARD;
513
514 int bindCount = m_SettingsKeybindModule.GetActionBindCount(actionName, actionPreset, device);
515
517 m_wDescriptionHeader.SetVisible(bindCount > 1);
518
520 {
521 m_wDescription.SetVisible(bindCount > 1);
522 m_wDescriptionNL.SetVisible(bindCount > 1);
523 }
524
525 foreach (int i, Widget widget : m_aDescriptionActionRows)
526 {
527 m_aDescriptionActionRows[i].SetVisible(bindCount > 1 && i <= bindCount - 1 && m_SelectedRowComponent != null);
528 }
529
530 // --- Update contents ---
531 if (!m_SelectedRowComponent || bindCount <= 1)
532 return;
533
535 m_wDescriptionHeader.SetText(m_SelectedRowComponent.GetDisplayName());
536
537 // Create or update necessary rows (we don't want to keep destroying and recreating them, so we add new ones only if necessary)
539 return;
540
541 for (int i = 0; i < bindCount; i++)
542 {
543 Widget row;
544
545 if (!m_aDescriptionActionRows.IsIndexValid(i))
546 {
548 if (row)
549 m_aDescriptionActionRows.Insert(row);
550 }
551 else
553
554 if (!row)
555 continue;
556
558 if (comp)
559 comp.Init(actionName, actionPreset, i, m_SettingsKeybindModule, device);
560 }
561 }
562
563 //------------------------------------------------------------------------------------------------
564 protected void OnRowFocus(SCR_ScriptedWidgetComponent component)
565 {
567 if (!row)
568 return;
569
571
572 Widget root = row.GetRootWidget();
573 if (root && !m_aRowWidgets.IsEmpty())
575
577 {
578 float sliderX;
579 m_wActionsScrollLayout.GetSliderPos(sliderX, m_fLastSliderY);
580 }
581
583 }
584
585 //------------------------------------------------------------------------------------------------
587 {
589
591 }
592
593 //------------------------------------------------------------------------------------------------
594 protected void OnRowInlineButton(string name)
595 {
596 switch (name)
597 {
601 }
602 }
603
604 //------------------------------------------------------------------------------------------------
605 protected void OnActionTriggered(string name, float multiplier)
606 {
607 switch (name)
608 {
611 case ACTION_UNBIND: UnbindSingleAction(); break;
612 }
613 }
614
615 //------------------------------------------------------------------------------------------------
616 protected void OnKeyCaptured()
617 {
619 }
620
621 //------------------------------------------------------------------------------------------------
622 protected void OnComboBoxChange()
623 {
624 // Bring focus and slider back to top
627 }
628
629 //------------------------------------------------------------------------------------------------
630 protected void OnInputDeviceChange(EInputDeviceType oldDevice, EInputDeviceType newDevice)
631 {
633 }
634}
bool GetHasKeyboard()
Definition game.c:210
SCR_SettingsManager GetSettingsManager()
Definition game.c:190
bool IsPlatformGameConsole()
Definition game.c:1357
ArmaReforgerScripted GetGame()
Definition game.c:1398
PlatformKind
Definition PlatformKind.c:8
InputManager GetInputManager()
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
ESettingManagerModuleType
Manages input key bindings, presets, contexts, and device calibration. Provides functions for creatin...
Object holding reference to resource. In destructor release the resource.
Definition Resource.c:25
static SCR_AdvancedActionRowComponent FindComponentInHierarchy(notnull Widget w)
void Init(string actionName, string actionPreset, int index, SCR_SettingsManagerKeybindModule settingsKeybindModule, EInputDeviceType device)
static SCR_ConfigurableDialogUi CreateKeybindsResetDialog()
static SCR_AdvancedKeybindDialogUI CreateAdvancedKeybindDialog(SCR_KeyBindingEntry entry, string displayName, string actionName, string actionPreset, SCR_EActionPrefixType prefixType)
static const string BUTTON_RESET
ScriptInvokerString GetOnInlineButton()
ScriptInvokerVoid GetOnKeyCaptured()
static const string BUTTON_ADVANCED_KEYBIND
ScriptInvokerScriptedWidgetComponent GetOnFocusLost()
static SCR_KeybindRowComponent FindComponent(Widget w)
ScriptInvokerScriptedWidgetComponent GetOnFocus()
static const string BUTTON_UNBIND
void Init(notnull InputBinding binding, SCR_KeyBindingEntry entry)
SCR_InputButtonComponent m_ResetSingleButton
static const string ACTION_ROW_LAYOUT_PATH
ScrollLayoutWidget m_wActionsScrollLayout
ScrollLayoutWidget m_wDescriptionScroll
SCR_SpinBoxComponent m_CategoriesSpinBox
void OnRowFocusLost(SCR_ScriptedWidgetComponent component)
override void OnMenuUpdate(float tDelta)
void OnRowFocus(SCR_ScriptedWidgetComponent component)
ref array< SCR_InputButtonComponent > m_aRowFooterButtons
ref array< Widget > m_aRowWidgets
SCR_KeybindRowComponent m_SelectedRowComponent
static const string SEPARATOR_LAYOUT_PATH
SCR_SettingsManagerKeybindModule m_SettingsKeybindModule
static const string KEY_BINDING_CONFIG
ref SCR_KeyBindingMenuConfig m_KeybindConfig
SCR_MenuActionsComponent m_ActionsComponent
SCR_InputButtonComponent m_CalibrateMCButton
SCR_InputButtonComponent m_ResetAllButton
VerticalLayoutWidget m_wActionsLayout
void OnInputDeviceChange(EInputDeviceType oldDevice, EInputDeviceType newDevice)
static const string ACTION_RESET_ALL
override void OnTabCreate(Widget menuRoot, ResourceName buttonsLayout, int index)
static const string ACTION_CALIBRATE_MC
static const string ACTION_RESET_SINGLE
static const string PRIMARY_PRESET_PREFIX
void UpdateListSelectionDisplay(int index)
SCR_InputButtonComponent m_SimpleBindingButton
void OnActionTriggered(string name, float multiplier)
static const string ACTION_UNBIND
SCR_InputButtonComponent m_AdvancedBindingButton
SCR_InputButtonComponent m_UnbindSingleActionButton
ref array< Widget > m_aDescriptionActionRows
static const string DESCRIPTION_ACTION_ROW_LAYOUT_PATH
static const string ACTION_ADVANCED_KEYBIND
void OnRowInlineButton(string name)
void SetText(string text)
void SetVisible(bool visible)
static SCR_LabelComponent GetComponent(string name, Widget parent, bool searchAllChildren=true)
void SetTopPadding(float padding)
static SCR_MenuActionsComponent FindComponent(Widget w)
override bool SetCurrentItem(int i, bool playSound=false, bool animate=false)
override int AddItem(string item, bool last=false, Managed data=null)
SCR_InputButtonComponent CreateNavigationButton(string actionName, string label, bool rightFooter=false, bool show=true)
EPlatform
Definition EPlatform.c:13