Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_InputButtonComponent.c
Go to the documentation of this file.
2{
3
4//---- REFACTOR NOTE START: This code will need to be refactored as current implementation is not conforming to the standards ----
5// Very bloated class, with a lot of functionality mixed with looks, and too many useless methods and attributes inherited from the parent.
6
7 [Attribute("1", desc: "If enabled, buttons won't show the Text/Image to display the required input")]
8 protected bool m_bKeybindActive;
9
10 [Attribute("MenuTabLeft", desc: "Name of action from chimeraInputCommon")]
11 protected string m_sActionName;
12
13 [Attribute("Navigation Button")]
14 protected string m_sLabel;
15
16 [Attribute("0")]
17 protected bool m_bIsMouseInput;
18
19 [Attribute("2", desc: "Amount of keybinds for one action we display to prevent displaying 100 alternatives for one action")]
20 protected int m_iMaxShownKeys;
21
22 [Attribute(defvalue: "32", desc: "Define the Height in PX. Wight will be adjusted automatically")]
24
25 [Attribute(UIColors.GetColorAttribute(UIColors.CONTRAST_COLOR), UIWidgets.ColorPicker)]
27
28 [Attribute(UIColors.GetColorAttribute(UIColors.HIGHLIGHTED), UIWidgets.ColorPicker)]
30
31 [Attribute(UIColors.GetColorAttribute(UIColors.IDLE_DISABLED), UIWidgets.ColorPicker)]
33
34 [Attribute(UIColors.GetColorAttribute(GUIColors.DEFAULT_GLOW), UIWidgets.ColorPicker)]
35 protected ref Color m_ActionUnbound;
36
37 [Attribute("not-available")]
38 protected string m_sActionUnboundIcon;
39
40 [Attribute(UIColors.GetColorAttribute(Color.White), UIWidgets.ColorPicker)]
42
43 [Attribute("0.597421 0.061189 0.475868 1.000000", UIWidgets.ColorPicker)]
45
46 [Attribute("0", desc: "If enabled there will be no sound played when the button is pressed")]
47 protected bool m_bDisableClickSound;
48
49 [Attribute("0", desc: "Postion offset when button is not held")]
51
52 [Attribute("5", desc: "Position offset when button is held")]
54
55 [Attribute("0.1", desc:"Time in sec who long the animation takes.")]
57
58 [Attribute("1", desc: "If false the button will never change to its disabled visual state.")]
60
61 [Attribute("1", desc: "If false the Label does not change its color to disabled when button is disabled.")]
63
64 [Attribute("InputButtonDisplayRoot")]
65 protected string m_sButtonWidgetName;
66
67 [Attribute("HorizontalLayout0")]
68 protected string m_sHorizontalLayoutWidget;
69
70 [Attribute("TextHint")]
71 protected string m_sTextHintWidget;
72
73 [Attribute("{B7C8B633428B153D}UI/layouts/WidgetLibrary/Buttons/WLib_InputButtonDisplay.layout")]
75
76 [Attribute("{983DFCCEB578C1C5}UI/layouts/InputButtons/InputButton_ComboIndicator.layout")]
78
79 [Attribute(UIConstants.ICONS_IMAGE_SET)]
81
82 [Attribute(UIConstants.ICONS_GLOW_IMAGE_SET)]
84
85 [Attribute(desc: "If enabled Text size is controlled by set size Inside the RichText widget")]
86 protected bool m_bOverrideTextSize;
87
88 [Attribute("-0.05", desc: "Time that will the HoldTime will be reduced by to make the Animation the right length. Time in seconds")]
89 protected float m_fHoldTimeReduction;
90
91 [Attribute()]
93
94 protected const string COMBO_INDICATOR_IMAGE_NAME = "ComboIndicatorImg";
95 protected const string COMBO_INDICATOR_SHADOW_NAME = "ComboIndicatorShadow";
96 protected const string COMBO_INDICATOR_DIVIDER_NAME = "keybind_divider";
97 protected const string COMBO_INDICATOR_COMBO_NAME = "keybind_combo";
98 protected const string COMBO_INDICATOR_KEY = " + ";
99 protected const string COMBO_DIVIDER_KEY = " | ";
100
101 protected const float COMBO_INDICATOR_SIZE_MULTIPLIER = 0.5;
102
103 // TODO: fix textures having improper offset: we should not need different padding scaling
104 protected const float COMBO_INDICATOR_PADDING_MULTIPLIER_LEFT = 0.20;
105 protected const float COMBO_INDICATOR_PADDING_MULTIPLIER_RIGHT = 0.15;
106
107 protected const float MIN_FONTSIZE_MULTIPLIER = 0.5;
108
112
113 protected ref array<SizeLayoutWidget> m_aComboIndicators = {};
114 protected ref array<Widget> m_aComboWidgets = {};
115 protected ref array<BaseContainer> m_aFilterStack = {};
116 protected ref array<int> m_aFilterStackIndexRemover = {};
117 protected ref array<string> m_aKeyStackArray = {};
118
119 InputManager m_InputManager = GetGame().GetInputManager();
120
121 protected bool m_bIsComboInput;
122 protected bool m_bIsAlternativeInput;
123 protected bool m_bIsHoldAction;
124 protected bool m_bIsDoubleTapAction;
125 protected bool m_bPressedInput;
126 protected bool m_bIsContinuous;
127
128 protected bool m_bForceDisabled;
129 protected bool m_bShouldBeEnabled;
131
133 protected bool m_bForceUpdate;
134
135 protected string m_sOldActionName;
136
137 protected bool m_bIsHoldingButton;
140
141 protected float m_fDefaultHoldTime;
142 protected float m_fDefaultClickTime;
144
146
147 protected EInputDeviceType m_eCurrentInputDevice;
148
152
154
155//---- REFACTOR NOTE END ----
156
157//---- REFACTOR NOTE START: This code will need to be refactored as current implementation is not conforming to the standards ----
158// Quick and dirty way of disabling the buttons when they're not in a top dialog. Can definitely be done better, as the buttons have no business knowing all displayed dialogs
159
160 protected ref array<DialogUI> m_aDialogs = {};
161
162//---- REFACTOR NOTE END ----
163
164 //------------------------------------------------------------------------------------------------
165 override void HandlerAttached(Widget w)
166 {
167 super.HandlerAttached(w);
168
170 m_wTextHint = RichTextWidget.Cast(w.FindAnyWidget(m_sTextHintWidget));
171
172 Widget buttonWidget = w.FindAnyWidget(m_sButtonWidgetName);
173 if (!buttonWidget)
174 return;
175
176 m_ButtonDisplay = SCR_InputButtonDisplay.Cast(buttonWidget.FindHandler(SCR_InputButtonDisplay));
177 if (!m_ButtonDisplay)
178 return;
179
181 GameProject.GetModuleConfig("InputManagerSettings").Get("HoldDuration", m_fDefaultHoldTime);
182 GameProject.GetModuleConfig("InputManagerSettings").Get("ClickDuration", m_fDefaultClickTime);
184 {
185 m_fDefaultClickTime /= 1000;
187 }
188
189 if (m_wTextHint)
190 {
191 if (!m_sLabel)
192 m_wTextHint.SetVisible(false);
193
194 m_wTextHint.SetText(m_sLabel);
195 m_wTextHint.SetColor(m_LabelDefault);
196 }
197
198 if (GetGame().InPlayMode())
199 {
206 }
207
209
211
212 EInputDeviceType currentDevice = EInputDeviceType.KEYBOARD;
213 if (!m_InputManager.IsUsingMouseAndKeyboard())
214 currentDevice = EInputDeviceType.GAMEPAD;
215
216 ChangeInputDevice(currentDevice, false);
217
218 GetGame().OnInputDeviceIsGamepadInvoker().Insert(OnInputDeviceUserChanged);
219
222 }
223
224 //------------------------------------------------------------------------------------------------
225 override void HandlerDeattached(Widget w)
226 {
228 if (!m_InputManager)
229 return;
230
231 GetGame().OnInputDeviceIsGamepadInvoker().Remove(OnInputDeviceUserChanged);
232
233 if (GetGame().InPlayMode())
234 {
241 }
242 }
243
244 //------------------------------------------------------------------------------------------------
245 override bool OnClick(Widget w, int x, int y, int button)
246 {
247 if (button != 0 || !m_wRoot.IsVisible() || !m_wRoot.IsEnabled())
248 return false;
249
251 return false;
252
253 m_bIsHoldingButton = true;
254
255 OnInput();
256
257 super.OnClick(w, x, y, button);
258
259 return false;
260 }
261
262 //------------------------------------------------------------------------------------------------
266 bool IsKeybindAvailable(inout notnull array<string> keyStack)
267 {
268 if (m_sActionName.IsEmpty())
269 return false;
270
271 if (m_aFilterStack.IsEmpty())
273
274 return m_InputManager && m_InputManager.GetActionKeybinding(m_sActionName, keyStack, m_aFilterStack, m_eCurrentInputDevice);
275 }
276
277 //------------------------------------------------------------------------------------------------
278 override void SetEnabled(bool enabled, bool animate = true)
279 {
280 m_bShouldBeEnabled = enabled;
281 SetEnabled_Internal(enabled, animate);
282 }
283
284 //------------------------------------------------------------------------------------------------
285 protected void SetEnabled_Internal(bool enabled, bool animate = true)
286 {
287 if (!m_bForceDisabled)
288 {
289 m_wRoot.SetEnabled(enabled);
290 if (enabled)
291 OnEnabled(animate);
292 else
293 OnDisabled(animate);
294 }
295 else
296 {
297 m_wRoot.SetEnabled(false);
298 OnDisabled(animate);
299 }
300 }
301
302 //------------------------------------------------------------------------------------------------
304 protected void OnInputDeviceUserChanged(bool isGamepad)
305 {
306 if (isGamepad)
307 ChangeInputDevice(EInputDeviceType.GAMEPAD, false);
308 else
309 ChangeInputDevice(EInputDeviceType.KEYBOARD, false);
310 }
311
312 //------------------------------------------------------------------------------------------------
317 protected bool ChangeInputDevice(EInputDeviceType inputDevice, bool hasFocus, bool resetOverride = false)
318 {
319 if (inputDevice == m_eCurrentInputDevice && m_sActionName == m_sOldActionName && !resetOverride && !m_bForceUpdate)
320 return true;
321
322 m_bForceUpdate = false;
323
324 if (inputDevice == EInputDeviceType.MOUSE && hasFocus && m_bIsMouseInput)
325 {
326 m_eCurrentInputDevice = inputDevice;
327 }
328 else
329 {
330 if (inputDevice == EInputDeviceType.GAMEPAD)
331 m_eCurrentInputDevice = inputDevice;
332 else
333 m_eCurrentInputDevice = EInputDeviceType.KEYBOARD;
334 }
335
336 if (inputDevice == EInputDeviceType.INVALID)
337 return false;
338
339 array<string> keyStack = {};
341 if (m_InputManager.GetActionKeybinding(m_sActionName, keyStack, m_aFilterStack, m_eCurrentInputDevice))
342 {
344 m_aKeyStackArray.Clear();
345 int index = keyStack.Count() - 1;
346 ProcessKeybindStack(index, keyStack);
347
348 if (keyStack.IsEmpty() || !m_aKeyStackArray || m_aKeyStackArray.IsEmpty())
349 return false;
350
351 string keyCode = m_aKeyStackArray[0];
353 if (m_InputManager.GetKeyUIMapping(keyCode))
354 data = m_InputManager.GetKeyUIMapping(keyCode).GetObject("Data");
355
356 if (!data)
357 {
358 Print(string.Format("No data found for %1 !! Check 'chimeraMapping.conf' and add data if necessary! Provided Actioname: %2.", keyCode, m_sActionName), LogLevel.ERROR);
359 return false;
360 }
361
362 //Check is there is a valid filter applied
364
365 //Process filter stack for visualisation
367
368 if (m_ButtonDisplay)
369 {
370 m_ButtonDisplay.SetAction(data, m_aFilterStack[0]);
371
372 if (!m_bKeybindActive)
373 m_ButtonDisplay.ChangeInputVisibility(false);
374 }
375
377 {
378 int textSize = m_iHeightInPixel / m_ButtonDisplay.GetTextSizeModifier();
379 m_wTextHint.SetDesiredFontSize(textSize);
380 m_wTextHint.SetMinFontSize(textSize * MIN_FONTSIZE_MULTIPLIER);
381 }
382
386
389 }
390 else
391 {
392 if (m_ButtonDisplay)
393 m_ButtonDisplay.OverrideTexture(UIConstants.ICONS_IMAGE_SET, m_sActionUnboundIcon, m_ActionUnbound, SCR_EButtonSize.KEYBOARD_SQUARE, false);
394
395 return false;
396 }
397
398 return true;
399 }
400
401 //------------------------------------------------------------------------------------------------
404 {
405
406//---- REFACTOR NOTE START: This code will need to be refactored as current implementation is not conforming to the standards ----
407// Flags
408
409 m_bIsHoldAction = false;
410 m_bIsDoubleTapAction = false;
411 m_bPressedInput = false;
412 m_bCanBeToggled = false;
413 m_bIsContinuous = false;
414
415//---- REFACTOR NOTE END ----
416
417 if (!filter)
418 return false;
419
420 switch (filter.GetClassName())
421 {
422 case "InputFilterHold":
423 {
424 filter.Get("HoldDuration", m_fMaxHoldtime);
425 if (m_fMaxHoldtime == -1 || m_fMaxHoldtime == 0)
427
428 m_fMaxHoldtime /= 1000;
430 if (m_fMaxHoldtime <= 0)
432
433 m_bIsHoldAction = true;
434 break;
435 }
436 case "InputFilterHoldOnce":
437 {
438 filter.Get("HoldDuration", m_fMaxHoldtime);
439 if (m_fMaxHoldtime == -1 || m_fMaxHoldtime == 0)
441
442 m_fMaxHoldtime /= 1000;
444 if (m_fMaxHoldtime <= 0)
446
447 m_bIsHoldAction = true;
448 break;
449 }
450 case "InputFilterDoubleClick":
451 {
453 filter.Get("Threshold", m_iDoubleTapThreshold);
454 if (m_iDoubleTapThreshold == -1)
455 GameProject.GetModuleConfig("InputManagerSettings").Get("DoubleClickDuration", m_iDoubleTapThreshold);
456
457 m_iDoubleTapThreshold /= 1000;
458 break;
459 }
460 case "InputFilterPressed":
461 {
462 m_bPressedInput = true;
463 break;
464 }
465 case "InputFilterToggle":
466 {
467 m_bCanBeToggled = true;
468 break;
469 }
470 case "InputFilterValue":
471 {
472 m_bIsContinuous = true;
473 break;
474 }
475 }
476
477 return false;
478 }
479
480 //------------------------------------------------------------------------------------------------
482 protected void CreateComboWidget()
483 {
484 if (m_ButtonDisplay.GetIsOverwritten())
485 return;
486
487 int comboCount;
488 int filterIndex = 1;
489 Widget button;
490 SizeLayoutWidget comboIndicatorContainer;
491 ImageWidget comboIndicator;
492 ImageWidget comboIndicatorShadow;
494 foreach (int i, string key : m_aKeyStackArray)
495 {
496 if (i == 0)
497 continue;//skip first button info to not duplicate it
498
499 if (key == COMBO_INDICATOR_KEY || key == COMBO_DIVIDER_KEY)
500 {
501 if (comboCount >= m_iMaxShownKeys - 1 && key == COMBO_DIVIDER_KEY)
502 break;
503
504 comboIndicatorContainer = SizeLayoutWidget.Cast(GetGame().GetWorkspace().CreateWidgets(m_sComboIndicatorWidget, m_wHorizontalLayout));
505 if (!comboIndicatorContainer)
506 {
507 Print(string.Format("Unable to create Widget! %1 or %2 are null!", m_sComboIndicatorWidget, m_wHorizontalLayout), LogLevel.ERROR);
508 return;
509 }
510
511 comboIndicator = ImageWidget.Cast(comboIndicatorContainer.FindAnyWidget(COMBO_INDICATOR_IMAGE_NAME));
512 comboIndicatorShadow = ImageWidget.Cast(comboIndicatorContainer.FindAnyWidget(COMBO_INDICATOR_SHADOW_NAME));
513
514 if (comboIndicator && comboIndicatorShadow)
515 {
516 if (key == COMBO_INDICATOR_KEY)
517 {
518 comboIndicator.LoadImageFromSet(0, m_sComboIndicatorImageSet, COMBO_INDICATOR_COMBO_NAME);
519 comboIndicatorShadow.LoadImageFromSet(0, m_sComboIndicatorImageSetGlow, COMBO_INDICATOR_COMBO_NAME);
520 }
521 else if (key == COMBO_DIVIDER_KEY)
522 {
523 comboIndicator.LoadImageFromSet(0, m_sComboIndicatorImageSet, COMBO_INDICATOR_DIVIDER_NAME);
524 comboIndicatorShadow.LoadImageFromSet(0, m_sComboIndicatorImageSetGlow, COMBO_INDICATOR_DIVIDER_NAME);
525
526 comboCount++;
527 }
528 }
529
530 m_aComboIndicators.Insert(comboIndicatorContainer);
531 m_aComboWidgets.Insert(comboIndicatorContainer);
532 continue;
533 }
534
535 BaseContainer keyData = m_InputManager.GetKeyUIMapping(m_aKeyStackArray[i]).GetObject("Data");
536 if (!keyData)
537 {
538 Print(string.Format("No data found for %1 !! Check 'chimeraMapping.conf' and add data if necessary!", m_aKeyStackArray[i]), LogLevel.ERROR);
539 return;
540 }
541
543 Widget comboWidget = GetGame().GetWorkspace().CreateWidgets(m_sInputButtonWidget, m_wHorizontalLayout);
544
545 if (!comboWidget)
546 {
547 Print(string.Format("Unable to create Widget! %1 or %2 are null!", m_sInputButtonWidget, m_wHorizontalLayout), LogLevel.ERROR);
548 return;
549 }
550
551 SCR_InputButtonDisplay component = SCR_InputButtonDisplay.Cast(comboWidget.FindHandler(SCR_InputButtonDisplay));
552
553 if (!component)
554 {
555 Print(string.Format("%1 has no 'SCR_InputButtonDisplay' component attached!", component), LogLevel.ERROR);
556 return;
557 }
558
560
561 component.Init(m_wRoot);
562 component.SetAction(keyData, m_aFilterStack[filterIndex]);
563 filterIndex++;
564
565 if (!m_bKeybindActive)
566 component.ChangeInputVisibility(false);
567
568 m_aComboWidgets.Insert(comboWidget);
569 }
570 }
571
572 //------------------------------------------------------------------------------------------------
574 protected void DeleteComboWidget()
575 {
576 if (m_aComboWidgets.IsEmpty())
577 return;
578
579 foreach (Widget widget : m_aComboWidgets)
580 {
581 if (!widget)
582 continue;
583
584 widget.RemoveFromHierarchy();
585 }
586
587 m_aComboWidgets.Clear();
588 m_aComboIndicators.Clear();
589 }
590
591 //------------------------------------------------------------------------------------------------
593 protected void SetInputAction()
594 {
595 if (!m_sOldActionName.IsEmpty())
596 {
598 m_InputManager.RemoveActionListener(m_sOldActionName, EActionTrigger.VALUE, OnButtonHold);
600 }
601
602 if (m_sActionName.IsEmpty())
603 return;
604
605 if (m_bIsHoldAction)
606 m_InputManager.AddActionListener(m_sActionName, EActionTrigger.VALUE, OnButtonHold);
607
608 if (m_bIsContinuous)
610
612
614 }
615
616 //------------------------------------------------------------------------------------------------
617 protected void OnButtonPressed(float value, EActionTrigger reason)
618 {
619 if (!m_bKeybindActive)
620 return;
621
623 OnInput();
624 }
625
626 //------------------------------------------------------------------------------------------------
627 override bool OnDoubleClick(Widget w, int x, int y, int button)
628 {
630 super.OnDoubleClick(w, x, y, button);
631
632 return false;
633 }
634
635 //------------------------------------------------------------------------------------------------
636 override bool OnMouseEnter(Widget w, int x, int y)
637 {
638 super.OnMouseEnter(w, x, y);
639
640 m_bIsHovered = true;
642 m_OnAnimateHover.Invoke(this);
643
644 return false;
645 }
646
647 //------------------------------------------------------------------------------------------------
648 override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
649 {
650 super.OnMouseLeave(w, enterW, x, y);
651
652 m_bIsHovered = false;
653
655 m_OnAnimateHover.Invoke(this);
656
657 return false;
658 }
659
660 //------------------------------------------------------------------------------------------------
661 override void OnDisabled(bool animate)
662 {
664 m_OnUpdateEnableColor.Invoke(this);
665 }
666
667 //------------------------------------------------------------------------------------------------
668 override void OnEnabled(bool animate)
669 {
670 super.OnEnabled(animate);
671
673 m_OnUpdateEnableColor.Invoke(this);
674 }
675
676 //------------------------------------------------------------------------------------------------
679 void OnButtonHold(float value)
680 {
681 if (!m_wRoot)
682 return;
683
684 if (m_bCanBeDisabled && (!m_wRoot.IsVisibleInHierarchy() || !m_wRoot.IsEnabledInHierarchy()))
685 return;
686
687 // Bail if attached to menu but menu is not focused
688 if (!IsParentMenuFocused())
689 return;
690
691 if (value == 0)
692 {
694 {
695 m_bIsHoldingButton = false;
697 }
698
699 return;
700 }
701
702 if (value < m_fDefaultClickTime)
703 return;
704
706 {
707 m_bIsHoldingButton = true;
708 ActionPressed(true);
709 }
710 }
711
712 //------------------------------------------------------------------------------------------------
714 {
716 return;
717
718 if (m_bCanBeDisabled && (!m_wRoot.IsVisibleInHierarchy() || !m_wRoot.IsEnabledInHierarchy()))
719 return;
720
722 }
723
724 //------------------------------------------------------------------------------------------------
726 protected void OnInput()
727 {
728 if (!m_wRoot)
729 return;
730
731 if (m_bCanBeDisabled && (!m_wRoot.IsVisibleInHierarchy() || !m_wRoot.IsEnabledInHierarchy()))
732 return;
733
734 // Bail if attached to menu but menu is not focused
735 if (!IsParentMenuFocused())
736 return;
737
738 //--- If a modal widget is active, check if the button is in its hierarchy
739 Widget modal = GetGame().GetWorkspace().GetModal();
740 if (modal && !SCR_WidgetTools.InHierarchy(m_wRoot, modal))
741 return;
742
743 m_OnActivated.Invoke(this, m_sActionName);
744 if (m_bIsHoldAction)
745 return;
746
748 }
749
750 //------------------------------------------------------------------------------------------------
751 protected void ActionPressed(bool isHoldAction = false)
752 {
753 if (m_ButtonDisplay)
754 m_ButtonDisplay.ActionPressed(isHoldAction);
755
756 foreach (Widget inputButton : m_aComboWidgets)
757 {
758 SCR_InputButtonDisplay component = SCR_InputButtonDisplay.Cast(inputButton.FindHandler(SCR_InputButtonDisplay));
759 if (!component)
760 continue;
761
762 component.ActionPressed(isHoldAction);
763 }
764 }
765
766 //------------------------------------------------------------------------------------------------
767 protected void ActionReleased()
768 {
769
771 return;
772
773 if (m_ButtonDisplay)
774 m_ButtonDisplay.ActionReleased();
775
776 foreach (Widget inputButton : m_aComboWidgets)
777 {
778 SCR_InputButtonDisplay component = SCR_InputButtonDisplay.Cast(inputButton.FindHandler(SCR_InputButtonDisplay));
779 if (!component)
780 continue;
781
782 component.ActionReleased();
783 }
784 }
785
786 //------------------------------------------------------------------------------------------------
788 {
789 return m_bIsHoldingButton;
790 }
791
792 //------------------------------------------------------------------------------------------------
793 void SetIsHoldingButton(bool isHolding)
794 {
795 m_bIsHoldingButton = isHolding;
796 }
797
798 //------------------------------------------------------------------------------------------------
800 {
801 return m_fAnimationRate;
802 }
803
804 //------------------------------------------------------------------------------------------------
806 {
807 return m_fAnimationTime;
808 }
809
810 //------------------------------------------------------------------------------------------------
812 {
813 return m_bIsComboInput;
814 }
815
816 //------------------------------------------------------------------------------------------------
824
825 //------------------------------------------------------------------------------------------------
833
834 //------------------------------------------------------------------------------------------------
842
843 //------------------------------------------------------------------------------------------------
846 void ProcessKeybindStack(inout int index, notnull array<string> keyStack)
847 {
848 if (!keyStack.IsIndexValid(index))
849 return;
850
851 // pop back
852 string key = keyStack[index];
853 index--;
854
855 switch (key)
856 {
857 case "+": // combo
858 {
860 ProcessKeybindStack(index, keyStack);
862 ProcessKeybindStack(index, keyStack);
863 m_bIsComboInput = true;
864 break;
865 }
866 case "|": // sum/alternative
867 {
869 ProcessKeybindStack(index, keyStack);
871 ProcessKeybindStack(index, keyStack);
873 break;
874 }
875
876 default: // key value
877 m_aKeyStackArray.Insert(key);
878
879 }
880 }
881
882 //------------------------------------------------------------------------------------------------
887 {
888 if (m_aFilterStack.IsEmpty())
889 return;
890
891 foreach (int index : m_aFilterStackIndexRemover)
892 {
893 m_aFilterStack.RemoveOrdered(index);
894 }
895
896 array<BaseContainer> filteredm_aFilterStack = {};
897 int count = m_aFilterStack.Count() - 1;
898 for (int i = count; i >= 0; i--)
899 {
900 BaseContainer m_aFilterStackIndex = m_aFilterStack[i];
901 filteredm_aFilterStack.Insert(m_aFilterStackIndex);
902
903 if (!m_aFilterStackIndex)
904 continue;
905
906 if (m_aFilterStackIndex.GetClassName() == "InputFilterHold" || m_aFilterStackIndex.GetClassName() == "InputFilterHoldOnce")
907 {
908 m_aFilterStackIndex.Get("HoldDuration", m_fMaxHoldtime);
909 if (m_fMaxHoldtime == -1 || m_fMaxHoldtime == 0)
911
912 m_fMaxHoldtime /= 1000;
914 if (m_fMaxHoldtime <= 0)
916
917 m_bIsHoldAction = true;
918 }
919 }
920 m_aFilterStack.Clear();
921 m_aFilterStack = filteredm_aFilterStack;
922 }
923
925 //------------------------------------------------------------------------------------------------
927 void SetLabel(string label)
928 {
929 if (!m_wTextHint)
930 return;
931
932 m_wTextHint.SetText(label);
933 m_wTextHint.SetVisible(true);
934 }
935
936 //------------------------------------------------------------------------------------------------
938 void SetLabelColor(notnull Color color)
939 {
940 if (!m_wTextHint)
941 return;
942
943 m_wTextHint.SetColor(color);
944 }
945
946 //------------------------------------------------------------------------------------------------
951 bool SetAction(string action, EInputDeviceType currentInputDevice = -1, bool forceUpdate = false)
952 {
953 if (forceUpdate)
954 m_sOldActionName = string.Empty;
955 else if (m_sActionName == action)
956 return true;
957
958 m_sActionName = action;
959 if (currentInputDevice < 0)
960 {
961 if (m_InputManager.IsUsingMouseAndKeyboard())
962 currentInputDevice = EInputDeviceType.KEYBOARD;
963 else
964 currentInputDevice = EInputDeviceType.GAMEPAD;
965 }
966
967 if (ChangeInputDevice(currentInputDevice, false))
968 return true;
969
970 if (!forceUpdate)
971 m_sActionName = string.Empty;
972
973 return false;
974 }
975
976 //------------------------------------------------------------------------------------------------
978 {
979 return m_iHeightInPixel;
980 }
981
982 //------------------------------------------------------------------------------------------------
985 void SetSize(int size)
986 {
988
990 {
991 int textSize = m_iHeightInPixel / m_ButtonDisplay.GetTextSizeModifier();
992 m_wTextHint.SetDesiredFontSize(textSize);
993 m_wTextHint.SetMinFontSize(textSize * MIN_FONTSIZE_MULTIPLIER);
994 }
995
997
998 m_ButtonDisplay.Resize();
999 }
1000
1001 //------------------------------------------------------------------------------------------------
1003 {
1004 return m_bDisableClickSound;
1005 }
1006
1007 //------------------------------------------------------------------------------------------------
1009 void SetClickSoundDisabled(bool isEnabled)
1010 {
1011 m_bDisableClickSound = isEnabled;
1012 }
1013
1014 //------------------------------------------------------------------------------------------------
1019 void SetTexture(string imagePath, string image = string.Empty, Color color = Color.FromInt(Color.WHITE), SCR_EButtonSize buttonType = SCR_EButtonSize.KEYBOARD_MEDIUM)
1020 {
1021 if (!m_ButtonDisplay)
1022 return;
1023
1025 m_ButtonDisplay.OverrideTexture(imagePath, image, color, buttonType);
1026 }
1027
1028 //------------------------------------------------------------------------------------------------
1032 {
1033 if (!m_ButtonDisplay)
1034 return;
1035
1036 m_ButtonDisplay.SetIsOverwritten(false);
1037
1038 EInputDeviceType currentDevice = EInputDeviceType.KEYBOARD;
1039 if (!m_InputManager.IsUsingMouseAndKeyboard())
1040 currentDevice = EInputDeviceType.GAMEPAD;
1041
1042 ChangeInputDevice(currentDevice, false, true);
1043 }
1044
1045 //------------------------------------------------------------------------------------------------
1047 {
1048 m_ActionDisabled = newColor;
1049 }
1050
1051 //------------------------------------------------------------------------------------------------
1054 void ChangeInputVisibility(bool visible)
1055 {
1056 if (!m_ButtonDisplay)
1057 return;
1058
1059 m_bKeybindActive = visible;
1060
1061 m_ButtonDisplay.ChangeInputVisibility(visible);
1062
1063 if (m_aComboWidgets.IsEmpty())
1064 return;
1065
1066 SCR_InputButtonDisplay component;
1067 foreach (Widget inputButton : m_aComboWidgets)
1068 {
1069 component = SCR_InputButtonDisplay.Cast(inputButton.FindHandler(SCR_InputButtonDisplay));
1070 if (!component)
1071 continue;
1072
1073 component.ChangeInputVisibility(visible);
1074 }
1075 }
1076
1077 //------------------------------------------------------------------------------------------------
1079 {
1080 return SCR_InputButtonComponent.Cast(w.FindHandler(SCR_InputButtonComponent));
1081 }
1082
1083 //------------------------------------------------------------------------------------------------
1085 {
1086 return m_bIsHovered;
1087 }
1088
1089 //------------------------------------------------------------------------------------------------
1090 protected void SetForceDisabled(bool forceDisabled, bool animate = true)
1091 {
1092 GetGame().GetCallqueue().Remove(SetForceDisabled); //Stop SetForceDisabledWithDelay
1093
1094 m_bForceDisabled = forceDisabled;
1095
1096 if (forceDisabled)
1097 SetEnabled_Internal(false);
1098 else
1100 }
1101
1102 //------------------------------------------------------------------------------------------------
1103 protected void SetForceDisabledWithDelay(bool forceDisabled, bool animate = true, int delay = 0)
1104 {
1105 m_bForceDisabled = forceDisabled;
1106
1107 if (delay == 0)
1108 {
1109 SetForceDisabled(forceDisabled, animate);
1110 return;
1111 }
1112
1113 GetGame().GetCallqueue().Remove(SetForceDisabled);
1114 GetGame().GetCallqueue().CallLater(SetForceDisabled, delay, false, forceDisabled, animate);
1115 }
1116
1117 //Handling Input through SCR_MenuHelper, ei: edit and combo boxes call this to disable buttons during interaction
1118 //------------------------------------------------------------------------------------------------
1119 void OnActiveWidgetInteraction(bool isInteractionActive, int delay)
1120 {
1121 m_bIsInteractionActive = isInteractionActive;
1122
1123 if (IsInTopMenu())
1124 SetForceDisabledWithDelay(isInteractionActive, true, delay);
1125 }
1126
1127 //------------------------------------------------------------------------------------------------
1129 {
1130 m_aDialogs.Insert(dialog);
1131
1133 }
1134
1135 //------------------------------------------------------------------------------------------------
1137 {
1138 m_aDialogs.RemoveItem(dialog);
1139
1141 }
1142
1143 //------------------------------------------------------------------------------------------------
1145 {
1147 SetForceDisabled(false);
1148 }
1149
1150 //------------------------------------------------------------------------------------------------
1152 {
1154 SetForceDisabled(true);
1155 }
1156
1157 //------------------------------------------------------------------------------------------------
1161 {
1162 if (!SCR_SettingsSuperMenu.Cast(menu))
1163 return;
1164
1165 EInputDeviceType currentDevice = EInputDeviceType.KEYBOARD;
1166 if (!m_InputManager.IsUsingMouseAndKeyboard())
1167 currentDevice = EInputDeviceType.GAMEPAD;
1168
1169 m_bForceUpdate = true;
1170
1171 ChangeInputDevice(currentDevice, false);
1172 }
1173
1174 //------------------------------------------------------------------------------------------------
1177 {
1178 return m_aDialogs.IsEmpty() || m_aDialogs[m_aDialogs.Count() - 1] == GetGame().GetMenuManager().GetOwnerMenu(GetRootWidget());
1179 }
1180
1181 //------------------------------------------------------------------------------------------------
1184 {
1185 return !m_aDialogs.IsEmpty() && m_aDialogs[m_aDialogs.Count() - 1] == GetGame().GetMenuManager().GetOwnerMenu(GetRootWidget());
1186 }
1187
1188 //------------------------------------------------------------------------------------------------
1190 {
1191 return m_bForceDisabled;
1192 }
1193
1194 //------------------------------------------------------------------------------------------------
1196 {
1200
1202 {
1203 w.SetWidthOverride(size);
1204 w.SetHeightOverride(size);
1205 LayoutSlot.SetPadding(w, paddingLeft, 0, paddingRight, 0);
1206 }
1207 }
1208
1209 //------------------------------------------------------------------------------------------------
1212 static SCR_InputButtonComponent GetInputButtonComponent(string name, notnull Widget parent, bool searchAllChildren = true)
1213 {
1215 SCR_WLibComponentBase.GetComponent(SCR_InputButtonComponent, name, parent, searchAllChildren)
1216 );
1217 return comp;
1218 }
1219}
ArmaReforgerScripted GetGame()
Definition game.c:1398
int size
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
Get all prefabs that have the spawner data
SCR_EButtonSize
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
ScriptInvokerBase< ScriptInvokerVoidMethod > ScriptInvokerVoid
Constant variables used in various menus.
static ChimeraMenuBase GetOwnerMenu(Widget w)
Returns parent menu of a widget.
Definition Color.c:13
Input management system for user interactions.
Base class for any button, regardless its own content.
bool IsParentMenuFocused()
Returns true if parent menu is focused, or if there is no parent menu.
void OnActiveWidgetInteraction(bool isInteractionActive, int delay)
void OnSettingsMenuClosed(ChimeraMenuBase menu)
override void HandlerAttached(Widget w)
ref array< BaseContainer > m_aFilterStack
bool IsKeybindAvailable(inout notnull array< string > keyStack)
override void OnDisabled(bool animate)
bool IsInTopMenu()
Returns true if there are no dailogs or if this button is in the last dialog opened.
ref ScriptInvokerVoid m_OnHoldAnimComplete
bool IsInTopDialog()
Returns true if there if this button is in the last dialog opened.
void SetForceDisabled(bool forceDisabled, bool animate=true)
void SetIsHoldingButton(bool isHolding)
void SetClickSoundDisabled(bool isEnabled)
Enable / disable the click sound played when button is pressed.
void SetLabelColor(notnull Color color)
Change the color of the Label.
void ProcessKeybindStack(inout int index, notnull array< string > keyStack)
bool ChangeInputDevice(EInputDeviceType inputDevice, bool hasFocus, bool resetOverride=false)
void OnButtonPressed(float value, EActionTrigger reason)
void SetForceDisabledWithDelay(bool forceDisabled, bool animate=true, int delay=0)
bool SetAction(string action, EInputDeviceType currentInputDevice=-1, bool forceUpdate=false)
void SetColorActionDisabled(Color newColor)
override bool OnMouseEnter(Widget w, int x, int y)
override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
void SetLabel(string label)
PUBLIC API\.
ref SCR_InputButtonDisplay m_ButtonDisplay
void SetEnabled_Internal(bool enabled, bool animate=true)
static SCR_InputButtonComponent GetInputButtonComponent(string name, notnull Widget parent, bool searchAllChildren=true)
static SCR_InputButtonComponent FindComponent(notnull Widget w)
void OnMenuFocusGained(ChimeraMenuBase menu)
void OnMenuFocusLost(ChimeraMenuBase menu)
void DeleteComboWidget()
Delete secound InputButton widget if there is one.
override bool OnDoubleClick(Widget w, int x, int y, int button)
void SetInputAction()
Add action listeners for selected input action.
ScriptInvokerVoid GetOnUpdateEnableColor()
override void SetEnabled(bool enabled, bool animate=true)
bool m_bForceUpdate
If user changed keybing then it should force update of hints.
override void OnEnabled(bool animate)
void ActionPressed(bool isHoldAction=false)
ref array< SizeLayoutWidget > m_aComboIndicators
ref ScriptInvokerVoid m_OnAnimateHover
void OnInputDeviceUserChanged(bool isGamepad)
React on switching between input methods.
void OnInput()
Called when Button is clicked / key is presses.
ref ScriptInvokerVoid m_OnUpdateEnableColor
ScriptInvokerVoid GetOnHoldAnimComplete()
void CreateComboWidget()
Create a second InputButton widget to display combos.
override void HandlerDeattached(Widget w)
bool GetInputFilterSettings(BaseContainer filter)
Check which filter is applied to the action to change the buttons behavior.
void SetTexture(string imagePath, string image=string.Empty, Color color=Color.FromInt(Color.WHITE), SCR_EButtonSize buttonType=SCR_EButtonSize.KEYBOARD_MEDIUM)
override bool OnClick(Widget w, int x, int y, int button)
bool SetAction(BaseContainer data, BaseContainer filter)
void ActionPressed(bool isHoldAction=false)
void ChangeInputVisibility(bool visible)
static ScriptInvokerDialog GetOnDialogOpen()
static ScriptInvokerDialog GetOnDialogClose()
static ScriptInvokerMenu GetOnMenuFocusLost()
static ScriptInvokerMenu GetOnMenuClose()
static ScriptInvokerMenu GetOnMenuFocusGained()
static ScriptInvokerActiveWidgetInteraction GetOnActiveWidgetInteraction()
Base class for all final Reforger interactive elements.
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
SCR_FieldOfViewSettings Attribute
EActionTrigger
ScriptInvokerBase< func > ScriptInvoker
Definition tools.c:134