示例#1
0
        public override void Draw()
        {
            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("clock"));
                }
            }
            foreach (var queue in queues)
            {
                var current = queue.Trait.CurrentItem();
                if (current == null)
                {
                    continue;
                }

                var actor = queue.Trait.AllItems().Where(a => a.Name == current.Item).FirstOrDefault();
                if (actor == null)
                {
                    continue;
                }

                var icon = new Animation(RenderSimple.GetImage(actor));
                icon.Play(actor.Traits.Get <TooltipInfo>().Icon);
                var size     = icon.Image.size / new float2(2, 2);
                var location = new float2(RenderBounds.Location) + new float2(queue.i * (int)size.Length, 0);
                WidgetUtils.DrawSHP(icon.Image, location, worldRenderer, size);

                var clock = clocks[queue.Trait];
                clock.PlayFetchIndex("idle",
                                     () => current.TotalTime == 0 ? 0 : ((current.TotalTime - current.RemainingTime)
                                                                         * (clock.CurrentSequence.Length - 1) / current.TotalTime));
                clock.Tick();
                WidgetUtils.DrawSHP(clock.Image, location, worldRenderer, size);

                var tiny = Game.Renderer.Fonts["Tiny"];
                var text = GetOverlayForItem(current);
                tiny.DrawTextWithContrast(text,
                                          location + new float2(16, 16) - new float2(tiny.Measure(text).X / 2, 0),
                                          Color.White, Color.Black, 1);
            }
        }
示例#2
0
        public override void Draw()
        {
            overlayFont = Game.Renderer.Fonts["TinyBold"];
            holdOffset  = new float2(32, 24) - overlayFont.Measure(HoldText) / 2;
            readyOffset = new float2(32, 24) - overlayFont.Measure(ReadyText) / 2;
            timeOffset  = new float2(32, 24) - overlayFont.Measure(WidgetUtils.FormatTime(0)) / 2;

            // Background
            foreach (var rect in Icons.Keys)
            {
                WidgetUtils.DrawPanel("panel-black", rect.InflateBy(1, 1, 1, 1));
            }

            // Icons
            foreach (var p in Icons.Values)
            {
                WidgetUtils.DrawSHP(p.Sprite, p.Pos, worldRenderer);

                // Charge progress
                clock.PlayFetchIndex("idle",
                                     () => (p.Power.TotalTime - p.Power.RemainingTime)
                                     * (clock.CurrentSequence.Length - 1) / p.Power.TotalTime);
                clock.Tick();
                WidgetUtils.DrawSHP(clock.Image, p.Pos, worldRenderer);
            }

            // Overlay
            foreach (var p in Icons.Values)
            {
                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.RemainingTime),
                                                     p.Pos + timeOffset,
                                                     Color.White, Color.Black, 1);
                }
            }
        }
        public override void Draw()
        {
            var player = GetPlayer();

            if (player == null)
            {
                return;
            }
            var powers = player.PlayerActor.Trait <SupportPowerManager>().Powers
                         .Select((a, i) => new { a, i });

            foreach (var power in powers)
            {
                if (!clocks.ContainsKey(power.a.Key))
                {
                    clocks.Add(power.a.Key, new Animation("clock"));
                }
            }
            foreach (var power in powers)
            {
                var item = power.a.Value;
                if (item == null || item.Info == null || item.Info.Icon == null)
                {
                    continue;
                }
                icon.Play(item.Info.Icon);
                var size     = icon.Image.size / new float2(2, 2);
                var location = new float2(RenderBounds.Location) + new float2(power.i * (int)size.Length, 0);
                WidgetUtils.DrawSHP(icon.Image, location, worldRenderer, size);

                var clock = clocks[power.a.Key];
                clock.PlayFetchIndex("idle",
                                     () => item.TotalTime == 0 ? 0 : ((item.TotalTime - item.RemainingTime)
                                                                      * (clock.CurrentSequence.Length - 1) / item.TotalTime));
                clock.Tick();
                WidgetUtils.DrawSHP(clock.Image, location, worldRenderer, size);

                var tiny = Game.Renderer.Fonts["Tiny"];
                var text = GetOverlayForItem(item);
                tiny.DrawTextWithContrast(text,
                                          location + new float2(16, 16) - new float2(tiny.Measure(text).X / 2, 0),
                                          Color.White, Color.Black, 1);
            }
        }
