Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_GalleryComponent.c
Go to the documentation of this file.
2{
3 [Attribute("0")]
4 protected int m_iInitialItemCount;
5
6 protected int m_iSelectedItem;
7
8 [Attribute("3")]
9 protected int m_iCountShownItems;
10
11 [Attribute("true", desc: "Should movement switch between whole pages, or just individual items?")]
12 protected bool m_bMovePerPage;
13
14 [Attribute("10")]
15 protected float m_fSpacing;
16
17 [Attribute("{02155A85F2DC521F}UI/layouts/Menus/PlayMenu/PlayMenuTile.layout", UIWidgets.ResourceNamePicker, "", "layout")]
19
20 [Attribute("MouseWheelUp")]
21 protected string m_sActionLeft;
22
23 [Attribute("MouseWheelDown")]
24 protected string m_sActionRight;
25
26 [Attribute("true")]
27 protected bool m_bShowPagingHints;
28
29 [Attribute("false")]
30 protected bool m_bCycleMode;
31
32 [Attribute("0.2")]
33 protected float m_fAnimationTime;
34
35 [Attribute("true")]
37
38 [Attribute("Hint")]
39 protected string m_sHintName;
40
41 [Attribute("Content")]
42 protected string m_sContentName;
43
44 protected ref array<Widget> m_aWidgets = {};
49 protected Widget m_wRoot;
51
52 //------------------------------------------------------------------------------------------------
53 override void HandlerAttached(Widget w)
54 {
55 m_wContentRoot = w.FindAnyWidget(m_sContentName);
56 m_wRoot = w;
57
58 // Convert time to animation speed
60
61 if (m_iInitialItemCount > 0)
62 {
66 }
67
68 // Setup controls
70 if (m_PagingLeft)
71 {
72 m_PagingLeft.m_OnClicked.Insert(OnNavigationLeft);
73 m_PagingLeft.GetRootWidget().SetVisible(m_bShowNavigationArrows);
74 }
75
77 if (m_PagingRight)
78 {
79 m_PagingRight.m_OnClicked.Insert(OnNavigationRight);
80 m_PagingRight.GetRootWidget().SetVisible(m_bShowNavigationArrows);
81 }
82
84
85 GetGame().GetInputManager().AddActionListener(UIConstants.MENU_ACTION_LEFT, EActionTrigger.DOWN, OnPreviousItem);
86 GetGame().GetInputManager().AddActionListener(UIConstants.MENU_ACTION_RIGHT, EActionTrigger.DOWN, OnNextItem);
87 GetGame().GetInputManager().AddActionListener(m_sActionLeft, EActionTrigger.DOWN, OnCustomLeft);
88 GetGame().GetInputManager().AddActionListener(m_sActionRight, EActionTrigger.DOWN, OnCustomRight);
89
90 GetGame().OnInputDeviceIsGamepadInvoker().Insert(OnInputDeviceIsGamepad);
91 }
92
93 //------------------------------------------------------------------------------------------------
94 protected void OnInputDeviceIsGamepad(bool isGamepad)
95 {
97 }
98
99
100 // TODO: This method should be used everywhere, but is bugged!!!
101 //------------------------------------------------------------------------------------------------
102 void ShowPagingButtons(bool animate = true)
103 {
104 bool show = GetGame().GetInputManager().IsUsingMouseAndKeyboard() && m_aWidgets.Count() > m_iCountShownItems;
105
106 if (m_PagingLeft)
107 m_PagingLeft.SetVisible(show, animate);
108
109 if (m_PagingRight)
110 m_PagingRight.SetVisible(show, animate);
111 }
112
113 //------------------------------------------------------------------------------------------------
114 protected void UpdatePagingButtons()
115 {
117 return;
118
120
121 // In cycle mode, if paging buttons are shown, they are always enabled
122 if (m_bCycleMode)
123 {
124 m_PagingLeft.SetEnabled(true);
125 m_PagingRight.SetEnabled(true);
126 return;
127 }
128
129 int count = m_aWidgets.Count();
130 int currentItem = m_iSelectedItem;
132 {
133 count = Math.Ceil(count / m_iCountShownItems);
134 currentItem = Math.Floor(m_iSelectedItem / m_iCountShownItems);
135 }
136
137 m_PagingLeft.SetEnabled(currentItem > 0);
138 m_PagingRight.SetEnabled(currentItem < count - 1);
139 }
140
141 //------------------------------------------------------------------------------------------------
142 protected void SetupHints(int count, bool animate = true)
143 {
144 if (!m_Hint)
145 {
146 Widget hint = m_wRoot.FindAnyWidget(m_sHintName);
147 if (hint)
149 }
150
151 if (!m_Hint)
152 return;
153
154 int hintsCount = count;
155 int currentItem = m_iSelectedItem;
157 {
158 hintsCount = Math.Ceil(count / m_iCountShownItems);
159 currentItem = Math.Ceil(m_iSelectedItem / m_iCountShownItems);
160 }
161
162 m_Hint.SetItemCount(hintsCount, animate);
163 m_Hint.SetCurrentItem(currentItem);
164 }
165
166 //------------------------------------------------------------------------------------------------
167 protected void CreateWidgets(int count)
168 {
169 if (!m_wContentRoot)
170 return;
171
172 // Delete old widgets
173 foreach (Widget w: m_aWidgets)
174 {
175 if (w)
176 w.RemoveFromHierarchy();
177 }
178 m_aWidgets.Clear();
179
180 for (int i = 0; i < count; i++)
181 {
182 CreateWidget();
183 }
184
185 m_iSelectedItem = 0;
186 ShowTiles(0);
187 }
188
189 //------------------------------------------------------------------------------------------------
191 {
192 if (!m_wContentRoot)
193 return null;
194
195 Widget w = GetGame().GetWorkspace().CreateWidgets(m_sItemLayout, m_wContentRoot);
196 if (!w)
197 return null;
198
199 SetupWidget(w);
200 return w;
201 }
202
203 //------------------------------------------------------------------------------------------------
204 private void SetupWidget(Widget w)
205 {
206 // Listen on focus event
208 if (!comp)
209 {
210 comp = new SCR_EventHandlerComponent();
211 w.AddHandler(comp);
212 }
213 comp.GetOnFocus().Insert(OnItemFocused);
214
215 // Check if root is actually a button
216 ButtonWidget button = ButtonWidget.Cast(w);
217 if (!button)
218 {
219 Print("[SCR_GalleryComponent.SetupWidget] the gallery element root has to be a button,"
220 + "otherwise interactivity will not work", LogLevel.WARNING);
221 }
222
223 // Apply spacing
224 float l, t, r, b;
225 AlignableSlot.GetPadding(w, l, t, r, b);
226 AlignableSlot.SetPadding(w, m_fSpacing * 0.5, t, m_fSpacing * 0.5, b);
228
229 m_aWidgets.Insert(w);
230 }
231
232 //------------------------------------------------------------------------------------------------
233 protected void SetAnimationRate()
234 {
235 if (m_fAnimationTime <= 0)
236 m_fAnimationRate = 1000;
237 else
239 }
240
241 //------------------------------------------------------------------------------------------------
243 {
244 m_iSelectedItem = m_aWidgets.Find(w);
245
246
250
251 m_Hint.SetCurrentItem(index);
253 }
254
255 //------------------------------------------------------------------------------------------------
257 {
258 if (!m_wRoot.IsEnabledInHierarchy() || !m_wRoot.IsVisibleInHierarchy())
259 return;
260
261 int selectedItem;
262 if (m_bMovePerPage)
263 selectedItem = Math.Max(m_iSelectedItem - m_iCountShownItems, 0);
264 else
265 selectedItem = m_iSelectedItem - 1;
266
267 SetFocusedItem(selectedItem);
268 }
269
270 //------------------------------------------------------------------------------------------------
272 {
273 if (!m_wRoot.IsEnabledInHierarchy() || !m_wRoot.IsVisibleInHierarchy())
274 return;
275
276 int selectedItem;
277 if (m_bMovePerPage)
278 selectedItem = Math.Min(m_iSelectedItem + m_iCountShownItems, m_aWidgets.Count() - 1);
279 else
280 selectedItem = m_iSelectedItem + 1;
281
282 SetFocusedItem(selectedItem);
283 }
284
285 //------------------------------------------------------------------------------------------------
287 {
288 if (!m_wRoot.IsEnabledInHierarchy() || !m_wRoot.IsVisibleInHierarchy())
289 return;
290
292 }
293
294 //------------------------------------------------------------------------------------------------
296 {
297 if (!m_wRoot.IsEnabledInHierarchy() || !m_wRoot.IsVisibleInHierarchy())
298 return;
299
301 }
302
303 //------------------------------------------------------------------------------------------------
304 protected void OnNextItem()
305 {
306 if (!m_wRoot.IsEnabledInHierarchy() || !m_wRoot.IsVisibleInHierarchy())
307 return;
308
309 int nextItem = m_iSelectedItem + 1;
310 if (nextItem >= m_aWidgets.Count())
311 return;
312
313 if (!m_aWidgets[nextItem].IsEnabled())
314 SetFocusedItem(nextItem);
315 }
316
317 //------------------------------------------------------------------------------------------------
318 protected void OnPreviousItem()
319 {
320 if (!m_wRoot.IsEnabledInHierarchy() || !m_wRoot.IsVisibleInHierarchy())
321 return;
322
323 int previousItem = m_iSelectedItem - 1;
324 if (previousItem < 0)
325 return;
326
327 if (!m_aWidgets[previousItem].IsEnabled())
328 SetFocusedItem(previousItem);
329 }
330
331 //------------------------------------------------------------------------------------------------
332 void SetFocusedItem(int index, bool force = false)
333 {
334 index = Math.ClampInt(index, 0, m_aWidgets.Count() - 1);
335 if ((!force && m_iSelectedItem == index) || index < 0)
336 return;
337
338 bool moveRight;
340 moveRight = true;
341
343 //if (m_Hint)
344 //m_Hint.SetCurrentItem(m_iSelectedItem);
345
347 {
348 int firstShownTile = m_iSelectedItem;
350 {
351 firstShownTile = Math.Floor(firstShownTile / m_iCountShownItems) * m_iCountShownItems;
352 }
353 else
354 {
355 if (moveRight)
356 firstShownTile = m_iSelectedItem - m_iCountShownItems + 1;
357 }
358
359 ShowTiles(firstShownTile);
360 }
361
362 GetGame().GetWorkspace().SetFocusedWidget(m_aWidgets[m_iSelectedItem]);
363 }
364
365 //------------------------------------------------------------------------------------------------
366 protected void ShowTiles(int startingIndex, bool animate = true)
367 {
368 foreach (int i, Widget w : m_aWidgets)
369 {
370 bool setVisible = i >= startingIndex && i < (startingIndex + m_iCountShownItems);
371 w.SetEnabled(setVisible);
372 w.SetVisible(setVisible);
373 }
374
375 // TODO: Implement any animation for the widget gallery
376 }
377
378 /*
379 //------------------------------------------------------------------------------------------------
380 protected void ExpandWidget(Widget widget, bool expand, bool animate = true)
381 {
382 if (!widget)
383 return;
384
385 if (animate && m_fAnimationRate < 1000)
386 {
387 LayoutSlot.SetFillWeight(widget, !expand);
388 AnimateWidget.LayoutFill(widget, expand, m_fAnimationRate);
389 }
390 else
391 {
392 LayoutSlot.SetFillWeight(widget, !expand);
393 }
394 }
395 */
396
397 // Public API
398 //------------------------------------------------------------------------------------------------
399 int GetWidgets(out array<Widget> widgets)
400 {
401 if (widgets)
402 widgets = m_aWidgets;
403
404 return m_aWidgets.Count();
405 }
406
407 //------------------------------------------------------------------------------------------------
409 {
410 Widget w = CreateWidget();
412 SetupHints(m_aWidgets.Count());
413 return w;
414 }
415
416 //------------------------------------------------------------------------------------------------
417 int AddItem(Widget widget)
418 {
419 if (!widget)
420 return -1;
421
422 m_wContentRoot.AddChild(widget);
423 SetupWidget(widget);
425
426 int count = m_aWidgets.Count();
427 SetupHints(count);
428 return count;
429 }
430
431 //------------------------------------------------------------------------------------------------
432 void ClearAll()
433 {
434 CreateWidgets(0);
435 SetupHints(0);
436 }
437
438 //------------------------------------------------------------------------------------------------
439 void RemoveItem(int item)
440 {
441 if (item < 0 || item >= m_aWidgets.Count())
442 return;
443
444 Widget w = m_aWidgets[item];
445 w.RemoveFromHierarchy();
446 m_aWidgets.Remove(item);
447
448 SetupHints(m_aWidgets.Count());
449 }
450
451 //------------------------------------------------------------------------------------------------
452 void SetCurrentItem(int i, bool animate = false)
453 {
455 }
456
457 //------------------------------------------------------------------------------------------------
460 static SCR_GalleryComponent GetGalleryComponent(string name, Widget parent, bool searchAllChildren = true)
461 {
462 if (!parent || name == string.Empty)
463 return null;
464
465 Widget w;
466 if (searchAllChildren)
467 w = parent.FindAnyWidget(name);
468 else
469 w = parent.FindWidget(name);
470
471 if (!w)
472 return null;
473
475 return comp;
476 }
477};
ArmaReforgerScripted GetGame()
Definition game.c:1398
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition Math.c:13
static SCR_PagingButtonComponent GetPagingButtonComponent(string name, Widget parent, bool searchAllChildren=true)
Base class for all final Reforger interactive elements.
static const float START_ANIMATION_PERIOD
static const float START_ANIMATION_RATE
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
LogLevel
Enum with severity of the logging message.
Definition LogLevel.c:14
SCR_FieldOfViewSettings Attribute
int IsEnabled()
Returns true if the light is enabled.
EActionTrigger