Ejemplo n.º 1
0
        public void AddSprite(Sprite s, Int32 x, Int32 y, float t, bool additive)
        {
            // shift into object space
              const Int32 MidPoint = (Constants.RoomSize * Constants.TileSize) / 2;
              x = (-MidPoint + (Constants.TileSize / 2)) + x;
              y = (MidPoint - (Constants.TileSize / 2)) - (y - Constants.TileSize);

              SpriteLayer sl = new SpriteLayer();
              sl.uid = s.getUID();
              sl.x = (byte)x;
              sl.y = (byte)y;
              sl.trans = (byte)(t * 255.0f);
              sl.glow = (byte)(additive ? 1 : 0);

              layers.Add(sl);
        }
Ejemplo n.º 2
0
        public override void Process(String compName, ResourcePack rp)
        {
            const Int32 MidPoint = (Constants.RoomSize * Constants.TileSize) / 2;
              Point assembleAtPoint;

              Bitmap edgedBitmap = new Bitmap(TargetBitmap, TargetBitmap.Width + Constants.TileSize, TargetBitmap.Height + Constants.TileSize);
              edgedBitmap.MakeTransparent();

              using (Graphics edgeGfx = Graphics.FromImage(edgedBitmap))
              {
            edgeGfx.Clear(Color.Transparent);

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

              foreach (ExtractedObject eo in ObjectExtents)
              {
            StateObject ob = new StateObject();
            ob.Name = compName;

            if (alignToCenter.Checked)
              assembleAtPoint = new Point(MidPoint - eo.bounds.Width / 2, MidPoint - eo.bounds.Height / 2);
            else
              assembleAtPoint = new Point(0, 0);

            foreach (Rectangle r in eo.slices)
            {
              Sprite b = new Sprite();

              b.SliceFromBitmap(edgedBitmap, r.Left, r.Top, 128);
              b.Name = compName;

              rp.Add(b);
              ob.AddSprite(b, assembleAtPoint.X + (r.Left - eo.bounds.Left), assembleAtPoint.Y + (r.Top - eo.bounds.Top), 1.0f, false);
            }

            rp.Add(ob);
              }
        }
Ejemplo n.º 3
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);
              if (bgTrans.Checked)
            edgedBitmap.MakeTransparent();

              using (Graphics edgeGfx = Graphics.FromImage(edgedBitmap))
              {
            if (bgTrans.Checked)
              edgeGfx.Clear(Color.Transparent);
            else
              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)
            {
              Sprite b = new Sprite();

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

              rp.Add(b);

              curX += Constants.TileSize + gapX;
            }

            curX = 0;
            curY += Constants.TileSize + gapY;
              }
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
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();
              }
        }