示例#4
0
		public override void Draw()
		{
			// Background
			foreach (var rect in Icons.Keys)
				WidgetUtils.DrawPanel("panel-black", rect.InflateBy(1,1,1,1));

			// Icons
			foreach (var p in Icons.Values)
			{
				WidgetUtils.DrawSHP(p.Sprite, p.Pos, worldRenderer);

				// Charge progress
				clock.PlayFetchIndex("idle",
					() => (p.Power.TotalTime - p.Power.RemainingTime)
						* (clock.CurrentSequence.Length - 1) / p.Power.TotalTime);
				clock.Tick();
				WidgetUtils.DrawSHP(clock.Image, p.Pos, worldRenderer);
			}

			// Overlay
			foreach (var p in Icons.Values)
			{
				if (p.Power.Ready)
					overlayFont.DrawTextWithContrast("Ready",
						p.Pos + readyOffset,
						Color.White, Color.Black, 1);
				else if (!p.Power.Active)
					overlayFont.DrawTextWithContrast("On Hold",
						p.Pos + holdOffset,
						Color.White, Color.Black, 1);
				else
					overlayFont.DrawTextWithContrast(WidgetUtils.FormatTime(p.Power.RemainingTime),
						p.Pos + timeOffset,
						Color.White, Color.Black, 1);
			}
		}
示例#5
0
        public override void Draw()
        {
            buttons.Clear();

            if (world.LocalPlayer == null)
            {
                return;
            }

            var manager   = world.LocalPlayer.PlayerActor.Trait <SupportPowerManager>();
            var powers    = manager.Powers.Where(p => !p.Value.Disabled);
            var numPowers = powers.Count();

            if (numPowers == 0)
            {
                return;
            }

            var rectBounds = RenderBounds;

            WidgetUtils.DrawRGBA(WidgetUtils.GetChromeImage(world, "specialbin-top"), new float2(rectBounds.X, rectBounds.Y));
            for (var i = 1; i < numPowers; i++)
            {
                WidgetUtils.DrawRGBA(WidgetUtils.GetChromeImage(world, "specialbin-middle"), new float2(rectBounds.X, rectBounds.Y + i * 51));
            }
            WidgetUtils.DrawRGBA(WidgetUtils.GetChromeImage(world, "specialbin-bottom"), new float2(rectBounds.X, rectBounds.Y + numPowers * 51));

            // Hack Hack Hack
            rectBounds.Width  = 69;
            rectBounds.Height = 10 + numPowers * 51 + 21;

            var y = rectBounds.Y + 10;

            foreach (var kv in powers)
            {
                var sp    = kv.Value;
                var image = spsprites[sp.Info.Image];

                var drawPos = new float2(rectBounds.X + 5, y);
                var rect    = new Rectangle(rectBounds.X + 5, y, 64, 48);

                if (rect.Contains(Viewport.LastMousePos))
                {
                    var pos = drawPos.ToInt2();
                    var tl  = new int2(pos.X - 3, pos.Y - 3);
                    var m   = new int2(pos.X + 64 + 3, pos.Y + 48 + 3);
                    var br  = tl + new int2(64 + 3 + 20, 40);

                    if (sp.TotalTime > 0)
                    {
                        br += new int2(0, 20);
                    }

                    if (sp.Info.LongDesc != null)
                    {
                        br += Game.Renderer.Fonts["Regular"].Measure(sp.Info.LongDesc.Replace("\\n", "\n"));
                    }
                    else
                    {
                        br += new int2(300, 0);
                    }

                    var border = WidgetUtils.GetBorderSizes("dialog4");

                    WidgetUtils.DrawPanelPartial("dialog4", Rectangle.FromLTRB(tl.X, tl.Y, m.X + border[3], m.Y),
                                                 PanelSides.Left | PanelSides.Top | PanelSides.Bottom | PanelSides.Center);
                    WidgetUtils.DrawPanelPartial("dialog4", Rectangle.FromLTRB(m.X - border[2], tl.Y, br.X, m.Y + border[1]),
                                                 PanelSides.Top | PanelSides.Right | PanelSides.Center);
                    WidgetUtils.DrawPanelPartial("dialog4", Rectangle.FromLTRB(m.X, m.Y - border[1], br.X, br.Y),
                                                 PanelSides.Left | PanelSides.Right | PanelSides.Bottom | PanelSides.Center);

                    pos += new int2(77, 5);
                    Game.Renderer.Fonts["Bold"].DrawText(sp.Info.Description, pos, Color.White);

                    if (sp.TotalTime > 0)
                    {
                        pos += new int2(0, 20);
                        Game.Renderer.Fonts["Bold"].DrawText(WidgetUtils.FormatTime(sp.RemainingTime).ToString(), pos, Color.White);
                        Game.Renderer.Fonts["Bold"].DrawText("/ {0}".F(WidgetUtils.FormatTime(sp.TotalTime)), pos + new int2(45, 0), Color.White);
                    }

                    if (sp.Info.LongDesc != null)
                    {
                        pos += new int2(0, 20);
                        Game.Renderer.Fonts["Regular"].DrawText(sp.Info.LongDesc.Replace("\\n", "\n"), pos, Color.White);
                    }
                }

                WidgetUtils.DrawSHP(image, drawPos, worldRenderer);

                clock.PlayFetchIndex("idle",
                                     () => sp.TotalTime == 0 ? clock.CurrentSequence.Length - 1 : (sp.TotalTime - sp.RemainingTime)
                                     * (clock.CurrentSequence.Length - 1) / sp.TotalTime);
                clock.Tick();

                WidgetUtils.DrawSHP(clock.Image, drawPos, worldRenderer);

                var overlay = sp.Ready ? ReadyText : sp.Active ? null : HoldText;
                var font    = Game.Renderer.Fonts["TinyBold"];
                if (overlay != null)
                {
                    var size       = font.Measure(overlay);
                    var overlayPos = drawPos + new float2(32, 16);
                    font.DrawTextWithContrast(overlay, overlayPos - new float2(size.X / 2, 0), Color.White, Color.Black, 1);
                }

                buttons.Add(Pair.New(rect, HandleSupportPower(kv.Key, manager)));

                y += 51;
            }
        }
