diff --git a/OpenRA.Mods.Cnc/Widgets/Logic/ProductionTooltipLogic.cs b/OpenRA.Mods.Cnc/Widgets/Logic/ProductionTooltipLogic.cs index fe01ed1fb7..114904c40f 100644 --- a/OpenRA.Mods.Cnc/Widgets/Logic/ProductionTooltipLogic.cs +++ b/OpenRA.Mods.Cnc/Widgets/Logic/ProductionTooltipLogic.cs @@ -8,6 +8,10 @@ */ #endregion +using System; +using System.Linq; +using OpenRA.Mods.RA; +using OpenRA.Mods.RA.Buildings; using OpenRA.Support; using OpenRA.Widgets; @@ -17,10 +21,78 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic { [ObjectCreator.UseCtor] public ProductionTooltipLogic([ObjectCreator.Param] Widget widget, + [ObjectCreator.Param] TooltipContainerWidget tooltipContainer, [ObjectCreator.Param] ProductionPaletteWidget palette) { widget.IsVisible = () => palette.TooltipActor != null; - widget.GetWidget("NAME").GetText = () => palette.TooltipActor; + var nameLabel = widget.GetWidget("NAME"); + var requiresLabel = widget.GetWidget("REQUIRES"); + var powerLabel = widget.GetWidget("POWER"); + var timeLabel = widget.GetWidget("TIME"); + var costLabel = widget.GetWidget("COST"); + + var font = Game.Renderer.Fonts[nameLabel.Font]; + var requiresFont = Game.Renderer.Fonts[requiresLabel.Font]; + var name = ""; + var requires = ""; + var power = ""; + var time = ""; + var cost = ""; + + string lastActor = null; + tooltipContainer.BeforeRender = () => + { + var actor = palette.TooltipActor; + if (actor == null || actor == lastActor) + return; + + var info = Rules.Info[actor]; + var tooltip = info.Traits.Get(); + var buildable = info.Traits.Get(); + name = tooltip.Name; + cost = "$: {0}".F(info.Traits.Get().Cost); + time = "T: {0}".F(WidgetUtils.FormatTime(palette.CurrentQueue.GetBuildTime(actor))); + + var bi = info.Traits.GetOrDefault(); + power = bi != null ? "P: {0}".F(bi.Power) : ""; + + var prereqs = buildable.Prerequisites.Select(a => ActorName(a)); + requires = prereqs.Any() ? "Requires {0}".F(string.Join(", ", prereqs.ToArray())) : ""; + + var leftWidth = Math.Max(font.Measure(name).X, requiresFont.Measure(requires).X); + var rightWidth = new [] {font.Measure(power).X, font.Measure(time).X, font.Measure(cost).X}.Aggregate(Math.Max); + timeLabel.Bounds.X = powerLabel.Bounds.X = costLabel.Bounds.X = leftWidth + 2*nameLabel.Bounds.X; + widget.Bounds.Width = leftWidth + rightWidth + 3*nameLabel.Bounds.X; + lastActor = actor; + + widget.Bounds.Height = bi != null ? 65 : 45; + }; + + nameLabel.GetText = () => name; + requiresLabel.GetText = () => requires; + powerLabel.GetText = () => power; + timeLabel.GetText = () => time; + costLabel.GetText = () => cost; + } + + static string ActorName( string a ) + { + // hack hack hack - going to die soon anyway + if (a == "barracks") + return "Infantry Production"; + if (a == "vehicleproduction") + return "Vehicle Production"; + if (a == "techcenter") + return "Tech Center"; + if (a == "anypower") + return "Power Plant"; + + ActorInfo ai; + Rules.Info.TryGetValue(a.ToLowerInvariant(), out ai); + if (ai != null && ai.Traits.Contains()) + return ai.Traits.Get().Name; + + return a; } } } diff --git a/mods/cnc/chrome/tooltips.yaml b/mods/cnc/chrome/tooltips.yaml index ee6b09fb42..01c7352601 100644 --- a/mods/cnc/chrome/tooltips.yaml +++ b/mods/cnc/chrome/tooltips.yaml @@ -54,16 +54,39 @@ Background@PRODUCTION_TOOLTIP: Id:PRODUCTION_TOOLTIP Logic:ProductionTooltipLogic Background:panel-black - Width:100 - Height:25 + Width:200 + Height:65 Children: Label@NAME: Id:NAME X:5 - Width:PARENT_RIGHT-10 Height:23 Font:Bold - + Label@REQUIRES: + Id:REQUIRES + X:5 + Y:19 + Height:23 + Font:TinyBold + Label@COST: + Id:COST + Height:23 + Font:Bold + Label@TIME: + Id:TIME + Y:19 + Height:23 + Font:Bold + Label@POWER: + Id:POWER + Y:39 + Height:23 + Font:Bold + Label@TIME: + Id:TIME + Y:39 + Height:23 + Font:Bold Background@SUPPORT_POWER_TOOLTIP: Id:SUPPORT_POWER_TOOLTIP Logic:SupportPowerTooltipLogic