示例#1
0
文件: Form1.cs 项目: davidsiaw/kubus
        private static SimpleTile GetSelectedTile(DraggableMap dmap, int x, int y)
        {
            int tilex = x / Tile.tilesize;
            int tiley = y / Tile.tilesize;
            dmap.HighlightTile(tilex, tiley);

            Bitmap b = new Bitmap(Tile.tilesize, Tile.tilesize);
            using (Graphics g = Graphics.FromImage(b))
            {
                g.DrawImage(
                    dmap.img,
                    new Rectangle(0, 0, Tile.tilesize, Tile.tilesize),
                    new Rectangle(tilex * Tile.tilesize, tiley * Tile.tilesize, Tile.tilesize, Tile.tilesize),
                    GraphicsUnit.Pixel);
            }
            SimpleTile st = new SimpleTile(b);
            return st;
        }
示例#2
0
文件: Form1.cs 项目: davidsiaw/kubus
        private static bool InsertSimpleTile(List<BasicTileFormat> tf, Bitmap bmp, ref int curx, ref int cury, Graphics g, ref int count, SimpleTile st)
        {
            st.num = count++;

            if (curx + st.bmp.Length * Tile.tilesize > bmp.Width)
            {
                curx = 0;
                cury += Tile.tilesize;

                if (cury >= bmp.Height)
                {
                    return false;
                }
            }

            tf.Add(new BasicTileFormat()
            {
                numframes = st.bmp.Length,
                width = (float)Tile.tilesize / bmp.Size.Width,
                height = (float)Tile.tilesize / bmp.Size.Height,
                x1 = (float)curx / bmp.Size.Width,
                y1 = ((float)cury + Tile.tilesize) / bmp.Size.Height,
                x2 = ((float)curx + Tile.tilesize) / bmp.Size.Width,
                y2 = ((float)cury + Tile.tilesize) / bmp.Size.Height,
                x3 = ((float)curx + Tile.tilesize) / bmp.Size.Width,
                y3 = (float)cury / bmp.Size.Height,
                x4 = (float)curx / bmp.Size.Width,
                y4 = (float)cury / bmp.Size.Height,
            });

            foreach (Bitmap frame in st.bmp)
            {
                g.DrawImage(frame, curx, cury);
                curx += Tile.tilesize;
            }

            return true;
        }
示例#3
0
文件: Tile.cs 项目: davidsiaw/kubus
        protected Bitmap GetBitmap(byte surroundings, uint tick, Rectangle[] corner, byte[,] posAndMaskToTile)
        {
            if ((surroundings & 0xf0) == 0)
            {
                surroundings &= 0xf0;
            }

            tick %= 4;

            var ats = new AutoTileSep()
            {
                tr = posAndMaskToTile[
                        (int)SubTilePos.TopLeft,
                        getCornerMask(SubTilePos.TopLeft, surroundings)],
                tl = posAndMaskToTile[
                        (int)SubTilePos.TopRight,
                        getCornerMask(SubTilePos.TopRight, surroundings)],
                br = posAndMaskToTile[
                        (int)SubTilePos.BottomLeft,
                        getCornerMask(SubTilePos.BottomLeft, surroundings)],
                bl = posAndMaskToTile[
                        (int)SubTilePos.BottomRight,
                        getCornerMask(SubTilePos.BottomRight, surroundings)]
            };

            if (!tileCache.ContainsKey(surroundings))
            {
                tileCache[surroundings] = ats;
            }

            if (!bitmapCache.ContainsKey(ats))
            {
                bitmapCache[ats] = new SimpleTile(null);
            }

            if (bitmapCache[ats].bmp[tick] == null)
            {
                Bitmap b = new Bitmap(Tile.tilesize, Tile.tilesize);
                using (Graphics g = Graphics.FromImage(b))
                {
                    g.DrawImage(
                        rawtiles[ats.tr].GetBitmap(surroundings, tick),
                        corner[(int)SubTilePos.TopLeft],
                        corner[(int)SubTilePos.TopLeft],
                        GraphicsUnit.Pixel);

                    g.DrawImage(
                        rawtiles[ats.br].GetBitmap(surroundings, tick),
                        corner[(int)SubTilePos.BottomLeft],
                        corner[(int)SubTilePos.BottomLeft],
                        GraphicsUnit.Pixel);

                    g.DrawImage(
                        rawtiles[ats.bl].GetBitmap(surroundings, tick),
                        corner[(int)SubTilePos.BottomRight],
                        corner[(int)SubTilePos.BottomRight],
                        GraphicsUnit.Pixel);

                    g.DrawImage(
                        rawtiles[ats.tl].GetBitmap(surroundings, tick),
                        corner[(int)SubTilePos.TopRight],
                        corner[(int)SubTilePos.TopRight],
                        GraphicsUnit.Pixel);
                }
                bitmapCache[ats].bmp[tick] = b;
            }

            return bitmapCache[tileCache[surroundings]].bmp[tick];
        }
示例#4
0
文件: Tile.cs 项目: davidsiaw/kubus
 public AutoTile94(SimpleTile[] simpletiles, int[] basicTiles)
     : base(13)
 {
     for (int i = 0; i < rawtiles.Length; i++)
     {
         rawtiles[i] = simpletiles[basicTiles[i]];
     }
 }
示例#5
0
文件: Tile.cs 项目: davidsiaw/kubus
 public AutoTile94()
     : base(13)
 {
     for (int i = 0; i < rawtiles.Length; i++)
     {
         rawtiles[i] = new SimpleTile(new Bitmap(Tile.tilesize, Tile.tilesize));
     }
 }
