示例#1
0
YamlNode * UISlider::SaveToYamlNode(UIYamlLoader * loader)
{
    thumbButton->SetName(UISLIDER_THUMB_SPRITE_CONTROL_NAME);

    YamlNode *node = UIControl::SaveToYamlNode(loader);

    // Sprite value
    float32 value = this->GetValue();
    node->Set("value", value);

    // Sprite min value
    value = this->GetMinValue();
    node->Set("minValue", value);

    // Sprite max value
    value = this->GetMaxValue();
    node->Set("maxValue", value);

    // Min/max background sprites.
    SaveBackground("min", minBackground, node, loader);
    SaveBackground("max", maxBackground, node, loader);

    // Sprites are now embedded into UISlider.
    node->Set("spritesEmbedded", true);

    return node;
}
示例#2
0
YamlNode * UIList::SaveToYamlNode(UIYamlLoader * loader)
{
	YamlNode *node = UIControl::SaveToYamlNode(loader);
	//Temp variable
	String stringValue;
    
	//Control Type
	node->Set("type", "UIList");
	//Orientation
	eListOrientation orient = this->GetOrientation();
	switch(orient)
	{
		case ORIENTATION_VERTICAL:
			stringValue = "ORIENTATION_VERTICAL";
			break;
		case ORIENTATION_HORIZONTAL:
			stringValue = "ORIENTATION_HORIZONTAL";
			break;
		default:
			stringValue = "ORIENTATION_VERTICAL";
			break;
	}
	node->Set("orientation", stringValue);
    
	return node;
}
示例#3
0
YamlNode*  UIJoypad::SaveToYamlNode(DAVA::UIYamlLoader *loader)
{
    UIJoypad* baseControl = new UIJoypad();

    YamlNode *node = UIControl::SaveToYamlNode(loader);
    
    // Sprite
    if (stick && stick->GetSprite())
    {
        node->Set("stickSprite", Sprite::GetPathString(stick->GetSprite()));
        node->Set("stickFrame", stick->GetFrame());
    }

    if (baseControl->GetDeadAreaSize() != GetDeadAreaSize())
    {
        node->Set("deadAreaSize", GetDeadAreaSize());
    }

    if (baseControl->GetDigitalSense() != GetDigitalSense())
    {
        node->Set("digitalSense", GetDigitalSense());
    }

    SafeRelease(baseControl);
    return node;
}
YamlNode * UIStaticText::SaveToYamlNode(UIYamlLoader * loader)
{
    YamlNode *node = UIControl::SaveToYamlNode(loader);

	UIStaticText *baseControl = new UIStaticText();	

    //Temp variable
    VariantType *nodeValue = new VariantType();
    
    //Control Type
	SetPreferredNodeType(node, "UIStaticText");

    //Font
    //Get font name and put it here
    nodeValue->SetString(FontManager::Instance()->GetFontName(this->GetFont()));
    node->Set("font", nodeValue);

	//TextColor
	nodeValue->SetVector4(Vector4(textColor.r, textColor.g, textColor.b, textColor.a));
	node->Set("textcolor", nodeValue);

	// ShadowColor
	nodeValue->SetVector4(Vector4(shadowColor.r, shadowColor.g, shadowColor.b, shadowColor.a));
	node->Set("shadowcolor", nodeValue);

	// ShadowOffset
	nodeValue->SetVector2(GetShadowOffset());
	node->Set("shadowoffset", nodeValue);

    //Text
    nodeValue->SetWideString(GetText());
    node->Set("text", nodeValue);    
    //Multiline
	if (baseControl->textBlock->GetMultiline() != this->textBlock->GetMultiline())
	{
    	node->Set("multiline", this->textBlock->GetMultiline());
	}
    //multilineBySymbol
	if (baseControl->textBlock->GetMultilineBySymbol() != this->textBlock->GetMultilineBySymbol())
	{
    	node->Set("multilineBySymbol", this->textBlock->GetMultilineBySymbol());
	}
    //fitting - STRING OF INT???
	if (baseControl->textBlock->GetFittingOption() != this->textBlock->GetFittingOption())
	{
    	node->Set("fitting", this->textBlock->GetFittingOption());
	}
    
	// Align
	node->SetNodeToMap("textalign", loader->GetAlignNodeValue(this->GetTextAlign()));

	// Draw type. Must be overriden for UITextControls.
	node->Set("drawType", loader->GetDrawTypeNodeValue(this->GetBackground()->GetDrawType()));

    SafeDelete(nodeValue);
	SafeRelease(baseControl);
    
    return node;
}
示例#5
0
YamlNode * Font::SaveToYamlNode() const
{
    YamlNode *node = new YamlNode(YamlNode::TYPE_MAP);
    
    VariantType *nodeValue = new VariantType();
    //Type
    node->Set("type", "Font");
    //Font size
    node->Set("size", this->GetSize());
    //Vertical Spacing
    node->Set("verticalSpacing", this->GetVerticalSpacing());

    SafeDelete(nodeValue);
    
    return node;
}
YamlNode* UIAggregatorControl::SaveToYamlNode(UIYamlLoader * loader)
{
	YamlNode* node = UIControl::SaveToYamlNode(loader);
	SetPreferredNodeType(node, "UIAggregatorControl");
	node->Set(AGGREGATOR_PATH, aggregatorPath.GetAbsolutePathname());
	return node;
}
示例#7
0
YamlNode * UIScrollBar::SaveToYamlNode(UIYamlLoader * loader)
{
	YamlNode *node = UIControl::SaveToYamlNode(loader);
	//Temp variables
	String stringValue;
    
	//Control Type
	SetPreferredNodeType(node, "UIScrollBar");

	//Orientation
	eScrollOrientation orient = this->GetOrientation();
	switch(orient)
	{
		case ORIENTATION_VERTICAL:
			stringValue = "ORIENTATION_VERTICAL";
			break;
		case ORIENTATION_HORIZONTAL:
			stringValue = "ORIENTATION_HORIZONTAL";
			break;
		default:
			stringValue = "ORIENTATION_VERTICAL";
			break;
	}
	node->Set("orientation", stringValue);
	
	// Slider have to be saved too.
	YamlNode* sliderNode = slider->SaveToYamlNode(loader);
	node->AddNodeToMap(UISCROLLBAR_SLIDER_NAME, sliderNode);
    
	return node;
}
示例#8
0
void ParticleEmitter::SaveToYaml(const String & filename)
{
    YamlParser* parser = YamlParser::Create();
    if (!parser)
    {
        Logger::Error("ParticleEmitter::SaveToYaml() - unable to create parser!");
        return;
    }

    YamlNode* rootYamlNode = new YamlNode(YamlNode::TYPE_MAP);
    YamlNode* emitterYamlNode = new YamlNode(YamlNode::TYPE_MAP);
    rootYamlNode->AddNodeToMap("emitter", emitterYamlNode);

    emitterYamlNode->Set("3d", this->is3D);
    emitterYamlNode->Set("type", GetEmitterTypeName());

    // Write the property lines.
    PropertyLineYamlWriter::WritePropertyLineToYamlNode<float32>(emitterYamlNode, "emissionAngle", this->emissionAngle);
    PropertyLineYamlWriter::WritePropertyLineToYamlNode<float32>(emitterYamlNode, "emissionRange", this->emissionRange);
    PropertyLineYamlWriter::WritePropertyLineToYamlNode<Vector3>(emitterYamlNode, "emissionVector", this->emissionVector);

    // Yuri Coder, 2013/04/12. After the coordinates inversion for the emission vector we need to introduce the
    // new "emissionVectorInverted" flag to mark we don't need to invert coordinates after re-loading the YAML.
    PropertyLineYamlWriter::WritePropertyValueToYamlNode<bool>(emitterYamlNode, "emissionVectorInverted", true);

    PropertyLineYamlWriter::WritePropertyLineToYamlNode<float32>(emitterYamlNode, "radius", this->radius);

    PropertyLineYamlWriter::WriteColorPropertyLineToYamlNode(emitterYamlNode, "colorOverLife", this->colorOverLife);

    PropertyLineYamlWriter::WritePropertyLineToYamlNode<Vector3>(emitterYamlNode, "size", this->size);
    PropertyLineYamlWriter::WritePropertyValueToYamlNode<float32>(emitterYamlNode, "life", this->lifeTime);

    // Now write all the Layers. Note - layers are child of root node, not the emitter one.
    int32 layersCount = this->layers.size();
    for (int32 i = 0; i < layersCount; i ++)
    {
        this->layers[i]->SaveToYamlNode(rootYamlNode, i);
    }

    parser->SaveToYamlFile(filename, rootYamlNode, true);
    parser->Release();
}
YamlNode * GraphicsFont::SaveToYamlNode()
{
    YamlNode *node = Font::SaveToYamlNode();
    
    //Type
    node->Set("type", "GraphicsFont");
    //horizontalSpacing
    node->Set("horizontalSpacing", this->GetHorizontalSpacing());
    //Sprite    
    Sprite *sprite = this->fontSprite;
    if (sprite)
    {
        //Truncate sprite ".txt" extension before save       
        node->Set("sprite", TruncateTxtFileExtension(sprite->GetName()));
    }    
    //Font Definition
    node->Set("definition", this->GetFontDefinitionName());

    return node;
}
示例#10
0
    YamlNode * UIListCell::SaveToYamlNode(UIYamlLoader * loader)
    {
        YamlNode *node = UIControl::SaveToYamlNode(loader);
        
        //Control Type
		SetPreferredNodeType(node, "UIListCell");

        //Identifier
        node->Set("identifier", this->GetIdentifier());
        
        return node;
    }
