From c4b925ffc32bc2fe3934fb379e80f986037734b6 Mon Sep 17 00:00:00 2001 From: DnAp Date: Mon, 28 Dec 2015 23:26:50 +0300 Subject: [PATCH] Make trait PowerTooltip --- OpenRA.Mods.Common/OpenRA.Mods.Common.csproj | 1 + OpenRA.Mods.Common/Traits/PowerTooltip.cs | 53 ++++++++++++++++++++ mods/ts/rules/civilian-structures.yaml | 1 + mods/ts/rules/gdi-structures.yaml | 1 + mods/ts/rules/nod-structures.yaml | 2 + 5 files changed, 58 insertions(+) create mode 100644 OpenRA.Mods.Common/Traits/PowerTooltip.cs diff --git a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj index ee5846cd43..0c7ff31ae8 100644 --- a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj +++ b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj @@ -293,6 +293,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 44e8a6404e..0c425c6d78 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 7bea3f31d9..5494968020 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 39db5143d0..9fb977ca2c 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