fixed #42 -- show harvester fullness in sprites

This commit is contained in:
Chris Forbes
2011-07-17 14:39:53 +12:00
parent 9dd0ad980b
commit fe6a99c993
7 changed files with 84 additions and 1 deletions

View File

@@ -0,0 +1,50 @@
#region Copyright & License Information
/*
* Copyright 2007-2011 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.Traits;
using OpenRA.Mods.RA.Orders;
namespace OpenRA.Mods.RA.Render
{
class RenderHarvesterInfo : RenderUnitInfo, Requires<HarvesterInfo>
{
public readonly string[] ImagesByFullness = { "harvempty", "harvhalf", "harv" };
public override object Create(ActorInitializer init) { return new RenderHarvester(init.self, this); }
}
class RenderHarvester : RenderUnit
{
Harvester harv;
RenderHarvesterInfo info;
public RenderHarvester(Actor self, RenderHarvesterInfo info) : base(self)
{
this.info = info;
harv = self.Trait<Harvester>();
foreach( var image in info.ImagesByFullness )
new Animation( image ); /* just force these to get loaded upfront */
}
public override void Tick(Actor self)
{
var desiredState = (int)(harv.Fullness * (info.ImagesByFullness.Length - 1));
var desiredImage = info.ImagesByFullness[desiredState];
if (anim.Name != desiredImage)
anim.ChangeImage( desiredImage, "idle" );
base.Tick(self);
}
}
}