Пример #1
0
        /// <summary>
        /// Update all tiles.
        /// </summary>
        public void UpdateTiles()
        {
            // Calculate the sectors range to draw
            int tileAvg = m_TileCount / 2;
            // Margin to point center
            int relativePosX = (int)Math.Round((m_ViewPoint.PosX % 192) * m_TileSize.Width / 192.0 + (m_ViewPoint.PosX < 0 ? m_TileSize.Width : 0));
            int relativePosY = (int)Math.Round((m_ViewPoint.PosY % 192) * m_TileSize.Height / 192.0 + (m_ViewPoint.PosY < 0 ? m_TileSize.Height : 0));
            int marginX      = (int)Math.Round(m_TileSize.Width / 2.0 - m_TileSize.Width - relativePosX);
            int marginY      = (int)Math.Round(m_TileSize.Height / 2.0 - m_TileSize.Height * 2 + relativePosY);

            this.InvokeIfRequired(() => {
                // Locate/Resize all sectors involved
                int i = 0;
                for (int sectorY = tileAvg + m_ViewPoint.ySector; sectorY >= -tileAvg + m_ViewPoint.ySector; sectorY--)
                {
                    int j = 0;
                    for (int sectorX = -tileAvg + m_ViewPoint.xSector; sectorX <= tileAvg + m_ViewPoint.xSector; sectorX++)
                    {
                        xMapTile sector      = null;
                        string path          = string.Format(m_FilePath, sectorX, sectorY);
                        Point sectorLocation = new Point(j * m_TileSize.Width + marginX, i * m_TileSize.Height + marginY);

                        // Check if has been loaded
                        if (m_Sectors.TryGetValue(path, out sector))
                        {
                            // Just update it if changes
                            if (sector.Location.X != sectorLocation.X || sector.Location.Y != sectorLocation.Y)
                            {
                                sector.Location = sectorLocation;
                            }
                            if (m_TileSize.Width != sector.Size.Width || m_TileSize.Height != sector.Size.Height)
                            {
                                sector.Size = m_TileSize;
                            }
                            sector.Visible = true;
                        }
                        else
                        {
                            // Create tile
                            sector             = new xMapTile(sectorX, sectorY);
                            sector.Name        = path;
                            sector.Size        = m_TileSize;
                            sector.Location    = sectorLocation;
                            sector.MouseClick += new MouseEventHandler(this.xMapTile_MouseClick);
                            // Try to Load
                            sector.LoadAsyncTile(path, m_TileSize);
                            // Add
                            m_Sectors[path] = sector;
                            this.Controls.Add(sector);
                            sector.SendToBack();
                        }
                        j++;
                    }
                    i++;
                }
            });
        }
Пример #2
0
 private void xMapTile_MouseClick(object sender, MouseEventArgs e)
 {
     if (e.Button == MouseButtons.Left)
     {
         xMapTile t = (xMapTile)sender;
         if (InfoManager.inGame)
         {
             Bot.Get.MoveTo(GetCoord(new Point(t.Location.X + e.Location.X, t.Location.Y + e.Location.Y)));
         }
     }
 }