Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_HUDManagerLayoutHandler.c
Go to the documentation of this file.
1 void OnLayoutChangeMethod(SCR_HUDLayout newLayout, SCR_HUDLayout oldLayout, SCR_HUDManagerComponent hudManager);
3 typedef ScriptInvokerBase<OnLayoutChangeMethod> OnLayoutChange;
4 
5 
8 {
9  [Attribute()]
10  protected ref array<ref SCR_HUDLayout> m_aHUDLayouts;
11 
12  [Attribute()]
13  protected string m_sMainLayout;
14 
15  protected SCR_HUDLayout m_ActiveLayout;
16  protected ref OnLayoutChange m_OnLayoutChange;
17 
18  protected ref ScriptInvokerVoid m_OnMainLayoutInitialize;
19 
20  //------------------------------------------------------------------------------------------------
21  void AddHUDLayout(notnull SCR_HUDLayout layout)
22  {
23  m_aHUDLayouts.Insert(layout);
24  }
25 
26  //------------------------------------------------------------------------------------------------
27  void RemoveHUDLayout(notnull SCR_HUDLayout layout)
28  {
29  if (m_aHUDLayouts.Contains(layout))
30  m_aHUDLayouts.RemoveItem(layout);
31  }
32 
33  //------------------------------------------------------------------------------------------------
34  array<ref SCR_HUDLayout> GetAllHUDLayouts()
35  {
36  ref array<ref SCR_HUDLayout> allLayouts = {};
37 
38  foreach (SCR_HUDLayout layout : m_aHUDLayouts)
39  {
40  allLayouts.Insert(layout);
41  }
42 
43  return allLayouts;
44  }
45 
46  //------------------------------------------------------------------------------------------------
47  OnLayoutChange GetOnLayoutChange()
48  {
49  if (!m_OnLayoutChange)
50  m_OnLayoutChange = new OnLayoutChange();
51 
52  return m_OnLayoutChange;
53  }
54 
55  //------------------------------------------------------------------------------------------------
56  SCR_HUDLayout GetActiveLayout()
57  {
58  return m_ActiveLayout;
59  }
60 
61  //------------------------------------------------------------------------------------------------
62  int GetAllHudElements(notnull out array<SCR_HUDElement> hudElements)
63  {
64  hudElements.Clear();
65 
66  foreach (SCR_HUDLayout hudLayout : m_aHUDLayouts)
67  {
68  hudLayout.GetHUDElements(hudElements);
69  }
70 
71  return hudElements.Count();
72  }
73 
74  //------------------------------------------------------------------------------------------------
75  array<string> GetAllIdentifiers()
76  {
77  array<string> allIdentifiers = {};
78  foreach (SCR_HUDLayout hudLayout : m_aHUDLayouts)
79  {
80  allIdentifiers.Insert(hudLayout.GetIdentifier());
81  }
82 
83  return allIdentifiers;
84  }
85 
86  //------------------------------------------------------------------------------------------------
91  Widget GetGroupByName(string groupName)
92  {
93  if (!m_ActiveLayout)
94  return null;
95 
96  return m_ActiveLayout.GetGroupWidgetByName(groupName);
97  }
98 
99  //------------------------------------------------------------------------------------------------
104  SCR_HUDGroupUIComponent GetGroupComponent(string groupName)
105  {
106  if (!m_ActiveLayout)
107  return null;
108 
109  return m_ActiveLayout.GetGroupComponent(groupName);
110  }
111 
112  //------------------------------------------------------------------------------------------------
117  SCR_HUDSlotUIComponent GetSlotComponentByName(string slotName)
118  {
119  if (!m_ActiveLayout)
120  return null;
121 
122  return m_ActiveLayout.FindSlotComponent(slotName);
123  }
124 
125  //------------------------------------------------------------------------------------------------
126  SCR_HUDSlotUIComponent FindSlotComponentFromAnyLayout(string slotName, out SCR_HUDLayout foundLayout = null)
127  {
128  SCR_HUDSlotUIComponent slotToReturn = GetSlotComponentByName(slotName);
129  if (!slotToReturn)
130  {
131  foreach (SCR_HUDLayout layout : m_aHUDLayouts)
132  {
133  slotToReturn = layout.FindSlotComponent(slotName);
134  if (slotToReturn)
135  {
136  foundLayout = layout;
137  return slotToReturn;
138  }
139  }
140  }
141 
142  foundLayout = m_ActiveLayout;
143  return slotToReturn;
144  }
145 
146  //------------------------------------------------------------------------------------------------
151  Widget FindWidgetByName(string widgetName)
152  {
153  if (!m_ActiveLayout)
154  return null;
155 
156  return m_ActiveLayout.FindWidgetByName(widgetName);
157  }
158 
159  //------------------------------------------------------------------------------------------------
160  Widget FindWidgetByNameFromAnyLayout(string widgetName, out SCR_HUDLayout foundLayout = null)
161  {
162  Widget foundWidget = FindWidgetByName(widgetName);
163  if (foundWidget)
164  {
165  foundLayout = m_ActiveLayout;
166  return foundWidget;
167  }
168 
169  foreach (SCR_HUDLayout hudLayout : m_aHUDLayouts)
170  {
171  foundWidget = hudLayout.FindWidgetByName(widgetName);
172  if (foundWidget)
173  {
174  foundLayout = hudLayout;
175  return foundWidget;
176  }
177  }
178 
179  return null;
180  }
181 
182  //------------------------------------------------------------------------------------------------
183  SCR_HUDLayout FindHUDLayout(string layoutIdentifier)
184  {
185  foreach (SCR_HUDLayout hudLayout : m_aHUDLayouts)
186  {
187  if (hudLayout.GetIdentifier() == layoutIdentifier)
188  return hudLayout;
189  }
190 
191  return null;
192  }
193 
194  //------------------------------------------------------------------------------------------------
195  protected void InitializeHUDLayouts()
196  {
197  WorkspaceWidget workspace = GetGame().GetWorkspace();
198 
199  foreach (SCR_HUDLayout hudLayout : m_aHUDLayouts)
200  {
201  Widget layoutWidget = workspace.CreateWidgets(hudLayout.GetLayout(), null);
202  if (!layoutWidget)
203  continue;
204 
205  hudLayout.SetRootWidget(layoutWidget);
206 
207  if (hudLayout.GetIdentifier() == m_sMainLayout)
208  {
209  m_ActiveLayout = hudLayout;
210  continue;
211  }
212 
213  layoutWidget.SetVisible(false);
214  layoutWidget.SetEnabled(false);
215  }
216  }
217 
218  //------------------------------------------------------------------------------------------------
219  void ChangeActiveHUDLayout(string layoutIdentifier = string.Empty)
220  {
221  if (layoutIdentifier.IsEmpty())
222  layoutIdentifier = m_sMainLayout;
223 
224  SCR_HUDLayout newLayout = FindHUDLayout(layoutIdentifier);
225  if (!newLayout || newLayout == m_ActiveLayout)
226  return;
227 
228  if (m_ActiveLayout)
229  SetLayoutEnabled(m_ActiveLayout.GetIdentifier(), false);
230 
231  SCR_HUDLayout mainLayout = FindHUDLayout(m_sMainLayout);
232  SCR_HUDLayout oldActiveLayout = m_ActiveLayout;
233  m_ActiveLayout = newLayout;
234  SetLayoutEnabled(m_ActiveLayout.GetIdentifier(), true);
235 
236  array<SCR_HUDElement> allHudElements = {};
237  GetAllHudElements(allHudElements);
238 
239  foreach (SCR_HUDElement element : allHudElements)
240  {
241  Widget elementWidget = element.GetWidget();
242  if (!elementWidget)
243  continue;
244 
245  Widget oldParentWidget = elementWidget.GetParent();
246  Widget newParentWidget = newLayout.FindWidgetByName(element.GetParentWidgetName());
247 
248  // Assign every slot back to the Main layout first to prevent them from getting destroyed
249  if (newLayout.GetIdentifier() != m_sMainLayout)
250  {
251  SCR_HUDLayout oldLayout = element.GetParentLayout();
252  if (oldLayout)
253  oldLayout.RemoveHudElement(element, true);
254 
255  elementWidget.SetVisible(false);
256  elementWidget.SetEnabled(false);
257 
258  if (mainLayout)
259  mainLayout.AddHudElement(element, true);
260  }
261 
262  if (!newParentWidget)
263  continue;
264 
265  elementWidget.SetVisible(true);
266  elementWidget.SetEnabled(true);
267 
268  SCR_HUDLayout oldLayout = element.GetParentLayout();
269  if (oldLayout)
270  oldLayout.RemoveHudElement(element, true);
271 
272  newLayout.AddHudElement(element, true);
273  }
274 
275  if (m_OnLayoutChange)
276  m_OnLayoutChange.Invoke(newLayout, oldActiveLayout, m_HUDManager);
277 
278  // Resize UI 1 frame after initializing it to prevent wrong resizing when done on same frame
279  GetGame().GetCallqueue().Call(newLayout.ResizeLayout);
280  }
281 
282  //------------------------------------------------------------------------------------------------
283  void SetLayoutEnabled(string layoutIdentifier, bool isEnabled)
284  {
285  SCR_HUDLayout hudLayout = FindHUDLayout(layoutIdentifier);
286  if (!hudLayout)
287  return;
288 
289  Widget hudWidget = hudLayout.GetRootWidget();
290  if (!hudWidget)
291  return;
292 
293  hudWidget.SetVisible(isEnabled);
294  hudWidget.SetEnabled(isEnabled);
295  }
296 
297  //------------------------------------------------------------------------------------------------
298  protected void StartMainLayout()
299  {
300  if (m_HUDManager.GetHUDElements().IsEmpty())
301  return;
302 
303  ChangeActiveHUDLayout(m_sMainLayout);
304  m_HUDManager.RemoveHandlerFromUpdatableHandlers(this);
305 
306  if (m_OnMainLayoutInitialize)
307  m_OnMainLayoutInitialize.Invoke();
308  }
309 
310  //------------------------------------------------------------------------------------------------
311  override void OnInit(notnull SCR_HUDManagerComponent owner)
312  {
313  super.OnInit(owner);
314 
315  InitializeHUDLayouts();
316  }
317 
318  //------------------------------------------------------------------------------------------------
319  override void OnUpdate(notnull SCR_HUDManagerComponent owner)
320  {
321  StartMainLayout();
322  }
323 
324  //------------------------------------------------------------------------------------------------
325  ScriptInvokerVoid GetOnMainLayoutInitialize()
326  {
327  if (!m_OnMainLayoutInitialize)
328  m_OnMainLayoutInitialize = new ScriptInvokerVoid();
329 
330  return m_OnMainLayoutInitialize;
331  }
332 
333 }
SCR_HUDManagerComponent
Definition: SCR_HUDManagerComponent.c:23
SCR_HUDManagerHandler
Definition: SCR_HUDManagerHandler.c:2
SCR_HUDGroupUIComponent
Definition: SCR_HUDGroupUIComponent.c:1
OnLayoutChange
ScriptInvokerBase< OnLayoutChangeMethod > OnLayoutChange
Definition: SCR_HUDManagerLayoutHandler.c:3
m_HUDManager
protected SCR_HUDManagerComponent m_HUDManager
Definition: game.c:41
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SCR_HUDLayout
Definition: SCR_HUDLayout.c:2
func
func
Definition: SCR_AIThreatSystem.c:5
OnLayoutChangeMethod
func OnLayoutChangeMethod
Definition: SCR_HUDManagerLayoutHandler.c:2
Attribute
typedef Attribute
Post-process effect of scripted camera.
layout
UI layouts HUD CampaignMP CampaignMainHUD layout
Definition: SCR_ScenarioFrameworkLayerTaskDefend.c:20
SCR_HUDManagerLayoutHandler
Definition: SCR_HUDManagerLayoutHandler.c:7
ScriptInvokerVoid
ScriptInvokerBase< ScriptInvokerVoidMethod > ScriptInvokerVoid
Definition: SCR_ScriptInvokerHelper.c:9
SCR_HUDElement
Definition: SCR_HUDFreeSlot.c:1
SCR_HUDSlotUIComponent
Definition: SCR_HUDSlotUIComponent.c:5
BaseContainerProps
SCR_AIGoalReaction_Follow BaseContainerProps
Handles insects that are supposed to be spawned around selected prefabs defined in prefab names array...
Definition: SCR_AIGoalReaction.c:468