예제 #1
0
        public override void draw(SpriteBatch spriteBatch, int xNonTile, int yNonTile, float layerDepth, float alpha = 1f)
        {
            if (Game1.eventUp && Game1.CurrentEvent.isTileWalkedOn(xNonTile / 64, yNonTile / 64))
            {
                return;
            }
            if ((int)(this.ParentSheetIndex) != 590 && (int)(this.Fragility) != 2)
            {
                spriteBatch.Draw(Game1.shadowTexture, Game1.GlobalToLocal(Game1.viewport, new Vector2((float)(xNonTile + 32), (float)(yNonTile + 51 + 4))), new Microsoft.Xna.Framework.Rectangle?(Game1.shadowTexture.Bounds), Color.White * alpha, 0.0f, new Vector2((float)Game1.shadowTexture.Bounds.Center.X, (float)Game1.shadowTexture.Bounds.Center.Y), 4f, SpriteEffects.None, layerDepth - 1E-06f);
            }
            SpriteBatch spriteBatch1      = spriteBatch;
            Texture2D   objectSpriteSheet = Game1.objectSpriteSheet;
            Vector2     local             = Game1.GlobalToLocal(Game1.viewport, new Vector2((float)(xNonTile + 32 + (this.shakeTimer > 0 ? Game1.random.Next(-1, 2) : 0)), (float)(yNonTile + 32 + (this.shakeTimer > 0 ? Game1.random.Next(-1, 2) : 0))));

            Microsoft.Xna.Framework.Rectangle?sourceRectangle = new Microsoft.Xna.Framework.Rectangle?(GameLocation.getSourceRectForObject(this.ParentSheetIndex));
            Color   color  = Color.White * alpha;
            double  num1   = 0.0;
            Vector2 origin = new Vector2(8f, 8f);
            Vector2 scale  = this.scale;
            double  num2   = (double)this.scale.Y > 1.0 ? (double)this.getScale().Y : 4.0;
            int     num3   = (bool)(this.flipped) ? 1 : 0;
            double  num4   = (double)layerDepth;

            spriteBatch1.Draw(TextureSheet.getTexture(), local, sourceRectangle, color, (float)num1, origin, (float)num2, (SpriteEffects)num3, (float)num4);
        }
예제 #2
0
 public Sprite(Rectangle location, TextureSheet textureSheet, Color color)
 {
     this.location  = location;
     texture2D      = GraphicsManager.GetTextureSheet(textureSheet);
     this.color     = color;
     rotationCenter = new Vector2(location.Width / 2, location.Height / 2);
 }
예제 #3
0
 public Rectangle GetTextureSheetSize(TextureSheet textureSheet)
 {
     if (spriteContentList.ContainsKey(textureSheet))
     {
         return(new Rectangle(0, 0, spriteContentList[textureSheet].Width, spriteContentList[textureSheet].Height));
     }
     else
     {
         return(Rectangle.Empty);
     }
 }
예제 #4
0
        public MultiTileComponent(int which, String name, String description, Animations.AnimationManager animationManager)
        {
            this.name                     = name;
            this.displayName              = name;
            this.description              = description;
            this.animationManager         = animationManager;
            this.TextureSheet             = animationManager.getExtendedTexture();
            this.defaultBoundingBox       = new Rectangle(0, 0, 16, 16);
            this.boundingBox.Value        = new Rectangle((int)0 * Game1.tileSize, (int)0 * Game1.tileSize, 1 * Game1.tileSize, 1 * Game1.tileSize);
            this.defaultSourceRect.Width  = 16;
            this.defaultSourceRect.Height = 16;
            this.sourceRect               = new Rectangle(which * 16 % TextureSheet.getTexture().Width, which * 16 / TextureSheet.getTexture().Width * 16, this.defaultSourceRect.Width * 16, this.defaultSourceRect.Height * 16);
            this.defaultSourceRect        = this.sourceRect;
            this.serializationName        = this.GetType().ToString();
            this.ParentSheetIndex         = which;

            this.NetFields.AddField(new NetCode.NetTexture2DExtended(this.getExtendedTexture()));

            this.InitializeBasics(0, Vector2.Zero);
        }
