예제 #1
0
        public virtual void Initialize(WidgetArgs args)
        {
            defaultCursor = ChromeMetrics.Get <string>("DefaultCursor");

            // Parse the YAML equations to find the widget bounds
            var parentBounds = (Parent == null)
                                ? new Rectangle(0, 0, Game.Renderer.Resolution.Width, Game.Renderer.Resolution.Height)
                                : Parent.Bounds;

            var substitutions = args.ContainsKey("substitutions") ?
                                new Dictionary <string, int>((Dictionary <string, int>)args["substitutions"]) :
                                new Dictionary <string, int>();

            substitutions.Add("WINDOW_RIGHT", Game.Renderer.Resolution.Width);
            substitutions.Add("WINDOW_BOTTOM", Game.Renderer.Resolution.Height);
            substitutions.Add("PARENT_RIGHT", parentBounds.Width);
            substitutions.Add("PARENT_LEFT", parentBounds.Left);
            substitutions.Add("PARENT_TOP", parentBounds.Top);
            substitutions.Add("PARENT_BOTTOM", parentBounds.Height);
            var width  = Evaluator.Evaluate(Width, substitutions);
            var height = Evaluator.Evaluate(Height, substitutions);

            substitutions.Add("WIDTH", width);
            substitutions.Add("HEIGHT", height);

            Bounds = new Rectangle(Evaluator.Evaluate(X, substitutions),
                                   Evaluator.Evaluate(Y, substitutions),
                                   width,
                                   height);
        }
예제 #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.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;
                    }
                }
            }
        }
예제 #3
0
        public MapPreviewWidget()
        {
            tooltipContainer = Exts.Lazy(() => Ui.Root.Get <TooltipContainerWidget>(TooltipContainer));

            spawnClaimed       = ChromeProvider.GetImage("lobby-bits", "spawn-claimed");
            spawnUnclaimed     = ChromeProvider.GetImage("lobby-bits", "spawn-unclaimed");
            spawnFont          = Game.Renderer.Fonts[ChromeMetrics.Get <string>("SpawnFont")];
            spawnColor         = ChromeMetrics.Get <Color>("SpawnColor");
            spawnContrastColor = ChromeMetrics.Get <Color>("SpawnContrastColor");
            spawnLabelOffset   = ChromeMetrics.Get <int2>("SpawnLabelOffset");
        }
예제 #4
0
        protected MapPreviewWidget(MapPreviewWidget other)
            : base(other)
        {
            Preview = other.Preview;

            IgnoreMouseInput = other.IgnoreMouseInput;
            ShowSpawnPoints  = other.ShowSpawnPoints;
            TooltipTemplate  = other.TooltipTemplate;
            TooltipContainer = other.TooltipContainer;
            SpawnOccupants   = other.SpawnOccupants;

            tooltipContainer = Exts.Lazy(() => Ui.Root.Get <TooltipContainerWidget>(TooltipContainer));

            spawnClaimed       = ChromeProvider.GetImage("lobby-bits", "spawn-claimed");
            spawnUnclaimed     = ChromeProvider.GetImage("lobby-bits", "spawn-unclaimed");
            spawnFont          = Game.Renderer.Fonts[ChromeMetrics.Get <string>("SpawnFont")];
            spawnColor         = ChromeMetrics.Get <Color>("SpawnColor");
            spawnContrastColor = ChromeMetrics.Get <Color>("SpawnContrastColor");
            spawnLabelOffset   = ChromeMetrics.Get <int2>("SpawnLabelOffset");
        }