4 protected const string GAMEPAD_PRESET_PREFIX =
"gamepad:";
5 protected const string PRIMARY_PRESET_PREFIX =
"";
7 protected const string DEVICE_KEYBOARD =
"keyboard";
8 protected const string DEVICE_GAMEPAD =
"gamepad";
10 protected ref InputBinding m_Binding;
14 protected static const string KEY_BINDING_CONFIG =
"{4EE7794C9A3F11EF}Configs/System/keyBindingMenu.conf";
20 Resource holder = BaseContainerTools.LoadContainer(KEY_BINDING_CONFIG);
23 Print(
"SCR_SettingsManagerKeybindModule: Loading of keybinding config failed!", LogLevel.WARNING);
27 BaseContainer container = holder.GetResource().ToBaseContainer();
30 Print(
"SCR_SettingsManagerKeybindModule: Loading of keybinding config failed!", LogLevel.WARNING);
37 Print(
"SCR_SettingsManagerKeybindModule: Loading of keybinding config failed!", LogLevel.WARNING);
42 m_Binding =
GetGame().GetInputManager().CreateUserBinding();
45 Print(
"SCR_SettingsManagerKeybindModule: InputBindings were not created!", LogLevel.WARNING);
51 int GetActionBindCount(
string actionName,
string actionPreset =
string.Empty, EInputDeviceType device = EInputDeviceType.KEYBOARD)
56 return m_Binding.GetBindingsCount(actionName, device, actionPreset);
60 InputBinding GetInputBindings()
66 void DeleteActionBindByIndex(
string actionName,
int keybindIndex,
string actionPreset =
"", EInputDeviceType device = EInputDeviceType.KEYBOARD)
71 if (m_Binding.IsDefault(actionName, device, actionPreset))
74 m_Binding.CreateUserBinding(actionName, device, actionPreset);
78 m_Binding.RemoveBinding(actionName, device, actionPreset, keybindIndex);
83 void StartCaptureForAction(
string actionName,
string actionPreset, EInputDeviceType device = EInputDeviceType.KEYBOARD,
bool append =
false)
88 m_Binding.StartCapture(actionName, device, actionPreset, append);
92 void SetFilterForActionByIndex(
string actionName,
string actionPreset,
int filterIndex,
int keybindIndex, SCR_EActionPrefixType prefixType, EInputDeviceType device = EInputDeviceType.KEYBOARD)
97 array<ref SCR_KeyBindingFilter> filters = GetFilters(prefixType);
105 if (m_Binding.IsDefault(actionName, device, actionPreset))
108 m_Binding.CreateUserBinding(actionName, device, actionPreset);
112 m_Binding.SetFilter(actionName, device, actionPreset, keybindIndex, filter.m_sFilterString);
117 void AddKeybindToActionByIndex(
string actionName,
string preset,
int bindIndex,
string filterName =
string.Empty)
122 array<ref SCR_KeyBindingBind> binds = GetCustomBinds();
126 SCR_KeyBindingBind bind = binds.Get(bindIndex);
130 m_Binding.AddBinding(actionName, preset, bind.m_sBindString, filterName);
135 array<ref SCR_KeyBindingFilter> GetFilters(SCR_EActionPrefixType filterType)
137 if (!m_KeybindConfig)
140 array <ref SCR_KeyBindingFilter> foundFilters = {};
143 if (filter.GetFilterType() == filterType)
144 foundFilters.Insert(filter);
151 array<ref SCR_KeyBindingBind> GetCustomBinds()
153 if (!m_KeybindConfig)
156 return m_KeybindConfig.m_aInputBinds;
160 array<ref SCR_KeyBindingCombo> GetCustomComboKeys()
162 if (!m_KeybindConfig)
165 return m_KeybindConfig.m_aComboKeys;
170 bool IsActionConflicted(
string actionName, notnull out array<SCR_KeyBindingEntry> confirmedConflicts,
int bindIndex,
string preset =
string.Empty)
172 if (!m_Binding || actionName.IsEmpty())
175 confirmedConflicts.Clear();
177 array<int> indices = {};
178 array<string> conflicts = {};
179 array<string> presets = {};
180 m_Binding.GetConflicts(actionName, indices, conflicts, presets, EInputDeviceType.KEYBOARD, preset);
182 if (conflicts.IsEmpty())
185 array<SCR_KeyBindingEntry> foundActions = {};
188 foreach (
int index,
string action : conflicts)
190 if (indices[
index] != bindIndex)
195 foreach (SCR_KeyBindingEntry entry :
category.m_KeyBindingEntries)
197 if (entry.m_sActionName ==
"separator" || entry.m_sActionName != action || entry.m_sPreset != presets[
index])
200 foundActions.Insert(entry);
205 confirmedConflicts.Copy(foundActions);
207 return !foundActions.IsEmpty();
211 void UnbindAction(
string actionName,
string preset =
"", EInputDeviceType device = EInputDeviceType.KEYBOARD)
213 m_Binding.StartCapture(actionName, device, preset,
false);
214 m_Binding.SaveCapture();
219 void AddComboToActionByIndex(
string actionName,
string preset,
int comboIndex,
int keybindIndex,
string filterName =
string.Empty,
int comboPosition = 0)
224 array<ref SCR_KeyBindingCombo> combos = GetCustomComboKeys();
232 m_Binding.InsertCombo(actionName, preset, combo.m_sComboString, filterName, keybindIndex, comboPosition);
237 void ResetAction(
string actionName,
string preset =
"", EInputDeviceType device = EInputDeviceType.KEYBOARD)
245 case EInputDeviceType.KEYBOARD:
246 case EInputDeviceType.MOUSE:
248 if (!m_Binding.IsDefault(actionName, EInputDeviceType.KEYBOARD, preset))
250 m_Binding.ResetDefault(actionName, EInputDeviceType.KEYBOARD, preset);
254 if (!m_Binding.IsDefault(actionName, EInputDeviceType.MOUSE, preset))
256 m_Binding.ResetDefault(actionName, EInputDeviceType.MOUSE, preset);
262 case EInputDeviceType.GAMEPAD:
264 if (!m_Binding.IsDefault(actionName, EInputDeviceType.GAMEPAD, preset))
266 m_Binding.ResetDefault(actionName, EInputDeviceType.GAMEPAD, preset);
281 void ResetAllActions(EInputDeviceType device = EInputDeviceType.KEYBOARD)
283 array<string> contexts = {};
284 m_Binding.GetContexts(contexts);
290 foreach (SCR_KeyBindingEntry entry:
category.m_KeyBindingEntries)
292 if (device == EInputDeviceType.GAMEPAD)
293 devicePrefix = GetGamepadPresetPrefix();
295 devicePrefix = GetPrimaryPresetPrefix();
297 if (!entry.m_sPreset.IsEmpty())
298 finalPreset = devicePrefix + entry.m_sPreset;
300 ResetAction(entry.m_sActionName, finalPreset, device);
307 string GetGamepadPresetPrefix()
309 return GAMEPAD_PRESET_PREFIX;
313 string GetPrimaryPresetPrefix()
315 return PRIMARY_PRESET_PREFIX;
319 string GetKeyboardDeviceString()
321 return DEVICE_KEYBOARD;
325 string GetGamepadDeviceString()
327 return DEVICE_GAMEPAD;