allow animations to pause on low power

closes #2949
This commit is contained in:
Matthias Mailänder
2014-04-20 13:30:03 +02:00
parent 9d02118e51
commit 01a3162725
15 changed files with 47 additions and 20 deletions

View File

@@ -15,14 +15,16 @@ namespace OpenRA.Graphics
{
public class Animation
{
string name;
public Sequence CurrentSequence { get; private set; }
public bool IsDecoration = false;
public Func<bool> Paused;
Func<int> facingFunc;
int frame = 0;
bool backwards = false;
bool tickAlways;
Func<int> facingFunc;
string name;
public string Name { get { return name; } }
@@ -122,6 +124,7 @@ namespace OpenRA.Graphics
public void Tick()
{
if (Paused == null || !Paused())
Tick(40); // tick one frame
}

View File

@@ -18,17 +18,19 @@ namespace OpenRA.Graphics
public readonly Animation Animation;
public readonly Func<WVec> OffsetFunc;
public readonly Func<bool> DisableFunc;
public readonly Func<bool> Paused;
public readonly Func<WPos, int> ZOffset;
public AnimationWithOffset(Animation a, Func<WVec> offset, Func<bool> disable)
: this(a, offset, disable, null) { }
: this(a, offset, disable, () => false, null) { }
public AnimationWithOffset(Animation a, Func<WVec> offset, Func<bool> disable, int zOffset)
: this(a, offset, disable, _ => zOffset) { }
: this(a, offset, disable, () => false, _ => zOffset) { }
public AnimationWithOffset(Animation a, Func<WVec> offset, Func<bool> disable, Func<WPos, int> zOffset)
public AnimationWithOffset(Animation a, Func<WVec> offset, Func<bool> disable, Func<bool> pause, Func<WPos, int> zOffset)
{
this.Animation = a;
this.Animation.Paused = pause;
this.OffsetFunc = offset;
this.DisableFunc = disable;
this.ZOffset = zOffset;
@@ -45,7 +47,7 @@ namespace OpenRA.Graphics
public static implicit operator AnimationWithOffset(Animation a)
{
return new AnimationWithOffset(a, null, null, null);
return new AnimationWithOffset(a, null, null, null, null);
}
}
}

View File

@@ -46,7 +46,7 @@ namespace OpenRA.Traits
{
get { return anims[""].Animation; }
protected set { anims[""] = new AnimationWithOffset(value,
anims[""].OffsetFunc, anims[""].DisableFunc, anims[""].ZOffset); }
anims[""].OffsetFunc, anims[""].DisableFunc, anims[""].Paused, anims[""].ZOffset); }
}
RenderSpritesInfo Info;

View File

