Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_BreadCrumbsComponent.c
Go to the documentation of this file.
2 {
3  [Attribute()]
4  protected ref array<string> m_aContent;
5 
6  [Attribute(defvalue: "{86576034F67F9F64}UI/layouts/Menus/Breadcrumbs/BreadCrumbsElement.layout")]
7  protected ResourceName m_sElementLayout;
8 
9  [Attribute(defvalue: "{287A657BF9A33943}UI/layouts/Menus/Breadcrumbs/BreadCrumbsRichElement.layout")]
10  protected ResourceName m_sRichElementLayout;
11 
12  [Attribute(defvalue: "{240DC2208952C2C2}UI/layouts/Menus/Breadcrumbs/BreadCrumbsSeparator.layout")]
13  protected ResourceName m_sSeparatorLayout;
14 
15  protected ref array<Widget> m_aElements = {};
16  protected ref array<Widget> m_aSeparators = {};
17 
18  //------------------------------------------------------------------------------------------------
19  override void HandlerAttached(Widget w)
20  {
21  super.HandlerAttached(w);
22 
23  Refresh();
24  }
25 
26  //------------------------------------------------------------------------------------------------
27  void Clear()
28  {
29  if (!m_aContent)
30  return;
31 
32  m_aContent.Clear();
33  Refresh();
34  }
35 
36  //------------------------------------------------------------------------------------------------
37  void Set(array<string> values)
38  {
39  if (!values) // can be empty
40  return;
41 
42  if (!m_aContent)
43  m_aContent = {};
44  else
45  m_aContent.Clear();
46 
47  foreach (string value : values)
48  {
49  value = value.Trim();
50  if (value)
51  m_aContent.Insert(value);
52  }
53 
54  Refresh();
55  }
56 
57  //------------------------------------------------------------------------------------------------
58  void Set(string value1, string value2 = "", string value3 = "")
59  {
60  array<string> values = { value1, value2, value3 };
61  Set(values);
62  }
63 
64  //------------------------------------------------------------------------------------------------
65  void SetFormat(string value, string arg1, string arg2 = "")
66  {
67  SCR_WidgetHelper.RemoveAllChildren(m_wRoot);
68 
69  Widget widget = GetGame().GetWorkspace().CreateWidgets(m_sElementLayout, m_wRoot);
70  if (!widget)
71  return;
72 
73  TextWidget textWidget = TextWidget.Cast(widget);
74  if (!textWidget)
75  return;
76 
77  textWidget.SetTextFormat(value, arg1, arg2);
78  m_aContent = { value };
79  }
80 
81  //------------------------------------------------------------------------------------------------
82  void SetRichFormat(string value, string arg1, string arg2 = "")
83  {
84  SCR_WidgetHelper.RemoveAllChildren(m_wRoot);
85 
86  Widget widget = GetGame().GetWorkspace().CreateWidgets(m_sRichElementLayout, m_wRoot);
87  if (!widget)
88  return;
89 
90  RichTextWidget richTextWidget = RichTextWidget.Cast(widget);
91  if (!richTextWidget)
92  return;
93 
94  richTextWidget.SetTextFormat(value, arg1, arg2);
95  m_aContent = { value };
96  }
97 
98  //------------------------------------------------------------------------------------------------
99  void AddBreadCrumbElement(SCR_UIInfo info)
100  {
101  Widget widget = GetGame().GetWorkspace().CreateWidgets(m_sElementLayout, m_wRoot);
102  if (!widget)
103  return;
104 
106  widget.FindHandler(SCR_BreadCrumbsElementComponent));
107 
108  if (comp)
109  comp.SetBreadCrumb(info);
110 
111  m_aElements.Insert(widget);
112 
113  // Add separators
114  Widget separator = GetGame().GetWorkspace().CreateWidgets(m_sSeparatorLayout, m_wRoot);
115  separator.SetVisible(false);
116 
117  // Display previous separator
118  int prevId = m_aSeparators.Count() - 1;
119  if (m_aSeparators.IsIndexValid(prevId))
120  m_aSeparators[prevId].SetVisible(true);
121 
122  m_aSeparators.Insert(separator);
123  }
124 
125  //------------------------------------------------------------------------------------------------
126  void RemoveLastBreadCrumbElement()
127  {
128  if (!m_aElements.IsIndexValid(m_aElements.Count() - 1)) // invalid index would break stuff next line
129  return;
130 
131  Widget last = m_aElements[m_aElements.Count() - 1];
132  if (!last)
133  return;
134 
135  // Hide previous separator
136  int prevId = m_aSeparators.Count() - 1;
137  if (m_aSeparators.IsIndexValid(prevId))
138  m_aSeparators[prevId].SetVisible(false);
139 
140  // Remove
141  m_wRoot.RemoveChild(last);
142  m_aElements.RemoveItem(last);
143 
144  Widget lastSeparator = m_aSeparators[prevId];
145 
146  m_wRoot.RemoveChild(lastSeparator);
147  m_aSeparators.RemoveItem(lastSeparator);
148  }
149 
150  //------------------------------------------------------------------------------------------------
151  protected void Refresh()
152  {
153  SCR_WidgetHelper.RemoveAllChildren(m_wRoot);
154 
155  m_aElements.Clear();
156  m_aSeparators.Clear();
157 
158  if (!m_aContent || !m_aContent.Count() || !m_sElementLayout)
159  return;
160 
161  Widget widget;
162  TextWidget textWidget;
163  array<TextWidget> createdWidgets = {};
164  for (int i, count = m_aContent.Count(); i < count; i++)
165  {
166  widget = GetGame().GetWorkspace().CreateWidgets(m_sElementLayout, m_wRoot);
167  if (!widget)
168  continue;
169 
170  textWidget = TextWidget.Cast(widget);
171  if (!textWidget)
172  continue;
173 
174  textWidget.SetText(m_aContent[i]);
175  createdWidgets.Insert(textWidget);
176 
177  if (m_sSeparatorLayout && i < count -1)
178  GetGame().GetWorkspace().CreateWidgets(m_sSeparatorLayout, m_wRoot);
179  }
180 
181  if (!createdWidgets.Count())
182  return;
183 
184  float left, top, right, bottom;
185 
186  widget = createdWidgets[0];
187  LayoutSlot.GetPadding(widget, left, top, right, bottom);
188  LayoutSlot.SetPadding(widget, 0, top, right, bottom);
189 
190  widget = createdWidgets[createdWidgets.Count() - 1];
191  LayoutSlot.GetPadding(widget, left, top, right, bottom);
192  LayoutSlot.SetPadding(widget, left, top, 0, bottom);
193  }
194 }
m_wRoot
protected Widget m_wRoot
Definition: SCR_ScenarioFrameworkLayerTaskDefend.c:59
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SCR_WidgetHelper
Definition: SCR_WidgetHelper.c:1
m_aElements
protected ref array< ref SCR_TabViewContent > m_aElements
Definition: SCR_TabViewComponent.c:13
Attribute
typedef Attribute
Post-process effect of scripted camera.
SCR_UIInfo
Definition: SCR_UIInfo.c:7
SCR_ScriptedWidgetComponent
Definition: SCR_ScriptedWidgetComponent.c:7
SCR_BreadCrumbsElementComponent
Definition: SCR_BreadCrumbElementComponent.c:7
SCR_BreadCrumbsComponent
Definition: SCR_BreadCrumbsComponent.c:1