예제 #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;
            }

            // 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;
                int leftOffset = this.Margin;

                // draw overlay label
                {
                    Vector2 labelSize = Game1.smallFont.MeasureString(this.CurrentMap.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.CurrentMap.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
        /*********
        ** 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;
            }

            // draw tile overlay
            IDictionary <Vector2, HashSet <Color> > drawnColors = new Dictionary <Vector2, HashSet <Color> >();
            {
                int tileSize = Game1.tileSize;
                foreach (TileGroup group in this.TileGroups.ToArray())
                {
                    HashSet <Vector2> tileHash = new HashSet <Vector2>(group.Tiles.Select(p => p.TilePosition));
                    foreach (TileData tile in group.Tiles)
                    {
                        Vector2 position = tile.TilePosition * tileSize - new Vector2(Game1.viewport.X, Game1.viewport.Y);

                        // should we draw this tile overlay?
                        bool drawOverlay = true;
                        if (drawnColors.TryGetValue(tile.TilePosition, out HashSet <Color> prevColors))
                        {
                            if (prevColors.Contains(tile.Color))
                            {
                                drawOverlay = false;
                            }
                            prevColors.Add(tile.Color);
                        }
                        else
                        {
                            drawnColors[tile.TilePosition] = new HashSet <Color> {
                                tile.Color
                            }
                        };

                        // draw tile overlay
                        if (drawOverlay)
                        {
                            spriteBatch.Draw(CommonHelper.Pixel, new Rectangle((int)position.X, (int)position.Y, tileSize, tileSize), tile.Color * .3f);
                        }

                        // draw borders
                        if (group.OuterBorderColor != null)
                        {
                            const int borderSize  = 4;
                            Color     borderColor = group.OuterBorderColor.Value * 0.9f;
                            int       x           = (int)tile.TilePosition.X;
                            int       y           = (int)tile.TilePosition.Y;

                            // left
                            if (!tileHash.Contains(new Vector2(x - 1, y)))
                            {
                                spriteBatch.Draw(CommonHelper.Pixel, new Rectangle((int)position.X, (int)position.Y, borderSize, tileSize), borderColor);
                            }

                            // right
                            if (!tileHash.Contains(new Vector2(x + 1, y)))
                            {
                                spriteBatch.Draw(CommonHelper.Pixel, new Rectangle((int)(position.X + tileSize - borderSize), (int)position.Y, borderSize, tileSize), borderColor);
                            }

                            // top
                            if (!tileHash.Contains(new Vector2(x, y - 1)))
                            {
                                spriteBatch.Draw(CommonHelper.Pixel, new Rectangle((int)position.X, (int)position.Y, tileSize, borderSize), borderColor);
                            }

                            // bottom
                            if (!tileHash.Contains(new Vector2(x, y + 1)))
                            {
                                spriteBatch.Draw(CommonHelper.Pixel, new Rectangle((int)position.X, (int)(position.Y + tileSize - borderSize), tileSize, borderSize), borderColor);
                            }
                        }
                    }
                }
            }

            // draw top-left boxes
            {
                // calculate dimensions
                int topOffset  = this.Margin;
                int leftOffset = this.Margin;

                // draw overlay label
                {
                    Vector2 labelSize = Game1.smallFont.MeasureString(this.CurrentMap.Name);
                    this.DrawScroll(spriteBatch, leftOffset, topOffset, this.BoxContentWidth, (int)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.CurrentMap.Name, contentPos, Color.Black);

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

                // draw legend
                if (this.Legend.Any())
                {
                    this.DrawScroll(spriteBatch, leftOffset, topOffset, 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);
                    }
                }
            }
        }