Merge pull request #5138 from Mailaender/disable-idle-overlay

Fixed the Dune 2000 outpost radar dish rotating when powered down
This commit is contained in:
Paul Chote
2014-04-21 00:59:38 +12:00
16 changed files with 55 additions and 20 deletions

View File

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

View File

@@ -18,17 +18,19 @@ namespace OpenRA.Graphics
public readonly Animation Animation; public readonly Animation Animation;
public readonly Func<WVec> OffsetFunc; public readonly Func<WVec> OffsetFunc;
public readonly Func<bool> DisableFunc; public readonly Func<bool> DisableFunc;
public readonly Func<bool> Paused;
public readonly Func<WPos, int> ZOffset; public readonly Func<WPos, int> ZOffset;
public AnimationWithOffset(Animation a, Func<WVec> offset, Func<bool> disable) 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) 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 = a;
this.Animation.Paused = pause;
this.OffsetFunc = offset; this.OffsetFunc = offset;
this.DisableFunc = disable; this.DisableFunc = disable;
this.ZOffset = zOffset; this.ZOffset = zOffset;
@@ -45,7 +47,7 @@ namespace OpenRA.Graphics
public static implicit operator AnimationWithOffset(Animation a) 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; } get { return anims[""].Animation; }
protected set { anims[""] = new AnimationWithOffset(value, protected set { anims[""] = new AnimationWithOffset(value,
anims[""].OffsetFunc, anims[""].DisableFunc, anims[""].ZOffset); } anims[""].OffsetFunc, anims[""].DisableFunc, anims[""].Paused, anims[""].ZOffset); }
} }
RenderSpritesInfo Info; RenderSpritesInfo Info;

View File

@@ -1,6 +1,6 @@
#region Copyright & License Information #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 * 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 * available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information, * 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)); var overlay = new Animation(rs.GetImage(init.self));
overlay.PlayThen(info.Sequence, () => buildComplete = false); overlay.PlayThen(info.Sequence, () => buildComplete = false);
rs.anims.Add("make_overlay_{0}".F(info.Sequence), 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, var muzzleFlash = new AnimationWithOffset(muzzleAnim,
() => PortOffset(self, port), () => PortOffset(self, port),
() => false, () => false,
() => false,
p => WithTurret.ZOffsetFromCenter(self, p, 1024)); p => WithTurret.ZOffsetFromCenter(self, p, 1024));
muzzles.Add(muzzleFlash); muzzles.Add(muzzleFlash);

View File

