From bcba26a04e1bc589c2ba8d2cc5e0bb0303965b99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Sat, 7 Dec 2013 11:44:01 +0100 Subject: [PATCH 1/6] don't hardcode SHIFT modifier for backwards tab cycle closes #4144 --- OpenRA.Game/GameRules/Settings.cs | 3 +- .../Widgets/ProductionTabsWidget.cs | 20 ++++++----- OpenRA.Mods.RA/Widgets/BuildPaletteWidget.cs | 33 ++++++++++--------- OpenRA.Mods.RA/Widgets/Logic/SettingsLogic.cs | 5 +-- 4 files changed, 35 insertions(+), 26 deletions(-) mode change 100755 => 100644 OpenRA.Mods.Cnc/Widgets/ProductionTabsWidget.cs diff --git a/OpenRA.Game/GameRules/Settings.cs b/OpenRA.Game/GameRules/Settings.cs index bb3d8adbc6..d5c752ee20 100644 --- a/OpenRA.Game/GameRules/Settings.cs +++ b/OpenRA.Game/GameRules/Settings.cs @@ -155,7 +155,8 @@ namespace OpenRA.GameRules public Hotkey PowerDownKey = new Hotkey(Keycode.F11, Modifiers.None); public Hotkey RepairKey = new Hotkey(Keycode.F12, Modifiers.None); - public Hotkey CycleTabsKey = new Hotkey(Keycode.TAB, Modifiers.None); + public Hotkey NextProductionTabKey = new Hotkey(Keycode.PAGEDOWN, Modifiers.None); + public Hotkey PreviousProductionTabKey = new Hotkey(Keycode.PAGEUP, Modifiers.None); public Hotkey ToggleStatusBarsKey = new Hotkey(Keycode.INSERT, Modifiers.None); diff --git a/OpenRA.Mods.Cnc/Widgets/ProductionTabsWidget.cs b/OpenRA.Mods.Cnc/Widgets/ProductionTabsWidget.cs old mode 100755 new mode 100644 index cf05ad0bf6..d5ea98871d --- a/OpenRA.Mods.Cnc/Widgets/ProductionTabsWidget.cs +++ b/OpenRA.Mods.Cnc/Widgets/ProductionTabsWidget.cs @@ -89,10 +89,12 @@ namespace OpenRA.Mods.Cnc.Widgets paletteWidget = Lazy.New(() => Ui.Root.Get(PaletteWidget)); } - public void SelectNextTab(bool reverse) + public bool SelectNextTab(bool reverse) { if (queueGroup == null) - return; + return true; + + Sound.PlayNotification(null, "Sounds", "ClickSound", null); // Prioritize alerted queues var queues = Groups[queueGroup].Tabs.Select(t => t.Queue) @@ -103,6 +105,8 @@ namespace OpenRA.Mods.Cnc.Widgets CurrentQueue = queues.SkipWhile(q => q != CurrentQueue) .Skip(1).FirstOrDefault() ?? queues.FirstOrDefault(); + + return true; } public string QueueGroup @@ -277,12 +281,12 @@ namespace OpenRA.Mods.Cnc.Widgets if (e.Event != KeyInputEvent.Down) return false; - if (Hotkey.FromKeyInput(e) == Game.Settings.Keys.CycleTabsKey) - { - Sound.PlayNotification(null, "Sounds", "ClickSound", null); - SelectNextTab(e.Modifiers.HasModifier(Modifiers.Shift)); - return true; - } + var hotkey = Hotkey.FromKeyInput(e); + + if (hotkey == Game.Settings.Keys.NextProductionTabKey) + return SelectNextTab(false); + else if (hotkey == Game.Settings.Keys.PreviousProductionTabKey) + return SelectNextTab(true); return false; } diff --git a/OpenRA.Mods.RA/Widgets/BuildPaletteWidget.cs b/OpenRA.Mods.RA/Widgets/BuildPaletteWidget.cs index e6fd815b5c..02de9e4984 100755 --- a/OpenRA.Mods.RA/Widgets/BuildPaletteWidget.cs +++ b/OpenRA.Mods.RA/Widgets/BuildPaletteWidget.cs @@ -149,11 +149,13 @@ namespace OpenRA.Mods.RA.Widgets if (e.Event == KeyInputEvent.Up) return false; - if (Hotkey.FromKeyInput(e) == Game.Settings.Keys.CycleTabsKey) - { - TabChange(e.Modifiers.HasModifier(Modifiers.Shift)); - return true; - } + var hotkey = Hotkey.FromKeyInput(e); + + if (hotkey == Game.Settings.Keys.NextProductionTabKey) + return ChangeTab(false); + else if (hotkey == Game.Settings.Keys.PreviousProductionTabKey) + return ChangeTab(true); + return DoBuildingHotkey(e, world); } @@ -164,15 +166,10 @@ namespace OpenRA.Mods.RA.Widgets return true; if (mi.Button == MouseButton.WheelDown) - { - TabChange(false); - return true; - } + return ChangeTab(false); + if (mi.Button == MouseButton.WheelUp) - { - TabChange(true); - return true; - } + return ChangeTab(true); var action = tabs.Where(a => a.First.Contains(mi.Location)) .Select(a => a.Second).FirstOrDefault(); @@ -515,14 +512,20 @@ namespace OpenRA.Mods.RA.Widgets return false; } - void TabChange(bool shift) + // NOTE: Always return true here to prevent mouse events from passing through the sidebar and interacting with the world behind it. + bool ChangeTab(bool reverse) { var queues = VisibleQueues.Concat(VisibleQueues); - if (shift) queues = queues.Reverse(); + if (reverse) + queues = queues.Reverse(); var nextQueue = queues.SkipWhile(q => q != CurrentQueue) .ElementAtOrDefault(1); if (nextQueue != null) + { SetCurrentTab(nextQueue); + return true; + } + return true; } } } \ No newline at end of file diff --git a/OpenRA.Mods.RA/Widgets/Logic/SettingsLogic.cs b/OpenRA.Mods.RA/Widgets/Logic/SettingsLogic.cs index 9e93fe7229..44f92d9bc8 100644 --- a/OpenRA.Mods.RA/Widgets/Logic/SettingsLogic.cs +++ b/OpenRA.Mods.RA/Widgets/Logic/SettingsLogic.cs @@ -257,9 +257,10 @@ namespace OpenRA.Mods.RA.Widgets.Logic { "PowerDownKey", "Power-down mode" }, { "RepairKey", "Repair mode" }, - { "CycleTabsKey", "Cycle production tabs" }, + { "NextProductionTabKey", "Next production tab" }, + { "PreviousProductionTabKey", "Previous production tab" }, - { "ToggleStatusBarsKey", "Toggle status bars" } + { "ToggleStatusBarsKey", "Toggle status bars" }, }; var unitHotkeys = new Dictionary() From 316161a3e0cccb7a20b14566700408a192db3b89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Sat, 7 Dec 2013 12:20:07 +0100 Subject: [PATCH 2/6] add audio feedback on mouse-wheel and hotkey build palette cycle --- OpenRA.Mods.RA/Widgets/BuildPaletteWidget.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/OpenRA.Mods.RA/Widgets/BuildPaletteWidget.cs b/OpenRA.Mods.RA/Widgets/BuildPaletteWidget.cs index 02de9e4984..998c5c9226 100755 --- a/OpenRA.Mods.RA/Widgets/BuildPaletteWidget.cs +++ b/OpenRA.Mods.RA/Widgets/BuildPaletteWidget.cs @@ -515,6 +515,7 @@ namespace OpenRA.Mods.RA.Widgets // NOTE: Always return true here to prevent mouse events from passing through the sidebar and interacting with the world behind it. bool ChangeTab(bool reverse) { + Sound.PlayNotification(null, "Sounds", "TabClick", null); var queues = VisibleQueues.Concat(VisibleQueues); if (reverse) queues = queues.Reverse(); 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 3/6] 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) From 127c9bb98cd0ac60f64a7146e1e2d928042983e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Sat, 7 Dec 2013 11:58:59 +0100 Subject: [PATCH 4/6] update CHANGELOG --- CHANGELOG | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index 525273b028..3efcaf2c9c 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -15,6 +15,8 @@ NEW: Added a setting to always display unit status bars (can also be toggled by hotkey). Added a setting for team health bar colors. Added a new hotkey to select all units on screen (default: CTRL + A). + Added a new hotkey to jump to production buildings (default: TAB). + Changed default hotkey (PageUp/Down) for build palette cycling and made reverse user configurable. Asset Browser: Fixed crashes when trying to load invalid filenames or sprites with just 1 frame. Added support for all sprite types. From 2e6646bd7390ba5c5ceb777384fc7ed8e2eb6bda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Sun, 8 Dec 2013 12:02:44 +0100 Subject: [PATCH 5/6] cycle production buildings ordered by products --- OpenRA.Mods.RA/Widgets/WorldCommandWidget.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/OpenRA.Mods.RA/Widgets/WorldCommandWidget.cs b/OpenRA.Mods.RA/Widgets/WorldCommandWidget.cs index d5bb6105b8..c86534ea1c 100644 --- a/OpenRA.Mods.RA/Widgets/WorldCommandWidget.cs +++ b/OpenRA.Mods.RA/Widgets/WorldCommandWidget.cs @@ -207,6 +207,7 @@ namespace OpenRA.Mods.RA.Widgets { var facilities = world.ActorsWithTrait() .Where(a => a.Actor.Owner == world.LocalPlayer && !a.Actor.HasTrait()) + .OrderBy(f => f.Actor.Info.Traits.Get().Produces.First()) .ToArray(); if (!facilities.Any()) From e0efa00d95621deee5ac196e20933bfb14593be4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20Mail=C3=A4nder?= Date: Sun, 8 Dec 2013 12:04:50 +0100 Subject: [PATCH 6/6] StyleCop --- OpenRA.Mods.RA/PrimaryBuilding.cs | 32 +++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/OpenRA.Mods.RA/PrimaryBuilding.cs b/OpenRA.Mods.RA/PrimaryBuilding.cs index 301a5f4ded..46f151087a 100755 --- a/OpenRA.Mods.RA/PrimaryBuilding.cs +++ b/OpenRA.Mods.RA/PrimaryBuilding.cs @@ -10,12 +10,21 @@ using System.Collections.Generic; using System.Linq; -using OpenRA.Mods.RA.Orders; using OpenRA.FileFormats; +using OpenRA.Mods.RA.Orders; using OpenRA.Traits; namespace OpenRA.Mods.RA { + static class PrimaryExts + { + public static bool IsPrimaryBuilding(this Actor a) + { + var pb = a.TraitOrDefault(); + return pb != null && pb.IsPrimary; + } + } + [Desc("Used together with ClassicProductionQueue.")] class PrimaryBuildingInfo : TraitInfo { } @@ -26,18 +35,18 @@ namespace OpenRA.Mods.RA public IEnumerable GetTags() { - yield return (isPrimary) ? TagType.Primary : TagType.None; + yield return isPrimary ? TagType.Primary : TagType.None; } public IEnumerable Orders { - get { yield return new DeployOrderTargeter( "PrimaryProducer", 1 ); } + get { yield return new DeployOrderTargeter("PrimaryProducer", 1); } } - public Order IssueOrder( Actor self, IOrderTargeter order, Target target, bool queued ) + public Order IssueOrder(Actor self, IOrderTargeter order, Target target, bool queued) { - if( order.OrderID == "PrimaryProducer" ) - return new Order( order.OrderID, self, false ); + if (order.OrderID == "PrimaryProducer") + return new Order(order.OrderID, self, false); return null; } @@ -63,7 +72,7 @@ namespace OpenRA.Mods.RA .ActorsWithTrait() .Where(a => a.Actor.Owner == self.Owner) .Where(x => x.Trait.IsPrimary - && (x.Actor.Info.Traits.Get().Produces.Contains(p)))) + && x.Actor.Info.Traits.Get().Produces.Contains(p))) b.Trait.SetPrimaryProducer(b.Actor, false); isPrimary = true; @@ -71,13 +80,4 @@ namespace OpenRA.Mods.RA Sound.PlayNotification(self.Owner, "Speech", "PrimaryBuildingSelected", self.Owner.Country.Race); } } - - static class PrimaryExts - { - public static bool IsPrimaryBuilding(this Actor a) - { - var pb = a.TraitOrDefault(); - return pb != null && pb.IsPrimary; - } - } }