示例#6
0
文件: Form1.cs 项目: davidsiaw/kubus
        private void OpenFile(string filename)
        {
            var img = new Bitmap(filename);
            img.SetResolution(96, 96);

            string name = Path.GetFileNameWithoutExtension(filename);
            tc_topRight.TabPages.Add(name, name);

            DraggableMap dm = new DraggableMap();
            tc_topRight.TabPages[name].Controls.Add(dm);

            Button basicTile = new Button();
            basicTile.Click += new EventHandler(basicTile_Click);
            basicTile.Text = "Create Basic Tile";
            basicTile.Dock = DockStyle.Bottom;

            tc_topRight.TabPages[name].Controls.Add(basicTile);

            Button autoTile12 = new Button();
            autoTile12.Click += new EventHandler((obj, evt) => {
                AutoTile12 at12 = new AutoTile12();
                DraggableMap dmap = ((Button)obj).Tag as DraggableMap;

                int x, y;
                dmap.GetHighlightedTile(out x, out y);

                for (int i = 0; i < AutoTile12.tileToRawTileIndex.Length; i++)
                {
                    Rectangle rect = AutoTile12.tileToRawTileIndex[i];
                    SimpleTile st = GetSelectedTile(dmap, rect.X + x * Tile.tilesize, rect.Y + y * Tile.tilesize);
                    at12.rawtiles[i] = st;
                }

                AddAutotile12(at12, at12);
            });
            autoTile12.Tag = dm;
            autoTile12.Text = "Create Autotile";
            autoTile12.Dock = DockStyle.Bottom;
            autoTile12.Enabled = false;

            tc_topRight.TabPages[name].Controls.Add(autoTile12);

            dm.map = new Tile[img.Width / Tile.tilesize, img.Height / Tile.tilesize, 1];
            dm.img = img;
            dm.Dock = DockStyle.Fill;
            dm.LeftClick += new Action<DraggableMap, MouseEventArgs>((dmap, evt) =>
            {
                int x, y;
                dmap.GetMapPos(evt, out x, out y);

                SimpleTile st = GetSelectedTile(dmap, x, y);

                currentTile = st;

                if (dmap.highlightwidth == 3 && dmap.highlightheight == 4)
                {
                    autoTile12.Enabled = true;
                }
                else
                {
                    autoTile12.Enabled = false;
                }
            });
            dm.LeftClickDrag += new Action<DraggableMap, MouseEventArgs>((dmap, evt) =>
            {
                int x, y;
                dmap.GetMapPos(evt, out x, out y);

                int tilex = x / Tile.tilesize;
                int tiley = y / Tile.tilesize;

                int htilex, htiley;
                dmap.GetHighlightedTile(out htilex, out htiley);

                dmap.HighlightTile(Math.Min(tilex, htilex), Math.Min(tiley, htiley));

                int dx = Math.Max(Math.Abs(tilex - htilex + 1), 1);
                int dy = Math.Max(Math.Abs(tiley - htiley + 1), 1);

                dmap.highlightwidth = dx;
                dmap.highlightheight = dy;

                if (dx == 3 && dy == 4)
                {
                    autoTile12.Enabled = true;
                }
                else
                {
                    autoTile12.Enabled = false;
                }

            });
        }
示例#7
0
文件: Form1.cs 项目: davidsiaw/kubus
 private void AddSimpleTile(SimpleTile basicTile)
 {
     RadioButton btn = new RadioButton();
     btn.Appearance = Appearance.Button;
     btn.Size = new System.Drawing.Size(40, 40);
     btn.Image = basicTile.GetBitmap(0, 0);
     btn.Tag = basicTile;
     btn.Click += new EventHandler((o, evt) =>
     {
         paintTile = (Tile)((RadioButton)o).Tag;
         populatePanel2WithTileEditor();
     });
     flow_tiles.Controls.Add(btn);
 }
示例#8
0
文件: Form1.cs 项目: davidsiaw/kubus
        private void AddBasicTile(SimpleTile tile)
        {
            RadioButton btn = new RadioButton();
            btn.Appearance = Appearance.Button;
            btn.Size = new System.Drawing.Size(40, 40);
            btn.Image = tile.GetBitmap(0, 0);
            btn.Tag = tile;
            btn.Click += new EventHandler((o, evt) =>
            {
                selectedBasicTile = (SimpleTile)((RadioButton)o).Tag;
                var tp = splitContainer4.Panel2;
                tp.Controls.Clear();
                int d = Tile.tilesize / 2;

                if (selectedBasicTile is SimpleTile)
                {
                    var st = selectedBasicTile as SimpleTile;

                    for (int i = 0; i < 4; i++)
                    {
                        Rectangle r = AutoTile94.tileToRawTileIndex[i];
                        PictureBox pb = new PictureBox();
                        pb.Location = new Point(r.X / d * 20, r.Y / d * 20 + 30);
                        pb.Size = new Size(r.Width + 6, r.Height + 6);
                        pb.Image = st.bmp[i];
                        pb.Tag = new KeyValuePair<SimpleTile, int>(st, i);
                        pb.Click += new EventHandler((ob, ev) =>
                        {
                            PictureBox thepb = (PictureBox)ob;
                            KeyValuePair<SimpleTile, int> theat = (KeyValuePair<SimpleTile, int>)thepb.Tag;
                            thepb.Image = currentTile.GetBitmap(0, 0);
                            theat.Key.bmp[theat.Value] = currentTile.bmp[0];
                        });
                        tp.Controls.Add(pb);
                    }
                }

            });
            flow_basictiles.Controls.Add(btn);
        }