5 protected bool m_bIsPositive;
7 [
Attribute(
"false", UIWidgets.Auto,
"Use action hint instead of an image")]
13 protected string m_sBackgroundImageName =
"BackgroundImage";
14 protected string m_sFrontImageName =
"Panel";
15 protected string m_sActionTextName =
"ActionText";
17 protected ImageWidget m_wPanel;
18 protected TextWidget m_wText;
19 protected Widget m_wBackgroundImage;
21 ref ScriptInvoker m_OnActivated =
new ScriptInvoker();
24 override void HandlerAttached(Widget w)
26 super.HandlerAttached(w);
28 m_wBackgroundImage = w.FindAnyWidget(m_sBackgroundImageName);
29 m_wPanel = ImageWidget.Cast(w.FindAnyWidget(m_sFrontImageName));
30 m_wText = TextWidget.Cast(w.FindAnyWidget(m_sActionTextName));
33 m_wPanel.SetVisible(!m_bUseActionHint);
35 if (m_wBackgroundImage)
37 m_wBackgroundImage.SetVisible(!m_bUseActionHint);
38 m_wBackgroundImage.SetColor(m_BackgroundDefault);
43 m_wText.SetVisible(m_bUseActionHint);
46 m_wText.SetTextFormat(
"<action name='%1' scale='1.5'/>",
m_sActionName);
52 FlipImage(!m_bIsPositive);
56 override bool OnClick(Widget w,
int x,
int y,
int button)
58 super.OnClick(w, x, y, button);
64 m_OnActivated.Invoke(
m_wRoot, 1);
66 m_OnActivated.Invoke(
m_wRoot, -1);
72 protected void FlipImage(
bool flip)
74 if (!m_wPanel || !m_wBackgroundImage)
79 m_wPanel.SetFlags(WidgetFlags.FLIPU);
80 m_wBackgroundImage.SetFlags(WidgetFlags.FLIPU);
84 m_wPanel.ClearFlags(WidgetFlags.FLIPU);
85 m_wBackgroundImage.ClearFlags(WidgetFlags.FLIPU);
90 override protected void OnMenuSelect()
97 if (!IsParentMenuFocused())
101 m_OnActivated.Invoke(
m_wRoot, 1);
103 m_OnActivated.Invoke(
m_wRoot, -1);
107 override void SetEnabled(
bool enabled,
bool animate =
true)
109 super.SetEnabled(enabled, animate);
110 if (m_wBackgroundImage && !m_bUseActionHint)
111 m_wBackgroundImage.SetVisible(enabled);
118 return m_bIsPositive;
122 void SetPositive(
bool positive)
124 m_bIsPositive = positive;
128 void SetAction(
string name)
133 GetGame().GetInputManager().RemoveActionListener(
m_sActionName, EActionTrigger.DOWN, OnMenuSelect);
138 if (name ==
string.Empty)
141 m_wText.SetText(
" ");
145 GetGame().GetInputManager().AddActionListener(
m_sActionName, EActionTrigger.DOWN, OnMenuSelect);
146 m_wText.SetTextFormat(
"<action name='%1' scale='1.5'/>",
m_sActionName);
151 override bool OnMouseEnter(Widget w,
int x,
int y)
153 super.OnMouseEnter(w, x, y);
155 if (!m_bUseColorization)
160 if (m_bUseActionHint)
161 AnimateWidget.Color(m_wText, m_BackgroundHovered, m_fAnimationRate);
163 AnimateWidget.Color(m_wBackgroundImage, m_BackgroundHovered, m_fAnimationRate);
169 override bool OnMouseLeave(Widget w, Widget enterW,
int x,
int y)
171 super.OnMouseLeave(w, enterW, x, y);
173 if (!m_bUseColorization)
176 if (m_bUseActionHint)
177 AnimateWidget.Color(m_wText, m_BackgroundDefault, m_fAnimationRate);
179 AnimateWidget.Color(m_wBackgroundImage, m_BackgroundDefault, m_fAnimationRate);