コード例 #1
0
        /*********
        ** Protected methods
        *********/
        /// <summary>Draw to the screen.</summary>
        /// <param name="spriteBatch">The sprite batch to which to draw.</param>
        protected override void Draw(SpriteBatch spriteBatch)
        {
            if (!this.DrawOverlay())
            {
                return;
            }

            int       tileSize   = Game1.tileSize;
            const int borderSize = 4;
            IDictionary <Vector2, TileDrawData> tiles = this.AggregateTileData(this.TileGroups, this.CombineOverlappingBorders);

            foreach (Vector2 tilePos in this.VisibleTiles)
            {
                Vector2 pixelPosition = tilePos * tileSize - new Vector2(Game1.viewport.X, Game1.viewport.Y);

                // draw tile data
                bool hasLeftBorder = false, hasRightBorder = false, hasTopBorder = false, hasBottomBorder = false;
                int  gridSize = this.ShowGrid || this.CurrentLayer.AlwaysShowGrid ? this.GridBorderSize : 0;
                if (tiles.TryGetValue(tilePos, out TileDrawData tile))
                {
                    // draw overlay
                    foreach (Color color in tile.Colors)
                    {
                        spriteBatch.Draw(CommonHelper.Pixel, new Rectangle((int)pixelPosition.X, (int)pixelPosition.Y, tileSize, tileSize), color * .3f);
                    }

                    // draw group borders
                    foreach (Color color in tile.BorderColors.Keys)
                    {
                        TileEdge edges = tile.BorderColors[color];

                        int leftBorderSize   = edges.HasFlag(TileEdge.Left) ? borderSize : gridSize;
                        int rightBorderSize  = edges.HasFlag(TileEdge.Right) ? borderSize : gridSize;
                        int topBorderSize    = edges.HasFlag(TileEdge.Top) ? borderSize : gridSize;
                        int bottomBorderSize = edges.HasFlag(TileEdge.Bottom) ? borderSize : gridSize;

                        hasLeftBorder   = this.DrawBorder(spriteBatch, pixelPosition, TileEdge.Left, color, leftBorderSize);
                        hasRightBorder  = this.DrawBorder(spriteBatch, pixelPosition, TileEdge.Right, color, rightBorderSize);
                        hasTopBorder    = this.DrawBorder(spriteBatch, pixelPosition, TileEdge.Top, color, topBorderSize);
                        hasBottomBorder = this.DrawBorder(spriteBatch, pixelPosition, TileEdge.Bottom, color, bottomBorderSize);
                    }
                }

                // draw grid
                if (gridSize > 0)
                {
                    Color color = (tile?.Colors.First() ?? this.GridColor) * 0.5f;
                    int   width = this.GridBorderSize;

                    if (!hasLeftBorder)
                    {
                        this.DrawBorder(spriteBatch, pixelPosition, TileEdge.Left, color, width);
                    }
                    if (!hasRightBorder)
                    {
                        this.DrawBorder(spriteBatch, pixelPosition, TileEdge.Right, color, width);
                    }
                    if (!hasTopBorder)
                    {
                        this.DrawBorder(spriteBatch, pixelPosition, TileEdge.Top, color, width);
                    }
                    if (!hasBottomBorder)
                    {
                        this.DrawBorder(spriteBatch, pixelPosition, TileEdge.Bottom, color, width);
                    }
                }
            }

            // draw top-left boxes
            {
                // calculate dimensions
                int topOffset = this.Margin;
                if (Game1.HostPaused)
                {
                    topOffset += 96; // don't cover the 'paused' message (which has a hardcoded size)
                }
                int leftOffset = this.Margin;

                // draw overlay label
                {
                    Vector2 labelSize = Game1.smallFont.MeasureString(this.CurrentLayer.Name);
                    CommonHelper.DrawScroll(spriteBatch, new Vector2(leftOffset, topOffset), new Vector2(this.BoxContentWidth, labelSize.Y), out Vector2 contentPos, out Rectangle bounds);

                    contentPos = contentPos + new Vector2((this.BoxContentWidth - labelSize.X) / 2, 0); // center label in box
                    spriteBatch.DrawString(Game1.smallFont, this.CurrentLayer.Name, contentPos, Color.Black);

                    topOffset += bounds.Height + this.Padding;
                }

                // draw legend
                if (this.Legend.Any())
                {
                    CommonHelper.DrawScroll(spriteBatch, new Vector2(leftOffset, topOffset), new Vector2(this.BoxContentWidth, this.Legend.Length * this.LegendColorSize), out Vector2 contentPos, out Rectangle _);
                    for (int i = 0; i < this.Legend.Length; i++)
                    {
                        LegendEntry value   = this.Legend[i];
                        int         legendX = (int)contentPos.X;
                        int         legendY = (int)(contentPos.Y + i * this.LegendColorSize);

                        spriteBatch.DrawLine(legendX, legendY, new Vector2(this.LegendColorSize), value.Color);
                        spriteBatch.DrawString(Game1.smallFont, value.Name, new Vector2(legendX + this.LegendColorSize + this.LegendColorPadding, legendY + 2), Color.Black);
                    }
                }
            }
        }
