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