示例#11
0
YamlNode * GraphicsFont::SaveToYamlNode()
{
    YamlNode *node = Font::SaveToYamlNode();

    //Type
    node->Set("type", "GraphicsFont");
    //horizontalSpacing
    node->Set("horizontalSpacing", this->GetHorizontalSpacing());
    //Sprite
    Sprite *sprite = this->fontSprite;
    if (sprite)
    {
        //Truncate sprite ".txt" extension before save
        FilePath path(sprite->GetRelativePathname());
        path.TruncateExtension();
        node->Set("sprite", path.GetAbsolutePathname());
    }
    //Font Definition
    node->Set("definition", this->GetFontDefinitionName().GetAbsolutePathname());

    return node;
}
bool HierarchyTreePlatformNode::Save(YamlNode* node)
{
	YamlNode* platform = new YamlNode(YamlNode::TYPE_MAP);
	platform->Set(WIDTH_NODE, GetWidth());
	platform->Set(HEIGHT_NODE, GetHeight());

	Map<String, YamlNode*> &platformsMap = node->AsMap();
	platformsMap[GetName().toStdString()] = platform;
	ActivatePlatform();
	
	Map<String, YamlNode*> &platformMap = platform->AsMap();
	YamlNode* screens = new YamlNode(YamlNode::TYPE_ARRAY);
	platformMap[SCREENS_NODE] = screens;

    // Add the Localization info - specific for each Platform.
    SaveLocalization(platform);

	QString projectFolder = GetResourceFolder();
	projectFolder += "UI";
	QDir dir;
	dir.mkpath(projectFolder);
	
	bool result = true;
	for (HIERARCHYTREENODESCONSTITER iter = GetChildNodes().begin();
		 iter != GetChildNodes().end();
		 ++iter)
	{
		HierarchyTreeScreenNode* screenNode = dynamic_cast<HierarchyTreeScreenNode*>(*iter);
		if (!screenNode)
			continue;
		
		QString screenPath = QString(SCREEN_PATH).arg(GetResourceFolder()).arg(screenNode->GetName());
		result &= screenNode->Save(screenPath);
		
		screens->AddValueToArray(screenNode->GetName().toStdString());
	}
	return result;
}
示例#13
0
YamlNode * UITextField::SaveToYamlNode(UIYamlLoader * loader)
{
    YamlNode *node = UIControl::SaveToYamlNode(loader);

    //Temp variable
    VariantType *nodeValue = new VariantType();

    //Control Type
	SetPreferredNodeType(node, "UITextField");

    //Text
    nodeValue->SetWideString(this->GetText());
    node->Set("text", nodeValue);

    //Font
    //Get font name and put it here
    nodeValue->SetString(FontManager::Instance()->GetFontName(this->GetFont()));
    node->Set("font", nodeValue);
	
	//TextColor
	Color textColor = GetTextColor();
	nodeValue->SetVector4(Vector4(textColor.r, textColor.g, textColor.b, textColor.a));
	node->Set("textcolor", nodeValue);

	// ShadowColor
	Color shadowColor = GetShadowColor();
	nodeValue->SetVector4(Vector4(shadowColor.r, shadowColor.g, shadowColor.b, shadowColor.a));
	node->Set("shadowcolor", nodeValue);

	// ShadowOffset
	nodeValue->SetVector2(GetShadowOffset());
	node->Set("shadowoffset", nodeValue);

	// Text align
	node->SetNodeToMap("textalign", loader->GetAlignNodeValue(this->GetTextAlign()));

	// Draw Type must be overwritten fot UITextField.
	UIControlBackground::eDrawType drawType =  this->GetBackground()->GetDrawType();
	node->Set("drawType", loader->GetDrawTypeNodeValue(drawType));

    SafeDelete(nodeValue);
    
    return node;
}
示例#14
0
YamlNode * UIStaticText::SaveToYamlNode(UIYamlLoader * loader)
{
    YamlNode *node = UIControl::SaveToYamlNode(loader);

    // Sprite node is not needed for UITextField.
    YamlNode *spriteNode = node->Get("sprite");
    if (spriteNode)
    {
        node->RemoveNodeFromMap("sprite");
    }

    //Temp variable
    VariantType *nodeValue = new VariantType();
    
    //Control Type
    node->Set("type", "UIStaticText");

    //Font
    //Get font name and put it here
    nodeValue->SetString(FontManager::Instance()->GetFontName(this->GetFont()));
    node->Set("font", nodeValue);

    //Text
    nodeValue->SetWideString(GetText());
    node->Set("text", nodeValue);    
    //Multiline
    node->Set("multiline", this->textBlock->GetMultiline());
    //multilineBySymbol
    node->Set("multilineBySymbol", this->textBlock->GetMultilineBySymbol());
    //fitting - STRING OF INT???  
    node->Set("fitting", this->textBlock->GetFittingOption());
    
    SafeDelete(nodeValue);
    
    return node;
}
YamlNode* UIAggregatorControl::SaveToYamlNode(UIYamlLoader * loader)
{
	YamlNode* node = UIControl::SaveToYamlNode(loader);
	node->Set(AGGREGATOR_PATH, aggregatorPath.GetFrameworkPath());
	return node;
}
示例#16
0
YamlNode * UISlider::SaveToYamlNode(UIYamlLoader * loader)
{
    YamlNode *node = UIControl::SaveToYamlNode(loader);
    
    // Control Type
	SetPreferredNodeType(node, "UISlider");

	// Sprite value
	float32 value = this->GetValue();
	node->Set("value", value);
	
	// Sprite min value
	value = this->GetMinValue();
	node->Set("minValue", value);
	
	// Sprite max value
	value = this->GetMaxValue();
	node->Set("maxValue", value);
		
	// Get thumb sprite and frame
	if (this->thumbButton != NULL)
	{
		Sprite *sprite = this->GetThumb()->GetSprite();
		int32 spriteFrame = this->GetThumb()->GetFrame();
		if (sprite)
		{
			//Create array yamlnode and add it to map
			YamlNode *spriteNode = new YamlNode(YamlNode::TYPE_ARRAY);
			spriteNode->AddValueToArray(TruncateTxtFileExtension(sprite->GetName()));
			spriteNode->AddValueToArray(spriteFrame);
			node->AddNodeToMap("thumbSprite", spriteNode);
		}
	}
	
	if (this->bgMin != NULL)
	{
		// Get min sprite and frame
		Sprite *sprite = this->GetBgMin()->GetSprite();
		int32 spriteFrame = this->GetBgMin()->GetFrame();
		if (sprite)
		{
			// Create array yamlnode and add it to map
			YamlNode *spriteNode = new YamlNode(YamlNode::TYPE_ARRAY);
			spriteNode->AddValueToArray(TruncateTxtFileExtension(sprite->GetName()));
			spriteNode->AddValueToArray(spriteFrame);
			node->AddNodeToMap("minSprite", spriteNode);
		}
		
		// Min draw type
		UIControlBackground::eDrawType drawType =  this->GetBgMin()->GetDrawType();
		node->Set("minDrawType", loader->GetDrawTypeNodeValue(drawType));
	}

	if (this->bgMax != NULL)
	{
		// Get max sprite and frame
		Sprite* sprite = this->GetBgMax()->GetSprite();
		int32 spriteFrame = this->GetBgMax()->GetFrame();
		if (sprite)
		{
			// Create array yamlnode and add it to map
			YamlNode *spriteNode = new YamlNode(YamlNode::TYPE_ARRAY);
			spriteNode->AddValueToArray(TruncateTxtFileExtension(sprite->GetName()));
			spriteNode->AddValueToArray(spriteFrame);
			node->AddNodeToMap("maxSprite", spriteNode);
		}
		
		// Max draw type
		UIControlBackground::eDrawType drawType =  this->GetBgMax()->GetDrawType();
		node->Set("maxDrawType", loader->GetDrawTypeNodeValue(drawType));
	}
    
    return node;
}
示例#17
0
	YamlNode * UIButton::SaveToYamlNode(UIYamlLoader * loader)
	{
		YamlNode *node = UIControl::SaveToYamlNode(loader);
		//Temp variable
		VariantType *nodeValue = new VariantType();
		String stringValue;
		
		UIButton *baseControl = new UIButton();
		
		//Control Type
		SetPreferredNodeType(node, "UIButton");
        
		//Remove values of UIControl
		//UIButton has state specific properties
		YamlNode *colorNode = node->Get("color");
		YamlNode *spriteNode = node->Get("sprite");
		YamlNode *drawTypeNode = node->Get("drawType");
		YamlNode *colorInheritNode = node->Get("colorInherit");
		YamlNode *alignNode = node->Get("align");
		YamlNode *leftRightStretchCapNode = node->Get("leftRightStretchCap");
		YamlNode *topBottomStretchCapNode = node->Get("topBottomStretchCap");
		YamlNode *spriteModificationNode = node->Get("spriteModification");
        
		if (colorNode)
		{
			node->RemoveNodeFromMap("color");
		}
		if (spriteNode)
		{
			node->RemoveNodeFromMap("sprite");
		}
		if (drawTypeNode)
		{
			node->RemoveNodeFromMap("drawType");
		}
		if (colorInheritNode)
		{
			node->RemoveNodeFromMap("colorInherit");
		}
		if (alignNode)
		{
			node->RemoveNodeFromMap("align");
		}
		if (leftRightStretchCapNode)
		{
			node->RemoveNodeFromMap("leftRightStretchCap");
		}
		if (topBottomStretchCapNode)
		{
			node->RemoveNodeFromMap("topBottomStretchCap");
		}
		if (spriteModificationNode)
		{
			node->RemoveNodeFromMap("spriteModification");
		}
        
		//States cycle for values
		for (int i = 0; i < STATE_COUNT; ++i)
		{
			//Get sprite and frame for state
			Sprite *stateSprite = this->GetStateSprite(stateArray[i]);
			int32 stateFrame = this->GetStateFrame(stateArray[i]);
			if (stateSprite)
			{
				//Create array yamlnode and add it to map
				YamlNode *spriteNode = new YamlNode(YamlNode::TYPE_ARRAY);
                
                FilePath path(stateSprite->GetRelativePathname());
                path.TruncateExtension();

                String pathname = path.GetFrameworkPath();
				spriteNode->AddValueToArray(pathname);
                
				spriteNode->AddValueToArray(stateFrame);
				int32 modification = stateBacks[BackgroundIndexForState((eButtonDrawState)i)]->GetModification();
				spriteNode->AddValueToArray(modification);
				node->AddNodeToMap(Format("stateSprite%s", statePostfix[i].c_str()), spriteNode);
			}

			//StateDrawType
			UIControlBackground::eDrawType drawType = this->GetStateDrawType(stateArray[i]);
			if (baseControl->GetStateDrawType(stateArray[i]) != drawType)
			{
				node->Set(Format("stateDrawType%s", statePostfix[i].c_str()), loader->GetDrawTypeNodeValue(drawType));
			}
			//leftRightStretchCap
			float32 leftStretchCap = this->GetActualBackground(stateArray[i])->GetLeftRightStretchCap();
			float32 baseLeftStretchCap = baseControl->GetActualBackground(stateArray[i])->GetLeftRightStretchCap();
			if (baseLeftStretchCap != leftStretchCap)
			{
				node->Set(Format("leftRightStretchCap%s", statePostfix[i].c_str()), leftStretchCap);
			}
			//topBottomStretchCap
			float32 topBottomStretchCap = this->GetActualBackground(stateArray[i])->GetTopBottomStretchCap();
			float32 baseTopBottomStretchCap = baseControl->GetActualBackground(stateArray[i])->GetTopBottomStretchCap();
			if (baseTopBottomStretchCap != topBottomStretchCap)
			{
				node->Set(Format("topBottomStretchCap%s", statePostfix[i].c_str()), topBottomStretchCap);
			}
			//State align
			int32 stateAlign = this->GetStateAlign(stateArray[i]);
			int32 baseStateAlign = baseControl->GetStateAlign(stateArray[i]);
			if (baseStateAlign != stateAlign)
			{
				node->AddNodeToMap(Format("stateAlign%s", statePostfix[i].c_str()), loader->GetAlignNodeValue(stateAlign));
			}
			//State font, state text, text color, shadow color and shadow offset
			if (this->GetStateTextControl(stateArray[i]))
			{
				Font *stateFont = this->GetStateTextControl(stateArray[i])->GetFont();
				node->Set(Format("stateFont%s", statePostfix[i].c_str()), FontManager::Instance()->GetFontName(stateFont));

				nodeValue->SetWideString(this->GetStateTextControl(stateArray[i])->GetText());
				node->Set(Format("stateText%s", statePostfix[i].c_str()), nodeValue);
				
				Color textColor = this->GetStateTextControl(stateArray[i])->GetTextColor();
				nodeValue->SetVector4(Vector4(textColor.r, textColor.g, textColor.b, textColor.a));
				node->Set(Format("stateTextcolor%s", statePostfix[i].c_str()), nodeValue);
				
				Color shadowColor = this->GetStateTextControl(stateArray[i])->GetShadowColor();
				nodeValue->SetVector4(Vector4(shadowColor.r, shadowColor.g, shadowColor.b, shadowColor.a));
				node->Set(Format("stateShadowcolor%s", statePostfix[i].c_str()), nodeValue);
				
				Vector2 shadowOffset = this->GetStateTextControl(stateArray[i])->GetShadowOffset();
				nodeValue->SetVector2(shadowOffset);
				node->Set(Format("stateShadowoffset%s", statePostfix[i].c_str()), nodeValue);
			}
			
			// State background color
			Color color = this->GetActualBackground(stateArray[i])->GetColor();
			Color baseColor =  baseControl->GetActualBackground(stateArray[i])->GetColor();
			if (baseColor != color)
			{
				Vector4 colorVector4(color.r, color.g, color.b, color.a);
				nodeValue->SetVector4(colorVector4);
				node->Set(Format("stateColor%s", statePostfix[i].c_str()), nodeValue);
			}
			
 			// State color inherittype
			UIControlBackground::eColorInheritType colorInheritType = this->GetActualBackground(stateArray[i])->GetColorInheritType();
			UIControlBackground::eColorInheritType baseColorInheritType = baseControl->GetActualBackground(stateArray[i])->GetColorInheritType();
			if (baseColorInheritType != colorInheritType)
			{
				node->Set(Format("stateColorInherit%s", statePostfix[i].c_str()), loader->GetColorInheritTypeNodeValue(colorInheritType));
			}
		}
        
		SafeDelete(nodeValue);
		SafeRelease(baseControl);
		      
		return node;
	}
