4 protected const string WIDGET_BIND_PC =
"PCBind";
5 protected const string WIDGET_BIND_CONTROLLER =
"ControllerBind";
7 static const string BUTTON_ADVANCED_KEYBIND =
"AdvancedKeybind";
8 static const string BUTTON_RESET =
"Reset";
9 static const string BUTTON_UNBIND =
"Unbind";
11 protected const string ACTION_DISPLAY_ROOT =
"KeybindActionDisplayRow";
13 protected bool m_bFocused;
14 protected bool m_bIsDialogOpen;
16 protected ref InputBinding m_Binding;
17 protected ref SCR_KeyBindingEntry m_Entry;
20 protected string m_sActionName;
21 protected string m_sActionPreset;
22 protected string m_sGamepadAltActionName;
23 protected string m_sGamepadAltActionPreset;
24 protected string m_sActionDisplayName;
26 protected SCR_EActionPrefixType m_eActionPrefixType;
28 protected bool m_bOnInlineMouseButton;
30 protected Widget m_wInlineButtonsWrapper;
32 protected SCR_ModularButtonComponent m_BindButtonKeyboard;
33 protected SCR_ModularButtonComponent m_BindButtonController;
45 override event bool OnFocus(Widget w,
int x,
int y)
48 UpdateInlineButtons();
50 UpdateActionDisplays();
55 return super.OnFocus(w, x, y);
59 override event bool OnFocusLost(Widget w,
int x,
int y)
62 UpdateInlineButtons();
64 UpdateActionDisplays();
69 return super.OnFocusLost(w, x, y);
73 override void HandlerDeattached(Widget w)
75 super.HandlerDeattached(w);
81 void Init(notnull InputBinding binding, SCR_KeyBindingEntry entry)
84 m_sActionDisplayName = entry.m_sDisplayName;
85 if (m_sActionDisplayName.Length() == 0)
86 m_sActionDisplayName =
"<#AR-Settings_Keybind_MissingName>" + entry.m_sActionName;
88 m_sActionPreset = entry.m_sPreset;
90 m_sGamepadAltActionName = entry.m_sActionNameGamepadOptional;
91 m_sGamepadAltActionPreset = entry.m_sPresetGamepadOptional;
94 m_eActionPrefixType = entry.m_ePrefixType;
100 RichTextWidget textBox = RichTextWidget.Cast(
m_wRoot.FindAnyWidget(
"Name"));
101 textBox.SetText(m_sActionDisplayName);
102 textBox.ElideText(1, 1.0,
"...");
106 Widget pcBind =
m_wRoot.FindAnyWidget(WIDGET_BIND_PC);
109 m_BindButtonKeyboard = SCR_ModularButtonComponent.FindComponent(pcBind);
111 if (m_ActionDisplayKeyboard)
112 m_ActionDisplayKeyboard.GetOnAdditionalBindsClicked().Insert(OnAdvancedKeybind);
115 if (m_BindButtonKeyboard)
118 m_BindButtonKeyboard.SetVisible(
false);
120 SetRichTextAction(EInputDeviceType.KEYBOARD);
122 m_BindButtonKeyboard.m_OnClicked.Insert(OnBindKeyboardClicked);
123 m_BindButtonKeyboard.m_OnMouseEnter.Insert(OnInlineMouseButtonEnter);
124 m_BindButtonKeyboard.m_OnMouseLeave.Insert(OnInlineMouseButtonLeave);
128 Widget controllerBind =
m_wRoot.FindAnyWidget(WIDGET_BIND_CONTROLLER);
131 m_BindButtonController = SCR_ModularButtonComponent.FindComponent(controllerBind);
135 if (m_BindButtonController)
137 SetRichTextAction(EInputDeviceType.GAMEPAD);
139 m_BindButtonController.m_OnClicked.Insert(OnBindControllerClicked);
140 m_BindButtonController.m_OnMouseEnter.Insert(OnInlineMouseButtonEnter);
141 m_BindButtonController.m_OnMouseLeave.Insert(OnInlineMouseButtonLeave);
145 SCR_ModularButtonComponent button = SCR_ModularButtonComponent.FindComponent(
m_wRoot);
147 button.m_OnClicked.Insert(OnButtonClick);
150 m_wInlineButtonsWrapper =
m_wRoot.FindAnyWidget(
"InlineButtons");
151 if (m_wInlineButtonsWrapper)
153 array<ref Widget> children = {};
155 SCR_ModularButtonComponent comp;
156 foreach (Widget child : children)
158 comp = SCR_ModularButtonComponent.FindComponent(child);
162 switch (child.GetName())
164 case BUTTON_ADVANCED_KEYBIND: comp.m_OnClicked.Insert(OnAdvancedKeybind);
break;
165 case BUTTON_RESET: comp.m_OnClicked.Insert(OnReset);
break;
166 case BUTTON_UNBIND: comp.m_OnClicked.Insert(OnUnbind);
break;
169 comp.m_OnMouseEnter.Insert(OnInlineMouseButtonEnter);
170 comp.m_OnMouseLeave.Insert(OnInlineMouseButtonLeave);
174 UpdateInlineButtons();
176 UpdateActionDisplays();
178 GetGame().OnInputDeviceUserChangedInvoker().Insert(OnInputDeviceChange);
185 protected void OnButtonClick()
187 EInputDeviceType device =
GetGame().GetInputManager().GetLastUsedInputDevice();
189 if (m_bOnInlineMouseButton && device == EInputDeviceType.MOUSE)
192 if (device == EInputDeviceType.MOUSE || device == EInputDeviceType.KEYBOARD)
195 else if (device == EInputDeviceType.GAMEPAD)
200 protected void CaptureKeyboard()
202 if (m_sActionPreset.IsEmpty())
213 m_sActionDisplayName,
216 EInputDeviceType.KEYBOARD
222 dialog.GetOnKeyCaptured().Insert(OnKeyCaptured);
226 protected void CaptureGamepad()
228 if (m_sActionPreset.IsEmpty() || !m_sGamepadAltActionPreset.IsEmpty())
233 if (m_sGamepadAltActionPreset.IsEmpty())
243 m_sActionDisplayName,
246 EInputDeviceType.GAMEPAD
252 dialog.GetOnKeyCaptured().Insert(OnKeyCaptured);
256 protected void OnInlineMouseButtonEnter(SCR_ModularButtonComponent comp,
bool mouseInput)
258 m_bOnInlineMouseButton =
true;
262 protected void OnInlineMouseButtonLeave(SCR_ModularButtonComponent comp,
bool mouseInput)
264 m_bOnInlineMouseButton =
false;
268 protected void OnBindKeyboardClicked(SCR_ModularButtonComponent comp)
270 if (!comp.GetToggled())
275 protected void OnBindControllerClicked(SCR_ModularButtonComponent comp)
277 if (!comp.GetToggled())
282 protected void OnAdvancedKeybind()
284 if (m_OnInlineButton)
285 m_OnInlineButton.Invoke(BUTTON_ADVANCED_KEYBIND);
289 protected void OnReset()
291 if (m_OnInlineButton)
292 m_OnInlineButton.Invoke(BUTTON_RESET);
296 protected void OnUnbind()
298 if (m_OnInlineButton)
299 m_OnInlineButton.Invoke(BUTTON_UNBIND);
303 protected void OnKeyCaptured()
306 m_OnKeyCaptured.Invoke();
310 protected void OnInputDeviceChange(EInputDeviceType oldDevice, EInputDeviceType newDevice)
312 UpdateInlineButtons();
314 UpdateActionDisplays();
318 protected void OnDialogOpen(
DialogUI dialog)
320 m_bIsDialogOpen =
true;
324 protected void OnDialogClose(
DialogUI dialog)
326 m_bIsDialogOpen =
false;
328 UpdateActionDisplays();
333 protected void SetRichTextAction(EInputDeviceType device)
335 if (device == EInputDeviceType.MOUSE)
336 device = EInputDeviceType.KEYBOARD;
338 if (m_ActionDisplayKeyboard && device != EInputDeviceType.GAMEPAD)
340 else if (m_ActionDisplayController)
345 protected void UpdateActionDisplayScrolling(
bool enable)
347 if (m_ActionDisplayKeyboard)
348 m_ActionDisplayKeyboard.UpdateScrolling(enable);
350 if (m_ActionDisplayController)
351 m_ActionDisplayController.UpdateScrolling(enable);
355 protected void UpdateInlineButtons()
357 bool visible = m_bFocused &&
GetGame().GetInputManager().GetLastUsedInputDevice() == EInputDeviceType.MOUSE;
359 if (m_wInlineButtonsWrapper)
360 m_wInlineButtonsWrapper.SetVisible(visible);
364 protected void UpdateBindButtons()
369 bool isController =
GetGame().GetInputManager().GetLastUsedInputDevice() == EInputDeviceType.GAMEPAD;
370 bool keyboardBindEnabled = !isController && (!
GetGame().IsPlatformGameConsole() ||
GetGame().GetHasKeyboard());
373 if (m_BindButtonKeyboard)
374 m_BindButtonKeyboard.SetToggled(!keyboardBindEnabled || m_sActionPreset.IsEmpty(),
false);
376 if (m_BindButtonController)
377 m_BindButtonController.SetToggled(!isController || m_sActionPreset.IsEmpty(),
false);
381 protected void UpdateActionDisplays()
383 bool isController =
GetGame().GetInputManager().GetLastUsedInputDevice() == EInputDeviceType.GAMEPAD;
384 SCR_EActionDisplayState stateKeyboard = SCR_EActionDisplayState.DEFAULT;
385 SCR_EActionDisplayState stateGamepad = SCR_EActionDisplayState.DEFAULT;
388 stateKeyboard = SCR_EActionDisplayState.DISABLED;
390 stateGamepad = SCR_EActionDisplayState.DISABLED;
392 if (m_ActionDisplayKeyboard)
393 m_ActionDisplayKeyboard.SetAllActionDisplayStates(stateKeyboard);
395 if (m_ActionDisplayController)
396 m_ActionDisplayController.SetAllActionDisplayStates(stateGamepad);
403 EInputDeviceType device =
GetGame().GetInputManager().GetLastUsedInputDevice();
407 SetRichTextAction(device);
408 UpdateActionDisplayScrolling(
false);
414 EInputDeviceType device =
GetGame().GetInputManager().GetLastUsedInputDevice();
417 if (device == EInputDeviceType.MOUSE)
418 device = EInputDeviceType.KEYBOARD;
422 SetRichTextAction(device);
423 UpdateActionDisplayScrolling(
false);
427 SCR_KeyBindingEntry GetEntry()
433 string GetActionName()
439 string GetDisplayName()
441 return m_sActionDisplayName;
445 string GetActionPreset()
447 return m_sActionPreset;
451 string GetFinalActionPreset()
455 EInputDeviceType deviceType =
GetGame().GetInputManager().GetLastUsedInputDevice();
457 if (deviceType == EInputDeviceType.GAMEPAD)
462 if (!m_sActionPreset.IsEmpty())
463 finalPreset = devicePrefix + m_sActionPreset;
469 SCR_EActionPrefixType GetActionPrefixType()
471 return m_eActionPrefixType;
495 if (!m_OnKeyCaptured)
498 return m_OnKeyCaptured;
504 if (!m_OnInlineButton)
507 return m_OnInlineButton;