From e7ed9a1ff7c725ee46ca1c3a92adc507320a2073 Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Sat, 22 Oct 2011 11:30:09 +1300 Subject: [PATCH] tidy up select-all-on-screen --- OpenRA.Game/Graphics/Viewport.cs | 9 +------ .../WorldInteractionControllerWidget.cs | 25 ++++++++----------- 2 files changed, 12 insertions(+), 22 deletions(-) diff --git a/OpenRA.Game/Graphics/Viewport.cs b/OpenRA.Game/Graphics/Viewport.cs index 38a56e8535..2f94ded976 100755 --- a/OpenRA.Game/Graphics/Viewport.cs +++ b/OpenRA.Game/Graphics/Viewport.cs @@ -18,14 +18,7 @@ using OpenRA.Support; namespace OpenRA.Graphics { [Flags] - public enum ScrollDirection - { - None = 0, - Up = 1, - Left = 2, - Down = 4, - Right = 8 - } + public enum ScrollDirection { None = 0, Up = 1, Left = 2, Down = 4, Right = 8 } public class Viewport { diff --git a/OpenRA.Game/Widgets/WorldInteractionControllerWidget.cs b/OpenRA.Game/Widgets/WorldInteractionControllerWidget.cs index df8d4f031c..be6a0f772e 100644 --- a/OpenRA.Game/Widgets/WorldInteractionControllerWidget.cs +++ b/OpenRA.Game/Widgets/WorldInteractionControllerWidget.cs @@ -36,14 +36,14 @@ namespace OpenRA.Widgets var selbox = SelectionBox; if (selbox == null) { - foreach (var u in SelectActorsInBox(world, dragStart, dragStart)) + foreach (var u in SelectActorsInBox(world, dragStart, dragStart, _ => true)) worldRenderer.DrawRollover(u); return; } - Game.Renderer.WorldLineRenderer.DrawRect( selbox.Value.First, selbox.Value.Second, Color.White ); - foreach (var u in SelectActorsInBox(world, selbox.Value.First, selbox.Value.Second)) + Game.Renderer.WorldLineRenderer.DrawRect(selbox.Value.First, selbox.Value.Second, Color.White); + foreach (var u in SelectActorsInBox(world, selbox.Value.First, selbox.Value.Second, _ => true)) worldRenderer.DrawRollover(u); } @@ -72,20 +72,17 @@ namespace OpenRA.Widgets { var unit = world.FindUnitsAtMouse(mi.Location).FirstOrDefault(); - Rectangle visibleWorld = Game.viewport.ViewBounds(world); - var newSelection = world.FindUnits(Game.viewport.ViewToWorldPx(new int2(visibleWorld.Left, visibleWorld.Top)), - Game.viewport.ViewToWorldPx(new int2(visibleWorld.Right, visibleWorld.Bottom))) - .Where(a => a.HasTrait() - && a.World.LocalShroud.IsVisible(a) - && unit != null - && a.Info.Name == unit.Info.Name - && a.Owner == unit.Owner); + var visibleWorld = Game.viewport.ViewBounds(world); + var topLeft = Game.viewport.ViewToWorldPx(new int2(visibleWorld.Left, visibleWorld.Top)); + var bottomRight = Game.viewport.ViewToWorldPx(new int2(visibleWorld.Right, visibleWorld.Bottom)); + var newSelection = SelectActorsInBox(world, topLeft, bottomRight, + a => unit != null && a.Info.Name == unit.Info.Name && a.Owner == unit.Owner); world.Selection.Combine(world, newSelection, true, false); } else { - var newSelection = SelectActorsInBox(world, dragStart, xy); + var newSelection = SelectActorsInBox(world, dragStart, xy, _ => true); world.Selection.Combine(world, newSelection, mi.Modifiers.HasModifier(Modifiers.Shift), dragStart == xy); } } @@ -160,10 +157,10 @@ namespace OpenRA.Widgets } static readonly Actor[] NoActors = {}; - IEnumerable SelectActorsInBox(World world, int2 a, int2 b) + IEnumerable SelectActorsInBox(World world, int2 a, int2 b, Func cond) { return world.FindUnits(a, b) - .Where( x => x.HasTrait() && world.LocalShroud.IsVisible(x) ) + .Where( x => x.HasTrait() && world.LocalShroud.IsVisible(x) && cond(x) ) .GroupBy(x => x.GetSelectionPriority()) .OrderByDescending(g => g.Key) .Select( g => g.AsEnumerable() )