add stance cycling on 'z'

This commit is contained in:
Chris Forbes
2011-10-11 09:18:31 +13:00
parent 59e4dd666a
commit 7f1918d07b
2 changed files with 34 additions and 1 deletions

View File

@@ -27,6 +27,7 @@ namespace OpenRA.Mods.RA.Widgets
public string StopKey = "s";
public string ScatterKey = "x";
public string DeployKey = "f";
public string StanceCycleKey = "z";
public string BaseCycleKey = "backspace";
public readonly OrderManager OrderManager;
@@ -38,6 +39,7 @@ namespace OpenRA.Mods.RA.Widgets
public override string GetCursor(int2 pos) { return null; }
public override Rectangle GetEventBounds() { return Rectangle.Empty; }
public override bool HandleKeyPress(KeyInput e)
{
if (World == null) return false;
@@ -67,6 +69,9 @@ namespace OpenRA.Mods.RA.Widgets
if (e.KeyName == DeployKey)
return PerformDeploy();
if (e.KeyName == StanceCycleKey)
return PerformStanceCycle();
}
return false;
@@ -115,6 +120,28 @@ namespace OpenRA.Mods.RA.Widgets
return true;
}
bool PerformStanceCycle()
{
var actor = World.Selection.Actors
.Where(a => a.Owner == World.LocalPlayer)
.Select(a => Pair.New( a, a.TraitOrDefault<AutoTarget>() ))
.Where(a => a.Second != null).FirstOrDefault();
if (actor.First == null)
return true;
var stances = (UnitStance[])Enum.GetValues(typeof(UnitStance));
var nextStance = stances.Concat(stances).SkipWhile(s => s != actor.Second.stance).Skip(1).First();
PerformKeyboardOrderOnSelection(a =>
new Order("SetUnitStance", a, false) { TargetLocation = new int2((int)nextStance, 0) });
Game.Debug( "Unit stance set to: {0}".F(nextStance) );
return true;
}
bool CycleBases()
{
var bases = World.ActorsWithTrait<BaseBuilding>()