Polish button tooltips. Add tooltips/hotkeys for menu/sell/repair
This commit is contained in:
@@ -19,8 +19,20 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
|
||||
public ButtonTooltipLogic([ObjectCreator.Param] Widget widget,
|
||||
[ObjectCreator.Param] TooltipButtonWidget button)
|
||||
{
|
||||
widget.GetWidget<LabelWidget>("LABEL").GetText = () => button.TooltipText;
|
||||
widget.GetWidget<LabelWidget>("HOTKEY").GetText = () => button.Key;
|
||||
var label = widget.GetWidget<LabelWidget>("LABEL");
|
||||
var hotkey = widget.GetWidget<LabelWidget>("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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<TooltipContainerWidget> tooltipContainer;
|
||||
|
||||
@@ -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<TooltipContainerWidget> 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()
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user