예제 #5
0
        private void SetTextureSheetData(XElement textureSheetElement, TextureSheet textureSheet)
        {
            // parent lookup
            string?parentValue = textureSheetElement.Attribute("parent")?.Value;

            if (!string.IsNullOrEmpty(parentValue))
            {
                XElement?parentElement = GameData.MergeXmlElements(GameData.Elements("CTextureSheet").Where(x => x.Attribute("id")?.Value == parentValue));
                if (parentElement != null)
                {
                    SetTextureSheetData(parentElement, textureSheet);
                }
            }

            foreach (XElement element in textureSheetElement.Elements())
            {
                string elementName = element.Name.LocalName.ToUpperInvariant();

                if (elementName == "IMAGE")
                {
                    textureSheet.Image = Path.GetFileName(PathHelper.GetFilePath(element.Attribute("value")?.Value))?.ToLowerInvariant();
                }
                else if (elementName == "ROWS")
                {
                    if (int.TryParse(element.Attribute("value")?.Value, out int value))
                    {
                        textureSheet.Rows = value;
                    }
                }
                else if (elementName == "COLUMNS")
                {
                    if (int.TryParse(element.Attribute("value")?.Value, out int value))
                    {
                        textureSheet.Columns = value;
                    }
                }
            }
        }
예제 #6
0
 public Sprite(Rectangle location, TextureSheet textureSheet, Vector2 rotationCenter)
 {
     this.location       = location;
     texture2D           = GraphicsManager.GetTextureSheet(textureSheet);
     this.rotationCenter = rotationCenter;
 }
예제 #7
0
 public static Rectangle GetTextureSheetSize(TextureSheet textureSheet)
 {
     return(texures.GetTextureSheetSize(textureSheet));
 }
예제 #8
0
 public static Texture2D GetTextureSheet(TextureSheet textureSheet)
 {
     return(texures.GetTexture(textureSheet));
 }
예제 #9
0
 public Texture2D GetTexture(TextureSheet textureSheet)
 {
     return(spriteContentList[textureSheet]);
 }
예제 #10
0
 public BackgroundMenu(Rectangle localLocation, DockType scaleType, TextureSheet textureSheet) : base(localLocation, scaleType, true)
 {
     canChangeFocusOrder = false;
     drawSpriteBack      = true;
     spriteBack          = new Sprite(GraphicsManager.GetTextureSheetSize(textureSheet), textureSheet);
 }
 public void OnEnable()
 {
     m_TextureInfo = target as TextureSheet;
     m_nRow        = m_TextureInfo.MaxRow;
     m_nColumn     = m_TextureInfo.MaxColumn;
 }
