Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
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")]
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.")]
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
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 //------------------------------------------------------------------------------------------------
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);
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 {
94 {
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
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 {
135 hasContent = m_ItemsWidget.GetChildren() != null;
136 }
137
138 SetToolbarVisible(hasContent);
139 }
140
141 //---- REFACTOR NOTE START: Call later used for fallback ui update
142
143 //------------------------------------------------------------------------------------------------
146 {
147 GetGame().GetCallqueue().Remove(Refresh); //--- Remove the previous queued call, to guarantee there will be the only one
148 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
149 }
150
151 //---- REFACTOR NOTE END ----
152
153 //------------------------------------------------------------------------------------------------
154 protected void OnPageChanged(int page)
155 {
156 m_iPage = page;
157 }
158
159 //------------------------------------------------------------------------------------------------
160 protected void CopyPage(SCR_DialogEditorUIComponent linkedComponent)
161 {
162 if (m_Pagination)
163 {
165 //m_Pagination.SetPage(toolbar.m_Pagination.GetCurrentPage()); //--- Unreliable, pagination component can de-initialize before this one
166 m_Pagination.SetPage(toolbar.m_iPage);
167 }
168 }
169
170 //------------------------------------------------------------------------------------------------
171 override protected bool CanOpenDialog()
172 {
173 if (m_HideWidget)
174 return m_HideWidget.IsVisible();
175 else
176 return super.CanOpenDialog();
177 }
178
179 //------------------------------------------------------------------------------------------------
180 override protected void OnDialogOpened(SCR_DialogEditorUIComponent linkedComponent)
181 {
182 CopyPage(linkedComponent);
183 }
184
185 //------------------------------------------------------------------------------------------------
186 override protected void OnDialogClosed(SCR_DialogEditorUIComponent linkedComponent)
187 {
188 CopyPage(linkedComponent);
189 }
190
191// //------------------------------------------------------------------------------------------------
192// override void OnInputDeviceUserChanged(EInputDeviceType oldDevice, EInputDeviceType newDevice)
193// {
194// if (SCR_Global.IsChangedMouseAndKeyboard(oldDevice, newDevice))
195// return;
196//
197// super.OnInputDeviceUserChanged(oldDevice, newDevice);
198// //if (!m_bIsInDialog) Refresh();
199// }
200
201 //------------------------------------------------------------------------------------------------
202 override bool OnMouseEnter(Widget w, int x, int y)
203 {
204 m_bIsUnderCursor = true;
205 super.OnMouseEnter(w, x, y);
206 return false;
207 }
208
209 //------------------------------------------------------------------------------------------------
210 override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
211 {
212 m_bIsUnderCursor = false;
213 super.OnMouseLeave(w, enterW, x, y);
214 return false;
215 }
216
217 //------------------------------------------------------------------------------------------------
219 {
220 super.HandlerAttachedScripted(w);
221
223 if (m_Pagination)
224 {
225 m_Pagination.GetOnShowEntries().Insert(ShowEntries);
226 m_Pagination.GetOnPageChanged().Insert(OnPageChanged);
227 }
228
229 Refresh();
230 }
231
232 //------------------------------------------------------------------------------------------------
233 override void HandlerAttached(Widget w)
234 {
235 super.HandlerAttached(w);
236
237 m_ItemsWidget = w.FindAnyWidget(m_sItemsWidgetName);
238 if (!m_ItemsWidget)
239 {
240 Print(string.Format("m_ItemsWidget '%1' not found!", m_sItemsWidgetName), LogLevel.WARNING);
241 return;
242 }
243
244 SetToolbarVisible(false);
245
246 DiagMenu.RegisterRange(SCR_DebugMenuID.DEBUGUI_EDITOR_GUI_TOOLBAR_FILL, "", "Duplicate Toolbar Items", "Editor GUI", "0, 24, 0, 1");
247 }
248}
SCR_DebugMenuID
This enum contains all IDs for DiagMenu entries added in script.
Definition DebugMenuID.c:4
ArmaReforgerScripted GetGame()
Definition game.c:1398
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Widget GetWidget()
Diagnostic and developer menu system.
Definition DiagMenu.c:18
override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
bool CreateItem(out Widget itemWidget, out SCR_BaseToolbarItemEditorUIComponent toolbarItem)
void OnDialogOpened(SCR_DialogEditorUIComponent linkedComponent)
void CopyPage(SCR_DialogEditorUIComponent linkedComponent)
override bool OnMouseEnter(Widget w, int x, int y)
SCR_ExternalPaginationUIComponent m_Pagination
void OnDialogClosed(SCR_DialogEditorUIComponent linkedComponent)
void ShowEntries(Widget contentWidget, int indexStart, int indexEnd)
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
@ MAX