示例#18
0
bool YamlParser::Parse(YamlDataHolder * dataHolder)
{
	yaml_parser_t parser;
	yaml_event_t event;
	
	int done = 0;
	
	/* Create the Parser object. */
	yaml_parser_initialize(&parser);
	
	yaml_parser_set_encoding(&parser, YAML_UTF8_ENCODING);
	
	/* Set a string input. */
	//yaml_parser_set_input_string(&parser, (const unsigned char*)pathName.c_str(), pathName.length());
		
	yaml_parser_set_input(&parser, read_handler, dataHolder);

	String lastMapKey;
	bool isKeyPresent = false;

	/* Read the event sequence. */
	while (!done) 
	{
		
		/* Get the next event. */
		if (!yaml_parser_parse(&parser, &event))
		{
			Logger::Error("[YamlParser::Parse] error: type: %d %s line: %d pos: %d", parser.error, parser.problem, parser.problem_mark.line, parser.problem_mark.column);
			break;
		}
		
		switch(event.type)
		{
		case YAML_ALIAS_EVENT:
			Logger::FrameworkDebug("[YamlParser::Parse] alias: %s", event.data.alias.anchor);
			break;
		
		case YAML_SCALAR_EVENT:
			{
				String scalarValue = (const char*)event.data.scalar.value;

				if (objectStack.empty())
				{
					YamlNode * node = YamlNode::CreateStringNode();
					node->Set(scalarValue);
					rootObject = node;
				}
				else
				{
					YamlNode * topContainer = objectStack.top();
					DVASSERT(topContainer->GetType() != YamlNode::TYPE_STRING);
					if (topContainer->GetType() == YamlNode::TYPE_MAP)
					{
						if (!isKeyPresent)
						{
							lastMapKey = scalarValue;
						}
						else
						{
							topContainer->Add(lastMapKey, scalarValue);
						}
						isKeyPresent = !isKeyPresent;
					}
					else if (topContainer->GetType() == YamlNode::TYPE_ARRAY)
					{
						topContainer->Add(scalarValue);
					}
				}
			}
			break;
		
		case YAML_DOCUMENT_START_EVENT:
			//Logger::FrameworkDebug("document start:");
			break;
		
		case YAML_DOCUMENT_END_EVENT:
			//Logger::FrameworkDebug("document end:");
			break;

		case YAML_SEQUENCE_START_EVENT:
			{
				YamlNode * node = YamlNode::CreateArrayNode();
				if (objectStack.empty())
				{
					rootObject = node;
				}
				else
				{
					YamlNode * topContainer = objectStack.top();
					DVASSERT(topContainer->GetType() != YamlNode::TYPE_STRING);
					if (topContainer->GetType() == YamlNode::TYPE_MAP)
					{
						DVASSERT(isKeyPresent);
						topContainer->AddNodeToMap(lastMapKey, node);
						isKeyPresent = false;
					}
					else if (topContainer->GetType() == YamlNode::TYPE_ARRAY)
					{
						topContainer->AddNodeToArray(node);
					}
				}
				objectStack.push(node);
			}break;
				
		case YAML_SEQUENCE_END_EVENT:
			{
				objectStack.pop();
			}break;
		
		case YAML_MAPPING_START_EVENT:
			{
				YamlNode * node = YamlNode::CreateMapNode();
				if (objectStack.empty())
				{
					rootObject = node;
				}
				else
				{
					YamlNode * topContainer = objectStack.top();
					if (topContainer->GetType() == YamlNode::TYPE_MAP)
					{
						DVASSERT(isKeyPresent);
						topContainer->AddNodeToMap(lastMapKey, node);
						isKeyPresent = false;
					}
					else if (topContainer->GetType() == YamlNode::TYPE_ARRAY)
					{
						topContainer->AddNodeToArray(node);
					}
				}
				objectStack.push(node);
			}
			break;
				
		case YAML_MAPPING_END_EVENT:
			{
				objectStack.pop();
			}
			break;
        default:
            break;
		};

		/* Are we finished? */
		done = (event.type == YAML_STREAM_END_EVENT);
		
		/* The application is responsible for destroying the event object. */
		yaml_event_delete(&event);
		
	}

	/* Destroy the Parser object. */
	yaml_parser_delete(&parser);

    DVASSERT(objectStack.size() == 0);

    return true;
}
示例#19
0
	YamlNode * UIButton::SaveToYamlNode(UIYamlLoader * loader)
	{
		YamlNode *node = UIControl::SaveToYamlNode(loader);
		//Temp variable
		VariantType *nodeValue = new VariantType();
		String stringValue;

		//Control Type
		node->Set("type", "UIButton");
        
		//Remove values of UIControl
		YamlNode *spriteNode = node->Get("sprite");
		YamlNode *drawTypeNode = node->Get("drawType");
		YamlNode *colorInheritNode = node->Get("colorInherit");
		YamlNode *alignNode = node->Get("align");
		YamlNode *leftRightStretchCapNode = node->Get("leftRightStretchCap");
		YamlNode *topBottomStretchCapNode = node->Get("topBottomStretchCap");
        
		if (spriteNode)
		{
			node->RemoveNodeFromMap("sprite");
		}
		if (drawTypeNode)
		{
			node->RemoveNodeFromMap("drawType");
		}
		if (colorInheritNode)
		{
			node->RemoveNodeFromMap("colorInherit");
		}
		if (alignNode)
		{
			node->RemoveNodeFromMap("align");
		}
		if (leftRightStretchCapNode)
		{
			node->RemoveNodeFromMap("leftRightStretchCap");
		}
		if (topBottomStretchCapNode)
		{
			node->RemoveNodeFromMap("topBottomStretchCap");
		}
        
		//States cycle for values
		for (int i = 0; i < STATE_COUNT; ++i)
		{
			//Get sprite and frame for state
			Sprite *stateSprite = this->GetStateSprite(stateArray[i]);
			int32 stateFrame = this->GetStateFrame(stateArray[i]);
			if (stateSprite)
			{
				//Create array yamlnode and add it to map
				YamlNode *spriteNode = new YamlNode(YamlNode::TYPE_ARRAY);
				spriteNode->AddValueToArray(TruncateTxtFileExtension(stateSprite->GetName()));
				spriteNode->AddValueToArray(stateFrame);
				node->AddNodeToMap(Format("stateSprite%s", statePostfix[i].c_str()), spriteNode);
			}

			//StateDrawType
			UIControlBackground::eDrawType drawType = this->GetStateDrawType(stateArray[i]); 
			node->Set(Format("stateDrawType%s", statePostfix[i].c_str()), loader->GetDrawTypeNodeValue(drawType));
			//leftRightStretchCap
			float32 leftStretchCap = this->GetActualBackground(stateArray[i])->GetLeftRightStretchCap();
			node->Set(Format("leftRightStretchCap%s", statePostfix[i].c_str()), leftStretchCap);            
			//topBottomStretchCap
			float32 topBottomStretchCap = this->GetActualBackground(stateArray[i])->GetTopBottomStretchCap();
			node->Set(Format("topBottomStretchCap%s", statePostfix[i].c_str()), topBottomStretchCap);
			//State align
			node->Set(Format("stateAlign%s", statePostfix[i].c_str()), this->GetStateAlign(stateArray[i]));
			//State font
            
			Font *stateFont = this->GetStateTextControl(stateArray[i])->GetFont();
			node->Set(Format("stateFont%s", statePostfix[i].c_str()), FontManager::Instance()->GetFontName(stateFont));
			//StateText
			if (this->GetStateTextControl(stateArray[i]))
			{
				nodeValue->SetWideString(this->GetStateTextControl(stateArray[i])->GetText());
				node->Set(Format("stateText%s", statePostfix[i].c_str()), nodeValue);
			}
            
			//colorInherit ???? For different states?
			// Yuri Coder, 2012/11/16. Temporarily commented out until clarification.
			//UIControlBackground::eColorInheritType colorInheritType = this->GetStateBackground(stateArray[i])->GetColorInheritType();
			//node->Set(Format("stateColorInherit%s", statePostfix[i].c_str()), loader->GetColorInheritTypeNodeValue(colorInheritType));
		}
        
		SafeDelete(nodeValue);
        
		return node;
	}
