big cleanup of Controller mess

This commit is contained in:
Chris Forbes
2010-01-03 16:40:24 +13:00
parent 43498a123e
commit e742097046
9 changed files with 144 additions and 114 deletions

View File

@@ -11,30 +11,37 @@ namespace OpenRa.Game.Orders
{
public IEnumerable<Order> Order(int2 xy, MouseInput mi)
{
if (!mi.IsFake && mi.Button == MouseButton.Right)
{
if (mi.Button == MouseButton.Right)
Game.controller.CancelInputMode();
yield break;
}
var loc = mi.Location + Game.viewport.Location;
var underCursor = Game.FindUnits(loc, loc)
.Where(a => a.Owner == Game.LocalPlayer
&& a.traits.Contains<Building>()
&& a.Info.Selectable).FirstOrDefault();
return OrderInner(xy, mi);
}
var building = underCursor != null ? underCursor.Info as BuildingInfo : null;
if (building == null || building.Unsellable)
IEnumerable<Order> OrderInner(int2 xy, MouseInput mi)
{
if (mi.Button == MouseButton.Left)
{
yield return new Order("NoSell", Game.LocalPlayer.PlayerActor, null, int2.Zero, null);
yield break;
}
var loc = mi.Location + Game.viewport.Location;
var underCursor = Game.FindUnits(loc, loc)
.Where(a => a.Owner == Game.LocalPlayer
&& a.traits.Contains<Building>()
&& a.Info.Selectable).FirstOrDefault();
yield return new Order("Sell", underCursor, null, int2.Zero, null);
var building = underCursor != null ? underCursor.Info as BuildingInfo : null;
if (building != null && !building.Unsellable)
yield return new Order("Sell", underCursor, null, int2.Zero, null);
}
}
public void Tick() {}
public void Render() {}
public Cursor GetCursor(int2 xy, MouseInput mi)
{
mi.Button = MouseButton.Left;
return OrderInner(xy, mi).Any()
? Cursor.Sell : Cursor.SellBlocked;
}
}
}