Beispiel #1
0
        private void panelMap_Paint(object sender, PaintEventArgs e)
        {
            if (selectMapId == 0 || selectMapSize.Width == 0 || selectMapSize.Height == 0)
            {
                return;
            }

            if (showSkin)
            {
                for (int i = baseOffside.X / 192; i < (baseOffside.X + panelMap.Width) / 192 + 1; i++)
                {
                    for (int j = baseOffside.Y / 192; j < (baseOffside.Y + panelMap.Height) / 192 + 1; j++)
                    {
                        string imagepath = string.Format("res/map/{0}/{1}_{2}.jpg", selectFolder, j, i);
                        //if (File.Exists(imagepath))
                        {
                            Image image = MapPainter.GetNetImage(imagepath);
                            e.Graphics.DrawImage(image, i * 192 - baseOffside.X, j * 192 - baseOffside.Y);
                            image.Dispose();
                        }
                    }
                }
            }

            if (showBarrier) //是否显示阻挡
            {
                int col = (int)Math.Floor((double)selectMapSize.Width / 48);

                int xoff = baseOffside.X % 48;
                int yoff = baseOffside.Y % 34;
                for (int x = -xoff; x < panelMap.Width + xoff; x += 48)
                {
                    for (int y = -yoff; y < panelMap.Width + yoff; y += 34)
                    {
                        Point tile = TilePixelConvertor.PixelToTile(x + baseOffside.X, y + baseOffside.Y);
                        int   val  = 1;
                        if (tile.Y >= 0 && tile.X >= 0)
                        {
                            if (tile.Y * col + tile.X >= blockInfos.Count)
                            {
                                val = 0;
                            }
                            else
                            {
                                val = blockInfos[tile.Y * col + tile.X];
                            }
                        }
                        MapPainter.DrawRectTile(e.Graphics, x, y, val);

/*                        tile = TilePixelConvertor.PixelToTile(i + 32, j + 16);
 *                      val = 1;
 *                      if (tile.Y >= 0 && tile.X >= 0)
 *                      {
 *                          if (tile.Y * col + tile.X >= blockInfos.Count)
 *                              val = 2;
 *                          else
 *                              val = blockInfos[tile.Y * col + tile.X];
 *                      }
 *                      MapPainter.DrawRectTile(e.Graphics, i - baseOffside.X + 32, j - baseOffside.Y + 16, val);*/
                    }
                }
            }

            if (false && showGridLine)
            { //show region
                int col = (int)Math.Round((double)selectMapSize.Width / 64);

                OldDataPack pack         = OldDataPackBook.GetPack("cfg_map_region");
                int         mapidindex   = pack.GetPackIndexByName("mapid");
                int         mapminxindex = pack.GetPackIndexByName("min_x");
                int         mapminyindex = pack.GetPackIndexByName("min_y");
                int         mapmaxxindex = pack.GetPackIndexByName("max_x");
                int         mapmaxyindex = pack.GetPackIndexByName("max_y");
                int         typeindex    = pack.GetPackIndexByName("type");

                List <List <String> > regions = new List <List <string> >();
                foreach (List <String> rect in pack.data.Values)
                {
                    if (int.Parse(rect[mapidindex]) == selectMapId)
                    {
                        regions.Add(rect);
                    }
                }

                Dictionary <int, bool> showname = new Dictionary <int, bool>();
                for (int i = baseOffside.X / 64 * 64; i < baseOffside.X + panelMap.Width; i += 64)
                {
                    for (int j = baseOffside.Y / 32 * 32; j < baseOffside.Y + panelMap.Height; j += 32)
                    {
                        foreach (List <String> region in regions)
                        {
                            Point tile = TilePixelConvertor.PixelToTile(i, j);
                            if (TilePixelConvertor.InRegion(int.Parse(region[mapminxindex]), int.Parse(region[mapminyindex]), int.Parse(region[mapmaxxindex]), int.Parse(region[mapmaxyindex]), tile.X, tile.Y))
                            {
                                MapPainter.DrawCircleRegion(e.Graphics, i - baseOffside.X, j - baseOffside.Y, int.Parse(region[typeindex]));

                                if (tile.X >= (int.Parse(region[mapminxindex]) + int.Parse(region[mapmaxxindex])) / 2 && tile.Y >= (int.Parse(region[mapminyindex]) + int.Parse(region[mapmaxyindex])) / 2)
                                {
                                    if (!showname.ContainsKey(int.Parse(region[0])))
                                    {
                                        Font fontSong = new Font("宋体", 14, FontStyle.Bold);
                                        e.Graphics.DrawString(region[1], fontSong, Brushes.Black, i - baseOffside.X - 10, j - baseOffside.Y - 4);
                                        fontSong.Dispose();
                                        showname.Add(int.Parse(region[0]), true);
                                    }
                                }
                            }

                            tile = TilePixelConvertor.PixelToTile(i + 32, j + 16);
                            if (TilePixelConvertor.InRegion(int.Parse(region[mapminxindex]), int.Parse(region[mapminyindex]), int.Parse(region[mapmaxxindex]), int.Parse(region[mapmaxyindex]), tile.X, tile.Y))
                            {
                                MapPainter.DrawCircleRegion(e.Graphics, i - baseOffside.X + 32, j - baseOffside.Y + 16, int.Parse(region[typeindex]));
                            }
                        }
                    }
                }
            }

            if (showGridLine) //是否显示网格
            {
                int xoff = baseOffside.X % 48;
                int yoff = baseOffside.Y % 34;
                for (int i = 1; i * 48 - xoff < panelMap.Width; ++i)
                {
                    e.Graphics.DrawLine(Pens.DarkGray, i * 48 - xoff, 0, i * 48 - xoff, panelMap.Height);
                }
                for (int i = 1; i * 34 - yoff < panelMap.Height; ++i)
                {
                    e.Graphics.DrawLine(Pens.DarkGray, 0, i * 34 - yoff, panelMap.Width, i * 34 - yoff);
                }
            }

            if (false)
            {//传送点
                OldDataPack pack         = OldDataPackBook.GetPack("cfg_map_rect");
                int         frommapindex = pack.GetPackIndexByName("from_map");
                int         fromxindex   = pack.GetPackIndexByName("from_x");
                int         fromyindex   = pack.GetPackIndexByName("from_y");
                int         tomapindex   = pack.GetPackIndexByName("to_map");

                Font fontSong = new Font("宋体", 11, FontStyle.Bold);

                foreach (List <String> rect in pack.data.Values)
                {
                    int frommap = int.Parse(rect[frommapindex]);
                    int fromx   = int.Parse(rect[fromxindex]);
                    int fromy   = int.Parse(rect[fromyindex]);
                    int tomap   = int.Parse(rect[tomapindex]);

                    Rectangle dest = new Rectangle(baseOffside.X, baseOffside.Y, panelMap.Width, panelMap.Height);
                    Point     mpos = TilePixelConvertor.TileToPixel(fromx, fromy);

                    if (selectMapId == frommap && dest.Contains(mpos))
                    {
                        Image body = Image.FromFile("icons/rect.png");
                        e.Graphics.DrawImage(body, mpos.X - baseOffside.X - body.Width / 2, mpos.Y - baseOffside.Y - body.Height / 2, body.Width, body.Height);
                        body.Dispose();

                        DataPack packm     = DataPackBook.GetPack("map");
                        int      nameindex = packm.GetPackIndexByName("name");
                        String   name      = packm.data[tomap][nameindex];
                        e.Graphics.DrawString(name, fontSong, Brushes.Black, mpos.X - baseOffside.X - 10, mpos.Y - baseOffside.Y - 4);
                        e.Graphics.DrawString(name, fontSong, Brushes.Lime, mpos.X - baseOffside.X - 11, mpos.Y - baseOffside.Y - 5);
                    }
                }

                fontSong.Dispose();
            }

            if (false && showPlant) //显示植物
            {
                OldDataPack pack         = OldDataPackBook.GetPack("cfg_map_plant");
                int         idindex      = pack.GetPackIndexByName("id");
                int         mapidindex   = pack.GetPackIndexByName("mapid");
                int         plantidindex = pack.GetPackIndexByName("plantid");
                int         xindex       = pack.GetPackIndexByName("x");
                int         yindex       = pack.GetPackIndexByName("y");

                OldDataPack mpack     = OldDataPackBook.GetPack("cfg_plant");
                int         bodyindex = mpack.GetPackIndexByName("body");

                Font fontSong = new Font("宋体", 11, FontStyle.Bold);
                foreach (List <String> plant in pack.data.Values)
                {
                    int id      = int.Parse(plant[idindex]);
                    int map     = int.Parse(plant[mapidindex]);
                    int x       = int.Parse(plant[xindex]);
                    int y       = int.Parse(plant[yindex]);
                    int plantid = int.Parse(plant[plantidindex]);

                    Rectangle dest = new Rectangle(baseOffside.X, baseOffside.Y, panelMap.Width, panelMap.Height);

                    Point mpos = TilePixelConvertor.TileToPixel(x, y);
                    if (map == selectMapId && dest.Contains(mpos))
                    {
                        string bodyurl   = mpack.data[plantid][bodyindex];
                        String imagepath = String.Format("res/entity/units/plant/{0}.png", bodyurl);
                        //Image body = MapPainter.GetNetImage(imagepath);
                        // string imagepath = string.Format("res/map/{0}/{1}_{2}.jpg", selectFolder, j, i);
                        // if (File.Exists(imagepath))
                        {
                            Image image = MapPainter.GetNetImage(imagepath); //new Bitmap(imagepath);
                            e.Graphics.DrawImage(image, mpos.X - baseOffside.X - image.Width / 2, mpos.Y - baseOffside.Y - image.Height, image.Width, image.Height);
                            //body.Dispose();
                            image.Dispose();
                        }

                        e.Graphics.DrawString(id.ToString(), fontSong, Brushes.Black, mpos.X - baseOffside.X - 10, mpos.Y - baseOffside.Y - 4);
                        e.Graphics.DrawString(id.ToString(), fontSong, Brushes.White, mpos.X - baseOffside.X - 11, mpos.Y - baseOffside.Y - 5);
                    }
                }

                fontSong.Dispose();
            }

            if (showMonster) //是否绘制怪物
            {
                int monnum = 0;

                DataPack pack                = DataPackBook.GetPack("map_monster");
                int      idindex             = pack.GetPackIndexByName("id");
                int      mapidindex          = pack.GetPackIndexByName("map_id");
                int      monstergroupidindex = pack.GetPackIndexByName("monster_group_id");
                int      xindex              = pack.GetPackIndexByName("x");
                int      yindex              = pack.GetPackIndexByName("y");

                DataPack mpack            = DataPackBook.GetPack("monster");
                int      groupindex       = mpack.GetPackIndexByName("group_id");
                int      monsterbodyindex = mpack.GetPackIndexByName("monster_body");
                int      avatarbodyindex  = mpack.GetPackIndexByName("avatar_body");

                Font fontSong = new Font("宋体", 11, FontStyle.Bold);
                foreach (List <String> mapmonster in pack.data.Values)
                {
                    int id             = int.Parse(mapmonster[idindex]);
                    int map            = int.Parse(mapmonster[mapidindex]);
                    int x              = int.Parse(mapmonster[xindex]);
                    int y              = int.Parse(mapmonster[yindex]);
                    int monstergroupid = int.Parse(mapmonster[monstergroupidindex]);

                    Rectangle dest = new Rectangle(baseOffside.X, baseOffside.Y, panelMap.Width, panelMap.Height);

                    Point mpos = TilePixelConvertor.TileToPixel(x, y);
                    if (map == selectMapId && dest.Contains(mpos))
                    {
                        foreach (List <String> monster in mpack.data.Values)
                        {
                            int groupid = int.Parse(monster[groupindex]);
                            if (groupid == monstergroupid)
                            {
                                string monsterbodyurl = monster[monsterbodyindex];
                                string avatarbodyurl  = monster[avatarbodyindex];
                                string bodyurl        = "";
                                if (monsterbodyurl.Length > 0)
                                {
                                    bodyurl = monsterbodyurl;
                                }
                                else
                                {
                                    bodyurl = avatarbodyurl;
                                }
                                String imagepath = String.Format("res/entity/monster/{0}.png", bodyurl);
                                Image  body      = MapPainter.GetNetImage(imagepath); //new Bitmap(imagepath);//
                                //if (File.Exists(imagepath))
                                {
                                    e.Graphics.DrawImage(body, mpos.X - baseOffside.X - body.Width / 2, mpos.Y - baseOffside.Y - body.Height, body.Width, body.Height);
                                    body.Dispose();
                                }
                                //body.Dispose();

                                e.Graphics.DrawString(id.ToString(), fontSong, Brushes.Black, mpos.X - baseOffside.X - 10, mpos.Y - baseOffside.Y - 4);
                                e.Graphics.DrawString(id.ToString(), fontSong, Brushes.White, mpos.X - baseOffside.X - 11, mpos.Y - baseOffside.Y - 5);

                                monnum++;
                                break;
                            }
                        }
                    }
                }

                String moncount = String.Format("当前屏怪物数:{0}", monnum);
                e.Graphics.DrawString(moncount, fontSong, Brushes.Black, 4, panelMap.Height - 19);
                e.Graphics.DrawString(moncount, fontSong, Brushes.White, 3, panelMap.Height - 20);

                fontSong.Dispose();
            }

            if (showNpc)
            {
                DataPack pack       = DataPackBook.GetPack("npc");
                int      idindex    = pack.GetPackIndexByName("id");
                int      mapidindex = pack.GetPackIndexByName("mapid");
                int      xindex     = pack.GetPackIndexByName("x");
                int      yindex     = pack.GetPackIndexByName("y");
                int      nameindex  = pack.GetPackIndexByName("name");
                int      bodyindex  = pack.GetPackIndexByName("body");

                Font fontSong = new Font("宋体", 11, FontStyle.Bold);
                foreach (List <String> npc in pack.data.Values)
                {
                    int    id      = int.Parse(npc[idindex]);
                    string map     = npc[mapidindex];
                    int    x       = int.Parse(npc[xindex]);
                    int    y       = int.Parse(npc[yindex]);
                    string bodyurl = npc[bodyindex];
                    string name    = npc[nameindex];

                    Rectangle dest = new Rectangle(baseOffside.X, baseOffside.Y, panelMap.Width, panelMap.Height);

                    Point mpos = TilePixelConvertor.TileToPixel(x, y);
                    if (map.Contains(selectMapId.ToString()) && dest.Contains(mpos))
                    {
                        String imagepath = String.Format("res/entity/npc/{0}.png", bodyurl);
                        Image  body      = MapPainter.GetNetImage(imagepath);
                        //if (File.Exists(imagepath))
                        {
                            //   Image body =new Bitmap(imagepath);
                            e.Graphics.DrawImage(body, mpos.X - baseOffside.X - body.Width / 2, mpos.Y - baseOffside.Y - body.Height, body.Width, body.Height);
                            body.Dispose();
                        }

                        e.Graphics.DrawString(id + "." + name, fontSong, Brushes.Black, mpos.X - baseOffside.X - 10, mpos.Y - baseOffside.Y - 4);
                        e.Graphics.DrawString(id + "." + name, fontSong, Brushes.White, mpos.X - baseOffside.X - 11, mpos.Y - baseOffside.Y - 5);
                    }
                }

                fontSong.Dispose();
            }

            e.Graphics.FillRectangle(Brushes.Gray, 0, 0, 4, panelMap.Height);
            e.Graphics.FillRectangle(Brushes.Gray, 0, panelMap.Height - 4, panelMap.Width, 4);
            e.Graphics.FillRectangle(Brushes.Orange, 0, baseOffside.Y * panelMap.Height / selectMapSize.Height, 4, panelMap.Height * panelMap.Height / selectMapSize.Height);
            e.Graphics.FillRectangle(Brushes.Orange, baseOffside.X * panelMap.Width / selectMapSize.Width, panelMap.Height - 4, panelMap.Width * panelMap.Width / selectMapSize.Width, 4);
        }
