Beispiel #1
0
void EditorConfig::ParseConfig(const FilePath &filePath)
{
	ClearConfig();

    YamlParser *parser = YamlParser::Create(filePath);
    if(parser)
    {
		YamlNode *rootNode = parser->GetRootNode();
		if(rootNode)
		{
			const Vector<YamlNode*> &yamlNodes = rootNode->AsVector();
			int32 propertiesCount = yamlNodes.size();
			for(int32 i = 0; i < propertiesCount; ++i)
			{
				YamlNode *propertyNode = yamlNodes[i];
				if(propertyNode)
				{
					const YamlNode *nameNode = propertyNode->Get("name");
					const YamlNode *typeNode = propertyNode->Get("type");
					const YamlNode *defaultNode = propertyNode->Get("default");
					if(nameNode && typeNode)
					{
						const String &nameStr = nameNode->AsString();
						const String &typeStr = typeNode->AsString();
						int32 type = ParseType(typeStr);
						if(type)
						{
							bool isOk = true;
							for(uint32 n = 0; n < propertyNames.size(); ++n)
							{
								if(propertyNames[n] == nameStr)
								{
									isOk = false;
									Logger::Error("EditorConfig::ParseConfig %s ERROR property %d property %s already exists", filePath.GetAbsolutePathname().c_str(), i, nameStr.c_str());
									break;
								}
							}

							if(isOk)
							{
								properties[nameStr] = new PropertyDescription();
								properties[nameStr]->name = nameStr;
								properties[nameStr]->type = type;
								switch(type)
								{
								case PT_BOOL:
									{
										bool defaultValue = false;
										if(defaultNode)
										{
											defaultValue = defaultNode->AsBool();
										}
										properties[nameStr]->defaultValue.SetBool(defaultValue);
									}
									break;
								case PT_INT:
									{
										int32 defaultValue = 0;
										if(defaultNode)
										{
											defaultValue = defaultNode->AsInt();
										}
										properties[nameStr]->defaultValue.SetInt32(defaultValue);
									}
									break;
								case PT_STRING:
									{
										String defaultValue;
										if(defaultNode)
										{
											defaultValue = defaultNode->AsString();
										}
										properties[nameStr]->defaultValue.SetString(defaultValue);
									}
									break;
								case PT_FLOAT:
									{
										float32 defaultValue = 0.0f;
										if(defaultNode)
										{
											defaultValue = defaultNode->AsFloat();
										}
										properties[nameStr]->defaultValue.SetFloat(defaultValue);
									}
									break;
								case PT_COMBOBOX:
									{
										int32 defaultValue = 0;
										if(defaultNode)
										{
											defaultValue = defaultNode->AsInt();
										}
										properties[nameStr]->defaultValue.SetInt32(defaultValue);

										const YamlNode *comboNode = propertyNode->Get("list");
										if(comboNode)
										{
											const Vector<YamlNode*> &comboValueNodes = comboNode->AsVector();
											int32 comboValuesCount = comboValueNodes.size();
											for(int32 i = 0; i < comboValuesCount; ++i)
											{
												properties[nameStr]->comboValues.push_back(comboValueNodes[i]->AsString());
											}
										}
									}
									break;
                                case PT_COLOR_LIST:
                                    {
                                        int32 defaultValue = 0;
                                        if(defaultNode)
                                        {
                                            defaultValue = defaultNode->AsInt();
                                        }
                                        properties[nameStr]->defaultValue.SetInt32(defaultValue);
                                        
                                        const YamlNode *colorListNode = propertyNode->Get("list");
                                        if(colorListNode)
                                        {
                                            const Vector<YamlNode*> &colorListNodes = colorListNode->AsVector();
                                            int32 colorListValuesCount = colorListNodes.size();
                                            for(int32 i = 0; i < colorListValuesCount; ++i)
                                            {
                                                const YamlNode* colorNode = colorListNodes[i];
                                                if(!colorNode || colorNode->GetCount() != 4)
                                                    continue;
                                                
                                                Color color(colorNode->Get(0)->AsFloat()/255.f,
                                                            colorNode->Get(1)->AsFloat()/255.f,
                                                            colorNode->Get(2)->AsFloat()/255.f,
                                                            colorNode->Get(3)->AsFloat()/255.f);

                                                properties[nameStr]->colorListValues.push_back(color);
                                            }
                                        }
                                    }
                                    break;
								}
								propertyNames.push_back(nameStr);
							} //isOk
						}
						else
						{
							Logger::Error("EditorConfig::ParseConfig %s ERROR property %d unknown type %s", filePath.GetAbsolutePathname().c_str(), i, typeStr.c_str());
						}
					}
					else
					{
						Logger::Error("EditorConfig::ParseConfig %s ERROR property %d type or name is missing", filePath.GetAbsolutePathname().c_str(), i);
					}
				}
				else
				{
					Logger::Error("EditorConfig::ParseConfig %s ERROR property %d is missing", filePath.GetAbsolutePathname().c_str(), i);
				}
			}
		} 
		// else file is empty - ok, no custom properties

		parser->Release();
	}
	// else file not found - ok, no custom properties
}
 RefPtr< PropertyLine<Vector3> > PropertyLineYamlReader::CreateVector3PropertyLineFromYamlNode( YamlNode * parentNode, const String & propertyName, RefPtr< PropertyLine<Vector3> > defaultPropertyLine /*= 0*/ )
 {
     YamlNode * node = parentNode->Get(propertyName);
     if (!node)return defaultPropertyLine;
     
     if (node->GetType() == YamlNode::TYPE_STRING)
     {
         if(propertyName == "emissionAngle") // for old emissionAngle compatibility
         {
             Vector3 res(0, 0, 0);
             float32 angle = DegToRad(node->AsFloat());
             res.x = cosf(angle);
             res.y = sinf(angle);
             return RefPtr< PropertyLine<Vector3> >(new PropertyLineValue<Vector3>(res));
         }
         
         float32 v = node->AsFloat();
         return RefPtr< PropertyLine<Vector3> >(new PropertyLineValue<Vector3>(Vector3(v, v, v)));
     }
     else if (node->GetType() == YamlNode::TYPE_ARRAY)
     {
         if(node->GetCount() == 2) // for 2D forces compatibility
         {
             Vector3 res(node->AsVector2());
             res.z = 0.0f;
             return RefPtr< PropertyLine<Vector3> >(new PropertyLineValue<Vector3>(res));
         }
         if (node->GetCount() == 3 || node->GetCount() == 2) 
         {
             Vector3 res(0.0f, 0.0f, 0.0f);
             res = node->AsVector3();
             return RefPtr< PropertyLine<Vector3> >(new PropertyLineValue<Vector3>(res));
         }
         
         RefPtr< PropertyLineKeyframes<Vector3> > keyframes (new PropertyLineKeyframes<Vector3>());
         
         for (int k = 0; k < node->GetCount() / 2; ++k)
         {
             YamlNode * time = node->Get(k * 2);
             YamlNode * value = node->Get(k * 2 + 1);
             
             if (time && value)
             {
                 if (value->GetType() == YamlNode::TYPE_ARRAY)
                 {
                     keyframes->AddValue(time->AsFloat(), value->AsVector3());
                 }
                 else 
                 {
                     Vector3 v = value->AsVector3();
                     if(propertyName == "emissionAngle") // for old emissionAngle compatibility
                     {
                         float32 angle = DegToRad(value->AsFloat());
                         v.x = cosf(angle);
                         v.y = sinf(angle);
                         v.z = 0.0f;
                     }
                     keyframes->AddValue(time->AsFloat(), v);
                 }
             }
         }
         return keyframes;
     }
     
     return RefPtr< PropertyLine<Vector3> >();
 }
