public override void Draw()
        {
            var preview = Preview();

            if (preview == null)
            {
                return;
            }

            // Stash a copy of the minimap to ensure consistency
            // (it may be modified by another thread)
            minimap = preview.Minimap;
            if (minimap == null)
            {
                return;
            }

            // Update map rect
            PreviewScale = Math.Min(RenderBounds.Width / minimap.size.X, RenderBounds.Height / minimap.size.Y);
            var w = (int)(PreviewScale * minimap.size.X);
            var h = (int)(PreviewScale * minimap.size.Y);
            var x = RenderBounds.X + (RenderBounds.Width - w) / 2;
            var y = RenderBounds.Y + (RenderBounds.Height - h) / 2;

            MapRect = new Rectangle(x, y, w, h);

            Game.Renderer.RgbaSpriteRenderer.DrawSprite(minimap, new float2(MapRect.Location), new float2(MapRect.Size));

            TooltipSpawnIndex = -1;
            if (ShowSpawnPoints)
            {
                var colors = SpawnOccupants().ToDictionary(c => c.Key, c => c.Value.Color.RGB);

                var spawnPoints = preview.SpawnPoints;
                foreach (var p in spawnPoints)
                {
                    var owned  = colors.ContainsKey(p);
                    var pos    = ConvertToPreview(p);
                    var sprite = ChromeProvider.GetImage("lobby-bits", owned ? "spawn-claimed" : "spawn-unclaimed");
                    var offset = new int2(sprite.bounds.Width, sprite.bounds.Height) / 2;

                    if (owned)
                    {
                        WidgetUtils.FillEllipseWithColor(new Rectangle(pos.X - offset.X + 1, pos.Y - offset.Y + 1, sprite.bounds.Width - 2, sprite.bounds.Height - 2), colors[p]);
                    }

                    Game.Renderer.RgbaSpriteRenderer.DrawSprite(sprite, pos - offset);
                    var fonts  = Game.Renderer.Fonts[ChromeMetrics.Get <string>("SpawnFont")];
                    var number = Convert.ToChar('A' + spawnPoints.IndexOf(p)).ToString();
                    offset    = fonts.Measure(number) / 2;
                    offset.Y += 1;                     // Does not center well vertically for some reason
                    fonts.DrawTextWithContrast(number, pos - offset, ChromeMetrics.Get <Color>("SpawnColor"), ChromeMetrics.Get <Color>("SpawnContrastColor"), 1);

                    if (((pos - Viewport.LastMousePos).ToFloat2() * offset.ToFloat2()).LengthSquared < 1)
                    {
                        TooltipSpawnIndex = spawnPoints.IndexOf(p) + 1;
                    }
                }
            }
        }
示例#2
0
        public override void Draw()
        {
            var preview = Preview();

            if (preview == null)
            {
                return;
            }

            // Stash a copy of the minimap to ensure consistency
            // (it may be modified by another thread)
            minimap = preview.GetMinimap();
            if (minimap == null)
            {
                return;
            }

            // Update map rect
            previewScale = Math.Min(RenderBounds.Width / minimap.size.X, RenderBounds.Height / minimap.size.Y);
            var w = (int)(previewScale * minimap.size.X);
            var h = (int)(previewScale * minimap.size.Y);
            var x = RenderBounds.X + (RenderBounds.Width - w) / 2;
            var y = RenderBounds.Y + (RenderBounds.Height - h) / 2;

            mapRect = new Rectangle(x, y, w, h);

            Game.Renderer.RgbaSpriteRenderer.DrawSprite(minimap, new float2(mapRect.Location), new float2(mapRect.Size));

            TooltipSpawnIndex = -1;
            if (ShowSpawnPoints)
            {
                var colors = SpawnOccupants().ToDictionary(c => c.Key, c => c.Value.Color.RGB);

                var spawnPoints = preview.SpawnPoints;
                foreach (var p in spawnPoints)
                {
                    var owned  = colors.ContainsKey(p);
                    var pos    = ConvertToPreview(p);
                    var sprite = owned ? spawnClaimed : spawnUnclaimed;
                    var offset = new int2(sprite.bounds.Width, sprite.bounds.Height) / 2;

                    if (owned)
                    {
                        WidgetUtils.FillEllipseWithColor(new Rectangle(pos.X - offset.X + 1, pos.Y - offset.Y + 1, sprite.bounds.Width - 2, sprite.bounds.Height - 2), colors[p]);
                    }

                    Game.Renderer.RgbaSpriteRenderer.DrawSprite(sprite, pos - offset);
                    var number     = Convert.ToChar('A' + spawnPoints.IndexOf(p)).ToString();
                    var textOffset = spawnFont.Measure(number) / 2 + spawnLabelOffset;

                    spawnFont.DrawTextWithContrast(number, pos - textOffset, spawnColor, spawnContrastColor, 1);

                    if (((pos - Viewport.LastMousePos).ToFloat2() / offset.ToFloat2()).LengthSquared <= 1)
                    {
                        TooltipSpawnIndex = spawnPoints.IndexOf(p) + 1;
                    }
                }
            }
        }