Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_InfoDisplaySlotHandler.c
Go to the documentation of this file.
3 {
4  [Attribute()]
5  protected string m_sSlotName;
6 
7  protected float m_fWidth, m_fHeight;
8  protected Widget m_wSlot;
9  protected Widget m_wContent;
10  protected SCR_HUDGroupUIComponent m_GroupComponent;
11  protected SCR_HUDSlotUIComponent m_SlotComponent;
12  protected WorkspaceWidget m_wWorkspace;
13  protected bool m_bIsVisible;
14 
15  [Attribute("0.1", desc: "When a difference in size equivalent to this value is detected, the slot will be resized.")]
16  protected float m_fResizeSensitivity;
17 
18  //------------------------------------------------------------------------------------------------
19  SCR_HUDSlotUIComponent GetSlotUIComponent()
20  {
21  if (!m_wContent)
22  return null;
23 
24  Widget parentWidget = m_wContent.GetParent();
25  if (parentWidget)
26  m_SlotComponent = SCR_HUDSlotUIComponent.Cast(parentWidget.FindHandler(SCR_HUDSlotUIComponent));
27 
28  return m_SlotComponent;
29  }
30 
31  //------------------------------------------------------------------------------------------------
32  Widget GetSlotWidget()
33  {
34  if (!m_SlotComponent)
35  return null;
36 
37  return m_SlotComponent.GetRootWidget();
38  }
39 
40  //------------------------------------------------------------------------------------------------
41  SCR_HUDGroupUIComponent GetGroupUIComponent()
42  {
43  if (!m_wContent)
44  return null;
45 
46  Widget slotWidget = m_wContent.GetParent();
47  if (!slotWidget)
48  return null;
49 
50  Widget groupWidget = slotWidget.GetParent();
51  if (!groupWidget)
52  return null;
53 
54  m_GroupComponent = SCR_HUDGroupUIComponent.Cast(groupWidget.FindHandler(SCR_HUDGroupUIComponent));
55  return m_GroupComponent;
56  }
57 
58  string GetSlotName()
59  {
60  return m_sSlotName;
61  }
62 
63  void SetSlotComponent(notnull SCR_HUDSlotUIComponent slot)
64  {
65  m_SlotComponent = slot;
66  }
67 
68  void SetGroupComponent(notnull SCR_HUDGroupUIComponent group)
69  {
70  m_GroupComponent = group;
71  }
72 
73  //------------------------------------------------------------------------------------------------
74  protected override void OnStart(notnull SCR_InfoDisplay display)
75  {
76 #ifdef WORKBENCH
77  if (!m_bCanUpdate)
78  Print("SCR_InfoDisplaySlotHandler requires CanUpdate to be set to true!", LogLevel.WARNING);
79 #endif
80  m_wWorkspace = GetGame().GetWorkspace();
81 
82  SCR_HUDManagerComponent hudManager = null;
83  SCR_HUDLayout owningLayout = null;
84 
85  if (!GrabHudComponents(m_GroupComponent, m_SlotComponent, hudManager, owningLayout))
86  {
87  Print("Failed To Create A Slot: " + m_sSlotName + ". One of the properties of the Info Dispaly is not defined properly, witch is preventing the initialization.", LogLevel.ERROR);
88  return;
89  }
90 
91  SCR_HUDManagerLayoutHandler layoutHandler = SCR_HUDManagerLayoutHandler.Cast(hudManager.FindHandler(SCR_HUDManagerLayoutHandler));
92  if (!layoutHandler)
93  {
94  Print("Failed to obtain SCR_HUDManagerLayoutHandler for InfoDisplay: " + m_OwnerDisplay.Type().ToString(), LogLevel.ERROR);
95  return;
96  }
97 
98  m_wSlot = m_SlotComponent.GetRootWidget();
99  if (!m_wSlot)
100  return;
101 
102  if (m_wSlot.GetChildren())
103  {
104  Print("Slot Already Taken: " + m_sSlotName + ". The Slot an Info Display is trying to occupy is already occupied!", LogLevel.ERROR);
105  return;
106  }
107 
108  Widget displayWidget = m_wWorkspace.CreateWidgets(display.m_LayoutPath, m_wSlot);
109  if (!displayWidget)
110  return;
111  m_wContent = displayWidget;
112 
113  SCR_HUDElement hudElement = new SCR_HUDElement();
114  hudElement.SetWidget(displayWidget);
115  hudElement.SetParentWidgetName(m_sSlotName);
116  hudElement.SetParentLayout(owningLayout);
117  owningLayout.AddHudElement(hudElement, false);
118 
119  display.SetRootWidget(displayWidget);
120  display.SetContentWidget(displayWidget);
121  display.RegisterToHudManager();
122 
123  m_bIsVisible = displayWidget.IsVisible();
124 
125  m_SlotComponent.Initialize();
126  m_SlotComponent.GetOnResize().Insert(OnSlotResize);
127 
128  m_GroupComponent.ResizeGroup();
129  }
130 
131  //------------------------------------------------------------------------------------------------
132  protected override void OnStop(notnull SCR_InfoDisplay display)
133  {
134  if (m_SlotComponent)
135  m_SlotComponent.GetOnResize().Remove(OnSlotResize);
136  }
137 
138  //------------------------------------------------------------------------------------------------
139  protected bool GrabHudComponents(out SCR_HUDGroupUIComponent groupComponent, out SCR_HUDSlotUIComponent slotComponent, out SCR_HUDManagerComponent hudManager, out SCR_HUDLayout owningLayout)
140  {
141  hudManager = SCR_HUDManagerComponent.GetHUDManager();
142  if (!hudManager)
143  return false;
144 
145  SCR_HUDManagerLayoutHandler layoutHandler = SCR_HUDManagerLayoutHandler.Cast(hudManager.FindHandler(SCR_HUDManagerLayoutHandler));
146  if (!layoutHandler)
147  return false;
148 
149  slotComponent = layoutHandler.FindSlotComponentFromAnyLayout(m_sSlotName, owningLayout);
150  if (!slotComponent)
151  return false;
152 
153  Widget slotWidget = slotComponent.GetRootWidget();
154  if (!slotWidget)
155  return false;
156 
157  Widget groupWidget = slotWidget.GetParent();
158  if (!groupWidget)
159  return false;
160 
161  groupComponent = SCR_HUDGroupUIComponent.Cast(groupWidget.FindHandler(SCR_HUDGroupUIComponent));
162  if (!groupComponent)
163  return false;
164 
165  return true;
166  }
167 
168  //------------------------------------------------------------------------------------------------
169  private void OnSlotResize(notnull SCR_HUDSlotUIComponent slot)
170  {
171  m_fWidth = slot.GetWidth();
172  m_fHeight = slot.GetHeight();
173  }
174 
175  //------------------------------------------------------------------------------------------------
176  override void OnUpdate(float timeSlice)
177  {
178  if (!m_wContent)
179  return;
180 
181  float width, height;
182  m_wContent.GetScreenSize(width, height);
183 
184  width = m_wWorkspace.DPIUnscale(width);
185  height = m_wWorkspace.DPIUnscale(height);
186 
187  bool isVisible = m_wContent.IsVisible();
188 
189  if (!float.AlmostEqual(width, m_fWidth, m_fResizeSensitivity) || !float.AlmostEqual(height, m_fHeight, m_fResizeSensitivity) || m_bIsVisible != isVisible)
190  {
191  m_GroupComponent.ResizeGroup();
192  m_fHeight = height;
193  m_fWidth = width;
194  m_bIsVisible = isVisible;
195  }
196 
197  }
198 }
SCR_HUDManagerComponent
Definition: SCR_HUDManagerComponent.c:23
SCR_HUDGroupUIComponent
Definition: SCR_HUDGroupUIComponent.c:1
m_fHeight
protected float m_fHeight
Definition: SCR_BaseAreaMeshComponent.c:15
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
Attribute
typedef Attribute
Post-process effect of scripted camera.
m_wContent
protected Widget m_wContent
Definition: SCR_InfoDisplay.c:64
SCR_InfoDisplaySlotHandler
Definition: SCR_InfoDisplaySlotHandler.c:2
m_wSlot
protected Widget m_wSlot
Definition: SCR_InfoDisplay.c:65
SCR_HUDManagerLayoutHandler
Definition: SCR_HUDManagerLayoutHandler.c:7
SCR_InfoDisplayHandler
Definition: SCR_InfoDisplayHandler.c:2
m_bIsVisible
protected bool m_bIsVisible
Definition: SCR_MapRTWBaseUI.c:29
SCR_HUDElement
Definition: SCR_HUDFreeSlot.c:1
SCR_HUDSlotUIComponent
Definition: SCR_HUDSlotUIComponent.c:5
m_wWorkspace
private WorkspaceWidget m_wWorkspace
Definition: SCR_CursorEditorUIComponent.c:17
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