Beispiel #3
0
	void UIButton::LoadFromYamlNode(YamlNode * node, UIYamlLoader * loader)
	{
		UIControl::LoadFromYamlNode(node, loader);
		
		//int32 stateArray[] = {STATE_NORMAL, STATE_PRESSED_INSIDE, STATE_PRESSED_OUTSIDE, STATE_DISABLED, STATE_SELECTED, STATE_HOVER};
		//String statePostfix[] = {"Normal", "PressedInside", "PressedOutside", "Disabled", "Selected", "Hover"};
	
		for (int k = 0; k < STATE_COUNT; ++k)
		{
			YamlNode * stateSpriteNode = node->Get(Format("stateSprite%s", statePostfix[k].c_str()));
			if (stateSpriteNode)
			{
				YamlNode * spriteNode = stateSpriteNode->Get(0);
				YamlNode * frameNode = stateSpriteNode->Get(1);
				
				int32 frame = 0;
				if (frameNode)frame = frameNode->AsInt();
				if (spriteNode)
				{
					SetStateSprite(stateArray[k], spriteNode->AsString(), frame);
				}
			}
            
            YamlNode * stateDrawTypeNode = node->Get(Format("stateDrawType%s", statePostfix[k].c_str()));
			if (stateDrawTypeNode)
			{
				UIControlBackground::eDrawType type = (UIControlBackground::eDrawType)loader->GetDrawTypeFromNode(stateDrawTypeNode);
                SetStateDrawType(stateArray[k],type);
                
                YamlNode * leftRightStretchCapNode = node->Get(Format("leftRightStretchCap%s", statePostfix[k].c_str()));
                YamlNode * topBottomStretchCapNode = node->Get(Format("topBottomStretchCap%s", statePostfix[k].c_str()));

                if(leftRightStretchCapNode)
                {
                    float32 leftStretchCap = leftRightStretchCapNode->AsFloat();
                    GetActualBackground(stateArray[k])->SetLeftRightStretchCap(leftStretchCap);
                }
                
                if(topBottomStretchCapNode)
                {
                    float32 topStretchCap = topBottomStretchCapNode->AsFloat();
                    GetActualBackground(stateArray[k])->SetTopBottomStretchCap(topStretchCap);
                }
			}
            
            YamlNode * stateAlignNode = node->Get(Format("stateAlign%s", statePostfix[k].c_str()));
			if (stateAlignNode)
			{
				int32 align = loader->GetAlignFromYamlNode(stateAlignNode);
                SetStateAlign(stateArray[k],align);
			}

			YamlNode * stateFontNode = node->Get(Format("stateFont%s", statePostfix[k].c_str()));
			if (stateFontNode)
			{
				Font * font = loader->GetFontByName(stateFontNode->AsString());
				if (font)SetStateFont(stateArray[k], font);
			}
			
			YamlNode * stateTextNode = node->Get(Format("stateText%s", statePostfix[k].c_str()));
			if (stateTextNode)
			{
				SetStateText(stateArray[k], LocalizedString(stateTextNode->AsWString()));
			}
			
			YamlNode * stateTextColorNode = node->Get(Format("stateTextcolor%s", statePostfix[k].c_str()));
			if (stateTextColorNode)
			{
				Vector4 c = stateTextColorNode->AsVector4();
				SetStateFontColor(stateArray[k], Color(c.x, c.y, c.z, c.w));
			}
			
			YamlNode * stateShadowColorNode = node->Get(Format("stateShadowcolor%s", statePostfix[k].c_str()));
			if (stateShadowColorNode)
			{
				Vector4 c = stateShadowColorNode->AsVector4();
				SetStateShadowColor(stateArray[k], Color(c.x, c.y, c.z, c.w));
			}			
			
			YamlNode * stateShadowOffsetNode = node->Get(Format("stateShadowoffset%s", statePostfix[k].c_str()));
			if (stateShadowOffsetNode)
			{
				SetStateShadowOffset(stateArray[k], stateShadowOffsetNode->AsVector2());
			}
		}
		for (int k = 0; k < STATE_COUNT; ++k)
		{
			YamlNode * colorInheritNode = node->Get("colorInherit");
			UIControlBackground::eColorInheritType type = (UIControlBackground::eColorInheritType)loader->GetColorInheritTypeFromNode(colorInheritNode);
			if(colorInheritNode)
			{
				for(int32 i = 0; i < DRAW_STATE_COUNT; ++i)
				{
					if(stateBacks[i])
					{
						stateBacks[i]->SetColorInheritType(type);
					}
				}
			}
		}
	}
