16 protected ref array<ref SCR_TabViewContent> m_aElements;
18 [
Attribute(
"0", UIWidgets.EditBox,
"Element selected by default")]
21 [
Attribute(
"", UIWidgets.ColorPicker,
"Color of gaps between tabs")]
22 ref Color m_ColorBackground;
24 [
Attribute(
"0", UIWidgets.CheckBox,
"Do not delete tabs, which are hidden")]
25 bool m_bKeepHiddenTabs;
27 [
Attribute(
"false", UIWidgets.CheckBox,
"Create all tabs on initialization, do not wait for first selection")]
28 bool m_bCreateAllTabsAtStart;
30 [
Attribute(
"false", UIWidgets.CheckBox,
"Do not initialize yourself. This is for initialization by supermenu.")]
33 [
Attribute(
"0", UIWidgets.CheckBox,
"Do not delete tabs, which are hidden")]
36 [
Attribute(
"{668B05FDEF1D3268}UI/layouts/WidgetLibrary/WLib_TabViewElement.layout", UIWidgets.ResourceNamePicker,
"Layout element used",
"layout")]
37 ResourceName m_TabLayout;
40 protected bool m_ListenToActions;
42 [
Attribute(
"MenuTabRight", UIWidgets.EditBox,
"Action used for navigating left")]
45 [
Attribute(
"MenuTabLeft", UIWidgets.EditBox,
"Action used for navigating right")]
46 string m_sActionRight;
48 [
Attribute(
"300", UIWidgets.EditBox,
"Select tab width. Use -1 to use fill mode")]
51 [
Attribute(
"32", UIWidgets.EditBox,
"Select tab width. Use -1 to use fill mode")]
52 float m_fTabWidthTextHidden;
55 protected string m_sSwitchSound;
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;
60 protected Widget m_wButtons;
61 protected Widget m_wButtonBar;
62 protected Widget m_wContentOverlay;
78 protected const float BUTTON_PADDING_RIGHT = 4;
81 override void HandlerAttached(Widget w)
83 super.HandlerAttached(w);
108 foreach (
int i, SCR_TabViewContent content :
m_aElements)
112 CreateTabContent(content, i);
117 ShowTab(realSelected,
true,
false);
125 AddActionListeners();
126 UpdatePagingButtons();
128 if (m_bShowTextOnlyWhenSelectedTab)
129 ShowAllTabsText(
false, m_fTabWidthTextHidden);
133 override void HandlerDeattached(Widget w)
135 super.HandlerDeattached(w);
136 RemoveActionListeners();
140 void CreateTab(SCR_TabViewContent content)
153 if (!content.m_bEnabled)
154 comp.SetEnabled(
false,
false);
158 LayoutSlot.SetSizeMode(button, LayoutSizeMode.Fill);
159 content.m_wLayout = SizeLayoutWidget.Cast(button.GetChildren());
163 SizeLayoutWidget
layout = SizeLayoutWidget.Cast(button.GetChildren());
164 content.m_wLayout =
layout;
167 layout.EnableWidthOverride(
true);
168 layout.SetWidthOverride(m_fTabWidth);
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;
177 ImageWidget image = ImageWidget.Cast(button.FindAnyWidget(
"TabImage"));
180 image.SetVisible(content.m_bShowImage);
181 if (content.m_bShowImage)
185 Widget imageSize = button.FindAnyWidget(
"SizeTabImage");
187 imageSize.SetVisible(content.m_bShowImage);
189 if (content.m_bShowIcon)
194 protected void CreateIcon(SCR_TabViewContent content)
196 Widget overlay = content.m_ButtonComponent.GetRootWidget().FindAnyWidget(
"Overlay");
200 SizeLayoutWidget size = SizeLayoutWidget.Cast(
GetGame().GetWorkspace().CreateWidget(WidgetType.SizeLayoutWidgetTypeID, WidgetFlags.VISIBLE, Color.FromInt(Color.WHITE), 0, overlay));
204 float width = content.m_fIconWidth;
205 float height = content.m_fIconHeight;
207 size.EnableWidthOverride(
true);
208 size.EnableHeightOverride(
true);
209 size.SetWidthOverride(width);
210 size.SetHeightOverride(height);
212 OverlaySlot.SetVerticalAlign(size, LayoutVerticalAlign.Top);
213 OverlaySlot.SetHorizontalAlign(size, LayoutHorizontalAlign.Right);
216 content.m_wIcon =
GetGame().GetWorkspace().CreateWidgets(content.m_IconLayout, size);
220 protected void CreateTabContent(SCR_TabViewContent content,
int index)
222 ResourceName path = content.m_ElementLayout;
223 if (path ==
string.Empty)
230 OverlaySlot.SetVerticalAlign(w, LayoutVerticalAlign.Stretch);
231 OverlaySlot.SetHorizontalAlign(w, LayoutHorizontalAlign.Stretch);
258 void FocusFirstWidget(Widget w)
263 ButtonWidget button = ButtonWidget.Cast(child);
264 if (button && button.IsEnabled())
266 GetGame().GetWorkspace().SetFocusedWidget(button);
270 child = child.GetChildren();
275 void ShowIcon(
int entry,
bool show)
288 bool IsIconShown(
int entry)
294 if (w && w.IsVisible())
301 Widget GetEntryIcon(
int entry)
310 SCR_TabViewContent GetEntryContent(
int index)
319 array<ref SCR_TabViewContent> GetContents()
325 protected void SelectIndex(
bool select,
int i)
334 if (!content.m_ButtonComponent)
337 content.m_ButtonComponent.SetToggled(select,
false);
339 Widget tab = content.m_wTab;
347 tab.SetVisible(
true);
348 FocusFirstWidget(tab);
352 CreateTabContent(content, i);
363 if (m_bKeepHiddenTabs)
368 tab.SetVisible(
false);
372 if (m_OnContentRemove)
375 tab.RemoveFromHierarchy();
386 void ShowTab(
int i,
bool callAction =
true,
bool playSound =
true)
398 if (i < 0 || i >=
m_aElements.Count() || !m_aElements[i].m_bEnabled)
402 SelectIndex(
false, m_iSelectedTab);
404 SelectIndex(
true, i);
409 if (callAction && m_OnChanged)
412 UpdatePagingButtons();
416 void ShowTabByIdentifier(
string identifier,
bool callAction =
true,
bool playSound =
true)
422 ShowTab(i, callAction, playSound);
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)
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;
451 if (iconLayout !=
string.Empty)
453 tabContent.m_bShowIcon =
true;
454 tabContent.m_IconLayout = iconLayout;
455 tabContent.m_fIconWidth = width;
456 tabContent.m_fIconHeight = height;
459 if (!tabImage.IsEmpty())
461 tabContent.m_TabImage = tabImage;
462 tabContent.m_bShowImage =
true;
472 CreateTab(tabContent);
474 if (m_bCreateAllTabsAtStart)
475 CreateTabContent(tabContent,
m_aElements.Count() - 1);
477 UpdatePagingButtons();
481 void RemoveTab(
int index)
488 if (content.m_ButtonComponent)
490 Widget button = content.m_ButtonComponent.GetRootWidget();
492 button.RemoveFromHierarchy();
495 Widget tab = content.m_wTab;
501 if (m_OnContentRemove)
504 content.m_wTab.RemoveFromHierarchy();
513 if (
index == m_iSelectedTab)
516 ShowTab(newIndex,
true);
518 UpdatePagingButtons();
522 void RemoveTabByIdentifier(
string identifier)
535 void AddContentElement(SCR_TabViewContent content)
541 void ShowTabText(
int index,
bool show,
int buttonWidth = -1)
559 void ShowAllTabsText(
bool show,
int buttonWidth = -1,
bool ignoreSelected =
true)
566 ShowTabText(i, show, buttonWidth);
573 ShowTabText(i, show, buttonWidth);
579 void SetTabText(
int index,
string text,
string textParam1 =
string.Empty,
string textParam2 =
string.Empty)
588 m_aElements[
index].m_ButtonComponent.GetTextWidget().SetTextFormat(text, textParam1, textParam2);
592 void SetTabImage(
int index, ResourceName tabImage)
602 ImageWidget image = ImageWidget.Cast(tabRoot.FindAnyWidget(
"TabImage"));
605 image.LoadImageTexture(0, tabImage);
606 image.SetVisible(
true);
609 Widget imageSize = tabRoot.FindAnyWidget(
"SizeTabImage");
611 imageSize.SetVisible(
true);
615 void ShowImage(
int index,
bool show)
622 ImageWidget image = ImageWidget.Cast(tabRoot.FindAnyWidget(
"TabImage"));
624 image.SetVisible(show);
626 Widget imageSize = tabRoot.FindAnyWidget(
"SizeTabImage");
628 imageSize.SetVisible(show);
634 for (
int i = 0, len =
m_aElements.Count(); i < len; i++)
660 SCR_ModularButtonComponent modularButton = SCR_ModularButtonComponent.Cast(button.GetRootWidget().FindHandler(SCR_ModularButtonComponent));
662 modularButton.SetToggled(isToggled);
666 protected void OnTabLeft()
671 int i = GetNextValidItem(
true);
677 protected void OnTabRight()
682 int i = GetNextValidItem(
false);
689 protected void UpdatePagingButtons(
bool animate =
true)
698 int GetNextValidItem(
bool toLeft)
712 while (foundItem < 0)
723 else if (i > lastIndex)
741 void EnableTab(
int tabIndex,
bool enable,
bool animate =
true)
743 if (tabIndex < 0 || tabIndex >=
m_aElements.Count())
750 if (!tab.m_ButtonComponent)
753 tab.m_ButtonComponent.SetEnabled(enable, animate);
754 tab.m_bEnabled = tab.m_ButtonComponent.IsVisible() && tab.m_ButtonComponent.IsEnabled();
756 UpdatePagingButtons();
760 void EnableAllTabs(
bool enable,
bool ignoreCurrentActive =
true,
bool animate =
true)
764 for (
int i = 0; i < count; i++)
769 EnableTab(i, enable, animate);
774 void SetTabVisible(
int tabIndex,
bool visible,
bool animate =
true)
776 if (tabIndex < 0 || tabIndex >=
m_aElements.Count())
783 if (!tab.m_ButtonComponent)
786 tab.m_ButtonComponent.SetVisible(visible, animate);
787 tab.m_bEnabled = tab.m_ButtonComponent.IsVisible() && tab.m_ButtonComponent.IsEnabled();
789 UpdatePagingButtons();
792 if (!visible && tabIndex == GetShownTab())
801 ShowTab(i,
true, animate);
809 void Enable(
bool enable)
811 Widget w =
m_wRoot.FindAnyWidget(
"ContentOverlay");
812 w.SetEnabled(enable);
816 bool IsTabEnabled(
int tabIndex)
818 if (tabIndex == -1 || tabIndex >=
m_aElements.Count())
825 void SetCanNavigate(
bool isAllowed)
831 bool GetCanNavigate()
837 void SetListenToActions(
bool isAllowed)
843 bool GetListenToActions()
849 protected void AddActionListeners()
859 protected void RemoveActionListeners()
868 SCR_TabViewContent GetShownTabComponent()
874 void SetEntryIconSize(
int index,
float width = -1,
float height = -1)
887 void SetPagingButtonsVisible(
bool visible,
bool animate =
true)
964 class SCR_TabViewContent
966 [
Attribute(
"", UIWidgets.ResourceNamePicker,
"Layout element used",
"layout")]
967 ResourceName m_ElementLayout;
969 [
Attribute(
"Button", UIWidgets.EditBox,
"Content of the button: It can contain either name or image resource")]
970 string m_sTabButtonContent;
972 [
Attribute(
"", UIWidgets.EditBox,
"Unique identifier of tab used in script to look for this one - optional for now")]
973 string m_sTabIdentifier;
975 [
Attribute(
desc:
"Param if m_sTabButtonContent is name rather then image resource")]
978 [
Attribute(
desc:
"Param if m_sTabButtonContent is name rather then image resource")]
981 [
Attribute(
"true", UIWidgets.CheckBox,
"Is tab enabled?")]
986 SizeLayoutWidget m_wLayout;
989 ResourceName m_TabImage;
991 [
Attribute(
desc:
"Image name used in front of tab text when using image set")]
992 string m_sTabImageName;
1000 [
Attribute(
"{6B997B683BD0FC21}UI/layouts/WidgetLibrary/TabView/WLib_TabViewInfoIcon.layout", UIWidgets.ResourceNamePicker,
"",
"Path to layout")]
1001 ResourceName m_IconLayout;
1007 float m_fIconHeight;