@@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -260,8 +260,8 @@ CONCRETEB:
|
||||
ProductionBar:
|
||||
ProvidesCustomPrerequisite:
|
||||
Prerequisite: Light
|
||||
WithIdleOverlay@WELDING:
|
||||
Sequence: idle-welding
|
||||
WithProductionOverlay@WELDING:
|
||||
Sequence: production-welding
|
||||
|
||||
^HEAVY:
|
||||
Inherits: ^Building
|
||||
@@ -300,8 +300,8 @@ CONCRETEB:
|
||||
ProductionBar:
|
||||
ProvidesCustomPrerequisite:
|
||||
Prerequisite: Heavy
|
||||
WithIdleOverlay@WELDING:
|
||||
Sequence: idle-welding
|
||||
WithProductionOverlay@WELDING:
|
||||
Sequence: production-welding
|
||||
|
||||
^RADAR:
|
||||
Inherits: ^Building
|
||||
@@ -603,8 +603,8 @@ WALL:
|
||||
Range: 4c0
|
||||
ProvidesCustomPrerequisite:
|
||||
Prerequisite: Hitech
|
||||
WithIdleOverlay@WELDING:
|
||||
Sequence: idle-welding
|
||||
# WithProductionOverlay@WELDING:
|
||||
# Sequence: production-welding
|
||||
|
||||
^RESEARCH:
|
||||
Inherits: ^Building
|
||||
|
||||
@@ -514,7 +514,7 @@ hightecha:
|
||||
damaged-idle: DATA
|
||||
Start: 2565
|
||||
Offset: -48,80
|
||||
idle-welding: DATA
|
||||
production-welding: DATA
|
||||
Start: 4614
|
||||
Length: 30
|
||||
Offset: -48,80
|
||||
@@ -690,7 +690,7 @@ lighta:
|
||||
damaged-idle-top: DATA
|
||||
Start: 2675
|
||||
Offset: -48,64
|
||||
idle-welding: DATA
|
||||
production-welding: DATA
|
||||
Start: 4644
|
||||
Length: 30
|
||||
Offset: -48,64
|
||||
@@ -739,7 +739,7 @@ heavya:
|
||||
damaged-idle-top: DATA
|
||||
Start: 2520
|
||||
Offset: -48,80
|
||||
idle-welding: DATA
|
||||
production-welding: DATA
|
||||
Start: 4674
|
||||
Length: 47
|
||||
Offset: -48,80
|
||||
@@ -1005,7 +1005,7 @@ hightechh:
|
||||
damaged-idle: DATA
|
||||
Start: 2725
|
||||
Offset: -48,80
|
||||
idle-welding: DATA
|
||||
production-welding: DATA
|
||||
Start: 4614
|
||||
Length: 30
|
||||
Offset: -48,80
|
||||
@@ -1090,7 +1090,7 @@ lighth:
|
||||
damaged-idle-top: DATA
|
||||
Start: 2835
|
||||
Offset: -48,64
|
||||
idle-welding: DATA
|
||||
production-welding: DATA
|
||||
Start: 4644
|
||||
Length: 30
|
||||
Offset: -48,64
|
||||
@@ -1139,7 +1139,7 @@ heavyh:
|
||||
damaged-idle-top: DATA
|
||||
Start: 2680
|
||||
Offset: -48,80
|
||||
idle-welding: DATA
|
||||
production-welding: DATA
|
||||
Start: 4674
|
||||
Length: 47
|
||||
Offset: -48,80
|
||||
@@ -1406,7 +1406,7 @@ hightecho:
|
||||
damaged-idle: DATA
|
||||
Start: 2885
|
||||
Offset: -48,80
|
||||
idle-welding: DATA
|
||||
production-welding: DATA
|
||||
Start: 4614
|
||||
Length: 30
|
||||
Offset: -48,80
|
||||
@@ -1483,7 +1483,7 @@ lighto:
|
||||
damaged-idle-top: DATA
|
||||
Start: 2995
|
||||
Offset: -48,64
|
||||
idle-welding: DATA
|
||||
production-welding: DATA
|
||||
Start: 4644
|
||||
Length: 30
|
||||
Offset: -48,64
|
||||
@@ -1532,7 +1532,7 @@ heavyo:
|
||||
damaged-idle-top: DATA
|
||||
Start: 2840
|
||||
Offset: -48,80
|
||||
idle-welding: DATA
|
||||
production-welding: DATA
|
||||
Start: 4674
|
||||
Length: 47
|
||||
Offset: -48,80
|
||||
@@ -1647,7 +1647,7 @@ heavyc: # TODO: unused
|
||||
damaged-idle-top: DATA
|
||||
Start: 3003
|
||||
Offset: -48,64
|
||||
idle-welding: DATA
|
||||
production-welding: DATA
|
||||
Start: 4674
|
||||
Length: 47
|
||||
Offset: -48,80
|
||||
|
||||
Reference in New Issue
Block a user