コード例 #1
0
        public override void Draw()
        {
            timeOffset = iconOffset - overlayFont.Measure(WidgetUtils.FormatTime(0, worldRenderer.World.Timestep)) / 2;

            // Icons
            Game.Renderer.EnableAntialiasingFilter();
            foreach (var p in icons.Values)
            {
                WidgetUtils.DrawSpriteCentered(p.Sprite, p.Palette, p.Pos + iconOffset);

                // Charge progress
                var sp = p.Power;
                clock.PlayFetchIndex(ClockSequence,
                                     () => sp.TotalTicks == 0 ? clock.CurrentSequence.Length - 1 : (sp.TotalTicks - sp.RemainingTicks)
                                     * (clock.CurrentSequence.Length - 1) / sp.TotalTicks);

                clock.Tick();
                WidgetUtils.DrawSpriteCentered(clock.Image, p.IconClockPalette, p.Pos + iconOffset);
            }

            Game.Renderer.DisableAntialiasingFilter();

            // Overlay
            foreach (var p in icons.Values)
            {
                var customText = p.Power.IconOverlayTextOverride();
                if (customText != null)
                {
                    var customOffset = iconOffset - overlayFont.Measure(customText) / 2;
                    overlayFont.DrawTextWithContrast(customText,
                                                     p.Pos + customOffset,
                                                     Color.White, Color.Black, 1);
                }
                else if (p.Power.Ready)
                {
                    overlayFont.DrawTextWithContrast(ReadyText,
                                                     p.Pos + readyOffset,
                                                     Color.White, Color.Black, 1);
                }
                else if (!p.Power.Active)
                {
                    overlayFont.DrawTextWithContrast(HoldText,
                                                     p.Pos + holdOffset,
                                                     Color.White, Color.Black, 1);
                }
                else
                {
                    overlayFont.DrawTextWithContrast(WidgetUtils.FormatTime(p.Power.RemainingTicks, worldRenderer.World.Timestep),
                                                     p.Pos + timeOffset,
                                                     Color.White, Color.Black, 1);
                }
            }
        }
コード例 #2
0
        public override void Draw()
        {
            if (sprite != null && palette != null)
            {
                var directionPalette = worldRenderer.Palette(palette);

                // Cursor is rendered in native window coordinates
                // Apply same scaling rules as hardware cursors
                var scale = (graphicSettings.CursorDouble ? 2 : 1) * (Game.Renderer.NativeWindowScale > 1.5f ? 2 : 1);
                WidgetUtils.DrawSpriteCentered(sprite, directionPalette, ChildOrigin, scale / Game.Renderer.WindowScale);
            }
        }