示例#20
0
YamlNode * UIStaticText::SaveToYamlNode(UIYamlLoader * loader)
{
    YamlNode *node = UIControl::SaveToYamlNode(loader);

    UIStaticText *baseControl = new UIStaticText();

    //Temp variable
    VariantType *nodeValue = new VariantType();

    //Font
    //Get font name and put it here
    nodeValue->SetString(FontManager::Instance()->GetFontName(this->GetFont()));
    node->Set("font", nodeValue);

    //TextColor
    const Color &textColor = GetTextColor();
    if (baseControl->GetTextColor() != textColor)
    {
        nodeValue->SetColor(textColor);
        node->Set("textcolor", nodeValue);
    }

    // Text Color Inherit Type.
    int32 colorInheritType = (int32)GetTextBackground()->GetColorInheritType();
    if (baseControl->GetTextBackground()->GetColorInheritType() != colorInheritType)
    {
        node->Set("textcolorInheritType", loader->GetColorInheritTypeNodeValue(colorInheritType));
    }

    // ShadowColor
    const Color &shadowColor = GetShadowColor();
    if (baseControl->GetShadowColor() != shadowColor)
    {
        nodeValue->SetColor(shadowColor);
        node->Set("shadowcolor", nodeValue);
    }

    // Shadow Color Inherit Type.
    colorInheritType = (int32)GetShadowBackground()->GetColorInheritType();
    if (baseControl->GetShadowBackground()->GetColorInheritType() != colorInheritType)
    {
        node->Set("shadowcolorInheritType", loader->GetColorInheritTypeNodeValue(colorInheritType));
    }

    // ShadowOffset
    const Vector2 &shadowOffset = GetShadowOffset();
    if (baseControl->GetShadowOffset() != shadowOffset)
    {
        nodeValue->SetVector2(shadowOffset);
        node->Set("shadowoffset", nodeValue);
    }

    //Text
    const WideString &text = GetText();
    if (baseControl->GetText() != text)
    {
        node->Set("text", text);
    }
    //Multiline
    if (baseControl->textBlock->GetMultiline() != this->textBlock->GetMultiline())
    {
        node->Set("multiline", this->textBlock->GetMultiline());
    }
    //multilineBySymbol
    if (baseControl->textBlock->GetMultilineBySymbol() != this->textBlock->GetMultilineBySymbol())
    {
        node->Set("multilineBySymbol", this->textBlock->GetMultilineBySymbol());
    }
    //fitting - Array of strings
    if (baseControl->textBlock->GetFittingOption() != this->textBlock->GetFittingOption())
    {
        node->SetNodeToMap("fitting", loader->GetFittingOptionNodeValue(textBlock->GetFittingOption()));
    }

    // Text Align
    if (baseControl->GetTextAlign() != this->GetTextAlign())
    {
        node->SetNodeToMap("textalign", loader->GetAlignNodeValue(this->GetTextAlign()));
    }

    // Draw type. Must be overriden for UITextControls.
    if (baseControl->GetBackground()->GetDrawType() != this->GetBackground()->GetDrawType())
    {
        node->Set("drawType", loader->GetDrawTypeNodeValue(this->GetBackground()->GetDrawType()));
    }

    SafeDelete(nodeValue);
    SafeRelease(baseControl);

    return node;
}
示例#21
0
bool HierarchyTreePlatformNode::Save(YamlNode* node, bool saveAll)
{
	YamlNode* platform = new YamlNode(YamlNode::TYPE_MAP);
	platform->Set(WIDTH_NODE, GetWidth());
	platform->Set(HEIGHT_NODE, GetHeight());

	MultiMap<String, YamlNode*> &platformsMap = node->AsMap();
	platformsMap.erase(GetName().toStdString());
	platformsMap.insert(std::pair<String, YamlNode*>(GetName().toStdString(), platform));
	ActivatePlatform();
	
	MultiMap<String, YamlNode*> &platformMap = platform->AsMap();
	YamlNode* screens = new YamlNode(YamlNode::TYPE_ARRAY);
	platformMap.erase(SCREENS_NODE);
	platformMap.insert(std::pair<String, YamlNode*>(SCREENS_NODE, screens));
	
	YamlNode* aggregators = new YamlNode(YamlNode::TYPE_MAP);
	platformMap.erase(AGGREGATORS_NODE);
	platformMap.insert(std::pair<String, YamlNode*>(AGGREGATORS_NODE, aggregators));

    // Add the Localization info - specific for each Platform.
    SaveLocalization(platform);

	QString platformFolder = GetPlatformFolder();

	QDir dir;
	dir.mkpath(platformFolder);
	
	bool result = true;
	
	//save aggregators node before save screens
	for (HIERARCHYTREENODESCONSTITER iter = GetChildNodes().begin();
		 iter != GetChildNodes().end();
		 ++iter)
	{
		HierarchyTreeAggregatorNode* node = dynamic_cast<HierarchyTreeAggregatorNode*>(*iter);
		if (!node)
			continue;

		QString path = QString(SCREEN_PATH).arg(platformFolder).arg(node->GetName());
		MultiMap<String, YamlNode*> &aggregatorsMap = aggregators->AsMap();
		
		YamlNode* aggregator = new YamlNode(YamlNode::TYPE_MAP);
		result &= node->Save(aggregator, path, saveAll);
		
		aggregatorsMap.erase(node->GetName().toStdString());
		aggregatorsMap.insert(std::pair<String, YamlNode*>(node->GetName().toStdString(), aggregator));
	}
		
	
	for (HIERARCHYTREENODESCONSTITER iter = GetChildNodes().begin();
		 iter != GetChildNodes().end();
		 ++iter)
	{
		HierarchyTreeAggregatorNode* node = dynamic_cast<HierarchyTreeAggregatorNode*>(*iter);
		if (node)
			continue;	//skip aggregators
		
		HierarchyTreeScreenNode* screenNode = dynamic_cast<HierarchyTreeScreenNode*>(*iter);
		if (!screenNode)
			continue;
		
		QString screenPath = QString(SCREEN_PATH).arg(platformFolder).arg(screenNode->GetName());
		result &= screenNode->Save(screenPath, saveAll);
		
		screens->AddValueToArray(screenNode->GetName().toStdString());
	}
	return result;
}