Merge pull request #10112 from DnAp/PowerTooltip

Closes #6011
This commit is contained in:
Matthias Mailänder
2016-01-07 20:57:14 +01:00
5 changed files with 58 additions and 0 deletions

View File

@@ -297,6 +297,7 @@
<Compile Include="Traits\Burns.cs" />
<Compile Include="Traits\C4Demolition.cs" />
<Compile Include="Traits\Health.cs" />
<Compile Include="Traits\PowerTooltip.cs" />
<Compile Include="Traits\VeteranProductionIconOverlay.cs" />
<Compile Include="Traits\Capturable.cs" />
<Compile Include="Traits\CaptureNotification.cs" />

View File

@@ -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<PowerManager>();
developerMode = self.Owner.PlayerActor.Trait<DeveloperMode>();
}
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<PowerManager>();
developerMode = newOwner.PlayerActor.Trait<DeveloperMode>();
}
}
}