From 7695714f6673b074e40ad85618da078c0ced35e7 Mon Sep 17 00:00:00 2001 From: Ivaylo Draganov Date: Wed, 2 Jan 2019 22:52:20 +0200 Subject: [PATCH] Add hotkey for removing actors from control groups * Add `RemoveFromControlGroup` hotkey * Add `RemoveFromControlGroup` method to `OpenRA.Game.Selection` --- OpenRA.Game/Selection.cs | 7 +++ OpenRA.Mods.Common/OpenRA.Mods.Common.csproj | 1 + .../RemoveFromControlGroupHotkeyLogic.cs | 45 +++++++++++++++++++ mods/cnc/chrome/ingame.yaml | 3 +- mods/common/chrome/ingame.yaml | 3 +- mods/common/hotkeys/game.yaml | 4 ++ 6 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 OpenRA.Mods.Common/Widgets/Logic/Ingame/Hotkeys/RemoveFromControlGroupHotkeyLogic.cs diff --git a/OpenRA.Game/Selection.cs b/OpenRA.Game/Selection.cs index 6987fa2764..b8519c38c5 100644 --- a/OpenRA.Game/Selection.cs +++ b/OpenRA.Game/Selection.cs @@ -187,6 +187,13 @@ namespace OpenRA controlGroups[group].Add(a); } + public void RemoveFromControlGroup(Actor a) + { + var group = GetControlGroupForActor(a); + if (group.HasValue) + controlGroups[group.Value].Remove(a); + } + public int? GetControlGroupForActor(Actor a) { return controlGroups.Where(g => g.Value.Contains(a)) diff --git a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj index ab95510a19..0cddf7be71 100644 --- a/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj +++ b/OpenRA.Mods.Common/OpenRA.Mods.Common.csproj @@ -892,6 +892,7 @@ + diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/Hotkeys/RemoveFromControlGroupHotkeyLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/Hotkeys/RemoveFromControlGroupHotkeyLogic.cs new file mode 100644 index 0000000000..0a79790855 --- /dev/null +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/Hotkeys/RemoveFromControlGroupHotkeyLogic.cs @@ -0,0 +1,45 @@ +#region Copyright & License Information +/* + * Copyright 2007-2019 The OpenRA Developers (see AUTHORS) + * This file is part of OpenRA, which is free software. It is made + * available to you under the terms of the GNU General Public License + * as published by the Free Software Foundation, either version 3 of + * the License, or (at your option) any later version. For more + * information, see COPYING. + */ +#endregion + +using System.Collections.Generic; +using System.Linq; +using OpenRA.Mods.Common.Lint; +using OpenRA.Widgets; + +namespace OpenRA.Mods.Common.Widgets.Logic.Ingame +{ + [ChromeLogicArgsHotkeys("RemoveFromControlGroupKey")] + public class RemoveFromControlGroupHotkeyLogic : SingleHotkeyBaseLogic + { + readonly Selection selection; + readonly World world; + + [ObjectCreator.UseCtor] + public RemoveFromControlGroupHotkeyLogic(Widget widget, ModData modData, World world, Dictionary logicArgs) + : base(widget, modData, "RemoveFromControlGroupKey", "WORLD_KEYHANDLER", logicArgs) + { + selection = world.Selection; + this.world = world; + } + + protected override bool OnHotkeyActivated(KeyInput e) + { + var selectedActors = selection.Actors + .Where(a => a.Owner == world.LocalPlayer && a.IsInWorld && !a.IsDead) + .ToArray(); + + foreach (var a in selectedActors) + selection.RemoveFromControlGroup(a); + + return true; + } + } +} diff --git a/mods/cnc/chrome/ingame.yaml b/mods/cnc/chrome/ingame.yaml index 26d678c3fb..e8a6f4c726 100644 --- a/mods/cnc/chrome/ingame.yaml +++ b/mods/cnc/chrome/ingame.yaml @@ -10,7 +10,8 @@ Container@INGAME_ROOT: TakeScreenshotKey: TakeScreenshot MuteAudioKey: ToggleMute LogicKeyListener@WORLD_KEYHANDLER: - Logic: CycleBasesHotkeyLogic, CycleProductionActorsHotkeyLogic, JumpToLastEventHotkeyLogic, JumpToSelectedActorsHotkeyLogic, TogglePixelDoubleHotkeyLogic, TogglePlayerStanceColorHotkeyLogic, CycleStatusBarsHotkeyLogic, PauseHotkeyLogic + Logic: CycleBasesHotkeyLogic, CycleProductionActorsHotkeyLogic, JumpToLastEventHotkeyLogic, JumpToSelectedActorsHotkeyLogic, TogglePixelDoubleHotkeyLogic, TogglePlayerStanceColorHotkeyLogic, CycleStatusBarsHotkeyLogic, PauseHotkeyLogic, RemoveFromControlGroupHotkeyLogic + RemoveFromControlGroupKey: RemoveFromControlGroup CycleBasesKey: CycleBase CycleProductionActorsKey: CycleProductionBuildings JumpToLastEventKey: ToLastEvent diff --git a/mods/common/chrome/ingame.yaml b/mods/common/chrome/ingame.yaml index ba7ba30dc2..9364a13cae 100644 --- a/mods/common/chrome/ingame.yaml +++ b/mods/common/chrome/ingame.yaml @@ -10,7 +10,8 @@ Container@INGAME_ROOT: TakeScreenshotKey: TakeScreenshot MuteAudioKey: ToggleMute LogicKeyListener@WORLD_KEYHANDLER: - Logic: CycleBasesHotkeyLogic, CycleProductionActorsHotkeyLogic, JumpToLastEventHotkeyLogic, JumpToSelectedActorsHotkeyLogic, TogglePixelDoubleHotkeyLogic, TogglePlayerStanceColorHotkeyLogic, CycleStatusBarsHotkeyLogic, PauseHotkeyLogic + Logic: CycleBasesHotkeyLogic, CycleProductionActorsHotkeyLogic, JumpToLastEventHotkeyLogic, JumpToSelectedActorsHotkeyLogic, TogglePixelDoubleHotkeyLogic, TogglePlayerStanceColorHotkeyLogic, CycleStatusBarsHotkeyLogic, PauseHotkeyLogic, RemoveFromControlGroupHotkeyLogic + RemoveFromControlGroupKey: RemoveFromControlGroup CycleBasesKey: CycleBase CycleProductionActorsKey: CycleProductionBuildings JumpToLastEventKey: ToLastEvent diff --git a/mods/common/hotkeys/game.yaml b/mods/common/hotkeys/game.yaml index 9fb0329692..5e52911b21 100644 --- a/mods/common/hotkeys/game.yaml +++ b/mods/common/hotkeys/game.yaml @@ -18,6 +18,10 @@ SelectUnitsByType: W Description: Select units by type Types: World +RemoveFromControlGroup: + Description: Remove from control group + Types: World + Pause: PAUSE Description: Pause / Unpause Types: World