@@ -83,6 +83,7 @@
|
||||
<Compile Include="FogPaletteFromR8.cs" />
|
||||
<Compile Include="DamagedWithoutFoundation.cs" />
|
||||
<Compile Include="Render\WithBuildingPlacedOverlayInfo.cs" />
|
||||
<Compile Include="Render\WithProductionOverlay.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<PropertyGroup>
|
||||
|
||||
95
OpenRA.Mods.D2k/Render/WithProductionOverlay.cs
Normal file
95
OpenRA.Mods.D2k/Render/WithProductionOverlay.cs
Normal file
@@ -0,0 +1,95 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2014 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 System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.FileFormats;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Mods.RA.Buildings;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.RA.Render
|
||||
{
|
||||
public class WithProductionOverlayInfo : ITraitInfo, Requires<RenderSpritesInfo>, Requires<IBodyOrientationInfo>
|
||||
{
|
||||
[Desc("Sequence name to use")]
|
||||
public readonly string Sequence = "production-overlay";
|
||||
|
||||
[Desc("Position relative to body")]
|
||||
public readonly WVec Offset = WVec.Zero;
|
||||
|
||||
public object Create(ActorInitializer init) { return new WithProductionOverlay(init.self, this); }
|
||||
}
|
||||
|
||||
public class WithProductionOverlay : INotifyDamageStateChanged, ITick, INotifyBuildComplete, INotifySold
|
||||
{
|
||||
Animation overlay;
|
||||
ProductionQueue queue;
|
||||
bool buildComplete;
|
||||
|
||||
bool IsProducing
|
||||
{
|
||||
get { return queue != null && queue.CurrentItem() != null && !queue.CurrentPaused; }
|
||||
}
|
||||
|
||||
public WithProductionOverlay(Actor self, WithProductionOverlayInfo info)
|
||||
{
|
||||
var rs = self.Trait<RenderSprites>();
|
||||
var body = self.Trait<IBodyOrientation>();
|
||||
|
||||
buildComplete = !self.HasTrait<Building>(); // always render instantly for units
|
||||
|
||||
overlay = new Animation(rs.GetImage(self));
|
||||
overlay.PlayRepeating(info.Sequence);
|
||||
rs.anims.Add("production_overlay_{0}".F(info.Sequence),
|
||||
new AnimationWithOffset(overlay,
|
||||
() => body.LocalToWorld(info.Offset.Rotate(body.QuantizeOrientation(self, self.Orientation))),
|
||||
() => !IsProducing || !buildComplete));
|
||||
}
|
||||
|
||||
public void Tick(Actor self)
|
||||
{
|
||||
// search for the queue here once so we don't rely on order of trait initialization
|
||||
if (queue == null)
|
||||
{
|
||||
var production = self.TraitOrDefault<Production>();
|
||||
|
||||
var perBuildingQueues = self.TraitsImplementing<ProductionQueue>();
|
||||
queue = perBuildingQueues.FirstOrDefault(q => production.Info.Produces.Contains(q.Info.Type));
|
||||
|
||||
if (queue == null)
|
||||
{
|
||||
var perPlayerQueues = self.Owner.PlayerActor.TraitsImplementing<ProductionQueue>();
|
||||
queue = perPlayerQueues.FirstOrDefault(q => production.Info.Produces.Contains(q.Info.Type));
|
||||
}
|
||||
|
||||
if (queue == null)
|
||||
throw new InvalidOperationException("Can't find production queues.");
|
||||
}
|
||||
}
|
||||
|
||||
public void BuildingComplete(Actor self)
|
||||
{
|
||||
buildComplete = true;
|
||||
}
|
||||
|
||||
public void Sold(Actor self) { }
|
||||
public void Selling(Actor self)
|
||||
{
|
||||
buildComplete = false;
|
||||
}
|
||||
|
||||
public void DamageStateChanged(Actor self, AttackInfo e)
|
||||
{
|
||||
overlay.ReplaceAnim(RenderSprites.NormalizeSequence(overlay, e.DamageState, overlay.CurrentSequence.Name));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user