예제 #1
0
        public override void Process(String compName, ResourcePack rp)
        {
            Int32 numTilesWide = (TargetBitmap.Width) / (Constants.TileSize);
              Int32 numTilesHigh = (TargetBitmap.Height) / (Constants.TileSize);

              Room r = new Room();
              r.Name = compName;

              Int32 numTilesAdded = 0;
              for (Int32 y = 0; y < numTilesHigh; y++)
              {
            for (Int32 x = 0; x < numTilesWide; x++)
            {
              Tile b = new Tile();

              Int32 tileX = x * (Constants.TileSize);
              Int32 tileY = y * (Constants.TileSize);

              b.SliceFromBitmap(TargetBitmap, tileX, tileY);
              b.Name = compName;

              if (rp.Add(b))
              {
            numTilesAdded++;
              }

              r.SetTile(x, y, b);
            }
              }

              rp.Add(r);
        }
예제 #2
0
        public override void Process(String compName, ResourcePack rp)
        {
            Int32 gapX = (Int32)gapInX.Value;
              Int32 gapY = (Int32)gapInY.Value;

              Bitmap edgedBitmap = new Bitmap(TargetBitmap, TargetBitmap.Width + Constants.TileSize, TargetBitmap.Height + Constants.TileSize);
              using (Graphics edgeGfx = Graphics.FromImage(edgedBitmap))
              {
            edgeGfx.Clear(colourSwatch.BackColor);

            edgeGfx.InterpolationMode = InterpolationMode.NearestNeighbor;
            edgeGfx.DrawImage(TargetBitmap, new Rectangle(0, 0, TargetBitmap.Width, TargetBitmap.Height), 0, 0, TargetBitmap.Width, TargetBitmap.Height, GraphicsUnit.Pixel);
              }

              Int32 curX = 0, curY = 0;
              while (curY < TargetBitmap.Height)
              {
            while (curX < TargetBitmap.Width)
            {
              Tile b = new Tile();

              b.SliceFromBitmap(edgedBitmap, curX, curY);
              b.Name = compName;

              rp.Add(b);

              curX += Constants.TileSize + gapX;
            }

            curX = 0;
            curY += Constants.TileSize + gapY;
              }
        }
