From b72ea8c2277485425fb00a0f59e07609f81efb46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Sat, 7 Dec 2013 11:56:05 +0100 Subject: [PATCH] added a new hotkey to cycle production buildings except conyards --- OpenRA.Game/GameRules/Settings.cs | 1 + OpenRA.Mods.RA/Widgets/Logic/SettingsLogic.cs | 1 + OpenRA.Mods.RA/Widgets/WorldCommandWidget.cs | 27 +++++++++++++++++++ 3 files changed, 29 insertions(+) diff --git a/OpenRA.Game/GameRules/Settings.cs b/OpenRA.Game/GameRules/Settings.cs index d5c752ee20..682dbbb76b 100644 --- a/OpenRA.Game/GameRules/Settings.cs +++ b/OpenRA.Game/GameRules/Settings.cs @@ -157,6 +157,7 @@ namespace OpenRA.GameRules public Hotkey NextProductionTabKey = new Hotkey(Keycode.PAGEDOWN, Modifiers.None); public Hotkey PreviousProductionTabKey = new Hotkey(Keycode.PAGEUP, Modifiers.None); + public Hotkey CycleProductionBuildingsKey = new Hotkey(Keycode.TAB, Modifiers.None); public Hotkey ToggleStatusBarsKey = new Hotkey(Keycode.INSERT, Modifiers.None); diff --git a/OpenRA.Mods.RA/Widgets/Logic/SettingsLogic.cs b/OpenRA.Mods.RA/Widgets/Logic/SettingsLogic.cs index 44f92d9bc8..66484c1624 100644 --- a/OpenRA.Mods.RA/Widgets/Logic/SettingsLogic.cs +++ b/OpenRA.Mods.RA/Widgets/Logic/SettingsLogic.cs @@ -259,6 +259,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic { "NextProductionTabKey", "Next production tab" }, { "PreviousProductionTabKey", "Previous production tab" }, + { "CycleProductionBuildingsKey", "Cycle production facilities" }, { "ToggleStatusBarsKey", "Toggle status bars" }, }; diff --git a/OpenRA.Mods.RA/Widgets/WorldCommandWidget.cs b/OpenRA.Mods.RA/Widgets/WorldCommandWidget.cs index f4dedf5356..d5bb6105b8 100644 --- a/OpenRA.Mods.RA/Widgets/WorldCommandWidget.cs +++ b/OpenRA.Mods.RA/Widgets/WorldCommandWidget.cs @@ -47,9 +47,13 @@ namespace OpenRA.Mods.RA.Widgets { var key = Hotkey.FromKeyInput(e); var ks = Game.Settings.Keys; + if (key == ks.CycleBaseKey) return CycleBases(); + if (key == ks.CycleProductionBuildingsKey) + return CycleProductionBuildings(); + if (key == ks.ToLastEventKey) return ToLastEvent(); @@ -199,6 +203,29 @@ namespace OpenRA.Mods.RA.Widgets return ToSelection(); } + bool CycleProductionBuildings() + { + var facilities = world.ActorsWithTrait() + .Where(a => a.Actor.Owner == world.LocalPlayer && !a.Actor.HasTrait()) + .ToArray(); + + if (!facilities.Any()) + return true; + + var next = facilities + .Select(b => b.Actor) + .SkipWhile(b => !world.Selection.Actors.Contains(b)) + .Skip(1) + .FirstOrDefault(); + + if (next == null) + next = facilities.Select(b => b.Actor).First(); + + world.Selection.Combine(world, new Actor[] { next }, false, true); + + return ToSelection(); + } + bool ToLastEvent() { if (world.LocalPlayer == null)