コード例 #2
0
 /*********
 ** Public methods
 *********/
 /// <summary>Construct an instance.</summary>
 /// <param name="tile">The tile position.</param>
 /// <param name="type">The associated legend entry.</param>
 /// <param name="color">The overlay color.</param>
 public TileData(Vector2 tile, LegendEntry type, Color color)
 {
     this.TilePosition = tile;
     this.Type         = type;
     this.Color        = color;
 }
コード例 #3
0
 /// <summary>Construct an instance.</summary>
 /// <param name="tile">The tile position.</param>
 /// <param name="type">The associated legend entry.</param>
 public TileData(Vector2 tile, LegendEntry type)
     : this(tile, type, type.Color)
 {
 }
コード例 #4
0
        /*********
        ** Protected methods
        *********/
        /// <summary>Draw to the screen.</summary>
        /// <param name="spriteBatch">The sprite batch to which to draw.</param>
        protected override void Draw(SpriteBatch spriteBatch)
        {
            if (!this.DrawOverlay())
            {
                return;
            }

            // collect tile details
            TileDrawData[] tiles = this.AggregateTileData(this.TileGroups, this.CombineOverlappingBorders).ToArray();

            // draw
            int       tileSize   = Game1.tileSize;
            const int borderSize = 4;

            foreach (TileDrawData tile in tiles)
            {
                Vector2 pixelPosition = tile.TilePosition * tileSize - new Vector2(Game1.viewport.X, Game1.viewport.Y);

                // overlay
                foreach (Color color in tile.Colors)
                {
                    spriteBatch.Draw(CommonHelper.Pixel, new Rectangle((int)pixelPosition.X, (int)pixelPosition.Y, tileSize, tileSize), color * .3f);
                }

                // borders
                foreach (Color color in tile.BorderColors.Keys)
                {
                    TileEdge edges = tile.BorderColors[color];
                    if (edges.HasFlag(TileEdge.Left))
                    {
                        spriteBatch.Draw(CommonHelper.Pixel, new Rectangle((int)pixelPosition.X, (int)pixelPosition.Y, borderSize, tileSize), color);
                    }
                    if (edges.HasFlag(TileEdge.Right))
                    {
                        spriteBatch.Draw(CommonHelper.Pixel, new Rectangle((int)(pixelPosition.X + tileSize - borderSize), (int)pixelPosition.Y, borderSize, tileSize), color);
                    }
                    if (edges.HasFlag(TileEdge.Top))
                    {
                        spriteBatch.Draw(CommonHelper.Pixel, new Rectangle((int)pixelPosition.X, (int)pixelPosition.Y, tileSize, borderSize), color);
                    }
                    if (edges.HasFlag(TileEdge.Bottom))
                    {
                        spriteBatch.Draw(CommonHelper.Pixel, new Rectangle((int)pixelPosition.X, (int)(pixelPosition.Y + tileSize - borderSize), tileSize, borderSize), color);
                    }
                }
            }

            // draw top-left boxes
            {
                // calculate dimensions
                int topOffset = this.Margin;
                if (Game1.HostPaused)
                {
                    topOffset += 96; // don't cover the 'paused' message (which has a hardcoded size)
                }
                int leftOffset = this.Margin;

                // draw overlay label
                {
                    Vector2 labelSize = Game1.smallFont.MeasureString(this.CurrentLayer.Name);
                    CommonHelper.DrawScroll(spriteBatch, new Vector2(leftOffset, topOffset), new Vector2(this.BoxContentWidth, labelSize.Y), out Vector2 contentPos, out Rectangle bounds);

                    contentPos = contentPos + new Vector2((this.BoxContentWidth - labelSize.X) / 2, 0); // center label in box
                    spriteBatch.DrawString(Game1.smallFont, this.CurrentLayer.Name, contentPos, Color.Black);

                    topOffset += bounds.Height + this.Padding;
                }

                // draw legend
                if (this.Legend.Any())
                {
                    CommonHelper.DrawScroll(spriteBatch, new Vector2(leftOffset, topOffset), new Vector2(this.BoxContentWidth, this.Legend.Length * this.LegendColorSize), out Vector2 contentPos, out Rectangle _);
                    for (int i = 0; i < this.Legend.Length; i++)
                    {
                        LegendEntry value   = this.Legend[i];
                        int         legendX = (int)contentPos.X;
                        int         legendY = (int)(contentPos.Y + i * this.LegendColorSize);

                        spriteBatch.DrawLine(legendX, legendY, new Vector2(this.LegendColorSize), value.Color);
                        spriteBatch.DrawString(Game1.smallFont, value.Name, new Vector2(legendX + this.LegendColorSize + this.LegendColorPadding, legendY + 2), Color.Black);
                    }
                }
            }
        }