Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_WidgetTools.c
Go to the documentation of this file.
2 {
9  static Widget FindWidgetInChildren(Widget w, WidgetType type)
10  {
11  if (w.GetTypeID() == type)
12  return w;
13 
14  Widget candidate;
15  w = w.GetChildren();
16  while (w)
17  {
18  candidate = FindWidgetInChildren(w, type);
19  if (candidate)
20  return candidate;
21 
22  w = w.GetSibling();
23  }
24  return null;
25  }
32  static Widget FindWidgetInChildren(Widget w, typename type)
33  {
34  if (w.FindHandler(type))
35  return w;
36 
37  Widget result;
38  w = w.GetChildren();
39  while (w)
40  {
41  result = FindWidgetInChildren(w, type);
42  if (result)
43  return result;
44 
45  w = w.GetSibling();
46  }
47  return null;
48  }
55  static Widget FindWidgetInParents(Widget w, WidgetType type)
56  {
57  while (w)
58  {
59  if (w.GetTypeID() == type)
60  return w;
61 
62  w = w.GetParent();
63  }
64  return null;
65  }
66 
73  static ScriptedWidgetEventHandler FindHandlerInChildren(Widget w, typename type)
74  {
75  ScriptedWidgetEventHandler component = w.FindHandler(type);
76  if (component)
77  return component;
78 
79  w = w.GetChildren();
80  while (w)
81  {
82  component = FindHandlerInChildren(w, type);
83  if (component)
84  return component;
85 
86  w = w.GetSibling();
87  }
88  return null;
89  }
96  static ScriptedWidgetEventHandler FindHandlerInParents(Widget w, typename type)
97  {
98  ScriptedWidgetEventHandler component;
99  while (w)
100  {
101  component = w.FindHandler(type);
102  if (component)
103  return component;
104 
105  w = w.GetParent();
106  }
107  return null;
108  }
115  static bool InHierarchy(Widget w, Widget parent)
116  {
117  while (w)
118  {
119  if (w == parent)
120  return true;
121 
122  w = w.GetParent();
123  }
124  return false;
125  }
130  static void RemoveChildrenFromHierarchy(Widget w)
131  {
132  Widget child = w.GetChildren();
133  while (child)
134  {
135  child.RemoveFromHierarchy();
136  child = child.GetSibling();
137  }
138  }
145  static MenuBase FindMenu(Widget w)
146  {
147  if (!w)
148  return null;
149 
150  MenuManager menuManager = GetGame().GetMenuManager();
151  if (!menuManager)
152  return null;
153 
154  if (!InHierarchy(w, GetGame().GetWorkspace()))
155  {
156  Debug.Error2("SCR_WidgetTools.GetMenu()", string.Format("Cannot find menu of widget '%1', it's not initialized yet. Are you perhaps calling it too early, e.g., from HandlerAttached()?", w.GetName()));
157  return null;
158  }
159 
160  MenuBase menuCandidate;
161  array<ScriptMenuPresetEnum> values = {};
162  for (int i, count = SCR_Enum.GetEnumValues(ChimeraMenuPreset, values); i < count; i++)
163  {
164  menuCandidate = menuManager.FindMenuByPreset(values[i]);
165  if (menuCandidate && InHierarchy(w, menuCandidate.GetRootWidget()))
166  return menuCandidate;
167  }
168  return null;
169  }
170 
177  static string GetHierarchyLog(Widget w, string delimiter = " / ")
178  {
179  string log;
180  while (w)
181  {
182  if (log.IsEmpty())
183  log = w.GetName();
184  else
185  log = w.GetName() + delimiter + log;
186 
187  w = w.GetParent();
188  }
189  return log;
190  }
191 
199  static ScriptedWidgetEventHandler FindHandlerOnWidget(Widget root, string widgetName, typename type)
200  {
201  if (!root)
202  return null;
203 
204  Widget w = root.FindAnyWidget(widgetName);
205  if (!w)
206  return null;
207 
208  return w.FindHandler(type);
209  }
210 };
SCR_WidgetTools
Definition: SCR_WidgetTools.c:1
SCR_Enum
Definition: SCR_Enum.c:1
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
ChimeraMenuPreset
ChimeraMenuPreset
Menu presets.
Definition: ChimeraMenuBase.c:3
type
EDamageType type
Definition: SCR_DestructibleTreeV2.c:32