diff --git a/OpenRA.Game/Graphics/CursorProvider.cs b/OpenRA.Game/Graphics/CursorProvider.cs index 516f9de1f2..a93420f3ef 100644 --- a/OpenRA.Game/Graphics/CursorProvider.cs +++ b/OpenRA.Game/Graphics/CursorProvider.cs @@ -20,37 +20,28 @@ namespace OpenRA.Graphics public static class CursorProvider { static Dictionary cursors; - - 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(); - - foreach (var f in sequenceFiles) - LoadSequenceSource(f); - - } - - static void LoadSequenceSource(string filename) - { - XmlDocument document = new XmlDocument(); - document.Load(FileSystem.Open(filename)); - foreach (XmlElement eCursor in document.SelectNodes("/sequences/cursor")) - LoadSequencesForCursor(eCursor); + public static void Initialize(string[] sequenceFiles) + { + cursors = new Dictionary(); + var sequences = new MiniYaml(null, sequenceFiles.Select(s => MiniYaml.FromFile(s)).Aggregate(MiniYaml.Merge)); + + 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 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) diff --git a/OpenRA.Game/Graphics/CursorSequence.cs b/OpenRA.Game/Graphics/CursorSequence.cs index f182dac2f4..f1d2b34625 100644 --- a/OpenRA.Game/Graphics/CursorSequence.cs +++ b/OpenRA.Game/Graphics/CursorSequence.cs @@ -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) diff --git a/mods/ra/cursors.xml b/mods/ra/cursors.xml deleted file mode 100644 index c0f1f3b871..0000000000 --- a/mods/ra/cursors.xml +++ /dev/null @@ -1,68 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/mods/ra/cursors.yaml b/mods/ra/cursors.yaml new file mode 100644 index 0000000000..0c49776e47 --- /dev/null +++ b/mods/ra/cursors.yaml @@ -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 \ No newline at end of file diff --git a/mods/ra/mod.yaml b/mods/ra/mod.yaml index 848926691d..765270d658 100644 --- a/mods/ra/mod.yaml +++ b/mods/ra/mod.yaml @@ -42,7 +42,7 @@ Sequences: mods/ra/sequences.yaml Cursors: - mods/ra/cursors.xml + mods/ra/cursors.yaml Chrome: mods/ra/chrome.xml