| 200 | {} |
| 201 | |
| 202 | MenuElementPtr 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 |
nothing calls this directly
no test coverage detected