what a hack, but the cursors work and the terrain doesnt break anymore
This commit is contained in:
@@ -7,15 +7,17 @@ using System.IO;
|
||||
|
||||
namespace OpenRa.Game
|
||||
{
|
||||
public class Cursor
|
||||
class Cursor
|
||||
{
|
||||
CursorSequence sequence;
|
||||
Cursor(string cursor)
|
||||
{
|
||||
sequence = SequenceProvider.GetCursorSequence(cursor);
|
||||
|
||||
}
|
||||
|
||||
public Sprite GetSprite(int frame) { return sequence.GetSprite(frame); }
|
||||
public int2 GetHotspot() { return sequence.Hotspot; }
|
||||
|
||||
public static Cursor Default
|
||||
{
|
||||
get { return new Cursor("default"); }
|
||||
|
||||
@@ -14,7 +14,10 @@ namespace OpenRa.Game.Graphics
|
||||
public int End { get { return start + length; } }
|
||||
public int Length { get { return length; } }
|
||||
|
||||
public readonly int2 Hotspot;
|
||||
|
||||
Sprite[] sprites;
|
||||
|
||||
public CursorSequence(string cursorSrc, XmlElement e)
|
||||
{
|
||||
sprites = CursorSheetBuilder.LoadAllSprites(cursorSrc, ".shp");
|
||||
@@ -29,6 +32,9 @@ namespace OpenRa.Game.Graphics
|
||||
length = int.Parse(e.GetAttribute("end")) - start;
|
||||
else
|
||||
length = 1;
|
||||
|
||||
int.TryParse( e.GetAttribute("x"), out Hotspot.X );
|
||||
int.TryParse( e.GetAttribute("y"), out Hotspot.Y );
|
||||
}
|
||||
|
||||
public Sprite GetSprite(int frame)
|
||||
|
||||
@@ -29,6 +29,8 @@ namespace OpenRa.Game.Graphics
|
||||
|
||||
foreach (XmlElement eSequence in eCursor.SelectNodes("./sequence"))
|
||||
cursors.Add(eSequence.GetAttribute("name"), new CursorSequence(cursorSrc, eSequence));
|
||||
|
||||
Log.Write("* LoadSequencesForCursor() done");
|
||||
}
|
||||
|
||||
public static void ForcePrecache() { } // force static ctor to run
|
||||
|
||||
@@ -25,6 +25,12 @@ namespace OpenRa.Game.Graphics
|
||||
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 Renderer renderer;
|
||||
|
||||
@@ -32,6 +32,8 @@ namespace OpenRa.Game.Graphics
|
||||
|
||||
Size tileSize = new Size( Game.CellSize, Game.CellSize );
|
||||
|
||||
SheetBuilder.ForceNewSheet();
|
||||
|
||||
var tileMapping = new Cache<TileReference, Sprite>(
|
||||
x => SheetBuilder.Add(tileSet.GetBytes(x), tileSize));
|
||||
|
||||
|
||||
@@ -17,6 +17,11 @@ namespace OpenRa.Game.Graphics
|
||||
public int Width { get { return (int)size.X; } }
|
||||
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)
|
||||
{
|
||||
scrollPosition = (scrollPosition + delta).Constrain(float2.Zero, mapSize);
|
||||
@@ -27,6 +32,7 @@ namespace OpenRa.Game.Graphics
|
||||
this.size = size;
|
||||
this.mapSize = Game.CellSize * mapSize - size + new float2(128, 0);
|
||||
this.renderer = renderer;
|
||||
cursorRenderer = new SpriteRenderer(renderer, true);
|
||||
}
|
||||
|
||||
List<Region> regions = new List<Region>();
|
||||
@@ -42,6 +48,9 @@ namespace OpenRa.Game.Graphics
|
||||
|
||||
foreach (Region region in regions)
|
||||
region.Draw(renderer);
|
||||
cursorFrame += 0.01f;
|
||||
cursorRenderer.DrawSprite(cursor.GetSprite((int)cursorFrame), mousePos + Location - cursor.GetHotspot(), 0);
|
||||
cursorRenderer.Flush();
|
||||
|
||||
renderer.EndFrame();
|
||||
}
|
||||
@@ -49,6 +58,9 @@ namespace OpenRa.Game.Graphics
|
||||
Region dragRegion = null;
|
||||
public void DispatchMouseInput(MouseInput mi)
|
||||
{
|
||||
if (mi.Event == MouseInputEvent.Move)
|
||||
mousePos = mi.Location;
|
||||
|
||||
if (dragRegion != null) {
|
||||
dragRegion.HandleMouseInput( mi );
|
||||
if (mi.Event == MouseInputEvent.Up) dragRegion = null;
|
||||
|
||||
@@ -6,7 +6,8 @@ using OpenRa.TechTree;
|
||||
|
||||
namespace OpenRa.Game
|
||||
{
|
||||
using GRegion = OpenRa.Game.Graphics.Region;
|
||||
using GRegion = OpenRa.Game.Graphics.Region;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
class MainWindow : Form
|
||||
{
|
||||
@@ -21,7 +22,10 @@ namespace OpenRa.Game
|
||||
|
||||
return new Size(settings.GetValue("width", desktopResolution.Width),
|
||||
settings.GetValue("height", desktopResolution.Height));
|
||||
}
|
||||
}
|
||||
|
||||
[DllImport("user32")]
|
||||
static extern int ShowCursor([MarshalAs(UnmanagedType.Bool)] bool visible);
|
||||
|
||||
public MainWindow(Settings settings)
|
||||
{
|
||||
@@ -58,7 +62,9 @@ namespace OpenRa.Game
|
||||
|
||||
sidebar = new Sidebar(renderer, game);
|
||||
|
||||
renderer.BuildPalette(game.map);
|
||||
renderer.BuildPalette(game.map);
|
||||
|
||||
ShowCursor(false);
|
||||
}
|
||||
|
||||
internal void Run()
|
||||
@@ -66,6 +72,12 @@ namespace OpenRa.Game
|
||||
while (Created && Visible)
|
||||
{
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -323,7 +323,7 @@
|
||||
<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" start="10" length="4" x="12" y="12"/>
|
||||
<sequence name="move-blocked" start="14" />
|
||||
<sequence name="select" start="15" length="6" />
|
||||
<sequence name="attack" start="21" length="8" />
|
||||
|
||||
Reference in New Issue
Block a user