Store mapped image coordinates in chrome.xml; port most of specialbin.png to this format
This commit is contained in:
31
OpenRa.Game/Graphics/MappedImage.cs
Normal file
31
OpenRa.Game/Graphics/MappedImage.cs
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
using System.Xml;
|
||||||
|
using System.Drawing;
|
||||||
|
using Ijw.DirectX;
|
||||||
|
using System.IO;
|
||||||
|
namespace OpenRa.Game.Graphics
|
||||||
|
{
|
||||||
|
class MappedImage
|
||||||
|
{
|
||||||
|
readonly Rectangle rect;
|
||||||
|
public readonly string Src;
|
||||||
|
public readonly string Name;
|
||||||
|
|
||||||
|
public MappedImage(string defaultSrc, XmlElement e)
|
||||||
|
{
|
||||||
|
Src = (e.HasAttribute("src")) ? e.GetAttribute("src") : defaultSrc;
|
||||||
|
Name = e.GetAttribute("name");
|
||||||
|
if (Src == null)
|
||||||
|
throw new InvalidDataException("Image src missing");
|
||||||
|
|
||||||
|
rect = new Rectangle(int.Parse(e.GetAttribute("x")),
|
||||||
|
int.Parse(e.GetAttribute("y")),
|
||||||
|
int.Parse(e.GetAttribute("width")),
|
||||||
|
int.Parse(e.GetAttribute("height")));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Sprite GetImage(Renderer r, Sheet s)
|
||||||
|
{
|
||||||
|
return new Sprite(s, rect, TextureChannel.Alpha);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,15 +10,25 @@ namespace OpenRa.Game.Graphics
|
|||||||
{
|
{
|
||||||
static Dictionary<string, Dictionary<string, Sequence>> units;
|
static Dictionary<string, Dictionary<string, Sequence>> units;
|
||||||
static Dictionary<string, CursorSequence> cursors;
|
static Dictionary<string, CursorSequence> cursors;
|
||||||
|
|
||||||
|
static Dictionary<string, Dictionary<string, MappedImage>> collections;
|
||||||
|
static Dictionary<string, Sheet> cachedSheets;
|
||||||
|
static Dictionary<string, Dictionary<string, Sprite>> cachedSprites;
|
||||||
|
|
||||||
public static void Initialize( bool useAftermath )
|
public static void Initialize( bool useAftermath )
|
||||||
{
|
{
|
||||||
units = new Dictionary<string, Dictionary<string, Sequence>>();
|
units = new Dictionary<string, Dictionary<string, Sequence>>();
|
||||||
cursors = new Dictionary<string, CursorSequence>();
|
cursors = new Dictionary<string, CursorSequence>();
|
||||||
|
|
||||||
|
collections = new Dictionary<string, Dictionary<string, MappedImage>>();
|
||||||
|
cachedSheets = new Dictionary<string, Sheet>();
|
||||||
|
cachedSprites = new Dictionary<string, Dictionary<string, Sprite>>();
|
||||||
|
|
||||||
LoadSequenceSource("sequences.xml");
|
LoadSequenceSource("sequences.xml");
|
||||||
if (useAftermath)
|
if (useAftermath)
|
||||||
LoadSequenceSource("sequences-aftermath.xml");
|
LoadSequenceSource("sequences-aftermath.xml");
|
||||||
|
|
||||||
|
LoadChromeSource("chrome.xml");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void LoadSequenceSource(string filename)
|
static void LoadSequenceSource(string filename)
|
||||||
@@ -32,7 +42,27 @@ namespace OpenRa.Game.Graphics
|
|||||||
foreach (XmlElement eCursor in document.SelectNodes("/sequences/cursor"))
|
foreach (XmlElement eCursor in document.SelectNodes("/sequences/cursor"))
|
||||||
LoadSequencesForCursor(eCursor);
|
LoadSequencesForCursor(eCursor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void LoadChromeSource(string filename)
|
||||||
|
{
|
||||||
|
XmlDocument document = new XmlDocument();
|
||||||
|
document.Load(FileSystem.Open(filename));
|
||||||
|
foreach (XmlElement eCollection in document.SelectNodes("/chrome/collection"))
|
||||||
|
LoadChromeForCollection(eCollection);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void LoadChromeForCollection(XmlElement eCollection)
|
||||||
|
{
|
||||||
|
string elementName = eCollection.GetAttribute("name");
|
||||||
|
string defaultSrc = (eCollection.HasAttribute("src") ? eCollection.GetAttribute("src") : null);
|
||||||
|
|
||||||
|
var images = eCollection.SelectNodes("./image").OfType<XmlElement>()
|
||||||
|
.Select(e => new MappedImage(defaultSrc, e))
|
||||||
|
.ToDictionary(s => s.Name);
|
||||||
|
|
||||||
|
collections.Add(elementName, images);
|
||||||
|
}
|
||||||
|
|
||||||
static void LoadSequencesForCursor(XmlElement eCursor)
|
static void LoadSequencesForCursor(XmlElement eCursor)
|
||||||
{
|
{
|
||||||
string cursorSrc = eCursor.GetAttribute("src");
|
string cursorSrc = eCursor.GetAttribute("src");
|
||||||
@@ -73,5 +103,32 @@ namespace OpenRa.Game.Graphics
|
|||||||
{
|
{
|
||||||
return cursors[cursor];
|
return cursors[cursor];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static Sprite GetImageFromCollection(Renderer renderer,string collection, string image)
|
||||||
|
{
|
||||||
|
// Cached sprite
|
||||||
|
if (cachedSprites.ContainsKey(collection) && cachedSprites[collection].ContainsKey(image))
|
||||||
|
return cachedSprites[collection][image];
|
||||||
|
|
||||||
|
var mi = collections[collection][image];
|
||||||
|
|
||||||
|
// Cached sheet
|
||||||
|
Sheet sheet;
|
||||||
|
if (cachedSheets.ContainsKey(mi.Src))
|
||||||
|
sheet = cachedSheets[mi.Src];
|
||||||
|
else
|
||||||
|
{
|
||||||
|
sheet = new Sheet(renderer, mi.Src);
|
||||||
|
cachedSheets.Add(mi.Src, sheet);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cache the sprite
|
||||||
|
if (!cachedSprites.ContainsKey(collection))
|
||||||
|
cachedSprites.Add(collection, new Dictionary<string,Sprite>());
|
||||||
|
cachedSprites[collection].Add(image, mi.GetImage(renderer, sheet));
|
||||||
|
|
||||||
|
return cachedSprites[collection][image];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -100,6 +100,7 @@
|
|||||||
<Compile Include="GameRules\UserSettings.cs" />
|
<Compile Include="GameRules\UserSettings.cs" />
|
||||||
<Compile Include="GameRules\VoiceInfo.cs" />
|
<Compile Include="GameRules\VoiceInfo.cs" />
|
||||||
<Compile Include="Effects\IEffect.cs" />
|
<Compile Include="Effects\IEffect.cs" />
|
||||||
|
<Compile Include="Graphics\MappedImage.cs" />
|
||||||
<Compile Include="Graphics\Minimap.cs" />
|
<Compile Include="Graphics\Minimap.cs" />
|
||||||
<Compile Include="Orders\ChronoshiftSelfDestinationOrderGenerator.cs" />
|
<Compile Include="Orders\ChronoshiftSelfDestinationOrderGenerator.cs" />
|
||||||
<Compile Include="Orders\ChronosphereSelectOrderGenerator.cs" />
|
<Compile Include="Orders\ChronosphereSelectOrderGenerator.cs" />
|
||||||
|
|||||||
31
chrome.xml
Normal file
31
chrome.xml
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
<chrome>
|
||||||
|
<collection name="radar">
|
||||||
|
<image name="nobg" x="0" y="0" width="210" height="201" src="radarbin-border.png" />
|
||||||
|
<image name="soviet" x="0" y="0" width="210" height="201" src="radarbin-soviet.png" />
|
||||||
|
<image name="allied" x="0" y="0" width="210" height="201" src="radarbin-allies.png" />
|
||||||
|
</collection>
|
||||||
|
<collection name="chrome" src="specialbin.png">
|
||||||
|
<image name="powershim-top" x="0" y="0" width="30" height="51" />
|
||||||
|
<image name="powershim-middle" x="0" y="51" width="30" height="51" />
|
||||||
|
<image name="powershim-bottom" x="0" y="153" width="30" height="39" />
|
||||||
|
<image name="moneybin" x="192" y="0" width="320" height="32" />
|
||||||
|
<image name="tooltip-bg" x="0" y="288" width="272" height="136" />
|
||||||
|
<image name="palette-border-tl" x="0" y="192" width="9" height="10" />
|
||||||
|
<image name="palette-border-bl" x="0" y="202" width="9" height="10" />
|
||||||
|
<image name="palette-border-left" x="0" y="216" width="9" height="48" />
|
||||||
|
<image name="palette-border-top" x="11" y="192" width="64" height="10" />
|
||||||
|
<image name="palette-border-bottom" x="11" y="202" width="64" height="10" />
|
||||||
|
</collection>
|
||||||
|
<collection name="digit" src="specialbin.png">
|
||||||
|
<image name="0" x="32" y="0" width="13" height="17" />
|
||||||
|
<image name="1" x="45" y="0" width="13" height="17" />
|
||||||
|
<image name="2" x="58" y="0" width="13" height="17" />
|
||||||
|
<image name="3" x="71" y="0" width="13" height="17" />
|
||||||
|
<image name="4" x="84" y="0" width="13" height="17" />
|
||||||
|
<image name="5" x="97" y="0" width="13" height="17" />
|
||||||
|
<image name="6" x="110" y="0" width="13" height="17" />
|
||||||
|
<image name="7" x="123" y="0" width="13" height="17" />
|
||||||
|
<image name="8" x="136" y="0" width="13" height="17" />
|
||||||
|
<image name="9" x="149" y="0" width="13" height="17" />
|
||||||
|
</collection>
|
||||||
|
</chrome>
|
||||||
Reference in New Issue
Block a user