Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_ToolboxComponent.c
Go to the documentation of this file.
1//------------------------------------------------------------------------------------------------
3{
5
6 [Attribute()]
8
9 [Attribute("{D27D044A8145DC7C}UI/layouts/WidgetLibrary/Buttons/WLib_ButtonTextUnderlined.layout", UIWidgets.ResourceNamePicker, "Layout element used", "layout")]
11
12 [Attribute("4")]
14
15 [Attribute("false", UIWidgets.CheckBox, "On last item and pressing right arrow, it will go to the start of the list")]
17
18 ref array<SCR_ButtonBaseComponent> m_aSelectionElements = new array<SCR_ButtonBaseComponent>;
20
21 //------------------------------------------------------------------------------------------------
22 override void HandlerAttached(Widget w)
23 {
24 super.HandlerAttached(w);
25 m_wButtonRow = w.FindAnyWidget("ButtonRow");
26
28 return;
29
32 }
33
34 //------------------------------------------------------------------------------------------------
35 protected void CreateWidgets()
36 {
37
38//---- REFACTOR NOTE START: This code will need to be refactored as current implementation is not conforming to the standards ----
39// Exposed an attribute, and then in the only place where it is used, changes it's value
40
41 float padding = m_fElementSpacing * 0.5;
42
43//---- REFACTOR NOTE END ----
44
45 LayoutSlot.SetPadding(m_wButtonRow, -padding, -padding, -padding, -padding);
46 foreach (string name : m_aElementNames)
47 {
48 Widget button = GetGame().GetWorkspace().CreateWidgets(m_ElementLayout, m_wButtonRow);
49 LayoutSlot.SetPadding(button, padding, padding, padding, padding);
50 LayoutSlot.SetSizeMode(button, LayoutSizeMode.Fill);
51 LayoutSlot.SetVerticalAlign(button, LayoutHorizontalAlign.Stretch);
52 LayoutSlot.SetHorizontalAlign(button, LayoutHorizontalAlign.Stretch);
53
55 if (!comp)
56 continue;
57
58 m_aSelectionElements.Insert(comp);
60 if (textComp)
61 textComp.SetText(name);
62 comp.m_OnClicked.Insert(OnElementClicked);
63 comp.m_OnToggled.Insert(OnElementChanged);
64 }
65
67 }
68
69 //------------------------------------------------------------------------------------------------
70 protected void ClearWidgets()
71 {
73 {
74 if (!element)
75 continue;
76
77 Widget w = element.GetRootWidget();
78 if (w)
79 w.RemoveFromHierarchy();
80 }
81
83 }
84
85 //------------------------------------------------------------------------------------------------
86 override bool OnFocus(Widget w, int x, int y)
87 {
88 super.OnFocus(w, x, y);
89
91 {
92 m_FocusedElement.ShowBorder(true);
93 }
94 else if (m_aSelectionElements.Count() > 0)
95 {
96 m_aSelectionElements[0].ShowBorder(true);
98 }
99
100 GetGame().GetInputManager().AddActionListener(UIConstants.MENU_ACTION_LEFT, EActionTrigger.DOWN, OnMenuLeft);
101 GetGame().GetInputManager().AddActionListener(UIConstants.MENU_ACTION_RIGHT, EActionTrigger.DOWN, OnMenuRight);
102
104 GetGame().GetInputManager().AddActionListener(UIConstants.MENU_ACTION_SELECT, EActionTrigger.DOWN, OnMenuSelect);
105
106 return false;
107 }
108
109 //------------------------------------------------------------------------------------------------
110 override bool OnFocusLost(Widget w, int x, int y)
111 {
112 super.OnFocusLost(w, x, y);
113
115 m_FocusedElement.ShowBorder(false);
116
117 GetGame().GetInputManager().RemoveActionListener(UIConstants.MENU_ACTION_LEFT, EActionTrigger.DOWN, OnMenuLeft);
118 GetGame().GetInputManager().RemoveActionListener(UIConstants.MENU_ACTION_RIGHT, EActionTrigger.DOWN, OnMenuRight);
119
121 GetGame().GetInputManager().RemoveActionListener(UIConstants.MENU_ACTION_SELECT, EActionTrigger.DOWN, OnMenuSelect);
122
123 return false;
124 }
125
126 //------------------------------------------------------------------------------------------------
127 protected void SetInitialState()
128 {
130 int realIndex = m_iSelectedItem;
131 m_iSelectedItem = -int.MAX;
132 SetCurrentItem(realIndex, false, false);
133 }
134
135 //------------------------------------------------------------------------------------------------
136 protected void OnMenuSelect()
137 {
139 m_FocusedElement.SetToggled(!m_FocusedElement.IsToggled());
140 }
141
142 //------------------------------------------------------------------------------------------------
144 {
145 foreach (int i, SCR_ButtonBaseComponent element : m_aSelectionElements)
146 {
147 if (element.IsToggled())
148 return element;
149 }
150
151 return null;
152 }
153
154 //------------------------------------------------------------------------------------------------
156 {
157 GetGame().GetWorkspace().SetFocusedWidget(m_wRoot);
158 int i = m_aSelectionElements.Find(comp);
159
161 SetFocusedItem(comp);
162 else
163 {
164 if (i == m_iSelectedItem)
165 {
166 comp.SetToggled(!comp.IsToggled(), false, false);
167 m_iSelectedItem = i;
168 }
169 else
170 {
171 SetCurrentItem(i, true, false);
172 }
173 }
174 }
175
176 //------------------------------------------------------------------------------------------------
178 {
179 // Do not invoke on false state when not having a multiselection
180 if (!m_bAllowMultiselection && !state)
181 return;
182
183 int i = m_aSelectionElements.Find(comp);
185 m_OnChanged.Invoke(this, i, state);
186 else
187 m_OnChanged.Invoke(this, i);
188 }
189
190 //------------------------------------------------------------------------------------------------
191 override bool SetCurrentItem(int i, bool playSound = false, bool animate = false)
192 {
193 int oldIndex = m_iSelectedItem;
194 int itemsCount = m_aSelectionElements.Count();
195 if (!super.SetCurrentItem(i, true, true))
196 return false;
197
198 if (!m_bAllowMultiselection && oldIndex >= 0 && oldIndex < itemsCount)
199 {
200 m_aSelectionElements[oldIndex].SetToggled(false, playSound, animate);
201 }
202
203 if (i >= 0 && i < itemsCount)
204 {
205 m_aSelectionElements[i].SetToggled(true, playSound, animate);
206 //m_OnChanged.Invoke(this, m_aSelectionElements[i].GetRootWidget(), i);
208 }
209
210 return true;
211 }
212
213 //------------------------------------------------------------------------------------------------
214 override bool OnMouseEnter(Widget w, int x, int y)
215 {
216 super.OnMouseEnter(w, x, y);
217 if (IsChildWidget(w, WidgetManager.GetWidgetUnderCursor()))
218 super.OnMouseEnter(w, x, y);
219
220 return false;
221 }
222
223 //------------------------------------------------------------------------------------------------
224 protected void OnMenuLeft()
225 {
226 int i = GetNextValidItem(true);
227 if (i < 0)
228 return;
229
232 else
233 SetCurrentItem(i, true, true);
234 }
235
236 //------------------------------------------------------------------------------------------------
237 protected void OnMenuRight()
238 {
239 int i = GetNextValidItem(false);
240 if (i < 0)
241 return;
242
245 else
246 SetCurrentItem(i, true, true);
247 }
248
249 //------------------------------------------------------------------------------------------------
250 protected int GetNextValidItem(bool toLeft)
251 {
252 if (m_aSelectionElements.IsEmpty())
253 return -1;
254
255 SCR_ButtonBaseComponent selectedElement;
256 int lastIndex = m_aSelectionElements.Count() - 1;
257
259 int foundItem = -1;
260 int nextItem = 1;
261 if (toLeft)
262 nextItem = -1;
263
264 while (foundItem < 0)
265 {
266 i += nextItem;
267 if (i < 0)
268 {
269 if (m_bCycleMode)
270 i = lastIndex;
271 else
272 return -1;
273
274 }
275 else if (i > lastIndex)
276 {
277 if (m_bCycleMode)
278 i = 0;
279 else
280 return -1;
281 }
282
284 return -1; // Went through all elements, found nothing
285
287 foundItem = i;
288 }
289 return foundItem;
290 }
291
292 //------------------------------------------------------------------------------------------------
293 int GetItems(notnull array<SCR_ButtonBaseComponent> elements)
294 {
295 elements.Clear();
296
298 elements.Insert(element);
299
300 return elements.Count();
301 }
302
304 {
306 return null;
307
309 }
310
311 //------------------------------------------------------------------------------------------------
312 override int AddItem(string item, bool last = false, Managed data = null)
313 {
314 int i = super.AddItem(item, last, data);
315 ClearWidgets();
317 return i;
318 }
319
320 //------------------------------------------------------------------------------------------------
321 override void ClearAll()
322 {
323 super.ClearAll();
324 ClearWidgets();
325 }
326
327 //------------------------------------------------------------------------------------------------
328 override void RemoveItem(int item, bool last = false)
329 {
330 super.RemoveItem(item, last);
331 ClearWidgets();
333 }
334
335 //------------------------------------------------------------------------------------------------
337 {
339 return false;
340
341 return m_aSelectionElements[index].IsToggled();
342 }
343
344 //------------------------------------------------------------------------------------------------
345 void SetItemSelected(int index, bool select, bool animate = true)
346 {
348 return;
349
351 m_aSelectionElements[index].SetToggled(select, animate, animate);
352 }
353
354 //------------------------------------------------------------------------------------------------
355 void SetFocusedItem(int index, bool animate = true)
356 {
358 return;
359
361 if (element == m_FocusedElement)
362 return;
363
364 bool focused = GetGame().GetWorkspace().GetFocusedWidget() == m_wRoot;
365
366 if (m_FocusedElement && focused)
367 m_FocusedElement.ShowBorder(false, animate);
368
369 m_FocusedElement = element;
370
371 if (focused)
372 m_FocusedElement.ShowBorder(true, animate);
373 }
374
375 //------------------------------------------------------------------------------------------------
376 void SetFocusedItem(SCR_ButtonBaseComponent element, bool animate = true)
377 {
378 if (!element || element == m_FocusedElement)
379 return;
380
381 bool focused = GetGame().GetWorkspace().GetFocusedWidget() == m_wRoot;
382
383 if (m_FocusedElement && focused)
384 m_FocusedElement.ShowBorder(false, animate);
385
386 m_FocusedElement = element;
387
388 if (focused)
389 m_FocusedElement.ShowBorder(true, animate);
390 }
391
392 //------------------------------------------------------------------------------------------------
394 {
396 }
397
398 //------------------------------------------------------------------------------------------------
401 static SCR_ToolboxComponent GetToolboxComponent(string name, Widget parent, bool searchAllChildren = true)
402 {
403 auto comp = SCR_ToolboxComponent.Cast(
404 SCR_WLibComponentBase.GetComponent(SCR_ToolboxComponent, name, parent, searchAllChildren)
405 );
406 return comp;
407 }
408};
ArmaReforgerScripted GetGame()
Definition game.c:1398
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
Get all prefabs that have the spawner data
Widget m_wRoot
Base class for any button, regardless its own content.
void SetToggled(bool toggled, bool animate=true, bool invokeChange=true, bool instant=false)
override void HandlerAttached(Widget w)
SCR_ButtonBaseComponent GetItem(int index)
SCR_ButtonBaseComponent m_FocusedElement
override int AddItem(string item, bool last=false, Managed data=null)
int GetNextValidItem(bool toLeft)
SCR_ButtonBaseComponent GetFirstSelectedIndex()
void OnElementClicked(SCR_ButtonBaseComponent comp)
ref array< SCR_ButtonBaseComponent > m_aSelectionElements
override bool OnMouseEnter(Widget w, int x, int y)
override bool SetCurrentItem(int i, bool playSound=false, bool animate=false)
static SCR_ToolboxComponent GetToolboxComponent(string name, Widget parent, bool searchAllChildren=true)
void SetFocusedItem(SCR_ButtonBaseComponent element, bool animate=true)
override bool OnFocus(Widget w, int x, int y)
void SetFocusedItem(int index, bool animate=true)
override void RemoveItem(int item, bool last=false)
override bool OnFocusLost(Widget w, int x, int y)
void OnElementChanged(SCR_ButtonBaseComponent comp, bool state)
void SetItemSelected(int index, bool select, bool animate=true)
int GetItems(notnull array< SCR_ButtonBaseComponent > elements)
Base class for all final Reforger interactive elements.
bool IsChildWidget(Widget parent, Widget child)
SCR_FieldOfViewSettings Attribute
EActionTrigger
LayoutHorizontalAlign
LayoutSizeMode