Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_InfoDisplayExtended.c
Go to the documentation of this file.
1//#define DISABLE_HUD
2//#define DEBUG_INFO_DISPLAY_EXT
4enum EShowGUI // TODO: SCR_
6 IN_ADS = 1,
10 WITHOUT_ENTITY = 16,
12 IN_EDITOR = 64
13}
14
15//------------------------------------------------------------------------------------------------
16class SCR_InfoDisplayExtended : SCR_InfoDisplay
17{
18 [Attribute("1", UIWidgets.CheckBox, "Toggles ON/OFF info display.")]
19 protected bool m_bIsEnabled;
20
21 [Attribute("39", UIWidgets.Flags, "Defines when the GUI element is allowed to show.", "", ParamEnumArray.FromEnum(EShowGUI) )]
22 private EShowGUI m_eShow;
23
24 [Attribute("", desc: "If Display can be disabled in settings, define the correct variable defined in: 'SCR_InterfaceSettings'")]
25 protected string m_sInterfaceSettingName;
26
29 protected SCR_CharacterCameraHandlerComponent m_CameraHandler;
31 protected EventHandlerManagerComponent m_EventHandlerManager;
33
35
36 protected bool m_bInThirdPerson;
37 protected bool m_bInADS;
38 protected bool m_bIsUnconscious;
39 protected bool m_bInPauseMenu;
40 protected bool m_bInEditor;
41 protected bool m_bCanShow; // Global GUI visibility flag, is not meant to be fiddled with outside this class
42 protected bool m_bIsEnabledInSettings = true;
43 protected bool m_bShowInAllCameras = true;
44
45 //------------------------------------------------------------------------------------------------
46 // DEBUG: Used to output debug prints only for specific class
47 //------------------------------------------------------------------------------------------------
48 #ifdef DEBUG_INFO_DISPLAY_EXT
49 //------------------------------------------------------------------------------------------------
50 void _printClass(string str)
51 {
52 if (this.Type() != SCR_DeathScreenEffect)
53 return;
54
55 Print(str, LogLevel.DEBUG);
56 }
57 #endif
58
59 //------------------------------------------------------------------------------------------------
60 void SetEnabled(bool isEnabled)
61 {
62 m_bIsEnabled = isEnabled;
63 }
64
65 //------------------------------------------------------------------------------------------------
66 // Interface methods for the extended InfoDisplay class.
67 //------------------------------------------------------------------------------------------------
68 protected bool DisplayStartDrawInit(IEntity owner)
69 {
70 return true;
71 }
72
73 //------------------------------------------------------------------------------------------------
74 protected void DisplayStartDraw(IEntity owner);
75
76 //------------------------------------------------------------------------------------------------
77 protected void DisplayStopDraw(IEntity owner);
78
79 //------------------------------------------------------------------------------------------------
80 protected void DisplayInit(IEntity owner);
81
82 //------------------------------------------------------------------------------------------------
83 protected void DisplayUpdate(IEntity owner, float timeSlice);
84
85 //------------------------------------------------------------------------------------------------
86 protected void DisplayControlledEntityChanged(IEntity from, IEntity to);
87
88 //------------------------------------------------------------------------------------------------
89 protected void DisplayConsciousnessChanged(bool conscious, bool init = false);
90
91 //------------------------------------------------------------------------------------------------
93 protected void DisplayOnSuspended()
94 {
95 #ifdef DEBUG_INFO_DISPLAY_EXT
96 _printClass(string.Format("%1 [DisplayOnSuspended]", this));
97 #endif
98 }
99
100 //------------------------------------------------------------------------------------------------
101 // Called when the visibility flags no longer suspend the GUI; e.g. GM left and GUI marked as not to show in GM -> GUI can show again
102 // Doesn't mean the GUI is visible, it is just not hidded due to visibility flags; use m_bShown to check the visibility
103 protected void DisplayOnResumed()
104 {
105 #ifdef DEBUG_INFO_DISPLAY_EXT
106 _printClass(string.Format("%1 [DisplayOnResumed]", this));
107 #endif
108 }
109
110 //------------------------------------------------------------------------------------------------
112 {
113 if (!m_HUDManager)
114 return;
115
116 BaseContainer interfaceSettings = GetGame().GetGameUserSettings().GetModule(m_HUDManager.GetInterfaceSettingsClass());
117 if (!interfaceSettings)
118 return;
119
120 bool state;
121 interfaceSettings.Get(m_sInterfaceSettingName, state);
123
124 GetGame().OnUserSettingsChangedInvoker().Insert(OnSettingsChanged);
125 }
126
127 //------------------------------------------------------------------------------------------------
128 protected void OnSettingsChanged()
129 {
130 if (!m_HUDManager)
131 return;
132
133 BaseContainer interfaceSettings = GetGame().GetGameUserSettings().GetModule(m_HUDManager.GetInterfaceSettingsClass());
134 if (!interfaceSettings)
135 return;
136
137 bool state;
138 if (!interfaceSettings.Get(m_sInterfaceSettingName, state))
139 return;
140
142
143 UpdateVisibility();
144 }
145
146 //------------------------------------------------------------------------------------------------
147 // InfoDisplay events blocked for overriding.
148 // The interface methods above should be used instead.
149 //------------------------------------------------------------------------------------------------
150 private override event void OnStartDraw(IEntity owner)
151 {
152 #ifdef DEBUG_INFO_DISPLAY_EXT
153 _printClass(string.Format("%1 [OnStartDraw] owner: %2", this, owner));
154 #endif
155
156 #ifdef DISABLE_HUD
157 m_bIsEnabled = false;
158 #endif
159
160 if (!m_bIsEnabled)
161 return;
162
163 m_MenuManager = GetGame().GetMenuManager();
164
165 if (!m_MenuManager)
166 {
167 m_bIsEnabled = false;
168 return;
169 }
170
171 m_HUDManager = SCR_HUDManagerComponent.GetHUDManager();
172
173 if (!m_HUDManager)
174 {
175 m_bIsEnabled = false;
176 return;
177 }
178
179 // Terminate if UI is not enabled for any of the camera modes (1PV, 3PV, ADS) && requires a controlled entity
180 if (m_eShow & (EShowGUI.IN_ADS | EShowGUI.IN_1ST_PERSON | EShowGUI.IN_3RD_PERSON | EShowGUI.WITHOUT_ENTITY) == 0)
181 {
182 m_bIsEnabled = false;
183 return;
184 }
185
186 m_bShowInAllCameras = (m_eShow & (EShowGUI.IN_ADS | EShowGUI.IN_1ST_PERSON | EShowGUI.IN_3RD_PERSON)) == (EShowGUI.IN_ADS | EShowGUI.IN_1ST_PERSON | EShowGUI.IN_3RD_PERSON);
187
188 m_PlayerController = SCR_PlayerController.Cast(GetGame().GetPlayerController());
189
191 {
192 m_bIsEnabled = false;
193 return;
194 }
195
196 // Init Editor Open/Close handling
197 SCR_EditorManagerEntity editorManager = SCR_EditorManagerEntity.GetInstance();
198
199 // If Editor doesn't exist yet, we need to add invoker and postpone the initialization of Editor Open/Close invokers
200 if (!editorManager)
201 {
202 SCR_EditorManagerCore core = SCR_EditorManagerCore.Cast(SCR_EditorManagerCore.GetInstance(SCR_EditorManagerCore));
203 core.Event_OnEditorManagerInitOwner.Insert(OnEditorInit);
204 }
205 else
206 {
207 OnEditorInit(editorManager);
208 }
209
210 // Init PauseMenu handling
211 if ((m_eShow & EShowGUI.IN_PAUSE_MENU) == 0)
212 {
213 PauseMenuUI.m_OnPauseMenuOpened.Insert(OnPauseMenuOpen);
214
215 PauseMenuUI.m_OnPauseMenuClosed.Insert(OnPauseMenuClose);
216 }
217
218 // Init monitor of controlled entity and setup initial GUI visibility
220 {
221 m_PlayerController.m_OnControlledEntityChanged.Insert(OnControlledEntityChanged);
222 }
223 // Init the 'OnControlledEntityChanged' with currently controlled entity
224 OnControlledEntityChanged(null, m_PlayerController.GetControlledEntity());
225
227
228 if (!m_bIsEnabled)
229 return;
230
231 super.OnStartDraw(owner);
232
233 if (!m_wRoot)
234 {
235 m_bIsEnabled = false;
236 return;
237 }
238
239 if (m_sInterfaceSettingName != string.Empty)
241
242 // Call the interface method, to allow setup and customization of newly created InfoDisplayExtended class
243 DisplayStartDraw(owner);
244
245 // Call the interface method, to allow init of custom 'EntityChanged' code
246 DisplayControlledEntityChanged(null, m_PlayerController.GetControlledEntity());
247
248 // Call the interface method, with 'init = true' to flag this is not a standard state change, but initialization
250
251 // Init visibility of newly created InfoDisplay
252 UpdateVisibility();
253 }
254
255 //------------------------------------------------------------------------------------------------
256 private void OnControlledEntityChanged(IEntity from, IEntity to)
257 {
258 #ifdef DEBUG_INFO_DISPLAY_EXT
259 _printClass(string.Format("%1 [OnControlledEntityChanged] %2 -> %3", this, from, to));
260 #endif
261
262 if (from)
263 {
264 ChimeraCharacter character = ChimeraCharacter.Cast(from);
265 if (character && m_CharacterController)
266 m_CharacterController.m_OnLifeStateChanged.Remove(OnLifeStateChanged);
267 }
268
269 // Update camera handler + init 1st/3rd person monitoring, if visibility is changing between 1st/3rd person cameras
270 if (m_CameraHandler)
271 m_CameraHandler.GetThirdPersonSwitchInvoker().Remove(UpdateVisibility);
272
273 if (to)
274 m_CameraHandler = SCR_CharacterCameraHandlerComponent.Cast(to.FindComponent(SCR_CharacterCameraHandlerComponent));
275 else
276 m_CameraHandler = null;
277
279 m_CameraHandler.GetThirdPersonSwitchInvoker().Insert(UpdateVisibility);
280
282 m_EventHandlerManager.RemoveScriptHandler("OnADSChanged", this, OnADSSwitched);
283
284 IEntity eventHandlerOwner;
286 eventHandlerOwner = to;
287 else
288 eventHandlerOwner = m_OwnerEntity;
289
290 if (eventHandlerOwner)
291 m_EventHandlerManager = EventHandlerManagerComponent.Cast(eventHandlerOwner.FindComponent(EventHandlerManagerComponent));
292 else
294
296 m_EventHandlerManager.RegisterScriptHandler("OnADSChanged", this, OnADSSwitched);
297
298 m_bIsUnconscious = false;
299
300 // Update character controller
301 ChimeraCharacter character = ChimeraCharacter.Cast(to);
302 if (character)
303 {
304 m_CharacterController = SCR_CharacterControllerComponent.Cast(character.GetCharacterController());
306 {
307 m_CharacterController.m_OnLifeStateChanged.Insert(OnLifeStateChanged);
308 m_bIsUnconscious = m_CharacterController.GetLifeState() == ECharacterLifeState.INCAPACITATED;
309 }
310 }
311
312 // Init the state flags
313 m_bInADS = false;
314 m_bInThirdPerson = m_CameraHandler && m_CameraHandler.Is3rdPersonView();
315
316 // Stop if InfoDisplay is not created yet - happens on the 1st 'init' run only
317 if (!m_wRoot)
318 return;
319
320 // Call the interface method
322
323 // Call the interface method, with 'init = true' to flag this is not a standard state change, but initialization when entity changed
325
326 // Update visibility after entity changed
327 UpdateVisibility();
328 }
329
330 //------------------------------------------------------------------------------------------------
331 private void OnADSSwitched(BaseWeaponComponent weapon, bool inADS)
332 {
333 #ifdef DEBUG_INFO_DISPLAY_EXT
334 _printClass(string.Format("%1 [OnADSSwitched] inADS: %2", this, inADS));
335 #endif
336
337 m_bInADS = inADS;
338
339 UpdateVisibility();
340 }
341
342 //------------------------------------------------------------------------------------------------
343 private void OnLifeStateChanged(ECharacterLifeState previousLifeState, ECharacterLifeState newLifeState)
344 {
345 #ifdef DEBUG_INFO_DISPLAY_EXT
346 _printClass(string.Format("%1 [OnLifeStateChanged] lifeState: %2", this, SCR_Enum.GetEnumName(ECharacterLifeState, newLifeState)));
347 #endif
348
349 m_bIsUnconscious = newLifeState == ECharacterLifeState.INCAPACITATED;
350
352
353 UpdateVisibility();
354 }
355
356 //------------------------------------------------------------------------------------------------
357 private void OnPauseMenuOpen()
358 {
359 #ifdef DEBUG_INFO_DISPLAY_EXT
360 _printClass(string.Format("%1 [OnPauseMenuOpen]", this));
361 #endif
362
363 m_bInPauseMenu = true;
364
365 UpdateVisibility();
366 }
367
368 //------------------------------------------------------------------------------------------------
369 private void OnPauseMenuClose()
370 {
371 #ifdef DEBUG_INFO_DISPLAY_EXT
372 _printClass(string.Format("%1 [OnPauseMenuClose]", this));
373 #endif
374
375 m_bInPauseMenu = false;
376
377 UpdateVisibility();
378 }
379
380 //------------------------------------------------------------------------------------------------
381 private void OnEditorInit(SCR_EditorManagerEntity editorManager)
382 {
383 #ifdef DEBUG_INFO_DISPLAY_EXT
384 _printClass(string.Format("%1 [OnEditorInit] editorManager: %2", this, editorManager));
385 #endif
386
387 if (!editorManager)
388 return;
389
390 m_EditorManager = editorManager;
391 m_bInEditor = editorManager.IsOpened();
392
393 // Init Editor handling
394 if ((m_eShow & EShowGUI.IN_EDITOR) == 0)
395 {
396 m_EditorManager.GetOnOpened().Insert(OnEditorOpen);
397
398 m_EditorManager.GetOnClosed().Insert(OnEditorClose);
399 }
400 }
401
402 //------------------------------------------------------------------------------------------------
403 private void OnEditorOpen()
404 {
405 #ifdef DEBUG_INFO_DISPLAY_EXT
406 _printClass(string.Format("%1 [OnEditorOpen]", this));
407 #endif
408
409 m_bInEditor = true;
410
411 UpdateVisibility();
412 }
413
414 //------------------------------------------------------------------------------------------------
415 private void OnEditorClose()
416 {
417 #ifdef DEBUG_INFO_DISPLAY_EXT
418 _printClass(string.Format("%1 [OnEditorClose]", this));
419 #endif
420
421 m_bInEditor = false;
422
423 UpdateVisibility();
424 }
425
426 //------------------------------------------------------------------------------------------------
427 private void UpdateVisibility()
428 {
429 #ifdef DEBUG_INFO_DISPLAY_EXT
430 _printClass(string.Format("%1 [UpdateVisibility] m_bInEditor: %2 | m_bInPauseMenu: %3 | m_bIsUnconscious: %4", this, m_bInEditor, m_bInPauseMenu, m_bIsUnconscious));
431 #endif
432
433 bool menuPassed = !m_bInPauseMenu || (m_bInPauseMenu && m_eShow & EShowGUI.IN_PAUSE_MENU);
434 bool editorPassed = !m_bInEditor || (m_bInEditor && m_eShow & EShowGUI.IN_EDITOR);
435 bool statePassed = !m_bIsUnconscious || (m_bIsUnconscious && m_eShow & EShowGUI.WHILE_UNCONSCIOUS);
436 bool cameraPassed;
437
438 if (m_CameraHandler)
439 {
440 m_bInThirdPerson = !m_bInADS && m_CameraHandler.Is3rdPersonView();
441
442 cameraPassed = (m_bInADS && m_eShow & EShowGUI.IN_ADS) || (m_bInThirdPerson && m_eShow & EShowGUI.IN_3RD_PERSON) || (!m_bInThirdPerson && !m_bInADS && m_eShow & EShowGUI.IN_1ST_PERSON);
443 }
444 else
445 {
446 cameraPassed = m_eShow & EShowGUI.WITHOUT_ENTITY;
447 }
448
449 bool updateNeeded = (cameraPassed && statePassed && menuPassed && editorPassed && m_bIsEnabledInSettings) != m_bCanShow;
450
451 m_bCanShow = cameraPassed && statePassed && menuPassed && editorPassed && m_bIsEnabledInSettings;
452
453 if (!updateNeeded)
454 return;
455
456 Show(m_bShown);
457
458 if (m_bCanShow)
460 else
462 }
463
464 //------------------------------------------------------------------------------------------------
465 override void Show(bool show, float speed = UIConstants.FADE_RATE_INSTANT, EAnimationCurve curve = EAnimationCurve.LINEAR)
466 {
467 // Make hiding GUI cuz failing show-conditions always instant as we want to prevent visual artifacts
468 if (!m_bCanShow)
469 speed = UIConstants.FADE_RATE_INSTANT;
470
471 #ifdef DEBUG_INFO_DISPLAY_EXT
472 _printClass(string.Format("%1 [Show] m_bShown && m_bCanShow: %2 | m_bShown: %3 | m_bCanShow: %4", this, show && m_bCanShow, show, m_bCanShow));
473 #endif
474
475 super.Show(show && m_bCanShow, speed, curve);
476
477 m_bShown = show; // Re-store the 'shown' flag, that get overridden inside the Show() method, so the info is not lost
478 }
479
480 //------------------------------------------------------------------------------------------------
481 private override event void OnStopDraw(IEntity owner)
482 {
483 #ifdef DEBUG_INFO_DISPLAY_EXT
484 _printClass(string.Format("%1 [OnStopDraw] owner: %2", this, owner));
485 #endif
486
487 #ifdef DISABLE_HUD
488 m_bIsEnabled = false;
489 #endif
490
491 if (!m_bIsEnabled)
492 return;
493
495 m_PlayerController.m_OnControlledEntityChanged.Remove(OnControlledEntityChanged);
496
498 m_CharacterController.m_OnLifeStateChanged.Remove(OnLifeStateChanged);
499
500 PauseMenuUI.m_OnPauseMenuOpened.Remove(OnPauseMenuOpen);
501 PauseMenuUI.m_OnPauseMenuClosed.Remove(OnPauseMenuClose);
502
504 {
505 m_EditorManager.GetOnOpened().Remove(OnEditorOpen);
506 m_EditorManager.GetOnClosed().Remove(OnEditorClose);
507 }
508
510 m_CameraHandler.GetThirdPersonSwitchInvoker().Remove(UpdateVisibility);
511
513 m_EventHandlerManager.RemoveScriptHandler("OnADSChanged", this, OnADSSwitched);
514
515 super.OnStopDraw(owner);
516
517 DisplayStopDraw(owner);
518
519 GetGame().OnUserSettingsChangedInvoker().Remove(OnSettingsChanged);
520 }
521
522 //------------------------------------------------------------------------------------------------
523 private override event void OnInit(IEntity owner)
524 {
525 #ifdef DEBUG_INFO_DISPLAY_EXT
526 _printClass(string.Format("%1 [OnInit] owner: %2", this, owner));
527 #endif
528
529 #ifdef DISABLE_HUD
530 m_bIsEnabled = false;
531 #endif
532
533 if (!m_bIsEnabled)
534 return;
535
536 m_bAttachedToPlayerController = PlayerController.Cast(owner);
537
538 super.OnInit(owner);
539
540 DisplayInit(owner);
541 }
542
543 //------------------------------------------------------------------------------------------------
544 private override event void UpdateValues(IEntity owner, float timeSlice)
545 {
546 if (!m_bIsEnabled || !m_bCanShow)
547 return;
548
549 super.UpdateValues(owner, timeSlice);
550
551 DisplayUpdate(owner, timeSlice);
552 }
553}
ArmaReforgerScripted GetGame()
Definition game.c:1398
SCR_HUDManagerComponent m_HUDManager
Definition game.c:39
SCR_AIUtilityComponentClass m_OwnerEntity
override event void DisplayStartDraw(IEntity owner)
override event void DisplayInit(IEntity owner)
override event void DisplayUpdate(IEntity owner, float timeSlice)
override event void DisplayStopDraw(IEntity owner)
SCR_CharacterPerceivableComponentClass m_CharacterController
void SCR_EditorManagerEntity(IEntitySource src, IEntity parent)
SCR_FastTravelComponentClass m_PlayerController
Widget m_wRoot
bool m_bShown
override event void UpdateValues(IEntity owner, float timeSlice)
override event void OnStartDraw(IEntity owner)
override event void OnStopDraw(IEntity owner)
bool m_bInADS
bool m_bInPauseMenu
bool m_bAttachedToPlayerController
bool DisplayStartDrawInit(IEntity owner)
void DisplayConsciousnessChanged(bool conscious, bool init=false)
SCR_CharacterCameraHandlerComponent m_CameraHandler
bool m_bShowInAllCameras
void InitializeInterfaceSettings()
void DisplayControlledEntityChanged(IEntity from, IEntity to)
bool m_bIsUnconscious
EventHandlerManagerComponent m_EventHandlerManager
bool m_bInThirdPerson
bool m_bIsEnabledInSettings
MenuManager m_MenuManager
void DisplayOnSuspended()
Called when GUI is temporarily suspended due to visibility flags; e.g. GM entered and GUI marked as n...
string m_sInterfaceSettingName
void DisplayOnResumed()
bool m_bCanShow
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
SCR_EditorManagerEntity m_EditorManager
int Type
enum EVehicleType IEntity
EAnimationCurve
proto external Managed FindComponent(typename typeName)
static SCR_HUDManagerComponent GetHUDManager()
override void Show()
Definition gameLib.c:262
ECharacterLifeState
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
void SetEnabled(bool enabled)
proto external PlayerController GetPlayerController()
void OnControlledEntityChanged(IEntity from, IEntity to)
Runs every time the controlled entity has been changed.