Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_MultipleStatesButtonComponent.c
Go to the documentation of this file.
1 // This class displays a button with multiple possible states.
4 
5 //------------------------------------------------------------------------------------------------
7 {
8  [Attribute()]
9  protected ref array<ref MultipleStateButtonState> m_aStates;
10 
11  [Attribute()]
12  protected ResourceName m_wIconSetTexture;
13 
14  /*[Attribute()]
15  ref array<string> m_aStateNames;
16 
17  [Attribute()]
18  ref array<string> m_aStateIcons;*/
19 
20  [Attribute()]
21  protected int m_iStateSelected;
22 
23  [Attribute()]
24  protected bool m_bEnabled = true;
25 
26  [Attribute("", "auto", "Action ID to be displayed as hint")]
27  protected string m_sHintAction;
28 
29  protected TextWidget m_ContentText;
30  protected TextWidget m_ProgressText;
31  protected ImageWidget m_Progress;
32  protected ImageWidget m_wIcon;
33  protected RichTextWidget m_wActionHint;
34 
35  ref ScriptInvoker m_OnStateChange = new ScriptInvoker;
36  ref ScriptInvoker m_OnHover = new ScriptInvoker;
37  ref ScriptInvoker m_OnHoverLeave = new ScriptInvoker;
38 
39  //------------------------------------------------------------------------------------------------
40  override void HandlerAttached(Widget w)
41  {
42  super.HandlerAttached(w);
43 
44  m_ContentText = TextWidget.Cast(m_wRoot.FindAnyWidget("ContentText"));
45  m_Progress = ImageWidget.Cast(m_wRoot.FindAnyWidget("Progress"));
46  m_ProgressText = TextWidget.Cast(m_wRoot.FindAnyWidget("ProgressNumber"));
47  m_wIcon = ImageWidget.Cast(m_wRoot.FindAnyWidget("ContentImage"));
48  m_wActionHint = RichTextWidget.Cast(m_wRoot.FindAnyWidget("ActionHint"));
49 
50  if (!m_sHintAction.IsEmpty())
51  m_wActionHint.SetText(string.Format("<action name=\"%1\"/>", m_sHintAction));
52  else
53  m_wActionHint.SetText(string.Empty);
54 
55  Init();
56  }
57 
58  //------------------------------------------------------------------------------------------------
59  void Init()
60  {
61  /*if (m_aStateNames.Count()>0)
62  ChangeState(m_iStateSelected);*/
63 
64  if (m_aStates.Count() > 0)
65  ChangeState(m_iStateSelected);
66  }
67 
68  //------------------------------------------------------------------------------------------------
69  override bool OnClick(Widget w, int x, int y, int button)
70  {
71  if (!m_bEnabled)
72  return false;
73  super.OnClick(w, x, y, button);
74  if (button != 0)
75  return false;
76 
77  return false;
78  }
79 
80  //------------------------------------------------------------------------------------------------
81  void ChangeState(int state)
82  {
83  if (!m_aStates)
84  return;
85 
86  if (state >= 0 && state < m_aStates.Count())
87  {
88  m_iStateSelected = state;
89 
90  // Text
91  string name = m_aStates[state].m_sName;
92  m_ContentText.SetText(name);
93 
94  // Image
95  m_wIcon.LoadImageFromSet(0, m_wIconSetTexture, m_aStates[state].m_sIcon);
96 
97  // Color
98  if(m_aStates[state].m_cContentColor)
99  {
100  if (m_ContentText)
101  m_ContentText.SetColor(m_aStates[state].m_cContentColor);
102 
103  if (m_wIcon)
104  m_wIcon.SetColor(m_aStates[state].m_cContentColor);
105  }
106  }
107 
108  m_OnStateChange.Invoke(state);
109  }
110 
111  //------------------------------------------------------------------------------------------------
112  void StartProgress()
113  {
114  m_Progress.SetVisible(true);
115  m_Progress.SetMaskProgress(0);
116  m_ContentText.SetText(m_aStates[m_iStateSelected].m_sName);
117  SetProgressText("0%");
118  }
119 
120  //------------------------------------------------------------------------------------------------
121  void SetProgress(int progress)
122  {
123  if (!m_Progress.IsVisible())
124  m_Progress.SetVisible(true);
125  m_Progress.SetMaskProgress(progress/100);
126  SetProgressText("" + progress + "%");
127 
128  }
129 
130  //------------------------------------------------------------------------------------------------
131  void FinishProgress()
132  {
133  m_Progress.SetVisible(false);
134  SetProgressText("");
135  }
136 
137  //------------------------------------------------------------------------------------------------
138  int GetSelectedItem()
139  {
140  return m_iStateSelected;
141  }
142 
143  //------------------------------------------------------------------------------------------------
144  void SetProgressText(string text)
145  {
146  m_ProgressText.SetText(text);
147 
148  }
149 
150  //------------------------------------------------------------------------------------------------
151  void SetHintVisible(bool show)
152  {
153  m_wActionHint.SetVisible(show);
154  }
155 
156  //------------------------------------------------------------------------------------------------
157  void EnableButton(bool bEnable)
158  {
159  if (!m_wRoot)
160  return;
161 
162  m_bEnabled = bEnable;
163  if (m_bEnabled)
164  {
165  m_wRoot.SetOpacity(1);
166 
167  }
168  else
169  {
170  m_wRoot.SetOpacity(0.6);
171  }
172  }
173 
174  //------------------------------------------------------------------------------------------------
175  bool IsButtonEnabled()
176  {
177  return m_bEnabled;
178  }
179 
180  //------------------------------------------------------------------------------------------------
181  override protected void OnMenuSelect()
182  {
183  if (m_bEnabled)
184  super.OnMenuSelect();
185  }
186 
187  //------------------------------------------------------------------------------------------------
188  override bool OnMouseButtonDown(Widget w, int x, int y, int button)
189  {
190  if (m_bEnabled)
191  return super.OnMouseButtonDown(w, x, y, button);
192  return false;
193  }
194 
195  //------------------------------------------------------------------------------------------------
196  override bool OnMouseButtonUp(Widget w, int x, int y, int button)
197  {
198  if (m_bEnabled)
199  return super.OnMouseButtonUp(w, x, y, button);
200 
201  return false;
202  }
203 
204  //------------------------------------------------------------------------------------------------
205  override bool OnMouseEnter(Widget w, int x, int y)
206  {
207  if (m_bEnabled)
208  {
209  m_OnHover.Invoke();
210  return super.OnMouseEnter(w, x, y);
211  }
212  return false;
213  }
214 
215  //------------------------------------------------------------------------------------------------
216  override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
217  {
218  if (m_bEnabled)
219  {
220  m_OnHoverLeave.Invoke();
221  return super.OnMouseLeave(w, enterW, x, y);
222  }
223  return false;
224  }
225 
226  //------------------------------------------------------------------------------------------------
227  override bool OnFocus(Widget w, int x, int y)
228  {
229  if (m_bEnabled)
230  return super.OnFocus(w, x, y);
231  return false;
232  }
233 
234  //------------------------------------------------------------------------------------------------
235  override bool OnFocusLost(Widget w, int x, int y)
236  {
237  if (m_bEnabled)
238  return super.OnFocusLost(w, x, y);
239  return false;
240  }
241 
242  //------------------------------------------------------------------------------------------------
243  string GetCurrentContent()
244  {
245  return m_aStates[m_iStateSelected].m_sName;
246  }
247 
248  //------------------------------------------------------------------------------------------------
251  static SCR_MultipleStatesButtonComponent GetMultipleStatesButtonComponent(string name, Widget parent, bool searchAllChildren = true)
252  {
253  auto comp = SCR_MultipleStatesButtonComponent.Cast(
254  SCR_WLibComponentBase.GetComponent(SCR_MultipleStatesButtonComponent, name, parent, searchAllChildren)
255  );
256  return comp;
257  }
258 };
259 
260 //------------------------------------------------------------------------------------------------
263 {
264  [Attribute()]
265  string m_sName;
266 
267  [Attribute()]
268  string m_sIcon;
269 
270  [Attribute("1 1 1 1", UIWidgets.ColorPicker)]
271  ref Color m_cContentColor;
272 };
SCR_MultipleStatesButtonComponent
Definition: SCR_MultipleStatesButtonComponent.c:6
m_wIcon
protected ImageWidget m_wIcon
Definition: SCR_InventoryHitZonePointUI.c:374
m_wRoot
protected Widget m_wRoot
Definition: SCR_ScenarioFrameworkLayerTaskDefend.c:59
MultipleStateButtonState
Definition: SCR_MultipleStatesButtonComponent.c:262
SCR_WLibComponentBase
Base class for all final Reforger interactive elements.
Definition: SCR_WLibComponentBase.c:4
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
m_bEnabled
private bool m_bEnabled
Definition: SCR_BaseManualCameraComponent.c:3
m_sName
protected LocalizedString m_sName
Definition: SCR_GroupIdentityComponent.c:19
m_sIcon
protected string m_sIcon
Definition: SCR_InventoryHitZonePointUI.c:373
BaseContainerProps
SCR_AIGoalReaction_Follow BaseContainerProps
Handles insects that are supposed to be spawned around selected prefabs defined in prefab names array...
Definition: SCR_AIGoalReaction.c:468