Clean up actor selection in WorldInteractionControllerWidget.

This commit is contained in:
Paul Chote
2014-03-09 12:33:49 +13:00
parent ea6f76e4f6
commit bbd1331536
2 changed files with 15 additions and 7 deletions

View File

@@ -206,5 +206,11 @@ namespace OpenRA.Traits
} }
} }
} }
public IEnumerable<Actor> ActorsInWorld()
{
return actors.SelectMany(a => a.Where(b => b.IsInWorld))
.Distinct();
}
} }
} }

View File

@@ -209,18 +209,20 @@ namespace OpenRA.Widgets
} }
else if (key == Game.Settings.Keys.SelectUnitsByTypeKey) else if (key == Game.Settings.Keys.SelectUnitsByTypeKey)
{ {
var selectedTypes = World.Selection.Actors.Where( var selectedTypes = World.Selection.Actors
x => x.Owner == World.RenderPlayer).Select(a => a.Info); .Where(x => x.Owner == World.RenderPlayer)
.Select(a => a.Info);
Func<Actor, bool> cond = a => a.Owner == World.RenderPlayer && selectedTypes.Contains(a.Info); Func<Actor, bool> cond = a => a.Owner == World.RenderPlayer && selectedTypes.Contains(a.Info);
var newSelection = SelectActorsInBox( var tl = worldRenderer.Viewport.TopLeft;
World, worldRenderer.Viewport.TopLeft, worldRenderer.Viewport.BottomRight, cond); var br = worldRenderer.Viewport.BottomRight;
var newSelection = SelectActorsInBox(World, tl, br, cond);
if (newSelection.Count() > selectedTypes.Count()) if (newSelection.Count() > selectedTypes.Count())
Game.Debug("Selected across screen"); Game.Debug("Selected across screen");
else else
{ {
newSelection = World.ActorMap.ActorsInBox( newSelection = World.ActorMap.ActorsInWorld().Where(cond);
World.Map.Bounds.TopLeftAsCPos().TopLeft,
World.Map.Bounds.BottomRightAsCPos().BottomRight).Where(cond);
Game.Debug("Selected across map"); Game.Debug("Selected across map");
} }