Пример #1
0
        public SpriteSheet GetSpriteSheet(FrameGroupType groupType)
        {
            FrameGroup frameGroup = this.GetFrameGroup(groupType);

            if (frameGroup == null)
            {
                return(null);
            }

            Sprite[] sprites                = this.sprites[groupType];
            int      totalX                 = frameGroup.PatternZ * frameGroup.PatternX * frameGroup.Layers;
            int      totalY                 = frameGroup.Frames * frameGroup.PatternY;
            int      bitmapWidth            = (totalX * frameGroup.Width) * Sprite.DefaultSize;
            int      bitmapHeight           = (totalY * frameGroup.Height) * Sprite.DefaultSize;
            int      pixelsWidth            = frameGroup.Width * Sprite.DefaultSize;
            int      pixelsHeight           = frameGroup.Height * Sprite.DefaultSize;
            Bitmap   bitmap                 = new Bitmap(bitmapWidth, bitmapHeight, PixelFormat.Format32bppArgb);
            Dictionary <int, Rect> rectList = new Dictionary <int, Rect>();

            BitmapLocker lockBitmap = new BitmapLocker(bitmap);

            lockBitmap.LockBits();

            for (int f = 0; f < frameGroup.Frames; f++)
            {
                for (int z = 0; z < frameGroup.PatternZ; z++)
                {
                    for (int y = 0; y < frameGroup.PatternY; y++)
                    {
                        for (int x = 0; x < frameGroup.PatternX; x++)
                        {
                            for (int l = 0; l < frameGroup.Layers; l++)
                            {
                                int index = frameGroup.GetTextureIndex(l, x, y, z, f);
                                int fx    = (index % totalX) * pixelsWidth;
                                int fy    = (int)(Math.Floor((decimal)(index / totalX)) * pixelsHeight);
                                rectList.Add(index, new Rect(fx, fy, pixelsWidth, pixelsHeight));

                                for (int w = 0; w < frameGroup.Width; w++)
                                {
                                    for (int h = 0; h < frameGroup.Height; h++)
                                    {
                                        index = frameGroup.GetSpriteIndex(w, h, l, x, y, z, f);
                                        int px = (frameGroup.Width - w - 1) * Sprite.DefaultSize;
                                        int py = (frameGroup.Height - h - 1) * Sprite.DefaultSize;
                                        lockBitmap.CopyPixels(sprites[index].GetBitmap(), px + fx, py + fy);
                                    }
                                }
                            }
                        }
                    }
                }
            }

            lockBitmap.UnlockBits();
            lockBitmap.Dispose();

            return(new SpriteSheet(bitmap, rectList));
        }
Пример #2
0
        public SpriteSheet GetSpriteSheet(ushort id, ThingCategory category, FrameGroupType groupType)
        {
            ThingType thing = this.Things.GetThing(id, category);

            if (thing == null)
            {
                return(null);
            }

            FrameGroup             group        = thing.GetFrameGroup(groupType);
            int                    totalX       = group.PatternZ * group.PatternX * group.Layers;
            int                    totalY       = group.Frames * group.PatternY;
            int                    bitmapWidth  = (totalX * group.Width) * Sprite.DefaultSize;
            int                    bitmapHeight = (totalY * group.Height) * Sprite.DefaultSize;
            int                    pixelsWidth  = group.Width * Sprite.DefaultSize;
            int                    pixelsHeight = group.Height * Sprite.DefaultSize;
            Bitmap                 bitmap       = new Bitmap(bitmapWidth, bitmapHeight, PixelFormat.Format32bppArgb);
            Dictionary <int, Rect> rectList     = new Dictionary <int, Rect>();

            BitmapLocker lockBitmap = new BitmapLocker(bitmap);

            lockBitmap.LockBits();

            for (int f = 0; f < group.Frames; f++)
            {
                for (int z = 0; z < group.PatternZ; z++)
                {
                    for (int y = 0; y < group.PatternY; y++)
                    {
                        for (int x = 0; x < group.PatternX; x++)
                        {
                            for (int l = 0; l < group.Layers; l++)
                            {
                                int index = group.GetTextureIndex(l, x, y, z, f);
                                int fx    = (index % totalX) * pixelsWidth;
                                int fy    = (int)(Math.Floor((decimal)(index / totalX)) * pixelsHeight);
                                rectList.Add(index, new Rect(fx, fy, pixelsWidth, pixelsHeight));

                                for (int w = 0; w < group.Width; w++)
                                {
                                    for (int h = 0; h < group.Height; h++)
                                    {
                                        index = group.GetSpriteIndex(w, h, l, x, y, z, f);
                                        int  px       = ((group.Width - w - 1) * Sprite.DefaultSize);
                                        int  py       = ((group.Height - h - 1) * Sprite.DefaultSize);
                                        uint spriteId = group.SpriteIDs[index];
                                        lockBitmap.CopyPixels(this.Sprites.GetSpriteBitmap(spriteId), px + fx, py + fy);
                                    }
                                }
                            }
                        }
                    }
                }
            }

            lockBitmap.UnlockBits();

            return(new SpriteSheet(bitmap, rectList));
        }