예제 #12
0
        static IEnumerable <SpriteData> ReadTexturesFromSheet(TextureSheet sheet, TextureUnravelSettings settings)
        {
            for (int i = 0; i < sheet.Sprites.Count; i++)
            {
                //Debugger.Log("D");
                Progress = i / (float)sheet.Sprites.Count;

                var sprite = sheet.Sprites[i];

                Vector2 uvOffset = new Vector2(0.001f, 0.001f);

                Vector2 PostProcessedBL = Vector2.zero;
                Vector2 PostProcessedTR = Vector2.zero;

                bool rotated = false;

                if (sprite.UVs[0].x == sprite.UVs[1].x && sprite.UVs[2].x == sprite.UVs[3].x)
                {
                    rotated = true;
                }


                if (rotated)
                {
                    PostProcessedBL = sprite.UVs[1];
                    PostProcessedTR = sprite.UVs[2];
                }
                else
                {
                    PostProcessedBL = sprite.UVs[0];
                    PostProcessedTR = sprite.UVs[3];
                }

                int PreBLx = Mathf.RoundToInt((PostProcessedBL.x * settings.texture.width) - uvOffset.x);
                int PreTRy = Mathf.RoundToInt(((PostProcessedBL.y) * settings.texture.height) - uvOffset.y);
                //float PreTRy = ((-PostProcessedBL.y + 1.0f) * settings.texture.height) - uvOffset.y;
                int PreTRx = Mathf.RoundToInt((PostProcessedTR.x * settings.texture.width) + uvOffset.x);
                int PreBLy = Mathf.RoundToInt(((PostProcessedTR.y) * settings.texture.height) + uvOffset.y);


                int PreWidth  = Difference(PreBLx, PreTRx);
                int PreHeight = Difference(PreBLy, PreTRy);

                Orientation orientation = Orientation.Up;

                if (PostProcessedBL.x < PostProcessedTR.x && PostProcessedBL.y < PostProcessedTR.y)
                {
                    orientation = Orientation.Up;
                }
                else if (PostProcessedBL.x < PostProcessedTR.x && PostProcessedBL.y > PostProcessedTR.y)
                {
                    orientation = Orientation.Right;
                }
                else if (PostProcessedBL.x > PostProcessedTR.x && PostProcessedBL.y > PostProcessedTR.y)
                {
                    orientation = Orientation.Down;
                }
                else if (PostProcessedBL.x > PostProcessedTR.x && PostProcessedBL.y < PostProcessedTR.y)
                {
                    orientation = Orientation.Left;
                }

                Vector2Int Min = new Vector2Int(Mathf.RoundToInt(Mathf.Min(PreBLx, PreTRx)), Mathf.RoundToInt(Mathf.Min(PreBLy, PreTRy)));

                Vector2Int Max = new Vector2Int(Mathf.RoundToInt(Mathf.Max(PreBLx, PreTRx)), Mathf.RoundToInt(Mathf.Max(PreBLy, PreTRy)));

                Vector2Int SpriteDimensions = new Vector2Int(Difference(Min.x, Max.x) + 1, Difference(Min.y, Max.y) + 1);

                Color[,] colorMatrix = new Color[SpriteDimensions.x, SpriteDimensions.y];

                for (int x = Min.x; x <= Max.x; x++)
                {
                    for (int y = Min.y; y <= Max.y; y++)
                    {
                        Color reading = settings.texture.GetPixel(x, y);
                        colorMatrix[x - Min.x, y - Min.y] = reading;
                    }
                }

                Texture2D texture = null;
                switch (orientation)
                {
                case Orientation.Up:
                    break;

                case Orientation.Right:
                    colorMatrix = RotateLeft(colorMatrix);
                    break;

                case Orientation.Down:
                    colorMatrix = RotateLeft(colorMatrix);
                    colorMatrix = RotateLeft(colorMatrix);
                    break;

                case Orientation.Left:
                    colorMatrix = RotateLeft(colorMatrix);
                    colorMatrix = RotateLeft(colorMatrix);
                    colorMatrix = RotateLeft(colorMatrix);
                    break;

                default:
                    break;
                }

                if (sprite.Flipped)
                {
                    colorMatrix = HorizontalFlip(colorMatrix);
                }

                texture      = new Texture2D(colorMatrix.GetLength(0), colorMatrix.GetLength(1));
                texture.name = sprite.SpriteName;
                for (int x = 0; x < texture.width; x++)
                {
                    for (int y = 0; y < texture.height; y++)
                    {
                        texture.SetPixel(x, y, colorMatrix[x, y]);
                    }
                }

                yield return(new SpriteData()
                {
                    Texture = texture,
                    Sheet = sprite,
                    UVDimensions = new Vector2Int(PreWidth, PreHeight),
                    PixelsPerUnit = texture.width / sprite.WorldSize.x,
                    SpriteCoords = new Rect(Min.x, Min.y, Max.x - Min.x + 1, Max.y - Min.y + 1)
                });

                /*var fileName = sprite.SpriteName;
                 * if (fileName == "")
                 * {
                 *      fileName = "unknown_" + i;
                 * }
                 *
                 * var filePath = folder + "/" + fileName + ".png";
                 *
                 *
                 * using (var file = File.Create(filePath))
                 * {
                 *      using (var writer = new BinaryWriter(file))
                 *      {
                 *              var png = texture.EncodeToPNG();
                 *              writer.Write(png);
                 *      }
                 * }*/
                /*AssetDatabase.ImportAsset(filePath);
                 *
                 * AddedSprites.Add(new SpriteLocation()
                 * {
                 *      Sprite = sprite,
                 *      FileLocation = filePath,
                 *      UVWidth = PreWidth,
                 *      UVHeight = PreHeight,
                 *      SpriteDimensions = new Vector2Int(colorMatrix.GetLength(0), colorMatrix.GetLength(1))
                 * });*/
            }
        }