示例#6
0
        public override void Draw()
        {
            overlayFont  = Game.Renderer.Fonts["TinyBold"];
            timeOffset   = new float2(32, 24) - overlayFont.Measure(WidgetUtils.FormatTime(0)) / 2;
            queuedOffset = new float2(4, 2);
            holdOffset   = new float2(32, 24) - overlayFont.Measure(HoldText) / 2;
            readyOffset  = new float2(32, 24) - overlayFont.Measure(ReadyText) / 2;

            if (CurrentQueue == null)
            {
                return;
            }

            var buildableItems = CurrentQueue.BuildableItems().OrderBy(a => a.Traits.Get <BuildableInfo>().BuildPaletteOrder);

            // Background
            foreach (var rect in icons.Keys)
            {
                WidgetUtils.DrawPanel("panel-black", rect.InflateBy(1, 1, 1, 1));
            }

            // Icons
            foreach (var icon in icons.Values)
            {
                WidgetUtils.DrawSHP(icon.Sprite, icon.Pos, worldRenderer);

                // Build progress
                if (icon.Queued.Count > 0)
                {
                    var first = icon.Queued[0];
                    clock.PlayFetchIndex("idle",
                                         () => (first.TotalTime - first.RemainingTime)
                                         * (clock.CurrentSequence.Length - 1) / first.TotalTime);
                    clock.Tick();
                    WidgetUtils.DrawSHP(clock.Image, icon.Pos, worldRenderer);
                }
                else if (!buildableItems.Any(a => a.Name == icon.Name))
                {
                    WidgetUtils.DrawSHP(cantBuild.Image, icon.Pos, worldRenderer);
                }
            }

            // Overlays
            foreach (var icon in icons.Values)
            {
                var total = icon.Queued.Count;
                if (total > 0)
                {
                    var first   = icon.Queued[0];
                    var waiting = first != CurrentQueue.CurrentItem() && !first.Done;
                    if (first.Done)
                    {
                        overlayFont.DrawTextWithContrast(ReadyText,
                                                         icon.Pos + readyOffset,
                                                         Color.White, Color.Black, 1);
                    }
                    else if (first.Paused)
                    {
                        overlayFont.DrawTextWithContrast(HoldText,
                                                         icon.Pos + holdOffset,
                                                         Color.White, Color.Black, 1);
                    }
                    else if (!waiting)
                    {
                        overlayFont.DrawTextWithContrast(WidgetUtils.FormatTime(first.RemainingTimeActual),
                                                         icon.Pos + timeOffset,
                                                         Color.White, Color.Black, 1);
                    }

                    if (total > 1 || waiting)
                    {
                        overlayFont.DrawTextWithContrast(total.ToString(),
                                                         icon.Pos + queuedOffset,
                                                         Color.White, Color.Black, 1);
                    }
                }
            }
        }
