Added Hotkeys for support powers
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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<LabelWidget>("NAME");
|
||||
var hotkeyLabel = widget.Get<LabelWidget>("HOTKEY");
|
||||
var timeLabel = widget.Get<LabelWidget>("TIME");
|
||||
var descLabel = widget.Get<LabelWidget>("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;
|
||||
|
||||
@@ -439,6 +439,20 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
BindHotkeyPref(kv, ks, productionTemplate, hotkeyList);
|
||||
}
|
||||
|
||||
// Support powers
|
||||
{
|
||||
var hotkeys = new Dictionary<string, string>();
|
||||
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<LabelWidget>("LABEL").GetText = () => "Support Power Commands";
|
||||
hotkeyList.AddChild(header);
|
||||
|
||||
foreach (var kv in hotkeys)
|
||||
BindHotkeyPref(kv, ks, productionTemplate, hotkeyList);
|
||||
}
|
||||
|
||||
// Developer
|
||||
{
|
||||
var hotkeys = new Dictionary<string, string>()
|
||||
|
||||
@@ -40,7 +40,7 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
Animation clock;
|
||||
Dictionary<Rectangle, SupportPowerIcon> icons = new Dictionary<Rectangle, SupportPowerIcon>();
|
||||
|
||||
public SupportPowerInstance TooltipPower { get; private set; }
|
||||
public SupportPowerIcon TooltipIcon { get; private set; }
|
||||
Lazy<TooltipContainerWidget> 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;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user