what a hack, but the cursors work and the terrain doesnt break anymore

This commit is contained in:
Chris Forbes
2009-10-15 19:15:40 +13:00
parent b2f1d2aa88
commit 9a9452c3fa
8 changed files with 48 additions and 6 deletions

View File

@@ -7,15 +7,17 @@ using System.IO;
namespace OpenRa.Game namespace OpenRa.Game
{ {
public class Cursor class Cursor
{ {
CursorSequence sequence; CursorSequence sequence;
Cursor(string cursor) Cursor(string cursor)
{ {
sequence = SequenceProvider.GetCursorSequence(cursor); sequence = SequenceProvider.GetCursorSequence(cursor);
} }
public Sprite GetSprite(int frame) { return sequence.GetSprite(frame); }
public int2 GetHotspot() { return sequence.Hotspot; }
public static Cursor Default public static Cursor Default
{ {
get { return new Cursor("default"); } get { return new Cursor("default"); }

View File

@@ -14,7 +14,10 @@ namespace OpenRa.Game.Graphics
public int End { get { return start + length; } } public int End { get { return start + length; } }
public int Length { get { return length; } } public int Length { get { return length; } }
public readonly int2 Hotspot;
Sprite[] sprites; Sprite[] sprites;
public CursorSequence(string cursorSrc, XmlElement e) public CursorSequence(string cursorSrc, XmlElement e)
{ {
sprites = CursorSheetBuilder.LoadAllSprites(cursorSrc, ".shp"); sprites = CursorSheetBuilder.LoadAllSprites(cursorSrc, ".shp");
@@ -29,6 +32,9 @@ namespace OpenRa.Game.Graphics
length = int.Parse(e.GetAttribute("end")) - start; length = int.Parse(e.GetAttribute("end")) - start;
else else
length = 1; length = 1;
int.TryParse( e.GetAttribute("x"), out Hotspot.X );
int.TryParse( e.GetAttribute("y"), out Hotspot.Y );
} }
public Sprite GetSprite(int frame) public Sprite GetSprite(int frame)

View File

@@ -29,6 +29,8 @@ namespace OpenRa.Game.Graphics
foreach (XmlElement eSequence in eCursor.SelectNodes("./sequence")) foreach (XmlElement eSequence in eCursor.SelectNodes("./sequence"))
cursors.Add(eSequence.GetAttribute("name"), new CursorSequence(cursorSrc, eSequence)); cursors.Add(eSequence.GetAttribute("name"), new CursorSequence(cursorSrc, eSequence));
Log.Write("* LoadSequencesForCursor() done");
} }
public static void ForcePrecache() { } // force static ctor to run public static void ForcePrecache() { } // force static ctor to run

View File

@@ -25,6 +25,12 @@ namespace OpenRa.Game.Graphics
return Add(data, size); return Add(data, size);
} }
public static void ForceNewSheet()
{
current = NewSheet();
channel = NextChannel(null);
}
static Sheet NewSheet() { return new Sheet(renderer, new Size(512, 512)); } static Sheet NewSheet() { return new Sheet(renderer, new Size(512, 512)); }
static Renderer renderer; static Renderer renderer;

View File

@@ -32,6 +32,8 @@ namespace OpenRa.Game.Graphics
Size tileSize = new Size( Game.CellSize, Game.CellSize ); Size tileSize = new Size( Game.CellSize, Game.CellSize );
SheetBuilder.ForceNewSheet();
var tileMapping = new Cache<TileReference, Sprite>( var tileMapping = new Cache<TileReference, Sprite>(
x => SheetBuilder.Add(tileSet.GetBytes(x), tileSize)); x => SheetBuilder.Add(tileSet.GetBytes(x), tileSize));

View File

@@ -17,6 +17,11 @@ namespace OpenRa.Game.Graphics
public int Width { get { return (int)size.X; } } public int Width { get { return (int)size.X; } }
public int Height { get { return (int)size.Y; } } public int Height { get { return (int)size.Y; } }
public Cursor cursor = Cursor.Move;
SpriteRenderer cursorRenderer;
int2 mousePos;
float cursorFrame = 0f;
public void Scroll(float2 delta) public void Scroll(float2 delta)
{ {
scrollPosition = (scrollPosition + delta).Constrain(float2.Zero, mapSize); scrollPosition = (scrollPosition + delta).Constrain(float2.Zero, mapSize);
@@ -27,6 +32,7 @@ namespace OpenRa.Game.Graphics
this.size = size; this.size = size;
this.mapSize = Game.CellSize * mapSize - size + new float2(128, 0); this.mapSize = Game.CellSize * mapSize - size + new float2(128, 0);
this.renderer = renderer; this.renderer = renderer;
cursorRenderer = new SpriteRenderer(renderer, true);
} }
List<Region> regions = new List<Region>(); List<Region> regions = new List<Region>();
@@ -42,6 +48,9 @@ namespace OpenRa.Game.Graphics
foreach (Region region in regions) foreach (Region region in regions)
region.Draw(renderer); region.Draw(renderer);
cursorFrame += 0.01f;
cursorRenderer.DrawSprite(cursor.GetSprite((int)cursorFrame), mousePos + Location - cursor.GetHotspot(), 0);
cursorRenderer.Flush();
renderer.EndFrame(); renderer.EndFrame();
} }
@@ -49,6 +58,9 @@ namespace OpenRa.Game.Graphics
Region dragRegion = null; Region dragRegion = null;
public void DispatchMouseInput(MouseInput mi) public void DispatchMouseInput(MouseInput mi)
{ {
if (mi.Event == MouseInputEvent.Move)
mousePos = mi.Location;
if (dragRegion != null) { if (dragRegion != null) {
dragRegion.HandleMouseInput( mi ); dragRegion.HandleMouseInput( mi );
if (mi.Event == MouseInputEvent.Up) dragRegion = null; if (mi.Event == MouseInputEvent.Up) dragRegion = null;

View File

@@ -6,7 +6,8 @@ using OpenRa.TechTree;
namespace OpenRa.Game namespace OpenRa.Game
{ {
using GRegion = OpenRa.Game.Graphics.Region; using GRegion = OpenRa.Game.Graphics.Region;
using System.Runtime.InteropServices;
class MainWindow : Form class MainWindow : Form
{ {
@@ -21,7 +22,10 @@ namespace OpenRa.Game
return new Size(settings.GetValue("width", desktopResolution.Width), return new Size(settings.GetValue("width", desktopResolution.Width),
settings.GetValue("height", desktopResolution.Height)); settings.GetValue("height", desktopResolution.Height));
} }
[DllImport("user32")]
static extern int ShowCursor([MarshalAs(UnmanagedType.Bool)] bool visible);
public MainWindow(Settings settings) public MainWindow(Settings settings)
{ {
@@ -58,7 +62,9 @@ namespace OpenRa.Game
sidebar = new Sidebar(renderer, game); sidebar = new Sidebar(renderer, game);
renderer.BuildPalette(game.map); renderer.BuildPalette(game.map);
ShowCursor(false);
} }
internal void Run() internal void Run()
@@ -66,6 +72,12 @@ namespace OpenRa.Game
while (Created && Visible) while (Created && Visible)
{ {
game.Tick(); game.Tick();
// rude hack
game.viewport.cursor = (game.controller.orderGenerator is UnitOrderGenerator)
&& (game.controller.orderGenerator as UnitOrderGenerator).selection.Count > 0
? OpenRa.Game.Cursor.Move : OpenRa.Game.Cursor.Default;
Application.DoEvents(); Application.DoEvents();
} }
} }

View File

@@ -323,7 +323,7 @@
<sequence name="scroll-l" start="7" /> <sequence name="scroll-l" start="7" />
<sequence name="scroll-ul" start="8" /> <sequence name="scroll-ul" start="8" />
<sequence name="scroll-blocked" start="9" /> <sequence name="scroll-blocked" start="9" />
<sequence name="move" start="10" length="4" /> <sequence name="move" start="10" length="4" x="12" y="12"/>
<sequence name="move-blocked" start="14" /> <sequence name="move-blocked" start="14" />
<sequence name="select" start="15" length="6" /> <sequence name="select" start="15" length="6" />
<sequence name="attack" start="21" length="8" /> <sequence name="attack" start="21" length="8" />