diff --git a/code/nel/include/nel/gui/interface_options.h b/code/nel/include/nel/gui/interface_options.h index e46be901b..969fe4439 100644 --- a/code/nel/include/nel/gui/interface_options.h +++ b/code/nel/include/nel/gui/interface_options.h @@ -81,6 +81,7 @@ namespace NLGUI virtual ~CInterfaceOptions(); virtual bool parse (xmlNodePtr cur); + virtual xmlNodePtr serialize( xmlNodePtr parentNode, const std::string &name ) const; // return NullValue if param not found const CInterfaceOptionValue &getValue(const std::string &sParamName) const; @@ -110,6 +111,7 @@ namespace NLGUI public: COptionsLayer( const TCtorParam &/* param */ ); ~COptionsLayer(); + xmlNodePtr serialize( xmlNodePtr parentNode, const std::string &name ) const; virtual bool parse (xmlNodePtr cur); // Container optimizer @@ -165,6 +167,7 @@ namespace NLGUI { public: COptionsContainerInsertion( const TCtorParam &/* param */ ); + xmlNodePtr serialize( xmlNodePtr parentNode, const std::string &name ) const; virtual bool parse (xmlNodePtr cur); sint32 TxId_R_Arrow; @@ -179,6 +182,7 @@ namespace NLGUI { public: COptionsContainerMove( const TCtorParam &/* param */ ); + xmlNodePtr serialize( xmlNodePtr parentNode, const std::string &name ) const; virtual bool parse (xmlNodePtr cur); sint32 TrackW; @@ -199,6 +203,7 @@ namespace NLGUI { public: COptionsList( const TCtorParam &/* param */ ); + xmlNodePtr serialize( xmlNodePtr parentNode, const std::string &name ) const; virtual bool parse (xmlNodePtr cur); uint getNumParams() const {return _NumParams;} diff --git a/code/nel/include/nel/gui/widget_manager.h b/code/nel/include/nel/gui/widget_manager.h index f4c121ca7..1a61a12c3 100644 --- a/code/nel/include/nel/gui/widget_manager.h +++ b/code/nel/include/nel/gui/widget_manager.h @@ -392,6 +392,7 @@ namespace NLGUI void addOptions( std::string name, CInterfaceOptions *options ); void removeOptions( std::string name ); void removeAllOptions(); + bool serializeOptions( xmlNodePtr parentNode ) const; // Enable mouse Events to interface. if false, release Captures. void enableMouseHandling( bool handle ); diff --git a/code/nel/src/gui/interface_options.cpp b/code/nel/src/gui/interface_options.cpp index 3423eb69b..cc75b2194 100644 --- a/code/nel/src/gui/interface_options.cpp +++ b/code/nel/src/gui/interface_options.cpp @@ -84,6 +84,39 @@ namespace NLGUI return ok; } + xmlNodePtr CInterfaceOptions::serialize( xmlNodePtr parentNode, const std::string &name ) const + { + if( parentNode == NULL ) + return NULL; + + if( name.empty() ) + return NULL; + + xmlNodePtr node = xmlNewNode( NULL, BAD_CAST "options" ); + if( node == NULL ) + return NULL; + + xmlSetProp( node, BAD_CAST "name", BAD_CAST name.c_str() ); + xmlAddChild( parentNode, node ); + + std::map< std::string, CInterfaceOptionValue >::const_iterator itr; + for( itr = _ParamValue.begin(); itr != _ParamValue.end(); ++itr ) + { + xmlNodePtr n = xmlNewNode( NULL, BAD_CAST "param" ); + if( n == NULL ) + { + xmlFreeNode( node ); + return NULL; + } + + xmlSetProp( n, BAD_CAST "name", BAD_CAST itr->first.c_str() ); + xmlSetProp( n, BAD_CAST "value", BAD_CAST itr->second.getValStr().c_str() ); + xmlAddChild( node, n ); + } + + return node; + } + // *************************************************************************** void CInterfaceOptions::copyBasicMap(const CInterfaceOptions &other) { @@ -153,6 +186,17 @@ namespace NLGUI { } + xmlNodePtr COptionsLayer::serialize( xmlNodePtr parentNode, const std::string &name ) const + { + xmlNodePtr node = CInterfaceOptions::serialize( parentNode, name ); + if( node == NULL ) + return NULL; + + xmlSetProp( node, BAD_CAST "type", BAD_CAST "layer" ); + + return node; + } + // ---------------------------------------------------------------------------- bool COptionsLayer::parse (xmlNodePtr cur) { @@ -252,6 +296,17 @@ namespace NLGUI TxId_InsertionBar = -2; } + xmlNodePtr COptionsContainerInsertion::serialize( xmlNodePtr parentNode, const std::string &name ) const + { + xmlNodePtr node = CInterfaceOptions::serialize( parentNode, name ); + if( node == NULL ) + return NULL; + + xmlSetProp( node, BAD_CAST "type", BAD_CAST "container_insertion_opt" ); + + return node; + } + // ---------------------------------------------------------------------------- bool COptionsContainerInsertion::parse(xmlNodePtr cur) { @@ -282,6 +337,17 @@ namespace NLGUI ResizerSize = 8; } + xmlNodePtr COptionsContainerMove::serialize( xmlNodePtr parentNode, const std::string &name ) const + { + xmlNodePtr node = CInterfaceOptions::serialize( parentNode, name ); + if( node == NULL ) + return NULL; + + xmlSetProp( node, BAD_CAST "type", BAD_CAST "container_move_opt" ); + + return node; + } + // *************************************************************************** bool COptionsContainerMove::parse(xmlNodePtr cur) { @@ -304,6 +370,39 @@ namespace NLGUI _NumParams= 0; } + + xmlNodePtr COptionsList::serialize( xmlNodePtr parentNode, const std::string &name ) const + { + if( parentNode == NULL ) + return NULL; + + if( name.empty() ) + return NULL; + + xmlNodePtr node = xmlNewNode( NULL, BAD_CAST "options" ); + if( node == NULL ) + return NULL; + + xmlSetProp( node, BAD_CAST "name", BAD_CAST name.c_str() ); + xmlSetProp( node, BAD_CAST "type", BAD_CAST "list" ); + xmlAddChild( parentNode, node ); + + std::map< std::string, CInterfaceOptionValue >::const_iterator itr; + for( itr = _ParamValue.begin(); itr != _ParamValue.end(); ++itr ) + { + xmlNodePtr n = xmlNewNode( NULL, BAD_CAST "param" ); + if( n == NULL ) + { + xmlFreeNode( node ); + return NULL; + } + xmlSetProp( n, BAD_CAST "value", BAD_CAST itr->second.getValStr().c_str() ); + xmlAddChild( node, n ); + } + + return node; + } + // *************************************************************************** bool COptionsList::parse (xmlNodePtr cur) { diff --git a/code/nel/src/gui/widget_manager.cpp b/code/nel/src/gui/widget_manager.cpp index bf872948b..4b711a008 100644 --- a/code/nel/src/gui/widget_manager.cpp +++ b/code/nel/src/gui/widget_manager.cpp @@ -2849,6 +2849,22 @@ namespace NLGUI { _OptionsMap.clear(); } + + + bool CWidgetManager::serializeOptions( xmlNodePtr parentNode ) const + { + if( parentNode == NULL ) + return false; + + std::map< std::string, NLMISC::CSmartPtr< CInterfaceOptions > >::const_iterator itr; + for( itr = _OptionsMap.begin(); itr != _OptionsMap.end(); ++itr ) + { + if( itr->second->serialize( parentNode, itr->first ) == NULL ) + return false; + } + + return true; + } // *************************************************************************** diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_serializer.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_serializer.cpp index 14f311b63..be7a3898e 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_serializer.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/gui_editor/widget_serializer.cpp @@ -43,6 +43,13 @@ namespace GUIEditor return false; } + if( !CWidgetManager::getInstance()->serializeOptions( root ) ) + { + xmlFreeNode( root ); + out.close(); + return false; + } + if( mg->serializeGroup( root, "root" ) == NULL ) { xmlFreeNode( root );