@@ -81,7 +81,7 @@ namespace OpenRA.Mods.RA.Buildings
{ {
for (var x = scanStart.X; x < scanEnd.X; x++) for (var x = scanStart.X; x < scanEnd.X; x++)
{ {
var pos = new CPos(x, y); var pos = new CPos(x, y);
var at = bi.GetBuildingAt(pos); var at = bi.GetBuildingAt(pos);
if (at == null || !at.IsInWorld || !at.HasTrait<GivesBuildableArea>()) if (at == null || !at.IsInWorld || !at.HasTrait<GivesBuildableArea>())
continue; continue;

View File

@@ -1,6 +1,6 @@
#region Copyright & License Information #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 * 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 * available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information, * as published by the Free Software Foundation. For more information,
@@ -9,6 +9,7 @@
#endregion #endregion
using System; using System;
using System.Linq;
using System.Collections.Generic; using System.Collections.Generic;
using OpenRA.Graphics; using OpenRA.Graphics;
using OpenRA.Mods.RA.Buildings; using OpenRA.Mods.RA.Buildings;
@@ -20,6 +21,7 @@ namespace OpenRA.Mods.RA.Render
public class RenderBuildingInfo : RenderSimpleInfo, Requires<BuildingInfo>, IPlaceBuildingDecoration public class RenderBuildingInfo : RenderSimpleInfo, Requires<BuildingInfo>, IPlaceBuildingDecoration
{ {
public readonly bool HasMakeAnimation = true; public readonly bool HasMakeAnimation = true;
public readonly bool PauseOnLowPower = false;
public override object Create(ActorInitializer init) { return new RenderBuilding(init, this);} 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 public class RenderBuilding : RenderSimple, INotifyDamageStateChanged
{ {
RenderBuildingInfo info;
public RenderBuilding(ActorInitializer init, RenderBuildingInfo info) public RenderBuilding(ActorInitializer init, RenderBuildingInfo info)
: this(init, info, () => 0) { } : this(init, info, () => 0) { }
@@ -42,6 +46,7 @@ namespace OpenRA.Mods.RA.Render
: base(init.self, baseFacing) : base(init.self, baseFacing)
{ {
var self = init.self; var self = init.self;
this.info = info;
// Work around a bogus crash // Work around a bogus crash
anim.PlayRepeating(NormalizeSequence(self, "idle")); anim.PlayRepeating(NormalizeSequence(self, "idle"));
@@ -59,6 +64,13 @@ namespace OpenRA.Mods.RA.Render
anim.PlayRepeating(NormalizeSequence(self, "idle")); anim.PlayRepeating(NormalizeSequence(self, "idle"));
foreach (var x in self.TraitsImplementing<INotifyBuildComplete>()) foreach (var x in self.TraitsImplementing<INotifyBuildComplete>())
x.BuildingComplete(self); 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) public void PlayCustomAnimThen(Actor self, string name, Action a)

View File

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

View File

@@ -1,6 +1,6 @@
#region Copyright & License Information #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 * 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 * available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information, * as published by the Free Software Foundation. For more information,
@@ -8,6 +8,7 @@
*/ */
#endregion #endregion
using System.Linq;
using OpenRA.FileFormats; using OpenRA.FileFormats;
using OpenRA.Graphics; using OpenRA.Graphics;
using OpenRA.Traits; using OpenRA.Traits;
@@ -23,6 +24,8 @@ namespace OpenRA.Mods.RA.Render
[Desc("Position relative to body")] [Desc("Position relative to body")]
public readonly WVec Offset = WVec.Zero; public readonly WVec Offset = WVec.Zero;
public readonly bool PauseOnLowPower = false;
public object Create(ActorInitializer init) { return new WithIdleOverlay(init.self, this); } public object Create(ActorInitializer init) { return new WithIdleOverlay(init.self, this); }
} }
@@ -35,14 +38,17 @@ namespace OpenRA.Mods.RA.Render
{ {
var rs = self.Trait<RenderSprites>(); var rs = self.Trait<RenderSprites>();
var body = self.Trait<IBodyOrientation>(); var body = self.Trait<IBodyOrientation>();
var disabled = self.TraitsImplementing<IDisable>();
buildComplete = !self.HasTrait<Building>(); // always render instantly for units buildComplete = !self.HasTrait<Building>(); // always render instantly for units
overlay = new Animation(rs.GetImage(self)); overlay = new Animation(rs.GetImage(self));
overlay.PlayRepeating(info.Sequence); overlay.PlayRepeating(info.Sequence);
rs.anims.Add("idle_overlay_{0}".F(info.Sequence), rs.anims.Add("idle_overlay_{0}".F(info.Sequence),
new AnimationWithOffset(overlay, new AnimationWithOffset(overlay,
() => body.LocalToWorld(info.Offset.Rotate(body.QuantizeOrientation(self, self.Orientation))), () => body.LocalToWorld(info.Offset.Rotate(body.QuantizeOrientation(self, self.Orientation))),
() => !buildComplete, p => WithTurret.ZOffsetFromCenter(self, p, 1))); () => !buildComplete,
() => info.PauseOnLowPower && disabled.Any(d => d.Disabled),
p => WithTurret.ZOffsetFromCenter(self, p, 1)));
} }
public void BuildingComplete(Actor self) public void BuildingComplete(Actor self)

View File

@@ -54,9 +54,10 @@ namespace OpenRA.Mods.RA.Render
var muzzleFlash = new Animation(render.GetImage(self), getFacing); var muzzleFlash = new Animation(render.GetImage(self), getFacing);
visible.Add(barrel, false); visible.Add(barrel, false);
anims.Add(barrel, anims.Add(barrel,
new AnimationWithOffset(muzzleFlash, new AnimationWithOffset(muzzleFlash,
() => info.IgnoreOffset ? WVec.Zero : arm.MuzzleOffset(self, barrel), () => info.IgnoreOffset ? WVec.Zero : arm.MuzzleOffset(self, barrel),
() => !visible[barrel], () => !visible[barrel],
() => false,
p => WithTurret.ZOffsetFromCenter(self, p, 2))); p => WithTurret.ZOffsetFromCenter(self, p, 2)));
} }
} }

View File

@@ -47,7 +47,7 @@ namespace OpenRA.Mods.RA.Render
rotorAnim.PlayRepeating(info.Sequence); rotorAnim.PlayRepeating(info.Sequence);
rs.anims.Add(info.Id, new AnimationWithOffset(rotorAnim, rs.anims.Add(info.Id, new AnimationWithOffset(rotorAnim,
() => body.LocalToWorld(info.Offset.Rotate(body.QuantizeOrientation(self, self.Orientation))), () => 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) 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 = new Animation(rs.GetImage(self), () => t.turretFacing);
anim.Play(info.Sequence); anim.Play(info.Sequence);
rs.anims.Add("turret_{0}".F(info.Turret), new AnimationWithOffset( 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 // Restrict turret facings to match the sprite
t.QuantizedFacings = anim.CurrentSequence.Facings; t.QuantizedFacings = anim.CurrentSequence.Facings;

View File

@@ -368,6 +368,8 @@ HQ:
RequiresPower: RequiresPower:
CanPowerDown: CanPowerDown:
DisabledOverlay: DisabledOverlay:
RenderBuilding:
PauseOnLowPower: yes
Health: Health:
HP: 750 HP: 750
RevealsShroud: RevealsShroud:
@@ -441,6 +443,8 @@ EYE:
RequiresPower: RequiresPower:
CanPowerDown: CanPowerDown:
DisabledOverlay: DisabledOverlay:
RenderBuilding:
PauseOnLowPower: yes
Health: Health:
HP: 1200 HP: 1200
RevealsShroud: RevealsShroud:

View File

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

View File

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

View File

@@ -507,6 +507,7 @@ GARADR:
Range: 10c0 Range: 10c0
WithIdleOverlay@DISH: WithIdleOverlay@DISH:
Sequence: idle-dish Sequence: idle-dish
PauseOnLowPower: yes
NARADR: NARADR:
Inherits: ^Building Inherits: ^Building
@@ -543,6 +544,7 @@ NARADR:
Range: 10c0 Range: 10c0
WithIdleOverlay@DISH: WithIdleOverlay@DISH:
Sequence: idle-dish Sequence: idle-dish
PauseOnLowPower: yes
GATECH: GATECH:
Inherits: ^Building Inherits: ^Building