diff --git a/OpenRa.Game/Controller.cs b/OpenRa.Game/Controller.cs index 401984036a..e899d9bdbd 100644 --- a/OpenRa.Game/Controller.cs +++ b/OpenRa.Game/Controller.cs @@ -5,6 +5,7 @@ using IjwFramework.Types; using OpenRa.Game.GameRules; using OpenRa.Game.Graphics; using OpenRa.Game.Traits; +using IjwFramework.Collections; namespace OpenRa.Game { @@ -67,20 +68,7 @@ namespace OpenRa.Game if (!(orderGenerator is PlaceBuilding)) { var newSelection = Game.SelectActorsInBox(Game.CellSize * dragStart, Game.CellSize * xy); - var oldSelection = (orderGenerator is UnitOrderGenerator) - ? (orderGenerator as UnitOrderGenerator).selection : new Actor[] { }.AsEnumerable(); - - if (dragStart == xy) - orderGenerator = new UnitOrderGenerator(mi.Modifiers.HasModifier(Keys.Shift) ? oldSelection.SymmetricDifference(newSelection) : newSelection); - else - orderGenerator = new UnitOrderGenerator(mi.Modifiers.HasModifier(Keys.Shift) ? oldSelection.Union(newSelection) : newSelection); - - var voicedUnit = ((UnitOrderGenerator)orderGenerator).selection - .Where(a => a.traits.Contains() - && a.Owner == Game.LocalPlayer) - .FirstOrDefault(); - - Sound.PlayVoice("Select", voicedUnit); + CombineSelection(newSelection, mi.Modifiers.HasModifier(Keys.Shift), dragStart == xy); } dragStart = dragEnd = xy; @@ -95,6 +83,26 @@ namespace OpenRa.Game return true; } + void CombineSelection(IEnumerable newSelection, bool isCombine, bool isClick) + { + var oldSelection = (orderGenerator is UnitOrderGenerator) + ? (orderGenerator as UnitOrderGenerator).selection : new Actor[] { }.AsEnumerable(); + + if (isClick) + orderGenerator = new UnitOrderGenerator(isCombine + ? oldSelection.SymmetricDifference(newSelection) : newSelection); + else + orderGenerator = new UnitOrderGenerator(isCombine + ? oldSelection.Union(newSelection) : newSelection); + + var voicedUnit = ((UnitOrderGenerator)orderGenerator).selection + .Where(a => a.traits.Contains() + && a.Owner == Game.LocalPlayer) + .FirstOrDefault(); + + Sound.PlayVoice("Select", voicedUnit); + } + public Pair? SelectionBox { get @@ -138,5 +146,30 @@ namespace OpenRa.Game return null; } } + + Cache> cache = new Cache>(_ => new List()); + + public void DoControlGroup(int group, Keys keys) + { + var uog = orderGenerator as UnitOrderGenerator; + if (keys.HasModifier(Keys.Control)) + { + if (uog == null || !uog.selection.Any()) + return; + + cache[group].Clear(); + cache[group].AddRange(uog.selection); + return; + } + + if (keys.HasModifier(Keys.Alt)) + { + // center on this group + return; + } + + if (uog == null) return; + CombineSelection(cache[group], keys.HasModifier(Keys.Shift), false); + } } } diff --git a/OpenRa.Game/MainWindow.cs b/OpenRa.Game/MainWindow.cs index 048393137c..5ff62cc5dc 100755 --- a/OpenRa.Game/MainWindow.cs +++ b/OpenRa.Game/MainWindow.cs @@ -139,6 +139,10 @@ namespace OpenRa.Game "ToggleReady", null, null, int2.Zero, Game.LocalPlayer.IsReady ? "ready" : "not ready") { IsImmediate = true }); } + + if (!Game.chat.isChatting) + if (e.KeyCode >= Keys.D0 && e.KeyCode <= Keys.D9) + Game.controller.DoControlGroup( (int)e.KeyCode - (int)Keys.D0, e.Modifiers ); } protected override void OnKeyPress(KeyPressEventArgs e)