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) public ButtonTooltipLogic(Widget widget, ButtonWidget button)
{ {
var label = widget.Get<LabelWidget>("LABEL"); 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; label.GetText = () => button.TooltipText;
var labelWidth = Game.Renderer.Fonts[label.Font].Measure(button.TooltipText).X;
label.Bounds.Width = labelWidth; label.Bounds.Width = labelWidth;
widget.Bounds.Width = 2 * label.Bounds.X + labelWidth;
var hotkeyLabel = "({0})".F(button.Key.DisplayString()); if (button.Key.IsValid())
hotkey.GetText = () => hotkeyLabel; {
hotkey.Bounds.X = labelWidth + 2 * label.Bounds.X; var hotkey = widget.Get<LabelWidget>("HOTKEY");
hotkey.Visible = true;
var panelWidth = hotkey.Bounds.X + label.Bounds.X var hotkeyLabel = "({0})".F(button.Key.DisplayString());
+ Game.Renderer.Fonts[label.Font].Measure(hotkeyLabel).X; hotkey.GetText = () => hotkeyLabel;
widget.Bounds.Width = panelWidth; hotkey.Bounds.X = labelWidth + 2 * label.Bounds.X;
widget.Bounds.Width = hotkey.Bounds.X + label.Bounds.X + font.Measure(hotkeyLabel).X;
}
} }
} }
} }

View File

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

View File

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

View File

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