Exemplo n.º 1
0
        public List <OutfitPreview> GetJobOutfitSprites(Gender gender, bool useInventoryIcon, out Vector2 maxDimensions)
        {
            List <OutfitPreview> outfitPreviews = new List <OutfitPreview>();

            maxDimensions = Vector2.One;

            var equipIdentifiers = Element.GetChildElements("ItemSet").Elements().Where(e => e.GetAttributeBool("outfit", false)).Select(e => e.GetAttributeString("identifier", ""));

            var outfitPrefabs = ItemPrefab.Prefabs.Where(itemPrefab => equipIdentifiers.Contains(itemPrefab.Identifier)).ToList();

            if (!outfitPrefabs.Any())
            {
                return(null);
            }

            for (int i = 0; i < outfitPrefabs.Count; i++)
            {
                var outfitPreview = new OutfitPreview();

                if (!ItemSets.TryGetValue(i, out var itemSetElement))
                {
                    continue;
                }
                var previewElement = itemSetElement.GetChildElement("PreviewSprites");
                if (previewElement == null || useInventoryIcon)
                {
                    if (outfitPrefabs[i] is ItemPrefab prefab && prefab.InventoryIcon != null)
                    {
                        outfitPreview.AddSprite(prefab.InventoryIcon, Vector2.Zero);
                        outfitPreview.Dimensions = prefab.InventoryIcon.SourceRect.Size.ToVector2();
                        maxDimensions.X          = MathHelper.Max(maxDimensions.X, outfitPreview.Dimensions.X);
                        maxDimensions.Y          = MathHelper.Max(maxDimensions.Y, outfitPreview.Dimensions.Y);
                    }
                    outfitPreviews.Add(outfitPreview);
                    continue;
                }

                var children = previewElement.Elements().ToList();
                for (int n = 0; n < children.Count; n++)
                {
                    XElement spriteElement = children[n];
                    string   spriteTexture = spriteElement.GetAttributeString("texture", "").Replace("[GENDER]", (gender == Gender.Female) ? "female" : "male");
                    var      sprite        = new Sprite(spriteElement, file: spriteTexture);
                    sprite.size = new Vector2(sprite.SourceRect.Width, sprite.SourceRect.Height);
                    outfitPreview.AddSprite(sprite, children[n].GetAttributeVector2("offset", Vector2.Zero));
                }

                outfitPreview.Dimensions = previewElement.GetAttributeVector2("dims", Vector2.One);
                maxDimensions.X          = MathHelper.Max(maxDimensions.X, outfitPreview.Dimensions.X);
                maxDimensions.Y          = MathHelper.Max(maxDimensions.Y, outfitPreview.Dimensions.Y);

                outfitPreviews.Add(outfitPreview);
            }

            return(outfitPreviews);
        }
Exemplo n.º 2
0
        public List <OutfitPreview> GetJobOutfitSprites(Gender gender, out Vector2 dimensions)
        {
            List <OutfitPreview> outfitPreviews = new List <OutfitPreview>();

            dimensions = PreviewElement.GetAttributeVector2("dims", Vector2.One);
            if (PreviewElement == null)
            {
                return(outfitPreviews);
            }

            var equipIdentifiers = Element.Elements("Items").Elements().Where(e => e.GetAttributeBool("outfit", false)).Select(e => e.GetAttributeString("identifier", ""));

            var children = PreviewElement.Elements().ToList();

            var outfitPrefab = MapEntityPrefab.List.Find(me => me is ItemPrefab itemPrefab && equipIdentifiers.Contains(itemPrefab.Identifier)) as ItemPrefab;

            if (outfitPrefab == null)
            {
                return(null);
            }
            var wearables = outfitPrefab.ConfigElement.Elements("Wearable");

            if (!wearables.Any())
            {
                return(null);
            }

            int variantCount = wearables.First().GetAttributeInt("variants", 1);

            for (int i = 0; i < variantCount; i++)
            {
                var outfitPreview = new OutfitPreview();
                for (int n = 0; n < children.Count; n++)
                {
                    XElement spriteElement  = children[n];
                    string   spriteTexture  = spriteElement.GetAttributeString("texture", "").Replace("[GENDER]", (gender == Gender.Female) ? "female" : "male");
                    string   textureVariant = spriteTexture.Replace("[VARIANT]", (i + 1).ToString());
                    if (!File.Exists(textureVariant))
                    {
                        textureVariant = spriteTexture.Replace("[VARIANT]", "1");
                    }
                    var torsoSprite = new Sprite(spriteElement, path: "", file: textureVariant);
                    torsoSprite.size = new Vector2(torsoSprite.SourceRect.Width, torsoSprite.SourceRect.Height);
                    outfitPreview.AddSprite(torsoSprite, children[n].GetAttributeVector2("offset", Vector2.Zero));
                }
                outfitPreviews.Add(outfitPreview);
            }

            return(outfitPreviews);
        }