GetById() public static méthode

Return a UIPackage with a certain id.
public static GetById ( string id ) : UIPackage
id string ID of the package.
Résultat UIPackage
Exemple #1
0
        /// <summary>
        /// 收集创建目标对象所需的所有类型信息
        /// </summary>
        /// <param name="item"></param>
        /// <param name="list"></param>
        static int CollectComponentChildren(PackageItem item, List <DisplayListItem> list)
        {
            ByteBuffer buffer = item.rawData;

            buffer.Seek(0, 2);

            int             dcnt = buffer.ReadShort();
            DisplayListItem di;
            PackageItem     pi;

            for (int i = 0; i < dcnt; i++)
            {
                int dataLen = buffer.ReadShort();
                int curPos  = buffer.position;

                buffer.Seek(curPos, 0);

                ObjectType type  = (ObjectType)buffer.ReadByte();
                string     src   = buffer.ReadS();
                string     pkgId = buffer.ReadS();

                buffer.position = curPos;

                if (src != null)
                {
                    UIPackage pkg;
                    if (pkgId != null)
                    {
                        pkg = UIPackage.GetById(pkgId);
                    }
                    else
                    {
                        pkg = item.owner;
                    }

                    pi = pkg != null?pkg.GetItem(src) : null;

                    di = new DisplayListItem(pi, type);

                    if (pi != null && pi.type == PackageItemType.Component)
                    {
                        di.childCount = CollectComponentChildren(pi, list);
                    }
                }
                else
                {
                    di = new DisplayListItem(null, type);
                    if (type == ObjectType.List) //list
                    {
                        di.listItemCount = CollectListChildren(buffer, list);
                    }
                }

                list.Add(di);
                buffer.position = curPos + dataLen;
            }

            return(dcnt);
        }
        private GObject ConstructChild(XML xml)
        {
            string    pkgId   = xml.GetAttribute("pkg");
            UIPackage thisPkg = _packageItem.owner;
            UIPackage pkg;

            if (pkgId != null && pkgId != thisPkg.id)
            {
                pkg = UIPackage.GetById(pkgId);
                if (pkg == null)
                {
                    return(null);
                }
            }
            else
            {
                pkg = thisPkg;
            }

            string src = xml.GetAttribute("src");

            if (src != null)
            {
                PackageItem pi = pkg.GetItem(src);
                if (pi == null)
                {
                    return(null);
                }

                GObject g = pkg.CreateObject(pi, null);
                return(g);
            }
            else
            {
                GObject g;
                if (xml.name == "text" && xml.GetAttributeBool("input", false))
                {
                    g = new GTextInput();
                }
                else
                {
                    g = UIObjectFactory.NewObject(xml.name);
                }
                return(g);
            }
        }
Exemple #3
0
		void LoadComponentChildren(PackageItem item)
		{
			XML listNode = item.componentData.GetNode("displayList");
			if (listNode != null)
			{
				XMLList col = listNode.Elements();
				int dcnt = col.Count;
				item.displayList = new DisplayListItem[dcnt];
				DisplayListItem di;
				for (int i = 0; i < dcnt; i++)
				{
					XML cxml = col[i];

					string src = cxml.GetAttribute("src");
					if (src != null)
					{
						string pkgId = cxml.GetAttribute("pkg");
						UIPackage pkg;
						if (pkgId != null && pkgId != item.owner.id)
							pkg = UIPackage.GetById(pkgId);
						else
							pkg = item.owner;

						PackageItem pi = pkg != null ? pkg.GetItem(src) : null;
						if (pi != null)
							di = new DisplayListItem(pi, null);
						else
							di = new DisplayListItem(null, cxml.name);
					}
					else
					{
						if (cxml.name == "text" && cxml.GetAttributeBool("input", false))
							di = new DisplayListItem(null, "inputtext");
						else
							di = new DisplayListItem(null, cxml.name);
					}

					di.desc = cxml;
					item.displayList[i] = di;
				}
			}
			else
				item.displayList = new DisplayListItem[0];
		}