예제 #3
0
        private void ctxTileImport_Click(object sender, EventArgs e)
        {
            Int32 uniqueAdds = 0;
              foreach (ImageListViewItem ilvi in tilesCache.SelectedItems)
              {
            String compFilename = ilvi.Tag as String;

            Tile sp = new Tile();
            sp.LoadFromFile(compFilename);

            if (hostPack.Add(sp))
              uniqueAdds++;
              }

              MessageBox.Show(String.Format("Added {0} unique tiles to the current resource pack", uniqueAdds), "InSiDe", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
예제 #4
0
파일: InSiDeForm.cs 프로젝트: ishani/InSiDe
        private void mmImportResDir_Click(object sender, EventArgs e)
        {
            if (ce != null)
              {
            ce.BringToFront();
            return;
              }

              if (findResourceCache.ShowDialog() == DialogResult.OK)
              {
            // show progress dialog
            ProcessingProgressForm ip = new ProcessingProgressForm();
            ip.Show();
            Application.DoEvents();

            ce = new CacheExplorer();
            ce.hostPack = resourcePack;

            ce.FormClosed += new FormClosedEventHandler((object _send, FormClosedEventArgs _e) => { ce = null; GC.Collect(); });

            ResourcePack dummyPack = new ResourcePack();
            Cursor.Current = Cursors.WaitCursor;

            // formulate directories to search
            String rootResDir = findResourceCache.SelectedPath;
            String tileDir = rootResDir + Path.DirectorySeparatorChar + "tile" + Path.DirectorySeparatorChar;
            String spriteDir = rootResDir + Path.DirectorySeparatorChar + "sprite" + Path.DirectorySeparatorChar;
            String objectDir = rootResDir + Path.DirectorySeparatorChar + "object" + Path.DirectorySeparatorChar;
            String roomDir = rootResDir + Path.DirectorySeparatorChar + "room" + Path.DirectorySeparatorChar;

            // go look up all the files we'll need to import
            Console.WriteLine("Gathering {0}...", tileDir);
            String[] tileFiles = (Directory.Exists(tileDir)) ? Directory.GetFiles(tileDir) : new String[] {};
            Console.WriteLine("Gathering {0}...", spriteDir);
            String[] spriteFiles = (Directory.Exists(spriteDir)) ? Directory.GetFiles(spriteDir) : new String[] {};
            Console.WriteLine("Gathering {0}...", objectDir);
            String[] objectFiles = (Directory.Exists(objectDir)) ? Directory.GetFiles(objectDir) : new String[] {};
            Console.WriteLine("Gathering {0}...", roomDir);
            String[] roomFiles = (Directory.Exists(roomDir)) ? Directory.GetFiles(roomDir) : new String[] { };
            Application.DoEvents();

            // setup progress bar for all files to load
            ip.progressBarLoad.Maximum = (tileFiles.Length + spriteFiles.Length + objectFiles.Length + roomFiles.Length);

            foreach (String tileFile in tileFiles)
            {
              ip.progressBarLoad.Value++;
              if (Path.GetExtension(tileFile) != "")
            continue;

              try
              {
            Tile t = new Tile();
            t.LoadFromFile(tileFile);
            dummyPack.Add(t);

            Bitmap rep = ResizeBitmap(t.RenderToBitmap(dummyPack), 4.0f);

            ce.tilesCache.Items.Add(t.getUID().ToString(), t.Name, rep);

            ImageListViewItem ilvi = ce.tilesCache.Items[ce.tilesCache.Items.Count - 1];
            ilvi.Tag = tileFile;
              }
              catch (System.Exception ex)
              {
            Console.WriteLine(ex.Message);
              }

              ce.tilesCache.Sort();
            }

            foreach (String spriteFile in spriteFiles)
            {
              ip.progressBarLoad.Value++;
              if (Path.GetExtension(spriteFile) != "")
            continue;

              try
              {
            Sprite s = new Sprite();
            s.LoadFromFile(spriteFile);

            Bitmap rep = ResizeBitmap(s.RenderToBitmap(dummyPack), 3.0f);
            dummyPack.Add(s);

            ce.spriteCache.Items.Add(s.getUID().ToString(), s.Name, rep);

            ImageListViewItem ilvi = ce.spriteCache.Items[ce.spriteCache.Items.Count - 1];
            ilvi.Tag = spriteFile;
              }
              catch (System.Exception ex)
              {
            Console.WriteLine(ex.Message);
              }

              ce.spriteCache.Sort();
            }

            foreach (String roomFile in roomFiles)
            {
              ip.progressBarLoad.Value++;
              if (Path.GetExtension(roomFile) != "")
            continue;

              try
              {
            Room r = new Room();
            r.LoadFromFile(roomFile);

            Bitmap rep = r.RenderToBitmap(dummyPack);
            dummyPack.Add(r);

            ce.roomCache.Items.Add(r.getUID().ToString(), r.Name, rep);

            ImageListViewItem ilvi = ce.roomCache.Items[ce.roomCache.Items.Count - 1];
            ilvi.Tag = roomFile;
              }
              catch (System.Exception ex)
              {
            Console.WriteLine(ex.Message);
              }

              ce.roomCache.Sort();
            }

            foreach (String objectFile in objectFiles)
            {
              ip.progressBarLoad.Value++;
              if (Path.GetExtension(objectFile) != "")
            continue;

              try
              {
            StateObject ob = new StateObject();
            ob.LoadFromFile(objectFile);

            Bitmap rep = ob.RenderToBitmap(dummyPack);
            dummyPack.Add(ob);

            ce.objectCache.Items.Add(ob.getUID().ToString(), ob.Name, rep);

            ImageListViewItem ilvi = ce.objectCache.Items[ce.objectCache.Items.Count - 1];
            ilvi.Tag = objectFile;
              }
              catch (System.Exception ex)
              {
            Console.WriteLine(ex.Message);
              }

              ce.objectCache.Sort();
            }

            ip.Close();

            Cursor.Current = Cursors.Default;
            ce.Show();

            GC.Collect();
              }
        }
예제 #5
0
파일: Room.cs 프로젝트: ishani/InSiDe
 /**
  * set individual tile at x,y
  */
 public void SetTile(Int32 x, Int32 y, Tile t)
 {
     layout[x, y] = t.getUID();
 }