diff --git a/OpenRA.Game/Traits/World/ActorMap.cs b/OpenRA.Game/Traits/World/ActorMap.cs index c85de0c256..810d69ca47 100644 --- a/OpenRA.Game/Traits/World/ActorMap.cs +++ b/OpenRA.Game/Traits/World/ActorMap.cs @@ -206,5 +206,11 @@ namespace OpenRA.Traits } } } + + public IEnumerable ActorsInWorld() + { + return actors.SelectMany(a => a.Where(b => b.IsInWorld)) + .Distinct(); + } } } diff --git a/OpenRA.Game/Widgets/WorldInteractionControllerWidget.cs b/OpenRA.Game/Widgets/WorldInteractionControllerWidget.cs index 3b1e4e50be..4f9ab0454f 100644 --- a/OpenRA.Game/Widgets/WorldInteractionControllerWidget.cs +++ b/OpenRA.Game/Widgets/WorldInteractionControllerWidget.cs @@ -209,18 +209,20 @@ namespace OpenRA.Widgets } else if (key == Game.Settings.Keys.SelectUnitsByTypeKey) { - var selectedTypes = World.Selection.Actors.Where( - x => x.Owner == World.RenderPlayer).Select(a => a.Info); + var selectedTypes = World.Selection.Actors + .Where(x => x.Owner == World.RenderPlayer) + .Select(a => a.Info); + Func cond = a => a.Owner == World.RenderPlayer && selectedTypes.Contains(a.Info); - var newSelection = SelectActorsInBox( - World, worldRenderer.Viewport.TopLeft, worldRenderer.Viewport.BottomRight, cond); + var tl = worldRenderer.Viewport.TopLeft; + var br = worldRenderer.Viewport.BottomRight; + var newSelection = SelectActorsInBox(World, tl, br, cond); + if (newSelection.Count() > selectedTypes.Count()) Game.Debug("Selected across screen"); else { - newSelection = World.ActorMap.ActorsInBox( - World.Map.Bounds.TopLeftAsCPos().TopLeft, - World.Map.Bounds.BottomRightAsCPos().BottomRight).Where(cond); + newSelection = World.ActorMap.ActorsInWorld().Where(cond); Game.Debug("Selected across map"); }