MCPcopy Create free account
hub / github.com/codereader/DarkRadiant / CreateFromNode

Method CreateFromNode

radiant/ui/menu/MenuElement.cpp:202–265  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

200{}
201
202MenuElementPtr MenuElement::CreateFromNode(const xml::Node& node)
203{
204 MenuElementPtr item;
205
206 // Don't create anything if the menu item requires a non-existent game feature
207 if (auto feature = node.getAttributeValue("gamefeature");
208 !feature.empty() && !GlobalGameManager().currentGame()->hasFeature(feature))
209 {
210 return {};
211 }
212
213 std::string nodeName = node.getName();
214
215 if (nodeName == "menuItem")
216 {
217 item = std::make_shared<MenuItem>();
218
219 // Get the EventPtr according to the event
220 item->setEvent(node.getAttributeValue("command"));
221 item->setIcon(node.getAttributeValue("icon"));
222 }
223 else if (nodeName == "menuSeparator")
224 {
225 item = std::make_shared<MenuSeparator>();
226 }
227 else if (nodeName == "subMenu")
228 {
229 item = std::make_shared<MenuFolder>();
230 }
231 else if (nodeName == "menu")
232 {
233 item = std::make_shared<MenuBar>();
234 }
235 else
236 {
237 rError() << "MenuElement: Unknown node found: " << node.getName() << std::endl;
238 return item;
239 }
240
241 item->setName(node.getAttributeValue("name"));
242
243 // Put the caption through gettext before passing it to setCaption
244 item->setCaption(_(node.getAttributeValue("caption").c_str()));
245
246 // Parse subnodes
247 xml::NodeList childNodes = node.getChildren();
248
249 for (const xml::Node& childNode : childNodes)
250 {
251 if (childNode.getName() == "text" || childNode.getName() == "comment")
252 {
253 continue;
254 }
255
256 // Allocate a new child item
257 MenuElementPtr childItem = CreateFromNode(childNode);
258
259 // Add the child to the list

Callers

nothing calls this directly

Calls 14

rErrorFunction · 0.85
hasFeatureMethod · 0.80
setIconMethod · 0.80
setCaptionMethod · 0.80
getChildrenMethod · 0.80
addChildMethod · 0.80
_Function · 0.50
getAttributeValueMethod · 0.45
emptyMethod · 0.45
currentGameMethod · 0.45
getNameMethod · 0.45
setEventMethod · 0.45

Tested by

no test coverage detected