Add hotkey support to ProductionPaletteWidget.
This commit is contained in:
@@ -29,6 +29,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
|||||||
|
|
||||||
widget.IsVisible = () => palette.TooltipActor != null;
|
widget.IsVisible = () => palette.TooltipActor != null;
|
||||||
var nameLabel = widget.Get<LabelWidget>("NAME");
|
var nameLabel = widget.Get<LabelWidget>("NAME");
|
||||||
|
var hotkeyLabel = widget.Get<LabelWidget>("HOTKEY");
|
||||||
var requiresLabel = widget.Get<LabelWidget>("REQUIRES");
|
var requiresLabel = widget.Get<LabelWidget>("REQUIRES");
|
||||||
var powerLabel = widget.Get<LabelWidget>("POWER");
|
var powerLabel = widget.Get<LabelWidget>("POWER");
|
||||||
var timeLabel = widget.Get<LabelWidget>("TIME");
|
var timeLabel = widget.Get<LabelWidget>("TIME");
|
||||||
@@ -54,6 +55,14 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
|||||||
|
|
||||||
nameLabel.GetText = () => tooltip.Name;
|
nameLabel.GetText = () => tooltip.Name;
|
||||||
|
|
||||||
|
var nameWidth = font.Measure(tooltip.Name).X;
|
||||||
|
var hotkeyText = "({0})".F(buildable.Hotkey.DisplayString());
|
||||||
|
var hotkeyWidth = buildable.Hotkey.IsValid() ? font.Measure(hotkeyText).X + 2 * nameLabel.Bounds.X : 0;
|
||||||
|
hotkeyLabel.GetText = () => hotkeyText;
|
||||||
|
hotkeyLabel.Bounds.X = nameWidth + 2 * nameLabel.Bounds.X;
|
||||||
|
hotkeyLabel.Visible = buildable.Hotkey.IsValid();
|
||||||
|
|
||||||
|
|
||||||
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;
|
||||||
@@ -80,7 +89,7 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
|||||||
var descString = tooltip.Description.Replace("\\n", "\n");
|
var descString = tooltip.Description.Replace("\\n", "\n");
|
||||||
descLabel.GetText = () => descString;
|
descLabel.GetText = () => descString;
|
||||||
|
|
||||||
var leftWidth = new[] { font.Measure(tooltip.Name).X, requiresFont.Measure(requiresString).X, descFont.Measure(descString).X }.Aggregate(Math.Max);
|
var leftWidth = new[] { nameWidth + hotkeyWidth, requiresFont.Measure(requiresString).X, descFont.Measure(descString).X }.Aggregate(Math.Max);
|
||||||
var rightWidth = new[] { font.Measure(powerString).X, font.Measure(timeString).X, font.Measure(costString).X }.Aggregate(Math.Max);
|
var rightWidth = new[] { font.Measure(powerString).X, font.Measure(timeString).X, font.Measure(costString).X }.Aggregate(Math.Max);
|
||||||
timeLabel.Bounds.X = powerLabel.Bounds.X = costLabel.Bounds.X = leftWidth + 2 * nameLabel.Bounds.X;
|
timeLabel.Bounds.X = powerLabel.Bounds.X = costLabel.Bounds.X = leftWidth + 2 * nameLabel.Bounds.X;
|
||||||
widget.Bounds.Width = leftWidth + rightWidth + 3 * nameLabel.Bounds.X;
|
widget.Bounds.Width = leftWidth + rightWidth + 3 * nameLabel.Bounds.X;
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ namespace OpenRA.Mods.RA.Widgets
|
|||||||
public class ProductionIcon
|
public class ProductionIcon
|
||||||
{
|
{
|
||||||
public string Name;
|
public string Name;
|
||||||
|
public Hotkey Hotkey;
|
||||||
public Sprite Sprite;
|
public Sprite Sprite;
|
||||||
public float2 Pos;
|
public float2 Pos;
|
||||||
public List<ProductionItem> Queued;
|
public List<ProductionItem> Queued;
|
||||||
@@ -120,14 +121,23 @@ namespace OpenRA.Mods.RA.Widgets
|
|||||||
if (icon == null)
|
if (icon == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
// Only support left and right clicks
|
||||||
|
if (mi.Button != MouseButton.Left && mi.Button != MouseButton.Right)
|
||||||
|
return false;
|
||||||
|
|
||||||
// Eat mouse-up events
|
// Eat mouse-up events
|
||||||
if (mi.Event != MouseInputEvent.Down)
|
if (mi.Event != MouseInputEvent.Down)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
return HandleEvent(icon, mi.Button == MouseButton.Left);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool HandleEvent(ProductionIcon icon, bool isLeftClick)
|
||||||
|
{
|
||||||
var actor = World.Map.Rules.Actors[icon.Name];
|
var actor = World.Map.Rules.Actors[icon.Name];
|
||||||
var first = icon.Queued.FirstOrDefault();
|
var first = icon.Queued.FirstOrDefault();
|
||||||
|
|
||||||
if (mi.Button == MouseButton.Left)
|
if (isLeftClick)
|
||||||
{
|
{
|
||||||
// Pick up a completed building
|
// Pick up a completed building
|
||||||
if (first != null && first.Done && actor.Traits.Contains<BuildingInfo>())
|
if (first != null && first.Done && actor.Traits.Contains<BuildingInfo>())
|
||||||
@@ -152,7 +162,7 @@ namespace OpenRA.Mods.RA.Widgets
|
|||||||
else
|
else
|
||||||
Sound.Play(DisabledTabClick);
|
Sound.Play(DisabledTabClick);
|
||||||
}
|
}
|
||||||
else if (mi.Button == MouseButton.Right)
|
else
|
||||||
{
|
{
|
||||||
// Hold/Cancel an existing item
|
// Hold/Cancel an existing item
|
||||||
if (first != null)
|
if (first != null)
|
||||||
@@ -179,6 +189,16 @@ namespace OpenRA.Mods.RA.Widgets
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override bool HandleKeyPress(KeyInput e)
|
||||||
|
{
|
||||||
|
if (e.Event == KeyInputEvent.Up || CurrentQueue == null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
var hotkey = Hotkey.FromKeyInput(e);
|
||||||
|
var toBuild = icons.Values.FirstOrDefault(i => i.Hotkey == hotkey);
|
||||||
|
return toBuild != null ? HandleEvent(toBuild, true) : false;
|
||||||
|
}
|
||||||
|
|
||||||
public void RefreshIcons()
|
public void RefreshIcons()
|
||||||
{
|
{
|
||||||
icons = new Dictionary<Rectangle, ProductionIcon>();
|
icons = new Dictionary<Rectangle, ProductionIcon>();
|
||||||
@@ -210,6 +230,7 @@ namespace OpenRA.Mods.RA.Widgets
|
|||||||
var pi = new ProductionIcon()
|
var pi = new ProductionIcon()
|
||||||
{
|
{
|
||||||
Name = item.Name,
|
Name = item.Name,
|
||||||
|
Hotkey = item.Traits.Get<BuildableInfo>().Hotkey,
|
||||||
Sprite = icon.Image,
|
Sprite = icon.Image,
|
||||||
Pos = new float2(rect.Location),
|
Pos = new float2(rect.Location),
|
||||||
Queued = CurrentQueue.AllQueued().Where(a => a.Item == item.Name).ToList(),
|
Queued = CurrentQueue.AllQueued().Where(a => a.Item == item.Name).ToList(),
|
||||||
|
|||||||
@@ -56,6 +56,11 @@ Background@PRODUCTION_TOOLTIP:
|
|||||||
X: 5
|
X: 5
|
||||||
Height: 23
|
Height: 23
|
||||||
Font: Bold
|
Font: Bold
|
||||||
|
Label@HOTKEY:
|
||||||
|
Visible: false
|
||||||
|
Height: 23
|
||||||
|
TextColor: 255,255,0
|
||||||
|
Font: Bold
|
||||||
Label@REQUIRES:
|
Label@REQUIRES:
|
||||||
X: 5
|
X: 5
|
||||||
Y: 19
|
Y: 19
|
||||||
|
|||||||
@@ -119,6 +119,12 @@ Background@PRODUCTION_TOOLTIP:
|
|||||||
Y: 2
|
Y: 2
|
||||||
Height: 23
|
Height: 23
|
||||||
Font: Bold
|
Font: Bold
|
||||||
|
Label@HOTKEY:
|
||||||
|
Visible: false
|
||||||
|
Y: 2
|
||||||
|
Height: 23
|
||||||
|
TextColor: 255,255,0
|
||||||
|
Font: Bold
|
||||||
Label@REQUIRES:
|
Label@REQUIRES:
|
||||||
X: 7
|
X: 7
|
||||||
Y: 21
|
Y: 21
|
||||||
|
|||||||
Reference in New Issue
Block a user