Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_TabViewComponent.c
Go to the documentation of this file.
1 void ScriptInvokerTabViewMethod(SCR_TabViewComponent tabView, Widget widget);
3 typedef ScriptInvokerBase<ScriptInvokerTabViewMethod> ScriptInvokerTabView;
4 
5 void ScriptInvokerTabViewIndexMethod(SCR_TabViewComponent tabView, Widget widget, int index);
7 typedef ScriptInvokerBase<ScriptInvokerTabViewIndexMethod> ScriptInvokerTabViewIndex;
8 
9 void ScriptInvokerTabViewContentIndexMethod(SCR_TabViewComponent tabView, SCR_TabViewContent tabContent, int index);
11 typedef ScriptInvokerBase<ScriptInvokerTabViewContentIndexMethod> ScriptInvokerTabViewContentIndex;
12 
14 {
15  [Attribute("", UIWidgets.Object, "")]
16  protected ref array<ref SCR_TabViewContent> m_aElements;
17 
18  [Attribute("0", UIWidgets.EditBox, "Element selected by default")]
19  int m_iSelectedTab;
20 
21  [Attribute("", UIWidgets.ColorPicker, "Color of gaps between tabs")]
22  ref Color m_ColorBackground;
23 
24  [Attribute("0", UIWidgets.CheckBox, "Do not delete tabs, which are hidden")]
25  bool m_bKeepHiddenTabs;
26 
27  [Attribute("false", UIWidgets.CheckBox, "Create all tabs on initialization, do not wait for first selection")]
28  bool m_bCreateAllTabsAtStart;
29 
30  [Attribute("false", UIWidgets.CheckBox, "Do not initialize yourself. This is for initialization by supermenu.")]
31  bool m_bManualInit;
32 
33  [Attribute("0", UIWidgets.CheckBox, "Do not delete tabs, which are hidden")]
34  bool m_bCycleMode;
35 
36  [Attribute("{668B05FDEF1D3268}UI/layouts/WidgetLibrary/WLib_TabViewElement.layout", UIWidgets.ResourceNamePicker, "Layout element used", "layout")]
37  ResourceName m_TabLayout;
38 
39  [Attribute("true")]
40  protected bool m_ListenToActions;
41 
42  [Attribute("MenuTabRight", UIWidgets.EditBox, "Action used for navigating left")]
43  string m_sActionLeft;
44 
45  [Attribute("MenuTabLeft", UIWidgets.EditBox, "Action used for navigating right")]
46  string m_sActionRight;
47 
48  [Attribute("300", UIWidgets.EditBox, "Select tab width. Use -1 to use fill mode")]
49  float m_fTabWidth;
50 
51  [Attribute("32", UIWidgets.EditBox, "Select tab width. Use -1 to use fill mode")]
52  float m_fTabWidthTextHidden;
53 
54  [Attribute(SCR_SoundEvent.TAB_SWITCH, UIWidgets.EditBox)]
55  protected string m_sSwitchSound;
56 
57  [Attribute("0", desc: "If true it will hide the text of the tab and only show it when the tab is selected. Tabs should have images otherwise it might look weird")]
58  protected bool m_bShowTextOnlyWhenSelectedTab;
59 
60  protected Widget m_wButtons;
61  protected Widget m_wButtonBar;
62  protected Widget m_wContentOverlay;
63  protected SCR_PagingButtonComponent m_PagingLeft;
64  protected SCR_PagingButtonComponent m_PagingRight;
65 
66  // Invokers
67  protected ref ScriptInvokerTabViewIndex m_OnChanged;
68  protected ref ScriptInvokerTabViewIndex m_OnContentCreate;
69 
70  protected ref ScriptInvokerTabView m_OnContentShow;
71  protected ref ScriptInvokerTabView m_OnContentHide;
72  protected ref ScriptInvokerTabView m_OnContentRemove;
73  protected ref ScriptInvokerTabView m_OnTabChange;
74 
75  //--- Called when a tab is selected, no matter if any content widget is tied to it
76  protected ref ScriptInvokerTabViewContentIndex m_OnContentSelect;
77 
78  protected const float BUTTON_PADDING_RIGHT = 4;
79 
80  //------------------------------------------------------------------------------------------------
81  override void HandlerAttached(Widget w)
82  {
83  super.HandlerAttached(w);
84  if (!m_bManualInit)
85  Init();
86  }
87 
88  //------------------------------------------------------------------------------------------------
89  void Init()
90  {
91  // Prevent multiple initialization
92  if (!m_wRoot || m_wButtonBar)
93  return;
94 
95  m_wButtonBar = m_wRoot.FindAnyWidget("HorizontalLayout0");
96  m_wButtons = m_wRoot.FindAnyWidget("Tabs");
97  m_wContentOverlay = m_wRoot.FindAnyWidget("ContentOverlay");
98 
100  return;
101 
102  m_PagingLeft = SCR_PagingButtonComponent.GetPagingButtonComponent("PagingLeft", m_wRoot);
103  m_PagingRight = SCR_PagingButtonComponent.GetPagingButtonComponent("PagingRight", m_wRoot);
104 
105  if (!m_aElements)
106  return;
107 
108  foreach (int i, SCR_TabViewContent content : m_aElements)
109  {
110  CreateTab(content);
112  CreateTabContent(content, i);
113  }
114 
115  int realSelected = m_iSelectedTab;
116  m_iSelectedTab = -1;
117  ShowTab(realSelected, true, false);
118 
119  if (m_PagingLeft)
120  m_PagingLeft.SetAction(m_sActionLeft);
121 
122  if (m_PagingRight)
123  m_PagingRight.SetAction(m_sActionRight);
124 
125  AddActionListeners();
126  UpdatePagingButtons();
127 
128  if (m_bShowTextOnlyWhenSelectedTab)
129  ShowAllTabsText(false, m_fTabWidthTextHidden);
130  }
131 
132  //------------------------------------------------------------------------------------------------
133  override void HandlerDeattached(Widget w)
134  {
135  super.HandlerDeattached(w);
136  RemoveActionListeners();
137  }
138 
139  //------------------------------------------------------------------------------------------------
140  void CreateTab(SCR_TabViewContent content)
141  {
142  // Create tab button
143  Widget button = GetGame().GetWorkspace().CreateWidgets(m_TabLayout, m_wButtons);
144  if (!button)
145  return;
146 
147  HorizontalLayoutSlot.SetPadding(button, 0, 0, BUTTON_PADDING_RIGHT, 0); // Add padding
148 
150  if (!comp)
151  return;
152 
153  if (!content.m_bEnabled)
154  comp.SetEnabled(false, false);
155 
156  if (m_fTabWidth < 0)
157  {
158  LayoutSlot.SetSizeMode(button, LayoutSizeMode.Fill);
159  content.m_wLayout = SizeLayoutWidget.Cast(button.GetChildren());
160  }
161  else
162  {
163  SizeLayoutWidget layout = SizeLayoutWidget.Cast(button.GetChildren());
164  content.m_wLayout = layout;
165  if (layout)
166  {
167  layout.EnableWidthOverride(true);
168  layout.SetWidthOverride(m_fTabWidth);
169  }
170  }
171 
172  comp.m_OnClicked.Insert(OnSelection);
173  comp.m_OnToggled.Insert(OnTabButtonToggle);
174  comp.SetTextWithParam(content.m_sTabButtonContent, content.m_sTabButtonContentParam1, content.m_sTabButtonContentParam2);
175  content.m_ButtonComponent = comp;
176 
177  ImageWidget image = ImageWidget.Cast(button.FindAnyWidget("TabImage"));
178  if (image)
179  {
180  image.SetVisible(content.m_bShowImage);
181  if (content.m_bShowImage)
182  SCR_WLibComponentBase.SetTexture(image, content.m_TabImage, content.m_sTabImageName);
183  }
184 
185  Widget imageSize = button.FindAnyWidget("SizeTabImage");
186  if (imageSize)
187  imageSize.SetVisible(content.m_bShowImage);
188 
189  if (content.m_bShowIcon)
190  CreateIcon(content);
191  }
192 
193  //------------------------------------------------------------------------------------------------
194  protected void CreateIcon(SCR_TabViewContent content)
195  {
196  Widget overlay = content.m_ButtonComponent.GetRootWidget().FindAnyWidget("Overlay");
197  if (!overlay)
198  return;
199 
200  SizeLayoutWidget size = SizeLayoutWidget.Cast(GetGame().GetWorkspace().CreateWidget(WidgetType.SizeLayoutWidgetTypeID, WidgetFlags.VISIBLE, Color.FromInt(Color.WHITE), 0, overlay));
201  if (!size)
202  return;
203 
204  float width = content.m_fIconWidth;
205  float height = content.m_fIconHeight;
206 
207  size.EnableWidthOverride(true);
208  size.EnableHeightOverride(true);
209  size.SetWidthOverride(width);
210  size.SetHeightOverride(height);
211 
212  OverlaySlot.SetVerticalAlign(size, LayoutVerticalAlign.Top);
213  OverlaySlot.SetHorizontalAlign(size, LayoutHorizontalAlign.Right);
214  OverlaySlot.SetPadding(size, 0, -height * 0.5, BUTTON_PADDING_RIGHT, 0); // Set some reasonable offset for the icon
215 
216  content.m_wIcon = GetGame().GetWorkspace().CreateWidgets(content.m_IconLayout, size);
217  }
218 
219  //------------------------------------------------------------------------------------------------
220  protected void CreateTabContent(SCR_TabViewContent content, int index)
221  {
222  ResourceName path = content.m_ElementLayout;
223  if (path == string.Empty)
224  return;
225 
226  Widget w = GetGame().GetWorkspace().CreateWidgets(path, m_wContentOverlay);
227  if (!w)
228  return;
229 
230  OverlaySlot.SetVerticalAlign(w, LayoutVerticalAlign.Stretch);
231  OverlaySlot.SetHorizontalAlign(w, LayoutHorizontalAlign.Stretch);
232 
233  if (m_OnContentCreate)
234  m_OnContentCreate.Invoke(this, w, index);
235 
236  content.m_wTab = w;
237 
238  int i = m_aElements.Find(content);
239  if (i != m_iSelectedTab)
240  {
241  w.SetVisible(false);
242  }
243  else
244  {
245  FocusFirstWidget(w);
246 
247  if (m_OnContentShow)
248  m_OnContentShow.Invoke(this, w);
249  }
250 
251  SCR_MenuHelper.OnTabChange(ChimeraMenuBase.GetOwnerMenu(m_wRoot));
252 
253  if (m_OnTabChange)
254  m_OnTabChange.Invoke(this, w);
255  }
256 
257  //------------------------------------------------------------------------------------------------
258  void FocusFirstWidget(Widget w)
259  {
260  Widget child = w;
261  while (child)
262  {
263  ButtonWidget button = ButtonWidget.Cast(child);
264  if (button && button.IsEnabled())
265  {
266  GetGame().GetWorkspace().SetFocusedWidget(button);
267  return;
268  }
269 
270  child = child.GetChildren();
271  }
272  }
273 
274  //------------------------------------------------------------------------------------------------
275  void ShowIcon(int entry, bool show)
276  {
277  if (entry < 0 || entry >= m_aElements.Count())
278  return;
279 
280  Widget w = m_aElements[entry].m_wIcon;
281  if (w)
282  w.SetVisible(show);
283  else if (show)
284  CreateIcon(m_aElements[entry]);
285  }
286 
287  //------------------------------------------------------------------------------------------------
288  bool IsIconShown(int entry)
289  {
290  if (entry < 0 || entry >= m_aElements.Count())
291  return false;
292 
293  Widget w = m_aElements[entry].m_wIcon;
294  if (w && w.IsVisible())
295  return true;
296 
297  return false;
298  }
299 
300  //------------------------------------------------------------------------------------------------
301  Widget GetEntryIcon(int entry)
302  {
303  if (entry < 0 || entry > m_aElements.Count())
304  return null;
305 
306  return m_aElements[entry].m_wIcon;
307  }
308 
309  //------------------------------------------------------------------------------------------------
310  SCR_TabViewContent GetEntryContent(int index)
311  {
312  if (index < 0 || index >= m_aElements.Count())
313  return null;
314 
315  return m_aElements[index];
316  }
317 
318  //------------------------------------------------------------------------------------------------
319  array<ref SCR_TabViewContent> GetContents()
320  {
321  return m_aElements;
322  }
323 
324  //------------------------------------------------------------------------------------------------
325  protected void SelectIndex(bool select, int i)
326  {
327  if (!m_aElements || i < 0 || i >= m_aElements.Count())
328  return;
329 
330  SCR_TabViewContent content = m_aElements[i];
331  if (!content)
332  return;
333 
334  if (!content.m_ButtonComponent)
335  return;
336 
337  content.m_ButtonComponent.SetToggled(select, false);
338 
339  Widget tab = content.m_wTab;
340  if (select)
341  {
342  if (m_bKeepHiddenTabs && tab)
343  {
344  if (m_OnContentShow)
345  m_OnContentShow.Invoke(this, tab);
346 
347  tab.SetVisible(true);
348  FocusFirstWidget(tab);
349  }
350  else
351  {
352  CreateTabContent(content, i);
353  }
354 
355  if (m_OnContentSelect)
356  m_OnContentSelect.Invoke(this, content, i);
357  }
358  else
359  {
360  if (!tab)
361  return;
362 
363  if (m_bKeepHiddenTabs)
364  {
365  if (m_OnContentHide)
366  m_OnContentHide.Invoke(this, tab);
367 
368  tab.SetVisible(false);
369  }
370  else
371  {
372  if (m_OnContentRemove)
373  m_OnContentRemove.Invoke(this, tab);
374 
375  tab.RemoveFromHierarchy();
376  }
377  }
378 
379  SCR_MenuHelper.OnTabChange(ChimeraMenuBase.GetOwnerMenu(m_wRoot));
380 
381  if (m_OnTabChange)
382  m_OnTabChange.Invoke(this, tab);
383  }
384 
385  //------------------------------------------------------------------------------------------------
386  void ShowTab(int i, bool callAction = true, bool playSound = true)
387  {
388  if (i == m_iSelectedTab)
389  callAction = false;
390 
392  {
393  ShowTabText(i, true, m_fTabWidth);
394  ShowTabText(m_iSelectedTab, false, m_fTabWidthTextHidden);
395  }
396 
397  // Do not switch into invalid or disabled element
398  if (i < 0 || i >= m_aElements.Count() || !m_aElements[i].m_bEnabled)
399  return;
400 
401  // Deselect old tab, select new tab
402  SelectIndex(false, m_iSelectedTab);
403  m_iSelectedTab = i;
404  SelectIndex(true, i);
405 
406  if (playSound)
407  SCR_UISoundEntity.SoundEvent(m_sSwitchSound);
408 
409  if (callAction && m_OnChanged)
410  m_OnChanged.Invoke(this, m_wRoot, m_iSelectedTab);
411 
412  UpdatePagingButtons();
413  }
414 
415  //------------------------------------------------------------------------------------------------
416  void ShowTabByIdentifier(string identifier, bool callAction = true, bool playSound = true)
417  {
418  for (int i = 0; i < m_aElements.Count(); i++)
419  {
420  if (m_aElements[i].m_sTabIdentifier == identifier)
421  {
422  ShowTab(i, callAction, playSound);
423  return;
424  }
425  }
426  }
427 
428  //------------------------------------------------------------------------------------------------
429  int GetShownTab()
430  {
431  return m_iSelectedTab;
432  }
433 
434  //------------------------------------------------------------------------------------------------
435  int GetTabCount()
436  {
437  return m_aElements.Count();
438  }
439 
440  //------------------------------------------------------------------------------------------------
441  void AddTab(ResourceName layout, string content, bool enabled = true, ResourceName tabImage = string.Empty, ResourceName iconLayout = string.Empty, float width = 32, float height = 32, string contentParam1 = string.Empty, string contentParam2 = string.Empty, string identifier = string.Empty)
442  {
443  SCR_TabViewContent tabContent = new SCR_TabViewContent;
444  tabContent.m_ElementLayout = layout;
445  tabContent.m_bEnabled = enabled;
446  tabContent.m_sTabButtonContent = content;
447  tabContent.m_sTabButtonContentParam1 = contentParam1;
448  tabContent.m_sTabButtonContentParam2 = contentParam2;
449  tabContent.m_sTabIdentifier = identifier;
450 
451  if (iconLayout != string.Empty)
452  {
453  tabContent.m_bShowIcon = true;
454  tabContent.m_IconLayout = iconLayout;
455  tabContent.m_fIconWidth = width;
456  tabContent.m_fIconHeight = height;
457  }
458 
459  if (!tabImage.IsEmpty())
460  {
461  tabContent.m_TabImage = tabImage;
462  tabContent.m_bShowImage = true;
463  }
464 
465  m_aElements.Insert(tabContent);
466 
467  // If tabView wasn't initialized do not create anything
468  if (!m_wButtonBar)
469  return;
470 
471  // Create button
472  CreateTab(tabContent);
473 
474  if (m_bCreateAllTabsAtStart)
475  CreateTabContent(tabContent, m_aElements.Count() - 1);
476 
477  UpdatePagingButtons();
478  }
479 
480  //------------------------------------------------------------------------------------------------
481  void RemoveTab(int index)
482  {
483  SCR_TabViewContent content = m_aElements[index];
484  if (!content)
485  return;
486 
487  // Always remove ordered
488  if (content.m_ButtonComponent)
489  {
490  Widget button = content.m_ButtonComponent.GetRootWidget();
491  if (button)
492  button.RemoveFromHierarchy();
493  }
494 
495  Widget tab = content.m_wTab;
496  if (tab)
497  {
498  if (m_OnContentHide)
499  m_OnContentHide.Invoke(this, tab);
500 
501  if (m_OnContentRemove)
502  m_OnContentRemove.Invoke(this, tab);
503 
504  content.m_wTab.RemoveFromHierarchy();
505  }
506 
507  SCR_TabViewContent currentContent = m_aElements[m_iSelectedTab];
508 
509  m_aElements.RemoveOrdered(index);
510 
511  int newIndex = m_aElements.Find(currentContent);
512 
513  if (index == m_iSelectedTab)
514  ShowTab(0, true);
515  else
516  ShowTab(newIndex, true);
517 
518  UpdatePagingButtons();
519  }
520 
521  //------------------------------------------------------------------------------------------------
522  void RemoveTabByIdentifier(string identifier)
523  {
524  for (int i = 0; i < m_aElements.Count(); i++)
525  {
526  if (m_aElements[i].m_sTabIdentifier == identifier)
527  {
528  RemoveTab(i);
529  return;
530  }
531  }
532  }
533 
534  //------------------------------------------------------------------------------------------------
535  void AddContentElement(SCR_TabViewContent content)
536  {
537  m_aElements.Insert(content);
538  }
539 
540  //------------------------------------------------------------------------------------------------
541  void ShowTabText(int index, bool show, int buttonWidth = -1)
542  {
543  if (index < 0 || index >= m_aElements.Count())
544  return;
545 
546  m_aElements[index].m_ButtonComponent.GetTextWidget().SetVisible(show);
547 
548  if (buttonWidth > 0 && m_aElements[index].m_wLayout)
549  {
550  if (m_aElements[index].m_wLayout)
551  {
552  m_aElements[index].m_wLayout.EnableWidthOverride(true);
553  m_aElements[index].m_wLayout.SetWidthOverride(buttonWidth);
554  }
555  }
556  }
557 
558  //------------------------------------------------------------------------------------------------
559  void ShowAllTabsText(bool show, int buttonWidth = -1, bool ignoreSelected = true)
560  {
561  if (ignoreSelected)
562  {
563  for (int i = 0; i < m_aElements.Count(); i++)
564  {
565  if (i != m_iSelectedTab)
566  ShowTabText(i, show, buttonWidth);
567  }
568  }
569  else
570  {
571  for (int i = 0; i < m_aElements.Count(); i++)
572  {
573  ShowTabText(i, show, buttonWidth);
574  }
575  }
576  }
577 
578  //------------------------------------------------------------------------------------------------
579  void SetTabText(int index, string text, string textParam1 = string.Empty, string textParam2 = string.Empty)
580  {
581  if (index < 0 || index >= m_aElements.Count())
582  return;
583 
584  m_aElements[index].m_sTabButtonContent = text;
585  m_aElements[index].m_sTabButtonContentParam1 = textParam1;
586  m_aElements[index].m_sTabButtonContentParam2 = textParam2;
587 
588  m_aElements[index].m_ButtonComponent.GetTextWidget().SetTextFormat(text, textParam1, textParam2);
589  }
590 
591  //------------------------------------------------------------------------------------------------
592  void SetTabImage(int index, ResourceName tabImage)
593  {
594  if (index < 0 || index >= m_aElements.Count())
595  return;
596 
597  m_aElements[index].m_TabImage = tabImage;
598  m_aElements[index].m_bShowImage = true;
599 
600  Widget tabRoot = m_aElements[index].m_ButtonComponent.GetRootWidget();
601 
602  ImageWidget image = ImageWidget.Cast(tabRoot.FindAnyWidget("TabImage"));
603  if (image)
604  {
605  image.LoadImageTexture(0, tabImage);
606  image.SetVisible(true);
607  }
608 
609  Widget imageSize = tabRoot.FindAnyWidget("SizeTabImage");
610  if (imageSize)
611  imageSize.SetVisible(true);
612  }
613 
614  //------------------------------------------------------------------------------------------------
615  void ShowImage(int index, bool show)
616  {
617  if (index < 0 || index >= m_aElements.Count())
618  return;
619 
620  Widget tabRoot = m_aElements[index].m_ButtonComponent.GetRootWidget();
621 
622  ImageWidget image = ImageWidget.Cast(tabRoot.FindAnyWidget("TabImage"));
623  if (image)
624  image.SetVisible(show);
625 
626  Widget imageSize = tabRoot.FindAnyWidget("SizeTabImage");
627  if (imageSize)
628  imageSize.SetVisible(show);
629  }
630 
631  //------------------------------------------------------------------------------------------------
632  protected void OnSelection(SCR_ButtonBaseComponent button)
633  {
634  for (int i = 0, len = m_aElements.Count(); i < len; i++)
635  {
636  // Deselect the old button, select the new button
637  if (m_aElements[i].m_ButtonComponent != button)
638  continue;
639 
640  // Prevent change when clicking same button
641  if (m_iSelectedTab == i)
642  {
643  m_aElements[i].m_ButtonComponent.SetToggled(true);
644  return;
645  }
646 
647  ShowTab(i);
648  return;
649  }
650  }
651 
652  //------------------------------------------------------------------------------------------------
655  protected void OnTabButtonToggle(SCR_ButtonBaseComponent button, bool isToggled)
656  {
657  if (!button)
658  return;
659 
660  SCR_ModularButtonComponent modularButton = SCR_ModularButtonComponent.Cast(button.GetRootWidget().FindHandler(SCR_ModularButtonComponent));
661  if (modularButton)
662  modularButton.SetToggled(isToggled);
663  }
664 
665  //------------------------------------------------------------------------------------------------
666  protected void OnTabLeft()
667  {
668  if (!m_ListenToActions)
669  return;
670 
671  int i = GetNextValidItem(true);
672  if (i >= 0)
673  ShowTab(i);
674  }
675 
676  //------------------------------------------------------------------------------------------------
677  protected void OnTabRight()
678  {
679  if (!m_ListenToActions)
680  return;
681 
682  int i = GetNextValidItem(false);
683  if (i >= 0)
684  ShowTab(i);
685  }
686 
687  //------------------------------------------------------------------------------------------------
689  protected void UpdatePagingButtons(bool animate = true)
690  {
691  if (m_PagingLeft)
692  m_PagingLeft.SetEnabled(GetNextValidItem(true) > -1 && m_ListenToActions, animate);
693  if (m_PagingRight)
694  m_PagingRight.SetEnabled(GetNextValidItem(false) > -1 && m_ListenToActions, animate);
695  }
696 
697  //------------------------------------------------------------------------------------------------
698  int GetNextValidItem(bool toLeft)
699  {
700  if (m_aElements.IsEmpty())
701  return -1;
702 
703  SCR_ButtonTextComponent selectedElement;
704  int lastIndex = m_aElements.Count() - 1;
705 
706  int i = m_iSelectedTab;
707  int foundItem = -1;
708  int nextItem = 1;
709  if (toLeft)
710  nextItem = -1;
711 
712  while (foundItem < 0)
713  {
714  i += nextItem;
715  if (i < 0)
716  {
717  if (m_bCycleMode)
718  i = lastIndex;
719  else
720  return -1;
721 
722  }
723  else if (i > lastIndex)
724  {
725  if (m_bCycleMode)
726  i = 0;
727  else
728  return -1;
729  }
730 
731  if (m_iSelectedTab >= 0 && m_iSelectedTab >= lastIndex && m_aElements[m_iSelectedTab] == m_aElements[i])
732  return -1; // Went through all elements, found nothing
733 
734  if (m_aElements[i].m_bEnabled)
735  foundItem = i;
736  }
737  return foundItem;
738  }
739 
740  //------------------------------------------------------------------------------------------------
741  void EnableTab(int tabIndex, bool enable, bool animate = true)
742  {
743  if (tabIndex < 0 || tabIndex >= m_aElements.Count())
744  return;
745 
746  SCR_TabViewContent tab = m_aElements[tabIndex];
747  if (!tab)
748  return;
749 
750  if (!tab.m_ButtonComponent)
751  return;
752 
753  tab.m_ButtonComponent.SetEnabled(enable, animate);
754  tab.m_bEnabled = tab.m_ButtonComponent.IsVisible() && tab.m_ButtonComponent.IsEnabled();
755 
756  UpdatePagingButtons();
757  }
758 
759  //------------------------------------------------------------------------------------------------
760  void EnableAllTabs(bool enable, bool ignoreCurrentActive = true, bool animate = true)
761  {
762  int count = m_aElements.Count();
763 
764  for (int i = 0; i < count; i++)
765  {
766  if (ignoreCurrentActive && m_iSelectedTab == i)
767  continue;
768 
769  EnableTab(i, enable, animate);
770  }
771  }
772 
773  //------------------------------------------------------------------------------------------------
774  void SetTabVisible(int tabIndex, bool visible, bool animate = true)
775  {
776  if (tabIndex < 0 || tabIndex >= m_aElements.Count())
777  return;
778 
779  SCR_TabViewContent tab = m_aElements[tabIndex];
780  if (!tab)
781  return;
782 
783  if (!tab.m_ButtonComponent)
784  return;
785 
786  tab.m_ButtonComponent.SetVisible(visible, animate);
787  tab.m_bEnabled = tab.m_ButtonComponent.IsVisible() && tab.m_ButtonComponent.IsEnabled();
788 
789  UpdatePagingButtons();
790 
791  //~ If active tab is set invisible try to set new active tab. If fails it will keep the current tab active
792  if (!visible && tabIndex == GetShownTab())
793  {
794  for (int i = 0; i < m_aElements.Count(); i++)
795  {
796  if (!m_aElements[i].m_ButtonComponent)
797  continue;
798 
799  if (m_aElements[i].m_ButtonComponent.IsVisible() && m_aElements[i].m_ButtonComponent.IsEnabled())
800  {
801  ShowTab(i, true, animate);
802  break;
803  }
804  }
805  }
806  }
807 
808  //------------------------------------------------------------------------------------------------
809  void Enable(bool enable)
810  {
811  Widget w = m_wRoot.FindAnyWidget("ContentOverlay");
812  w.SetEnabled(enable);
813  }
814 
815  //------------------------------------------------------------------------------------------------
816  bool IsTabEnabled(int tabIndex)
817  {
818  if (tabIndex == -1 || tabIndex >= m_aElements.Count())
819  return false;
820 
821  return m_aElements[tabIndex].m_bEnabled;
822  }
823 
824  //------------------------------------------------------------------------------------------------
825  void SetCanNavigate(bool isAllowed)
826  {
827  m_ListenToActions = isAllowed;
828  }
829 
830  //------------------------------------------------------------------------------------------------
831  bool GetCanNavigate()
832  {
833  return m_ListenToActions;
834  }
835 
836  //------------------------------------------------------------------------------------------------
837  void SetListenToActions(bool isAllowed)
838  {
839  m_ListenToActions = isAllowed;
840  }
841 
842  //------------------------------------------------------------------------------------------------
843  bool GetListenToActions()
844  {
845  return m_ListenToActions;
846  }
847 
848  //------------------------------------------------------------------------------------------------
849  protected void AddActionListeners()
850  {
851  if (m_PagingLeft)
852  m_PagingLeft.m_OnActivated.Insert(OnTabLeft);
853 
854  if (m_PagingRight)
855  m_PagingRight.m_OnActivated.Insert(OnTabRight);
856  }
857 
858  //------------------------------------------------------------------------------------------------
859  protected void RemoveActionListeners()
860  {
861  if (m_PagingLeft)
862  m_PagingLeft.m_OnActivated.Remove(OnTabLeft);
863  if (m_PagingRight)
864  m_PagingRight.m_OnActivated.Remove(OnTabRight);
865  }
866 
867  //------------------------------------------------------------------------------------------------
868  SCR_TabViewContent GetShownTabComponent()
869  {
870  return m_aElements[m_iSelectedTab];
871  }
872 
873  //------------------------------------------------------------------------------------------------
874  void SetEntryIconSize(int index, float width = -1, float height = -1)
875  {
876  if (index < 0 || index >= m_aElements.Count())
877  return;
878 
879  if (width > 0)
880  m_aElements[index].m_fIconWidth = width;
881 
882  if (height > 0)
883  m_aElements[index].m_fIconHeight = height;
884  }
885 
886  //------------------------------------------------------------------------------------------------
887  void SetPagingButtonsVisible(bool visible, bool animate = true)
888  {
889  if (m_PagingLeft)
890  m_PagingLeft.SetVisible(visible, animate);
891  if (m_PagingRight)
892  m_PagingRight.SetVisible(visible, animate);
893  }
894 
895  //------------------------------------------------------------------------------------------------
896  // --- Invokers ---
897  //------------------------------------------------------------------------------------------------
898  //------------------------------------------------------------------------------------------------
899  ScriptInvokerTabViewIndex GetOnChanged()
900  {
901  if (!m_OnChanged)
903 
904  return m_OnChanged;
905  }
906 
907  //------------------------------------------------------------------------------------------------
908  ScriptInvokerTabViewIndex GetOnContentCreate()
909  {
910  if (!m_OnContentCreate)
912 
913  return m_OnContentCreate;
914  }
915 
916  //------------------------------------------------------------------------------------------------
917  ScriptInvokerTabView GetOnContentShow()
918  {
919  if (!m_OnContentShow)
921 
922  return m_OnContentShow;
923  }
924 
925  //------------------------------------------------------------------------------------------------
926  ScriptInvokerTabView GetOnContentHide()
927  {
928  if (!m_OnContentHide)
930 
931  return m_OnContentHide;
932  }
933 
934  //------------------------------------------------------------------------------------------------
935  ScriptInvokerTabView GetOnContentRemove()
936  {
937  if (!m_OnContentRemove)
939 
940  return m_OnContentRemove;
941  }
942 
943  //------------------------------------------------------------------------------------------------
944  ScriptInvokerTabView GetOnTabChange()
945  {
946  if (!m_OnTabChange)
948 
949  return m_OnTabChange;
950  }
951 
952  //------------------------------------------------------------------------------------------------
953  ScriptInvokerTabViewContentIndex GetOnContentSelect()
954  {
955  if (!m_OnContentSelect)
957 
958  return m_OnContentSelect;
959  }
960 }
961 
962 //------------------------------------------------------------------------------------------------
964 class SCR_TabViewContent
965 {
966  [Attribute("", UIWidgets.ResourceNamePicker, "Layout element used", "layout")]
967  ResourceName m_ElementLayout;
968 
969  [Attribute("Button", UIWidgets.EditBox, "Content of the button: It can contain either name or image resource")]
970  string m_sTabButtonContent;
971 
972  [Attribute("", UIWidgets.EditBox, "Unique identifier of tab used in script to look for this one - optional for now")]
973  string m_sTabIdentifier;
974 
975  [Attribute(desc: "Param if m_sTabButtonContent is name rather then image resource")]
976  LocalizedString m_sTabButtonContentParam1;
977 
978  [Attribute(desc: "Param if m_sTabButtonContent is name rather then image resource")]
979  LocalizedString m_sTabButtonContentParam2;
980 
981  [Attribute("true", UIWidgets.CheckBox, "Is tab enabled?")]
982  bool m_bEnabled;
983 
984  SCR_ButtonTextComponent m_ButtonComponent;
985  Widget m_wTab;
986  SizeLayoutWidget m_wLayout;
987 
988  [Attribute(desc: "Image shown in front of tab text", params: "edds imageset")]
989  ResourceName m_TabImage;
990 
991  [Attribute(desc: "Image name used in front of tab text when using image set")]
992  string m_sTabImageName;
993 
994  [Attribute("0")]
995  bool m_bShowImage;
996 
997  [Attribute()]
998  bool m_bShowIcon;
999 
1000  [Attribute("{6B997B683BD0FC21}UI/layouts/WidgetLibrary/TabView/WLib_TabViewInfoIcon.layout", UIWidgets.ResourceNamePicker, "", "Path to layout")]
1001  ResourceName m_IconLayout;
1002 
1003  [Attribute("32")]
1004  float m_fIconWidth;
1005 
1006  [Attribute("32")]
1007  float m_fIconHeight;
1008 
1009  Widget m_wIcon;
1010 }
ChimeraMenuBase
Constant variables used in various menus.
Definition: ChimeraMenuBase.c:70
m_OnContentSelect
protected ref ScriptInvokerTabViewContentIndex m_OnContentSelect
Definition: SCR_TabViewComponent.c:73
m_wIcon
protected ImageWidget m_wIcon
Definition: SCR_InventoryHitZonePointUI.c:374
m_OnTabChange
protected ref ScriptInvokerTabView m_OnTabChange
Definition: SCR_TabViewComponent.c:70
m_wRoot
protected Widget m_wRoot
Definition: SCR_ScenarioFrameworkLayerTaskDefend.c:59
m_wButtons
protected Widget m_wButtons
Definition: SCR_TabViewComponent.c:57
SCR_WLibComponentBase
Base class for all final Reforger interactive elements.
Definition: SCR_WLibComponentBase.c:4
m_bShowTextOnlyWhenSelectedTab
protected bool m_bShowTextOnlyWhenSelectedTab
Definition: SCR_TabViewComponent.c:55
SCR_UISoundEntity
Definition: SCR_UISoundEntity.c:7
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SCR_BaseContainerLocalizedTitleField
SCR_TabViewComponent SCR_ScriptedWidgetComponent SCR_BaseContainerLocalizedTitleField("m_sTabButtonContent")
Definition: SCR_TabViewComponent.c:963
SCR_SoundEvent
Definition: SCR_SoundEvent.c:1
m_fTabWidthTextHidden
float m_fTabWidthTextHidden
Definition: SCR_TabViewComponent.c:49
BaseContainerProps
SCR_TabViewComponent SCR_ScriptedWidgetComponent BaseContainerProps()
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
m_OnContentShow
protected ref ScriptInvokerTabView m_OnContentShow
Definition: SCR_TabViewComponent.c:67
func
func
Definition: SCR_AIThreatSystem.c:5
SCR_TabViewComponent
Definition: SCR_TabViewComponent.c:13
m_ListenToActions
protected bool m_ListenToActions
Definition: SCR_TabViewComponent.c:37
m_OnChanged
protected ref ScriptInvokerTabViewIndex m_OnChanged
Definition: SCR_TabViewComponent.c:64
ScriptInvokerTabViewContentIndexMethod
func ScriptInvokerTabViewContentIndexMethod
Definition: SCR_TabViewComponent.c:10
m_aElements
protected ref array< ref SCR_TabViewContent > m_aElements
Definition: SCR_TabViewComponent.c:13
m_iSelectedTab
int m_iSelectedTab
Definition: SCR_TabViewComponent.c:16
m_wContentOverlay
protected Widget m_wContentOverlay
Definition: SCR_TabViewComponent.c:59
SCR_PagingButtonComponent
Definition: SCR_PagingButtonComponent.c:2
Attribute
typedef Attribute
Post-process effect of scripted camera.
m_PagingRight
protected SCR_PagingButtonComponent m_PagingRight
Definition: SCR_TabViewComponent.c:61
SCR_ButtonTextComponent
Definition: SCR_ButtonTextComponent.c:2
m_fTabWidth
float m_fTabWidth
Definition: SCR_TabViewComponent.c:46
m_wButtonBar
protected Widget m_wButtonBar
Definition: SCR_TabViewComponent.c:58
SCR_ButtonBaseComponent
Base class for any button, regardless its own content.
Definition: SCR_ButtonBaseComponent.c:3
m_OnContentHide
protected ref ScriptInvokerTabView m_OnContentHide
Definition: SCR_TabViewComponent.c:68
m_TabLayout
ResourceName m_TabLayout
Definition: SCR_TabViewComponent.c:34
SCR_MenuHelper
Definition: SCR_MenuHelper.c:15
layout
UI layouts HUD CampaignMP CampaignMainHUD layout
Definition: SCR_ScenarioFrameworkLayerTaskDefend.c:20
m_PagingLeft
protected SCR_PagingButtonComponent m_PagingLeft
Definition: SCR_TabViewComponent.c:60
BUTTON_PADDING_RIGHT
const protected float BUTTON_PADDING_RIGHT
Definition: SCR_TabViewComponent.c:75
index
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
Definition: SCR_DestructionSynchronizationComponent.c:17
ScriptInvokerTabViewContentIndex
ScriptInvokerBase< ScriptInvokerTabViewContentIndexMethod > ScriptInvokerTabViewContentIndex
Definition: SCR_TabViewComponent.c:11
m_OnContentRemove
protected ref ScriptInvokerTabView m_OnContentRemove
Definition: SCR_TabViewComponent.c:69
m_OnContentCreate
protected ref ScriptInvokerTabViewIndex m_OnContentCreate
Definition: SCR_TabViewComponent.c:65
m_bCycleMode
bool m_bCycleMode
Definition: SCR_TabViewComponent.c:31
ScriptInvokerTabViewMethod
func ScriptInvokerTabViewMethod
Definition: SCR_TabViewComponent.c:2
ScriptInvokerTabViewIndex
ScriptInvokerBase< ScriptInvokerTabViewIndexMethod > ScriptInvokerTabViewIndex
Definition: SCR_TabViewComponent.c:7
m_bEnabled
private bool m_bEnabled
Definition: SCR_BaseManualCameraComponent.c:3
params
Configs ServerBrowser KickDialogs params
Definition: SCR_NotificationSenderComponent.c:24
m_bKeepHiddenTabs
bool m_bKeepHiddenTabs
Definition: SCR_TabViewComponent.c:22
SCR_ScriptedWidgetComponent
Definition: SCR_ScriptedWidgetComponent.c:7
m_bCreateAllTabsAtStart
bool m_bCreateAllTabsAtStart
Definition: SCR_TabViewComponent.c:25
LocalizedString
Definition: LocalizedString.c:21
ScriptInvokerTabView
ScriptInvokerBase< ScriptInvokerTabViewMethod > ScriptInvokerTabView
Definition: SCR_TabViewComponent.c:3
ScriptInvokerTabViewIndexMethod
func ScriptInvokerTabViewIndexMethod
Definition: SCR_TabViewComponent.c:6
m_bManualInit
bool m_bManualInit
Definition: SCR_TabViewComponent.c:28