big cleanup of Controller mess
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using OpenRa.Game.Traits;
|
||||
using OpenRa.Game.GameRules;
|
||||
|
||||
namespace OpenRa.Game.Orders
|
||||
{
|
||||
@@ -33,5 +35,59 @@ namespace OpenRa.Game.Orders
|
||||
foreach( var a in selection )
|
||||
Game.worldRenderer.DrawSelectionBox( a, Color.White, true );
|
||||
}
|
||||
|
||||
public Cursor GetCursor(int2 xy, MouseInput mi)
|
||||
{
|
||||
return ChooseCursor(mi);
|
||||
}
|
||||
|
||||
Cursor ChooseCursor( MouseInput mi )
|
||||
{
|
||||
var p = Game.controller.MousePosition;
|
||||
var c = Order(p.ToInt2(), mi)
|
||||
.Where(o => o.Validate())
|
||||
.Select(o => CursorForOrderString(o.OrderString, o.Subject, o.TargetLocation))
|
||||
.FirstOrDefault(a => a != null);
|
||||
|
||||
return c ??
|
||||
(Game.SelectActorsInBox(Game.CellSize * p,
|
||||
Game.CellSize * p).Any()
|
||||
? Cursor.Select : Cursor.Default);
|
||||
}
|
||||
|
||||
Cursor CursorForOrderString(string s, Actor a, int2 location)
|
||||
{
|
||||
var movement = a.traits.WithInterface<IMovement>().FirstOrDefault();
|
||||
switch (s)
|
||||
{
|
||||
case "Attack": return Cursor.Attack;
|
||||
case "Heal": return Cursor.Heal;
|
||||
case "C4": return Cursor.C4;
|
||||
case "Move":
|
||||
if (movement.CanEnterCell(location))
|
||||
return Cursor.Move;
|
||||
else
|
||||
return Cursor.MoveBlocked;
|
||||
case "DeployMcv":
|
||||
var factBuildingInfo = (BuildingInfo)Rules.UnitInfo["fact"];
|
||||
if (Game.CanPlaceBuilding(factBuildingInfo, a.Location - new int2(1, 1), a, false))
|
||||
return Cursor.Deploy;
|
||||
else
|
||||
return Cursor.DeployBlocked;
|
||||
case "Deploy": return Cursor.Deploy;
|
||||
case "Chronoshift":
|
||||
if (movement.CanEnterCell(location))
|
||||
return Cursor.Chronoshift;
|
||||
else
|
||||
return Cursor.MoveBlocked;
|
||||
case "Enter": return Cursor.Enter;
|
||||
case "Deliver": return Cursor.Enter;
|
||||
case "Infiltrate": return Cursor.Enter;
|
||||
case "Capture": return Cursor.Capture;
|
||||
case "Harvest": return Cursor.Attack; // TODO: special harvest cursor?
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user