示例#1
0
        public override void Draw(BaseScreen.Resources screenResources, SmartSpriteBatch spriteBatch, ScreenAbstractor screen, float opacity, FloatRectangle?clip = null, Texture2D bgTexture = null, Vector2?scrollOffset = null)
        {
            if (this.Children.Value == null || this.Children.Value.Count == 0)
            {
                return;
            }

            foreach (DataboundAsset databoundAsset in this.Children.Value)
            {
                databoundAsset.IsHidden.Value = true;
            }

            DataboundAsset select = this.Children.Value.First();

            if (this.State.Value == ButtonState.Hover && this.Children.Value.Count > 1)
            {
                select = this.Children.Value[1];
            }
            if (this.State.Value == ButtonState.Pressing && this.Children.Value.Count > 2)
            {
                select = this.Children.Value[2];
            }

            select.IsHidden.Value = false;

            SetChildrenOriginToMyOrigin();

            if (this.ActualSize == Vector2.Zero)
            {
                this.ActualSize = this.Children.Value.First().ActualSize;
            }
        }
示例#2
0
        public static List <DataboundAsset> GetVirtualChildren(DataboundAsset screenAsset)
        {
            List <DataboundAsset> result = new List <DataboundAsset>();

            if (screenAsset is TemplateAsset templateAsset)
            {
                if (!string.IsNullOrWhiteSpace(templateAsset.Template.Value))
                {
                    //  string templateName = templateAsset.Template.Value;

                    //  DataboundAsset templateContent = Templates[templateName].DeepClone();
                    //  templateContent.ParentPosition = templateAsset.ActualPosition;

                    //if (templateContent is DataboundContainterAsset templateContainterAsset)
                    //{
                    //    List<DataboundAsset> childs = templateAsset.Children.Value.DeepClone();
                    //    foreach (DataboundAsset databoundAsset in childs)
                    //    {
                    //        databoundAsset.ParentPosition = templateAsset.ActualPosition;
                    //    }
                    //    List<ContentAsset> content = FindChildrenOfType<ContentAsset>(templateContainterAsset);



                    //    foreach (var cont in content)
                    //    {
                    //        cont.Children.Value = childs;
                    //        cont.ParentPosition = templateAsset.ActualPosition;
                    //    }

                    //  //  templateContainterAsset.Children = new DataboundAsset.DataboundValue<List<DataboundAsset>>();
                    //}

                    // result.Add(templateContent);
                    //result.AddRange(GetVirtualChildren(templateContent));
                }
            }
            else if (screenAsset is DataboundContainterAsset asset)
            {
                if (asset.Children.Value != null)
                {
                    result.AddRange(asset.Children.Value);
                }
            }

            return(result);
        }
示例#3
0
        public static List <DataboundAsset> FlattenTree(DataboundAsset asset)
        {
            List <DataboundAsset> result = new List <DataboundAsset> {
                asset
            };

            if (asset is DataboundContainterAsset dbc)
            {
                foreach (DataboundAsset databoundAsset in GetVirtualChildren(dbc))
                {
                    result.AddRange(FlattenTree(databoundAsset));
                }
            }


            return(result.Where(t => !(t is ContentAsset)).ToList());
        }
示例#4
0
        public static List <DataboundAsset> HandleChildren(BaseScreen.Resources screenResources, XmlNode node, DataboundAsset parentAsset = null, BaseScreen screen = null)
        {
            List <DataboundAsset> results = new List <DataboundAsset>();
            List <Type>           types   = ReflectionHelpers.TypesImplementingInterface(typeof(DataboundAsset)).ToList();

            foreach (XmlNode childNode in node.ChildNodes)
            {
                Type type = types.FirstOrDefault(t => t.Name == childNode.Name);
                if (type != null)
                {
                    DataboundAsset asset = DataboundAsset.CreateFromXml(childNode.Attributes, type, parentAsset, screen);
                    asset.ParentAsset = parentAsset;

                    if (asset is DataboundAssetWhereChildIsContentAsset masterAsset && !string.IsNullOrEmpty(childNode.InnerText))
                    {
                        masterAsset.LoadContent(childNode.InnerText);
                    }

                    if (asset is DataboundContainterAsset containerAsset)
                    {
                        containerAsset.Children.Value.AddRange(HandleChildren(screenResources, childNode, asset));
                    }

                    results.Add(asset);
                }
                else
                {
                    if (childNode.Name.ToLower() == "resources")
                    {
                        foreach (XmlNode xmlNode in childNode.ChildNodes)
                        {
                            if (xmlNode.Name.ToLower() == "template")
                            {
                                string nm = (string)xmlNode.Attributes.GetNamedItem("Name").Value;

                                string templateAsString = xmlNode.InnerXml;
                                screenResources.TemplateXMLs.Add(nm, templateAsString);
                            }
                        }
                    }
                }
            }

            return(results);
        }
示例#5
0
        public override void Draw(BaseScreen.Resources screenResources, SmartSpriteBatch spriteBatch, ScreenAbstractor screen, float opacity, FloatRectangle?clip = null, Texture2D bgTexture = null, Vector2?scrollOffset = null)
        {
            if (!haveLoadedTemplate)
            {
                string template = Template.Value();

                List <DataboundAsset> children = this.Children.Value;

                DataboundAsset templateContent = screenResources.GetTemplate(template);
                templateContent.ParentAsset = this;

                if (templateContent is DataboundContainterAsset containerAsset)
                {
                    //containerAsset.Children.Value = children;

                    List <DataboundAsset> contentAssets = containerAsset.FindChildrenOfType <ContentAsset>();
                    if (contentAssets.Count > 0)
                    {
                        foreach (var contentAsset in contentAssets)
                        {
                            ((DataboundContainterAsset)contentAsset.ParentAsset).Children.Value = children;
                        }
                    }
                }

                this.Children.Value = new List <DataboundAsset> {
                    templateContent
                };
                this.FixParentChildRelationship();

                this.FixBinds();
                haveLoadedTemplate = true;
            }

            SetChildrenOriginToMyOrigin();
            if (ActualSize == Vector2.Zero)
            {
                this.ActualSize = this.Children.Value.First().ActualSize;
            }
        }