Exemple #4
0
        internal void ConstructFromResource(List <GObject> objectPool, int poolIndex)
        {
            if (!packageItem.translated)
            {
                packageItem.translated = true;
                TranslationHelper.TranslateComponent(packageItem);
            }

            ByteBuffer buffer = packageItem.rawData;

            buffer.Seek(0, 0);

            underConstruct = true;

            sourceWidth  = buffer.ReadInt();
            sourceHeight = buffer.ReadInt();
            initWidth    = sourceWidth;
            initHeight   = sourceHeight;

            SetSize(sourceWidth, sourceHeight);

            if (buffer.ReadBool())
            {
                minWidth  = buffer.ReadInt();
                maxWidth  = buffer.ReadInt();
                minHeight = buffer.ReadInt();
                maxHeight = buffer.ReadInt();
            }

            if (buffer.ReadBool())
            {
                float f1 = buffer.ReadFloat();
                float f2 = buffer.ReadFloat();
                SetPivot(f1, f2, buffer.ReadBool());
            }

            if (buffer.ReadBool())
            {
                _margin.top    = buffer.ReadInt();
                _margin.bottom = buffer.ReadInt();
                _margin.left   = buffer.ReadInt();
                _margin.right  = buffer.ReadInt();
            }

            OverflowType overflow = (OverflowType)buffer.ReadByte();

            if (overflow == OverflowType.Scroll)
            {
                int savedPos = buffer.position;
                buffer.Seek(0, 7);
                SetupScroll(buffer);
                buffer.position = savedPos;
            }
            else
            {
                SetupOverflow(overflow);
            }

            if (buffer.ReadBool())             //clipSoftness
            {
                buffer.Skip(8);
            }

            _buildingDisplayList = true;

            buffer.Seek(0, 1);

            int controllerCount = buffer.ReadShort();

            for (int i = 0; i < controllerCount; i++)
            {
                int nextPos = buffer.ReadShort();
                nextPos += buffer.position;

                Controller controller = new Controller();
                _controllers.Add(controller);
                controller.parent = this;
                controller.Setup(buffer);

                buffer.position = nextPos;
            }

            buffer.Seek(0, 2);

            GObject child;
            int     childCount = buffer.ReadShort();

            for (int i = 0; i < childCount; i++)
            {
                int dataLen = buffer.ReadShort();
                int curPos  = buffer.position;

                if (objectPool != null)
                {
                    child = objectPool[poolIndex + i];
                }
                else
                {
                    buffer.Seek(curPos, 0);

                    ObjectType type  = (ObjectType)buffer.ReadByte();
                    string     src   = buffer.ReadS();
                    string     pkgId = buffer.ReadS();

                    PackageItem pi = null;
                    if (src != null)
                    {
                        UIPackage pkg;
                        if (pkgId != null)
                        {
                            pkg = UIPackage.GetById(pkgId);
                        }
                        else
                        {
                            pkg = packageItem.owner;
                        }

                        pi = pkg != null?pkg.GetItem(src) : null;
                    }

                    if (pi != null)
                    {
                        child             = UIObjectFactory.NewObject(pi);
                        child.packageItem = pi;
                        child.ConstructFromResource();
                    }
                    else
                    {
                        child = UIObjectFactory.NewObject(type);
                    }
                }

                child.underConstruct = true;
                child.Setup_BeforeAdd(buffer, curPos);
                child.InternalSetParent(this);
                _children.Add(child);

                buffer.position = curPos + dataLen;
            }

            buffer.Seek(0, 3);
            this.relations.Setup(buffer, true);

            buffer.Seek(0, 2);
            buffer.Skip(2);

            for (int i = 0; i < childCount; i++)
            {
                int nextPos = buffer.ReadShort();
                nextPos += buffer.position;

                buffer.Seek(buffer.position, 3);
                _children[i].relations.Setup(buffer, false);

                buffer.position = nextPos;
            }

            buffer.Seek(0, 2);
            buffer.Skip(2);

            for (int i = 0; i < childCount; i++)
            {
                int nextPos = buffer.ReadShort();
                nextPos += buffer.position;

                child = _children[i];
                child.Setup_AfterAdd(buffer, buffer.position);
                child.underConstruct = false;

                buffer.position = nextPos;
            }

            buffer.Seek(0, 4);

            buffer.Skip(2);             //customData
            this.opaque = buffer.ReadBool();
            int maskId = buffer.ReadShort();

            if (maskId != -1)
            {
                this.mask = GetChildAt(maskId).displayObject;
                buffer.ReadBool();                 //reversedMask
            }
            string hitTestId = buffer.ReadS();

            if (hitTestId != null)
            {
                PackageItem pi = packageItem.owner.GetItem(hitTestId);
                if (pi != null && pi.pixelHitTestData != null)
                {
                    int i1 = buffer.ReadInt();
                    int i2 = buffer.ReadInt();
                    this.rootContainer.hitArea = new PixelHitTest(pi.pixelHitTestData, i1, i2, sourceWidth, sourceHeight);
                }
            }

            buffer.Seek(0, 5);

            int transitionCount = buffer.ReadShort();

            for (int i = 0; i < transitionCount; i++)
            {
                int nextPos = buffer.ReadShort();
                nextPos += buffer.position;

                Transition trans = new Transition(this);
                trans.Setup(buffer);
                _transitions.Add(trans);

                buffer.position = nextPos;
            }

            if (_transitions.Count > 0)
            {
                this.onAddedToStage.Add(__addedToStage);
                this.onRemovedFromStage.Add(__removedFromStage);
            }

            ApplyAllControllers();

            _buildingDisplayList = false;
            underConstruct       = false;

            BuildNativeDisplayList();
            SetBoundsChangedFlag();

            if (packageItem.objectType != ObjectType.Component)
            {
                ConstructExtension(buffer);
            }

            OnConstruct();
        }