Ejemplo n.º 1
0
        /// <summary>
        /// Creates a new drawgroup instance.
        /// </summary>
        /// <param name="ChunkData">The data for the chunk.</param>
        /// <param name="Sprites">The sprites that the DGRP consists of.</param>
        public DrawGroup(IffChunk Chunk, List <SPR2Parser> Sprites) : base(Chunk)
        {
            MemoryStream MemStream = new MemoryStream(Chunk.Data);
            BinaryReader Reader    = new BinaryReader(MemStream);

            m_ID      = ID;
            m_Sprites = Sprites;

            m_Version = Reader.ReadUInt16() - 20000;

            uint Count = (m_Version < 3) ? Reader.ReadUInt16() : Reader.ReadUInt32();
            uint SpriteCount, DirectionFlag, Zoom;

            for (int i = 0; i < Count; i++)
            {
                if (m_Version < 3)
                {
                    SpriteCount   = Reader.ReadUInt16();
                    DirectionFlag = Reader.ReadByte();
                    Zoom          = Reader.ReadByte();
                }
                else
                {
                    DirectionFlag = Reader.ReadUInt32();
                    Zoom          = Reader.ReadUInt32();
                    SpriteCount   = Reader.ReadUInt32();
                }
                DrawGroupImg Image = new DrawGroupImg(SpriteCount, DirectionFlag, Zoom);

                for (int j = 0; j < SpriteCount; j++)
                {
                    ushort Tag = 0;
                    int    PixelX = 0, PixelY = 0;
                    uint   SprID = 0, SprFrameID = 0, Flags = 0;
                    float  ZOffset = 0, XOffset = 0, YOffset = 0;

                    if (m_Version < 3)
                    {
                        Tag        = Reader.ReadUInt16();
                        SprID      = Reader.ReadUInt16();
                        SprFrameID = Reader.ReadUInt16();
                        Flags      = Reader.ReadUInt16();
                        PixelX     = Reader.ReadInt16();
                        PixelY     = Reader.ReadInt16();

                        if (m_Version == 1)
                        {
                            ZOffset = Reader.ReadUInt32();
                        }
                    }
                    else
                    {
                        SprID      = Reader.ReadUInt32();
                        SprFrameID = Reader.ReadUInt32();
                        PixelX     = Reader.ReadInt32();
                        PixelY     = Reader.ReadInt32();
                        ZOffset    = Reader.ReadUInt32();
                        Flags      = Reader.ReadUInt32();
                        if (m_Version == 4)
                        {
                            XOffset = Reader.ReadUInt32();
                            YOffset = Reader.ReadUInt32();
                        }
                    }

                    SpriteFrame Frame = FindSpriteFrame(SprID, SprFrameID);
                    if (Frame != null)
                    {
                        DrawGroupSprite Sprite = new DrawGroupSprite(Tag, Flags, new PixelOffset(PixelX, PixelY),
                                                                     new WorldOffset(XOffset, YOffset, ZOffset), Frame);
                        Image.Sprites.Insert(0, Sprite);
                    }
                }

                m_Images.Add(Image);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a new drawgroup instance.
        /// </summary>
        /// <param name="ChunkData">The data for the chunk.</param>
        /// <param name="Sprites">The sprites that the DGRP consists of.</param>
        public DrawGroup(IffChunk Chunk, List<SPR2Parser> Sprites)
            : base(Chunk)
        {
            MemoryStream MemStream = new MemoryStream(Chunk.Data);
            BinaryReader Reader = new BinaryReader(MemStream);

            m_ID = ID;
            m_Sprites = Sprites;

            m_Version = Reader.ReadUInt16() - 20000;

            uint Count = (m_Version < 3) ? Reader.ReadUInt16() : Reader.ReadUInt32();
            uint SpriteCount, DirectionFlag, Zoom;

            for (int i = 0; i < Count; i++)
            {
                if (m_Version < 3)
                {
                    SpriteCount = Reader.ReadUInt16();
                    DirectionFlag = Reader.ReadByte();
                    Zoom = Reader.ReadByte();
                }
                else
                {
                    DirectionFlag = Reader.ReadUInt32();
                    Zoom = Reader.ReadUInt32();
                    SpriteCount = Reader.ReadUInt32();
                }
                DrawGroupImg Image = new DrawGroupImg(SpriteCount, DirectionFlag, Zoom);

                for (int j = 0; j < SpriteCount; j++)
                {
                    ushort Tag = 0;
                    int PixelX = 0, PixelY = 0;
                    uint SprID = 0, SprFrameID = 0, Flags = 0;
                    float ZOffset = 0, XOffset = 0, YOffset = 0;

                    if (m_Version < 3)
                    {
                        Tag = Reader.ReadUInt16();
                        SprID = Reader.ReadUInt16();
                        SprFrameID = Reader.ReadUInt16();
                        Flags = Reader.ReadUInt16();
                        PixelX = Reader.ReadInt16();
                        PixelY = Reader.ReadInt16();

                        if (m_Version == 1)
                            ZOffset = Reader.ReadUInt32();
                    }
                    else
                    {
                        SprID = Reader.ReadUInt32();
                        SprFrameID = Reader.ReadUInt32();
                        PixelX = Reader.ReadInt32();
                        PixelY = Reader.ReadInt32();
                        ZOffset = Reader.ReadUInt32();
                        Flags = Reader.ReadUInt32();
                        if (m_Version == 4)
                        {
                            XOffset = Reader.ReadUInt32();
                            YOffset = Reader.ReadUInt32();
                        }
                    }

                    SpriteFrame Frame = FindSpriteFrame(SprID, SprFrameID);
                    if (Frame != null)
                    {
                        DrawGroupSprite Sprite = new DrawGroupSprite(Tag, Flags, new PixelOffset(PixelX, PixelY),
                            new WorldOffset(XOffset, YOffset, ZOffset), Frame);
                        Image.Sprites.Insert(0, Sprite);
                    }
                }

                m_Images.Add(Image);
            }
        }