Beispiel #4
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 *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]);
			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);
			}
            
			//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);
		SafeRelease(baseControl);
		      
		return node;
	}
Beispiel #5
0
void UISlider::LoadFromYamlNode(YamlNode * node, UIYamlLoader * loader)
{
	UIControl::LoadFromYamlNode(node, loader);
	
	InitThumb();
	
	YamlNode * thumbSpriteNode = node->Get("thumbSprite");

	if (thumbSpriteNode)
	{
		YamlNode * spriteNode = thumbSpriteNode->Get(0);
		YamlNode * frameNode = thumbSpriteNode->Get(1);
		
		if (spriteNode)
			SetThumbSprite(spriteNode->AsString(), frameNode->AsInt());
		//SetMinSprite("/XGfx/Options/slider_bg", 1);
		//SetMaxSprite("/XGfx/Options/slider_bg", 0);
	}
	
	YamlNode * minSpriteNode = node->Get("minSprite");
	
	if (minSpriteNode)
	{
		YamlNode * spriteNode = minSpriteNode->Get(0);
		YamlNode * frameNode = minSpriteNode->Get(1);
		
		if (spriteNode)
			SetMinSprite(spriteNode->AsString(), frameNode->AsInt());
		//SetMinSprite("/XGfx/Options/slider_bg", 1);
		//SetMaxSprite("/XGfx/Options/slider_bg", 0);
	}
	
	YamlNode * maxSpriteNode = node->Get("maxSprite");
	
	if (maxSpriteNode)
	{
		YamlNode * spriteNode = maxSpriteNode->Get(0);
		YamlNode * frameNode = maxSpriteNode->Get(1);
		
		if (spriteNode)
			SetMaxSprite(spriteNode->AsString(), frameNode->AsInt());
		//SetMinSprite("/XGfx/Options/slider_bg", 1);
		//SetMaxSprite("/XGfx/Options/slider_bg", 0);
	}
	
	// Values
	YamlNode * valueNode = node->Get("value");
	
	if (valueNode)
		SetValue(valueNode->AsFloat());
		
	YamlNode * minValueNode= node->Get("minValue");
	
	if (minValueNode)
		SetMinValue(minValueNode->AsFloat());
		
	YamlNode * maxValueNode= node->Get("maxValue");
	
	if (maxValueNode)
		SetMaxValue(maxValueNode->AsFloat());
	
	// Min/Max draw type
	YamlNode * minDrawTypeNode = node->Get("minDrawType");

	if(minDrawTypeNode)
	{
		UIControlBackground::eDrawType type = (UIControlBackground::eDrawType)loader->GetDrawTypeFromNode(minDrawTypeNode);
		SetMinDrawType(type);
	}
	
	YamlNode * maxDrawTypeNode = node->Get("maxDrawType");

	if(maxDrawTypeNode)
	{
		UIControlBackground::eDrawType type = (UIControlBackground::eDrawType)loader->GetDrawTypeFromNode(maxDrawTypeNode);
		SetMaxDrawType(type);
	}		
}