CHANGED: #1471 Variables are now serialized.

This commit is contained in:
dfighter1985 2012-08-17 06:10:18 +02:00
parent ff02875d45
commit ef43b498bc
4 changed files with 80 additions and 0 deletions

View file

@ -100,6 +100,20 @@ namespace NLGUI
virtual void setupOptions() = 0; virtual void setupOptions() = 0;
}; };
struct VariableData
{
std::string entry;
std::string type;
std::string value;
uint32 size;
VariableData()
{
size = 0;
}
};
CInterfaceParser(); CInterfaceParser();
virtual ~CInterfaceParser(); virtual ~CInterfaceParser();
@ -333,6 +347,7 @@ namespace NLGUI
std::map< uint32, SLinkData > links; std::map< uint32, SLinkData > links;
bool editorMode; bool editorMode;
std::map< std::string, VariableData > variableCache;
public: public:
void initLUA(); void initLUA();
@ -358,6 +373,8 @@ namespace NLGUI
void updateLinkData( uint32 id, const SLinkData &linkData ); void updateLinkData( uint32 id, const SLinkData &linkData );
void setEditorMode( bool b ){ editorMode = b; } void setEditorMode( bool b ){ editorMode = b; }
bool serializeVariables( xmlNodePtr parentNode ) const;
}; };
} }

View file

@ -82,6 +82,7 @@ namespace NLGUI
virtual void removeLinkData( uint32 id ) = 0; virtual void removeLinkData( uint32 id ) = 0;
virtual bool getLinkData( uint32 id, SLinkData &linkData ) = 0; virtual bool getLinkData( uint32 id, SLinkData &linkData ) = 0;
virtual void updateLinkData( uint32 id, const SLinkData &linkData ) = 0; virtual void updateLinkData( uint32 id, const SLinkData &linkData ) = 0;
virtual bool serializeVariables( xmlNodePtr parentNode ) const = 0;
}; };
} }

View file

@ -1061,7 +1061,9 @@ namespace NLGUI
value = entry; value = entry;
} }
else else
{
value = string((const char*)ptr); value = string((const char*)ptr);
}
// Array definition // Array definition
sint size= 1; sint size= 1;
@ -1073,6 +1075,7 @@ namespace NLGUI
{ {
ArrayMode= true; ArrayMode= true;
fromString((const char*)ptr, size); fromString((const char*)ptr, size);
string::size_type pos= entry.find("$i"); string::size_type pos= entry.find("$i");
if( pos==string::npos ) if( pos==string::npos )
{ {
@ -1118,6 +1121,24 @@ namespace NLGUI
} }
} }
if( editorMode )
{
VariableData data;
data.entry = entry;
data.type = type;
ptr = xmlGetProp( cur, BAD_CAST "value" );
if( ptr != NULL )
data.value = std::string( ptr );
ptr = xmlGetProp( cur, BAD_CAST "size" );
if( ptr != NULL )
fromString( std::string( ptr ), data.size );
variableCache[ data.entry ] = data;
}
return true; return true;
} }
@ -2557,6 +2578,7 @@ namespace NLGUI
NLMISC::contReset (_ParentSizesMap); NLMISC::contReset (_ParentSizesMap);
NLMISC::contReset (_ParentSizesMaxMap); NLMISC::contReset (_ParentSizesMaxMap);
NLMISC::contReset (_LuaClassAssociation); NLMISC::contReset (_LuaClassAssociation);
variableCache.clear();
} }
@ -2917,5 +2939,38 @@ namespace NLGUI
return; return;
itr->second = linkData; itr->second = linkData;
} }
bool CInterfaceParser::serializeVariables( xmlNodePtr parentNode ) const
{
if( parentNode == NULL )
return false;
xmlNodePtr node = NULL;
std::map< std::string, VariableData >::const_iterator itr;
for( itr = variableCache.begin(); itr != variableCache.end(); ++itr )
{
const VariableData &data = itr->second;
node = xmlNewNode( NULL, BAD_CAST "variable" );
if( node == NULL )
return false;
xmlAddChild( parentNode, node );
xmlSetProp( node, BAD_CAST "entry", BAD_CAST data.entry.c_str() );
xmlSetProp( node, BAD_CAST "type", BAD_CAST data.type.c_str() );
if( !data.value.empty() )
xmlSetProp( node, BAD_CAST "value", BAD_CAST data.value.c_str() );
if( data.size != 0 )
xmlSetProp( node, BAD_CAST "size", BAD_CAST toString( data.size ).c_str() );
}
return true;
}
} }

View file

@ -43,6 +43,13 @@ namespace GUIEditor
return false; return false;
} }
if( !CWidgetManager::getInstance()->getParser()->serializeVariables( root ) )
{
xmlFreeNode( root );
out.close();
return false;
}
if( !CWidgetManager::getInstance()->serializeOptions( root ) ) if( !CWidgetManager::getInstance()->serializeOptions( root ) )
{ {
xmlFreeNode( root ); xmlFreeNode( root );