Hide invalid hotkey from button tooltips.

This commit is contained in:
Paul Chote
2014-07-15 15:45:17 +12:00
parent 90403ad40b
commit ba21428276
4 changed files with 16 additions and 8 deletions

View File

@@ -18,19 +18,24 @@ namespace OpenRA.Mods.RA.Widgets.Logic
public ButtonTooltipLogic(Widget widget, ButtonWidget button)
{
var label = widget.Get<LabelWidget>("LABEL");
var hotkey = widget.Get<LabelWidget>("HOTKEY");
var font = Game.Renderer.Fonts[label.Font];
var labelWidth = font.Measure(button.TooltipText).X;
label.GetText = () => button.TooltipText;
var labelWidth = Game.Renderer.Fonts[label.Font].Measure(button.TooltipText).X;
label.Bounds.Width = labelWidth;
widget.Bounds.Width = 2 * label.Bounds.X + labelWidth;
if (button.Key.IsValid())
{
var hotkey = widget.Get<LabelWidget>("HOTKEY");
hotkey.Visible = true;
var hotkeyLabel = "({0})".F(button.Key.DisplayString());
hotkey.GetText = () => hotkeyLabel;
hotkey.Bounds.X = labelWidth + 2 * label.Bounds.X;
var panelWidth = hotkey.Bounds.X + label.Bounds.X
+ Game.Renderer.Fonts[label.Font].Measure(hotkeyLabel).X;
widget.Bounds.Width = panelWidth;
widget.Bounds.Width = hotkey.Bounds.X + label.Bounds.X + font.Measure(hotkeyLabel).X;
}
}
}
}

View File

@@ -18,6 +18,7 @@ Background@BUTTON_TOOLTIP:
Height: 23
Font: Bold
Label@HOTKEY:
Visible: false
TextColor: 255,255,0
Height: 23
Font: Bold

View File

@@ -20,6 +20,7 @@ Background@BUTTON_TOOLTIP:
Height: 23
Font: Bold
Label@HOTKEY:
Visible: false
Y: 3
Height: 23
TextColor: 255,255,0

View File

@@ -20,6 +20,7 @@ Background@BUTTON_TOOLTIP:
Height: 23
Font: Bold
Label@HOTKEY:
Visible: false
Y: 2
Height: 23
TextColor: 255,255,0