コード例 #3
0
        public override void Draw()
        {
            productionIcons.Clear();
            productionIconsBounds.Clear();

            var player = GetPlayer();

            if (player == null)
            {
                return;
            }

            var queues = world.ActorsWithTrait <ProductionQueue>()
                         .Where(a => a.Actor.Owner == player)
                         .Select((a, i) => new { a.Trait, i });

            foreach (var queue in queues)
            {
                if (!clocks.ContainsKey(queue.Trait))
                {
                    clocks.Add(queue.Trait, new Animation(world, ClockAnimation));
                }
            }

            var currentItemsByItem = queues
                                     .Select(a => a.Trait.CurrentItem())
                                     .Where(pi => pi != null)
                                     .GroupBy(pr => pr.Item)
                                     .OrderBy(g => g.First().Queue.Info.DisplayOrder)
                                     .ThenBy(g => g.First().BuildPaletteOrder)
                                     .ToList();

            Game.Renderer.EnableAntialiasingFilter();

            var queueCol = 0;

            foreach (var currentItems in currentItemsByItem)
            {
                var queued = currentItems
                             .OrderBy(pi => pi.Done ? 0 : (pi.Paused ? 2 : 1))
                             .ThenBy(q => q.RemainingTimeActual)
                             .ToList();

                var current = queued.First();
                var queue   = current.Queue;

                var faction = queue.Actor.Owner.Faction.InternalName;
                var actor   = queue.AllItems().FirstOrDefault(a => a.Name == current.Item);
                if (actor == null)
                {
                    continue;
                }

                var rsi  = actor.TraitInfo <RenderSpritesInfo>();
                var icon = new Animation(world, rsi.GetImage(actor, faction));
                var bi   = actor.TraitInfo <BuildableInfo>();

                icon.Play(bi.Icon);
                var topLeftOffset = new float2(queueCol * (IconWidth + IconSpacing), 0);

                var iconTopLeft    = RenderOrigin + topLeftOffset;
                var centerPosition = iconTopLeft + 0.5f * iconSize;

                var palette = bi.IconPaletteIsPlayerPalette ? bi.IconPalette + player.InternalName : bi.IconPalette;
                WidgetUtils.DrawSpriteCentered(icon.Image, worldRenderer.Palette(palette), centerPosition, 0.5f);

                var rect = new Rectangle((int)iconTopLeft.X, (int)iconTopLeft.Y, (int)iconSize.X, (int)iconSize.Y);
                productionIcons.Add(new ProductionIcon
                {
                    Actor           = actor,
                    Pos             = new float2(rect.Location),
                    Queued          = queued,
                    ProductionQueue = current.Queue
                });

                productionIconsBounds.Add(rect);

                var pio = queue.Actor.Owner.PlayerActor.TraitsImplementing <IProductionIconOverlay>()
                          .FirstOrDefault(p => p.IsOverlayActive(actor));

                if (pio != null)
                {
                    WidgetUtils.DrawSpriteCentered(pio.Sprite, worldRenderer.Palette(pio.Palette),
                                                   centerPosition + pio.Offset(iconSize), 0.5f);
                }

                var clock = clocks[queue];
                clock.PlayFetchIndex(ClockSequence, () => current.TotalTime == 0 ? 0 :
                                     (current.TotalTime - current.RemainingTime) * (clock.CurrentSequence.Length - 1) / current.TotalTime);

                clock.Tick();
                WidgetUtils.DrawSpriteCentered(clock.Image, worldRenderer.Palette(ClockPalette), centerPosition, 0.5f);

                queueCol++;
            }

            var newWidth = Math.Max(queueCol * (IconWidth + IconSpacing), MinWidth);

            if (newWidth != Bounds.Width)
            {
                var wasInBounds = EventBounds.Contains(Viewport.LastMousePos);
                Bounds.Width = newWidth;
                var isInBounds = EventBounds.Contains(Viewport.LastMousePos);

                // HACK: Ui.MouseOverWidget is normally only updated when the mouse moves
                // Call ResetTooltips to force a fake mouse movement so the checks in Tick will work properly
                if (wasInBounds != isInBounds)
                {
                    Game.RunAfterTick(Ui.ResetTooltips);
                }
            }

            Game.Renderer.DisableAntialiasingFilter();

            var tiny = Game.Renderer.Fonts["Tiny"];
            var bold = Game.Renderer.Fonts["Small"];

            foreach (var icon in productionIcons)
            {
                var current = icon.Queued.First();
                var text    = GetOverlayForItem(current, world.Timestep);
                tiny.DrawTextWithContrast(text,
                                          icon.Pos + new float2(16, 12) - new float2(tiny.Measure(text).X / 2, 0),
                                          Color.White, Color.Black, 1);

                if (icon.Queued.Count > 1)
                {
                    text = icon.Queued.Count.ToString();
                    bold.DrawTextWithContrast(text, icon.Pos + new float2(16, 0) - new float2(bold.Measure(text).X / 2, 0),
                                              Color.White, Color.Black, 1);
                }
            }

            var parentWidth = Bounds.X + Bounds.Width;

            Parent.Bounds.Width = parentWidth;

            var gradient = Parent.Get <GradientColorBlockWidget>("PLAYER_GRADIENT");

            var offset        = gradient.Bounds.X - Bounds.X;
            var gradientWidth = Math.Max(MinWidth - offset, currentItemsByItem.Count * (IconWidth + IconSpacing));

            gradient.Bounds.Width = gradientWidth;
            var widestChildWidth = Parent.Parent.Children.Max(x => x.Bounds.Width);

            Parent.Parent.Bounds.Width = Math.Max(25 + widestChildWidth, Bounds.Left + MinWidth);
        }
