Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_HUDMenuComponent.c
Go to the documentation of this file.
2 {
3  [Attribute(desc: "Identifier used by HudManager to find the correct layout. \nMUST BE UNIQUE!!")]
4  protected string m_sIdentifier;
5 
6  protected ref SCR_HUDLayout m_HudLayout = new SCR_HUDLayout();
7 
8  protected SCR_HUDManagerLayoutHandler m_LayoutHandler;
9  protected SCR_HUDManagerComponent m_HudManager;
10 
11  protected bool m_bIsMenuEnabled;
12 
13  //------------------------------------------------------------------------------------------------
14  override void HandlerAttached(Widget w)
15  {
16  m_wRoot = w;
17 
18  if (!m_wRoot.IsEnabled())
19  return;
20 
21  ActivateHudLayout();
22  }
23 
24  //------------------------------------------------------------------------------------------------
25  override void HandlerDeattached(Widget w)
26  {
27  if (!m_LayoutHandler || !m_bIsMenuEnabled)
28  return;
29 
30  m_bIsMenuEnabled = false;
31  DeactivateHudLayout();
32  }
33 
34  //------------------------------------------------------------------------------------------------
36  protected void ActivateHudLayout()
37  {
38  if (!m_HudLayout)
39  {
40  Print("Failed to initialize SCR_HUDLayout!", LogLevel.WARNING);
41  return;
42  }
43 
44  m_HudLayout.SetRootWidget(m_wRoot);
45 
46  if (!m_sIdentifier)
47  {
48  Print("No Identifier set in " + ClassName() + ". Set a unique identifier!", LogLevel.WARNING);
49  return;
50  }
51 
52  m_HudLayout.SetIdentifier(m_sIdentifier);
53 
54  PlayerController pController = GetGame().GetPlayerController();
55  if (!pController)
56  return;
57 
58  m_HudManager = SCR_HUDManagerComponent.Cast(pController.FindComponent(SCR_HUDManagerComponent));
59  if (!m_HudManager)
60  return;
61 
62  m_LayoutHandler = SCR_HUDManagerLayoutHandler.Cast(m_HudManager.FindHandler(SCR_HUDManagerLayoutHandler));
63  if (!m_LayoutHandler)
64  return;
65 
66  if (m_HudManager.GetHUDElements().IsEmpty())
67  {
68  //Wait for the MainLayout to be initialize and try again
69  m_LayoutHandler.GetOnMainLayoutInitialize().Insert(DelayHUDLayoutChange);
70  return;
71  }
72 
73  m_LayoutHandler.GetOnMainLayoutInitialize().Remove(DelayHUDLayoutChange);
74 
75  if (!m_LayoutHandler.GetAllHUDLayouts().Contains(m_HudLayout))
76  m_LayoutHandler.AddHUDLayout(m_HudLayout);
77 
78  m_LayoutHandler.ChangeActiveHUDLayout(m_sIdentifier);
79 
80  m_bIsMenuEnabled = true;
81  }
82 
83  //------------------------------------------------------------------------------------------------
85  protected void DeactivateHudLayout()
86  {
87  if (!m_LayoutHandler)
88  return;
89 
90  //Remove the Listener in case the Menu gets closed before the MainLayout is initialized
91  m_LayoutHandler.GetOnMainLayoutInitialize().Remove(DelayHUDLayoutChange);
92 
93  if (m_HudManager.GetHUDElements().IsEmpty())
94  return;
95 
96  SCR_HUDLayout currentLayout = m_LayoutHandler.GetActiveLayout();
97 
98  //If there is no new layout yet, activate the Main layout otherwise the new Menu will Change it itself.
99  if (currentLayout == m_HudLayout)
100  m_LayoutHandler.ChangeActiveHUDLayout();
101 
102  if (m_LayoutHandler.GetAllHUDLayouts().Contains(m_HudLayout))
103  m_LayoutHandler.RemoveHUDLayout(m_HudLayout);
104  }
105 
106  //------------------------------------------------------------------------------------------------
107  void DelayHUDLayoutChange()
108  {
109  //Delay the change of the HUDLayout when they just got initialized to prevent wrong reparenting
110  GetGame().GetCallqueue().Call(ActivateHudLayout);
111  }
112 
113  //------------------------------------------------------------------------------------------------
115  void EnableHUDMenu()
116  {
117  m_wRoot.SetEnabled(true);
118  ActivateHudLayout();
119  }
120 
121  //------------------------------------------------------------------------------------------------
123  void DisableHUDMenu()
124  {
125  m_bIsMenuEnabled = false;
126  DeactivateHudLayout();
127  }
128 }
SCR_HUDManagerComponent
Definition: SCR_HUDManagerComponent.c:23
m_wRoot
protected Widget m_wRoot
Definition: SCR_ScenarioFrameworkLayerTaskDefend.c:59
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SCR_HUDLayout
Definition: SCR_HUDLayout.c:2
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
m_sIdentifier
string m_sIdentifier
Definition: SCR_MapMarkerEntryPlaced.c:3
SCR_HUDMenuComponent
Definition: SCR_HUDMenuComponent.c:1
Attribute
typedef Attribute
Post-process effect of scripted camera.
SCR_HUDManagerLayoutHandler
Definition: SCR_HUDManagerLayoutHandler.c:7
SCR_ScriptedWidgetComponent
Definition: SCR_ScriptedWidgetComponent.c:7