removed needless cursor indirection

This commit is contained in:
Chris Forbes
2010-02-06 16:18:48 +13:00
parent 4724734454
commit 3b1dc39d6d
16 changed files with 47 additions and 75 deletions

View File

@@ -132,7 +132,7 @@ namespace OpenRa
public float2 MousePosition { get { return dragEnd; } } public float2 MousePosition { get { return dragEnd; } }
public Cursor ChooseCursor( World world ) public string ChooseCursor( World world )
{ {
int sync = world.SyncHash(); int sync = world.SyncHash();

View File

@@ -5,36 +5,12 @@ namespace OpenRa
public class Cursor public class Cursor
{ {
CursorSequence sequence; CursorSequence sequence;
Cursor(string cursor) public Cursor(string cursor)
{ {
sequence = SequenceProvider.GetCursorSequence(cursor); sequence = SequenceProvider.GetCursorSequence(cursor);
} }
public Sprite GetSprite(int frame) { return sequence.GetSprite(frame); } public Sprite GetSprite(int frame) { return sequence.GetSprite(frame); }
public int2 GetHotspot() { return sequence.Hotspot; } public int2 GetHotspot() { return sequence.Hotspot; }
public static Cursor None { get { return null; } }
public static Cursor Default { get { return new Cursor("default"); } }
public static Cursor Move { get { return new Cursor("move"); } }
public static Cursor Select { get { return new Cursor("select"); } }
public static Cursor MoveBlocked { get { return new Cursor("move-blocked"); } }
public static Cursor Attack { get { return new Cursor("attack"); } }
public static Cursor AttackMove { get { return new Cursor("attackmove"); } }
public static Cursor Deploy { get { return new Cursor("deploy"); } }
public static Cursor Enter { get { return new Cursor("enter"); } }
public static Cursor DeployBlocked { get { return new Cursor("deploy-blocked"); } }
public static Cursor Chronoshift { get { return new Cursor("chrono-target"); } }
public static Cursor ChronoshiftSelect { get { return new Cursor("chrono-select"); } }
public static Cursor Nuke { get { return new Cursor("nuke"); } }
public static Cursor Ability { get { return new Cursor("ability"); } }
public static Cursor C4 { get { return new Cursor("c4"); } }
public static Cursor Capture { get { return new Cursor("capture"); } }
public static Cursor Heal { get { return new Cursor("heal"); } }
public static Cursor Sell { get { return new Cursor("sell"); } }
public static Cursor SellBlocked { get { return new Cursor("sell-blocked"); } }
public static Cursor Repair { get { return new Cursor("repair"); } }
public static Cursor RepairBlocked { get { return new Cursor("repair-blocked"); } }
public static Cursor PowerDown { get { return new Cursor("powerdown"); } }
public static Cursor PowerDownBlocked { get { return new Cursor("powerdown-blocked"); } }
} }
} }

View File

@@ -79,7 +79,8 @@ namespace OpenRa.Graphics
} }
} }
var c = Game.chrome.HitTest(mousePos) ? Cursor.Default : Game.controller.ChooseCursor( world ); var cursorName = Game.chrome.HitTest(mousePos) ? "default" : Game.controller.ChooseCursor( world );
var c = new Cursor(cursorName);
cursorRenderer.DrawSprite(c.GetSprite((int)cursorFrame), mousePos + Location - c.GetHotspot(), "cursor"); cursorRenderer.DrawSprite(c.GetSprite((int)cursorFrame), mousePos + Location - c.GetHotspot(), "cursor");
cursorRenderer.Flush(); cursorRenderer.Flush();

View File

@@ -7,6 +7,6 @@ namespace OpenRa
IEnumerable<Order> Order( World world, int2 xy, MouseInput mi ); IEnumerable<Order> Order( World world, int2 xy, MouseInput mi );
void Tick( World world ); void Tick( World world );
void Render( World world ); void Render( World world );
Cursor GetCursor( World world, int2 xy, MouseInput mi ); string GetCursor( World world, int2 xy, MouseInput mi );
} }
} }

View File

@@ -53,9 +53,6 @@ namespace OpenRa.Orders
world.WorldRenderer.uiOverlay.DrawBuildingGrid( world, Building, BuildingInfo ); world.WorldRenderer.uiOverlay.DrawBuildingGrid( world, Building, BuildingInfo );
} }
public Cursor GetCursor(World world, int2 xy, MouseInput mi) public string GetCursor(World world, int2 xy, MouseInput mi) { return "default"; }
{
return Cursor.Default;
}
} }
} }

View File

@@ -34,11 +34,11 @@ namespace OpenRa.Orders
public void Tick( World world ) { } public void Tick( World world ) { }
public void Render( World world ) { } public void Render( World world ) { }
public Cursor GetCursor(World world, int2 xy, MouseInput mi) public string GetCursor(World world, int2 xy, MouseInput mi)
{ {
mi.Button = MouseButton.Left; mi.Button = MouseButton.Left;
return OrderInner(world, xy, mi).Any() return OrderInner(world, xy, mi).Any()
? Cursor.PowerDown : Cursor.PowerDownBlocked; ? "powerdown" : "powerdown-blocked";
} }
} }
} }

