Port cursors to yaml.

This commit is contained in:
Paul Chote
2011-01-20 09:21:35 +13:00
parent 827a19adef
commit ea9003d6fc
5 changed files with 292 additions and 104 deletions

View File

@@ -23,34 +23,25 @@ namespace OpenRA.Graphics
public static void Initialize(string[] sequenceFiles)
{
// TODO: Convert cursor definitions to yaml and parse cursor palette info
Game.modData.Palette.AddPalette("cursor", new Palette( FileSystem.Open( "cursor.pal" ), false ));
cursors = new Dictionary<string, CursorSequence>();
var sequences = new MiniYaml(null, sequenceFiles.Select(s => MiniYaml.FromFile(s)).Aggregate(MiniYaml.Merge));
foreach (var f in sequenceFiles)
LoadSequenceSource(f);
foreach (var s in sequences.NodesDict["Palettes"].Nodes)
Game.modData.Palette.AddPalette(s.Key, new Palette(FileSystem.Open(s.Value.Value), false));
foreach (var s in sequences.NodesDict["Cursors"].Nodes)
LoadSequencesForCursor(s.Key, s.Value);
}
static void LoadSequenceSource(string filename)
{
XmlDocument document = new XmlDocument();
document.Load(FileSystem.Open(filename));
foreach (XmlElement eCursor in document.SelectNodes("/sequences/cursor"))
LoadSequencesForCursor(eCursor);
}
static void LoadSequencesForCursor(XmlElement eCursor)
static void LoadSequencesForCursor(string cursorSrc, MiniYaml cursor)
{
Game.modData.LoadScreen.Display();
string cursorSrc = eCursor.GetAttribute("src");
string palette = eCursor.GetAttribute("palette");
foreach (XmlElement eSequence in eCursor.SelectNodes("./sequence"))
cursors.Add(eSequence.GetAttribute("name"), new CursorSequence(cursorSrc, palette, eSequence));
foreach (var sequence in cursor.Nodes)
{
Console.WriteLine(sequence.Key);
cursors.Add(sequence.Key, new CursorSequence(cursorSrc, cursor.Value, sequence.Value));
}
}
public static bool HasCursorSequence(string cursor)

View File

