Polish button tooltips. Add tooltips/hotkeys for menu/sell/repair

This commit is contained in:
Paul Chote
2011-07-05 17:43:19 +12:00
parent 460451c402
commit b4489028de
6 changed files with 42 additions and 34 deletions

View File

@@ -19,8 +19,20 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
public ButtonTooltipLogic([ObjectCreator.Param] Widget widget, public ButtonTooltipLogic([ObjectCreator.Param] Widget widget,
[ObjectCreator.Param] TooltipButtonWidget button) [ObjectCreator.Param] TooltipButtonWidget button)
{ {
widget.GetWidget<LabelWidget>("LABEL").GetText = () => button.TooltipText; var label = widget.GetWidget<LabelWidget>("LABEL");
widget.GetWidget<LabelWidget>("HOTKEY").GetText = () => button.Key; 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;
} }
} }
} }

View File

@@ -34,7 +34,7 @@ namespace OpenRA.Mods.Cnc.Widgets
public readonly int Columns = 3; public readonly int Columns = 3;
public readonly string TabClick = "button.aud"; public readonly string TabClick = "button.aud";
public readonly string TooltipContainer; public readonly string TooltipContainer;
public readonly string TooltipTemplate; public readonly string TooltipTemplate = "PRODUCTION_TOOLTIP";
public string TooltipActor { get; private set; } public string TooltipActor { get; private set; }
Lazy<TooltipContainerWidget> tooltipContainer; Lazy<TooltipContainerWidget> tooltipContainer;

View File

