/// <summary>
 /// Updates the canvas image at the specified position.
 /// </summary>
 /// <param name="position">Position to update the image of, in tile space.</param>
 /// <param name="tileImage">New image to be rendered at the specified position.</param>
 public void UpdateMapCanvas(Vector2I position, BitmapImage tileImage)
 {
     this.canvasImages[position.X, position.Y].Source = tileImage;
 }
        /// <summary>
        ///   Creates a new map based on the properties of the New Map window.
        /// </summary>
        public void CreateMap()
        {
            // Parse map dimensions.
            int width;
            int height;

            try
            {
                width = int.Parse(this.newMapWindow.TextBoxMapWidth.Text);
            }
            catch (FormatException)
            {
                this.ShowErrorMessage("Incorrect Width", "Please specify a map width.");
                return;
            }

            try
            {
                height = int.Parse(this.newMapWindow.TextBoxMapHeight.Text);
            }
            catch (FormatException)
            {
                this.ShowErrorMessage("Incorrect Height", "Please specify a map height.");
                return;
            }

            // Update status text.
            this.mainWindow.SetStatusText("Creating new map...");

            // Run background worker thread.
            BackgroundWorker worker = new BackgroundWorker();
            worker.DoWork += this.BackgroundCreateMap;
            worker.RunWorkerCompleted += this.BackgroundCreateMapCompleted;
            worker.ProgressChanged += this.BackgroundCreateMapProgressChanged;
            worker.WorkerReportsProgress = true;

            Vector2I mapSize = new Vector2I(width, height);
            worker.RunWorkerAsync(mapSize);
        }
        public void OnTileClicked(Vector2I position)
        {
            // Early out if no brush selected.
            if (this.currentBrush == null)
            {
                return;
            }

            // Early out if nothing changed.
            if (this.map[position].Type.Equals(this.currentBrush.Name))
            {
                return;
            }

            // Modify map model.
            this.currentDrawCommand.OldTileTypes[position] = this.map[position].Type;
            this.currentDrawCommand.NewTileTypes[position] = this.currentBrush.Name;

            this.map[position].Type = this.currentBrush.Name;

            // Update canvas.
            this.mainWindow.UpdateMapCanvas(position, this.tileImages[this.currentBrush.Name]);
        }
        /// <summary>
        /// Map tile with the specified position.
        /// </summary>
        /// <param name="position">Position of the map tile.</param>
        /// <returns>Map tile with the specified coordinates.</returns>
        public MapTile this[Vector2I position]
        {
            get
            {
                return this[position.X, position.Y];
            }

            set
            {
                this[position.X, position.Y] = value;
            }
        }