@@ -9,6 +9,7 @@
#endregion
using System.Xml;
using OpenRA.FileFormats;
namespace OpenRA.Graphics
{
@@ -25,24 +26,27 @@ namespace OpenRA.Graphics
Sprite[] sprites;
public CursorSequence(string cursorSrc, string palette, XmlElement e)
public CursorSequence(string cursorSrc, string palette, MiniYaml info)
{
sprites = Game.modData.CursorSheetBuilder.LoadAllSprites(cursorSrc);
var d = info.NodesDict;
start = int.Parse(e.GetAttribute("start"));
start = int.Parse(d["start"].Value);
this.palette = palette;
if (e.GetAttribute("length") == "*" || e.GetAttribute("end") == "*")
if ((d.ContainsKey("length") && d["length"].Value == "*") || (d.ContainsKey("end") && d["end"].Value == "*"))
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 if (d.ContainsKey("length"))
length = int.Parse(d["length"].Value);
else if (d.ContainsKey("end"))
length = int.Parse(d["end"].Value) - start;
else
length = 1;
int.TryParse( e.GetAttribute("x"), out Hotspot.X );
int.TryParse( e.GetAttribute("y"), out Hotspot.Y );
if (d.ContainsKey("x"))
int.TryParse(d["x"].Value, out Hotspot.X );
if (d.ContainsKey("y"))
int.TryParse(d["y"].Value, out Hotspot.Y );
}
public Sprite GetSprite(int frame)

View File

@@ -1,68 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<sequences>
<cursor src="mouse" palette="cursor">
<sequence name="scroll-t" start="1" x="12" y="12" />
<sequence name="scroll-tr" start="2" x="12" y="12" />
<sequence name="scroll-r" start="3" x="12" y="12" />
<sequence name="scroll-br" start="4" x="12" y="12" />
<sequence name="scroll-b" start="5" x="12" y="12" />
<sequence name="scroll-bl" start="6" x="12" y="12" />
<sequence name="scroll-l" start="7" x="12" y="12" />
<sequence name="scroll-tl" start="8" x="12" y="12" />
<sequence name="scroll-t-blocked" start="124" x="12" y="12" />
<sequence name="scroll-tr-blocked" start="125" x="12" y="12" />
<sequence name="scroll-r-blocked" start="126" x="12" y="12" />
<sequence name="scroll-br-blocked" start="127" x="12" y="12" />
<sequence name="scroll-b-blocked" start="128" x="12" y="12" />
<sequence name="scroll-bl-blocked" start="129" x="12" y="12" />
<sequence name="scroll-l-blocked" start="130" x="12" y="12" />
<sequence name="scroll-tl-blocked" start="131" x="12" y="12" />
<sequence name="select" start="15" length="6" x="12" y="12" />
<sequence name="default" start="0" />
<sequence name="default-minimap" start="80" />
<sequence name="generic-blocked" start="9" />
<sequence name="generic-blocked-minimap" start="33" />
<sequence name="move" start="10" length="4" x="12" y="12" />
<sequence name="move-minimap" start="29" length="4" x="12" y="12" />
<sequence name="move-blocked" start="14" x="12" y="12" />
<sequence name="move-blocked-minimap" start="33" x="12" y="12" />
<sequence name="attack" start="195" length="8" x="12" y="12" />
<sequence name="attack-minimap" start="203" length="8" x="12" y="12" />
<sequence name="attackmove" start="21" length="8" x="12" y="12" />
<sequence name="attackmove-minimap" start="134" length="8" x="12" y="12" />
<sequence name="enter" start="113" length="3" x="12" y="12" />
<sequence name="enter-minimap" start="139" length="3" x="12" y="12" />
<sequence name="enter-blocked" start="212" length="1" x="12" y="12" />
<sequence name="enter-blocked-minimap" start="33" />
<sequence name="c4" start="116" length="3" x="12" y="12" />
<sequence name="c4-minimap" start="121" length="3" x="12" y="12" />
<sequence name="guard" start="147" length="1" x="12" y="12" />
<sequence name="guard-minimap" start="146" length="1" x="12" y="12" />
<sequence name="capture" start="164" length="3" x="12" y="12" />
<sequence name="capture-minimap" start="167" length="3" x="12" y="12" />
<sequence name="heal" start="160" length="4" x="12" y="12" />
<sequence name="heal-minimap" start="194" length="1" x="12" y="12" />
<sequence name="ability" start="82" length="8" x="12" y="12" />
<sequence name="ability-minimap" start="214" length="8" x="12" y="12" />
<!-- Want minimap cursors -->
<sequence name="deploy" start="59" length="9" x="12" y="12" />
<sequence name="deploy-blocked" start="211" length="1" x="12" y="12" />
<sequence name="goldwrench" start="170" length="24" x="12" y="12" />
<sequence name="goldwrench-blocked" start="213" length="1" x="12" y="12" />
<sequence name="nuke" start="90" length="7" x="12" y="12" />
<sequence name="chrono-select" start="97" length="8" x="12" y="12" />
<sequence name="chrono-target" start="105" length="8" x="12" y="12" />
<sequence name="sell" start="68" length="12" x="12" y="12" />
<sequence name="sell-blocked" start="119" length="1" x="12" y="12" />
<sequence name="repair" start="35" length="24" x="12" y="12" />
<sequence name="repair-blocked" start="120" length="1" x="12" y="12" />
<sequence name="sell2" start="148" length="12" />
</cursor>
<cursor src="nopower" palette="cursor">
<sequence name="powerdown-blocked" start="0" length="1" x="12" y="12" />
<sequence name="powerdown" start="1" length="3" x="12" y="12" />
</cursor>
</sequences>

261
mods/ra/cursors.yaml Normal file
View File

@@ -0,0 +1,261 @@
Palettes:
cursor: cursor.pal
Cursors:
mouse: cursor
scroll-t:
start:1
x: 12
y: 12
scroll-tr:
start: 2
x: 12
y: 12
scroll-r:
start: 3
x: 12
y: 12
scroll-br:
start: 4
x: 12
y: 12
scroll-b:
start:5
x: 12
y: 12
scroll-bl:
start:6
x: 12
y: 12
scroll-l:
start:7
x: 12
y: 12
scroll-tl:
start:8
x: 12
y: 12
scroll-t-blocked:
start:124
x: 12
y: 12
scroll-tr-blocked:
start:125
x: 12
y: 12
scroll-r-blocked:
start:126
x: 12
y: 12
scroll-br-blocked:
start:127
x: 12
y: 12
scroll-b-blocked:
start:128
x: 12
y: 12
scroll-bl-blocked:
start:129
x: 12
y: 12
scroll-l-blocked:
start:130
x: 12
y: 12
scroll-tl-blocked:
start:131
x: 12
y: 12
select:
start:15
length: 6
x: 12
y: 12
default:
start:0
default-minimap:
start:80
generic-blocked:
start:9
generic-blocked-minimap:
start:33
move:
start:10
length: 4
x: 12
y: 12
move-minimap:
start:29
length: 4
x: 12
y: 12
move-blocked:
start:14
x: 12
y: 12
move-blocked-minimap:
start:33
x: 12
y: 12
attack:
start:195
length: 8
x: 12
y: 12
attack-minimap:
start:203
length: 8
x: 12
y: 12
attackmove:
start:21
length: 8
x: 12
y: 12
attackmove-minimap:
start:134
length: 8
x: 12
y: 12
enter:
start:113
length: 3
x: 12
y: 12
enter-minimap:
start:139
length: 3
x: 12
y: 12
enter-blocked:
start:212
length: 1
x: 12
y: 12
enter-blocked-minimap:
start:33
c4:
start:116
length: 3
x: 12
y: 12
c4-minimap:
start:121
length: 3
x: 12
y: 12
guard:
start:147
length: 1
x: 12
y: 12
guard-minimap:
start:146
length: 1
x: 12
y: 12
capture:
start:164
length: 3
x: 12
y: 12
capture-minimap:
start:167
length: 3
x: 12
y: 12
heal:
start:160
length: 4
x: 12
y: 12
heal-minimap:
start:194
length: 1
x: 12
y: 12
ability:
start:82
length: 8
x: 12
y: 12
ability-minimap:
start:214
length: 8
x: 12
y: 12
# Cursors that need minimap variants
deploy:
start:59
length: 9
x: 12
y: 12
deploy-blocked:
start:211
length: 1
x: 12
y: 12
goldwrench:
start:170
length: 24
x: 12
y: 12
goldwrench-blocked:
start:213
length: 1
x: 12
y: 12
nuke:
start:90
length: 7
x: 12
y: 12
chrono-select:
start:97
length: 8
x: 12
y: 12
chrono-target:
start:105
length: 8
x: 12
y: 12
sell:
start:68
length: 12
x: 12
y: 12
sell-blocked:
start:119
length: 1
x: 12
y: 12
repair:
start:35
length: 24
x: 12
y: 12
repair-blocked:
start:120
length: 1
x: 12
y: 12
sell2:
start:148
length: 12
nopower: cursor
powerdown-blocked:
start:0
length: 1
x: 12
y: 12
powerdown:
start:1
length: 3
x: 12
y: 12

View File

@@ -42,7 +42,7 @@ Sequences:
mods/ra/sequences.yaml
Cursors:
mods/ra/cursors.xml
mods/ra/cursors.yaml
Chrome:
mods/ra/chrome.xml