Example #1
0
        private void ctxSpriteImport_Click(object sender, EventArgs e)
        {
            Int32 uniqueAdds = 0;
              foreach (ImageListViewItem ilvi in spriteCache.SelectedItems)
              {
            String compFilename = ilvi.Tag as String;

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

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

              MessageBox.Show(String.Format("Added {0} unique sprites to the current resource pack", uniqueAdds), "InSiDe", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
Example #2
0
        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();
              }
        }