Пример #3
0
        public Bitmap GetObjectImage(ushort id, ThingCategory category, FrameGroupType groupType)
        {
            ThingType thing = this.Things.GetThing(id, category);

            if (thing == null)
            {
                return(null);
            }

            Bitmap bitmap = this.spriteCache.GetPicture(id, category);

            if (bitmap != null)
            {
                return(bitmap);
            }

            FrameGroup group  = thing.GetFrameGroup(groupType);
            int        width  = Sprite.DefaultSize * group.Width;
            int        height = Sprite.DefaultSize * group.Height;

            bitmap = new Bitmap(width, height, PixelFormat.Format32bppArgb);

            BitmapLocker lockBitmap = new BitmapLocker(bitmap);

            lockBitmap.LockBits();

            byte layers = group.Layers;
            byte x      = 0;

            if (category == ThingCategory.Outfit)
            {
                layers = 1;
                x      = (byte)(2 % group.PatternX);
            }

            // draw sprite
            for (byte l = 0; l < layers; l++)
            {
                for (byte w = 0; w < group.Width; w++)
                {
                    for (byte h = 0; h < group.Height; h++)
                    {
                        int  index    = group.GetSpriteIndex(w, h, l, x, 0, 0, 0);
                        uint spriteId = group.SpriteIDs[index];
                        int  px       = (group.Width - w - 1) * Sprite.DefaultSize;
                        int  py       = (group.Height - h - 1) * Sprite.DefaultSize;

                        lockBitmap.CopyPixels(this.Sprites.GetSpriteBitmap(spriteId), px, py);
                    }
                }
            }

            lockBitmap.UnlockBits();
            lockBitmap.Dispose();

            this.spriteCache.SetPicture(id, category, bitmap);
            return(bitmap);
        }
