Beginnings of cursor support.

This commit is contained in:
Matthew Bowra-Dean
2009-10-15 18:37:24 +13:00
parent 05cbf6b680
commit 3deacd8062
5 changed files with 107 additions and 0 deletions

View File

@@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
namespace OpenRa.Game.Graphics
{
class CursorSequence
{
readonly int start, length;
public int Start { get { return start; } }
public int End { get { return start + length; } }
public int Length { get { return length; } }
Sprite[] sprites;
public CursorSequence(string cursorSrc, XmlElement e)
{
sprites = CursorSheetBuilder.LoadAllSprites(cursorSrc, ".shp");
start = int.Parse(e.GetAttribute("start"));
if (e.GetAttribute("length") == "*" || e.GetAttribute("end") == "*")
length = sprites.Length - 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 sprites[(frame % length) + start];
}
}
}

View File

@@ -9,6 +9,8 @@ namespace OpenRa.Game.Graphics
static Dictionary<string, Dictionary<string, Sequence>> units =
new Dictionary<string, Dictionary<string, Sequence>>();
static Dictionary<string, CursorSequence> cursors = new Dictionary<string, CursorSequence>();
static SequenceProvider()
{
XmlDocument document = new XmlDocument();
@@ -16,6 +18,17 @@ namespace OpenRa.Game.Graphics
foreach (XmlElement eUnit in document.SelectNodes("/sequences/unit"))
LoadSequencesForUnit(eUnit);
foreach (XmlElement eCursor in document.SelectNodes("/sequences/cursor"))
LoadSequencesForCursor(eCursor);
}
static void LoadSequencesForCursor(XmlElement eCursor)
{
string cursorSrc = eCursor.GetAttribute("src");
foreach (XmlElement eSequence in eCursor.SelectNodes("./sequence"))
cursors.Add(eSequence.GetAttribute("name"), new CursorSequence(cursorSrc, eSequence));
}
public static void ForcePrecache() { } // force static ctor to run
@@ -35,5 +48,10 @@ namespace OpenRa.Game.Graphics
{
return units[unitName][sequenceName];
}
public static CursorSequence GetCursorSequence(string cursor)
{
return cursors[cursor];
}
}
}