Added refund tooltip.
This commit is contained in:
@@ -8,8 +8,10 @@
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using OpenRA.Mods.Common.Activities;
|
||||
using OpenRA.Mods.Common.Orders;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
@@ -20,13 +22,20 @@ namespace OpenRA.Mods.Common.Traits
|
||||
public readonly int RefundPercent = 50;
|
||||
public readonly string[] SellSounds = { };
|
||||
|
||||
public object Create(ActorInitializer init) { return new Sellable(this); }
|
||||
public object Create(ActorInitializer init) { return new Sellable(init.Self, this); }
|
||||
}
|
||||
|
||||
public class Sellable : UpgradableTrait<SellableInfo>, IResolveOrder
|
||||
public class Sellable : UpgradableTrait<SellableInfo>, IResolveOrder, IProvideTooltipInfo
|
||||
{
|
||||
public Sellable(SellableInfo info)
|
||||
: base(info) { }
|
||||
readonly Actor self;
|
||||
readonly Lazy<Health> health;
|
||||
|
||||
public Sellable(Actor self, SellableInfo info)
|
||||
: base(info)
|
||||
{
|
||||
this.self = self;
|
||||
health = Exts.Lazy(() => self.TraitOrDefault<Health>());
|
||||
}
|
||||
|
||||
public void ResolveOrder(Actor self, Order order)
|
||||
{
|
||||
@@ -57,5 +66,27 @@ namespace OpenRA.Mods.Common.Traits
|
||||
else
|
||||
self.QueueActivity(false, new Sell());
|
||||
}
|
||||
|
||||
public bool IsTooltipVisible(Player forPlayer)
|
||||
{
|
||||
if (self.World.OrderGenerator is SellOrderGenerator)
|
||||
return forPlayer == self.Owner;
|
||||
return false;
|
||||
}
|
||||
|
||||
public string TooltipText
|
||||
{
|
||||
get
|
||||
{
|
||||
var sellValue = self.GetSellValue() * Info.RefundPercent / 100;
|
||||
if (health.Value != null)
|
||||
{
|
||||
sellValue *= health.Value.HP;
|
||||
sellValue /= health.Value.MaxHP;
|
||||
}
|
||||
|
||||
return "Refund: " + sellValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user