Move hardcoded production keys into yaml.
This commit is contained in:
@@ -297,7 +297,6 @@ namespace OpenRA
|
|||||||
public Hotkey PrevMusicKey = new Hotkey(Keycode.AUDIOPREV, Modifiers.None);
|
public Hotkey PrevMusicKey = new Hotkey(Keycode.AUDIOPREV, Modifiers.None);
|
||||||
public Hotkey NextMusicKey = new Hotkey(Keycode.AUDIONEXT, Modifiers.None);
|
public Hotkey NextMusicKey = new Hotkey(Keycode.AUDIONEXT, Modifiers.None);
|
||||||
|
|
||||||
static readonly Func<KeySettings, Hotkey>[] ProductionKeys = GetKeys(24, "Production");
|
|
||||||
static readonly Func<KeySettings, Hotkey>[] SupportPowerKeys = GetKeys(6, "SupportPower");
|
static readonly Func<KeySettings, Hotkey>[] SupportPowerKeys = GetKeys(6, "SupportPower");
|
||||||
|
|
||||||
static Func<KeySettings, Hotkey>[] GetKeys(int count, string prefix)
|
static Func<KeySettings, Hotkey>[] GetKeys(int count, string prefix)
|
||||||
@@ -316,11 +315,6 @@ namespace OpenRA
|
|||||||
return () => (Hotkey)field.GetValue(this);
|
return () => (Hotkey)field.GetValue(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Hotkey GetProductionHotkey(int index)
|
|
||||||
{
|
|
||||||
return GetKey(ProductionKeys, index);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Hotkey GetSupportPowerHotkey(int index)
|
public Hotkey GetSupportPowerHotkey(int index)
|
||||||
{
|
{
|
||||||
return GetKey(SupportPowerKeys, index);
|
return GetKey(SupportPowerKeys, index);
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
var descFont = Game.Renderer.Fonts[descLabel.Font];
|
var descFont = Game.Renderer.Fonts[descLabel.Font];
|
||||||
var requiresFont = Game.Renderer.Fonts[requiresLabel.Font];
|
var requiresFont = Game.Renderer.Fonts[requiresLabel.Font];
|
||||||
ActorInfo lastActor = null;
|
ActorInfo lastActor = null;
|
||||||
|
Hotkey lastHotkey = Hotkey.Invalid;
|
||||||
|
|
||||||
tooltipContainer.BeforeRender = () =>
|
tooltipContainer.BeforeRender = () =>
|
||||||
{
|
{
|
||||||
@@ -55,7 +56,11 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
var actor = tooltipIcon.Actor;
|
var actor = tooltipIcon.Actor;
|
||||||
if (actor == null || actor == lastActor)
|
if (actor == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var hotkey = tooltipIcon.Hotkey != null ? tooltipIcon.Hotkey.GetValue() : Hotkey.Invalid;
|
||||||
|
if (actor == lastActor && hotkey == lastHotkey)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var tooltip = actor.TraitInfos<TooltipInfo>().FirstOrDefault(Exts.IsTraitEnabled);
|
var tooltip = actor.TraitInfos<TooltipInfo>().FirstOrDefault(Exts.IsTraitEnabled);
|
||||||
@@ -65,14 +70,19 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
|
|
||||||
nameLabel.GetText = () => name;
|
nameLabel.GetText = () => name;
|
||||||
|
|
||||||
var hotkey = tooltipIcon.Hotkey;
|
|
||||||
var nameWidth = font.Measure(name).X;
|
var nameWidth = font.Measure(name).X;
|
||||||
var hotkeyText = "({0})".F(hotkey.DisplayString());
|
var hotkeyWidth = 0;
|
||||||
var hotkeyWidth = hotkey.IsValid() ? font.Measure(hotkeyText).X + 2 * nameLabel.Bounds.X : 0;
|
|
||||||
hotkeyLabel.GetText = () => hotkeyText;
|
|
||||||
hotkeyLabel.Bounds.X = nameWidth + 2 * nameLabel.Bounds.X;
|
|
||||||
hotkeyLabel.Visible = hotkey.IsValid();
|
hotkeyLabel.Visible = hotkey.IsValid();
|
||||||
|
|
||||||
|
if (hotkeyLabel.Visible)
|
||||||
|
{
|
||||||
|
var hotkeyText = "({0})".F(hotkey.DisplayString());
|
||||||
|
|
||||||
|
hotkeyWidth = font.Measure(hotkeyText).X + 2 * nameLabel.Bounds.X;
|
||||||
|
hotkeyLabel.Text = hotkeyText;
|
||||||
|
hotkeyLabel.Bounds.X = nameWidth + 2 * nameLabel.Bounds.X;
|
||||||
|
}
|
||||||
|
|
||||||
var prereqs = buildable.Prerequisites.Select(a => ActorName(mapRules, a)).Where(s => !s.StartsWith("~"));
|
var prereqs = buildable.Prerequisites.Select(a => ActorName(mapRules, a)).Where(s => !s.StartsWith("~"));
|
||||||
var requiresString = prereqs.Any() ? requiresLabel.Text.F(prereqs.JoinWith(", ")) : "";
|
var requiresString = prereqs.Any() ? requiresLabel.Text.F(prereqs.JoinWith(", ")) : "";
|
||||||
requiresLabel.GetText = () => requiresString;
|
requiresLabel.GetText = () => requiresString;
|
||||||
@@ -112,6 +122,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
widget.Bounds.Height = Math.Max(leftHeight, rightHeight) * 3 / 2 + 3 * nameLabel.Bounds.Y;
|
widget.Bounds.Height = Math.Max(leftHeight, rightHeight) * 3 / 2 + 3 * nameLabel.Bounds.Y;
|
||||||
|
|
||||||
lastActor = actor;
|
lastActor = actor;
|
||||||
|
lastHotkey = hotkey;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ using System.Collections.Generic;
|
|||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using OpenRA.Graphics;
|
using OpenRA.Graphics;
|
||||||
|
using OpenRA.Mods.Common.Lint;
|
||||||
using OpenRA.Mods.Common.Orders;
|
using OpenRA.Mods.Common.Orders;
|
||||||
using OpenRA.Mods.Common.Traits;
|
using OpenRA.Mods.Common.Traits;
|
||||||
using OpenRA.Mods.Common.Traits.Render;
|
using OpenRA.Mods.Common.Traits.Render;
|
||||||
@@ -26,7 +27,7 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
{
|
{
|
||||||
public ActorInfo Actor;
|
public ActorInfo Actor;
|
||||||
public string Name;
|
public string Name;
|
||||||
public Hotkey Hotkey;
|
public NamedHotkey Hotkey;
|
||||||
public Sprite Sprite;
|
public Sprite Sprite;
|
||||||
public PaletteReference Palette;
|
public PaletteReference Palette;
|
||||||
public PaletteReference IconClockPalette;
|
public PaletteReference IconClockPalette;
|
||||||
@@ -51,6 +52,10 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
public readonly string TooltipContainer;
|
public readonly string TooltipContainer;
|
||||||
public readonly string TooltipTemplate = "PRODUCTION_TOOLTIP";
|
public readonly string TooltipTemplate = "PRODUCTION_TOOLTIP";
|
||||||
|
|
||||||
|
// Note: LinterHotkeyNames assumes that these are disabled by default
|
||||||
|
public readonly string HotkeyPrefix = null;
|
||||||
|
public readonly int HotkeyCount = 0;
|
||||||
|
|
||||||
public readonly string ClockAnimation = "clock";
|
public readonly string ClockAnimation = "clock";
|
||||||
public readonly string ClockSequence = "idle";
|
public readonly string ClockSequence = "idle";
|
||||||
public readonly string ClockPalette = "chrome";
|
public readonly string ClockPalette = "chrome";
|
||||||
@@ -79,6 +84,7 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
|
|
||||||
Lazy<TooltipContainerWidget> tooltipContainer;
|
Lazy<TooltipContainerWidget> tooltipContainer;
|
||||||
ProductionQueue currentQueue;
|
ProductionQueue currentQueue;
|
||||||
|
NamedHotkey[] hotkeys;
|
||||||
|
|
||||||
public ProductionQueue CurrentQueue
|
public ProductionQueue CurrentQueue
|
||||||
{
|
{
|
||||||
@@ -90,10 +96,34 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
Dictionary<Rectangle, ProductionIcon> icons = new Dictionary<Rectangle, ProductionIcon>();
|
Dictionary<Rectangle, ProductionIcon> icons = new Dictionary<Rectangle, ProductionIcon>();
|
||||||
Animation cantBuild, clock;
|
Animation cantBuild, clock;
|
||||||
Rectangle eventBounds = Rectangle.Empty;
|
Rectangle eventBounds = Rectangle.Empty;
|
||||||
|
|
||||||
readonly WorldRenderer worldRenderer;
|
readonly WorldRenderer worldRenderer;
|
||||||
|
|
||||||
SpriteFont overlayFont;
|
SpriteFont overlayFont;
|
||||||
float2 holdOffset, readyOffset, timeOffset, queuedOffset;
|
float2 holdOffset, readyOffset, timeOffset, queuedOffset;
|
||||||
|
|
||||||
|
[CustomLintableHotkeyNames]
|
||||||
|
public static IEnumerable<string> LinterHotkeyNames(MiniYamlNode widgetNode, Action<string> emitError, Action<string> emitWarning)
|
||||||
|
{
|
||||||
|
var prefix = "";
|
||||||
|
var prefixNode = widgetNode.Value.Nodes.FirstOrDefault(n => n.Key == "HotkeyPrefix");
|
||||||
|
if (prefixNode != null)
|
||||||
|
prefix = prefixNode.Value.Value;
|
||||||
|
|
||||||
|
var count = 0;
|
||||||
|
var countNode = widgetNode.Value.Nodes.FirstOrDefault(n => n.Key == "HotkeyCount");
|
||||||
|
if (countNode != null)
|
||||||
|
count = FieldLoader.GetValue<int>("HotkeyCount", countNode.Value.Value);
|
||||||
|
|
||||||
|
if (count == 0)
|
||||||
|
return new string[0];
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(prefix))
|
||||||
|
emitError("{0} must define HotkeyPrefix if HotkeyCount > 0.".F(widgetNode.Location));
|
||||||
|
|
||||||
|
return Exts.MakeArray(count, i => prefix + (i + 1).ToString("D2"));
|
||||||
|
}
|
||||||
|
|
||||||
[ObjectCreator.UseCtor]
|
[ObjectCreator.UseCtor]
|
||||||
public ProductionPaletteWidget(OrderManager orderManager, World world, WorldRenderer worldRenderer)
|
public ProductionPaletteWidget(OrderManager orderManager, World world, WorldRenderer worldRenderer)
|
||||||
{
|
{
|
||||||
@@ -109,6 +139,14 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
clock = new Animation(world, ClockAnimation);
|
clock = new Animation(world, ClockAnimation);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override void Initialize(WidgetArgs args)
|
||||||
|
{
|
||||||
|
base.Initialize(args);
|
||||||
|
|
||||||
|
hotkeys = Exts.MakeArray(HotkeyCount,
|
||||||
|
i => new NamedHotkey(HotkeyPrefix + (i + 1).ToString("D2"), Game.Settings.Keys));
|
||||||
|
}
|
||||||
|
|
||||||
public void ScrollDown()
|
public void ScrollDown()
|
||||||
{
|
{
|
||||||
if (CanScrollDown)
|
if (CanScrollDown)
|
||||||
@@ -307,7 +345,7 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
if (batchModifiers != Modifiers.None)
|
if (batchModifiers != Modifiers.None)
|
||||||
hotkey = new Hotkey(hotkey.Key, hotkey.Modifiers ^ Modifiers.Shift);
|
hotkey = new Hotkey(hotkey.Key, hotkey.Modifiers ^ Modifiers.Shift);
|
||||||
|
|
||||||
var toBuild = icons.Values.FirstOrDefault(i => i.Hotkey == hotkey);
|
var toBuild = icons.Values.FirstOrDefault(i => i.Hotkey != null && i.Hotkey.GetValue() == hotkey);
|
||||||
return toBuild != null ? HandleEvent(toBuild, MouseButton.Left, batchModifiers) : false;
|
return toBuild != null ? HandleEvent(toBuild, MouseButton.Left, batchModifiers) : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -329,7 +367,6 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
var oldIconCount = DisplayedIconCount;
|
var oldIconCount = DisplayedIconCount;
|
||||||
DisplayedIconCount = 0;
|
DisplayedIconCount = 0;
|
||||||
|
|
||||||
var ks = Game.Settings.Keys;
|
|
||||||
var rb = RenderBounds;
|
var rb = RenderBounds;
|
||||||
var faction = producer.Trait.Faction;
|
var faction = producer.Trait.Faction;
|
||||||
|
|
||||||
@@ -348,7 +385,7 @@ namespace OpenRA.Mods.Common.Widgets
|
|||||||
{
|
{
|
||||||
Actor = item,
|
Actor = item,
|
||||||
Name = item.Name,
|
Name = item.Name,
|
||||||
Hotkey = ks.GetProductionHotkey(DisplayedIconCount),
|
Hotkey = DisplayedIconCount < HotkeyCount ? hotkeys[DisplayedIconCount] : null,
|
||||||
Sprite = icon.Image,
|
Sprite = icon.Image,
|
||||||
Palette = worldRenderer.Palette(bi.IconPalette),
|
Palette = worldRenderer.Palette(bi.IconPalette),
|
||||||
IconClockPalette = worldRenderer.Palette(ClockPalette),
|
IconClockPalette = worldRenderer.Palette(ClockPalette),
|
||||||
|
|||||||
@@ -714,6 +714,8 @@ Container@PLAYER_WIDGETS:
|
|||||||
TooltipContainer: TOOLTIP_CONTAINER
|
TooltipContainer: TOOLTIP_CONTAINER
|
||||||
ReadyText: Ready
|
ReadyText: Ready
|
||||||
HoldText: On Hold
|
HoldText: On Hold
|
||||||
|
HotkeyPrefix: Production
|
||||||
|
HotkeyCount: 24
|
||||||
ProductionTabs@PRODUCTION_TABS:
|
ProductionTabs@PRODUCTION_TABS:
|
||||||
Logic: ProductionTabsLogic
|
Logic: ProductionTabsLogic
|
||||||
PaletteWidget: PRODUCTION_PALETTE
|
PaletteWidget: PRODUCTION_PALETTE
|
||||||
|
|||||||
@@ -480,6 +480,8 @@ Container@PLAYER_WIDGETS:
|
|||||||
IconSpriteOffset: 0, 0
|
IconSpriteOffset: 0, 0
|
||||||
MinimumRows: 5
|
MinimumRows: 5
|
||||||
MaximumRows: 6
|
MaximumRows: 6
|
||||||
|
HotkeyPrefix: Production
|
||||||
|
HotkeyCount: 24
|
||||||
Container@PRODUCTION_TYPES:
|
Container@PRODUCTION_TYPES:
|
||||||
X: 6
|
X: 6
|
||||||
Y: 2
|
Y: 2
|
||||||
|
|||||||
@@ -469,6 +469,8 @@ Container@PLAYER_WIDGETS:
|
|||||||
IconSize: 62, 46
|
IconSize: 62, 46
|
||||||
IconMargin: 1, 1
|
IconMargin: 1, 1
|
||||||
IconSpriteOffset: -1, -1
|
IconSpriteOffset: -1, -1
|
||||||
|
HotkeyPrefix: Production
|
||||||
|
HotkeyCount: 24
|
||||||
Container@PALETTE_FOREGROUND:
|
Container@PALETTE_FOREGROUND:
|
||||||
X: 40
|
X: 40
|
||||||
Y: 0 - 1
|
Y: 0 - 1
|
||||||
|
|||||||
@@ -483,6 +483,8 @@ Container@PLAYER_WIDGETS:
|
|||||||
IconSpriteOffset: 0, 0
|
IconSpriteOffset: 0, 0
|
||||||
MinimumRows: 4
|
MinimumRows: 4
|
||||||
MaximumRows: 6
|
MaximumRows: 6
|
||||||
|
HotkeyPrefix: Production
|
||||||
|
HotkeyCount: 24
|
||||||
Container@PRODUCTION_TYPES:
|
Container@PRODUCTION_TYPES:
|
||||||
X: 0
|
X: 0
|
||||||
Y: 0 - 32
|
Y: 0 - 32
|
||||||
|
|||||||
Reference in New Issue
Block a user