Added Hotkeys for support powers

This commit is contained in:
sinf
2015-04-03 13:22:00 +03:00
parent f6051b1e2b
commit 9250c61473
7 changed files with 96 additions and 16 deletions

View File

@@ -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;