예제 #1
0
        /// <summary>
        /// Creates the MapPictureBoxes for the loaded map.
        /// </summary>
        private void InitializeMap()
        {
            panel1.Controls.Clear();

            int x = 0;
            int y = 0;

            foreach (int id in _loadedMap.Tiles)
            {
                MapPictureBox box = new MapPictureBox();
                box.Size        = new Size(50, 50);
                box.Location    = new Point(x, y);
                box.MapTileID   = id;
                box.BorderStyle = BorderStyle.FixedSingle;
                box.Tag         = new int[] { x / 50, y / 50 }; //Set the int[,] coordinates; Map => tiles
                panel1.Controls.Add(box);
                if (x == (_loadedMap.Width * 50) - 50)
                {
                    x  = 0;
                    y += 50;
                }
                else
                {
                    x += 50;
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Loads the available tiles.
        /// </summary>
        private void LoadMapTiles()
        {
            int x = 0;
            int y = 0;

            foreach (MapTile tile in Tiles.MapTiles)
            {
                MapPictureBox box = new MapPictureBox();
                box.MapTileID = tile.ID;
                box.Size      = new Size(50, 50);
                box.Location  = new Point(x, y);
                box.Click    += new EventHandler(SelectMapPictureBoxes_Click);
                selectPanel.Controls.Add(box);

                if (x == 150)
                {
                    x  = 0;
                    y += 50;
                }
                else
                {
                    x += 50;
                }
            }
        }
예제 #3
0
        /// <summary>
        /// Click event for the MapPictureBoxes which hold the tiles of the currently loaded map.
        /// Places the selected tile on the clicked MapPictureBox.
        /// </summary>
        private void MapPictureBoxes_Click(object sender, EventArgs e)
        {
            MapPictureBox clickedBox = (MapPictureBox)sender;

            if (_selectedMapPictureBox != null)
            {
                clickedBox.MapTileID = _selectedMapPictureBox.MapTileID;
            }
        }
예제 #4
0
        /// <summary>
        /// Click event for the MapPictureBoxes which hold the available tiles.
        /// Selects the clicked tile.
        /// </summary>
        private void SelectMapPictureBoxes_Click(object sender, EventArgs e)
        {
            if (_selectedMapPictureBox != null)
            {
                _selectedMapPictureBox.BorderStyle = BorderStyle.None;
            }

            MapPictureBox clickedBox = (MapPictureBox)sender;

            _selectedMapPictureBox = clickedBox;
            clickedBox.BorderStyle = BorderStyle.Fixed3D;
        }
예제 #5
0
        /// <summary>
        /// Fills the MapPictureBoxes even if the left mouse button is held down.
        /// </summary>
        private void MapPictureBox_MouseMove(object sender, MouseEventArgs e)
        {
            MapPictureBox box = (MapPictureBox)sender;

            if (e.Button == MouseButtons.Left)
            {
                Point     pt = box.PointToClient(Cursor.Position);
                Rectangle rc = box.ClientRectangle;
                if (rc.Contains(pt))
                {
                    if (_selectedMapPictureBox != null)
                    {
                        box.MapTileID = _selectedMapPictureBox.MapTileID;
                    }
                }
            }

            box.Capture = false;
        }