Sequence.facing idea/RFC.
This commit is contained in:
@@ -10,12 +10,20 @@ namespace OpenRa.Graphics
|
||||
bool backwards = false;
|
||||
bool tickAlways;
|
||||
|
||||
Func<int> facingFunc;
|
||||
|
||||
public string Name { get { return name; } }
|
||||
|
||||
public Animation( string name )
|
||||
: this( name, () => 0 )
|
||||
{
|
||||
}
|
||||
|
||||
public Animation( string name, Func<int> facingFunc )
|
||||
{
|
||||
this.name = name.ToLowerInvariant();
|
||||
tickFunc = () => { };
|
||||
this.tickFunc = () => { };
|
||||
this.facingFunc = facingFunc;
|
||||
}
|
||||
|
||||
public Sprite Image
|
||||
@@ -23,8 +31,8 @@ namespace OpenRa.Graphics
|
||||
get
|
||||
{
|
||||
return backwards
|
||||
? CurrentSequence.GetSprite(CurrentSequence.End - frame - 1)
|
||||
: CurrentSequence.GetSprite(frame);
|
||||
? CurrentSequence.GetSprite(CurrentSequence.End - frame - 1, facingFunc())
|
||||
: CurrentSequence.GetSprite(frame, facingFunc());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,12 +5,13 @@ namespace OpenRa.Graphics
|
||||
public class Sequence
|
||||
{
|
||||
readonly Sprite[] sprites;
|
||||
readonly int start, length;
|
||||
readonly int start, length, facings;
|
||||
|
||||
public readonly string Name;
|
||||
public int Start { get { return start; } }
|
||||
public int End { get { return start + length; } }
|
||||
public int Length { get { return length; } }
|
||||
public int Facings { get { return facings; } }
|
||||
|
||||
public Sequence(string unit, XmlElement e)
|
||||
{
|
||||
@@ -28,11 +29,22 @@ namespace OpenRa.Graphics
|
||||
length = int.Parse(e.GetAttribute("end")) - int.Parse(e.GetAttribute("start"));
|
||||
else
|
||||
length = 1;
|
||||
|
||||
if( e.HasAttribute( "facings" ) )
|
||||
facings = int.Parse( e.GetAttribute( "facings" ) );
|
||||
else
|
||||
facings = 1;
|
||||
}
|
||||
|
||||
public Sprite GetSprite(int frame)
|
||||
public Sprite GetSprite( int frame )
|
||||
{
|
||||
return sprites[ ( frame % length ) + start ];
|
||||
return GetSprite( frame, 0 );
|
||||
}
|
||||
|
||||
public Sprite GetSprite(int frame, int facing)
|
||||
{
|
||||
var f = Traits.Util.QuantizeFacing( facing, facings );
|
||||
return sprites[ (f * length) + ( frame % length ) + start ];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,12 +40,10 @@ namespace OpenRa.Traits.Activities
|
||||
!self.World.Map.Harvest(self.Location, out isGem))
|
||||
return false;
|
||||
|
||||
var harvestAnim = "harvest" + Util.QuantizeFacing(unit.Facing, 8);
|
||||
|
||||
if (harvestAnim != renderUnit.anim.CurrentSequence.Name)
|
||||
if (renderUnit.anim.CurrentSequence.Name != "harvest")
|
||||
{
|
||||
isHarvesting = true;
|
||||
renderUnit.PlayCustomAnimation(self, harvestAnim, () => isHarvesting = false);
|
||||
renderUnit.PlayCustomAnimation(self, "harvest", () => isHarvesting = false);
|
||||
}
|
||||
harv.AcceptResource(isGem);
|
||||
return true;
|
||||
|
||||
@@ -15,6 +15,7 @@ namespace OpenRa.Traits
|
||||
public RenderUnit(Actor self)
|
||||
: base(self)
|
||||
{
|
||||
anim = new Animation( GetImage( self ), () => self.traits.Get<Unit>().Facing );
|
||||
PlayFacingAnim(self);
|
||||
|
||||
anims.Add( "smoke", new AnimationWithOffset( new Animation( "smoke_m" ), null, () => !isSmoking ) );
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- openra/sequences.xml
|
||||
|
||||
this file describes animation sequences for structures and units.
|
||||
@@ -234,15 +234,8 @@
|
||||
</unit>
|
||||
<!-- harv -->
|
||||
<unit name="harv">
|
||||
<sequence name="idle" start="0" length="32" />
|
||||
<sequence name="harvest0" start="32" length="8" />
|
||||
<sequence name="harvest1" start="40" length="8" />
|
||||
<sequence name="harvest2" start="48" length="8" />
|
||||
<sequence name="harvest3" start="56" length="8" />
|
||||
<sequence name="harvest4" start="64" length="8" />
|
||||
<sequence name="harvest5" start="72" length="8" />
|
||||
<sequence name="harvest6" start="80" length="8" />
|
||||
<sequence name="harvest7" start="88" length="8" />
|
||||
<sequence name="idle" start="0" length="1" facings="32" />
|
||||
<sequence name="harvest" start="32" length="8" facings="8" />
|
||||
<sequence name="empty" start="96" length="15" />
|
||||
</unit>
|
||||
<!-- light tank -->
|
||||
|
||||
Reference in New Issue
Block a user