diff --git a/OpenRA.Game/Traits/TraitsInterfaces.cs b/OpenRA.Game/Traits/TraitsInterfaces.cs index 748de195d8..850b5e92ff 100644 --- a/OpenRA.Game/Traits/TraitsInterfaces.cs +++ b/OpenRA.Game/Traits/TraitsInterfaces.cs @@ -136,6 +136,12 @@ namespace OpenRA.Traits bool IsOwnerRowVisible { get; } } + public interface IProvideTooltipInfo + { + bool IsTooltipVisible(Player forPlayer); + string TooltipText { get; } + } + public interface IDisabledTrait { bool IsTraitDisabled { get; } } public interface IDisable { bool Disabled { get; } } public interface IExplodeModifier { bool ShouldExplode(Actor self); } diff --git a/OpenRA.Game/Widgets/ViewportControllerWidget.cs b/OpenRA.Game/Widgets/ViewportControllerWidget.cs index 1c580dcc44..888b56e52b 100644 --- a/OpenRA.Game/Widgets/ViewportControllerWidget.cs +++ b/OpenRA.Game/Widgets/ViewportControllerWidget.cs @@ -27,6 +27,7 @@ namespace OpenRA.Widgets public WorldTooltipType TooltipType { get; private set; } public IToolTip ActorTooltip { get; private set; } + public IEnumerable ActorTooltipExtra { get; private set; } public FrozenActor FrozenActorTooltip { get; private set; } public int EdgeScrollThreshold = 15; @@ -109,6 +110,7 @@ namespace OpenRA.Widgets if (underCursor != null) { ActorTooltip = underCursor.TraitsImplementing().First(); + ActorTooltipExtra = underCursor.TraitsImplementing(); TooltipType = WorldTooltipType.Actor; return; } @@ -120,6 +122,7 @@ namespace OpenRA.Widgets if (frozen != null) { FrozenActorTooltip = frozen; + ActorTooltipExtra = frozen.Actor.TraitsImplementing(); TooltipType = WorldTooltipType.FrozenActor; } } diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/WorldTooltipLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/WorldTooltipLogic.cs index 30424c6783..0d39760a31 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/WorldTooltipLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/WorldTooltipLogic.cs @@ -9,6 +9,7 @@ #endregion using System; +using System.Collections.Generic; using System.Drawing; using OpenRA.Traits; using OpenRA.Widgets; @@ -24,6 +25,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic var label = widget.Get("LABEL"); var flag = widget.Get("FLAG"); var owner = widget.Get("OWNER"); + var extras = widget.Get("EXTRA"); var font = Game.Renderer.Fonts[label.Font]; var ownerFont = Game.Renderer.Fonts[owner.Font]; @@ -33,6 +35,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic var flagRace = ""; var ownerName = ""; var ownerColor = Color.White; + var extraText = ""; var singleHeight = widget.Get("SINGLE_HEIGHT").Bounds.Height; var doubleHeight = widget.Get("DOUBLE_HEIGHT").Bounds.Height; @@ -42,6 +45,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic if (viewport == null || viewport.TooltipType == WorldTooltipType.None) return; + var index = 0; + extraText = ""; showOwner = false; Player o = null; @@ -71,7 +76,22 @@ namespace OpenRA.Mods.Common.Widgets.Logic } } - var textWidth = font.Measure(labelText).X; + if (viewport.ActorTooltipExtra != null) + { + foreach (var info in viewport.ActorTooltipExtra) + { + if (info.IsTooltipVisible(world.LocalPlayer)) + { + if (index != 0) + extraText += "\n"; + extraText += info.TooltipText; + index++; + } + } + } + + var textWidth = Math.Max(font.Measure(labelText).X, font.Measure(extraText).X); + if (textWidth != cachedWidth) { label.Bounds.Width = textWidth; @@ -86,9 +106,15 @@ namespace OpenRA.Mods.Common.Widgets.Logic widget.Bounds.Height = doubleHeight; widget.Bounds.Width = Math.Max(widget.Bounds.Width, owner.Bounds.X + ownerFont.Measure(ownerName).X + label.Bounds.X); + index++; } else widget.Bounds.Height = singleHeight; + + if (extraText != "") + { + widget.Bounds.Height += font.Measure(extraText).Y + extras.Bounds.Height; + } }; label.GetText = () => labelText; @@ -98,6 +124,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic owner.IsVisible = () => showOwner; owner.GetText = () => ownerName; owner.GetColor = () => ownerColor; + extras.GetText = () => extraText; } } } diff --git a/mods/cnc/chrome/tooltips.yaml b/mods/cnc/chrome/tooltips.yaml index a2164612ff..4bc3042ab6 100644 --- a/mods/cnc/chrome/tooltips.yaml +++ b/mods/cnc/chrome/tooltips.yaml @@ -45,6 +45,11 @@ Background@WORLD_TOOLTIP: Y: 19 Height: 23 Font: Bold + Label@EXTRA: + X: 5 + Y: 45 + Height: 4 + Font: Bold Background@PRODUCTION_TOOLTIP: Logic: ProductionTooltipLogic diff --git a/mods/d2k/chrome/tooltips.yaml b/mods/d2k/chrome/tooltips.yaml index 1be6cd1480..f6faef849a 100644 --- a/mods/d2k/chrome/tooltips.yaml +++ b/mods/d2k/chrome/tooltips.yaml @@ -49,6 +49,11 @@ Background@WORLD_TOOLTIP: Y: 25 Height: 23 Font: Bold + Label@EXTRA: + X: 7 + Y: 55 + Height: 4 + Font: Bold Background@SPAWN_TOOLTIP: Logic: SpawnSelectorTooltipLogic diff --git a/mods/ra/chrome/tooltips.yaml b/mods/ra/chrome/tooltips.yaml index 5b78684304..9a6b06d65f 100644 --- a/mods/ra/chrome/tooltips.yaml +++ b/mods/ra/chrome/tooltips.yaml @@ -49,6 +49,11 @@ Background@WORLD_TOOLTIP: Y: 22 Height: 23 Font: Bold + Label@EXTRA: + X: 7 + Y: 48 + Height: 4 + Font: Bold Background@SPAWN_TOOLTIP: Logic: SpawnSelectorTooltipLogic