Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_SettingsManagerKeybindModule.c
Go to the documentation of this file.
1//------------------------------------------------------------------------------------------------
3{
4 protected const string GAMEPAD_PRESET_PREFIX = "gamepad:";
5 protected const string PRIMARY_PRESET_PREFIX = "";
6
7 protected ref InputBinding m_Binding;
8
10
11 // Duplicate configs mayy be found as active preset for multiple combo boxes.
12 // Configs linked must be unique for each list to prevent it.
15
16 protected static const ResourceName KEY_BINDING_CONFIG = "{4EE7794C9A3F11EF}Configs/System/keyBindingMenu.conf";
17 protected static const ResourceName CONTROLLER_PRESETS_CONFIG = "{27780DD27C5E97CF}Configs/System/ControlSchemes/Gamepad/ControllerPresets.conf";
18 protected static const ResourceName JOYSTICK_0_PRESETS_CONFIG = "{2823E147630F55BF}Configs/System/ControlSchemes/Joystick/Joystick0Presets.conf";
19 protected static const ResourceName JOYSTICK_1_PRESETS_CONFIG = "{810AEDDD191484A0}Configs/System/ControlSchemes/Joystick/Joystick1Presets.conf";
20
21 //------------------------------------------------------------------------------------------------
22 // constructor
24 {
28
29 SetModuleType(ESettingManagerModuleType.SETTINGS_MANAGER_KEYBINDING);
30 m_Binding = GetGame().GetInputManager().CreateUserBinding();
31 if (!m_Binding)
32 Print("SCR_SettingsManagerKeybindModule: InputBindings were not created!", LogLevel.WARNING);
33 }
34
35 //------------------------------------------------------------------------------------------------
36 int GetActionBindCount(string actionName, string actionPreset = string.Empty, EInputDeviceType device = EInputDeviceType.KEYBOARD)
37 {
38 if (!m_Binding)
39 return 0;
40
41 return m_Binding.GetBindingsCount(actionName, device, actionPreset);
42 }
43
44 //------------------------------------------------------------------------------------------------
46 {
47 return m_Binding;
48 }
49
50 //------------------------------------------------------------------------------------------------
51 void DeleteActionBindByIndex(string actionName, int keybindIndex, string actionPreset = "", EInputDeviceType device = EInputDeviceType.KEYBOARD)
52 {
53 if (!m_Binding)
54 return;
55
56 if (m_Binding.IsDefault(actionName, device, actionPreset))
57 {
58 // if it is default binding first create user binding
59 m_Binding.CreateUserBinding(actionName, device, actionPreset);
60 m_Binding.Save();
61 }
62
63 m_Binding.RemoveBinding(actionName, device, actionPreset, keybindIndex);
64 m_Binding.Save();
65 }
66
67 //------------------------------------------------------------------------------------------------
68 void StartCaptureForAction(string actionName, string actionPreset, EInputDeviceType device = EInputDeviceType.KEYBOARD, bool append = false)
69 {
70 if (!m_Binding)
71 return;
72
73 m_Binding.StartCapture(actionName, device, actionPreset, append);
74 }
75
76 //------------------------------------------------------------------------------------------------
77 void SetFilterForActionByIndex(string actionName, string actionPreset, int filterIndex, int keybindIndex, SCR_EActionPrefixType prefixType, EInputDeviceType device = EInputDeviceType.KEYBOARD)
78 {
79 if (!m_Binding)
80 return;
81
82 array<ref SCR_KeyBindingFilter> filters = GetFilters(prefixType);
83 if (!filters)
84 return;
85
86 SCR_KeyBindingFilter filter = filters.Get(filterIndex);
87 if (!filter)
88 return;
89
90 if (m_Binding.IsDefault(actionName, device, actionPreset))
91 {
92 // if it is default binding first create user binding
93 m_Binding.CreateUserBinding(actionName, device, actionPreset);
94 m_Binding.Save();
95 }
96
97 m_Binding.SetFilter(actionName, device, actionPreset, keybindIndex, filter.m_sFilterString);
98 m_Binding.Save();
99 }
100
101 //------------------------------------------------------------------------------------------------
102 void AddKeybindToActionByIndex(string actionName, string preset, int bindIndex, string filterName = string.Empty)
103 {
104 if (!m_Binding)
105 return;
106
107 array<ref SCR_KeyBindingBind> binds = GetCustomBinds();
108 if (!binds)
109 return;
110
111 SCR_KeyBindingBind bind = binds.Get(bindIndex);
112 if (!bind)
113 return;
114
115 m_Binding.AddBinding(actionName, preset, bind.m_sBindString, filterName);
116 m_Binding.Save();
117 }
118
119 //------------------------------------------------------------------------------------------------
120 array<ref SCR_KeyBindingFilter> GetFilters(SCR_EActionPrefixType filterType)
121 {
122 if (!m_KeybindConfig)
123 return null;
124
125 array <ref SCR_KeyBindingFilter> foundFilters = {};
126 foreach (SCR_KeyBindingFilter filter : m_KeybindConfig.m_aInputFilters)
127 {
128 if (filterType == SCR_EActionPrefixType.AMBIGUOUS || filter.GetFilterType() == filterType)
129 foundFilters.Insert(filter);
130 }
131
132 return foundFilters;
133 }
134
135 //------------------------------------------------------------------------------------------------
136 array<ref SCR_KeyBindingBind> GetCustomBinds()
137 {
138 if (!m_KeybindConfig)
139 return null;
140
141 return m_KeybindConfig.m_aInputBinds;
142 }
143
144 //------------------------------------------------------------------------------------------------
145 array<ref SCR_KeyBindingCombo> GetCustomComboKeys()
146 {
147 if (!m_KeybindConfig)
148 return null;
149
150 return m_KeybindConfig.m_aComboKeys;
151 }
152
153 //------------------------------------------------------------------------------------------------
155 bool IsActionConflicted(string actionName, notnull out array<SCR_KeyBindingEntry> confirmedConflicts, int bindIndex, string preset = string.Empty)
156 {
157 if (!m_Binding || actionName.IsEmpty())
158 return false;
159
160 confirmedConflicts.Clear();
161
162 array<int> indices = {};
163 array<string> conflicts = {};
164 array<string> presets = {};
165 m_Binding.GetConflicts(actionName, indices, conflicts, presets, EInputDeviceType.KEYBOARD, preset);
166
167 if (conflicts.IsEmpty())
168 return false;
169
170 array<SCR_KeyBindingEntry> foundActions = {};
171
172 //compare the actions against those configures in keybinding config, and save only those, to avoid actions for UI etc
173 foreach (int index, string action : conflicts)
174 {
175 if (indices[index] != bindIndex)
176 continue;
177
178 foreach (SCR_KeyBindingCategory category : m_KeybindConfig.m_KeyBindingCategories)
179 {
180 foreach (SCR_KeyBindingEntry entry : category.m_KeyBindingEntries)
181 {
182 if (entry.m_sActionName == "separator" || entry.m_sActionName != action || entry.m_sPreset != presets[index])
183 continue;
184
185 foundActions.Insert(entry);
186 }
187 }
188 }
189
190 confirmedConflicts.Copy(foundActions);
191
192 return !foundActions.IsEmpty();
193 }
194
195 //------------------------------------------------------------------------------------------------
196 void UnbindAction(string actionName, string preset = "", EInputDeviceType device = EInputDeviceType.KEYBOARD)
197 {
198 m_Binding.StartCapture(actionName, device, preset, false);
199 m_Binding.SaveCapture();
200 m_Binding.Save();
201 //SCR_AnalyticsApplication.GetInstance().ChangeKeybind(actionName, preset);
202 }
203
204 //------------------------------------------------------------------------------------------------
205 void AddComboToActionByIndex(string actionName, string preset, int comboIndex, int keybindIndex, string filterName = string.Empty, int comboPosition = 0)
206 {
207 if (!m_Binding)
208 return;
209
210 array<ref SCR_KeyBindingCombo> combos = GetCustomComboKeys();
211 if (!combos)
212 return;
213
214 SCR_KeyBindingCombo combo = combos.Get(comboIndex);
215 if (!combo)
216 return;
217
218 m_Binding.InsertCombo(actionName, preset, combo.m_sComboString, filterName, keybindIndex, comboPosition);
219 m_Binding.Save();
220 }
221
222 //------------------------------------------------------------------------------------------------
223 void ResetAction(string actionName, string preset = "", EInputDeviceType device = EInputDeviceType.KEYBOARD)
224 {
225 if (!m_Binding)
226 return;
227
228 bool reset;
229 switch (device)
230 {
231 case EInputDeviceType.KEYBOARD:
232 case EInputDeviceType.MOUSE:
233 {
234 if (!m_Binding.IsDefault(actionName, EInputDeviceType.KEYBOARD, preset))
235 {
236 m_Binding.ResetDefault(actionName, EInputDeviceType.KEYBOARD, preset);
237 reset = true;
238 }
239
240 if (!m_Binding.IsDefault(actionName, EInputDeviceType.MOUSE, preset))
241 {
242 m_Binding.ResetDefault(actionName, EInputDeviceType.MOUSE, preset);
243 reset = true;
244 }
245
246 break;
247 }
248 case EInputDeviceType.GAMEPAD:
249 {
250 if (!m_Binding.IsDefault(actionName, EInputDeviceType.GAMEPAD, preset))
251 {
252 m_Binding.ResetDefault(actionName, EInputDeviceType.GAMEPAD, preset);
253 reset = true;
254 }
255
256 break;
257 }
258 }
259
260 if (!reset)
261 return;
262
263 m_Binding.Save();
264 }
265
266 //------------------------------------------------------------------------------------------------
267 void ResetAllActions(EInputDeviceType device = EInputDeviceType.KEYBOARD)
268 {
269 array<string> contexts = {};
270 m_Binding.GetContexts(contexts);
271 string finalPreset;
272 string devicePrefix;
273 string actionName;
274
275 foreach (SCR_KeyBindingCategory category: m_KeybindConfig.m_KeyBindingCategories)
276 {
277 foreach (SCR_KeyBindingEntry entry: category.m_KeyBindingEntries)
278 {
279 if (device == EInputDeviceType.GAMEPAD)
280 devicePrefix = GetGamepadPresetPrefix();
281 else
282 devicePrefix = GetPrimaryPresetPrefix();
283
284 if (device == EInputDeviceType.GAMEPAD && !entry.m_sPresetGamepadOptional.IsEmpty())
285 finalPreset = devicePrefix + entry.m_sPresetGamepadOptional;
286 else if (!entry.m_sPreset.IsEmpty())
287 finalPreset = devicePrefix + entry.m_sPreset;
288
289 if (device == EInputDeviceType.GAMEPAD && !entry.m_sActionNameGamepadOptional.IsEmpty())
290 actionName = entry.m_sActionNameGamepadOptional;
291 else
292 actionName = entry.m_sActionName;
293
294 ResetAction(actionName, finalPreset, device);
295 }
296 }
297
298 m_Binding.Save();
299 //SCR_AnalyticsApplication.GetInstance().ResetAllKeybinds();
300 }
301
302 //------------------------------------------------------------------------------------------------
304 {
306 }
307
308 //------------------------------------------------------------------------------------------------
310 {
312 }
313
314 //------------------------------------------------------------------------------------------------
319 void GetControllerPresets(notnull out array<ref SCR_ControllerPreset> controllerPresets)
320 {
322 controllerPresets = m_ControllerPresetsConfig.GetPresets();
323 else
324 Print("SCR_SettingsManagerKeybindModule: Controller presets not present, check init process!", LogLevel.ERROR);
325 }
326
327 //------------------------------------------------------------------------------------------------
329 //todo: add so this returns presets loaded from profile folder
330 void GetJoystickPresets(notnull out array<ref SCR_ControllerPreset> joystickPresets)
331 {
333 joystickPresets = m_JoystickPresetsConfig.GetPresets();
334 }
335
336 //------------------------------------------------------------------------------------------------
339 void SelectControllerPresets(int presetIndex = -1)
340 {
341 if (!m_Binding)
342 return;
343
344 array<ref SCR_ControllerPreset> controllerPresets = {};
345 GetControllerPresets(controllerPresets);
346
347 //empty preset config means we set it to default
348 array<ResourceName> presets = {};
350 int index;
351
352 // Controller
353 if (controllerPresets.IsIndexValid(presetIndex))
354 index = presetIndex;
355 else
356 index = GetActivePresetIndex(controllerPresets);
357
358 if (controllerPresets.IsIndexValid(index))
359 {
360 preset = controllerPresets.Get(index);
361 if (preset && !preset.GetResourceName().IsEmpty())
362 presets.Insert(preset.GetResourceName());
363 }
364
365 m_Binding.SetCustomConfigs(presets);
366 m_Binding.Save();
367 }
368
369 //------------------------------------------------------------------------------------------------
372 void SelectJoystickPreset(int presetIndex = -1)
373 {
374 if (!m_Binding)
375 return;
376
377 array<ref SCR_ControllerPreset> joystickPresets = {};
378 GetJoystickPresets(joystickPresets);
379
380 //empty preset config means we set it to default
381 array<ResourceName> presets = {};
383 int index;
384
385 // Controller
386 if (joystickPresets.IsIndexValid(presetIndex))
387 index = presetIndex;
388 else
389 index = GetActivePresetIndex(joystickPresets);
390
391 if (joystickPresets.IsIndexValid(index))
392 {
393 preset = joystickPresets.Get(index);
394 if (preset && !preset.GetResourceName().IsEmpty())
395 presets.Insert(preset.GetResourceName());
396 }
397
398 m_Binding.SetCustomConfigs(presets);
399 m_Binding.Save();
400 }
401
402
403 //------------------------------------------------------------------------------------------------
407 {
408 if (!m_Binding)
409 return;
410
411 array<ref SCR_ControllerPreset> joystickPresets = {};
412 GetJoystickPresets(joystickPresets);
413
414 //empty preset config means we set it to default
415 array<ResourceName> presets = {};
416 presets.Insert(path);
417
418 m_Binding.SetCustomConfigs(presets);
419 m_Binding.Save();
420 }
421
422 //------------------------------------------------------------------------------------------------
426 int GetActivePresetIndex(notnull array<ref SCR_ControllerPreset> presets)
427 {
428 if (!m_Binding)
429 return -1;
430
431 array<ResourceName> setPresets = {};
432 m_Binding.GetCustomConfigs(setPresets);
433 foreach (int i, SCR_ControllerPreset preset : presets)
434 {
435 if (setPresets.Contains(preset.GetResourceName()))
436 return i;
437 }
438
439 return -1;
440 }
441}
string path
ArmaReforgerScripted GetGame()
Definition game.c:1398
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
void SetModuleType(ESettingManagerModuleType managerType)
void SCR_SettingsManagerModuleBase()
ESettingManagerModuleType
Manages input key bindings, presets, contexts, and device calibration. Provides functions for creatin...
Controller preset config class.
Controller presets config root.
array< ref SCR_KeyBindingCombo > GetCustomComboKeys()
void ResetAction(string actionName, string preset="", EInputDeviceType device=EInputDeviceType.KEYBOARD)
void SetFilterForActionByIndex(string actionName, string actionPreset, int filterIndex, int keybindIndex, SCR_EActionPrefixType prefixType, EInputDeviceType device=EInputDeviceType.KEYBOARD)
void GetControllerPresets(notnull out array< ref SCR_ControllerPreset > controllerPresets)
ref SCR_ControllerPresetsConfig m_ControllerPresetsConfig
void AddComboToActionByIndex(string actionName, string preset, int comboIndex, int keybindIndex, string filterName=string.Empty, int comboPosition=0)
array< ref SCR_KeyBindingBind > GetCustomBinds()
int GetActionBindCount(string actionName, string actionPreset=string.Empty, EInputDeviceType device=EInputDeviceType.KEYBOARD)
void AddKeybindToActionByIndex(string actionName, string preset, int bindIndex, string filterName=string.Empty)
void DeleteActionBindByIndex(string actionName, int keybindIndex, string actionPreset="", EInputDeviceType device=EInputDeviceType.KEYBOARD)
void ResetAllActions(EInputDeviceType device=EInputDeviceType.KEYBOARD)
bool IsActionConflicted(string actionName, notnull out array< SCR_KeyBindingEntry > confirmedConflicts, int bindIndex, string preset=string.Empty)
returns false if the action has no conflicts (no other action in keybind settings with same bind),...
ref SCR_ControllerPresetsConfig m_JoystickPresetsConfig
array< ref SCR_KeyBindingFilter > GetFilters(SCR_EActionPrefixType filterType)
int GetActivePresetIndex(notnull array< ref SCR_ControllerPreset > presets)
void StartCaptureForAction(string actionName, string actionPreset, EInputDeviceType device=EInputDeviceType.KEYBOARD, bool append=false)
void GetJoystickPresets(notnull out array< ref SCR_ControllerPreset > joystickPresets)
Get all preset lists defined for joysticks.
void UnbindAction(string actionName, string preset="", EInputDeviceType device=EInputDeviceType.KEYBOARD)
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
LogLevel
Enum with severity of the logging message.
Definition LogLevel.c:14