Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_HUDGroupUIComponent.c
Go to the documentation of this file.
1 class SCR_HUDGroupUIComponent : ScriptedWidgetComponent
2 {
3  [Attribute("1")]
4  protected bool m_bEnableDebugFont;
5 
6  [Attribute("20")]
8  private int m_iDebugFontSize;
9 
10  protected float m_fWidth;
11  protected float m_fHeight;
12 
13  protected Widget m_wRoot;
14 
15  protected ref SCR_HUDSizeCalculator m_HUDSizeCalculator = new SCR_HUDSizeCalculator();
16  protected ref array<SCR_HUDSlotUIComponent> m_aSlots = {};
17 
18  //------------------------------------------------------------------------------------------------
22  Widget GetRootWidget()
23  {
24  return m_wRoot;
25  }
26 
27  //------------------------------------------------------------------------------------------------
28  int GetSlotComponents(notnull out array<SCR_HUDSlotUIComponent> slotComponents)
29  {
30  slotComponents.Clear();
31 
32  foreach (SCR_HUDSlotUIComponent slot : m_aSlots)
33  {
34  slotComponents.Insert(slot);
35  }
36 
37  return slotComponents.Count();
38  }
39 
40  //------------------------------------------------------------------------------------------------
41  SCR_HUDSlotUIComponent FindSlotComponent(string slotName)
42  {
43  foreach (SCR_HUDSlotUIComponent slot : m_aSlots)
44  {
45  Widget slotWidget = slot.GetRootWidget();
46  if (!slotWidget)
47  continue;
48 
49  if (slotWidget.GetName() == slotName)
50  return slot;
51  }
52 
53  return null;
54  }
55 
56 #ifdef WORKBENCH
57  //------------------------------------------------------------------------------------------------
58  override bool OnUpdate(Widget w)
59  {
60  if (!SCR_Global.IsEditMode())
61  return false;
62 
63  m_wRoot.GetScreenSize(m_fWidth, m_fHeight);
64  m_HUDSizeCalculator.ResizeGroup(m_aSlots, m_fHeight, m_fWidth);
65 
66  return false;
67  }
68 #endif
69 
70  //------------------------------------------------------------------------------------------------
74  void ResizeGroup()
75  {
76  WorkspaceWidget workspace = GetGame().GetWorkspace();
77 
78  m_wRoot.GetScreenSize(m_fWidth, m_fHeight);
79  m_fWidth = workspace.DPIUnscale(m_fWidth);
80  m_fHeight = workspace.DPIUnscale(m_fHeight);
81 
82  m_HUDSizeCalculator.ResizeGroup(m_aSlots, m_fHeight, m_fWidth);
83  }
84 
85  //------------------------------------------------------------------------------------------------
86  override void HandlerAttached(Widget w)
87  {
88  m_wRoot = w;
89 
90  Widget iteratedWidget = w.GetChildren();
91  while (iteratedWidget)
92  {
93  SCR_HUDSlotUIComponent slot = SCR_HUDSlotUIComponent.Cast(iteratedWidget.FindHandler(SCR_HUDSlotUIComponent));
94  if (!slot)
95  {
96  iteratedWidget = iteratedWidget.GetSibling();
97  continue;
98  }
99 
100  slot.Initialize();
101  m_aSlots.Insert(slot);
102  iteratedWidget = iteratedWidget.GetSibling();
103  }
104 
105 #ifdef WORKBENCH
106  if (!SCR_Global.IsEditMode())
107  return;
108 
109  WorkspaceWidget workspace = GetGame().GetWorkspace();
110  foreach (SCR_HUDSlotUIComponent slot : m_aSlots)
111  {
112  FrameWidget slotFrame = FrameWidget.Cast(slot.GetRootWidget());
113  if (!slotFrame)
114  {
115  Debug.Error2("Wrong Slot Widget Type", "SCR_HUDSlotUIComponent Requires to be attached to a FrameWidget!");
116  return;
117  }
118 
119  slot.m_wDebugOverlay = OverlayWidget.Cast(workspace.CreateWidget(WidgetType.OverlayWidgetTypeID, WidgetFlags.VISIBLE, Color.FromInt(Color.BLACK), 0, slot.GetRootWidget()));
120  if (!slot.m_wDebugOverlay || !m_bEnableDebugFont)
121  return;
122 
123  slot.m_wDebugImg = ImageWidget.Cast(workspace.CreateWidget(WidgetType.ImageWidgetTypeID, WidgetFlags.VISIBLE, new Color(Math.RandomFloat(0, 0.1), Math.RandomFloat(0, 0.1), Math.RandomFloat(0, 0.1), 1), 0, slot.m_wDebugOverlay));
124  LayoutSlot.SetHorizontalAlign(slot.m_wDebugImg, LayoutHorizontalAlign.Stretch);
125  LayoutSlot.SetVerticalAlign(slot.m_wDebugImg, LayoutVerticalAlign.Stretch);
126 
127  slot.m_wDebugVertical = workspace.CreateWidget(WidgetType.VerticalLayoutWidgetTypeID, WidgetFlags.VISIBLE, Color.FromInt(Color.BLACK), 0, slot.m_wDebugOverlay);
128  OverlaySlot.SetHorizontalAlign(slot.m_wDebugVertical, LayoutHorizontalAlign.Stretch);
129  OverlaySlot.SetVerticalAlign(slot.m_wDebugVertical, LayoutVerticalAlign.Stretch);
130 
131  slot.m_wDebugNameText = TextWidget.Cast(workspace.CreateWidget(WidgetType.TextWidgetTypeID, WidgetFlags.VISIBLE, Color.FromInt(Color.WHITE), 0, slot.m_wDebugVertical));
132  OverlaySlot.SetHorizontalAlign(slot.m_wDebugNameText, LayoutHorizontalAlign.Center);
133  slot.m_wDebugNameText.SetText(slot.GetRootWidget().GetName());
134  slot.m_wDebugNameText.SetExactFontSize(m_iDebugFontSize);
135 
136  slot.m_wDebugPriorityText = TextWidget.Cast(workspace.CreateWidget(WidgetType.TextWidgetTypeID, WidgetFlags.VISIBLE, Color.FromInt(Color.WHITE), 0, slot.m_wDebugVertical));
137  OverlaySlot.SetHorizontalAlign(slot.m_wDebugPriorityText, LayoutHorizontalAlign.Center);
138  slot.SetPriority(slot.GetPriority());
139  slot.m_wDebugPriorityText.SetExactFontSize(m_iDebugFontSize);
140 
141  slot.m_wDebugHeightText = RichTextWidget.Cast(workspace.CreateWidget(WidgetType.RichTextWidgetTypeID, WidgetFlags.VISIBLE, Color.FromInt(Color.WHITE), 0, slot.m_wDebugVertical));
142  OverlaySlot.SetHorizontalAlign(slot.m_wDebugHeightText, LayoutHorizontalAlign.Center);
143  slot.m_wDebugHeightText.SetExactFontSize(m_iDebugFontSize);
144 
145  slot.m_wDebugWidthText = RichTextWidget.Cast(workspace.CreateWidget(WidgetType.RichTextWidgetTypeID, WidgetFlags.VISIBLE, Color.FromInt(Color.WHITE), 0, slot.m_wDebugVertical));
146  OverlaySlot.SetHorizontalAlign(slot.m_wDebugWidthText, LayoutHorizontalAlign.Center);
147  slot.m_wDebugWidthText.SetExactFontSize(m_iDebugFontSize);
148  }
149 
150 #endif
151  }
152 };
SCR_HUDGroupUIComponent
Definition: SCR_HUDGroupUIComponent.c:1
m_fHeight
protected float m_fHeight
Definition: SCR_BaseAreaMeshComponent.c:15
m_wRoot
protected Widget m_wRoot
Definition: SCR_ScenarioFrameworkLayerTaskDefend.c:59
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
OnUpdate
override void OnUpdate(BaseWorld world, float timeslice)
Definition: game.c:910
SCR_HUDSizeCalculator
Definition: SCR_HUDSizeCalculator.c:7
Attribute
typedef Attribute
Post-process effect of scripted camera.
m_aSlots
protected ref array< SCR_WeaponRackSlotEntity > m_aSlots
Definition: SCR_ArsenalDisplayComponent.c:13
SCR_Global
Definition: Functions.c:6
SCR_HUDSlotUIComponent
Definition: SCR_HUDSlotUIComponent.c:5