7 protected static const int EMPTY_Z_ORDER =
int.MAX;
10 protected ResourceName m_ItemLayout;
12 [
Attribute(
"-1",
desc:
"When >= 0, it will hide parent when there are no items.\n0 means this widget will be hidden, 1 means its parent will, etc.")]
13 protected int m_iHideParentIndexWhenEmpty;
15 [
Attribute(
desc:
"When defined, toolbar will be hidden when empty and widget with this name on the level defined by 'Hide Parent Index When Empty' will be shown instead.")]
16 protected string m_sEmptyWidgetName;
19 protected string m_sItemsWidgetName;
22 protected Widget m_ItemsWidget;
23 protected Widget m_HideWidget;
24 protected int m_iFirstShownIndex;
25 protected int m_iFocusedIndex;
26 protected int m_iItemsCount;
27 protected int m_iPage;
28 protected bool m_bIsUnderCursor;
35 return m_bIsUnderCursor || !
GetGame().GetInputManager().IsUsingMouseAndKeyboard();
43 itemWidget =
GetGame().GetWorkspace().CreateWidgets(m_ItemLayout, m_ItemsWidget);
48 itemWidget.SetName(
string.Format(
"%1_%2", itemWidget.GetName(), m_iItemsCount));
49 TextWidget debugText = TextWidget.Cast(itemWidget.FindAnyWidget(
"Debug"));
52 debugText.SetVisible(
true);
53 debugText.SetText(m_iItemsCount.ToString());
60 Print(
string.Format(
"'%1' must contain SCR_BaseToolbarItemEditorUIComponent!", m_ItemLayout), LogLevel.WARNING);
61 itemWidget.RemoveFromHierarchy();
65 toolbarItem.InitToolbarItem(itemWidget);
67 AllowFocus(itemWidget);
78 protected void DeleteAllItems()
80 Widget deletedChild, child = m_ItemsWidget.GetChildren();
84 child = child.GetSibling();
85 deletedChild.RemoveFromHierarchy();
91 protected void SetToolbarVisible(
bool show)
93 if (!m_HideWidget && m_iHideParentIndexWhenEmpty >= 0)
96 for (
int i = 0; i < m_iHideParentIndexWhenEmpty; i++)
99 m_HideWidget = m_HideWidget.GetParent();
107 m_HideWidget.SetVisible(show);
109 if (m_sEmptyWidgetName)
111 Widget emptyWidget = m_HideWidget.GetParent().FindWidget(m_sEmptyWidgetName);
113 emptyWidget.SetVisible(!show);
119 protected void ShowEntries(Widget contentWidget,
int indexStart,
int indexEnd)
124 protected void Refresh()
129 hasContent = m_Pagination.RefreshPage();
134 ShowEntries(m_ItemsWidget, 0,
int.MAX);
135 hasContent = m_ItemsWidget.GetChildren() !=
null;
138 SetToolbarVisible(hasContent);
143 void MarkForRefresh()
145 GetGame().GetCallqueue().Remove(Refresh);
146 GetGame().GetCallqueue().CallLater(Refresh, 1);
150 protected void OnPageChanged(
int page)
162 m_Pagination.SetPage(toolbar.m_iPage);
167 override protected bool CanOpenDialog()
170 return m_HideWidget.IsVisible();
172 return super.CanOpenDialog();
178 CopyPage(linkedComponent);
184 CopyPage(linkedComponent);
198 override bool OnMouseEnter(Widget w,
int x,
int y)
200 m_bIsUnderCursor =
true;
201 super.OnMouseEnter(w, x, y);
206 override bool OnMouseLeave(Widget w, Widget enterW,
int x,
int y)
208 m_bIsUnderCursor =
false;
209 super.OnMouseLeave(w, enterW, x, y);
214 override void HandlerAttachedScripted(Widget w)
216 super.HandlerAttachedScripted(w);
221 m_Pagination.GetOnShowEntries().Insert(ShowEntries);
222 m_Pagination.GetOnPageChanged().Insert(OnPageChanged);
229 override void HandlerAttached(Widget w)
231 super.HandlerAttached(w);
233 m_ItemsWidget = w.FindAnyWidget(m_sItemsWidgetName);
236 Print(
string.Format(
"m_ItemsWidget '%1' not found!", m_sItemsWidgetName), LogLevel.WARNING);
240 SetToolbarVisible(
false);
242 DiagMenu.RegisterRange(
SCR_DebugMenuID.DEBUGUI_EDITOR_GUI_TOOLBAR_FILL,
"",
"Duplicate Toolbar Items",
"Editor GUI",
"0, 24, 0, 1");