Beginnings of cursor support.
This commit is contained in:
29
OpenRa.Game/Cursor.cs
Normal file
29
OpenRa.Game/Cursor.cs
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using OpenRa.Game.Graphics;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
|
namespace OpenRa.Game
|
||||||
|
{
|
||||||
|
public class Cursor
|
||||||
|
{
|
||||||
|
CursorSequence sequence;
|
||||||
|
Cursor(string cursor)
|
||||||
|
{
|
||||||
|
sequence = SequenceProvider.GetCursorSequence(cursor);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Cursor Default
|
||||||
|
{
|
||||||
|
get { return new Cursor("default"); }
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Cursor Move
|
||||||
|
{
|
||||||
|
get { return new Cursor("move"); }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
39
OpenRa.Game/Graphics/CursorSequence.cs
Normal file
39
OpenRa.Game/Graphics/CursorSequence.cs
Normal 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];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,6 +9,8 @@ namespace OpenRa.Game.Graphics
|
|||||||
static Dictionary<string, Dictionary<string, Sequence>> units =
|
static Dictionary<string, Dictionary<string, Sequence>> units =
|
||||||
new Dictionary<string, Dictionary<string, Sequence>>();
|
new Dictionary<string, Dictionary<string, Sequence>>();
|
||||||
|
|
||||||
|
static Dictionary<string, CursorSequence> cursors = new Dictionary<string, CursorSequence>();
|
||||||
|
|
||||||
static SequenceProvider()
|
static SequenceProvider()
|
||||||
{
|
{
|
||||||
XmlDocument document = new XmlDocument();
|
XmlDocument document = new XmlDocument();
|
||||||
@@ -16,6 +18,17 @@ namespace OpenRa.Game.Graphics
|
|||||||
|
|
||||||
foreach (XmlElement eUnit in document.SelectNodes("/sequences/unit"))
|
foreach (XmlElement eUnit in document.SelectNodes("/sequences/unit"))
|
||||||
LoadSequencesForUnit(eUnit);
|
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
|
public static void ForcePrecache() { } // force static ctor to run
|
||||||
@@ -35,5 +48,10 @@ namespace OpenRa.Game.Graphics
|
|||||||
{
|
{
|
||||||
return units[unitName][sequenceName];
|
return units[unitName][sequenceName];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static CursorSequence GetCursorSequence(string cursor)
|
||||||
|
{
|
||||||
|
return cursors[cursor];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -76,6 +76,7 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="Actor.cs" />
|
<Compile Include="Actor.cs" />
|
||||||
<Compile Include="Controller.cs" />
|
<Compile Include="Controller.cs" />
|
||||||
|
<Compile Include="Cursor.cs" />
|
||||||
<Compile Include="GameRules\FieldLoader.cs" />
|
<Compile Include="GameRules\FieldLoader.cs" />
|
||||||
<Compile Include="GameRules\Footprint.cs" />
|
<Compile Include="GameRules\Footprint.cs" />
|
||||||
<Compile Include="GameRules\InfoLoader.cs" />
|
<Compile Include="GameRules\InfoLoader.cs" />
|
||||||
@@ -86,6 +87,7 @@
|
|||||||
<Compile Include="GameRules\WeaponInfo.cs" />
|
<Compile Include="GameRules\WeaponInfo.cs" />
|
||||||
<Compile Include="Graphics\Animation.cs" />
|
<Compile Include="Graphics\Animation.cs" />
|
||||||
<Compile Include="Game.cs" />
|
<Compile Include="Game.cs" />
|
||||||
|
<Compile Include="Graphics\CursorSequence.cs" />
|
||||||
<Compile Include="Graphics\CursorSheetBuilder.cs" />
|
<Compile Include="Graphics\CursorSheetBuilder.cs" />
|
||||||
<Compile Include="Graphics\LineRenderer.cs" />
|
<Compile Include="Graphics\LineRenderer.cs" />
|
||||||
<Compile Include="Graphics\OverlayRenderer.cs" />
|
<Compile Include="Graphics\OverlayRenderer.cs" />
|
||||||
|
|||||||
@@ -311,5 +311,24 @@
|
|||||||
<unit name="clock">
|
<unit name="clock">
|
||||||
<sequence name="idle" start="0" length="*"/>
|
<sequence name="idle" start="0" length="*"/>
|
||||||
</unit>
|
</unit>
|
||||||
|
|
||||||
|
<cursor src="mouse">
|
||||||
|
<sequence name="default" start="0" />
|
||||||
|
<sequence name="scroll-u" start="1" />
|
||||||
|
<sequence name="scroll-ur" start="2" />
|
||||||
|
<sequence name="scroll-r" start="3" />
|
||||||
|
<sequence name="scroll-dr" start="4" />
|
||||||
|
<sequence name="scroll-d" start="5" />
|
||||||
|
<sequence name="scroll-dl" start="6" />
|
||||||
|
<sequence name="scroll-l" start="7" />
|
||||||
|
<sequence name="scroll-ul" start="8" />
|
||||||
|
<sequence name="scroll-blocked" start="9" />
|
||||||
|
<sequence name="move" start="10" length="4" />
|
||||||
|
<sequence name="move-blocked" start="14" />
|
||||||
|
<sequence name="select" start="15" length="6" />
|
||||||
|
<sequence name="attack" start="21" length="8" />
|
||||||
|
<sequence name="move-minimap" start="29" length="6" />
|
||||||
|
<sequence name="repair" start="35" length="24" />
|
||||||
|
</cursor>
|
||||||
|
|
||||||
</sequences>
|
</sequences>
|
||||||
|
|||||||
Reference in New Issue
Block a user