Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_LoadingOverlay.c
Go to the documentation of this file.
1/*
2How to use:
3
4Variant 1:
5 Put a LoadingOverlay.layout into your layout manually, adjust text, size, hide background and blur if needed.
6
7Variant 2:
8 Call SCR_LoadingOverlay.ShowForWidget() to render the overlay over a specific widget. The target widget can be of any kind.
9 Call HideForWidget() when you want to hide and delete the overlay.
10 Call public methods to show/hide temporary, or adjust text, blur, background.
11 When target widget is destroyed, the loading overlay of it is also destroyed automatically.
12*/
13
14
17{
18 SCR_LoadingOverlay m_OverlayComponent;
19
20 Widget m_wTarget; // This component is attached to this widget
21
22 //------------------------------------------------------------------------------------------------
23 void Init(Widget targetWidget, SCR_LoadingOverlay overlayComponent)
24 {
25 m_wTarget = targetWidget;
26 m_OverlayComponent = overlayComponent;
27 }
28
29
30
31 //------------------------------------------------------------------------------------------------
32 override void HandlerDeattached(Widget w)
33 {
34 if (!GetGame().GetWorkspace())
35 return;
36
37 // When the target widget is deleted, we also delete the overlay
38 if (m_OverlayComponent)
39 {
40 if (m_OverlayComponent.m_wRoot)
41 GetGame().GetWorkspace().RemoveChild(m_OverlayComponent.m_wRoot);
42 }
43 }
44};
45
46
47
48//------------------------------------------------------------------------------------------------
50{
51 Widget m_wRoot;
52
53 ref SCR_LoadingOverlayWidgets widgets;
54
56
57 protected bool m_bRenderTopMost = false;
58
59 protected bool m_bShown = true; // At start it is shown by default
60
61 // -------- Attributes for the component when placed through editor ---------
62
63 [Attribute(defvalue: "true", uiwidget: UIWidgets.CheckBox, desc: "The overlay is shown at start")]
65
66 [Attribute("true", uiwidget: UIWidgets.CheckBox, desc: "Should background image be visible?")]
67 protected bool m_bShowBackground;
68
69 //------------------------------------------------------------------------------------------------
72 static SCR_LoadingOverlay ShowForWidget(Widget targetWidget, string text = string.Empty, bool showBlur = true, bool showBackground = true)
73 {
74 if (!targetWidget)
75 return null;
76
79 Widget overlayRoot;
80
81 // First check if an overlay is already present for this widget
82 helper = SCR_LoadingOverlayHelperComponent.Cast(targetWidget.FindHandler(SCR_LoadingOverlayHelperComponent));
83
84 if (!helper)
85 {
86 // Add helper component to target widget
88 targetWidget.AddHandler(helper);
89 }
90 else
91 {
92 comp = helper.m_OverlayComponent;
93 overlayRoot = comp.m_wRoot;
94 }
95
96 // Create the overlay component if it's not found
97 if (!comp)
98 {
99 overlayRoot = GetGame().GetWorkspace().CreateWidgets(SCR_LoadingOverlayWidgets.s_sLayout, GetGame().GetWorkspace());
100 comp = SCR_LoadingOverlay.Cast(overlayRoot.FindHandler(SCR_LoadingOverlay));
101 }
102
103
104 if (!overlayRoot || !comp || !helper)
105 return null;
106
107 helper.Init(targetWidget, comp);
108 comp.Init(overlayRoot, helper);
109
110 comp.SetText(text);
111 comp.ShowBlur(showBlur);
112 comp.ShowBackground(showBackground);
113 comp.SetShown(true);
114
115 return comp;
116 }
117
118
119
120 //------------------------------------------------------------------------------------------------
122 static void HideForWidget(Widget targetWidget)
123 {
125
126 // If no helper component found at the target widget, we can't do anything
127 if (!helper)
128 return;
129
130 SCR_LoadingOverlay comp = helper.m_OverlayComponent;
131
132 comp.HideAndDelete();
133 }
134
135
136
137 //------------------------------------------------------------------------------------------------
140 {
141 // Remove the helper component from target
142 if (m_Helper)
143 {
144 if (m_Helper.m_wTarget)
145 {
146 m_Helper.m_wTarget.RemoveHandler(m_Helper);
147 }
148 }
149
150 // Remove the overlay from workspace
151 if (m_wRoot)
152 {
153 // This component is going to be deleted now as well
154 GetGame().GetWorkspace().RemoveChild(m_wRoot);
155 }
156 }
157
158
159
160 //------------------------------------------------------------------------------------------------
162 void SetShown(bool show)
163 {
164 // Avoid calling Show many times
165 if (m_bShown == show)
166 return;
167
168 m_bShown = show;
169
170 m_wRoot.SetVisible(show);
171 }
172
173
174
175 //------------------------------------------------------------------------------------------------
176 void SetText(string text)
177 {
178 this.widgets.m_Text.SetText(text);
179 }
180
181
182
183 //------------------------------------------------------------------------------------------------
184 void ShowBackground(bool show)
185 {
186 this.widgets.m_BackgroundImage.SetVisible(show);
187 }
188
189
190
191 //------------------------------------------------------------------------------------------------
192 void ShowBlur(bool show)
193 {
194 this.widgets.m_Blur.SetVisible(show);
195 }
196
197
198
199 //------------------------------------------------------------------------------------------------
201 {
202 return m_wRoot;
203 }
204
205
206 //------------------------------------------------------------------------------------------------
209 void SetFocus()
210 {
211 //GetGame().GetWorkspace().SetFocusedWidget(null);
212 GetGame().GetWorkspace().AddModal(m_wRoot, m_wRoot);
213 GetGame().GetWorkspace().SetFocusedWidget(m_wRoot); // Our root widget is a button
214 }
215
216
217 // ----------- Private methods below -------------
218
219
220
221 //------------------------------------------------------------------------------------------------
222 override void HandlerAttached(Widget w)
223 {
224 // If attached to workspace root, this will render over everything
225 // Also in this case the ShowForWidget method calls the Init
226 if (w.GetParent() == GetGame().GetWorkspace())
227 {
228 m_bRenderTopMost = true;
229 }
230 else
231 {
232 // If not attached to workspace root, this will act as if placed in a reagular widget hierarchy
233 this.Init(w, null);
234
235 this.SetShown(m_bShownAtStart);
237 }
238 }
239
240
241
242 //------------------------------------------------------------------------------------------------
243 protected void Init(Widget overlayRoot, SCR_LoadingOverlayHelperComponent helper)
244 {
245 m_wRoot = overlayRoot;
246 m_Helper = helper;
247
248 widgets = new SCR_LoadingOverlayWidgets;
249 widgets.Init(m_wRoot);
250
251 // If this is supposed to be rendered over everything,
252 // set Z order to some high value
253 if (helper && m_bRenderTopMost)
254 {
255 int zOrder = 9001; // todo redo Z values with enum
256 if (helper.m_wTarget == GetGame().GetWorkspace())
257 zOrder += 1000;
258 m_wRoot.SetZOrder(zOrder);
259
260 GetGame().GetCallqueue().CallLater(SetSizeFromTarget, 0);
261 }
262 }
263
264
265
266 //------------------------------------------------------------------------------------------------
267 protected void SetSizeFromTarget()
268 {
269 if (!m_Helper)
270 return;
271
272 if (!m_Helper.m_wTarget)
273 return;
274
275 Widget targetWidget = m_Helper.m_wTarget;
276
277 float x, y, sizex, sizey;
278 targetWidget.GetScreenPos(x, y);
279 targetWidget.GetScreenSize(sizex, sizey);
280
281 WorkspaceWidget ww = GetGame().GetWorkspace();
282
283 x = ww.DPIUnscale(x);
284 y = ww.DPIUnscale(y);
285 sizex = ww.DPIUnscale(sizex);
286 sizey = ww.DPIUnscale(sizey);
287
288 FrameSlot.SetPos(m_wRoot, x, y);
289 FrameSlot.SetSize(m_wRoot, sizex, sizey);
290 }
291
292
293
294 //------------------------------------------------------------------------------------------------
295 override bool OnUpdate(Widget w)
296 {
297 // This is only needed if we put the overlay to Workspace root and want to track the size and pos
298 // of the targer widget
299 if (!m_bRenderTopMost)
300 return false;
301
302 if (!m_wRoot || !m_Helper || !m_Helper.m_wTarget)
303 {
304 return false;
305 }
306
307 GetGame().GetCallqueue().CallLater(SetSizeFromTarget, 0);
308
309 return true;
310 }
311
312
313
314
315 // Overriding events so that we can intercept them
316 override bool OnClick(Widget w, int x, int y, int button)
317 {
318 return true;
319 }
320 override bool OnModalClosed(Widget modalRoot) {return true;}
321 override bool OnDoubleClick(Widget w, int x, int y, int button) {return true;}
322 override bool OnItemSelected(Widget w, int row, int column, int oldRow, int oldColumn) {return true;}
323 override bool OnFocus(Widget w, int x, int y) { return true; }
324 override bool OnFocusLost(Widget w, int x, int y) { return true; }
325 override bool OnMouseEnter(Widget w, int x, int y) {return true;}
326 override bool OnMouseLeave(Widget w, Widget enterW, int x, int y) {return true;}
327 override bool OnMouseWheel(Widget w, int x, int y, int wheel) {return true;}
328 override bool OnMouseButtonDown(Widget w, int x, int y, int button) {return true;}
329 override bool OnMouseButtonUp(Widget w, int x, int y, int button) {return true;}
331 override bool OnController(Widget w, int control, int value) {return true;}
332 override bool OnChar(Widget w, int charCode) {return true;}
333 override bool OnChange(Widget w, bool finished) {return true;}
334 override bool OnModalClickOut(Widget modalRoot, int x, int y, int button) {return true;}
335
336};
override void Init()
ArmaReforgerScripted GetGame()
Definition game.c:1398
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
This component is attached to the target widget and holds a reference to the overlay targeted at this...
override bool OnUpdate(Widget w)
void ShowBackground(bool show)
override bool OnChange(Widget w, bool finished)
override bool OnModalClickOut(Widget modalRoot, int x, int y, int button)
override bool OnMouseButtonUp(Widget w, int x, int y, int button)
override void HandlerAttached(Widget w)
void SetText(string text)
override bool OnController(Widget w, int control, int value)
control is one of ControlID
override bool OnMouseWheel(Widget w, int x, int y, int wheel)
override bool OnMouseEnter(Widget w, int x, int y)
override bool OnFocusLost(Widget w, int x, int y)
override bool OnClick(Widget w, int x, int y, int button)
override bool OnMouseButtonDown(Widget w, int x, int y, int button)
override bool OnItemSelected(Widget w, int row, int column, int oldRow, int oldColumn)
void SetShown(bool show)
Shows or hides the overlay. The overlay is not destroyed if hidden and can be shown again.
override bool OnChar(Widget w, int charCode)
override bool OnFocus(Widget w, int x, int y)
void Init(Widget overlayRoot, SCR_LoadingOverlayHelperComponent helper)
override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
void HideAndDelete()
Hides the overlay. The overlay will be destroyed, and the SCR_LoadingOverlay component will be delete...
override bool OnModalClosed(Widget modalRoot)
static SCR_LoadingOverlay ShowForWidget(Widget targetWidget, string text=string.Empty, bool showBlur=true, bool showBackground=true)
void ShowBlur(bool show)
override bool OnDoubleClick(Widget w, int x, int y, int button)
static void HideForWidget(Widget targetWidget)
Hides overlay for given target widget.
SCR_FieldOfViewSettings Attribute