added M-n support to center on a group

This commit is contained in:
Chris Forbes
2009-12-15 21:17:38 +13:00
parent 6d1653ca2f
commit 8ed1fec49c
2 changed files with 13 additions and 8 deletions

View File

@@ -83,15 +83,20 @@ namespace OpenRa.Game.Graphics
return (1 / 24.0f) * (new float2(mi.Location.X, mi.Location.Y) + Location);
}
public void Center(IEnumerable<Actor> actors)
{
if (!actors.Any()) return;
var avgPos = (1f / actors.Count()) * actors
.Select(a => a.CenterLocation)
.Aggregate((a, b) => a + b);
scrollPosition = avgPos - .5f * new float2(Width, Height);
}
public void GoToStartLocation()
{
var unit = Game.world.Actors
.FirstOrDefault(a => a.Owner == Game.LocalPlayer);
if (unit == null)
return;
scrollPosition = unit.CenterLocation - .5f * new float2(Width, Height);
Center(Game.world.Actors.Where(a => a.Owner == Game.LocalPlayer));
}
}
}