diff --git a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj index f4d9622074..810e1ea4ae 100644 --- a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj +++ b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj @@ -297,6 +297,7 @@ + diff --git a/OpenRA.Mods.Common/Traits/PowerTooltip.cs b/OpenRA.Mods.Common/Traits/PowerTooltip.cs new file mode 100644 index 0000000000..5d648540e4 --- /dev/null +++ b/OpenRA.Mods.Common/Traits/PowerTooltip.cs @@ -0,0 +1,53 @@ +#region Copyright & License Information +/* + * Copyright 2007-2015 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. For more information, + * see COPYING. + */ +#endregion + +using OpenRA.Traits; + +namespace OpenRA.Mods.Common.Traits +{ + [Desc("Shown power info on the build palette widget.")] + public class PowerTooltipInfo : ITraitInfo + { + public object Create(ActorInitializer init) { return new PowerTooltip(init.Self); } + } + + public class PowerTooltip : IProvideTooltipInfo, INotifyOwnerChanged + { + readonly Actor self; + PowerManager powerManager; + DeveloperMode developerMode; + + public PowerTooltip(Actor self) + { + this.self = self; + powerManager = self.Owner.PlayerActor.Trait(); + developerMode = self.Owner.PlayerActor.Trait(); + } + + public bool IsTooltipVisible(Player forPlayer) + { + return forPlayer == self.Owner; + } + + public string TooltipText + { + get + { + return "Power Usage: {0}{1}".F(powerManager.PowerDrained, developerMode.UnlimitedPower ? "" : "/" + powerManager.PowerProvided); + } + } + + public void OnOwnerChanged(Actor self, Player oldOwner, Player newOwner) + { + powerManager = newOwner.PlayerActor.Trait(); + developerMode = newOwner.PlayerActor.Trait(); + } + } +} diff --git a/mods/ts/rules/civilian-structures.yaml b/mods/ts/rules/civilian-structures.yaml index 35bccf8495..b9a16aba55 100644 --- a/mods/ts/rules/civilian-structures.yaml +++ b/mods/ts/rules/civilian-structures.yaml @@ -1092,6 +1092,7 @@ CTDAM: Dimensions: 2, 5 Power: Amount: 200 + PowerTooltip: Armor: Type: heavy Health: diff --git a/mods/ts/rules/gdi-structures.yaml b/mods/ts/rules/gdi-structures.yaml index 814c0f34b3..bca918757d 100644 --- a/mods/ts/rules/gdi-structures.yaml +++ b/mods/ts/rules/gdi-structures.yaml @@ -30,6 +30,7 @@ GAPOWR: Amount: 100 InfiltrateForPowerOutage: AffectedByPowerOutage: + PowerTooltip: Targetable: TargetTypes: Ground, C4, DetonateAttack, SpyInfiltrate ScalePowerWithHealth: diff --git a/mods/ts/rules/nod-structures.yaml b/mods/ts/rules/nod-structures.yaml index e605cb0ac1..1010adeb39 100644 --- a/mods/ts/rules/nod-structures.yaml +++ b/mods/ts/rules/nod-structures.yaml @@ -31,6 +31,7 @@ NAPOWR: Targetable: TargetTypes: Ground, C4, DetonateAttack, SpyInfiltrate ScalePowerWithHealth: + PowerTooltip: DisabledOverlay: SelectionDecorations: VisualBounds: 88, 80, 2, -12 @@ -69,6 +70,7 @@ NAAPWR: TargetTypes: Ground, C4, DetonateAttack, SpyInfiltrate ScalePowerWithHealth: DisabledOverlay: + PowerTooltip: SelectionDecorations: VisualBounds: 100, 74, 0, -12