Пример #1
0
        private static (XdObjectJson[], float Spacing) ExpandRepeatGridGroup(XdObjectJson xdObject, XdObjectJson repeatGrid, string scrollingType, IObbGetter obbGetter, ref List <SpecialSpacing> specialSpacings)
        {
            var listElement = repeatGrid.Group.Children[0].Group.Children[0];
            var listItems   = new[] { listElement };
            var childSize   = obbGetter.Get(listElement).Size;

            float spacing;

            if (scrollingType == "vertical")
            {
                spacing = (repeatGrid.Meta?.Ux?.RepeatGrid?.PaddingY ?? 0f) + (repeatGrid.Meta?.Ux?.RepeatGrid?.CellHeight ?? 0f) - childSize.y;
            }
            else
            {
                spacing = (repeatGrid.Meta?.Ux?.RepeatGrid?.PaddingX ?? 0f) + (repeatGrid.Meta?.Ux?.RepeatGrid?.CellWidth ?? 0f) - childSize.x;
            }

            if (xdObject.HasParameter("multiitems"))
            {
                listItems = ExpandMultiItemsList(listElement, scrollingType, obbGetter, ref specialSpacings);
            }

            foreach (var listItem in listItems)
            {
                listItem.RemoveConstraint();
            }

            return(listItems.ToArray(), spacing);
        }
Пример #2
0
        public (IComponent[], IAsset[]) Render(XdObjectJson xdObject, Obb obb, XdAssetHolder assetHolder)
        {
            var(imageComponent, assets) = ShapeObjectParser.RenderImage(xdObject, obb, assetHolder);

            IComponent scrollbar = new VerticalScrollbarComponent(imageComponent);

            if (xdObject.HasParameter("horizontal"))
            {
                scrollbar = new HorizontalScrollbarComponent(imageComponent);
            }
            return(new[] { scrollbar }, assets);
        }
Пример #3
0
        private static (XdObjectJson[], float Spacing) ExpandRepeatGridGroup(XdObjectJson xdObject, XdObjectJson repeatGrid, string scrollingType, IObbGetter obbGetter, ref List <SpecialSpacing> specialSpacings)
        {
            var spacing = repeatGrid.GetRepeatGridSpacing(scrollingType);

            var listElement = repeatGrid.Group.Children[0].Group.Children[0];
            var listItems   = new[] { listElement };

            if (xdObject.HasParameter("multiitems"))
            {
                listItems = ExpandMultiItemsList(listElement, scrollingType, obbGetter, ref specialSpacings);
            }

            foreach (var listItem in listItems)
            {
                listItem.RemoveConstraint();
            }

            return(listItems.ToArray(), spacing);
        }
Пример #4
0
        public static (ImageComponent, IAsset[]) RenderImage(XdObjectJson xdObject, Obb obb, XdAssetHolder assetHolder)
        {
            ImageComponent imageComponent = null;
            SpriteAsset    asset          = null;

            var color     = xdObject.GetFillUnityColor();
            var ux        = xdObject.Style?.Fill?.Pattern?.Meta?.Ux;
            var flipX     = ux?.FlipX ?? false;
            var flipY     = ux?.FlipY ?? false;
            var direction = new Vector2Int(flipX ? -1 : 1, flipY ? -1 : 1);
            var shapeType = xdObject.Shape?.Type;

            if (!string.IsNullOrWhiteSpace(ux?.Uid))
            {
                var spriteUid = $"{xdObject.GetSimpleName()}_{ux?.Uid.Substring(0, 8)}.png";
                asset          = new SpriteAsset(spriteUid, xdObject.Style.Fill.Pattern.Meta.Ux.HrefLastModifiedDate, obb.Size, null, null);
                imageComponent = new ImageComponent(
                    spriteUid,
                    color,
                    direction
                    );
                assetHolder.Save(spriteUid, xdObject.Style.Fill.Pattern.Meta);
            }
            else if (SvgUtil.Types.Contains(shapeType))
            {
                var spriteUid = $"{xdObject.GetSimpleName()}_{xdObject.Id.Substring(0, 8)}.png";
                var svg       = SvgUtil.CreateSvg(xdObject);
                var svgHash   = FastHash.CalculateHash(svg);

                var cachedSvg = assetHolder.GetCachedSvg(svgHash);
                if (cachedSvg != null)
                {
                    spriteUid = cachedSvg.SpriteUid;
                }
                else
                {
                    asset = new SpriteAsset(spriteUid, svgHash, obb.Size, null, null);
                    var xdImportSettings = XdImporter.Settings;
                    assetHolder.Save(spriteUid, () => SvgToPng.Convert(svg, obb.Size, xdImportSettings));
                    assetHolder.SaveCacheSvg(spriteUid, svgHash);
                }

                imageComponent = new ImageComponent(
                    spriteUid,
                    new Color(1f, 1f, 1f, color.a),
                    direction
                    );
            }
            else
            {
                Debug.LogError($"Unknown shape type {shapeType} in {xdObject.Name}({xdObject.Id}, {xdObject.Guid})");
            }

            var assets = new List <IAsset>();

            if (!xdObject.HasParameter("placeholder") && asset != null)
            {
                assets.Add(asset);
            }
            return(imageComponent, assets.ToArray());
        }
Пример #5
0
 public bool Is(XdObjectJson xdObject)
 {
     return(xdObject.HasParameter("vector"));
 }