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";
12 protected const float FIRST_SEPARATOR_PADDING = 20;
15 protected VerticalLayoutWidget m_wActionsLayout;
16 protected ScrollLayoutWidget m_wActionsScrollLayout;
19 protected ref InputBinding m_Binding;
20 protected static const string PRIMARY_PRESET_PREFIX =
"";
24 protected int m_iLastSelectedRowIndex;
25 protected float m_fLastSliderY;
33 protected ref array<Widget> m_aRowWidgets = {};
34 protected ref array<SCR_InputButtonComponent> m_aRowFooterButtons = {};
37 protected TextWidget m_wDescriptionHeader;
38 protected RichTextWidget m_wDescription;
39 protected Widget m_wDescriptionActionRowsContainer;
40 protected ScrollLayoutWidget m_wDescriptionScroll;
42 protected ref array<Widget> m_aDescriptionActionRows = {};
52 protected const string DESCRIPTION =
"#AR-Settings_Keybind_DetailsPanel_Description";
53 protected const string DESCRIPTION_ADVANCED_BINDINGS =
"#AR-Settings_Keybind_DetailsPanel_Description_AdvancedBindings";
55 protected static const string ACTION_RESET_SINGLE =
"MenuResetKeybind";
56 protected static const string ACTION_RESET_ALL =
"MenuResetAllKeybind";
57 protected static const string ACTION_UNBIND =
"MenuUnbindKeybind";
58 protected static const string ACTION_ADVANCED_KEYBIND =
"MenuAdvancedKeybind";
61 override void OnTabCreate(Widget menuRoot, ResourceName buttonsLayout,
int index)
63 super.OnTabCreate(menuRoot, buttonsLayout,
index);
65 m_wActionsLayout = VerticalLayoutWidget.Cast(
GetRootWidget().FindAnyWidget(
"ActionRowsContent"));
66 if (!m_wActionsLayout)
69 m_wActionsScrollLayout = ScrollLayoutWidget.Cast(
GetRootWidget().FindAnyWidget(
"ActionRowScroll"));
70 if (!m_wActionsScrollLayout)
80 m_wDescriptionHeader = TextWidget.Cast(
GetRootWidget().FindAnyWidget(
"DescriptionHeader"));
81 m_wDescription = RichTextWidget.Cast(
GetRootWidget().FindAnyWidget(
"Description"));
82 m_wDescriptionActionRowsContainer =
GetRootWidget().FindAnyWidget(
"DescriptionActionRows");
83 m_wDescriptionScroll = ScrollLayoutWidget.Cast(
GetRootWidget().FindAnyWidget(
"DescriptionScroll"));
87 m_wDescription.SetVisible(
false);
89 string action =
string.Format(
90 "<action name='%1', scale='%2', state = '%3'/>",
91 ACTION_ADVANCED_KEYBIND,
93 UIConstants.GetActionDisplayStateAttribute(SCR_EActionDisplayState.NON_INTERACTABLE_HINT)
96 m_wDescription.SetText(DESCRIPTION +
"\n" + WidgetManager.Translate(DESCRIPTION_ADVANCED_BINDINGS, action));
100 CreateResetAllKeybindsButton();
101 CreateSimpleBindingButton();
102 CreateUnbindSingleButton();
103 CreateSingleKeybindResetButton();
104 CreateAdvancedBindingButton();
108 if (m_ActionsComponent)
109 m_ActionsComponent.GetOnAction().Insert(OnActionTriggered);
112 Resource holder = BaseContainerTools.LoadContainer(KEY_BINDING_CONFIG);
113 BaseContainer container = holder.GetResource().ToBaseContainer();
115 InsertCategoriesToComboBox();
117 GetGame().OnInputDeviceUserChangedInvoker().Insert(OnInputDeviceChange);
121 override void OnMenuUpdate(
float tDelta)
123 super.OnMenuUpdate(tDelta);
130 override void OnTabShow()
134 ListActionsFromCurrentCategory();
136 m_SelectedRowComponent =
null;
138 if (m_ActionsComponent)
139 m_ActionsComponent.ActivateActions();
145 override void OnTabHide()
149 if (m_CategoriesSpinBox)
151 m_CategoriesSpinBox.SetKeepActionListeners(
false);
152 m_CategoriesSpinBox.RemoveActionListeners();
155 if (m_ActionsComponent)
156 m_ActionsComponent.DeactivateActions();
160 override void OnMenuFocusGained()
162 super.OnMenuFocusGained();
164 if (m_CategoriesSpinBox)
166 m_CategoriesSpinBox.SetKeepActionListeners(
true);
167 m_CategoriesSpinBox.AddActionListeners();
172 override void OnMenuFocusLost()
174 super.OnMenuFocusLost();
176 if (m_CategoriesSpinBox)
178 m_CategoriesSpinBox.SetKeepActionListeners(
false);
179 m_CategoriesSpinBox.RemoveActionListeners();
184 override void OnMenuShow()
189 m_ActionsComponent.ActivateActions();
195 protected void ListActionsFromCurrentCategory()
197 Widget spinBox =
GetRootWidget().FindAnyWidget(
"CategoriesBox");
198 bool firstSeparator =
true;
203 if (!m_CategoriesSpinBox)
208 m_CategoriesSpinBox.SetKeepActionListeners(
true);
209 m_CategoriesSpinBox.AddActionListeners();
216 foreach (Widget row : m_aRowWidgets)
218 row.RemoveFromHierarchy();
221 m_aRowWidgets.Clear();
230 foreach (SCR_KeyBindingEntry entry :
category.m_KeyBindingEntries)
233 if (entry.m_sActionName !=
"separator")
235 rowWidget =
GetGame().GetWorkspace().CreateWidgets(ACTION_ROW_LAYOUT_PATH ,m_wActionsLayout);
239 m_aRowWidgets.Insert(rowWidget);
245 component.Init(m_Binding, entry);
246 component.GetOnFocus().Insert(OnRowFocus);
247 component.GetOnFocusLost().Insert(OnRowFocusLost);
248 component.GetOnKeyCaptured().Insert(OnKeyCaptured);
249 component.GetOnInlineButton().Insert(OnRowInlineButton);
255 rowWidget =
GetGame().GetWorkspace().CreateWidgets(SEPARATOR_LAYOUT_PATH ,m_wActionsLayout);
259 m_aRowWidgets.Insert(rowWidget);
265 separatorText.SetVisible(!entry.m_sDisplayName.IsEmpty());
266 separatorText.SetText(entry.m_sDisplayName);
270 separatorText.ResetTopPadding();
275 keybindTitle = rowWidget.FindAnyWidget(
"Keybind");
279 gamepadTitle = rowWidget.FindAnyWidget(
"Gamepad");
281 gamepadTitle.SetVisible(
true);
283 separatorText.SetTopPadding(FIRST_SEPARATOR_PADDING);
285 firstSeparator =
false;
289 if (m_iLastSelectedRowIndex > 0)
290 GetGame().GetCallqueue().CallLater(UpdateListSelectionDisplay, 100,
false, m_iLastSelectedRowIndex);
292 UpdateListSelectionDisplay(0);
296 protected void UpdateListSelectionDisplay(
int index)
298 GetGame().GetCallqueue().Remove(UpdateListSelectionDisplay);
300 if (!m_wActionsScrollLayout)
305 sliderTarget = m_fLastSliderY;
308 if (!m_aRowWidgets.IsEmpty() && m_aRowWidgets.IsIndexValid(
index))
309 focusTarget = m_aRowWidgets[
index];
311 m_wActionsScrollLayout.SetSliderPos(0, sliderTarget);
314 UpdateFocusedWidget(focusTarget);
318 protected void UpdateFocusedWidget(Widget w)
324 GetGame().GetWorkspace().SetFocusedWidget(w);
325 else if (m_CategoriesSpinBox)
326 GetGame().GetWorkspace().SetFocusedWidget(m_CategoriesSpinBox.GetRootWidget());
330 protected void InsertCategoriesToComboBox()
332 Widget spinBox =
GetRootWidget().FindAnyWidget(
"CategoriesBox");
337 if (!spinBoxComponent)
340 spinBoxComponent.ClearAll();
342 int total = m_KeybindConfig.m_KeyBindingCategories.Count();
344 spinBoxComponent.AddItem(
category.m_sDisplayName, i == total - 1);
346 spinBoxComponent.SetCurrentItem(0);
348 spinBoxComponent.m_OnChanged.Insert(OnComboBoxChange);
352 protected void ResetKeybindsToDefault()
355 dialog.m_OnConfirm.Insert(ResetKeybindsToDefaultConfirm);
359 protected void ResetSingleKeybindToDefault()
361 if (!m_SelectedRowComponent)
364 m_SelectedRowComponent.ResetAction();
368 protected void ResetKeybindsToDefaultConfirm()
370 EInputDeviceType device =
GetGame().GetInputManager().GetLastUsedInputDevice();
373 ListActionsFromCurrentCategory();
379 protected void CreateResetAllKeybindsButton()
381 m_ResetAllButton = CreateNavigationButton(ACTION_RESET_ALL,
"#AR-Settings_Keybind_ResetEveryKeybind",
true);
382 m_ResetAllButton.m_OnActivated.Insert(ResetKeybindsToDefault);
387 protected void CreateSingleKeybindResetButton()
389 m_ResetSingleButton = CreateNavigationButton(ACTION_RESET_SINGLE,
"#AR-Settings_Keybind_ResetAllKeybinds",
true);
390 m_ResetSingleButton.m_OnActivated.Insert(ResetSingleKeybindToDefault);
392 m_aRowFooterButtons.Insert(m_ResetSingleButton);
396 protected void CreateUnbindSingleButton()
398 m_UnbindSingleActionButton = CreateNavigationButton(ACTION_UNBIND,
"#AR-Settings_Keybind_UnbindOne",
true);
399 m_UnbindSingleActionButton.m_OnActivated.Insert(UnbindSingleAction);
400 m_aRowFooterButtons.Insert(m_UnbindSingleActionButton);
405 protected void CreateSimpleBindingButton()
407 m_SimpleBindingButton = CreateNavigationButton(
UIConstants.MENU_ACTION_SELECT,
"#AR-Settings_Keybind_Assign",
true);
408 m_aRowFooterButtons.Insert(m_SimpleBindingButton);
412 protected void CreateAdvancedBindingButton()
414 m_AdvancedBindingButton = CreateNavigationButton(ACTION_ADVANCED_KEYBIND,
"#AR_Settings_KeybindAdvanced_Title",
true);
415 m_AdvancedBindingButton.m_OnActivated.Insert(AdvancedKeybindButtonClick);
416 m_aRowFooterButtons.Insert(m_AdvancedBindingButton);
420 protected void UnbindSingleAction()
422 if (!m_SelectedRowComponent)
425 m_SelectedRowComponent.Unbind();
429 protected void AdvancedKeybindButtonClick()
431 if (!m_SelectedRowComponent)
435 m_SelectedRowComponent.GetEntry(),
436 m_SelectedRowComponent.GetDisplayName(),
437 m_SelectedRowComponent.GetActionName(),
438 PRIMARY_PRESET_PREFIX + m_SelectedRowComponent.GetActionPreset(),
439 m_SelectedRowComponent.GetActionPrefixType()
443 keybindDialog.m_OnCancel.Insert(ListActionsFromCurrentCategory);
447 protected void UpdateButtons()
449 bool consoleController =
GetGame().IsPlatformGameConsole() && !
GetGame().GetHasKeyboard();
450 bool usingMouse =
GetGame().GetInputManager().GetLastUsedInputDevice() == EInputDeviceType.MOUSE;
451 bool usingKeyboard =
GetGame().GetInputManager().GetLastUsedInputDevice() == EInputDeviceType.KEYBOARD;
452 bool show = !usingMouse && m_SelectedRowComponent;
454 if (m_ResetSingleButton)
455 m_ResetSingleButton.SetVisible(
m_bShown && show,
false);
457 if (m_UnbindSingleActionButton)
458 m_UnbindSingleActionButton.SetVisible(
m_bShown && show,
false);
460 if (m_SimpleBindingButton)
461 m_SimpleBindingButton.SetVisible(
m_bShown && show && !m_SelectedRowComponent.GetActionPreset().IsEmpty(),
false);
463 if (m_AdvancedBindingButton)
464 m_AdvancedBindingButton.SetVisible(
m_bShown && show && !consoleController && usingKeyboard,
false);
468 protected void UpdateDescription()
470 if (m_wDescriptionScroll)
471 m_wDescriptionScroll.SetSliderPos(0, 0,
true);
477 if (m_SelectedRowComponent)
479 actionName = m_SelectedRowComponent.GetActionName();
480 actionPreset = m_SelectedRowComponent.GetActionPreset();
483 EInputDeviceType device =
GetGame().GetInputManager().GetLastUsedInputDevice();
484 if (device != EInputDeviceType.GAMEPAD)
485 device = EInputDeviceType.KEYBOARD;
489 if (m_wDescriptionHeader)
490 m_wDescriptionHeader.SetVisible(bindCount > 1);
493 m_wDescription.SetVisible(bindCount > 1);
495 foreach (
int i, Widget widget : m_aDescriptionActionRows)
497 m_aDescriptionActionRows[i].SetVisible(bindCount > 1 && i <= bindCount - 1 && m_SelectedRowComponent !=
null);
501 if (!m_SelectedRowComponent || bindCount <= 1)
504 if (m_wDescriptionHeader)
505 m_wDescriptionHeader.SetText(m_SelectedRowComponent.GetDisplayName());
508 if (!m_wDescriptionActionRowsContainer)
511 for (
int i = 0; i < bindCount; i++)
515 if (!m_aDescriptionActionRows.IsIndexValid(i))
517 row =
GetGame().GetWorkspace().CreateWidgets(DESCRIPTION_ACTION_ROW_LAYOUT_PATH, m_wDescriptionActionRowsContainer);
519 m_aDescriptionActionRows.Insert(row);
522 row = m_aDescriptionActionRows[i];
540 m_SelectedRowComponent = row;
542 Widget root = row.GetRootWidget();
543 if (root && !m_aRowWidgets.IsEmpty())
544 m_iLastSelectedRowIndex = m_aRowWidgets.Find(root);
546 if (m_wActionsScrollLayout)
549 m_wActionsScrollLayout.GetSliderPos(sliderX, m_fLastSliderY);
558 m_SelectedRowComponent =
null;
564 protected void OnRowInlineButton(
string name)
575 protected void OnActionTriggered(
string name,
float multiplier)
579 case ACTION_ADVANCED_KEYBIND: AdvancedKeybindButtonClick();
break;
580 case ACTION_RESET_SINGLE: ResetSingleKeybindToDefault();
break;
581 case ACTION_UNBIND: UnbindSingleAction();
break;
586 protected void OnKeyCaptured()
588 ListActionsFromCurrentCategory();
592 protected void OnComboBoxChange()
595 m_iLastSelectedRowIndex = 0;
596 ListActionsFromCurrentCategory();
600 protected void OnInputDeviceChange(EInputDeviceType oldDevice, EInputDeviceType newDevice)