diff --git a/OpenRa.Game/Controller.cs b/OpenRa.Game/Controller.cs index e899d9bdbd..954d71a098 100644 --- a/OpenRa.Game/Controller.cs +++ b/OpenRa.Game/Controller.cs @@ -164,7 +164,7 @@ namespace OpenRa.Game if (keys.HasModifier(Keys.Alt)) { - // center on this group + Game.viewport.Center(cache[group]); return; } diff --git a/OpenRa.Game/Graphics/Viewport.cs b/OpenRa.Game/Graphics/Viewport.cs index f0345a5b0e..2655c25555 100644 --- a/OpenRa.Game/Graphics/Viewport.cs +++ b/OpenRa.Game/Graphics/Viewport.cs @@ -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 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)); } } }