5 [
Attribute(
"", UIWidgets.CheckBox,
"Can the button be only clicked, or also toggled?")]
9 protected bool m_bIsToggled;
11 [
Attribute(
"true", UIWidgets.CheckBox,
"Use in built button colorization or handle it on your own")]
12 bool m_bUseColorization;
14 [
Attribute(
"1 1 1 0.1", UIWidgets.ColorPicker)]
15 ref Color m_BackgroundDefault;
17 [
Attribute(
"1 1 1 0.3", UIWidgets.ColorPicker)]
18 ref Color m_BackgroundHovered;
20 [
Attribute(
"0.760 0.392 0.08 0.3", UIWidgets.ColorPicker)]
21 ref Color m_BackgroundSelected;
23 [
Attribute(
"0.898 0.541 0.184 1", UIWidgets.ColorPicker)]
24 ref Color m_BackgroundSelectedHovered;
26 [
Attribute(
"0.898 0.541 0.184 1", UIWidgets.ColorPicker)]
27 ref Color m_BackgroundClicked;
30 bool m_bShowBorderOnFocus;
33 bool m_bShowBackgroundOnFocus;
36 bool m_bNoBorderAnimation;
39 bool m_bNoBackgroundAnimation;
42 bool m_bShowBorderOnHover;
48 ref ScriptInvoker m_OnClicked =
new ScriptInvoker();
50 ref ScriptInvoker m_OnToggled =
new ScriptInvoker();
53 ref ScriptInvoker<Widget> m_OnFocus =
new ScriptInvoker<Widget>();
54 ref ScriptInvoker<Widget> m_OnFocusLost =
new ScriptInvoker<Widget>();
57 ref ScriptInvoker m_OnShowBorder =
new ScriptInvoker();
59 protected MenuBase m_ParentMenu;
63 override void HandlerAttached(Widget w)
65 super.HandlerAttached(w);
67 m_wBorder = w.FindAnyWidget(
"Border");
69 if (m_wBorder && m_bUseColorization)
70 m_wBorder.SetOpacity(0);
75 ColorizeBackground(
false);
82 GetGame().GetCallqueue().CallLater(FindParentMenu, 0);
86 override bool OnClick(Widget w,
int x,
int y,
int button)
88 super.OnClick(w, x, y, button);
93 SetToggled(!m_bIsToggled);
100 override bool OnMouseEnter(Widget w,
int x,
int y)
102 super.OnMouseEnter(w, x, y);
104 if (m_bMouseOverToFocus)
107 if (m_bShowBorderOnHover && m_wBorder)
109 if (m_bNoBorderAnimation)
110 m_wBorder.SetOpacity(1);
112 AnimateWidget.Opacity(m_wBorder, 1, m_fAnimationRate,
true);
115 if (!m_bUseColorization)
122 AnimateWidget.Color(
m_wBackground, m_BackgroundSelectedHovered, m_fAnimationRate);
124 AnimateWidget.Color(
m_wBackground, m_BackgroundHovered, m_fAnimationRate);
130 override bool OnMouseLeave(Widget w, Widget enterW,
int x,
int y)
132 super.OnMouseLeave(w, enterW, x, y);
134 if (m_bMouseOverToFocus)
140 AnimateWidget.Color(
m_wBackground, m_BackgroundSelected, m_fAnimationRate);
142 AnimateWidget.Color(
m_wBackground, m_BackgroundDefault, m_fAnimationRate);
145 if (!m_wBorder || !m_bShowBorderOnHover || (m_bShowBorderOnFocus &&
GetGame().GetWorkspace().GetFocusedWidget() ==
m_wRoot))
148 if (m_bNoBorderAnimation)
149 m_wBorder.SetOpacity(0);
151 AnimateWidget.Opacity(m_wBorder, 0, m_fAnimationRate,
true);
156 override bool OnFocus(Widget w,
int x,
int y)
158 super.OnFocus(w, x, y);
160 if (m_bShowBorderOnFocus && m_wBorder)
162 if (m_bNoBorderAnimation)
163 m_wBorder.SetOpacity(1);
165 AnimateWidget.Opacity(m_wBorder, 1, m_fAnimationRate,
true);
170 if (m_bNoBackgroundAnimation)
173 AnimateWidget.Opacity(
m_wBackground, 1, m_fAnimationRate,
true);
182 override bool OnFocusLost(Widget w,
int x,
int y)
184 super.OnFocusLost(w, x, y);
190 if (m_bNoBackgroundAnimation)
193 AnimateWidget.Opacity(
m_wBackground, 0, m_fAnimationRate,
true);
196 if (!m_bShowBorderOnFocus || !m_wBorder || (m_bShowBorderOnHover && WidgetManager.GetWidgetUnderCursor() ==
m_wRoot))
199 if (m_bNoBorderAnimation)
200 m_wBorder.SetOpacity(0);
202 AnimateWidget.Opacity(m_wBorder, 0, m_fAnimationRate,
true);
208 protected void OnMenuSelect()
219 protected void MenuSelectBase()
223 SetToggled(!m_bIsToggled);
227 AnimateWidget.Color(
m_wBackground, m_BackgroundClicked, m_fAnimationRate);
228 GetGame().GetCallqueue().CallLater(ColorizeBackground, m_fAnimationTime * 500 + 1,
false,
true);
234 void SetToggled(
bool toggled,
bool animate =
true,
bool invokeChange =
true)
239 m_bIsToggled = toggled;
241 ColorizeBackground(animate);
253 void SetToggleable(
bool togglable)
265 void ShowBorder(
bool show,
bool animate =
true)
270 AnimateWidget.Opacity(m_wBorder, show, m_fAnimationRate,
true);
272 m_wBorder.SetOpacity(show);
275 m_OnShowBorder.Invoke(
this, show);
283 return m_wBorder.GetOpacity() != 0;
288 void SetBackgroundColors(Color defColor =
null, Color hoverColor =
null, Color selectColor =
null, Color selectHoverColor =
null, Color clickColor =
null)
291 m_BackgroundDefault = defColor;
294 m_BackgroundHovered = hoverColor;
297 m_BackgroundSelected = selectColor;
299 if (selectHoverColor)
300 m_BackgroundSelectedHovered = selectHoverColor;
303 m_BackgroundClicked = clickColor;
307 void ColorizeBackground(
bool animate =
true)
313 bool isHovered = WidgetManager.GetWidgetUnderCursor() ==
m_wRoot;
317 color = m_BackgroundSelectedHovered;
319 color = m_BackgroundSelected;
324 color = m_BackgroundHovered;
326 color = m_BackgroundDefault;
333 AnimateWidget.StopAnimation(
m_wBackground, WidgetAnimationColor);
349 protected void FindParentMenu()
352 MenuBase parentMenu =
GetGame().GetMenuManager().GetOwnerMenu(
m_wRoot);
353 m_ParentMenu = parentMenu;
356 Widget wParent =
m_wRoot.GetParent();
359 ScriptedWidgetEventHandler subMenuBase = wParent.FindHandler(
SCR_SubMenuBase);
365 wParent = wParent.GetParent();
375 protected bool IsParentMenuFocused()
378 return m_ParentSubMenu.GetShown();
379 else if(m_ParentMenu)
380 return m_ParentMenu.IsFocused();