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();
        }
        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
        }
Ejemplo n.º 3
0
        private void InitializeToolStripCollections()
        {
            tools.Add(tspBrush, new Brush(selectorTileset));
            tools.Add(tspFill, new Fill());
            tools.Add(tspMarquee, new Marquee(selectorMarquee));

            currentTool = tools[tspBrush];
        }
Ejemplo n.º 4
0
        private void tspTool_Click(object sender, EventArgs e)
        {
            Tool.PaintType = Tool.PaintingType.None;

            var menuItem = (ToolStripButton)sender;

            currentTool = tools[menuItem];

            foreach (ToolStripButton button in tools.Keys)
                button.Checked = false;

            menuItem.Checked = true;
        }