win
git-svn-id: svn://svn.ijw.co.nz/svn/OpenRa@1288 993157c7-ee19-0410-b2c4-bb4e9862e678
This commit is contained in:
@@ -7,10 +7,12 @@ namespace OpenRa.Game
|
|||||||
{
|
{
|
||||||
class ConstructionYard : Actor
|
class ConstructionYard : Actor
|
||||||
{
|
{
|
||||||
static Range<int> normalSequence = UnitSheetBuilder.GetUnit("fact");
|
const string name = "fact";
|
||||||
static Range<int> makeSequence = UnitSheetBuilder.GetUnit("factmake");
|
|
||||||
|
|
||||||
Range<int> sequence = makeSequence;
|
static Sequence idle = SequenceProvider.GetSequence(name, "idle");
|
||||||
|
static Sequence make = SequenceProvider.GetSequence(name, "make");
|
||||||
|
|
||||||
|
Sequence current = make;
|
||||||
int frame = -1;
|
int frame = -1;
|
||||||
|
|
||||||
public ConstructionYard(float2 location, int palette)
|
public ConstructionYard(float2 location, int palette)
|
||||||
@@ -23,16 +25,14 @@ namespace OpenRa.Game
|
|||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
if ((sequence.Start == makeSequence.Start) && ++frame >= sequence.End - sequence.Start)
|
if ((current == make) && ++frame >= current.Length)
|
||||||
{
|
{
|
||||||
frame = 0;
|
frame = 0;
|
||||||
sequence = normalSequence;
|
current = idle;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Sprite[] { UnitSheetBuilder.sprites[sequence.Start + frame] };
|
return new Sprite[] { current.GetSprite(frame) };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Tick(World world, double t) { }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,12 +41,14 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="Actor.cs" />
|
<Compile Include="Actor.cs" />
|
||||||
|
<Compile Include="Sequence.cs" />
|
||||||
<Compile Include="ConstructionYard.cs" />
|
<Compile Include="ConstructionYard.cs" />
|
||||||
<Compile Include="float2.cs" />
|
<Compile Include="float2.cs" />
|
||||||
<Compile Include="int2.cs" />
|
<Compile Include="int2.cs" />
|
||||||
<Compile Include="ISelectable.cs" />
|
<Compile Include="ISelectable.cs" />
|
||||||
<Compile Include="MoveOrder.cs" />
|
<Compile Include="MoveOrder.cs" />
|
||||||
<Compile Include="Region.cs" />
|
<Compile Include="Region.cs" />
|
||||||
|
<Compile Include="SequenceProvider.cs" />
|
||||||
<Compile Include="SheetBuilder.cs" />
|
<Compile Include="SheetBuilder.cs" />
|
||||||
<Compile Include="HardwarePalette.cs" />
|
<Compile Include="HardwarePalette.cs" />
|
||||||
<Compile Include="MainWindow.cs">
|
<Compile Include="MainWindow.cs">
|
||||||
|
|||||||
@@ -9,7 +9,8 @@ namespace OpenRa.Game
|
|||||||
{
|
{
|
||||||
class Refinery : Actor
|
class Refinery : Actor
|
||||||
{
|
{
|
||||||
static Range<int> sequence = UnitSheetBuilder.GetUnit("proc");
|
const string name = "proc";
|
||||||
|
static Sequence idle = SequenceProvider.GetSequence(name, "idle");
|
||||||
|
|
||||||
public Refinery(float2 location, int palette)
|
public Refinery(float2 location, int palette)
|
||||||
{
|
{
|
||||||
@@ -17,14 +18,9 @@ namespace OpenRa.Game
|
|||||||
this.palette = palette;
|
this.palette = palette;
|
||||||
}
|
}
|
||||||
|
|
||||||
int GetFrame() { return 1; }
|
|
||||||
|
|
||||||
public override Sprite[] CurrentImages
|
public override Sprite[] CurrentImages
|
||||||
{
|
{
|
||||||
get
|
get { return new Sprite[] { idle.GetSprite(0) }; }
|
||||||
{
|
|
||||||
return new Sprite[] { UnitSheetBuilder.sprites[sequence.Start + GetFrame()] };
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
41
OpenRa.Game/Sequence.cs
Normal file
41
OpenRa.Game/Sequence.cs
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
using BluntDirectX.Direct3D;
|
||||||
|
using System.Xml;
|
||||||
|
|
||||||
|
namespace OpenRa.Game
|
||||||
|
{
|
||||||
|
class Sequence
|
||||||
|
{
|
||||||
|
readonly int start, length;
|
||||||
|
|
||||||
|
public int Start { get { return start; } }
|
||||||
|
public int End { get { return start + length; } }
|
||||||
|
public int Length { get { return length; } }
|
||||||
|
|
||||||
|
public Sequence(string unit, XmlElement e)
|
||||||
|
{
|
||||||
|
string srcOverride = e.GetAttribute("src");
|
||||||
|
|
||||||
|
Range<int> src = UnitSheetBuilder.GetUnit(
|
||||||
|
string.IsNullOrEmpty(srcOverride) ? unit : srcOverride);
|
||||||
|
|
||||||
|
start = src.Start + int.Parse(e.GetAttribute("start"));
|
||||||
|
|
||||||
|
if (e.GetAttribute("length") == "*" || e.GetAttribute("end") == "*")
|
||||||
|
length = src.End - start;
|
||||||
|
else if (e.HasAttribute("length"))
|
||||||
|
length = int.Parse(e.GetAttribute("length"));
|
||||||
|
else if (e.HasAttribute("end"))
|
||||||
|
length = int.Parse(e.GetAttribute("end")) - start;
|
||||||
|
else
|
||||||
|
length = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Sprite GetSprite(int frame)
|
||||||
|
{
|
||||||
|
return UnitSheetBuilder.sprites[frame + start];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
38
OpenRa.Game/SequenceProvider.cs
Normal file
38
OpenRa.Game/SequenceProvider.cs
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
using System.Xml;
|
||||||
|
|
||||||
|
namespace OpenRa.Game
|
||||||
|
{
|
||||||
|
static class SequenceProvider
|
||||||
|
{
|
||||||
|
static Dictionary<string, Dictionary<string, Sequence>> units =
|
||||||
|
new Dictionary<string, Dictionary<string, Sequence>>();
|
||||||
|
|
||||||
|
static SequenceProvider()
|
||||||
|
{
|
||||||
|
XmlDocument document = new XmlDocument();
|
||||||
|
document.Load("../../../sequences.xml");
|
||||||
|
|
||||||
|
foreach (XmlElement eUnit in document.SelectNodes("/sequences/unit"))
|
||||||
|
LoadSequencesForUnit(eUnit);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void LoadSequencesForUnit(XmlElement eUnit)
|
||||||
|
{
|
||||||
|
string unitName = eUnit.GetAttribute("name");
|
||||||
|
Dictionary<string, Sequence> sequences = new Dictionary<string, Sequence>();
|
||||||
|
|
||||||
|
foreach (XmlElement eSequence in eUnit.SelectNodes("./sequence"))
|
||||||
|
sequences.Add(eSequence.GetAttribute("name"), new Sequence(unitName, eSequence));
|
||||||
|
|
||||||
|
units.Add(unitName, sequences);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Sequence GetSequence(string unitName, string sequenceName)
|
||||||
|
{
|
||||||
|
return units[unitName][sequenceName];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
51
sequences.xml
Normal file
51
sequences.xml
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
|
|
||||||
|
<!-- openra/sequences.xml
|
||||||
|
|
||||||
|
this file describes animation sequences for structures and units.
|
||||||
|
|
||||||
|
<sequence src=...> can be used to override the choice of .shp file
|
||||||
|
used to extract a sequence. if it is not present, the .shp matching
|
||||||
|
the unit name is used instead.
|
||||||
|
|
||||||
|
either of <sequence length=...> or <sequence end=...> are
|
||||||
|
recognized; if neither is present, a 1-frame sequence is assumed
|
||||||
|
|
||||||
|
also, <sequence length="*"> creates a sequence that includes all frames
|
||||||
|
after `start`.
|
||||||
|
|
||||||
|
one day, we might support inheritance here too.
|
||||||
|
|
||||||
|
standard sequence names:
|
||||||
|
idle - doing nothing
|
||||||
|
make - deploy (sell is `make` played backwards)
|
||||||
|
build - production building doing something
|
||||||
|
|
||||||
|
damaged-idle - doing nothing while on yellow health (or worse)
|
||||||
|
damaged-build - production while on yellow health
|
||||||
|
|
||||||
|
author: C. Forbes
|
||||||
|
|
||||||
|
-->
|
||||||
|
|
||||||
|
<sequences>
|
||||||
|
|
||||||
|
<!-- construction yard -->
|
||||||
|
|
||||||
|
<unit name="fact">
|
||||||
|
<sequence name="idle" start="0"/>
|
||||||
|
<sequence name="make" start="0" length="32" src="factmake" />
|
||||||
|
<sequence name="build" start="1" length="25"/>
|
||||||
|
<sequence name="damaged-idle" start="26"/>
|
||||||
|
<sequence name="damaged-build" start="27" length="25"/>
|
||||||
|
</unit>
|
||||||
|
|
||||||
|
<!-- refinery -->
|
||||||
|
|
||||||
|
<unit name="proc">
|
||||||
|
<sequence name="idle" start="0"/>
|
||||||
|
<sequence name="damaged-idle" start="1"/>
|
||||||
|
<sequence name="make" start="0" length="*" src="procmake" />
|
||||||
|
</unit>
|
||||||
|
|
||||||
|
</sequences>
|
||||||
Reference in New Issue
Block a user