mirror of
https://port.numenaute.org/aleajactaest/khanat-code-old.git
synced 2024-12-27 19:10:52 +00:00
CHANGED: #1471 Variables are now serialized.
This commit is contained in:
parent
ff02875d45
commit
ef43b498bc
4 changed files with 80 additions and 0 deletions
|
@ -100,6 +100,20 @@ namespace NLGUI
|
|||
virtual void setupOptions() = 0;
|
||||
};
|
||||
|
||||
|
||||
struct VariableData
|
||||
{
|
||||
std::string entry;
|
||||
std::string type;
|
||||
std::string value;
|
||||
uint32 size;
|
||||
|
||||
VariableData()
|
||||
{
|
||||
size = 0;
|
||||
}
|
||||
};
|
||||
|
||||
CInterfaceParser();
|
||||
virtual ~CInterfaceParser();
|
||||
|
||||
|
@ -333,6 +347,7 @@ namespace NLGUI
|
|||
std::map< uint32, SLinkData > links;
|
||||
|
||||
bool editorMode;
|
||||
std::map< std::string, VariableData > variableCache;
|
||||
|
||||
public:
|
||||
void initLUA();
|
||||
|
@ -358,6 +373,8 @@ namespace NLGUI
|
|||
void updateLinkData( uint32 id, const SLinkData &linkData );
|
||||
|
||||
void setEditorMode( bool b ){ editorMode = b; }
|
||||
|
||||
bool serializeVariables( xmlNodePtr parentNode ) const;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -82,6 +82,7 @@ namespace NLGUI
|
|||
virtual void removeLinkData( uint32 id ) = 0;
|
||||
virtual bool getLinkData( uint32 id, SLinkData &linkData ) = 0;
|
||||
virtual void updateLinkData( uint32 id, const SLinkData &linkData ) = 0;
|
||||
virtual bool serializeVariables( xmlNodePtr parentNode ) const = 0;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -1061,7 +1061,9 @@ namespace NLGUI
|
|||
value = entry;
|
||||
}
|
||||
else
|
||||
{
|
||||
value = string((const char*)ptr);
|
||||
}
|
||||
|
||||
// Array definition
|
||||
sint size= 1;
|
||||
|
@ -1073,6 +1075,7 @@ namespace NLGUI
|
|||
{
|
||||
ArrayMode= true;
|
||||
fromString((const char*)ptr, size);
|
||||
|
||||
string::size_type pos= entry.find("$i");
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -2557,6 +2578,7 @@ namespace NLGUI
|
|||
NLMISC::contReset (_ParentSizesMap);
|
||||
NLMISC::contReset (_ParentSizesMaxMap);
|
||||
NLMISC::contReset (_LuaClassAssociation);
|
||||
variableCache.clear();
|
||||
}
|
||||
|
||||
|
||||
|
@ -2917,5 +2939,38 @@ namespace NLGUI
|
|||
return;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -43,6 +43,13 @@ namespace GUIEditor
|
|||
return false;
|
||||
}
|
||||
|
||||
if( !CWidgetManager::getInstance()->getParser()->serializeVariables( root ) )
|
||||
{
|
||||
xmlFreeNode( root );
|
||||
out.close();
|
||||
return false;
|
||||
}
|
||||
|
||||
if( !CWidgetManager::getInstance()->serializeOptions( root ) )
|
||||
{
|
||||
xmlFreeNode( root );
|
||||
|
|
Loading…
Reference in a new issue