diff --git a/src/framework/luafunctions.cpp b/src/framework/luafunctions.cpp index f3bf3fb8..9798f3e8 100644 --- a/src/framework/luafunctions.cpp +++ b/src/framework/luafunctions.cpp @@ -576,6 +576,7 @@ void Application::registerLuaFunctions() // UI g_lua.registerStaticClass("g_ui"); + g_lua.bindClassStaticFunction("g_ui", "clearStyles", std::bind(&UIManager::clearStyles, &g_ui)); g_lua.bindClassStaticFunction("g_ui", "importStyle", std::bind(&UIManager::importStyle, &g_ui, std::placeholders::_1)); g_lua.bindClassStaticFunction("g_ui", "getStyle", std::bind(&UIManager::getStyle, &g_ui, std::placeholders::_1)); g_lua.bindClassStaticFunction("g_ui", "getStyleClass", std::bind(&UIManager::getStyleClass, &g_ui, std::placeholders::_1)); diff --git a/src/framework/ui/uimanager.cpp b/src/framework/ui/uimanager.cpp index 78d4eac4..9039bdbf 100644 --- a/src/framework/ui/uimanager.cpp +++ b/src/framework/ui/uimanager.cpp @@ -293,6 +293,11 @@ void UIManager::onWidgetDestroy(const UIWidgetPtr& widget) #endif } +void UIManager::clearStyles() +{ + m_styles.clear(); +} + bool UIManager::importStyle(const std::string& file) { try { @@ -317,10 +322,19 @@ void UIManager::importStyleFromOTML(const OTMLNodePtr& styleNode) std::string name = split[0]; std::string base = split[1]; + bool unique = false; boost::trim(name); boost::trim(base); + if(name[0] == '#') { + name = name.substr(1); + unique = true; + + styleNode->setTag(name); + styleNode->writeAt("__unique", true); + } + // TODO: styles must be searched by widget scopes, in that way this warning could be fixed // this warning is disabled because many ppl was complening about it /* @@ -329,13 +343,16 @@ void UIManager::importStyleFromOTML(const OTMLNodePtr& styleNode) g_logger.warning("style '%s' is being redefined", name); */ - 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; + OTMLNodePtr oldStyle = m_styles[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; + } } OTMLNodePtr UIManager::getStyle(const std::string& styleName) diff --git a/src/framework/ui/uimanager.h b/src/framework/ui/uimanager.h index 2869fd01..f03902d5 100644 --- a/src/framework/ui/uimanager.h +++ b/src/framework/ui/uimanager.h @@ -41,6 +41,7 @@ public: bool updateDraggingWidget(const UIWidgetPtr& draggingWidget, const Point& clickedPos = Point()); void updateHoveredWidget(); + void clearStyles(); bool importStyle(const std::string& file); void importStyleFromOTML(const OTMLNodePtr& styleNode); OTMLNodePtr getStyle(const std::string& styleName);