fix the weapon factory door opening animation

This commit is contained in:
Matthias Mailänder
2015-04-20 21:20:06 +02:00
parent 9c20de7d98
commit 9a37e77d1a
5 changed files with 126 additions and 24 deletions

View File

@@ -405,6 +405,7 @@
<Compile Include="Traits\Render\WithTurret.cs" /> <Compile Include="Traits\Render\WithTurret.cs" />
<Compile Include="Traits\Render\WithFire.cs" /> <Compile Include="Traits\Render\WithFire.cs" />
<Compile Include="Traits\Render\WithBuildingPlacedOverlay.cs" /> <Compile Include="Traits\Render\WithBuildingPlacedOverlay.cs" />
<Compile Include="Traits\Render\WithProductionDoorOverlay.cs" />
<Compile Include="Traits\Render\WithProductionOverlay.cs" /> <Compile Include="Traits\Render\WithProductionOverlay.cs" />
<Compile Include="Traits\Repairable.cs" /> <Compile Include="Traits\Repairable.cs" />
<Compile Include="Traits\RepairableNear.cs" /> <Compile Include="Traits\RepairableNear.cs" />

View File

@@ -0,0 +1,91 @@
#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 System.Collections.Generic;
using System.Linq;
using OpenRA.Graphics;
using OpenRA.Mods.Common.Graphics;
using OpenRA.Mods.Common.Traits;
using OpenRA.Traits;
namespace OpenRA.Mods.TS.Traits
{
[Desc("Play an animation when a unit exits or blocks the exit after production finished.")]
class WithProductionDoorOverlayInfo : ITraitInfo, IRenderActorPreviewSpritesInfo, Requires<RenderSpritesInfo>, Requires<IBodyOrientationInfo>, Requires<BuildingInfo>
{
public readonly string Sequence = "idle-door";
public readonly string BuildSequence = "build-door";
public object Create(ActorInitializer init) { return new WithProductionDoorOverlay(init.Self, this); }
public IEnumerable<IActorPreview> RenderPreviewSprites(ActorPreviewInitializer init, RenderSpritesInfo rs, string image, int facings, PaletteReference p)
{
var anim = new Animation(init.World, image, () => 0);
anim.PlayRepeating(Sequence);
var bi = init.Actor.Traits.Get<BuildingInfo>();
var offset = FootprintUtils.CenterOffset(init.World, bi).Y + 512; // Additional 512 units move from center -> top of cell
yield return new SpriteActorPreview(anim, WVec.Zero, offset, p, rs.Scale);
}
}
class WithProductionDoorOverlay : INotifyBuildComplete, ITick, INotifyProduction, INotifySold, INotifyDamageStateChanged
{
readonly WithProductionDoorOverlayInfo info;
readonly RenderSprites renderSprites;
readonly Animation door;
bool isOpen;
CPos openExit;
bool buildComplete;
public WithProductionDoorOverlay(Actor self, WithProductionDoorOverlayInfo info)
{
this.info = info;
renderSprites = self.Trait<RenderSprites>();
door = new Animation(self.World, renderSprites.GetImage(self));
door.Play(RenderSprites.NormalizeSequence(door, self.GetDamageState(), info.Sequence));
var buildingInfo = self.Info.Traits.Get<BuildingInfo>();
var offset = FootprintUtils.CenterOffset(self.World, buildingInfo).Y + 512;
renderSprites.Add("door_overlay_{0}".F(info.Sequence), new AnimationWithOffset(door, null, () => !buildComplete, offset));
}
public void BuildingComplete(Actor self)
{
buildComplete = true;
}
public void Tick(Actor self)
{
if (isOpen && !self.World.ActorMap.GetUnitsAt(openExit).Any(a => a != self))
{
isOpen = false;
door.PlayBackwardsThen(RenderSprites.NormalizeSequence(door, self.GetDamageState(), info.BuildSequence),
() => door.Play(RenderSprites.NormalizeSequence(door, self.GetDamageState(), info.Sequence)));
}
}
public void DamageStateChanged(Actor self, AttackInfo e)
{
if (door.CurrentSequence != null)
door.ReplaceAnim(RenderSprites.NormalizeSequence(door, e.DamageState, door.CurrentSequence.Name));
}
public void UnitProduced(Actor self, Actor other, CPos exit)
{
door.PlayThen(RenderSprites.NormalizeSequence(door, self.GetDamageState(), info.BuildSequence), () => { isOpen = true; openExit = exit; });
}
public void Selling(Actor self) { buildComplete = false; }
public void Sold(Actor self) { }
}
}

View File

