Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_BaseToolbarEditorUIComponent.c
Go to the documentation of this file.
1 //#define TOOLBAR_DEBUG
2 
4 
6 {
7  protected static const int EMPTY_Z_ORDER = int.MAX;
8 
9  [Attribute(params: "layout")]
10  protected ResourceName m_ItemLayout;
11 
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;
14 
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;
17 
18  [Attribute()]
19  protected string m_sItemsWidgetName;
20 
21  protected SCR_ExternalPaginationUIComponent m_Pagination;
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;
29 
30  //------------------------------------------------------------------------------------------------
33  bool IsUnderCursor()
34  {
35  return m_bIsUnderCursor || !GetGame().GetInputManager().IsUsingMouseAndKeyboard();
36  }
37 
38  //------------------------------------------------------------------------------------------------
39  protected bool CreateItem(out Widget itemWidget, out SCR_BaseToolbarItemEditorUIComponent toolbarItem)
40  {
41  if (m_ItemsWidget)
42  {
43  itemWidget = GetGame().GetWorkspace().CreateWidgets(m_ItemLayout, m_ItemsWidget);
44  if (!itemWidget)
45  return false;
46 
47 #ifdef TOOLBAR_DEBUG
48  itemWidget.SetName(string.Format("%1_%2", itemWidget.GetName(), m_iItemsCount));
49  TextWidget debugText = TextWidget.Cast(itemWidget.FindAnyWidget("Debug"));
50  if (debugText)
51  {
52  debugText.SetVisible(true);
53  debugText.SetText(m_iItemsCount.ToString());
54  }
55 #endif
56 
57  toolbarItem = SCR_BaseToolbarItemEditorUIComponent.Cast(itemWidget.FindHandler(SCR_BaseToolbarItemEditorUIComponent));
58  if (!toolbarItem)
59  {
60  Print(string.Format("'%1' must contain SCR_BaseToolbarItemEditorUIComponent!", m_ItemLayout), LogLevel.WARNING);
61  itemWidget.RemoveFromHierarchy();
62  return false;
63  }
64 
65  toolbarItem.InitToolbarItem(itemWidget);
66  m_iItemsCount++;
67  AllowFocus(itemWidget);
68 
69  return true;
70  }
71  else
72  {
73  return false;
74  }
75  }
76 
77  //------------------------------------------------------------------------------------------------
78  protected void DeleteAllItems()
79  {
80  Widget deletedChild, child = m_ItemsWidget.GetChildren();
81  while (child)
82  {
83  deletedChild = child;
84  child = child.GetSibling(); //--- Get sibling before removing the child from hierarchy
85  deletedChild.RemoveFromHierarchy();
86  }
87  m_iItemsCount = 0;
88  }
89 
90  //------------------------------------------------------------------------------------------------
91  protected void SetToolbarVisible(bool show)
92  {
93  if (!m_HideWidget && m_iHideParentIndexWhenEmpty >= 0)
94  {
95  m_HideWidget = GetWidget();
96  for (int i = 0; i < m_iHideParentIndexWhenEmpty; i++)
97  {
98  if (m_HideWidget)
99  m_HideWidget = m_HideWidget.GetParent();
100  else
101  break;
102  }
103  }
104 
105  if (m_HideWidget)
106  {
107  m_HideWidget.SetVisible(show);
108 
109  if (m_sEmptyWidgetName)
110  {
111  Widget emptyWidget = m_HideWidget.GetParent().FindWidget(m_sEmptyWidgetName);
112  if (emptyWidget)
113  emptyWidget.SetVisible(!show);
114  }
115  }
116  }
117 
118  //------------------------------------------------------------------------------------------------
119  protected void ShowEntries(Widget contentWidget, int indexStart, int indexEnd)
120  {
121  }
122 
123  //------------------------------------------------------------------------------------------------
124  protected void Refresh()
125  {
126  bool hasContent;
127  if (m_Pagination)
128  {
129  hasContent = m_Pagination.RefreshPage();
130  }
131  else
132  {
133  DeleteAllItems();
134  ShowEntries(m_ItemsWidget, 0, int.MAX);
135  hasContent = m_ItemsWidget.GetChildren() != null;
136  }
137 
138  SetToolbarVisible(hasContent);
139  }
140 
141  //------------------------------------------------------------------------------------------------
143  void MarkForRefresh()
144  {
145  GetGame().GetCallqueue().Remove(Refresh); //--- Remove the previous queued call, to guarantee there will be the only one
146  GetGame().GetCallqueue().CallLater(Refresh, 1); //--- Call with a delay, in case whatever called this is not ready yet and the toolbar would reflect incorrect state
147  }
148 
149  //------------------------------------------------------------------------------------------------
150  protected void OnPageChanged(int page)
151  {
152  m_iPage = page;
153  }
154 
155  //------------------------------------------------------------------------------------------------
156  protected void CopyPage(SCR_DialogEditorUIComponent linkedComponent)
157  {
158  if (m_Pagination)
159  {
161  //m_Pagination.SetPage(toolbar.m_Pagination.GetCurrentPage()); //--- Unreliable, pagination component can de-initialize before this one
162  m_Pagination.SetPage(toolbar.m_iPage);
163  }
164  }
165 
166  //------------------------------------------------------------------------------------------------
167  override protected bool CanOpenDialog()
168  {
169  if (m_HideWidget)
170  return m_HideWidget.IsVisible();
171  else
172  return super.CanOpenDialog();
173  }
174 
175  //------------------------------------------------------------------------------------------------
176  override protected void OnDialogOpened(SCR_DialogEditorUIComponent linkedComponent)
177  {
178  CopyPage(linkedComponent);
179  }
180 
181  //------------------------------------------------------------------------------------------------
182  override protected void OnDialogClosed(SCR_DialogEditorUIComponent linkedComponent)
183  {
184  CopyPage(linkedComponent);
185  }
186 
187 // //------------------------------------------------------------------------------------------------
188 // override void OnInputDeviceUserChanged(EInputDeviceType oldDevice, EInputDeviceType newDevice)
189 // {
190 // if (SCR_Global.IsChangedMouseAndKeyboard(oldDevice, newDevice))
191 // return;
192 //
193 // super.OnInputDeviceUserChanged(oldDevice, newDevice);
194 // //if (!m_bIsInDialog) Refresh();
195 // }
196 
197  //------------------------------------------------------------------------------------------------
198  override bool OnMouseEnter(Widget w, int x, int y)
199  {
200  m_bIsUnderCursor = true;
201  super.OnMouseEnter(w, x, y);
202  return false;
203  }
204 
205  //------------------------------------------------------------------------------------------------
206  override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
207  {
208  m_bIsUnderCursor = false;
209  super.OnMouseLeave(w, enterW, x, y);
210  return false;
211  }
212 
213  //------------------------------------------------------------------------------------------------
214  override void HandlerAttachedScripted(Widget w)
215  {
216  super.HandlerAttachedScripted(w);
217 
218  m_Pagination = SCR_ExternalPaginationUIComponent.Cast(w.FindHandler(SCR_ExternalPaginationUIComponent));
219  if (m_Pagination)
220  {
221  m_Pagination.GetOnShowEntries().Insert(ShowEntries);
222  m_Pagination.GetOnPageChanged().Insert(OnPageChanged);
223  }
224 
225  Refresh();
226  }
227 
228  //------------------------------------------------------------------------------------------------
229  override void HandlerAttached(Widget w)
230  {
231  super.HandlerAttached(w);
232 
233  m_ItemsWidget = w.FindAnyWidget(m_sItemsWidgetName);
234  if (!m_ItemsWidget)
235  {
236  Print(string.Format("m_ItemsWidget '%1' not found!", m_sItemsWidgetName), LogLevel.WARNING);
237  return;
238  }
239 
240  SetToolbarVisible(false);
241 
242  DiagMenu.RegisterRange(SCR_DebugMenuID.DEBUGUI_EDITOR_GUI_TOOLBAR_FILL, "", "Duplicate Toolbar Items", "Editor GUI", "0, 24, 0, 1");
243  }
244 }
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SCR_ExternalPaginationUIComponent
Definition: SCR_ExternalPaginationUIComponent.c:1
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
Attribute
typedef Attribute
Post-process effect of scripted camera.
m_iPage
protected int m_iPage
Definition: BanCommands.c:54
SCR_BaseToolbarItemEditorUIComponent
Definition: SCR_BaseToolbarItemEditorUIComponent.c:1
params
Configs ServerBrowser KickDialogs params
Definition: SCR_NotificationSenderComponent.c:24
SCR_DialogEditorUIComponent
Definition: SCR_DialogEditorUIComponent.c:3
SCR_DebugMenuID
SCR_DebugMenuID
This enum contains all IDs for DiagMenu entries added in script.
Definition: DebugMenuID.c:3
GetWidget
protected Widget GetWidget()
Definition: SCR_VonDisplay.c:155
SCR_BaseToolbarEditorUIComponent
Definition: SCR_BaseToolbarEditorUIComponent.c:5