Exemplo n.º 1
0
        /// <summary>
        /// Called by PckViewForm.OnImportSpritesheetClick()
        /// </summary>
        /// <param name="bitmap">bitmap containing sprites</param>
        /// <param name="pal"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <param name="pad"></param>
        /// <returns></returns>
        public static SpriteCollectionBase CreateSpriteset(
            Bitmap bitmap,
            Palette pal,
            int width,
            int height,
            int pad)
        {
            var spriteset = new SpriteCollectionBase();

            int cols = (bitmap.Width + pad) / (width + pad);
            int rows = (bitmap.Height + pad) / (height + pad);

            int terrainId = 0;

            for (int i = 0; i != cols * rows; ++i)
            {
                int x = (i % cols) * (width + pad);
                int y = (i / cols) * (height + pad);
                spriteset.Add(CreateSprite(
                                  bitmap,
                                  terrainId++,
                                  pal,
                                  x, y,
                                  width, height));
//				UpdateProgressBar(aniSprite, rows * cols);
            }

            spriteset.Pal = pal;

            return(spriteset);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Called by PckViewForm.OnImportSpritesheetClick()
        /// </summary>
        /// <param name="b">an indexed Bitmap of a spritesheet</param>
        /// <param name="pal"></param>
        /// <param name="width"></param>
        /// <param name="height"></param>
        /// <param name="pad"></param>
        /// <returns></returns>
        public static SpriteCollectionBase CreateSheetSprites(
            Bitmap b,
            Palette pal,
            int width,
            int height,
            int pad = 0)
        {
            var spriteset = new SpriteCollectionBase();

            int cols = (b.Width + pad) / (width + pad);
            int rows = (b.Height + pad) / (height + pad);

            int id = -1;

            for (int i = 0; i != cols * rows; ++i)
            {
                int x = (i % cols) * (width + pad);
                int y = (i / cols) * (height + pad);
                spriteset.Add(CreateSprite(
                                  b,
                                  ++id,
                                  pal,
                                  width, height,
                                  x, y));
            }

            spriteset.Pal = pal;

            return(spriteset);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Saves the current spriteset to PCK+TAB.
        /// </summary>
        /// <param name="dir">the directory to save to</param>
        /// <param name="file">the filename without extension</param>
        /// <param name="spriteset">pointer to the base spriteset</param>
        /// <param name="tabOffsetLength">2 for terrains/bigobs/ufo-units, 4 for tftd-units</param>
        /// <returns>true if mission was successful</returns>
        public static bool SaveSpriteset(
            string dir,
            string file,
            SpriteCollectionBase spriteset,
            int tabOffsetLength)
        {
            //LogFile.WriteLine("SpriteCollection.SaveSpriteset");
            string pfePck = Path.Combine(dir, file + GlobalsXC.PckExt);
            string pfeTab = Path.Combine(dir, file + GlobalsXC.TabExt);

            using (var bwPck = new BinaryWriter(File.Create(pfePck)))
                using (var bwTab = new BinaryWriter(File.Create(pfeTab)))
                {
                    switch (tabOffsetLength)
                    {
                    case 2:
                    {
                        int pos = 0;
                        foreach (XCImage sprite in spriteset)
                        {
                            //LogFile.WriteLine(". pos[pre]= " + pos);
                            if (pos > UInt16.MaxValue)                             // bork. Psst, happens at ~150 sprites.
                            {
                                //LogFile.WriteLine(". . UInt16 MaxValue exceeded - ret FALSE");
                                return(false);
                            }

                            bwTab.Write((ushort)pos);
                            pos += PckImage.SaveSpritesetSprite(bwPck, sprite);
                            //LogFile.WriteLine(". pos[pst]= " + pos);
                        }
                        break;
                    }

                    case 4:
                    {
                        uint pos = 0;
                        foreach (XCImage sprite in spriteset)
                        {
                            bwTab.Write(pos);
                            pos += (uint)PckImage.SaveSpritesetSprite(bwPck, sprite);
                        }
                        break;
                    }
                    }
                }
            return(true);
        }