Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
ButtonComponent.c
Go to the documentation of this file.
1 // More complex button handling 6 states:
2 // Default, hovered, focused, hovered+focused, clicked, disabled.
3 // Used for more complex buttons types requiring hovering over a button
4 
6 {
7  [Attribute("1 1 1 0.05", UIWidgets.ColorPicker, "")]
8  protected ref Color m_ColorButtonHovered;
9 
10  [Attribute("1 1 1 0.25", UIWidgets.ColorPicker, "")]
11  protected ref Color m_ColorButtonHoveredFocused;
12 
13  [Attribute("1 1 1 1", UIWidgets.ColorPicker, "")]
14  protected ref Color m_ColorChildHovered;
15 
16  [Attribute("0 0 0 1", UIWidgets.ColorPicker, "")]
17  protected ref Color m_ColorChildHoveredFocused;
18 
19  [Attribute(SCR_SoundEvent.SOUND_FE_BUTTON_HOVER, UIWidgets.EditBox, "")]
20  protected string m_sSoundHovered;
21 
22  protected bool m_bIsHovered = false;
23 
24  //------------------------------------------------------------------------------------------------
25  override void HandlerDeattached(Widget w)
26  {
27  super.HandlerDeattached(w);
28  m_ColorButtonHovered = null;
29  m_ColorChildHovered = null;
30  m_ColorButtonHoveredFocused = null;
31  m_ColorChildHoveredFocused = null;
32  }
33 
34  //------------------------------------------------------------------------------------------------
35  override bool OnMouseButtonUp(Widget w, int x, int y, int button)
36  {
37  AnimateWidget.Color(w, m_ColorButtonHoveredFocused, m_fAnimationLength);
38 
39  if (m_bColorizeChildren && m_wChild)
40  AnimateWidget.Color(m_wChild, m_ColorChildHoveredFocused, m_fAnimationLength);
41 
42  return false;
43  }
44 
45  //------------------------------------------------------------------------------------------------
46  override bool OnFocus(Widget w, int x, int y)
47  {
48  m_bIsFocused = true;
49  SCR_UISoundEntity.SoundEvent(m_sSoundFocused);
50 
51  Color buttonColor;
52  Color childColor;
53  if (m_bIsHovered)
54  {
55  buttonColor = m_ColorButtonHoveredFocused;
56  childColor = m_ColorChildHoveredFocused;
57  }
58  else
59  {
60  buttonColor = m_ColorButtonFocused;
61  childColor = m_ColorChildFocused;
62  }
63 
64  AnimateWidget.Color(w, buttonColor, m_fAnimationLength);
65  if (m_bColorizeChildren && m_wChild)
66  AnimateWidget.Color(m_wChild, childColor, m_fAnimationLength);
67 
68  return false;
69  }
70 
71  //------------------------------------------------------------------------------------------------
72  override bool OnFocusLost(Widget w, int x, int y)
73  {
74  m_bIsFocused = false;
75 
76  Color buttonColor;
77  Color childColor;
78  if (m_bIsHovered)
79  {
80  buttonColor = m_ColorButtonHovered;
81  childColor = m_ColorChildHovered;
82  }
83  else
84  {
85  buttonColor = m_ColorButtonDefault;
86  childColor = m_ColorChildDefault;
87  }
88 
89  AnimateWidget.Color(w, buttonColor, m_fAnimationLength);
90  if (m_bColorizeChildren && m_wChild)
91  AnimateWidget.Color(m_wChild, childColor, m_fAnimationLength);
92 
93  return false;
94  }
95 
96  //------------------------------------------------------------------------------------------------
97  override bool OnMouseEnter(Widget w, int x, int y)
98  {
99  m_bIsHovered = true;
100  SCR_UISoundEntity.SoundEvent(m_sSoundHovered);
101 
102  Color buttonColor;
103  Color childColor;
104  if (m_bIsFocused)
105  {
106  buttonColor = m_ColorButtonHoveredFocused;
107  childColor = m_ColorChildHoveredFocused;
108  }
109  else
110  {
111  buttonColor = m_ColorButtonHovered;
112  childColor = m_ColorChildHovered;
113  }
114 
115  AnimateWidget.Color(w, buttonColor, m_fAnimationLength);
116  if (m_bColorizeChildren && m_wChild)
117  AnimateWidget.Color(m_wChild, childColor, m_fAnimationLength);
118 
119  return false;
120  }
121 
122  //------------------------------------------------------------------------------------------------
123  override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
124  {
125  m_bIsHovered = false;
126 
127  Color buttonColor;
128  Color childColor;
129  if (m_bIsFocused)
130  {
131  buttonColor = m_ColorButtonFocused;
132  childColor = m_ColorChildFocused;
133  }
134  else
135  {
136  buttonColor = m_ColorButtonDefault;
137  childColor = m_ColorChildDefault;
138  }
139 
140  AnimateWidget.Color(w, buttonColor, m_fAnimationLength);
141  if (m_bColorizeChildren && m_wChild)
142  AnimateWidget.Color(m_wChild, childColor, m_fAnimationLength);
143 
144  return false;
145  }
146 };
SCR_UISoundEntity
Definition: SCR_UISoundEntity.c:7
SCR_SoundEvent
Definition: SCR_SoundEvent.c:1
ButtonComponent
Definition: ButtonComponent.c:5
Attribute
typedef Attribute
Post-process effect of scripted camera.
SimpleButtonComponent
Definition: SimpleButtonComponent.c:9
m_bIsHovered
protected bool m_bIsHovered
Definition: SCR_CampaignMobileAssemblyStandaloneComponent.c:23