diff --git a/OpenRA.Game/Traits/Player/FrozenActorLayer.cs b/OpenRA.Game/Traits/Player/FrozenActorLayer.cs index 5e1b6a1f37..d63694c053 100644 --- a/OpenRA.Game/Traits/Player/FrozenActorLayer.cs +++ b/OpenRA.Game/Traits/Player/FrozenActorLayer.cs @@ -40,7 +40,7 @@ namespace OpenRA.Traits public ITooltipInfo TooltipInfo { get; private set; } public Player TooltipOwner { get; private set; } - readonly ITooltip tooltip; + readonly ITooltip[] tooltips; public int HP { get; private set; } public DamageState DamageState { get; private set; } @@ -80,7 +80,7 @@ namespace OpenRA.Traits Bounds = self.Bounds; TargetTypes = self.GetEnabledTargetTypes().ToHashSet(); - tooltip = self.TraitsImplementing().FirstOrDefault(); + tooltips = self.TraitsImplementing().ToArray(); health = self.TraitOrDefault(); UpdateVisibility(); @@ -101,6 +101,7 @@ namespace OpenRA.Traits DamageState = health.DamageState; } + var tooltip = tooltips.FirstOrDefault(Exts.IsTraitEnabled); if (tooltip != null) { TooltipInfo = tooltip.TooltipInfo; diff --git a/OpenRA.Mods.Common/Traits/Tooltip.cs b/OpenRA.Mods.Common/Traits/Tooltip.cs index caf690379f..33dcc8505e 100644 --- a/OpenRA.Mods.Common/Traits/Tooltip.cs +++ b/OpenRA.Mods.Common/Traits/Tooltip.cs @@ -13,11 +13,9 @@ using OpenRA.Traits; namespace OpenRA.Mods.Common.Traits { - public abstract class TooltipInfoBase : ITraitInfo + public abstract class TooltipInfoBase : UpgradableTraitInfo { [Translate] public readonly string Name = ""; - - public abstract object Create(ActorInitializer init); } [Desc("Shown in map editor.")] @@ -61,7 +59,7 @@ namespace OpenRA.Mods.Common.Traits public bool IsOwnerRowVisible { get { return ShowOwnerRow; } } } - public class Tooltip : ITooltip + public class Tooltip : UpgradableTrait, ITooltip { readonly Actor self; readonly TooltipInfo info; @@ -70,6 +68,7 @@ namespace OpenRA.Mods.Common.Traits public Player Owner { get { return self.Owner; } } public Tooltip(Actor self, TooltipInfo info) + : base(info) { this.self = self; this.info = info; diff --git a/OpenRA.Mods.Common/Traits/World/EditorActorPreview.cs b/OpenRA.Mods.Common/Traits/World/EditorActorPreview.cs index dea7b228e8..b3d8e613a7 100644 --- a/OpenRA.Mods.Common/Traits/World/EditorActorPreview.cs +++ b/OpenRA.Mods.Common/Traits/World/EditorActorPreview.cs @@ -70,7 +70,9 @@ namespace OpenRA.Mods.Common.Traits Footprint = new ReadOnlyDictionary(footprint); } - var tooltip = Info.TraitInfoOrDefault() as TooltipInfoBase ?? Info.TraitInfoOrDefault(); + var tooltip = Info.TraitInfos().FirstOrDefault(Exts.IsTraitEnabled) as TooltipInfoBase + ?? Info.TraitInfos().FirstOrDefault(Exts.IsTraitEnabled); + Tooltip = (tooltip == null ? " < " + Info.Name + " >" : tooltip.Name) + "\n" + owner.Name + " (" + owner.Faction + ")" + "\nID: " + ID + "\nType: " + Info.Name; diff --git a/OpenRA.Mods.Common/Widgets/Logic/Editor/ActorSelectorLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Editor/ActorSelectorLogic.cs index a6551e8d80..d64640a873 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Editor/ActorSelectorLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Editor/ActorSelectorLogic.cs @@ -132,7 +132,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic item.Bounds.Height = preview.Bounds.Height + 2 * preview.Bounds.Y; item.IsVisible = () => true; - var tooltip = actor.TraitInfoOrDefault() as TooltipInfoBase ?? actor.TraitInfoOrDefault(); + var tooltip = actor.TraitInfos().FirstOrDefault(Exts.IsTraitEnabled) as TooltipInfoBase + ?? actor.TraitInfos().FirstOrDefault(Exts.IsTraitEnabled); + item.GetTooltipText = () => (tooltip == null ? "Type: " : tooltip.Name + "\nType: ") + actor.Name; panel.AddChild(item); diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/ProductionTooltipLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/ProductionTooltipLogic.cs index 630615e129..23b937b40b 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/ProductionTooltipLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/ProductionTooltipLogic.cs @@ -55,7 +55,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic if (actor == null || actor == lastActor) return; - var tooltip = actor.TraitInfo(); + var tooltip = actor.TraitInfos().First(Exts.IsTraitEnabled); var buildable = actor.TraitInfo(); var cost = actor.TraitInfo().Cost; @@ -115,7 +115,11 @@ namespace OpenRA.Mods.Common.Widgets.Logic { ActorInfo ai; if (rules.Actors.TryGetValue(a.ToLowerInvariant(), out ai) && ai.HasTraitInfo()) - return ai.TraitInfo().Name; + { + var actorTooltip = ai.TraitInfos().FirstOrDefault(Exts.IsTraitEnabled); + if (actorTooltip != null) + return actorTooltip.Name; + } return a; } diff --git a/OpenRA.Mods.Common/Widgets/ViewportControllerWidget.cs b/OpenRA.Mods.Common/Widgets/ViewportControllerWidget.cs index afe88e4fa9..8fc3baafb1 100644 --- a/OpenRA.Mods.Common/Widgets/ViewportControllerWidget.cs +++ b/OpenRA.Mods.Common/Widgets/ViewportControllerWidget.cs @@ -191,9 +191,13 @@ namespace OpenRA.Mods.Common.Widgets if (underCursor != null) { - ActorTooltip = underCursor.TraitsImplementing().First(); - ActorTooltipExtra = underCursor.TraitsImplementing().ToArray(); - TooltipType = WorldTooltipType.Actor; + ActorTooltip = underCursor.TraitsImplementing().FirstOrDefault(Exts.IsTraitEnabled); + if (ActorTooltip != null) + { + ActorTooltipExtra = underCursor.TraitsImplementing().ToArray(); + TooltipType = WorldTooltipType.Actor; + } + return; }