View File

@@ -48,11 +48,11 @@ namespace OpenRa.Orders
public void Render( World world ) {} public void Render( World world ) {}
public Cursor GetCursor(World world, int2 xy, MouseInput mi) public string GetCursor(World world, int2 xy, MouseInput mi)
{ {
mi.Button = MouseButton.Left; mi.Button = MouseButton.Left;
return OrderInner(world, xy, mi).Any() return OrderInner(world, xy, mi).Any()
? Cursor.Repair : Cursor.RepairBlocked; ? "repair" : "repair-blocked";
} }
} }
} }

View File

@@ -36,11 +36,11 @@ namespace OpenRa.Orders
public void Tick( World world ) {} public void Tick( World world ) {}
public void Render( World world ) {} public void Render( World world ) {}
public Cursor GetCursor(World world, int2 xy, MouseInput mi) public string GetCursor(World world, int2 xy, MouseInput mi)
{ {
mi.Button = MouseButton.Left; mi.Button = MouseButton.Left;
return OrderInner(world, xy, mi).Any() return OrderInner(world, xy, mi).Any()
? Cursor.Sell : Cursor.SellBlocked; ? "sell" : "sell-blocked";
} }
} }
} }

View File

@@ -36,12 +36,12 @@ namespace OpenRa.Orders
world.WorldRenderer.DrawSelectionBox( a, Color.White, true ); world.WorldRenderer.DrawSelectionBox( a, Color.White, true );
} }
public Cursor GetCursor( World world, int2 xy, MouseInput mi ) public string GetCursor( World world, int2 xy, MouseInput mi )
{ {
return ChooseCursor(world, mi); return ChooseCursor(world, mi);
} }
Cursor ChooseCursor( World world, MouseInput mi ) string ChooseCursor( World world, MouseInput mi )
{ {
var p = Game.controller.MousePosition; var p = Game.controller.MousePosition;
var c = Order(world, p.ToInt2(), mi) var c = Order(world, p.ToInt2(), mi)
@@ -51,22 +51,22 @@ namespace OpenRa.Orders
return c ?? return c ??
(world.SelectActorsInBox(Game.CellSize * p, (world.SelectActorsInBox(Game.CellSize * p,
Game.CellSize * p).Any() Game.CellSize * p).Any()
? Cursor.Select : Cursor.Default); ? "select" : "default");
} }
Cursor CursorForOrderString(string s, Actor a, int2 location) string CursorForOrderString(string s, Actor a, int2 location)
{ {
var movement = a.traits.GetOrDefault<IMovement>(); var movement = a.traits.GetOrDefault<IMovement>();
switch (s) switch (s)
{ {
case "Attack": return Cursor.Attack; case "Attack": return "attack";
case "Heal": return Cursor.Heal; case "Heal": return "heal";
case "C4": return Cursor.C4; case "C4": return "c4";
case "Move": case "Move":
if (movement.CanEnterCell(location)) if (movement.CanEnterCell(location))
return Cursor.Move; return "move";
else else
return Cursor.MoveBlocked; return "move-blocked";
case "DeployTransform": case "DeployTransform":
var depInfo = a.Info.Traits.Get<TransformsOnDeployInfo>(); var depInfo = a.Info.Traits.Get<TransformsOnDeployInfo>();
var transInfo = Rules.Info[depInfo.TransformsInto]; var transInfo = Rules.Info[depInfo.TransformsInto];
@@ -74,18 +74,18 @@ namespace OpenRa.Orders
{ {
var bi = transInfo.Traits.Get<BuildingInfo>(); var bi = transInfo.Traits.Get<BuildingInfo>();
if (!a.World.CanPlaceBuilding(depInfo.TransformsInto, bi, a.Location + new int2(depInfo.Offset[0], depInfo.Offset[1]), a)) if (!a.World.CanPlaceBuilding(depInfo.TransformsInto, bi, a.Location + new int2(depInfo.Offset[0], depInfo.Offset[1]), a))
return Cursor.DeployBlocked; return "deploy-blocked";
} }
return Cursor.Deploy; return "deploy";
case "Deploy": return Cursor.Deploy; case "Deploy": return "deploy";
case "Enter": return Cursor.Enter; case "Enter": return "enter";
case "EnterTransport": return Cursor.Enter; case "EnterTransport": return "enter";
case "Deliver": return Cursor.Enter; case "Deliver": return "enter";
case "Infiltrate": return Cursor.Enter; case "Infiltrate": return "enter";
case "Capture": return Cursor.Capture; case "Capture": return "capture";
case "Harvest": return Cursor.AttackMove; case "Harvest": return "attackmove";
case "Steal" : return Cursor.Enter; case "Steal" : return "enter";
default: default:
return null; return null;
} }

View File

@@ -112,11 +112,11 @@ namespace OpenRa.Traits
public void Render( World world ) { } public void Render( World world ) { }
public Cursor GetCursor(World world, int2 xy, MouseInput mi) public string GetCursor(World world, int2 xy, MouseInput mi)
{ {
mi.Button = MouseButton.Left; mi.Button = MouseButton.Left;
return OrderInner(world, xy, mi).Any() return OrderInner(world, xy, mi).Any()
? Cursor.ChronoshiftSelect : Cursor.MoveBlocked; ? "chrono-select" : "move-blocked";
} }
} }
@@ -153,13 +153,13 @@ namespace OpenRa.Traits
world.WorldRenderer.DrawSelectionBox(self, Color.Red, true); world.WorldRenderer.DrawSelectionBox(self, Color.Red, true);
} }
public Cursor GetCursor(World world, int2 xy, MouseInput mi) public string GetCursor(World world, int2 xy, MouseInput mi)
{ {
if (!world.LocalPlayer.Shroud.IsExplored(xy)) if (!world.LocalPlayer.Shroud.IsExplored(xy))
return Cursor.MoveBlocked; return "move-blocked";
var movement = self.traits.GetOrDefault<IMovement>(); var movement = self.traits.GetOrDefault<IMovement>();
return (movement.CanEnterCell(xy)) ? Cursor.Chronoshift : Cursor.MoveBlocked; return (movement.CanEnterCell(xy)) ? "chrono-target" : "move-blocked";
} }
} }
} }

