UIWidgetPtr UIManager::createWidgetFromOTML(const OTMLNodePtr& widgetNode, const UIWidgetPtr& parent) { OTMLNodePtr originalStyleNode = getStyle(widgetNode->tag()); if(!originalStyleNode) stdext::throw_exception(stdext::format("'%s' is not a defined style", widgetNode->tag())); OTMLNodePtr styleNode = originalStyleNode->clone(); styleNode->merge(widgetNode); std::string widgetType = styleNode->valueAt("__class"); // call widget creation from lua UIWidgetPtr widget = g_lua.callGlobalField<UIWidgetPtr>(widgetType, "create"); if(parent) parent->addChild(widget); if(widget) { widget->callLuaField("onCreate"); widget->setStyleFromNode(styleNode); for(const OTMLNodePtr& childNode : styleNode->children()) { if(!childNode->isUnique()) { createWidgetFromOTML(childNode, widget); styleNode->removeChild(childNode); } } } else stdext::throw_exception(stdext::format("unable to create widget of type '%s'", widgetType)); widget->callLuaField("onSetup"); return widget; }
void Config::mergeNode(const std::string& key, const OTMLNodePtr& node) { OTMLNodePtr clone = node->clone(); node->setTag(key); node->setUnique(true); m_confsDoc->addChild(node); }
void ParticleEffectType::load(const OTMLNodePtr& node) { m_node = node->clone(); for(const OTMLNodePtr& childNode : node->children()) { if(childNode->tag() == "name") m_name = childNode->value(); else if(childNode->tag() == "description") m_description = childNode->value(); } }
void UIWidget::setStyle(const std::string& styleName) { OTMLNodePtr styleNode = g_ui.getStyle(styleName); if(!styleNode) { g_logger.traceError(stdext::format("unable to retrieve style '%s': not a defined style", styleName)); return; } styleNode = styleNode->clone(); applyStyle(styleNode); m_style = styleNode; updateStyle(); }
void UIWidget::setStyle(const std::string& styleName) { OTMLNodePtr styleNode = g_ui.getStyle(styleName); if(!styleNode) { logTraceError("unable to retrive style '", styleName, "': not a defined style"); return; } styleNode = styleNode->clone(); applyStyle(styleNode); m_style = styleNode; updateStyle(); }
void UIManager::importStyleFromOTML(const OTMLNodePtr& styleNode) { std::string tag = styleNode->tag(); std::vector<std::string> split = stdext::split(tag, "<"); if(split.size() != 2) throw OTMLException(styleNode, "not a valid style declaration"); std::string name = split[0]; std::string base = split[1]; bool unique = false; stdext::trim(name); stdext::trim(base); if(name[0] == '#') { name = name.substr(1); unique = true; styleNode->setTag(name); styleNode->writeAt("__unique", true); } OTMLNodePtr oldStyle = m_styles[name]; // Warn about redefined styles /* if(!g_app.isRunning() && (oldStyle && !oldStyle->valueAt("__unique", false))) { auto it = m_styles.find(name); if(it != m_styles.end()) g_logger.warning(stdext::format("style '%s' is being redefined", name)); } */ if(!oldStyle || !oldStyle->valueAt("__unique", false) || unique) { OTMLNodePtr originalStyle = getStyle(base); if(!originalStyle) stdext::throw_exception(stdext::format("base style '%s', is not defined", base)); OTMLNodePtr style = originalStyle->clone(); style->merge(styleNode); style->setTag(name); m_styles[name] = style; } }