Ejemplo n.º 1
0
        public override void Draw(IBatchRenderer sbatch)
        {
            int ioffX = -(int)(Owner.MapOffsetX / TILE_WIDTH);
            int ioffY = -(int)(Owner.MapOffsetY / TILE_WIDTH);

            int extensionX = MathHelper.Min(MAX_EXTENSION_X, FloatMath.Ceiling(VAdapter.VirtualGuaranteedBoundingsOffsetX / TILE_WIDTH));
            int extensionY = MathHelper.Min(MAX_EXTENSION_Y, FloatMath.Ceiling(VAdapter.VirtualGuaranteedBoundingsOffsetY / TILE_WIDTH));

            int countX = FloatMath.Ceiling(VAdapter.VirtualTotalWidth / TILE_WIDTH) + 1;
            int countY = FloatMath.Ceiling(VAdapter.VirtualTotalHeight / TILE_WIDTH) + 1;

            for (int ox = ioffX - extensionX; ox < ioffX + countX + extensionX; ox++)
            {
                for (int oy = ioffY - extensionY; oy < ioffY + countY + extensionY; oy++)
                {
                    var x = ox + MAX_EXTENSION_X;                     // real coords -> array coords
                    var y = oy + MAX_EXTENSION_Y;

                    if (x < 0)
                    {
                        continue;
                    }
                    if (y < 0)
                    {
                        continue;
                    }
                    if (x >= tileCountX)
                    {
                        continue;
                    }
                    if (y >= tileCountY)
                    {
                        continue;
                    }

                    var color = GetGridColor(x, y);

                    var rect = new FRectangle(ox * TILE_WIDTH, oy * TILE_WIDTH, TILE_WIDTH, TILE_WIDTH);

                    sbatch.DrawStretched(Textures.TexPixel, rect, color);
                    sbatch.DrawStretched(Textures.TexTileBorder, rect, Color.White);

#if DEBUG
                    if (DebugSettings.Get("DebugBackground"))
                    {
                        var tx = rect.X + 8;
                        var ty = rect.Y + 8;

                        sbatch.DrawString(
                            Textures.DebugFontSmall,
                            string.Format("({4}|{5})\n{0,2}: {1:000}\n[{2}]{3}", _grid[x, y].Fraction?.ToString() ?? "##", _grid[x, y].PowerCurr * 100, _grid[x, y].SourceDistance, _grid[x, y].IsNeutralDraining ? "D" : "", ox, oy),
                            new FPoint(tx, ty),
                            _grid[x, y].Fraction?.Color ?? Color.Black);

                        if (_grid[x, y].SpawnSource != null)
                        {
                            SimpleRenderHelper.DrawCross(sbatch, rect, _grid[x, y].SpawnSource.Fraction.Color * 0.5f, 2);
                        }

                        var v4tl = new Vector2(+5, +5);
                        var v4tr = new Vector2(-5, +5);
                        var v4br = new Vector2(-5, -5);
                        var v4bl = new Vector2(+5, -5);

                        if (_grid[x, y].BlockNorth)
                        {
                            sbatch.DrawLine(rect.TopLeft + v4tl, rect.TopRight + v4tr, Color.Yellow * 0.6f, 4);
                        }

                        if (_grid[x, y].BlockEast)
                        {
                            sbatch.DrawLine(rect.TopRight + v4tr, rect.BottomRight + v4br, Color.Yellow * 0.6f, 4);
                        }

                        if (_grid[x, y].BlockSouth)
                        {
                            sbatch.DrawLine(rect.BottomRight + v4br, rect.BottomLeft + v4bl, Color.Yellow * 0.6f, 4);
                        }

                        if (_grid[x, y].BlockWest)
                        {
                            sbatch.DrawLine(rect.BottomLeft + v4bl, rect.TopLeft + v4tl, Color.Yellow * 0.6f, 4);
                        }
                    }
#endif
                }
            }
        }