9 static Widget FindWidgetInChildren(Widget w, WidgetType
type)
11 if (w.GetTypeID() ==
type)
18 candidate = FindWidgetInChildren(w,
type);
32 static Widget FindWidgetInChildren(Widget w,
typename type)
34 if (w.FindHandler(
type))
41 result = FindWidgetInChildren(w,
type);
55 static Widget FindWidgetInParents(Widget w, WidgetType
type)
59 if (w.GetTypeID() ==
type)
73 static ScriptedWidgetEventHandler FindHandlerInChildren(Widget w,
typename type)
75 ScriptedWidgetEventHandler component = w.FindHandler(
type);
82 component = FindHandlerInChildren(w,
type);
96 static ScriptedWidgetEventHandler FindHandlerInParents(Widget w,
typename type)
98 ScriptedWidgetEventHandler component;
101 component = w.FindHandler(
type);
115 static bool InHierarchy(Widget w, Widget parent)
130 static void RemoveChildrenFromHierarchy(Widget w)
132 Widget child = w.GetChildren();
135 child.RemoveFromHierarchy();
136 child = child.GetSibling();
145 static MenuBase FindMenu(Widget w)
150 MenuManager menuManager =
GetGame().GetMenuManager();
154 if (!InHierarchy(w,
GetGame().GetWorkspace()))
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()));
160 MenuBase menuCandidate;
161 array<ScriptMenuPresetEnum> values = {};
164 menuCandidate = menuManager.FindMenuByPreset(values[i]);
165 if (menuCandidate && InHierarchy(w, menuCandidate.GetRootWidget()))
166 return menuCandidate;
177 static string GetHierarchyLog(Widget w,
string delimiter =
" / ")
185 log = w.GetName() + delimiter + log;
199 static ScriptedWidgetEventHandler FindHandlerOnWidget(Widget root,
string widgetName,
typename type)
204 Widget w = root.FindAnyWidget(widgetName);
208 return w.FindHandler(
type);