示例#7
0
        int DrawPalette(ProductionQueue queue)
        {
            buttons.Clear();

            string paletteCollection = "palette-" + world.LocalPlayer.Country.Race;
            float2 origin            = new float2(paletteOrigin.X + 9, paletteOrigin.Y + 9);
            var    x = 0;
            var    y = 0;

            if (queue != null)
            {
                var buildableItems = queue.BuildableItems().ToArray();
                var allBuildables  = queue.AllItems().OrderBy(a => a.Traits.Get <BuildableInfo>().BuildPaletteOrder).ToArray();

                var overlayBits = new List <Pair <Sprite, float2> >();
                var textBits    = new List <Pair <float2, string> >();
                numActualRows = Math.Max((allBuildables.Count() + Columns - 1) / Columns, Rows);

                // Palette Background
                WidgetUtils.DrawRGBA(ChromeProvider.GetImage(paletteCollection, "top"), new float2(origin.X - 9, origin.Y - 9));
                for (var w = 0; w < numActualRows; w++)
                {
                    WidgetUtils.DrawRGBA(
                        ChromeProvider.GetImage(paletteCollection, "bg-" + (w % 4).ToString()),
                        new float2(origin.X - 9, origin.Y + 48 * w));
                }
                WidgetUtils.DrawRGBA(ChromeProvider.GetImage(paletteCollection, "bottom"),
                                     new float2(origin.X - 9, origin.Y - 1 + 48 * numActualRows));


                // Icons
                string tooltipItem = null;
                foreach (var item in allBuildables)
                {
                    var rect    = new RectangleF(origin.X + x * 64, origin.Y + 48 * y, 64, 48);
                    var drawPos = new float2(rect.Location);
                    WidgetUtils.DrawSHP(iconSprites[item.Name], drawPos, worldRenderer);

                    var firstOfThis = queue.AllQueued().FirstOrDefault(a => a.Item == item.Name);

                    if (rect.Contains(Viewport.LastMousePos))
                    {
                        tooltipItem = item.Name;
                    }

                    var overlayPos = drawPos + new float2(32, 16);

                    if (firstOfThis != null)
                    {
                        clock.PlayFetchIndex("idle",
                                             () => (firstOfThis.TotalTime - firstOfThis.RemainingTime)
                                             * (clock.CurrentSequence.Length - 1) / firstOfThis.TotalTime);
                        clock.Tick();
                        WidgetUtils.DrawSHP(clock.Image, drawPos, worldRenderer);

                        if (queue.CurrentItem() == firstOfThis)
                        {
                            textBits.Add(Pair.New(overlayPos, GetOverlayForItem(firstOfThis)));
                        }

                        var repeats = queue.AllQueued().Count(a => a.Item == item.Name);
                        if (repeats > 1 || queue.CurrentItem() != firstOfThis)
                        {
                            textBits.Add(Pair.New(overlayPos + new float2(-24, -14), repeats.ToString()));
                        }
                    }
                    else
                    if (!buildableItems.Any(a => a.Name == item.Name))
                    {
                        overlayBits.Add(Pair.New(cantBuild.Image, drawPos));
                    }

                    var closureName = buildableItems.Any(a => a.Name == item.Name) ? item.Name : null;
                    buttons.Add(Pair.New(new Rectangle((int)rect.X, (int)rect.Y, (int)rect.Width, (int)rect.Height), HandleClick(closureName, world)));

                    if (++x == Columns)
                    {
                        x = 0; y++;
                    }
                }
                if (x != 0)
                {
                    y++;
                }

                foreach (var ob in overlayBits)
                {
                    WidgetUtils.DrawSHP(ob.First, ob.Second, worldRenderer);
                }

                var font = Game.Renderer.Fonts["TinyBold"];
                foreach (var tb in textBits)
                {
                    var size = font.Measure(tb.Second);
                    font.DrawTextWithContrast(tb.Second, tb.First - new float2(size.X / 2, 0),
                                              Color.White, Color.Black, 1);
                }

                // Tooltip
                if (tooltipItem != null && !paletteAnimating && paletteOpen)
                {
                    DrawProductionTooltip(world, tooltipItem,
                                          new float2(Game.viewport.Width, origin.Y + numActualRows * 48 + 9).ToInt2());
                }
            }

            // Palette Dock
            WidgetUtils.DrawRGBA(ChromeProvider.GetImage(paletteCollection, "dock-top"),
                                 new float2(Game.viewport.Width - 14, origin.Y - 23));

            for (int i = 0; i < numActualRows; i++)
            {
                WidgetUtils.DrawRGBA(ChromeProvider.GetImage(paletteCollection, "dock-" + (i % 4).ToString()),
                                     new float2(Game.viewport.Width - 14, origin.Y + 48 * i));
            }

            WidgetUtils.DrawRGBA(ChromeProvider.GetImage(paletteCollection, "dock-bottom"),
                                 new float2(Game.viewport.Width - 14, origin.Y - 1 + 48 * numActualRows));

            return(48 * y + 9);
        }