@@ -1,6 +1,6 @@
#region Copyright & License Information
/*
* Copyright 2007-2013 The OpenRA Developers (see AUTHORS)
* 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,
@@ -35,7 +35,7 @@ namespace OpenRA.Mods.RA.Render
var overlay = new Animation(rs.GetImage(init.self));
overlay.PlayThen(info.Sequence, () => buildComplete = false);
rs.anims.Add("make_overlay_{0}".F(info.Sequence),
new AnimationWithOffset(overlay, null, () => !buildComplete, null));
new AnimationWithOffset(overlay, null, () => !buildComplete));
}
}

View File

@@ -164,6 +164,7 @@ namespace OpenRA.Mods.RA
var muzzleFlash = new AnimationWithOffset(muzzleAnim,
() => PortOffset(self, port),
() => false,
() => false,
p => WithTurret.ZOffsetFromCenter(self, p, 1024));
muzzles.Add(muzzleFlash);

View File

@@ -1,6 +1,6 @@
#region Copyright & License Information
/*
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
* 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,
@@ -9,6 +9,7 @@
#endregion
using System;
using System.Linq;
using System.Collections.Generic;
using OpenRA.Graphics;
using OpenRA.Mods.RA.Buildings;
@@ -20,6 +21,7 @@ namespace OpenRA.Mods.RA.Render
public class RenderBuildingInfo : RenderSimpleInfo, Requires<BuildingInfo>, IPlaceBuildingDecoration
{
public readonly bool HasMakeAnimation = true;
public readonly bool PauseOnLowPower = false;
public override object Create(ActorInitializer init) { return new RenderBuilding(init, this);}
@@ -35,6 +37,8 @@ namespace OpenRA.Mods.RA.Render
public class RenderBuilding : RenderSimple, INotifyDamageStateChanged
{
RenderBuildingInfo info;
public RenderBuilding(ActorInitializer init, RenderBuildingInfo info)
: this(init, info, () => 0) { }
@@ -42,6 +46,7 @@ namespace OpenRA.Mods.RA.Render
: base(init.self, baseFacing)
{
var self = init.self;
this.info = info;
// Work around a bogus crash
anim.PlayRepeating(NormalizeSequence(self, "idle"));
@@ -59,6 +64,13 @@ namespace OpenRA.Mods.RA.Render
anim.PlayRepeating(NormalizeSequence(self, "idle"));
foreach (var x in self.TraitsImplementing<INotifyBuildComplete>())
x.BuildingComplete(self);
if (info.PauseOnLowPower)
{
var disabled = self.TraitsImplementing<IDisable>();
anim.Paused = () => disabled.Any(d => d.Disabled)
&& anim.CurrentSequence.Name == NormalizeSequence(self, "idle");
}
}
public void PlayCustomAnimThen(Actor self, string name, Action a)

View File

@@ -42,6 +42,7 @@ namespace OpenRA.Mods.RA.Render
rs.anims.Add("harvest_{0}".F(info.Sequence), new AnimationWithOffset(anim,
() => body.LocalToWorld(info.Offset.Rotate(body.QuantizeOrientation(self, self.Orientation))),
() => !visible,
() => false,
p => WithTurret.ZOffsetFromCenter(self, p, 0)));
}

View File

@@ -24,7 +24,7 @@ namespace OpenRA.Mods.RA.Render
[Desc("Position relative to body")]
public readonly WVec Offset = WVec.Zero;
public readonly bool HideOnLowPower = false;
public readonly bool PauseOnLowPower = false;
public object Create(ActorInitializer init) { return new WithIdleOverlay(init.self, this); }
}
@@ -46,7 +46,8 @@ namespace OpenRA.Mods.RA.Render
rs.anims.Add("idle_overlay_{0}".F(info.Sequence),
new AnimationWithOffset(overlay,
() => body.LocalToWorld(info.Offset.Rotate(body.QuantizeOrientation(self, self.Orientation))),
() => !buildComplete || (info.HideOnLowPower && disabled.Any(d => d.Disabled)),
() => !buildComplete,
() => info.PauseOnLowPower && disabled.Any(d => d.Disabled),
p => WithTurret.ZOffsetFromCenter(self, p, 1)));
}

View File

@@ -57,6 +57,7 @@ namespace OpenRA.Mods.RA.Render
new AnimationWithOffset(muzzleFlash,
() => info.IgnoreOffset ? WVec.Zero : arm.MuzzleOffset(self, barrel),
() => !visible[barrel],
() => false,
p => WithTurret.ZOffsetFromCenter(self, p, 2)));
}
}

View File

@@ -47,7 +47,7 @@ namespace OpenRA.Mods.RA.Render
rotorAnim.PlayRepeating(info.Sequence);
rs.anims.Add(info.Id, new AnimationWithOffset(rotorAnim,
() => body.LocalToWorld(info.Offset.Rotate(body.QuantizeOrientation(self, self.Orientation))),
null, p => WithTurret.ZOffsetFromCenter(self, p, 1)));
null, () => false, p => WithTurret.ZOffsetFromCenter(self, p, 1)));
}
public void Tick(Actor self)

View File

@@ -58,7 +58,7 @@ namespace OpenRA.Mods.RA.Render
anim = new Animation(rs.GetImage(self), () => t.turretFacing);
anim.Play(info.Sequence);
rs.anims.Add("turret_{0}".F(info.Turret), new AnimationWithOffset(
anim, () => TurretOffset(self), null, p => ZOffsetFromCenter(self, p, 1)));
anim, () => TurretOffset(self), null, () => false, p => ZOffsetFromCenter(self, p, 1)));
// Restrict turret facings to match the sprite
t.QuantizedFacings = anim.CurrentSequence.Facings;

View File

@@ -367,6 +367,8 @@ HQ:
RequiresPower:
CanPowerDown:
DisabledOverlay:
RenderBuilding:
PauseOnLowPower: yes
Health:
HP: 750
RevealsShroud:
@@ -440,6 +442,8 @@ EYE:
RequiresPower:
CanPowerDown:
DisabledOverlay:
RenderBuilding:
PauseOnLowPower: yes
Health:
HP: 1200
RevealsShroud:

View File

@@ -338,7 +338,7 @@ CONCRETEB:
Prerequisite: Outpost
WithIdleOverlay@DISH:
Sequence: idle-dish
HideOnLowPower: yes
PauseOnLowPower: yes
^STARPORT:
Inherits: ^Building

View File

@@ -67,6 +67,8 @@ GAP:
RequiresPower:
CanPowerDown:
DisabledOverlay:
RenderBuilding:
PauseOnLowPower: yes
Health:
HP: 1000
Armor: