RenderBuildingSilo -> WithSiloAnimation

This commit is contained in:
reaperrr
2015-07-15 06:57:43 +02:00
parent 2df318cd3e
commit 69d062495c
8 changed files with 107 additions and 66 deletions

View File

@@ -411,7 +411,6 @@
<Compile Include="Traits\Render\RenderNameTag.cs" />
<Compile Include="Traits\Render\RenderSimple.cs" />
<Compile Include="Traits\Render\RenderSprites.cs" />
<Compile Include="Traits\Render\RenderBuildingSilo.cs" />
<Compile Include="Traits\Render\RenderBuildingWall.cs" />
<Compile Include="Traits\Render\RenderDetectionCircle.cs" />
<Compile Include="Traits\Render\RenderRangeCircle.cs" />
@@ -424,6 +423,7 @@
<Compile Include="Traits\Render\WithActiveAnimation.cs" />
<Compile Include="Traits\Render\WithAttackAnimation.cs" />
<Compile Include="Traits\Render\WithMoveAnimation.cs" />
<Compile Include="Traits\Render\WithSiloAnimation.cs" />
<Compile Include="Traits\Render\WithBuildingPlacedAnimation.cs" />
<Compile Include="Traits\Render\WithMakeAnimation.cs" />
<Compile Include="Traits\Render\WithChargeAnimation.cs" />

View File

@@ -1,61 +0,0 @@
#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 OpenRA.Graphics;
using OpenRA.Mods.Common.Graphics;
using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits
{
[Desc("Render trait for buildings that change the sprite according to the remaining resource storage capacity across all depots.")]
class RenderBuildingSiloInfo : RenderBuildingInfo
{
public override object Create(ActorInitializer init) { return new RenderBuildingSilo(init, this); }
public override IEnumerable<IActorPreview> RenderPreviewSprites(ActorPreviewInitializer init, RenderSpritesInfo rs, string image, int facings, PaletteReference p)
{
// Show a static frame instead of animating all of the fullness states
var anim = new Animation(init.World, image, () => 0);
anim.PlayFetchIndex(RenderSprites.NormalizeSequence(anim, init.GetDamageState(), Sequence), () => 0);
yield return new SpriteActorPreview(anim, WVec.Zero, 0, p, rs.Scale);
}
}
class RenderBuildingSilo : RenderBuilding, INotifyBuildComplete, INotifyOwnerChanged
{
readonly RenderBuildingSiloInfo info;
PlayerResources playerResources;
public RenderBuildingSilo(ActorInitializer init, RenderBuildingSiloInfo info)
: base(init, info)
{
this.info = info;
playerResources = init.Self.Owner.PlayerActor.Trait<PlayerResources>();
}
public override void BuildingComplete(Actor self)
{
var animation = RenderSprites.NormalizeSequence(DefaultAnimation, self.GetDamageState(), info.Sequence);
DefaultAnimation.PlayFetchIndex(animation,
() => playerResources.ResourceCapacity != 0
? ((10 * DefaultAnimation.CurrentSequence.Length - 1) * playerResources.Resources) / (10 * playerResources.ResourceCapacity)
: 0);
}
public override void OnOwnerChanged(Actor self, Player oldOwner, Player newOwner)
{
playerResources = newOwner.PlayerActor.Trait<PlayerResources>();
base.OnOwnerChanged(self, oldOwner, newOwner);
}
}
}

View File

@@ -0,0 +1,55 @@
#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 OpenRA.Graphics;
using OpenRA.Mods.Common.Graphics;
using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits
{
[Desc("Render trait for buildings that change the sprite according to the remaining resource storage capacity across all depots.")]
class WithSiloAnimationInfo : ITraitInfo, Requires<WithSpriteBodyInfo>, Requires<RenderSpritesInfo>
{
public readonly int Stages = 10;
public object Create(ActorInitializer init) { return new WithSiloAnimation(init, this); }
}
class WithSiloAnimation : INotifyBuildComplete, INotifyOwnerChanged
{
readonly WithSiloAnimationInfo info;
readonly WithSpriteBody wsb;
PlayerResources playerResources;
public WithSiloAnimation(ActorInitializer init, WithSiloAnimationInfo info)
{
this.info = info;
wsb = init.Self.Trait<WithSpriteBody>();
playerResources = init.Self.Owner.PlayerActor.Trait<PlayerResources>();
}
public void BuildingComplete(Actor self)
{
var animation = wsb.NormalizeSequence(self, wsb.Info.Sequence);
wsb.DefaultAnimation.PlayFetchIndex(animation,
() => playerResources.ResourceCapacity != 0
? ((info.Stages * wsb.DefaultAnimation.CurrentSequence.Length - 1) * playerResources.Resources) / (info.Stages * playerResources.ResourceCapacity)
: 0);
}
public void OnOwnerChanged(Actor self, Player oldOwner, Player newOwner)
{
playerResources = newOwner.PlayerActor.Trait<PlayerResources>();
OnOwnerChanged(self, oldOwner, newOwner);
}
}
}

