Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_InfoDisplay.c
Go to the documentation of this file.
1void SCR_InfoDisplayStartStopCallback(SCR_InfoDisplay display);
3typedef ScriptInvokerBase<SCR_InfoDisplayStartStopCallback> SCR_InfoDisplayInvoker;
5//#define DEBUG_ADAPTIVE_OPACITY
6//#define DEBUG_INFO_DISPLAY
9{
10 TOPLEFT,
11 TOP,
13 LEFT,
14 CENTER,
15 RIGHT,
17 BOTTOM,
19}
20
21class SCR_InfoDisplay : GroupInfoDisplay
22{
23 // Attributes
24 [Attribute("", UIWidgets.ResourceNamePicker, "Layout", "layout")]
25 ResourceName m_LayoutPath;
26
27 [Attribute("2", UIWidgets.ComboBox, "HUD Layer for the UI element to be placed in. Ignored when InfoDisplay is nested under another InfoDisplay.", "", ParamEnumArray.FromEnum(EHudLayers))]
29
30 [Attribute("1", UIWidgets.CheckBox, "Make UI element visible when it is created.")]
31 private bool m_bShowWhenCreated;
32
33 [Attribute("0", UIWidgets.EditBox, "Override the hierarchy to show display in front or behind other displays.")]
34 int m_iOverrideZOrder;
35
36 [Attribute("", UIWidgets.EditBox, "Name of slot in parent widget, the UI element is going to be placed in. Used when InfoDisplay is nested under another InfoDisplay.")]
37 protected string m_sParentSlot;
38
39 // Dimensions and safezone
40 [Attribute("", UIWidgets.EditBox, "Name of widget containing the GUI element content. Uses the root widget, if empty.")]
41 protected string m_sContentWidget;
42
43 [Attribute("0", UIWidgets.Slider, "Adjustment to the content widget width. Can be used to provide a widget-specific padding.", "-200 200 1")]
45
46 [Attribute("0", UIWidgets.Slider, "Adjustment to the content height width. Can be used to provide a widget-specific padding.", "-200 200 1")]
48
49 // Attributes for adaptive opacity
50 [Attribute("1", UIWidgets.CheckBox, "Adjusts opacity of the widget based on level of ambient light.")]
51 private bool m_bAdaptiveOpacity;
52
53 [Attribute("", UIWidgets.EditBox, "Name of the widget in the layout the adaptive opacity is applied to. If empty, layout root is used.")]
55
56 [Attribute()]
57 protected ref array<ref SCR_InfoDisplayHandler> m_aHandlers;
58
59 private Widget m_wAdaptiveOpacity;
60 private float m_fAdaptiveOpacity = 1;
61 protected bool m_bShown;
62
63 protected Widget m_wRoot;
64 protected Widget m_wContent;
65 protected Widget m_wSlot;
67
68 protected int m_iChildDisplays = 0;
69 protected ref array<BaseInfoDisplay> m_aChildDisplays = new array<BaseInfoDisplay>;
70 protected SCR_InfoDisplay m_pParentDisplay;
71 protected bool m_bRegistered = false;
72
74 protected ref array<ref SCR_InfoDisplayHandler> m_aUpdatableHandlers = {};
75
78
79 //------------------------------------------------------------------------------------------------
80 SCR_InfoDisplayHandler GetHandler(typename handlerType)
81 {
82 foreach (SCR_InfoDisplayHandler handler : m_aHandlers)
83 {
84 if (handler.Type() == handlerType)
85 return handler;
86 }
87
88 return null;
89 }
90
91 //------------------------------------------------------------------------------------------------
96
97 //------------------------------------------------------------------------------------------------
99 {
100 return m_OnStop;
101 }
102
103 //------------------------------------------------------------------------------------------------
105 {
106 return m_OwnerEntity;
107 }
108
109 //------------------------------------------------------------------------------------------------
111 {
112 return m_wContent;
113 }
114
115 //------------------------------------------------------------------------------------------------
117 {
118 return m_sContentWidget;
119 }
120
121 //------------------------------------------------------------------------------------------------
122 void SetRootWidget(notnull Widget root)
123 {
124 m_wRoot = root;
125 }
126
127 //------------------------------------------------------------------------------------------------
129 {
131 }
132
133 //------------------------------------------------------------------------------------------------
138 void Show(bool show, float speed = UIConstants.FADE_RATE_INSTANT, EAnimationCurve curve = EAnimationCurve.LINEAR)
139 {
140 #ifdef DEBUG_ADAPTIVE_OPACITY
141 if (this.Type() == SCR_AvailableActionsDisplay)
142 PrintFormat("%1 [Show] show: %2 | m_bShown: %3 | m_wSlot: %4", this, show, m_bShown, m_wSlot);
143 #endif
144
145 if (!m_wRoot)
146 return;
147
148 Widget w = m_wRoot;
149
150 // If a slot is defined, use the slot for fading and visibility control
151 if (m_wSlot)
152 w = m_wSlot;
153
154 m_bShown = show;
155
156 float targetOpacity = show;
157
158 if (show && m_wAdaptiveOpacity && m_wAdaptiveOpacity == w)
159 targetOpacity = m_fAdaptiveOpacity;
160
161 if (speed > 0)
162 {
163 #ifdef DEBUG_ADAPTIVE_OPACITY
164 if (this.Type() == SCR_AvailableActionsDisplay)
165 PrintFormat("%1 [Show] Opacity animation started: %2 -> %3", this, w.GetOpacity(), targetOpacity);
166 #endif
167
168 WidgetAnimationOpacity anim = AnimateWidget.Opacity(w, targetOpacity, speed, true); // true = set visibility of widget to false, if opacity drops to 0%
169
170 if (anim)
171 {
172 anim.SetCurve(curve);
173 anim.GetOnCompleted().Insert(OnShownFinishedPrivate);
174 }
175 else
176 {
177 w.SetOpacity(targetOpacity);
178 w.SetVisible(show);
179 OnShownFinished(w, targetOpacity);
180 }
181 }
182 else
183 {
184 #ifdef DEBUG_ADAPTIVE_OPACITY
185 if (this.Type() == SCR_AvailableActionsDisplay)
186 PrintFormat("%1 [Show] Opacity insta-changed: %2 -> %3", this, w.GetOpacity(), targetOpacity);
187 #endif
188
189 w.SetOpacity(targetOpacity);
190 w.SetVisible(show);
191 OnShownFinished(w, targetOpacity);
192 }
193 }
194
195 //------------------------------------------------------------------------------------------------
196 private void OnShownFinishedPrivate(WidgetAnimationOpacity anim)
197 {
198 if (!anim)
199 return;
200
201 float targetOpacity = anim.GetTargetValue();
202 Widget w = anim.GetWidget();
203
204 OnShownFinished(w, targetOpacity, anim);
205 }
206
207 //------------------------------------------------------------------------------------------------
208 // Interface for overriding 'OnShownFinished'
209 protected void OnShownFinished(Widget w, float targetOpacity, WidgetAnimationOpacity anim = null)
210 {
211 #ifdef DEBUG_INFO_DISPLAY
212 PrintFormat("[OnShownFinished] %1 | desired opacity: %2 (real opacity: %4) | shown: %3", this, targetOpacity, m_bShown, w.GetOpacity());
213 #endif
214 }
215
216 //------------------------------------------------------------------------------------------------
217 bool IsShown()
218 {
219 return m_bShown;
220 }
221
222 //------------------------------------------------------------------------------------------------
224 {
225 return m_wRoot;
226 }
227
228 //------------------------------------------------------------------------------------------------
234 bool GetDimensions(out float width, out float height, bool addSafezones = true)
235 {
236 if (!m_wContent)
237 {
238 width = 0;
239 height = 0;
240 return false;
241 }
242
243 m_wContent.GetScreenSize(width, height);
244
245 WorkspaceWidget workspace = m_wContent.GetWorkspace();
246 width = workspace.DPIUnscale(width);
247 height = workspace.DPIUnscale(height);
248
249 if (addSafezones)
250 {
253 }
254
255 return true;
256 }
257
258 //------------------------------------------------------------------------------------------------
265 bool GetAnchorPosition(out float x, out float y, EWidgetAnchor anchor = EWidgetAnchor.TOPLEFT, bool addSafezones = true)
266 {
267 if (!m_wContent)
268 {
269 x = 0;
270 y = 0;
271 return false;
272 }
273
274 float width, height;
275
276 GetDimensions(width, height, addSafezones);
277
278 m_wContent.GetScreenPos(x, y);
279
280 WorkspaceWidget workspace = m_wContent.GetWorkspace();
281 x = workspace.DPIUnscale(x) - m_iContentWidthAdjustment * 0.5 * addSafezones;
282 y = workspace.DPIUnscale(y) - m_iContentHeightAdjustment * 0.5 * addSafezones;
283
284 switch (anchor)
285 {
286 case EWidgetAnchor.TOPLEFT:
287
288 break;
289
290 case EWidgetAnchor.TOP:
291
292 x += width / 2;
293 break;
294
295 case EWidgetAnchor.TOPRIGHT:
296
297 x += width;
298 break;
299
300 case EWidgetAnchor.LEFT:
301
302 y += height / 2;
303 break;
304
305 case EWidgetAnchor.CENTER:
306
307 y += height / 2;
308 x += width / 2;
309 break;
310
311 case EWidgetAnchor.RIGHT:
312
313 y += height / 2;
314 x += width;
315 break;
316
317 case EWidgetAnchor.BOTTOMLEFT:
318
319 y += height;
320 break;
321
322 case EWidgetAnchor.BOTTOM:
323
324 y += height;
325 x += width / 2;
326 break;
327
328 case EWidgetAnchor.BOTTOMRIGHT:
329
330 y += height;
331 x += width;
332 break;
333
334 default:
335
336 break;
337 }
338
339 return true;
340 }
341
342 //------------------------------------------------------------------------------------------------
345 {
346 m_bShown = false;
347 m_HUDManager.RegisterHUDElement(this);
348 m_bRegistered = true;
349 }
350
351 //------------------------------------------------------------------------------------------------
352 private void CreateDisplayLegacy(IEntity owner)
353 {
354 // If SCR_InfoDisplaySlotHandler handler is attached, this function will prematurely return here.
355 // This is intended behavior inorder to protect backwards compatability.
356 if (m_wRoot)
357 return;
358
359 if (!m_HUDManager)
360 m_HUDManager = SCR_HUDManagerComponent.GetHUDManager();
361
362 if (!m_HUDManager)
363 return;
364
365 // Nested placement; used when parent InfoDisplay is properly defined
367 {
368 Widget wParentRoot = m_pParentDisplay.m_wRoot;
369
370 if (wParentRoot)
371 {
372 m_wSlot = wParentRoot.FindAnyWidget(m_sParentSlot);
373 WorkspaceWidget wWorkspace = GetGame().GetWorkspace();
374
375 if (m_wSlot && wWorkspace)
376 m_wRoot = wWorkspace.CreateWidgets(m_LayoutPath, m_wSlot);
377 }
378 }
379
380 // Default placement; used when there is no parent InfoDisplay or it's slot cannot be SCR_BannedAddonsDetectedDialog
381 if (!m_wRoot)
382 {
383 m_pParentDisplay = null;
384 m_sParentSlot = "";
385
387 m_wRoot = m_HUDManager.CreateLayout(m_LayoutPath, m_eLayer, m_iOverrideZOrder);
388 }
389
390 if (!m_wRoot)
391 return;
392
393 // Detect 'content widget'
394 if (m_sContentWidget != string.Empty)
395 m_wContent = m_wRoot.FindAnyWidget(m_sContentWidget);
396
397 if (!m_wContent)
399
400 AdaptiveOpacity_Initialize();
401
402 #ifdef DEBUG_INFO_DISPLAY
403 PrintFormat("%1 [OnStartDraw] m_wRoot: %2", this, m_wRoot);
404 #endif
405 }
406
407 //------------------------------------------------------------------------------------------------
408 protected override event void OnStartDraw(IEntity owner)
409 {
411
412 foreach (SCR_InfoDisplayHandler handler : m_aHandlers)
413 {
414 if (handler.m_bCanUpdate)
415 m_aUpdatableHandlers.Insert(handler);
416 handler.Initialize(this);
417 }
418
419 foreach (SCR_InfoDisplayHandler handler : m_aHandlers)
420 {
421 handler.OnStart(this);
422 }
423
424 m_OnStart.Invoke(this);
425
427 CreateDisplayLegacy(owner);
428
429 if (!m_wContent)
431
432 AdaptiveOpacity_Initialize();
433 Show(m_bShowWhenCreated);
434 }
435
436 //------------------------------------------------------------------------------------------------
437 private void AdaptiveOpacity_Initialize()
438 {
439 #ifdef DEBUG_ADAPTIVE_OPACITY
440 if (this.Type() == SCR_AvailableActionsDisplay)
441 PrintFormat(">> %1 >> AdaptiveOpacity_Initialize", this);
442 #endif
443
444 // Safecheck for multiple adaptive opacity (parent & child display)
445 if (m_bAdaptiveOpacity && m_pParentDisplay && m_pParentDisplay.m_bAdaptiveOpacity)
446 {
447 m_bAdaptiveOpacity = false;
448 PrintFormat("[AdaptiveOpacity] Duplicate AO disabled on info display %1. Parent display %2 already has AO enabled.", this, m_pParentDisplay);
449 }
450
451 // Adaptive opacity initialization
452 if (m_bAdaptiveOpacity)
453 {
454 if (m_sAdaptiveOpacityWidgetName != string.Empty)
455 m_wAdaptiveOpacity = m_wRoot.FindAnyWidget(m_sAdaptiveOpacityWidgetName);
456
457 if (!m_wAdaptiveOpacity)
458 m_wAdaptiveOpacity = m_wRoot;
459
460 m_HUDManager.GetSceneBrightnessChangedInvoker().Insert(AdaptiveOpacity_OnScreenBrightnessChange);
462 }
463 }
464
465 //------------------------------------------------------------------------------------------------
466 private void AdaptiveOpacity_OnScreenBrightnessChange(float opacity, float sceneBrightness)
467 {
468 AdaptiveOpacity_Update(opacity, sceneBrightness, false);
469 }
470
471 //------------------------------------------------------------------------------------------------
472 protected void AdaptiveOpacity_Update(float opacity, float sceneBrightness, bool init = false)
473 {
474 if (!m_bAdaptiveOpacity)
475 return;
476
477 #ifdef DEBUG_ADAPTIVE_OPACITY
478 if (this.Type() == SCR_AvailableActionsDisplay)
479 PrintFormat("%1 [AdaptiveOpacity_Update] opacity: %2 | sceneBrightness: %3", this, opacity, sceneBrightness);
480 #endif
481
482 // Store the calculated adaptive opacity value, so it can be used by other methods, like Show()
483 m_fAdaptiveOpacity = opacity;
484
485 // We can terminate if info display is not shown, as adaptive opacity is already stored ^^
486 if (!m_bShown && !init)
487 return;
488
489 // Detect running opacity animation
491
492 if (animation)
493 {
494 float targetOpacity = animation.GetTargetValue();
495
496 // Terminate, if already fading out (should not be needed, if properly implemented as m_bShown *should* be false)
497 if (targetOpacity < 0.01)
498 return;
499
500 #ifdef DEBUG_ADAPTIVE_OPACITY
501 if (this.Type() == SCR_AvailableActionsDisplay)
502 PrintFormat("%1 [AdaptiveOpacity_Update] Updated running opacity animation; target opacity %2 -> %3", this, targetOpacity, opacity);
503 #endif
504
505 animation.SetTargetValue(opacity);
506 }
507 else
508 {
509 #ifdef DEBUG_ADAPTIVE_OPACITY
510 if (this.Type() == SCR_AvailableActionsDisplay)
511 PrintFormat("%1 [AdaptiveOpacity_Update] %2 -> %3", this, m_wAdaptiveOpacity.GetOpacity(), opacity);
512 #endif
513
514 if (m_wAdaptiveOpacity && m_wAdaptiveOpacity.GetOpacity())
515 m_wAdaptiveOpacity.SetOpacity(opacity);
516 }
517 }
518
519 //------------------------------------------------------------------------------------------------
520 protected override event void OnStopDraw(IEntity owner)
521 {
522 foreach (SCR_InfoDisplayHandler handler : m_aHandlers)
523 {
524 handler.OnStop(this);
525 }
526
527 m_OnStop.Invoke(this);
528
529 // Adaptive opacity initialization
530 if (m_wRoot && m_HUDManager && m_bAdaptiveOpacity)
531 m_HUDManager.GetSceneBrightnessChangedInvoker().Remove(AdaptiveOpacity_OnScreenBrightnessChange);
532
533 if (m_wRoot)
534 m_wRoot.RemoveFromHierarchy();
535
537 m_HUDManager.UnregisterHUDElement(this);
538
539 #ifdef DEBUG_INFO_DISPLAY
540 PrintFormat("%1 [OnStopDraw] m_wRoot: %2", this, m_wRoot);
541 #endif
542
543 m_aUpdatableHandlers.Clear();
544 }
545
546 //------------------------------------------------------------------------------------------------
547 protected override event void UpdateValues(IEntity owner, float timeSlice)
548 {
550 {
551 if (handler.IsEnabled())
552 handler.OnUpdate(timeSlice);
553 }
554 }
555
556 //------------------------------------------------------------------------------------------------
557 protected override event void OnInit(IEntity owner)
558 {
559 // Get slotted children info
561
562 m_OwnerEntity = owner;
563
564 foreach (BaseInfoDisplay pDisplay : m_aChildDisplays)
565 {
566 SCR_InfoDisplay pInfoDisplay = SCR_InfoDisplay.Cast(pDisplay);
567
568 if (pInfoDisplay)
569 pInfoDisplay.m_pParentDisplay = this;
570 }
571 }
572}
class RestAPIHelper< JsonApiStruct T > content
ArmaReforgerScripted GetGame()
Definition game.c:1398
SCR_HUDManagerComponent m_HUDManager
Definition game.c:39
SCR_AIUtilityComponentClass m_OwnerEntity
Widget m_wRoot
bool IsShown()
SCR_InfoDisplayInvoker GetOnStop()
bool m_bShown
int m_iContentHeightAdjustment
TOPLEFT
SCR_InfoDisplayHandler GetHandler(typename handlerType)
string m_sAdaptiveOpacityWidgetName
string m_sContentWidget
string m_sParentSlot
SCR_InfoDisplay m_pParentDisplay
ref SCR_InfoDisplayInvoker m_OnStart
BOTTOMLEFT
IEntity GetOwnerEntity()
void AdaptiveOpacity_Update(float opacity, float sceneBrightness, bool init=false)
override event void UpdateValues(IEntity owner, float timeSlice)
void SetRootWidget(notnull Widget root)
ScriptInvokerBase< SCR_InfoDisplayStartStopCallback > SCR_InfoDisplayInvoker
EHudLayers m_eLayer
string GetContentWidgetName()
void RegisterToHudManager()
TOPRIGHT
Widget m_wSlot
func SCR_InfoDisplayStartStopCallback
ref SCR_InfoDisplayInvoker m_OnStop
EWidgetAnchor
override event void OnStartDraw(IEntity owner)
void SetContentWidget(notnull Widget content)
override event void OnStopDraw(IEntity owner)
ref array< BaseInfoDisplay > m_aChildDisplays
SCR_InfoDisplayInvoker GetOnStart()
Widget GetContentWidget()
int m_iContentWidthAdjustment
ref array< ref SCR_InfoDisplayHandler > m_aUpdatableHandlers
BOTTOMRIGHT
int m_iChildDisplays
bool GetAnchorPosition(out float x, out float y, EWidgetAnchor anchor=EWidgetAnchor.TOPLEFT, bool addSafezones=true)
bool m_bRegistered
bool GetDimensions(out float width, out float height, bool addSafezones=true)
void OnShownFinished(Widget w, float targetOpacity, WidgetAnimationOpacity anim=null)
ref array< ref SCR_InfoDisplayHandler > m_aHandlers
Widget GetRootWidget()
int Type
enum EVehicleType IEntity
EAnimationCurve
static WidgetAnimationBase GetAnimation(Widget w, typename type)
static WidgetAnimationOpacity Opacity(Widget widget, float targetValue, float speed, bool toggleVisibility=false)
ScriptInvokerBase< OnScreenBrightnessChanged > GetSceneBrightnessChangedInvoker()
static SCR_HUDManagerComponent GetHUDManager()
Widget CreateLayout(ResourceName path, EHudLayers layer, int zOrder=0)
void SetTargetValue(float targetValue)
override void Show()
Definition gameLib.c:262
proto void PrintFormat(string fmt, void param1=NULL, void param2=NULL, void param3=NULL, void param4=NULL, void param5=NULL, void param6=NULL, void param7=NULL, void param8=NULL, void param9=NULL, LogLevel level=LogLevel.NORMAL)
@ CENTER
Text will be centered.
SCR_FieldOfViewSettings Attribute
@ LEFT
navigation
@ RIGHT
BaseHUDComponentClass GameComponentClass GetInfoDisplays(out notnull array< BaseInfoDisplay > outInfoDisplays)
class WidgetType BOTTOM
class WidgetType TOP