public Map(Map mapCopy)
        {
            TileTypes = new BindingList<TileType>();

            foreach (TileType tileType in mapCopy.TileTypes)
            {
                TileTypes.Add(new TileType(tileType));
            }

            TilesetTexture = mapCopy.TilesetTexture;

            CustomLayer = new TileLayer(mapCopy.CustomLayer);
            TileLayers = new List<TileLayer>();

            foreach (TileLayer layer in mapCopy.TileLayers)
                TileLayers.Add(new TileLayer(layer));
        }
        public void DrawMap(Map map, Tool currentTool, Rectangle toolPreviewRect, Rectangle viewingRectangle, TileType tileType, bool showOtherLayers, bool showCollisionLayer, bool showGrid, bool renderDisplay)
        {
            Vector3 previewCamera = new Vector3(-viewingRectangle.X, -viewingRectangle.Y, 0f);

            spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, null, null, null, null, Matrix.CreateTranslation(previewCamera));

            spriteBatch.GraphicsDevice.Clear(displayClearColor);

            if (renderDisplay)
            {
                DrawLayersWithToolPreviews(map, currentTool, toolPreviewRect, viewingRectangle, tileType, showOtherLayers, showCollisionLayer);

                if (showGrid)
                    DrawGrid(map.TileSize, viewingRectangle);
            }

            spriteBatch.End();
        }
        public void DrawTileset(Map map, Rectangle viewingRectangle, bool showGrid, bool renderDisplay)
        {
            Vector3 tilesetCamera = new Vector3(-viewingRectangle.X, -viewingRectangle.Y, 0f);

            spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, null, null, null, null, Matrix.CreateTranslation(tilesetCamera));

            spriteBatch.GraphicsDevice.Clear(displayClearColor);

            if (renderDisplay)
            {
                spriteBatch.Draw(map.TilesetTexture, Vector2.Zero, Color.White);

                if (showGrid)
                    DrawGrid(map.TileSize, viewingRectangle);

                Utility.DrawRectangle(spriteBatch, 3, selectorTileset.Rectangle, Color.Red); // Tileset selector border
            }

            spriteBatch.End();
        }
        private void DrawLayersWithToolPreviews(Map map, Tool currentTool, Rectangle toolPreviewRect, Rectangle viewingRectangle, TileType tileType, bool showOtherLayers, bool showCollisionLayer)
        {
            Rectangle currentViewingRectangle = new Rectangle(viewingRectangle.X / map.TileSize, viewingRectangle.Y / map.TileSize, viewingRectangle.Width / map.TileSize + 3, viewingRectangle.Height / map.TileSize + 3); // Draw a couple more just in case

            bool isCustomTile = tileType.Identifier != 0;

            foreach (TileLayer layer in map.TileLayers)
            {
                bool isLayerActive = map.ActiveLayerIndex == map.TileLayers.IndexOf(layer);

                if (isLayerActive)
                {
                    if (!isCustomTile)
                    {
                        currentTool.DrawRegularTilePreview(spriteBatch, map.TilesetTexture, toolPreviewRect, selectorTileset.Rectangle);
                    }

                    layer.Draw(spriteBatch, toolPreviewRect, !isCustomTile, currentViewingRectangle); // Draws the layer and skips tiles covered by the tool preview
                }
                else
                {
                    if (showOtherLayers)
                    {
                        layer.Draw(spriteBatch, currentViewingRectangle);
                    }
                }
            }

            if (isCustomTile)
                currentTool.DrawCustomTilePreview(spriteBatch, toolPreviewRect, tileType);

            if (showCollisionLayer)
                map.CustomLayer.Draw(spriteBatch, toolPreviewRect, isCustomTile, currentViewingRectangle); // Draw the collision layer and skip tiles that are covered by the tool preview

            if (toolPreviewRect != Rectangle.Empty)
                Utility.DrawRectangle(spriteBatch, 3, toolPreviewRect, Color.Orange); // Draw border around selector
        }
        public Map Undo(Map activeMap)
        {
            redoMap = new Map(activeMap);

            return undoMap;
        }
 public Edit(Map map)
 {
     undoMap = new Map(map);
 }