public virtual void Setup_BeforeAdd(XML xml)
{
string str;
string[] arr;
id = xml.GetAttribute("id");
name = xml.GetAttribute("name");
arr = xml.GetAttributeArray("xy");
if (arr != null)
this.SetXY(int.Parse(arr[0]), int.Parse(arr[1]));
arr = xml.GetAttributeArray("size");
if (arr != null)
{
initWidth = int.Parse(arr[0]);
initHeight = int.Parse(arr[1]);
SetSize(initWidth, initHeight, true);
}
arr = xml.GetAttributeArray("scale");
if (arr != null)
SetScale(float.Parse(arr[0]), float.Parse(arr[1]));
arr = xml.GetAttributeArray("skew");
if (arr != null)
this.skew = new Vector2(float.Parse(arr[0]), float.Parse(arr[1]));
str = xml.GetAttribute("rotation");
if (str != null)
this.rotation = int.Parse(str);
arr = xml.GetAttributeArray("pivot");
if (arr != null)
{
float f1 = float.Parse(arr[0]);
float f2 = float.Parse(arr[1]);
//处理旧版本的兼容性(旧版本发布的值是坐标值,新版本是比例,一般都小于2)
if (f1 > 2)
{
if (sourceWidth != 0)
f1 = f1 / sourceWidth;
else
f1 = 0;
}
if (f2 > 2)
{
if (sourceHeight != 0)
f2 = f2 / sourceHeight;
else
f2 = 0;
}
this.SetPivot(f1, f2, xml.GetAttributeBool("anchor"));
}
else
this.SetPivot(0, 0, false);
str = xml.GetAttribute("alpha");
if (str != null)
this.alpha = float.Parse(str);
this.touchable = xml.GetAttributeBool("touchable", true);
this.visible = xml.GetAttributeBool("visible", true);
this.grayed = xml.GetAttributeBool("grayed", false);
str = xml.GetAttribute("blend");
if (str != null)
this.blendMode = FieldTypes.ParseBlendMode(str);
str = xml.GetAttribute("filter");
if (str != null)
{
switch (str)
{
case "color":
ColorFilter cf = new ColorFilter();
this.filter = cf;
arr = xml.GetAttributeArray("filterData");
cf.AdjustBrightness(float.Parse(arr[0]));
cf.AdjustContrast(float.Parse(arr[1]));
cf.AdjustSaturation(float.Parse(arr[2]));
cf.AdjustHue(float.Parse(arr[3]));
break;
}
}
str = xml.GetAttribute("tooltips");
if (str != null)
this.tooltips = str;
}