7 protected string m_sSoundHovered;
10 protected string m_sSoundClicked;
12 [
Attribute(defvalue:
"0.2", UIWidgets.EditBox,
"How fast each animation proceeds")]
13 protected float m_fAnimationTime;
16 protected bool m_bMouseOverToFocus;
19 protected float m_fDisabledOpacity;
21 protected float m_fAnimationRate;
23 static const float START_ANIMATION_RATE = 10001;
24 static const float START_ANIMATION_PERIOD = 250;
27 override void HandlerAttached(Widget w)
29 super.HandlerAttached(w);
31 m_fAnimationRate = START_ANIMATION_RATE;
33 GetGame().GetCallqueue().CallLater(SetAnimationRate, START_ANIMATION_PERIOD);
36 SetEnabled(
false,
false);
40 override bool OnClick(Widget w,
int x,
int y,
int button)
46 PlaySound(m_sSoundClicked);
51 override bool OnMouseEnter(Widget w,
int x,
int y)
54 if (m_bMouseOverToFocus && w.IsFocusable() &&
GetGame().
GetInputManager().GetLastUsedInputDevice() == EInputDeviceType.MOUSE)
56 GetGame().GetWorkspace().SetFocusedWidget(
null);
57 GetGame().GetWorkspace().SetFocusedWidget(w);
60 PlaySound(m_sSoundHovered);
66 override bool OnFocus(Widget w,
int x,
int y)
68 PlaySound(m_sSoundHovered);
73 protected void OnEnabled(
bool animate)
75 if (animate && m_fAnimationRate != START_ANIMATION_RATE)
76 AnimateWidget.Opacity(
m_wRoot, 1, m_fAnimationRate);
82 protected void OnDisabled(
bool animate)
84 if (animate && m_fAnimationRate != START_ANIMATION_RATE)
85 AnimateWidget.Opacity(
m_wRoot, m_fDisabledOpacity, m_fAnimationRate);
87 m_wRoot.SetOpacity(m_fDisabledOpacity);
91 protected bool IsChildWidget(Widget parent, Widget child)
93 if (parent ==
null || child ==
null)
96 child = child.GetParent();
102 child = child.GetParent();
108 protected void SetAnimationRate()
110 m_fAnimationRate = 1 / m_fAnimationTime;
114 protected void PlaySound(
string sound)
116 if (m_fAnimationRate != START_ANIMATION_RATE && sound !=
string.Empty)
121 static bool SetTexture(ImageWidget widget, ResourceName texture,
string image =
"")
123 if (!widget || texture == ResourceName.Empty)
128 if (texture.EndsWith(
".edds"))
129 success = widget.LoadImageTexture(0, texture);
131 success = widget.LoadImageFromSet(0, texture, image);
136 widget.GetImageSize(0, x, y);
137 widget.SetSize(x, y);
144 void SetHoverSound(
string soundHover)
146 m_sSoundHovered = soundHover;
150 void SetClickedSound(
string soundClicked)
152 m_sSoundClicked = soundClicked;
156 string GetHoverSound()
158 return m_sSoundHovered;
162 string GetClickedSound()
164 return m_sSoundClicked;
168 void SetEnabled(
bool enabled,
bool animate =
true)
181 void SetVisible(
bool visible,
bool animate =
true)
187 AnimateWidget.Opacity(
m_wRoot, visible, m_fAnimationRate,
true);
202 void SetMouseOverToFocus(
bool mouseOverToFocus)
204 m_bMouseOverToFocus = mouseOverToFocus;
208 void SetDisabledOpacity(
float newDisabledOpacity)
210 m_fDisabledOpacity = newDisabledOpacity;