View File

@@ -59,11 +59,11 @@ namespace OpenRa.Traits
public void Render(World world) { } public void Render(World world) { }
public Cursor GetCursor(World world, int2 xy, MouseInput mi) public string GetCursor(World world, int2 xy, MouseInput mi)
{ {
mi.Button = MouseButton.Left; mi.Button = MouseButton.Left;
return OrderInner(world, xy, mi).Any() return OrderInner(world, xy, mi).Any()
? Cursor.Ability : Cursor.MoveBlocked; ? "ability" : "move-blocked";
} }
} }
} }

View File

@@ -62,9 +62,7 @@ namespace OpenRa.Traits
IEnumerable<Order> OrderInner(World world, int2 xy, MouseInput mi) IEnumerable<Order> OrderInner(World world, int2 xy, MouseInput mi)
{ {
if (mi.Button == MouseButton.Left) if (mi.Button == MouseButton.Left)
{
yield return new Order("NuclearMissile", world.LocalPlayer.PlayerActor, xy); yield return new Order("NuclearMissile", world.LocalPlayer.PlayerActor, xy);
}
yield break; yield break;
} }
@@ -80,7 +78,7 @@ namespace OpenRa.Traits
} }
public void Render(World world) { } public void Render(World world) { }
public Cursor GetCursor(World world, int2 xy, MouseInput mi) { return Cursor.Nuke; } public string GetCursor(World world, int2 xy, MouseInput mi) { return "nuke"; }
} }
} }

View File

@@ -30,13 +30,13 @@ namespace OpenRa.Mods.Aftermath.Orders
world.WorldRenderer.DrawSelectionBox(self, Color.White, true); world.WorldRenderer.DrawSelectionBox(self, Color.White, true);
} }
public Cursor GetCursor(World world, int2 xy, MouseInput mi) public string GetCursor(World world, int2 xy, MouseInput mi)
{ {
if (!world.LocalPlayer.Shroud.IsExplored(xy)) if (!world.LocalPlayer.Shroud.IsExplored(xy))
return Cursor.MoveBlocked; return "move-blocked";
var movement = self.traits.GetOrDefault<IMovement>(); var movement = self.traits.GetOrDefault<IMovement>();
return (movement.CanEnterCell(xy)) ? Cursor.Chronoshift : Cursor.MoveBlocked; return (movement.CanEnterCell(xy)) ? "chrono-target" : "move-blocked";
} }
} }
} }

View File

@@ -84,11 +84,11 @@ namespace OpenRa.Mods.RA
public void Render(World world) { } public void Render(World world) { }
public Cursor GetCursor(World world, int2 xy, MouseInput mi) public string GetCursor(World world, int2 xy, MouseInput mi)
{ {
mi.Button = MouseButton.Left; mi.Button = MouseButton.Left;
return OrderInner(world, xy, mi).Any() return OrderInner(world, xy, mi).Any()
? Cursor.Ability : Cursor.MoveBlocked; ? "ability" : "move-blocked";
} }
} }
} }

View File

@@ -31,9 +31,9 @@ namespace OpenRa.Mods.RA
public void Tick(World world) {} public void Tick(World world) {}
public void Render(World world) {} public void Render(World world) {}
public Cursor GetCursor(World world, int2 xy, MouseInput mi) public string GetCursor(World world, int2 xy, MouseInput mi)
{ {
return Cursor.Ability; return "ability";
} }
} }

View File

@@ -60,7 +60,7 @@ namespace OpenRa.Mods.RA
public void Tick(World world) {} public void Tick(World world) {}
public void Render(World world) {} public void Render(World world) {}
public Cursor GetCursor(World world, int2 xy, MouseInput mi) { return Cursor.Ability; } public string GetCursor(World world, int2 xy, MouseInput mi) { return "ability"; }
} }
} }
} }