diff --git a/OpenRA.Mods.Common/Lint/CheckTooltips.cs b/OpenRA.Mods.Common/Lint/CheckTooltips.cs new file mode 100644 index 0000000000..e88bae5602 --- /dev/null +++ b/OpenRA.Mods.Common/Lint/CheckTooltips.cs @@ -0,0 +1,35 @@ +#region Copyright & License Information +/* + * Copyright 2007-2016 The OpenRA Developers (see AUTHORS) + * This file is part of OpenRA, which is free software. It is made + * available to you under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. For more + * information, see COPYING. + */ +#endregion + +using System; +using System.Linq; +using OpenRA.Mods.Common.Traits; +using OpenRA.Traits; + +namespace OpenRA.Mods.Common.Lint +{ + class CheckTooltips : ILintRulesPass + { + public void Run(Action emitError, Action emitWarning, Ruleset rules) + { + foreach (var actorInfo in rules.Actors) + { + var buildable = actorInfo.Value.TraitInfoOrDefault(); + if (buildable == null) + continue; + + var tooltip = actorInfo.Value.TraitInfos().FirstOrDefault(Exts.IsTraitEnabled); + if (tooltip == null) + emitError("The following buildable actor has no (enabled) Tooltip: " + actorInfo.Key); + } + } + } +} diff --git a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj index 689ba58687..1d45daaa43 100644 --- a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj +++ b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj @@ -176,6 +176,7 @@ + diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/ProductionTooltipLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/ProductionTooltipLogic.cs index 23b937b40b..a4b769a9eb 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/ProductionTooltipLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/ProductionTooltipLogic.cs @@ -55,14 +55,15 @@ namespace OpenRA.Mods.Common.Widgets.Logic if (actor == null || actor == lastActor) return; - var tooltip = actor.TraitInfos().First(Exts.IsTraitEnabled); + var tooltip = actor.TraitInfos().FirstOrDefault(Exts.IsTraitEnabled); + var name = tooltip != null ? tooltip.Name : actor.Name; var buildable = actor.TraitInfo(); var cost = actor.TraitInfo().Cost; - nameLabel.GetText = () => tooltip.Name; + nameLabel.GetText = () => name; var hotkey = palette.TooltipIcon.Hotkey; - var nameWidth = font.Measure(tooltip.Name).X; + var nameWidth = font.Measure(name).X; var hotkeyText = "({0})".F(hotkey.DisplayString()); var hotkeyWidth = hotkey.IsValid() ? font.Measure(hotkeyText).X + 2 * nameLabel.Bounds.X : 0; hotkeyLabel.GetText = () => hotkeyText; @@ -103,7 +104,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic timeLabel.Bounds.X = powerLabel.Bounds.X = costLabel.Bounds.X = timeIcon.Bounds.Right + iconMargin; widget.Bounds.Width = leftWidth + rightWidth + 3 * nameLabel.Bounds.X + timeIcon.Bounds.Width + iconMargin; - var leftHeight = font.Measure(tooltip.Name).Y + requiresFont.Measure(requiresString).Y + descFont.Measure(descString).Y; + var leftHeight = font.Measure(name).Y + requiresFont.Measure(requiresString).Y + descFont.Measure(descString).Y; var rightHeight = font.Measure(powerString).Y + font.Measure(timeString).Y + font.Measure(costString).Y; widget.Bounds.Height = Math.Max(leftHeight, rightHeight) * 3 / 2 + 3 * nameLabel.Bounds.Y;