diff --git a/OpenRA.Mods.Cnc/Widgets/Logic/ButtonTooltipLogic.cs b/OpenRA.Mods.Cnc/Widgets/Logic/ButtonTooltipLogic.cs index 1cb0c7d5fa..9cb12c6d32 100644 --- a/OpenRA.Mods.Cnc/Widgets/Logic/ButtonTooltipLogic.cs +++ b/OpenRA.Mods.Cnc/Widgets/Logic/ButtonTooltipLogic.cs @@ -19,8 +19,20 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic public ButtonTooltipLogic([ObjectCreator.Param] Widget widget, [ObjectCreator.Param] TooltipButtonWidget button) { - widget.GetWidget("LABEL").GetText = () => button.TooltipText; - widget.GetWidget("HOTKEY").GetText = () => button.Key; + var label = widget.GetWidget("LABEL"); + var hotkey = widget.GetWidget("HOTKEY"); + + label.GetText = () => button.TooltipText; + var labelWidth = Game.Renderer.Fonts[label.Font].Measure(button.TooltipText).X; + label.Bounds.Width = labelWidth; + + var hotkeyLabel = "({0})".F(button.Key.ToUpperInvariant()); + 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; } } } diff --git a/OpenRA.Mods.Cnc/Widgets/ProductionPaletteWidget.cs b/OpenRA.Mods.Cnc/Widgets/ProductionPaletteWidget.cs index 6834b8cc7b..2a8bd485ab 100755 --- a/OpenRA.Mods.Cnc/Widgets/ProductionPaletteWidget.cs +++ b/OpenRA.Mods.Cnc/Widgets/ProductionPaletteWidget.cs @@ -34,7 +34,7 @@ namespace OpenRA.Mods.Cnc.Widgets public readonly int Columns = 3; public readonly string TabClick = "button.aud"; public readonly string TooltipContainer; - public readonly string TooltipTemplate; + public readonly string TooltipTemplate = "PRODUCTION_TOOLTIP"; public string TooltipActor { get; private set; } Lazy tooltipContainer; diff --git a/OpenRA.Mods.Cnc/Widgets/TooltipButtonWidget.cs b/OpenRA.Mods.Cnc/Widgets/TooltipButtonWidget.cs index b7abb2e111..ccb6654ace 100644 --- a/OpenRA.Mods.Cnc/Widgets/TooltipButtonWidget.cs +++ b/OpenRA.Mods.Cnc/Widgets/TooltipButtonWidget.cs @@ -15,7 +15,7 @@ namespace OpenRA.Mods.Cnc.Widgets { public class TooltipButtonWidget : ButtonWidget { - public readonly string TooltipTemplate; + public readonly string TooltipTemplate = "BUTTON_TOOLTIP"; public readonly string TooltipText; public readonly string TooltipContainer; Lazy tooltipContainer; @@ -42,8 +42,8 @@ namespace OpenRA.Mods.Cnc.Widgets if (TooltipContainer == null) return; - var panel = Widget.LoadWidget(TooltipTemplate, null, new WidgetArgs() {{ "button", this }}); - tooltipContainer.Value.SetTooltip(panel); + tooltipContainer.Value.SetTooltip( + Widget.LoadWidget(TooltipTemplate, null, new WidgetArgs() {{ "button", this }})); } public override void MouseExited() diff --git a/OpenRA.Mods.Cnc/Widgets/TooltipContainerWidget.cs b/OpenRA.Mods.Cnc/Widgets/TooltipContainerWidget.cs index b8b308e4a1..6201c4cd4c 100755 --- a/OpenRA.Mods.Cnc/Widgets/TooltipContainerWidget.cs +++ b/OpenRA.Mods.Cnc/Widgets/TooltipContainerWidget.cs @@ -21,7 +21,7 @@ namespace OpenRA.Mods.Cnc.Widgets { class TooltipContainerWidget : Widget { - public int2 CursorOffset = new int2(20, 0); + public int2 CursorOffset = new int2(0, 20); public int TooltipDelay = 10; Widget tooltip; @@ -51,7 +51,7 @@ namespace OpenRA.Mods.Cnc.Widgets if (tooltip != null) { if (pos.X + tooltip.Bounds.Right > Game.viewport.Width) - pos.X -= 2*CursorOffset.X + tooltip.Bounds.Right; + pos.X = Game.viewport.Width - tooltip.Bounds.Right; } return pos; diff --git a/mods/cnc/chrome/ingame.yaml b/mods/cnc/chrome/ingame.yaml index cf3152568b..2ccfa4d024 100644 --- a/mods/cnc/chrome/ingame.yaml +++ b/mods/cnc/chrome/ingame.yaml @@ -92,7 +92,7 @@ Container@INGAME_ROOT: Height:240 Background:panel-black Children: - Button@OPTIONS_BUTTON: + TooltipButton@OPTIONS_BUTTON: Id:OPTIONS_BUTTON Key:escape X:40 @@ -101,22 +101,30 @@ Container@INGAME_ROOT: Height:25 Text:Opt Font:Bold - Button@SELL_BUTTON: + TooltipText: Menu + TooltipContainer:TOOLTIP_CONTAINER + TooltipButton@SELL_BUTTON: Id:SELL_BUTTON + Key: [ X:80 Y:0-24 Width:35 Height:25 Text:$ Font:Bold - Button@REPAIR_BUTTON: + TooltipText: Sell + TooltipContainer:TOOLTIP_CONTAINER + TooltipButton@REPAIR_BUTTON: Id:REPAIR_BUTTON + Key: ] X:120 Y:0-24 Width:35 Height:25 Text:R Font:Bold + TooltipText: Repair + TooltipContainer:TOOLTIP_CONTAINER Background@RADAR: X:13 Y:5 @@ -186,8 +194,7 @@ Container@INGAME_ROOT: Text: B Key: y TooltipText: Buildings - TooltipContainer: TOOLTIP_CONTAINER - TooltipTemplate: BUTTON_TOOLTIP + TooltipContainer:TOOLTIP_CONTAINER TooltipButton@DEFENSE: Id:DEFENSE X:35 @@ -196,8 +203,7 @@ Container@INGAME_ROOT: Text: D Key: u TooltipText: Defense - TooltipContainer: TOOLTIP_CONTAINER - TooltipTemplate: BUTTON_TOOLTIP + TooltipContainer:TOOLTIP_CONTAINER TooltipButton@INFANTRY: Id:INFANTRY X:70 @@ -206,8 +212,7 @@ Container@INGAME_ROOT: Text: I Key: i TooltipText: Infantry - TooltipContainer: TOOLTIP_CONTAINER - TooltipTemplate: BUTTON_TOOLTIP + TooltipContainer:TOOLTIP_CONTAINER TooltipButton@VEHICLE: Id:VEHICLE X:105 @@ -216,8 +221,7 @@ Container@INGAME_ROOT: Text: V Key: o TooltipText: Vehicles - TooltipContainer: TOOLTIP_CONTAINER - TooltipTemplate: BUTTON_TOOLTIP + TooltipContainer:TOOLTIP_CONTAINER TooltipButton@AIRCRAFT: Id:AIRCRAFT X:140 @@ -226,8 +230,7 @@ Container@INGAME_ROOT: Text: H Key: p TooltipText: Aircraft - TooltipContainer: TOOLTIP_CONTAINER - TooltipTemplate: BUTTON_TOOLTIP + TooltipContainer:TOOLTIP_CONTAINER ProductionTabs: Id:PRODUCTION_TABS PaletteWidget:PRODUCTION_PALETTE @@ -240,8 +243,7 @@ Container@INGAME_ROOT: X:WINDOW_RIGHT - 204 Y:287 TabClick: button.aud - TooltipContainer: TOOLTIP_CONTAINER - TooltipTemplate: PRODUCTION_TOOLTIP + TooltipContainer:TOOLTIP_CONTAINER TooltipContainer: Id:TOOLTIP_CONTAINER diff --git a/mods/cnc/chrome/tooltips.yaml b/mods/cnc/chrome/tooltips.yaml index 0fde42d0de..555de23f6c 100644 --- a/mods/cnc/chrome/tooltips.yaml +++ b/mods/cnc/chrome/tooltips.yaml @@ -3,34 +3,28 @@ Background@PRODUCTION_TOOLTIP: Logic:ProductionTooltipLogic Background:panel-black Width:100 - Height:30 + Height:25 Children: Label@NAME: Id:NAME X:5 - Y:5 Width:PARENT_RIGHT-10 - Height:PARENT_BOTTOM-10 + Height:23 Font:Bold Background@BUTTON_TOOLTIP: Id:BUTTON_TOOLTIP Logic:ButtonTooltipLogic Background:panel-black Width:100 - Height:30 + Height:25 Children: Label@LABEL: Id:LABEL X:5 - Y:5 - Width:PARENT_RIGHT-10 - Height:PARENT_BOTTOM-10 + Height:23 Font:Bold Label@HOTKEY: Id:HOTKEY - X:PARENT_RIGHT-15 - Y:5 Color:255,255,0 - Width:PARENT_RIGHT-10 - Height:PARENT_BOTTOM-10 + Height:23 Font:Bold \ No newline at end of file