Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_PagingButtonComponent.c
Go to the documentation of this file.
1 //------------------------------------------------------------------------------------------------
3 {
4  [Attribute()]
5  protected bool m_bIsPositive;
6 
7  [Attribute("false", UIWidgets.Auto, "Use action hint instead of an image")]
8  bool m_bUseActionHint;
9 
10  [Attribute("MenuSearch")]
11  string m_sActionName;
12 
13  protected string m_sBackgroundImageName = "BackgroundImage";
14  protected string m_sFrontImageName = "Panel";
15  protected string m_sActionTextName = "ActionText";
16 
17  protected ImageWidget m_wPanel;
18  protected TextWidget m_wText;
19  protected Widget m_wBackgroundImage;
20 
21  ref ScriptInvoker m_OnActivated = new ScriptInvoker(); // Returns -1 if negative, 1 if positive
22 
23  //------------------------------------------------------------------------------------------------
24  override void HandlerAttached(Widget w)
25  {
26  super.HandlerAttached(w);
27 
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));
31 
32  if (m_wPanel)
33  m_wPanel.SetVisible(!m_bUseActionHint);
34 
35  if (m_wBackgroundImage)
36  {
37  m_wBackgroundImage.SetVisible(!m_bUseActionHint);
38  m_wBackgroundImage.SetColor(m_BackgroundDefault);
39  }
40 
41  if (m_wText)
42  {
43  m_wText.SetVisible(m_bUseActionHint);
44  if (m_bUseActionHint)
45  {
46  m_wText.SetTextFormat("<action name='%1' scale='1.5'/>", m_sActionName);
47  }
48  }
49 
50  SetAction(m_sActionName);
51 
52  FlipImage(!m_bIsPositive);
53  }
54 
55  //------------------------------------------------------------------------------------------------
56  override bool OnClick(Widget w, int x, int y, int button)
57  {
58  super.OnClick(w, x, y, button);
59 
60  if (button != 0)
61  return false;
62 
63  if (m_bIsPositive)
64  m_OnActivated.Invoke(m_wRoot, 1);
65  else
66  m_OnActivated.Invoke(m_wRoot, -1);
67 
68  return false;
69  }
70 
71  //------------------------------------------------------------------------------------------------
72  protected void FlipImage(bool flip)
73  {
74  if (!m_wPanel || !m_wBackgroundImage)
75  return;
76 
77  if (flip)
78  {
79  m_wPanel.SetFlags(WidgetFlags.FLIPU);
80  m_wBackgroundImage.SetFlags(WidgetFlags.FLIPU);
81  }
82  else
83  {
84  m_wPanel.ClearFlags(WidgetFlags.FLIPU);
85  m_wBackgroundImage.ClearFlags(WidgetFlags.FLIPU);
86  }
87  }
88 
89  //------------------------------------------------------------------------------------------------
90  override protected void OnMenuSelect()
91  {
92  MenuSelectBase();
93  if (!m_wRoot.IsEnabled())
94  return;
95 
96  // Bail if attached to menu but menu is not focused
97  if (!IsParentMenuFocused())
98  return;
99 
100  if (m_bIsPositive)
101  m_OnActivated.Invoke(m_wRoot, 1);
102  else
103  m_OnActivated.Invoke(m_wRoot, -1);
104  }
105 
106  //------------------------------------------------------------------------------------------------
107  override void SetEnabled(bool enabled, bool animate = true)
108  {
109  super.SetEnabled(enabled, animate);
110  if (m_wBackgroundImage && !m_bUseActionHint)
111  m_wBackgroundImage.SetVisible(enabled);
112  }
113 
114  // User API
115  //------------------------------------------------------------------------------------------------
116  bool IsPositive()
117  {
118  return m_bIsPositive;
119  }
120 
121  //------------------------------------------------------------------------------------------------
122  void SetPositive(bool positive)
123  {
124  m_bIsPositive = positive;
125  }
126 
127  //------------------------------------------------------------------------------------------------
128  void SetAction(string name)
129  {
130  if (!m_wText)
131  return;
132 
133  GetGame().GetInputManager().RemoveActionListener(m_sActionName, EActionTrigger.DOWN, OnMenuSelect);
134  m_sActionName = name;
135 
136  // Handle case of empty action
137  name = name.Trim();
138  if (name == string.Empty)
139  {
140  if (m_wText)
141  m_wText.SetText(" ");
142  }
143  else
144  {
145  GetGame().GetInputManager().AddActionListener(m_sActionName, EActionTrigger.DOWN, OnMenuSelect);
146  m_wText.SetTextFormat("<action name='%1' scale='1.5'/>", m_sActionName);
147  }
148  }
149 
150  //------------------------------------------------------------------------------------------------
151  override bool OnMouseEnter(Widget w, int x, int y)
152  {
153  super.OnMouseEnter(w, x, y);
154 
155  if (!m_bUseColorization)
156  return false;
157 
158  PlaySound(m_sSoundHovered);
159 
160  if (m_bUseActionHint)
161  AnimateWidget.Color(m_wText, m_BackgroundHovered, m_fAnimationRate);
162  else
163  AnimateWidget.Color(m_wBackgroundImage, m_BackgroundHovered, m_fAnimationRate);
164 
165  return false;
166  }
167 
168  //------------------------------------------------------------------------------------------------
169  override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
170  {
171  super.OnMouseLeave(w, enterW, x, y);
172 
173  if (!m_bUseColorization)
174  return false;
175 
176  if (m_bUseActionHint)
177  AnimateWidget.Color(m_wText, m_BackgroundDefault, m_fAnimationRate);
178  else
179  AnimateWidget.Color(m_wBackgroundImage, m_BackgroundDefault, m_fAnimationRate);
180 
181  return false;
182  }
183 
184  //------------------------------------------------------------------------------------------------
185  string GetAction()
186  {
187  return m_sActionName;
188  }
189 
190  //------------------------------------------------------------------------------------------------
191  static SCR_PagingButtonComponent GetPagingButtonComponent(string name, Widget parent, bool searchAllChildren = true)
192  {
193  return SCR_PagingButtonComponent.Cast(SCR_PagingButtonComponent.GetComponent(SCR_ButtonBaseComponent, name, parent, searchAllChildren));
194  }
195 };
PlaySound
SCR_ParticleContactComponentClass ScriptComponentClass PlaySound(IEntity owner, SCR_ParticleContactComponentClass prefabData, Contact contact)
Definition: SCR_ParticleContactComponent.c:38
m_wRoot
protected Widget m_wRoot
Definition: SCR_ScenarioFrameworkLayerTaskDefend.c:59
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
m_sActionName
protected string m_sActionName
Definition: SCR_ActionsRadialMenuEditorComponent.c:24
SCR_PagingButtonComponent
Definition: SCR_PagingButtonComponent.c:2
Attribute
typedef Attribute
Post-process effect of scripted camera.
SCR_ButtonBaseComponent
Base class for any button, regardless its own content.
Definition: SCR_ButtonBaseComponent.c:3