View File

@@ -1841,6 +1841,40 @@ namespace OpenRA.Mods.Common.UtilityCommands
if (rrb != null)
rrb.Key = "-WithChargeAnimation";
}
// Replaced RenderBuildingSilo with RenderSprites + WithSpriteBody + WithSiloAnimation (+AutoSelectionSize)
if (depth == 0)
{
var childKeySequence = new[] { "Sequence", "PauseOnLowPower" };
var rb = node.Value.Nodes.FirstOrDefault(n => n.Key.StartsWith("RenderBuildingSilo"));
if (rb != null)
{
rb.Key = "WithSiloAnimation";
var rsNodes = rb.Value.Nodes.Where(n => !childKeySequence.Contains(n.Key)).ToList();
var wsbNodes = rb.Value.Nodes.Where(n => childKeySequence.Contains(n.Key)).ToList();
if (rsNodes.Any())
node.Value.Nodes.Add(new MiniYamlNode("RenderSprites", new MiniYaml("", rsNodes)));
else
node.Value.Nodes.Add(new MiniYamlNode("RenderSprites", ""));
if (wsbNodes.Any())
node.Value.Nodes.Add(new MiniYamlNode("WithSpriteBody", new MiniYaml("", wsbNodes)));
else
node.Value.Nodes.Add(new MiniYamlNode("WithSpriteBody", ""));
node.Value.Nodes.Add(new MiniYamlNode("AutoSelectionSize", ""));
rb.Value.Nodes.RemoveAll(n => rsNodes.Contains(n));
rb.Value.Nodes.RemoveAll(n => wsbNodes.Contains(n));
}
var rrb = node.Value.Nodes.FirstOrDefault(n => n.Key.StartsWith("-RenderBuildingSilo"));
if (rrb != null)
rrb.Key = "-WithSiloAnimation";
}
}
UpgradeActorRules(engineVersion, ref node.Value.Nodes, node, depth + 1);

View File

@@ -210,7 +210,10 @@ SILO:
Range: 4c0
Bib:
HasMinibib: Yes
RenderBuildingSilo:
RenderSprites:
WithSpriteBody:
AutoSelectionSize:
WithSiloAnimation:
StoresResources:
PipCount: 10
PipColor: Green
@@ -223,6 +226,7 @@ SILO:
RequiredForShortGame: false
SelectionDecorations:
VisualBounds: 49,30
-WithMakeAnimation:
PYLE:
Inherits: ^BaseBuilding

View File

@@ -242,11 +242,13 @@ silo:
RevealsShroud:
Range: 4c0
-RenderBuilding:
RenderBuildingSilo:
RenderSprites:
Image: silo.harkonnen
FactionImages:
atreides: silo.atreides
ordos: silo.ordos
WithSpriteBody:
WithSiloAnimation:
StoresResources:
PipColor: green
PipCount: 5
@@ -256,6 +258,7 @@ silo:
Amount: -5
MustBeDestroyed:
RequiredForShortGame: false
-WithMakeAnimation:
light:
Inherits: ^Building

View File

@@ -982,7 +982,9 @@ SILO:
Range: 4c0
Bib:
HasMinibib: Yes
RenderBuildingSilo:
RenderSprites:
WithSpriteBody:
WithSiloAnimation:
StoresResources:
PipCount: 5
Capacity: 1500
@@ -990,6 +992,7 @@ SILO:
-EmitInfantryOnSell:
Power:
Amount: -10
-WithMakeAnimation:
HPAD:
Inherits: ^Building

View File

@@ -127,11 +127,13 @@ GASILO:
RevealsShroud:
Range: 4c0
-RenderBuilding:
RenderBuildingSilo:
RenderSprites:
Image: gasilo.gdi
FactionImages:
gdi: gasilo.gdi
nod: gasilo.nod
WithSpriteBody:
WithSiloAnimation:
WithIdleOverlay@UNDERLAY:
Sequence: idle-underlay
WithIdleOverlay@LIGHTS:
@@ -143,6 +145,7 @@ GASILO:
Amount: -10
SelectionDecorations:
VisualBounds: 80, 48, -5, 0
-WithMakeAnimation:
ANYPOWER:
AlwaysVisible: