Exemplo n.º 1
0
        public LTextureList(Stream ins0)
        {
            this.imageList  = new Dictionary <string, ImageData>(10);
            this.autoExpand = false;
            this.visible    = true;

            int index = 0;

            string x = "x", y = "y", w = "w", h = "h";
            string scale = "scale", src = "src", maskName = "mask", empty = "empty";
            string name = "name", filterName = "filter", n = "nearest", l = "linear";

            XMLDocument       doc    = XMLParser.Parse(ins0);
            List <XMLElement> images = doc.GetRoot().Find("image");

            if (images.Count > 0)
            {
                IEnumerator <XMLElement> it = images.GetEnumerator();
                for (; it.MoveNext();)
                {
                    XMLElement ele = it.Current;
                    if (ele != null)
                    {
                        ImageData data = new ImageData();
                        data.x     = ele.GetIntAttribute(x, 0);
                        data.y     = ele.GetIntAttribute(y, 0);
                        data.w     = ele.GetIntAttribute(w, 0);
                        data.h     = ele.GetIntAttribute(h, 0);
                        data.scale = ele.GetFloatAttribute(scale, 0);
                        data.xref  = ele.GetAttribute(src, empty);
                        XMLElement mask = ele.GetChildrenByName(maskName);
                        if (mask != null)
                        {
                            int r = mask.GetIntAttribute("r", 0);
                            int g = mask.GetIntAttribute("g", 0);
                            int b = mask.GetIntAttribute("b", 0);
                            int a = mask.GetIntAttribute("a", 0);
                            data.mask = new LColor(r, g, b, a);
                        }
                        else
                        {
                            data.mask = null;
                        }
                        string filter = ele.GetAttribute(filterName, n);
                        if (filter.Equals(n))
                        {
                            data.scaleType = 0;
                        }
                        if (filter.Equals(l))
                        {
                            data.scaleType = 1;
                        }
                        data.index = index;
                        XMLElement parent = ele.GetParent();
                        if (parent != null)
                        {
                            CollectionUtils.Put(imageList, parent.GetAttribute(name, empty), data);
                            index++;
                        }
                    }
                }
            }
            this.count  = imageList.Count;
            this.values = new LTextureObject[count];
        }