Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_KeybindRowComponent.c
Go to the documentation of this file.
1//------------------------------------------------------------------------------------------------
3{
4 protected const string WIDGET_BIND_PC = "PCBind";
5 protected const string WIDGET_BIND_CONTROLLER = "ControllerBind";
6
7 static const string BUTTON_ADVANCED_KEYBIND = "AdvancedKeybind";
8 static const string BUTTON_RESET = "Reset";
9 static const string BUTTON_UNBIND = "Unbind";
10
11 protected const string ACTION_DISPLAY_ROOT = "KeybindActionDisplayRow";
12
13 protected bool m_bFocused;
14 protected bool m_bIsDialogOpen;
15
16 protected ref InputBinding m_Binding;
17 protected ref SCR_KeyBindingEntry m_Entry;
19
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;
25
26 protected SCR_EActionPrefixType m_eActionPrefixType;
27
28 protected bool m_bOnInlineMouseButton;
29
31
32 protected SCR_ModularButtonComponent m_BindButtonKeyboard;
33 protected SCR_ModularButtonComponent m_BindButtonController;
34
37
40
43
44 //------------------------------------------------------------------------------------------------
45 override event bool OnFocus(Widget w, int x, int y)
46 {
47 m_bFocused = true;
51
52 if (m_OnFocus)
53 m_OnFocus.Invoke(this);
54
55 return super.OnFocus(w, x, y);
56 }
57
58 //------------------------------------------------------------------------------------------------
59 override event bool OnFocusLost(Widget w, int x, int y)
60 {
61 m_bFocused = false;
65
66 if (m_OnFocusLost)
67 m_OnFocusLost.Invoke(this);
68
69 return super.OnFocusLost(w, x, y);
70 }
71
72 //------------------------------------------------------------------------------------------------
73 override void HandlerDeattached(Widget w)
74 {
75 super.HandlerDeattached(w);
77 }
78
79 // Init
80 //------------------------------------------------------------------------------------------------
81 void Init(notnull InputBinding binding, SCR_KeyBindingEntry entry)
82 {
83 // Setup
84 m_sActionDisplayName = entry.m_sDisplayName;
85 if (m_sActionDisplayName.Length() == 0)
86 m_sActionDisplayName = "<#AR-Settings_Keybind_MissingName>" + entry.m_sActionName;
87
88 m_sActionPreset = entry.m_sPreset;
89 m_sActionName = entry.m_sActionName;
90 m_sGamepadAltActionName = entry.m_sActionNameGamepadOptional;
91 m_sGamepadAltActionPreset = entry.m_sPresetGamepadOptional;
92 m_Binding = binding;
93 m_Entry = entry;
94 m_eActionPrefixType = entry.m_ePrefixType;
95
98 return;
99
100 RichTextWidget textBox = RichTextWidget.Cast(m_wRoot.FindAnyWidget("Name"));
101 textBox.SetText(m_sActionDisplayName);
102 textBox.ElideText(1, 1.0, "...");
103
104 // Bindings buttons
105 // Keyboard
106 Widget pcBind = m_wRoot.FindAnyWidget(WIDGET_BIND_PC);
107 if (pcBind)
108 {
109 m_BindButtonKeyboard = SCR_ModularButtonComponent.FindComponent(pcBind);
112 m_ActionDisplayKeyboard.GetOnAdditionalBindsClicked().Insert(OnAdvancedKeybind);
113 }
114
116 {
118 m_BindButtonKeyboard.SetVisible(false);
119 else
120 SetRichTextAction(EInputDeviceType.KEYBOARD);
121
123 m_BindButtonKeyboard.m_OnMouseEnter.Insert(OnInlineMouseButtonEnter);
124 m_BindButtonKeyboard.m_OnMouseLeave.Insert(OnInlineMouseButtonLeave);
125 }
126
127 // Controller
128 Widget controllerBind = m_wRoot.FindAnyWidget(WIDGET_BIND_CONTROLLER);
129 if (controllerBind)
130 {
131 m_BindButtonController = SCR_ModularButtonComponent.FindComponent(controllerBind);
133 }
134
136 {
137 SetRichTextAction(EInputDeviceType.GAMEPAD);
138
142 }
143
144 // Main button
145 SCR_ModularButtonComponent button = SCR_ModularButtonComponent.FindComponent(m_wRoot);
146 if (button)
147 button.m_OnClicked.Insert(OnButtonClick);
148
149 // Inline buttons
150 m_wInlineButtonsWrapper = m_wRoot.FindAnyWidget("InlineButtons");
152 {
153 array<ref Widget> children = {};
154 SCR_WidgetHelper.GetAllChildren(m_wInlineButtonsWrapper, children);
155 SCR_ModularButtonComponent comp;
156 foreach (Widget child : children)
157 {
158 comp = SCR_ModularButtonComponent.FindComponent(child);
159 if (!comp)
160 continue;
161
162 switch (child.GetName())
163 {
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;
167 }
168
169 comp.m_OnMouseEnter.Insert(OnInlineMouseButtonEnter);
170 comp.m_OnMouseLeave.Insert(OnInlineMouseButtonLeave);
171 }
172 }
173
177
178 GetGame().OnInputDeviceUserChangedInvoker().Insert(OnInputDeviceChange);
181 }
182
183 // Protected
184 //------------------------------------------------------------------------------------------------
185 protected void OnButtonClick()
186 {
187 EInputDeviceType device = GetGame().GetInputManager().GetLastUsedInputDevice();
188
189 if (m_bOnInlineMouseButton && device == EInputDeviceType.MOUSE)
190 return;
191
192 if (device == EInputDeviceType.MOUSE || device == EInputDeviceType.KEYBOARD)
194
195 else if (device == EInputDeviceType.GAMEPAD)
197 }
198
199 //------------------------------------------------------------------------------------------------
200 protected void CaptureKeyboard()
201 {
202 if (m_sActionPreset.IsEmpty())
203 return;
204
205 string finalPreset = m_SettingsKeybindModule.GetPrimaryPresetPrefix() + m_sActionPreset;
206
207 // Enfusion supports capturing mouse and keyboard at once under the EInputDeviceType.KEYBOARD
208 m_SettingsKeybindModule.StartCaptureForAction(m_sActionName, finalPreset, EInputDeviceType.KEYBOARD, false);
209
210 // Dialog
212 m_Entry,
215 m_Binding,
216 EInputDeviceType.KEYBOARD
217 );
218
219 if (!dialog)
220 return;
221
222 dialog.GetOnKeyCaptured().Insert(OnKeyCaptured);
223 }
224
225 //------------------------------------------------------------------------------------------------
226 protected void CaptureGamepad()
227 {
228 if (m_sActionPreset.IsEmpty() && m_sGamepadAltActionPreset.IsEmpty())
229 return;
230
231 string finalPreset;
232
233 if (m_sGamepadAltActionPreset.IsEmpty())
234 finalPreset = m_SettingsKeybindModule.GetGamepadPresetPrefix() + m_sActionPreset;
235 else
236 finalPreset = m_SettingsKeybindModule.GetGamepadPresetPrefix() + m_sGamepadAltActionPreset;
237
238 string actionName = m_sActionName;
239 if (!m_sGamepadAltActionName.IsEmpty())
240 actionName = m_sGamepadAltActionName;
241
242 m_SettingsKeybindModule.StartCaptureForAction(actionName, finalPreset, EInputDeviceType.GAMEPAD, false);
243
244 // Dialog
246 m_Entry,
248 actionName,
249 m_Binding,
250 EInputDeviceType.GAMEPAD
251 );
252
253 if (!dialog)
254 return;
255
256 dialog.GetOnKeyCaptured().Insert(OnKeyCaptured);
257 }
258
259 //------------------------------------------------------------------------------------------------
260 protected void OnInlineMouseButtonEnter(SCR_ModularButtonComponent comp, bool mouseInput)
261 {
263 }
264
265 //------------------------------------------------------------------------------------------------
266 protected void OnInlineMouseButtonLeave(SCR_ModularButtonComponent comp, bool mouseInput)
267 {
269 }
270
271 //------------------------------------------------------------------------------------------------
272 protected void OnBindKeyboardClicked(SCR_ModularButtonComponent comp)
273 {
274 if (!comp.GetToggled())
276 }
277
278 //------------------------------------------------------------------------------------------------
279 protected void OnBindControllerClicked(SCR_ModularButtonComponent comp)
280 {
281 if (!comp.GetToggled())
283 }
284
285 //------------------------------------------------------------------------------------------------
286 protected void OnAdvancedKeybind()
287 {
290 }
291
292 //------------------------------------------------------------------------------------------------
293 protected void OnReset()
294 {
297 }
298
299 //------------------------------------------------------------------------------------------------
300 protected void OnUnbind()
301 {
304 }
305
306 //------------------------------------------------------------------------------------------------
307 protected void OnKeyCaptured()
308 {
309 if (m_OnKeyCaptured)
310 m_OnKeyCaptured.Invoke();
311 }
312
313 //------------------------------------------------------------------------------------------------
314 protected void OnInputDeviceChange(EInputDeviceType oldDevice, EInputDeviceType newDevice)
315 {
319 }
320
321 //------------------------------------------------------------------------------------------------
322 protected void OnDialogOpen(DialogUI dialog)
323 {
324 m_bIsDialogOpen = true;
325 }
326
327 //------------------------------------------------------------------------------------------------
328 protected void OnDialogClose(DialogUI dialog)
329 {
330 m_bIsDialogOpen = false;
333 }
334
335 //------------------------------------------------------------------------------------------------
336 // Currently supports either KEYBOARD or GAMEPAD
337 protected void SetRichTextAction(EInputDeviceType device)
338 {
339 if (device == EInputDeviceType.MOUSE)
340 device = EInputDeviceType.KEYBOARD;
341
342 if (m_ActionDisplayKeyboard && device != EInputDeviceType.GAMEPAD)
343 m_ActionDisplayKeyboard.CreateActionDisplays(m_Entry, m_SettingsKeybindModule, device);
345 m_ActionDisplayController.CreateActionDisplays(m_Entry, m_SettingsKeybindModule, device);
346 }
347
348 //------------------------------------------------------------------------------------------------
349 protected void UpdateActionDisplayScrolling(bool enable)
350 {
352 m_ActionDisplayKeyboard.UpdateScrolling(enable);
353
355 m_ActionDisplayController.UpdateScrolling(enable);
356 }
357
358 //------------------------------------------------------------------------------------------------
359 protected void UpdateInlineButtons()
360 {
361 bool visible = m_bFocused && GetGame().GetInputManager().GetLastUsedInputDevice() == EInputDeviceType.MOUSE;
362
364 m_wInlineButtonsWrapper.SetVisible(visible);
365 }
366
367 //------------------------------------------------------------------------------------------------
368 protected void UpdateBindButtons()
369 {
370 if (m_bIsDialogOpen)
371 return;
372
373 bool isController = GetGame().GetInputManager().GetLastUsedInputDevice() == EInputDeviceType.GAMEPAD;
374 bool keyboardBindEnabled = !isController && (!GetGame().IsPlatformGameConsole() || GetGame().GetHasKeyboard());
375
376 // Toggling is used as an alternative to disabling, so that they may still react to mouse inputs
378 m_BindButtonKeyboard.SetToggled(!keyboardBindEnabled || m_sActionPreset.IsEmpty(), false);
379
381 m_BindButtonController.SetToggled(!isController || m_sActionPreset.IsEmpty(), false);
382 }
383
384 //------------------------------------------------------------------------------------------------
385 protected void UpdateActionDisplays()
386 {
387 bool isController = GetGame().GetInputManager().GetLastUsedInputDevice() == EInputDeviceType.GAMEPAD;
388 SCR_EActionDisplayState stateKeyboard = SCR_EActionDisplayState.DEFAULT;
389 SCR_EActionDisplayState stateGamepad = SCR_EActionDisplayState.DEFAULT;
390
391 if (isController)
392 stateKeyboard = SCR_EActionDisplayState.DISABLED;
393 else
394 stateGamepad = SCR_EActionDisplayState.DISABLED;
395
397 m_ActionDisplayKeyboard.SetAllActionDisplayStates(stateKeyboard);
398
400 m_ActionDisplayController.SetAllActionDisplayStates(stateGamepad);
401 }
402
403 // Public
404 //------------------------------------------------------------------------------------------------
406 {
407 EInputDeviceType device = GetGame().GetInputManager().GetLastUsedInputDevice();
408
409 string actionName = m_sActionName;
410 if (device == EInputDeviceType.GAMEPAD && !m_sGamepadAltActionName.IsEmpty())
411 actionName = m_sGamepadAltActionName;
412
413 m_SettingsKeybindModule.ResetAction(actionName, GetFinalActionPreset(), device);
414
415 SetRichTextAction(device);
417
418 //SCR_AnalyticsApplication.GetInstance().ChangeKeybind(m_sActionName, m_sActionPreset);
419 }
420
421 //------------------------------------------------------------------------------------------------
422 void Unbind()
423 {
424 EInputDeviceType device = GetGame().GetInputManager().GetLastUsedInputDevice();
425
426 // KEYBOARD is also used for mouse
427 if (device == EInputDeviceType.MOUSE)
428 device = EInputDeviceType.KEYBOARD;
429
430 string actionName = m_sActionName;
431 if (device == EInputDeviceType.GAMEPAD && !m_sGamepadAltActionName.IsEmpty())
432 actionName = m_sGamepadAltActionName;
433
434 m_SettingsKeybindModule.UnbindAction(actionName, GetFinalActionPreset(), device);
435
436 SetRichTextAction(device);
438 }
439
440 //------------------------------------------------------------------------------------------------
441 SCR_KeyBindingEntry GetEntry()
442 {
443 return m_Entry;
444 }
445
446 //------------------------------------------------------------------------------------------------
448 {
449 return m_sActionName;
450 }
451
452 //------------------------------------------------------------------------------------------------
454 {
456 }
457
458 //------------------------------------------------------------------------------------------------
460 {
461 return m_sActionPreset;
462 }
463
464 //------------------------------------------------------------------------------------------------
466 {
467 string finalPreset;
468 string devicePrefix;
469 EInputDeviceType deviceType = GetGame().GetInputManager().GetLastUsedInputDevice();
470
471 if (deviceType == EInputDeviceType.GAMEPAD)
472 devicePrefix = m_SettingsKeybindModule.GetGamepadPresetPrefix();
473 else
474 devicePrefix = m_SettingsKeybindModule.GetPrimaryPresetPrefix();
475
476 if (deviceType == EInputDeviceType.GAMEPAD && !m_sGamepadAltActionPreset.IsEmpty())
477 finalPreset = devicePrefix + m_sGamepadAltActionPreset;
478 else if (!m_sActionPreset.IsEmpty())
479 finalPreset = devicePrefix + m_sActionPreset;
480
481 return finalPreset;
482 }
483
484 //------------------------------------------------------------------------------------------------
485 SCR_EActionPrefixType GetActionPrefixType()
486 {
487 return m_eActionPrefixType;
488 }
489
490 //------------------------------------------------------------------------------------------------
498
499 //------------------------------------------------------------------------------------------------
507
508 //------------------------------------------------------------------------------------------------
516
517 //------------------------------------------------------------------------------------------------
525
526 //------------------------------------------------------------------------------------------------
531}
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
ScriptInvokerBase< ScriptInvokerVoidMethod > ScriptInvokerVoid
ScriptInvokerBase< ScriptInvokerStringMethod > ScriptInvokerString
ScriptInvokerBase< ScriptInvokerScriptedWidgetComponentMethod > ScriptInvokerScriptedWidgetComponent
ESettingManagerModuleType
Manages input key bindings, presets, contexts, and device calibration. Provides functions for creatin...
static SCR_KeybindActionDisplayRowComponent FindComponentInHierarchy(notnull Widget w)
static SCR_SimpleKeybindDialogUI CreateSimpleKeybindDialog(SCR_KeyBindingEntry entry, string displayName, string actionName, InputBinding binding, EInputDeviceType device, bool showOverrideWarning=true)
void UpdateActionDisplayScrolling(bool enable)
static const string BUTTON_RESET
override event bool OnFocusLost(Widget w, int x, int y)
ScriptInvokerString GetOnInlineButton()
ScriptInvokerVoid GetOnKeyCaptured()
ref ScriptInvokerVoid m_OnKeyCaptured
static const string BUTTON_ADVANCED_KEYBIND
ScriptInvokerScriptedWidgetComponent GetOnFocusLost()
void OnDialogClose(DialogUI dialog)
override void HandlerDeattached(Widget w)
static SCR_KeybindRowComponent FindComponent(Widget w)
void OnInlineMouseButtonEnter(SCR_ModularButtonComponent comp, bool mouseInput)
SCR_KeybindActionDisplayRowComponent m_ActionDisplayKeyboard
ScriptInvokerScriptedWidgetComponent GetOnFocus()
SCR_ModularButtonComponent m_BindButtonKeyboard
SCR_EActionPrefixType GetActionPrefixType()
SCR_SettingsManagerKeybindModule m_SettingsKeybindModule
override event bool OnFocus(Widget w, int x, int y)
ref ScriptInvokerScriptedWidgetComponent m_OnFocusLost
void OnInputDeviceChange(EInputDeviceType oldDevice, EInputDeviceType newDevice)
void OnInlineMouseButtonLeave(SCR_ModularButtonComponent comp, bool mouseInput)
SCR_KeybindActionDisplayRowComponent m_ActionDisplayController
ref SCR_KeyBindingEntry m_Entry
SCR_ModularButtonComponent m_BindButtonController
void SetRichTextAction(EInputDeviceType device)
static const string BUTTON_UNBIND
void OnBindKeyboardClicked(SCR_ModularButtonComponent comp)
void OnBindControllerClicked(SCR_ModularButtonComponent comp)
void OnDialogOpen(DialogUI dialog)
SCR_EActionPrefixType m_eActionPrefixType
ref ScriptInvokerString m_OnInlineButton
ref ScriptInvokerScriptedWidgetComponent m_OnFocus
void Init(notnull InputBinding binding, SCR_KeyBindingEntry entry)
static ScriptInvokerDialog GetOnDialogOpen()
static ScriptInvokerDialog GetOnDialogClose()