Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_MultipleStatesButtonComponent.c
Go to the documentation of this file.
1
3// 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()]
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
34
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)
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 //------------------------------------------------------------------------------------------------
113 {
114 m_Progress.SetVisible(true);
115 m_Progress.SetMaskProgress(0);
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 //------------------------------------------------------------------------------------------------
132 {
133 m_Progress.SetVisible(false);
134 SetProgressText("");
135 }
136
137 //------------------------------------------------------------------------------------------------
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 //------------------------------------------------------------------------------------------------
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 //------------------------------------------------------------------------------------------------
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_AIAnimation_Loitering BaseContainerProps
Commanding menu commanding element class.
LocalizedString m_sName
Definition Color.c:13
Base class for any button, regardless its own content.
static SCR_MultipleStatesButtonComponent GetMultipleStatesButtonComponent(string name, Widget parent, bool searchAllChildren=true)
override bool OnFocus(Widget w, int x, int y)
override bool OnClick(Widget w, int x, int y, int button)
override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
override bool OnFocusLost(Widget w, int x, int y)
override bool OnMouseButtonUp(Widget w, int x, int y, int button)
override bool OnMouseEnter(Widget w, int x, int y)
override bool OnMouseButtonDown(Widget w, int x, int y, int button)
ref array< ref MultipleStateButtonState > m_aStates
Base class for all final Reforger interactive elements.
SCR_FieldOfViewSettings Attribute
ScriptInvokerBase< func > ScriptInvoker
Definition tools.c:134