コード例 #4
0
        public override void Draw()
        {
            armyIcons.Clear();

            var player = GetPlayer();

            if (player == null)
            {
                return;
            }

            var playerStatistics = stats.Update(player);

            var items = playerStatistics.Units.Values
                        .Where(u => u.Count > 0 && u.Icon != null)
                        .OrderBy(u => u.ProductionQueueOrder)
                        .ThenBy(u => u.BuildPaletteOrder);

            Game.Renderer.EnableAntialiasingFilter();

            var queueCol = 0;

            foreach (var unit in items)
            {
                var icon          = unit.Icon;
                var topLeftOffset = new int2(queueCol * (IconWidth + IconSpacing), 0);

                var iconTopLeft    = RenderOrigin + topLeftOffset;
                var centerPosition = iconTopLeft;

                var palette = unit.IconPaletteIsPlayerPalette ? unit.IconPalette + player.InternalName : unit.IconPalette;
                WidgetUtils.DrawSpriteCentered(icon.Image, worldRenderer.Palette(palette), centerPosition + 0.5f * iconSize, 0.5f);

                armyIcons.Add(new ArmyIcon
                {
                    Bounds = new Rectangle(iconTopLeft.X, iconTopLeft.Y, (int)iconSize.X, (int)iconSize.Y),
                    Unit   = unit
                });

                queueCol++;
            }

            var newWidth = Math.Max(queueCol * (IconWidth + IconSpacing), MinWidth);

            if (newWidth != Bounds.Width)
            {
                var wasInBounds = EventBounds.Contains(Viewport.LastMousePos);
                Bounds.Width = newWidth;
                var isInBounds = EventBounds.Contains(Viewport.LastMousePos);

                // HACK: Ui.MouseOverWidget is normally only updated when the mouse moves
                // Call ResetTooltips to force a fake mouse movement so the checks in Tick will work properly
                if (wasInBounds != isInBounds)
                {
                    Game.RunAfterTick(Ui.ResetTooltips);
                }
            }

            Game.Renderer.DisableAntialiasingFilter();

            var bold = Game.Renderer.Fonts["TinyBold"];

            foreach (var armyIcon in armyIcons)
            {
                var text = armyIcon.Unit.Count.ToString();
                bold.DrawTextWithContrast(text, armyIcon.Bounds.Location + new float2(iconSize.X, 0) - new float2(bold.Measure(text).X, bold.TopOffset),
                                          Color.White, Color.Black, 1);
            }

            var parentWidth = Bounds.X + Bounds.Width;

            Parent.Bounds.Width = parentWidth;

            var gradient = Parent.Get <GradientColorBlockWidget>("PLAYER_GRADIENT");

            var offset        = gradient.Bounds.X - Bounds.X;
            var gradientWidth = Math.Max(MinWidth - offset, queueCol * (IconWidth + IconSpacing));

            gradient.Bounds.Width = gradientWidth;
            var widestChildWidth = Parent.Parent.Children.Max(x => x.Bounds.Width);

            Parent.Parent.Bounds.Width = Math.Max(25 + widestChildWidth, Bounds.Left + MinWidth);
        }
コード例 #5
0
        public override void Draw()
        {
            supportPowerIconsIcons.Clear();
            supportPowerIconsBounds.Clear();

            var player = GetPlayer();

            if (player == null)
            {
                return;
            }

            var powers = player.PlayerActor.Trait <SupportPowerManager>().Powers
                         .Where(x => !x.Value.Disabled)
                         .OrderBy(p => p.Value.Info.SupportPowerPaletteOrder)
                         .Select((a, i) => new { a, i })
                         .ToList();

            foreach (var power in powers)
            {
                if (!clocks.ContainsKey(power.a.Key))
                {
                    clocks.Add(power.a.Key, new Animation(world, ClockAnimation));
                }
            }

            Bounds.Width = powers.Count() * (IconWidth + IconSpacing);

            Game.Renderer.EnableAntialiasingFilter();

            var iconSize = new float2(IconWidth, IconHeight);

            foreach (var power in powers)
            {
                var item = power.a.Value;
                if (item == null || item.Info == null || item.Info.Icon == null)
                {
                    continue;
                }

                icon = new Animation(worldRenderer.World, item.Info.IconImage);
                icon.Play(item.Info.Icon);
                var location = new float2(RenderBounds.Location) + new float2(power.i * (IconWidth + IconSpacing), 0);

                supportPowerIconsIcons.Add(new SupportPowersWidget.SupportPowerIcon {
                    Power = item, Pos = location
                });
                supportPowerIconsBounds.Add(new Rectangle((int)location.X, (int)location.Y, (int)iconSize.X, (int)iconSize.Y));

                WidgetUtils.DrawSpriteCentered(icon.Image, worldRenderer.Palette(item.Info.IconPalette), location + 0.5f * iconSize, 0.5f);

                var clock = clocks[power.a.Key];
                clock.PlayFetchIndex(ClockSequence,
                                     () => item.TotalTicks == 0 ? 0 : ((item.TotalTicks - item.RemainingTicks)
                                                                       * (clock.CurrentSequence.Length - 1) / item.TotalTicks));
                clock.Tick();
                WidgetUtils.DrawSpriteCentered(clock.Image, worldRenderer.Palette(ClockPalette), location + 0.5f * iconSize, 0.5f);
            }

            Game.Renderer.DisableAntialiasingFilter();

            var tiny = Game.Renderer.Fonts["Tiny"];

            foreach (var icon in supportPowerIconsIcons)
            {
                var text = GetOverlayForItem(icon.Power, world.Timestep);
                tiny.DrawTextWithContrast(text,
                                          icon.Pos + new float2(16, 12) - new float2(tiny.Measure(text).X / 2, 0),
                                          Color.White, Color.Black, 1);
            }
        }