diff --git a/OpenRA.Game/Settings.cs b/OpenRA.Game/Settings.cs index ffb4fd6b3f..c8a5169011 100644 --- a/OpenRA.Game/Settings.cs +++ b/OpenRA.Game/Settings.cs @@ -212,6 +212,13 @@ namespace OpenRA public Hotkey ProductionTypeTankKey = new Hotkey(Keycode.I, Modifiers.None); public Hotkey ProductionTypeMerchantKey = new Hotkey(Keycode.O, Modifiers.None); + public Hotkey SupportPower01Key = new Hotkey(Keycode.UNKNOWN, Modifiers.None); + public Hotkey SupportPower02Key = new Hotkey(Keycode.UNKNOWN, Modifiers.None); + public Hotkey SupportPower03Key = new Hotkey(Keycode.UNKNOWN, Modifiers.None); + public Hotkey SupportPower04Key = new Hotkey(Keycode.UNKNOWN, Modifiers.None); + public Hotkey SupportPower05Key = new Hotkey(Keycode.UNKNOWN, Modifiers.None); + public Hotkey SupportPower06Key = new Hotkey(Keycode.UNKNOWN, Modifiers.None); + public Hotkey GetProductionHotkey(int index) { var field = GetType().GetField("Production{0:D2}Key".F(index + 1)); @@ -220,6 +227,15 @@ namespace OpenRA return (Hotkey)field.GetValue(this); } + + public Hotkey GetSupportPowerHotkey(int index) + { + var field = GetType().GetField("SupportPower{0:D2}Key".F(index + 1)); + if (field == null) + return Hotkey.Invalid; + + return (Hotkey)field.GetValue(this); + } } public class Settings diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/SupportPowerTooltipLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/SupportPowerTooltipLogic.cs index 129168ea64..f55aae2244 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/SupportPowerTooltipLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/SupportPowerTooltipLogic.cs @@ -19,8 +19,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic [ObjectCreator.UseCtor] public SupportPowerTooltipLogic(Widget widget, TooltipContainerWidget tooltipContainer, SupportPowersWidget palette) { - widget.IsVisible = () => palette.TooltipPower != null; + widget.IsVisible = () => palette.TooltipIcon != null; var nameLabel = widget.Get("NAME"); + var hotkeyLabel = widget.Get("HOTKEY"); var timeLabel = widget.Get("TIME"); var descLabel = widget.Get("DESC"); var nameFont = Game.Renderer.Fonts[nameLabel.Font]; @@ -35,10 +36,13 @@ namespace OpenRA.Mods.Common.Widgets.Logic SupportPowerInstance lastPower = null; tooltipContainer.BeforeRender = () => { - var sp = palette.TooltipPower; - if (sp == null) + var icon = palette.TooltipIcon; + + if (icon == null) return; + var sp = icon.Power; + if (sp.Info == null) return; // no instances actually exist (race with destroy) @@ -50,8 +54,16 @@ namespace OpenRA.Mods.Common.Widgets.Logic name = sp.Info.Description; desc = sp.Info.LongDesc.Replace("\\n", "\n"); + + var hotkey = icon.Hotkey; + var hotkeyText = "({0})".F(hotkey.DisplayString()); + var hotkeyWidth = hotkey.IsValid() ? nameFont.Measure(hotkeyText).X + 2 * nameLabel.Bounds.X : 0; + hotkeyLabel.GetText = () => hotkeyText; + hotkeyLabel.Bounds.X = nameFont.Measure(name).X + 2 * nameLabel.Bounds.X; + hotkeyLabel.Visible = hotkey.IsValid(); + var timeWidth = timeFont.Measure(time).X; - var topWidth = nameFont.Measure(name).X + timeWidth + timeOffset; + var topWidth = nameFont.Measure(name).X + hotkeyWidth + timeWidth + timeOffset; var descSize = descFont.Measure(desc); widget.Bounds.Width = 2 * nameLabel.Bounds.X + Math.Max(topWidth, descSize.X); widget.Bounds.Height = baseHeight + descSize.Y; diff --git a/OpenRA.Mods.Common/Widgets/Logic/SettingsLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/SettingsLogic.cs index a90eb6fa12..a5afc008da 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/SettingsLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/SettingsLogic.cs @@ -439,6 +439,20 @@ namespace OpenRA.Mods.Common.Widgets.Logic BindHotkeyPref(kv, ks, productionTemplate, hotkeyList); } + // Support powers + { + var hotkeys = new Dictionary(); + for (var i = 1; i <= 6; i++) + hotkeys.Add("SupportPower{0:D2}Key".F(i), "Slot {0}".F(i)); + + var header = ScrollItemWidget.Setup(hotkeyHeader, returnTrue, doNothing); + header.Get("LABEL").GetText = () => "Support Power Commands"; + hotkeyList.AddChild(header); + + foreach (var kv in hotkeys) + BindHotkeyPref(kv, ks, productionTemplate, hotkeyList); + } + // Developer { var hotkeys = new Dictionary() diff --git a/OpenRA.Mods.Common/Widgets/SupportPowersWidget.cs b/OpenRA.Mods.Common/Widgets/SupportPowersWidget.cs index bd174a98e9..9153ff7eee 100644 --- a/OpenRA.Mods.Common/Widgets/SupportPowersWidget.cs +++ b/OpenRA.Mods.Common/Widgets/SupportPowersWidget.cs @@ -40,7 +40,7 @@ namespace OpenRA.Mods.Common.Widgets Animation clock; Dictionary icons = new Dictionary(); - public SupportPowerInstance TooltipPower { get; private set; } + public SupportPowerIcon TooltipIcon { get; private set; } Lazy tooltipContainer; Rectangle eventBounds; @@ -65,6 +65,7 @@ namespace OpenRA.Mods.Common.Widgets public SupportPowerInstance Power; public float2 Pos; public Sprite Sprite; + public Hotkey Hotkey; } public void RefreshIcons() @@ -76,6 +77,8 @@ namespace OpenRA.Mods.Common.Widgets IconCount = 0; var rb = RenderBounds; + var ks = Game.Settings.Keys; + foreach (var p in powers) { var rect = new Rectangle(rb.X, rb.Y + IconCount * (IconSize.Y + IconMargin), IconSize.X, IconSize.Y); @@ -85,7 +88,8 @@ namespace OpenRA.Mods.Common.Widgets { Power = p, Pos = new float2(rect.Location), - Sprite = icon.Image + Sprite = icon.Image, + Hotkey = ks.GetSupportPowerHotkey(IconCount) }; icons.Add(rect, power); @@ -98,6 +102,31 @@ namespace OpenRA.Mods.Common.Widgets OnIconCountChanged(oldIconCount, IconCount); } + protected void ClickIcon(SupportPowerIcon clicked) + { + if (!clicked.Power.Active) + Sound.PlayToPlayer(spm.Self.Owner, clicked.Power.Info.InsufficientPowerSound); + else + clicked.Power.Target(); + } + + public override bool HandleKeyPress(KeyInput e) + { + if (e.Event == KeyInputEvent.Down) + { + var hotkey = Hotkey.FromKeyInput(e); + var a = icons.Values.FirstOrDefault(i => i.Hotkey == hotkey); + + if (a != null) + { + ClickIcon(a); + return true; + } + } + + return false; + } + public override void Draw() { var iconOffset = 0.5f * IconSize.ToFloat2() + IconSpriteOffset; @@ -170,7 +199,7 @@ namespace OpenRA.Mods.Common.Widgets var icon = icons.Where(i => i.Key.Contains(mi.Location)) .Select(i => i.Value).FirstOrDefault(); - TooltipPower = icon != null ? icon.Power : null; + TooltipIcon = icon; return false; } @@ -181,12 +210,7 @@ namespace OpenRA.Mods.Common.Widgets .Select(i => i.Value).FirstOrDefault(); if (clicked != null) - { - if (!clicked.Power.Active) - Sound.PlayToPlayer(spm.Self.Owner, clicked.Power.Info.InsufficientPowerSound); - - clicked.Power.Target(); - } + ClickIcon(clicked); return true; } diff --git a/mods/cnc/chrome/tooltips.yaml b/mods/cnc/chrome/tooltips.yaml index f62af8ee09..402d6592c8 100644 --- a/mods/cnc/chrome/tooltips.yaml +++ b/mods/cnc/chrome/tooltips.yaml @@ -116,8 +116,12 @@ Background@SUPPORT_POWER_TOOLTIP: X: 5 Height: 20 Font: Bold + Label@HOTKEY: + Visible: false + Height: 20 + TextColor: 255,255,0 + Font: Bold Label@TIME: - X: 20 Y: 6 Font: TinyBold VAlign: Top diff --git a/mods/d2k/chrome/tooltips.yaml b/mods/d2k/chrome/tooltips.yaml index bfb8fecab2..c47e2e50cf 100644 --- a/mods/d2k/chrome/tooltips.yaml +++ b/mods/d2k/chrome/tooltips.yaml @@ -181,8 +181,13 @@ Background@SUPPORT_POWER_TOOLTIP: Y: 2 Height: 20 Font: Bold + Label@HOTKEY: + Visible: false + Y: 2 + Height: 20 + TextColor: 255,255,0 + Font: Bold Label@TIME: - X: 20 Y: 8 Font: TinyBold VAlign: Top diff --git a/mods/ra/chrome/tooltips.yaml b/mods/ra/chrome/tooltips.yaml index 2c3656fcbe..89705556fd 100644 --- a/mods/ra/chrome/tooltips.yaml +++ b/mods/ra/chrome/tooltips.yaml @@ -181,8 +181,13 @@ Background@SUPPORT_POWER_TOOLTIP: Y: 2 Height: 20 Font: Bold + Label@HOTKEY: + Visible: false + Y: 2 + Height: 20 + TextColor: 255,255,0 + Font: Bold Label@TIME: - X: 20 Y: 8 Font: TinyBold VAlign: Top