@@ -123,8 +123,6 @@ GAWEAP:
HP: 1000 HP: 1000
RevealsShroud: RevealsShroud:
Range: 4c0 Range: 4c0
-RenderBuilding:
RenderBuildingWarFactory:
RallyPoint: RallyPoint:
RallyPoint: 6,1 RallyPoint: 6,1
Exit@1: Exit@1:
@@ -134,6 +132,9 @@ GAWEAP:
Produces: Vehicle Produces: Vehicle
PrimaryBuilding: PrimaryBuilding:
ProductionBar: ProductionBar:
WithIdleOverlay@ROOF:
Sequence: idle-roof
WithProductionDoorOverlay@DOOR:
WithProductionOverlay@WHITELIGHTS: WithProductionOverlay@WHITELIGHTS:
Sequence: production-lights-white Sequence: production-lights-white
WithProductionOverlay@REDLIGHTS: WithProductionOverlay@REDLIGHTS:

View File

@@ -130,8 +130,6 @@ NAWEAP:
HP: 1000 HP: 1000
RevealsShroud: RevealsShroud:
Range: 4c0 Range: 4c0
-RenderBuilding:
RenderBuildingWarFactory:
RallyPoint: RallyPoint:
RallyPoint: 6,1 RallyPoint: 6,1
Exit@1: Exit@1:
@@ -141,6 +139,9 @@ NAWEAP:
Produces: Vehicle Produces: Vehicle
PrimaryBuilding: PrimaryBuilding:
ProductionBar: ProductionBar:
WithIdleOverlay@ROOF:
Sequence: idle-roof
WithProductionDoorOverlay@DOOR:
WithProductionOverlay@LIGHTS: WithProductionOverlay@LIGHTS:
Sequence: production-lights Sequence: production-lights
WithIdleOverlay@BIB: WithIdleOverlay@BIB:

View File

@@ -136,12 +136,17 @@ gaweap:
Defaults: Defaults:
Offset: -12, -42 Offset: -12, -42
UseTilesetCode: true UseTilesetCode: true
idle: idle: gtweap_1
ShadowStart: 3 ShadowStart: 2
damaged-idle: damaged-idle: gtweap_1
Start: 1 Start: 1
ShadowStart: 4 ShadowStart: 3
dead: idle-roof: gtweap_2
ShadowStart: 2
damaged-idle-roof: gtweap_2
Start: 1
ShadowStart: 3
dead: gtweap
Start: 2 Start: 2
ShadowStart: 5 ShadowStart: 5
Tick: 400 Tick: 400
@@ -171,14 +176,14 @@ gaweap:
Length: 4 Length: 4
Tick: 80 Tick: 80
ZOffset: 2048 ZOffset: 2048
build-top: gtweap_d build-door: gtweap_d
Length: 9 Length: 9
ShadowStart: 9 ShadowStart: 9
damaged-build-top: gtweap_d damaged-build-door: gtweap_d
Length: 9 Length: 9
ShadowStart: 9 ShadowStart: 9
idle-top: gtweap_2 idle-door: gtweap_d
damaged-idle-top: gtweap_2 damaged-idle-door: gtweap_d
Start: 1 Start: 1
make: gtweapmk make: gtweapmk
Length: 20 Length: 20
@@ -195,7 +200,6 @@ gaweap:
icon: weapicon icon: weapicon
Offset: 0, 0 Offset: 0, 0
UseTilesetCode: false UseTilesetCode: false
# TODO: gtweap_1 & gtweap_a & gtweap_b & gtweap_c are unused
napowr: napowr:
Defaults: Defaults:
@@ -289,12 +293,17 @@ naweap:
Defaults: Defaults:
Offset: -12, -42 Offset: -12, -42
UseTilesetCode: true UseTilesetCode: true
idle: idle: ntweap_1
ShadowStart: 3 ShadowStart: 2
damaged-idle: damaged-idle: ntweap_1
Start: 1 Start: 1
ShadowStart: 4 ShadowStart: 3
dead: idle-roof: ntweap_2
ShadowStart: 2
damaged-idle-roof: ntweap_2
Start: 1
ShadowStart: 3
dead: ntweap
Start: 2 Start: 2
ShadowStart: 5 ShadowStart: 5
Tick: 400 Tick: 400
@@ -307,15 +316,15 @@ naweap:
Length: 16 Length: 16
Tick: 100 Tick: 100
ZOffset: 2048 ZOffset: 2048
build-top: ntweap_b build-door: ntweap_b
Length: 10 Length: 10
ShadowStart: 10 ShadowStart: 10
damaged-build-top: ntweap_b damaged-build-door: ntweap_b
Start: 10 Start: 10
Length: 10 Length: 10
ShadowStart: 20 ShadowStart: 20
idle-top: ntweap_2 idle-door: ntweap_b
damaged-idle-top: ntweap_2 damaged-idle-door: ntweap_b
Start: 1 Start: 1
make: ntweapmk make: ntweapmk
Length: 22 Length: 22
@@ -329,7 +338,6 @@ naweap:
icon: nwepicon icon: nwepicon
Offset: 0, 0 Offset: 0, 0
UseTilesetCode: false UseTilesetCode: false
# TODO: ntweap_1 & ntweap_b & ntweap_c are unused
naradr: naradr:
Defaults: Defaults: