Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
MenuRootComponent.c
Go to the documentation of this file.
1
7{
8 protected Widget m_Widget;
10 protected ref array<MenuRootSubComponent> m_aComponents = {};
11
12 //------------------------------------------------------------------------------------------------
19 {
20 if (!widget)
21 return null;
22
23 WorkspaceWidget workspace = GetGame().GetWorkspace();
24 Widget widgetRoot = widget;
25 while (widgetRoot)
26 {
27 Widget widgetRootParent = widgetRoot.GetParent();
28 if (!widgetRootParent || widgetRootParent == workspace)
29 break;
30 widgetRoot = widgetRootParent;
31 }
32
33 MenuRootComponent rootComponent = MenuRootComponent.Cast(widgetRoot.FindHandler(MenuRootComponent));
34 if (!rootComponent)
35 {
36 rootComponent = new MenuRootComponent;
37 widgetRoot.AddHandler(rootComponent);
38 }
39 return rootComponent;
40 }
41
42 //------------------------------------------------------------------------------------------------
49 {
50 Widget widgetRoot = menu.GetRootWidget();
51 return GetRootOf(widgetRoot);
52 }
53
54 //------------------------------------------------------------------------------------------------
60 {
61 return m_Menu;
62 }
63
64 //------------------------------------------------------------------------------------------------
70 {
71 return m_Widget;
72 }
73
74 //------------------------------------------------------------------------------------------------
80 {
81 if (m_aComponents.Find(component) == -1)
82 m_aComponents.InsertAt(component, 0); //--- Place at the beginning to make sure the newest component is found first
83 }
84
85 //------------------------------------------------------------------------------------------------
91 {
92 m_aComponents.RemoveItem(component);
93 }
94
95 //------------------------------------------------------------------------------------------------
101 MenuRootSubComponent FindComponent(typename type, bool showError = false)
102 {
103 foreach (MenuRootSubComponent component: m_aComponents)
104 {
105 if (component && component.Type() == type)
106 return component;
107 }
108
109 if (showError)
110 Print(string.Format("Cannot find UI component '%1'!", type), LogLevel.ERROR);
111
112 return null;
113 }
114
115 //------------------------------------------------------------------------------------------------
122 int FindComponents(typename type, notnull out array<MenuRootSubComponent> outComponents)
123 {
124 outComponents.Clear();
125 foreach (auto component: m_aComponents)
126 {
127 if (component && component.Type() == type)
128 outComponents.Insert(component);
129 }
130 return outComponents.Count();
131 }
132
133 //------------------------------------------------------------------------------------------------
135 {
136 if (m_Menu)
137 return;
138
139 m_Menu = menu;
140
141 int count = m_aComponents.Count();
142 foreach (auto component : m_aComponents)
143 {
144 component.HandlerAttachedScripted(component.GetWidget());
145
146 //--- Show error when the components creates new widgets here, changing the array and breaking indexing
147 if (count != m_aComponents.Count())
148 {
149 Print(string.Format("Error when initializing MenuRootComponent - new components were added during init of %1! The menu will not function correctly!", component.Type()), LogLevel.ERROR);
150 return;
151 }
152 }
153 }
154
155 //------------------------------------------------------------------------------------------------
156 protected void InitNotRoot()
157 {
158 Init(null);
159 }
160
161 //------------------------------------------------------------------------------------------------
162 protected void ExecInit(Widget w)
163 {
164 //--- Recursively iterate through children
165 Widget child = w.GetChildren();
166 while (child)
167 {
168 ExecInit(child);
169 child = child.GetSibling();
170 }
171
172 //--- Iterate through handlers
173 int subComponentsCount = w.GetNumHandlers();
174 for (int i; i < subComponentsCount; i++)
175 {
176 MenuRootSubComponent subComponent = MenuRootSubComponent.Cast(w.GetHandler(i));
177 if (subComponent)
178 subComponent.HandlerAttachedScripted(w);
179 }
180 }
181
182 //------------------------------------------------------------------------------------------------
183 override void HandlerAttached(Widget w)
184 {
185 m_Widget = w;
186 super.HandlerAttached(w);
187 GetGame().GetCallqueue().CallLater(InitNotRoot, 1, false); //--- Initialize components in case the root is not part of MenuRootBase
188 }
189};
override void Init()
ArmaReforgerScripted GetGame()
Definition game.c:1398
EDamageType type
void ExecInit(Widget w)
int FindComponents(typename type, notnull out array< MenuRootSubComponent > outComponents)
MenuRootSubComponent FindComponent(typename type, bool showError=false)
void AddComponent(MenuRootSubComponent component)
static MenuRootComponent GetRootOf(Widget widget)
static MenuRootComponent GetRootOf(MenuBase menu)
ref array< MenuRootSubComponent > m_aComponents
void RemoveComponent(MenuRootSubComponent component)
void Init(MenuRootBase menu)
MenuRootBase GetMenu()
override void HandlerAttached(Widget w)
void HandlerAttachedScripted(Widget w)
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
LogLevel
Enum with severity of the logging message.
Definition LogLevel.c:14