@@ -15,7 +15,7 @@ namespace OpenRA.Mods.Cnc.Widgets
{ {
public class TooltipButtonWidget : ButtonWidget public class TooltipButtonWidget : ButtonWidget
{ {
public readonly string TooltipTemplate; public readonly string TooltipTemplate = "BUTTON_TOOLTIP";
public readonly string TooltipText; public readonly string TooltipText;
public readonly string TooltipContainer; public readonly string TooltipContainer;
Lazy<TooltipContainerWidget> tooltipContainer; Lazy<TooltipContainerWidget> tooltipContainer;
@@ -42,8 +42,8 @@ namespace OpenRA.Mods.Cnc.Widgets
if (TooltipContainer == null) if (TooltipContainer == null)
return; return;
var panel = Widget.LoadWidget(TooltipTemplate, null, new WidgetArgs() {{ "button", this }}); tooltipContainer.Value.SetTooltip(
tooltipContainer.Value.SetTooltip(panel); Widget.LoadWidget(TooltipTemplate, null, new WidgetArgs() {{ "button", this }}));
} }
public override void MouseExited() public override void MouseExited()

View File

@@ -21,7 +21,7 @@ namespace OpenRA.Mods.Cnc.Widgets
{ {
class TooltipContainerWidget : Widget class TooltipContainerWidget : Widget
{ {
public int2 CursorOffset = new int2(20, 0); public int2 CursorOffset = new int2(0, 20);
public int TooltipDelay = 10; public int TooltipDelay = 10;
Widget tooltip; Widget tooltip;
@@ -51,7 +51,7 @@ namespace OpenRA.Mods.Cnc.Widgets
if (tooltip != null) if (tooltip != null)
{ {
if (pos.X + tooltip.Bounds.Right > Game.viewport.Width) 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; return pos;

View File

@@ -92,7 +92,7 @@ Container@INGAME_ROOT:
Height:240 Height:240
Background:panel-black Background:panel-black
Children: Children:
Button@OPTIONS_BUTTON: TooltipButton@OPTIONS_BUTTON:
Id:OPTIONS_BUTTON Id:OPTIONS_BUTTON
Key:escape Key:escape
X:40 X:40
@@ -101,22 +101,30 @@ Container@INGAME_ROOT:
Height:25 Height:25
Text:Opt Text:Opt
Font:Bold Font:Bold
Button@SELL_BUTTON: TooltipText: Menu
TooltipContainer:TOOLTIP_CONTAINER
TooltipButton@SELL_BUTTON:
Id:SELL_BUTTON Id:SELL_BUTTON
Key: [
X:80 X:80
Y:0-24 Y:0-24
Width:35 Width:35
Height:25 Height:25
Text:$ Text:$
Font:Bold Font:Bold
Button@REPAIR_BUTTON: TooltipText: Sell
TooltipContainer:TOOLTIP_CONTAINER
TooltipButton@REPAIR_BUTTON:
Id:REPAIR_BUTTON Id:REPAIR_BUTTON
Key: ]
X:120 X:120
Y:0-24 Y:0-24
Width:35 Width:35
Height:25 Height:25
Text:R Text:R
Font:Bold Font:Bold
TooltipText: Repair
TooltipContainer:TOOLTIP_CONTAINER
Background@RADAR: Background@RADAR:
X:13 X:13
Y:5 Y:5
@@ -186,8 +194,7 @@ Container@INGAME_ROOT:
Text: B Text: B
Key: y Key: y
TooltipText: Buildings TooltipText: Buildings
TooltipContainer: TOOLTIP_CONTAINER TooltipContainer:TOOLTIP_CONTAINER
TooltipTemplate: BUTTON_TOOLTIP
TooltipButton@DEFENSE: TooltipButton@DEFENSE:
Id:DEFENSE Id:DEFENSE
X:35 X:35
@@ -196,8 +203,7 @@ Container@INGAME_ROOT:
Text: D Text: D
Key: u Key: u
TooltipText: Defense TooltipText: Defense
TooltipContainer: TOOLTIP_CONTAINER TooltipContainer:TOOLTIP_CONTAINER
TooltipTemplate: BUTTON_TOOLTIP
TooltipButton@INFANTRY: TooltipButton@INFANTRY:
Id:INFANTRY Id:INFANTRY
X:70 X:70
@@ -206,8 +212,7 @@ Container@INGAME_ROOT:
Text: I Text: I
Key: i Key: i
TooltipText: Infantry TooltipText: Infantry
TooltipContainer: TOOLTIP_CONTAINER TooltipContainer:TOOLTIP_CONTAINER
TooltipTemplate: BUTTON_TOOLTIP
TooltipButton@VEHICLE: TooltipButton@VEHICLE:
Id:VEHICLE Id:VEHICLE
X:105 X:105
@@ -216,8 +221,7 @@ Container@INGAME_ROOT:
Text: V Text: V
Key: o Key: o
TooltipText: Vehicles TooltipText: Vehicles
TooltipContainer: TOOLTIP_CONTAINER TooltipContainer:TOOLTIP_CONTAINER
TooltipTemplate: BUTTON_TOOLTIP
TooltipButton@AIRCRAFT: TooltipButton@AIRCRAFT:
Id:AIRCRAFT Id:AIRCRAFT
X:140 X:140
@@ -226,8 +230,7 @@ Container@INGAME_ROOT:
Text: H Text: H
Key: p Key: p
TooltipText: Aircraft TooltipText: Aircraft
TooltipContainer: TOOLTIP_CONTAINER TooltipContainer:TOOLTIP_CONTAINER
TooltipTemplate: BUTTON_TOOLTIP
ProductionTabs: ProductionTabs:
Id:PRODUCTION_TABS Id:PRODUCTION_TABS
PaletteWidget:PRODUCTION_PALETTE PaletteWidget:PRODUCTION_PALETTE
@@ -240,8 +243,7 @@ Container@INGAME_ROOT:
X:WINDOW_RIGHT - 204 X:WINDOW_RIGHT - 204
Y:287 Y:287
TabClick: button.aud TabClick: button.aud
TooltipContainer: TOOLTIP_CONTAINER TooltipContainer:TOOLTIP_CONTAINER
TooltipTemplate: PRODUCTION_TOOLTIP
TooltipContainer: TooltipContainer:
Id:TOOLTIP_CONTAINER Id:TOOLTIP_CONTAINER

View File

@@ -3,34 +3,28 @@ Background@PRODUCTION_TOOLTIP:
Logic:ProductionTooltipLogic Logic:ProductionTooltipLogic
Background:panel-black Background:panel-black
Width:100 Width:100
Height:30 Height:25
Children: Children:
Label@NAME: Label@NAME:
Id:NAME Id:NAME
X:5 X:5
Y:5
Width:PARENT_RIGHT-10 Width:PARENT_RIGHT-10
Height:PARENT_BOTTOM-10 Height:23
Font:Bold Font:Bold
Background@BUTTON_TOOLTIP: Background@BUTTON_TOOLTIP:
Id:BUTTON_TOOLTIP Id:BUTTON_TOOLTIP
Logic:ButtonTooltipLogic Logic:ButtonTooltipLogic
Background:panel-black Background:panel-black
Width:100 Width:100
Height:30 Height:25
Children: Children:
Label@LABEL: Label@LABEL:
Id:LABEL Id:LABEL
X:5 X:5
Y:5 Height:23
Width:PARENT_RIGHT-10
Height:PARENT_BOTTOM-10
Font:Bold Font:Bold
Label@HOTKEY: Label@HOTKEY:
Id:HOTKEY Id:HOTKEY
X:PARENT_RIGHT-15
Y:5
Color:255,255,0 Color:255,255,0
Width:PARENT_RIGHT-10 Height:23
Height:PARENT_BOTTOM-10
Font:Bold Font:Bold