Пример #4
0
        public static ThingType ToSingleFrameGroup(ThingType thing)
        {
            if (thing.Category != ThingCategory.Outfit || thing.FrameGroupCount != 2)
            {
                return(thing);
            }

            FrameGroup walkingFrameGroup = thing.GetFrameGroup(FrameGroupType.Walking);
            FrameGroup newGroup          = walkingFrameGroup.Clone();

            if (walkingFrameGroup.Frames > 1)
            {
                newGroup.Frames         = (byte)(newGroup.Frames + 1);
                newGroup.SpriteIDs      = new uint[newGroup.GetTotalSprites()];
                newGroup.IsAnimation    = true;
                newGroup.FrameDurations = new FrameDuration[newGroup.Frames];

                for (int i = 0; i < newGroup.Frames; i++)
                {
                    if (newGroup.FrameDurations[i] != null)
                    {
                        newGroup.FrameDurations[i] = newGroup.FrameDurations[i];
                    }
                    else
                    {
                        newGroup.FrameDurations[i] = new FrameDuration(ThingCategory.Outfit);
                    }
                }
            }

            for (byte k = 0; k < thing.FrameGroupCount; k++)
            {
                FrameGroup group = thing.GetFrameGroup((FrameGroupType)k);

                for (byte f = 0; f < group.Frames; f++)
                {
                    for (byte z = 0; z < group.PatternZ; z++)
                    {
                        for (byte y = 0; y < group.PatternY; y++)
                        {
                            for (byte x = 0; x < group.PatternX; x++)
                            {
                                for (byte l = 0; l < group.Layers; l++)
                                {
                                    for (byte w = 0; w < group.Width; w++)
                                    {
                                        for (byte h = 0; h < group.Height; h++)
                                        {
                                            if (k == (byte)FrameGroupType.Default && f == 0)
                                            {
                                                int i  = group.GetSpriteIndex(w, h, l, x, y, z, f);
                                                int ni = newGroup.GetSpriteIndex(w, h, l, x, y, z, f);
                                                newGroup.SpriteIDs[ni] = group.SpriteIDs[i];
                                            }
                                            else if (k == (byte)FrameGroupType.Walking)
                                            {
                                                int i  = group.GetSpriteIndex(w, h, l, x, y, z, f);
                                                int ni = newGroup.GetSpriteIndex(w, h, l, x, y, z, f + 1);
                                                newGroup.SpriteIDs[ni] = group.SpriteIDs[i];
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            thing.FrameGroups = new Dictionary <FrameGroupType, FrameGroup>();
            thing.FrameGroups.Add(FrameGroupType.Default, newGroup);
            return(thing);
        }
Пример #5
0
        public Bitmap GetObjectImage(ushort id, Direction direction, OutfitData data, bool mount)
        {
            ThingType thing = this.Things.GetThing(id, ThingCategory.Outfit);

            if (thing == null)
            {
                return(null);
            }

            FrameGroup group = thing.GetFrameGroup(FrameGroupType.Default);

            if (group.Layers < 2)
            {
                return(this.GetObjectImage(id, ThingCategory.Outfit, FrameGroupType.Default));
            }

            int    width       = Sprite.DefaultSize * group.Width;
            int    height      = Sprite.DefaultSize * group.Height;
            Bitmap grayBitmap  = new Bitmap(width, height, PixelFormat.Format32bppArgb);
            Bitmap blendBitmap = new Bitmap(width, height, PixelFormat.Format32bppArgb);
            Bitmap bitmap      = new Bitmap(width, height, PixelFormat.Format32bppArgb);

            BitmapLocker grayLocker   = new BitmapLocker(grayBitmap);
            BitmapLocker blendLocker  = new BitmapLocker(blendBitmap);
            BitmapLocker bitmapLocker = new BitmapLocker(bitmap);

            grayLocker.LockBits();
            blendLocker.LockBits();
            bitmapLocker.LockBits();

            byte x = (byte)((byte)direction % group.PatternX);
            byte z = mount && group.PatternZ > 1 ? (byte)1 : (byte)0;

            for (int y = 0; y < group.PatternY; y++)
            {
                if (y == 0 || (data.Addons & 1 << (y - 1)) != 0)
                {
                    for (byte w = 0; w < group.Width; w++)
                    {
                        for (byte h = 0; h < group.Height; h++)
                        {
                            int  index    = group.GetSpriteIndex(w, h, 0, x, y, z, 0);
                            uint spriteId = group.SpriteIDs[index];
                            int  px       = (group.Width - w - 1) * Sprite.DefaultSize;
                            int  py       = (group.Height - h - 1) * Sprite.DefaultSize;
                            grayLocker.CopyPixels(this.Sprites.GetSpriteBitmap(spriteId), px, py);

                            index    = group.GetSpriteIndex(w, h, 1, x, y, z, 0);
                            spriteId = group.SpriteIDs[index];
                            blendLocker.CopyPixels(this.Sprites.GetSpriteBitmap(spriteId), px, py);
                        }
                    }

                    bitmapLocker.ColorizePixels(grayLocker.Pixels, blendLocker.Pixels, data.Head, data.Body, data.Legs, data.Feet);
                }
            }

            grayLocker.UnlockBits();
            grayLocker.Dispose();
            blendLocker.UnlockBits();
            blendLocker.Dispose();
            bitmapLocker.UnlockBits();
            bitmapLocker.Dispose();
            grayBitmap.Dispose();
            blendBitmap.Dispose();
            return(bitmap);
        }