From d9752c3bdfd7a6aee0a07f88deafa46ae08510e6 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sun, 28 Dec 2014 17:24:12 +1300 Subject: [PATCH] Make production type hotkeys configurable. --- OpenRA.Game/Settings.cs | 6 ++++++ OpenRA.Mods.Cnc/Widgets/Logic/ProductionTabsLogic.cs | 10 ++++++++++ OpenRA.Mods.Common/Widgets/Logic/SettingsLogic.cs | 11 ++++++++++- .../Widgets/Logic/ClassicProductionLogic.cs | 10 ++++++++++ OpenRA.Mods.RA/Widgets/ProductionTypeButtonWidget.cs | 1 + mods/cnc/chrome/ingame.yaml | 10 +++++----- mods/ra/chrome/ingame-player.yaml | 12 ++++++------ 7 files changed, 48 insertions(+), 12 deletions(-) diff --git a/OpenRA.Game/Settings.cs b/OpenRA.Game/Settings.cs index 78207f5c32..869762b2b8 100644 --- a/OpenRA.Game/Settings.cs +++ b/OpenRA.Game/Settings.cs @@ -200,6 +200,12 @@ namespace OpenRA public Hotkey Production23Key = new Hotkey(Keycode.F11, Modifiers.Ctrl); public Hotkey Production24Key = new Hotkey(Keycode.F12, Modifiers.Ctrl); + public Hotkey ProductionTypeBuildingKey = new Hotkey(Keycode.E, Modifiers.None); + public Hotkey ProductionTypeDefenseKey = new Hotkey(Keycode.R, Modifiers.None); + public Hotkey ProductionTypeInfantryKey = new Hotkey(Keycode.T, Modifiers.None); + public Hotkey ProductionTypeVehicleKey = new Hotkey(Keycode.Y, Modifiers.None); + public Hotkey ProductionTypeAircraftKey = new Hotkey(Keycode.U, Modifiers.None); + public Hotkey ProductionTypeNavalKey = new Hotkey(Keycode.I, Modifiers.None); public Hotkey GetProductionHotkey(int index) { diff --git a/OpenRA.Mods.Cnc/Widgets/Logic/ProductionTabsLogic.cs b/OpenRA.Mods.Cnc/Widgets/Logic/ProductionTabsLogic.cs index a19f3a28c4..f442ab2e72 100644 --- a/OpenRA.Mods.Cnc/Widgets/Logic/ProductionTabsLogic.cs +++ b/OpenRA.Mods.Cnc/Widgets/Logic/ProductionTabsLogic.cs @@ -32,10 +32,20 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic tabs.QueueGroup = button.ProductionGroup; }; + Func getKey = _ => Hotkey.Invalid; + if (!string.IsNullOrEmpty(button.HotkeyName)) + { + var ks = Game.Settings.Keys; + var field = ks.GetType().GetField(button.HotkeyName); + if (field != null) + getKey = _ => (Hotkey)field.GetValue(ks); + } + button.IsDisabled = () => tabs.Groups[button.ProductionGroup].Tabs.Count == 0; button.OnMouseUp = mi => selectTab(mi.Modifiers.HasModifier(Modifiers.Shift)); button.OnKeyPress = e => selectTab(e.Modifiers.HasModifier(Modifiers.Shift)); button.IsHighlighted = () => tabs.QueueGroup == button.ProductionGroup; + button.GetKey = getKey; var chromeName = button.ProductionGroup.ToLowerInvariant(); var icon = button.Get("ICON"); diff --git a/OpenRA.Mods.Common/Widgets/Logic/SettingsLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/SettingsLogic.cs index 8aabc593b7..871861a760 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/SettingsLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/SettingsLogic.cs @@ -412,7 +412,16 @@ namespace OpenRA.Mods.Common.Widgets.Logic // Production { - var hotkeys = new Dictionary(); + var hotkeys = new Dictionary() + { + { "ProductionTypeBuildingKey", "Building Tab" }, + { "ProductionTypeDefenseKey", "Defense Tab" }, + { "ProductionTypeInfantryKey", "Infantry Tab" }, + { "ProductionTypeVehicleKey", "Vehicle Tab" }, + { "ProductionTypeAircraftKey", "Aircraft Tab" }, + { "ProductionTypeNavalKey", "Naval Tab" } + }; + for (var i = 1; i <= 24; i++) hotkeys.Add("Production{0:D2}Key".F(i), "Slot {0}".F(i)); diff --git a/OpenRA.Mods.RA/Widgets/Logic/ClassicProductionLogic.cs b/OpenRA.Mods.RA/Widgets/Logic/ClassicProductionLogic.cs index 37bad035f3..451f10537a 100644 --- a/OpenRA.Mods.RA/Widgets/Logic/ClassicProductionLogic.cs +++ b/OpenRA.Mods.RA/Widgets/Logic/ClassicProductionLogic.cs @@ -37,11 +37,21 @@ namespace OpenRA.Mods.RA.Widgets.Logic palette.CurrentQueue = queues.FirstOrDefault(q => q.Enabled); }; + Func getKey = _ => Hotkey.Invalid; + if (!string.IsNullOrEmpty(button.HotkeyName)) + { + var ks = Game.Settings.Keys; + var field = ks.GetType().GetField(button.HotkeyName); + if (field != null) + getKey = _ => (Hotkey)field.GetValue(ks); + } + button.IsDisabled = () => !queues.Any(q => q.BuildableItems().Any()); button.OnMouseUp = mi => selectTab(mi.Modifiers.HasModifier(Modifiers.Shift)); button.OnKeyPress = e => selectTab(e.Modifiers.HasModifier(Modifiers.Shift)); button.OnClick = () => selectTab(false); button.IsHighlighted = () => queues.Contains(palette.CurrentQueue); + button.GetKey = getKey; var chromeName = button.ProductionGroup.ToLowerInvariant(); var icon = button.Get("ICON"); diff --git a/OpenRA.Mods.RA/Widgets/ProductionTypeButtonWidget.cs b/OpenRA.Mods.RA/Widgets/ProductionTypeButtonWidget.cs index ef2de799bf..e51c7f5210 100644 --- a/OpenRA.Mods.RA/Widgets/ProductionTypeButtonWidget.cs +++ b/OpenRA.Mods.RA/Widgets/ProductionTypeButtonWidget.cs @@ -15,6 +15,7 @@ namespace OpenRA.Mods.RA.Widgets public class ProductionTypeButtonWidget : ButtonWidget { public readonly string ProductionGroup; + public readonly string HotkeyName; [ObjectCreator.UseCtor] public ProductionTypeButtonWidget(Ruleset modRules) diff --git a/mods/cnc/chrome/ingame.yaml b/mods/cnc/chrome/ingame.yaml index 055b3a4ab1..63da31364c 100644 --- a/mods/cnc/chrome/ingame.yaml +++ b/mods/cnc/chrome/ingame.yaml @@ -363,10 +363,10 @@ Container@PLAYER_WIDGETS: ProductionTypeButton@BUILDING: Width: 30 Height: 30 - Key: e TooltipText: Buildings TooltipContainer: TOOLTIP_CONTAINER ProductionGroup: Building + HotkeyName: ProductionTypeBuildingKey Children: Image@ICON: X: 7 @@ -376,10 +376,10 @@ Container@PLAYER_WIDGETS: X: 35 Width: 30 Height: 30 - Key: r TooltipText: Defence TooltipContainer: TOOLTIP_CONTAINER ProductionGroup: Defence + HotkeyName: ProductionTypeDefenseKey Children: Image@ICON: X: 7 @@ -389,10 +389,10 @@ Container@PLAYER_WIDGETS: X: 70 Width: 30 Height: 30 - Key: t TooltipText: Infantry TooltipContainer: TOOLTIP_CONTAINER ProductionGroup: Infantry + HotkeyName: ProductionTypeInfantryKey Children: Image@ICON: X: 7 @@ -402,10 +402,10 @@ Container@PLAYER_WIDGETS: X: 105 Width: 30 Height: 30 - Key: y TooltipText: Vehicles TooltipContainer: TOOLTIP_CONTAINER ProductionGroup: Vehicle + HotkeyName: ProductionTypeVehicleKey Children: Image@ICON: X: 7 @@ -415,10 +415,10 @@ Container@PLAYER_WIDGETS: X: 140 Width: 30 Height: 30 - Key: u TooltipText: Aircraft TooltipContainer: TOOLTIP_CONTAINER ProductionGroup: Aircraft + HotkeyName: ProductionTypeAircraftKey Children: Image@ICON: X: 7 diff --git a/mods/ra/chrome/ingame-player.yaml b/mods/ra/chrome/ingame-player.yaml index 240b960f7c..552f28c6eb 100644 --- a/mods/ra/chrome/ingame-player.yaml +++ b/mods/ra/chrome/ingame-player.yaml @@ -248,7 +248,6 @@ Container@PLAYER_WIDGETS: Children: ProductionTypeButton@BUILDING: Logic: AddRaceSuffixLogic - Key: e Width: 28 Height: 28 VisualHeight: 0 @@ -256,6 +255,7 @@ Container@PLAYER_WIDGETS: TooltipText: Buildings TooltipContainer: TOOLTIP_CONTAINER ProductionGroup: Building + HotkeyName: ProductionTypeBuildingKey Children: Image@ICON: X: 6 @@ -263,7 +263,6 @@ Container@PLAYER_WIDGETS: ImageCollection: production-icons ProductionTypeButton@DEFENSE: Logic: AddRaceSuffixLogic - Key: r Y: 31 Width: 28 Height: 28 @@ -272,6 +271,7 @@ Container@PLAYER_WIDGETS: TooltipText: Defense TooltipContainer: TOOLTIP_CONTAINER ProductionGroup: Defense + HotkeyName: ProductionTypeDefenseKey Children: Image@ICON: X: 6 @@ -279,7 +279,6 @@ Container@PLAYER_WIDGETS: ImageCollection: production-icons ProductionTypeButton@INFANTRY: Logic: AddRaceSuffixLogic - Key: t Y: 62 Width: 28 Height: 28 @@ -288,6 +287,7 @@ Container@PLAYER_WIDGETS: TooltipText: Infantry TooltipContainer: TOOLTIP_CONTAINER ProductionGroup: Infantry + HotkeyName: ProductionTypeInfantryKey Children: Image@ICON: X: 6 @@ -295,7 +295,6 @@ Container@PLAYER_WIDGETS: ImageCollection: production-icons ProductionTypeButton@VEHICLE: Logic: AddRaceSuffixLogic - Key: y Y: 93 Width: 28 Height: 28 @@ -304,6 +303,7 @@ Container@PLAYER_WIDGETS: TooltipText: Vehicles TooltipContainer: TOOLTIP_CONTAINER ProductionGroup: Vehicle + HotkeyName: ProductionTypeVehicleKey Children: Image@ICON: X: 6 @@ -311,7 +311,6 @@ Container@PLAYER_WIDGETS: ImageCollection: production-icons ProductionTypeButton@AIRCRAFT: Logic: AddRaceSuffixLogic - Key: u Y: 124 Width: 28 Height: 28 @@ -320,6 +319,7 @@ Container@PLAYER_WIDGETS: TooltipText: Aircraft TooltipContainer: TOOLTIP_CONTAINER ProductionGroup: Aircraft + HotkeyName: ProductionTypeAircraftKey Children: Image@ICON: X: 6 @@ -327,7 +327,6 @@ Container@PLAYER_WIDGETS: ImageCollection: production-icons ProductionTypeButton@NAVAL: Logic: AddRaceSuffixLogic - Key: i Y: 155 Width: 28 Height: 28 @@ -336,6 +335,7 @@ Container@PLAYER_WIDGETS: TooltipText: Naval TooltipContainer: TOOLTIP_CONTAINER ProductionGroup: Ship + HotkeyName: ProductionTypeNavalKey Children: Image@ICON: X: 6