Beispiel #2
0
        private void doubleBufferedPanel1_Paint(object sender, PaintEventArgs e)
        {
            int mid1 = GetData("m1");
            int mid2 = GetData("m2");

            if (mid1 == 0)
            {
                mid1 = mid2;
            }

            if (mid2 == 0)
            {
                mid2 = mid1;
            }


            Point pos = TilePixelConvertor.TileToPixel(GetData("x1"), GetData("y1"));

            for (int i = -1; i <= 1; i++)
            {
                for (int j = -1; j <= 1; j++)
                {
                    String imagepath = String.Format("res/map/{0}/{1}_{2}.jpg", mid1, pos.Y / 300 + j, pos.X / 300 + i);

                    Image item = MapPainter.GetNetImage(imagepath);
                    //if (File.Exists(imagepath))
                    if (item != null)
                    {
                        Image image = item;// new Bitmap(imagepath);
                        e.Graphics.DrawImage(image, (i + 1) * 80, (j + 1) * 80, 80, 80);
                        image.Dispose();
                    }
                }
            }

            e.Graphics.DrawEllipse(Pens.Red, (pos.X % 80) + 80 - 15, (pos.Y % 80) + 80 - 15, 30, 30);

            pos = TilePixelConvertor.TileToPixel(GetData("x2"), GetData("y2"));

            for (int i = -1; i <= 1; i++)
            {
                for (int j = -1; j <= 1; j++)
                {
                    String imagepath = String.Format("res/map/{0}/{1}_{2}.jpg", mid2, pos.Y / 300 + j, pos.X / 300 + i);

                    Image item = MapPainter.GetNetImage(imagepath);

                    if (item != null)
                    {
                        Image image = item;// new Bitmap(imagepath);
                        e.Graphics.DrawImage(image, (i + 1) * 80 + 240, (j + 1) * 80, 80, 80);
                        image.Dispose();
                    }
                }
            }

            e.Graphics.DrawEllipse(Pens.Red, (pos.X % 80) + 80 + 240 - 15, (pos.Y % 80) + 80 - 15, 30, 30);

            Font font = new Font("宋体", 10, FontStyle.Bold);

            e.Graphics.DrawString("出发地", font, Brushes.Black, 10, 10);
            e.Graphics.DrawString("出发地", font, Brushes.White, 9, 9);

            e.Graphics.DrawString("目的地", font, Brushes.Black, 250, 10);
            e.Graphics.DrawString("目的地", font, Brushes.White, 249, 9);
            font.Dispose();
        }