diff --git a/OpenRA.Game/Widgets/Widget.cs b/OpenRA.Game/Widgets/Widget.cs
index 3b89078d55..44cb792924 100644
--- a/OpenRA.Game/Widgets/Widget.cs
+++ b/OpenRA.Game/Widgets/Widget.cs
@@ -69,7 +69,9 @@ namespace OpenRA.Widgets
public static bool DoHandleInput(MouseInput mi)
{
- if (mi.Event == MouseInputEvent.Move)
+ var wasMouseOver = MouseOverWidget;
+
+ if (mi.Event == MouseInputEvent.Move)
MouseOverWidget = null;
bool handled = false;
@@ -85,6 +87,15 @@ namespace OpenRA.Widgets
Viewport.TicksSinceLastMove = 0;
}
+ if (wasMouseOver != MouseOverWidget)
+ {
+ if (wasMouseOver != null)
+ wasMouseOver.MouseExited();
+
+ if (MouseOverWidget != null)
+ MouseOverWidget.MouseEntered();
+ }
+
return handled;
}
@@ -268,6 +279,8 @@ namespace OpenRA.Widgets
return EventBounds.Contains(pos) ? GetCursor(pos) : null;
}
+ public virtual void MouseEntered() {}
+ public virtual void MouseExited() {}
public virtual bool HandleMouseInput(MouseInput mi) { return false; }
public bool HandleMouseInputOuter(MouseInput mi)
{
diff --git a/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj b/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj
index 14465d8818..6565b299ef 100644
--- a/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj
+++ b/OpenRA.Mods.Cnc/OpenRA.Mods.Cnc.csproj
@@ -96,6 +96,10 @@
+
+
+
+
diff --git a/OpenRA.Mods.Cnc/Widgets/Logic/ButtonTooltipLogic.cs b/OpenRA.Mods.Cnc/Widgets/Logic/ButtonTooltipLogic.cs
new file mode 100644
index 0000000000..1cb0c7d5fa
--- /dev/null
+++ b/OpenRA.Mods.Cnc/Widgets/Logic/ButtonTooltipLogic.cs
@@ -0,0 +1,27 @@
+#region Copyright & License Information
+/*
+ * Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
+ * This file is part of OpenRA, which is free software. It is made
+ * available to you under the terms of the GNU General Public License
+ * as published by the Free Software Foundation. For more information,
+ * see COPYING.
+ */
+#endregion
+
+using OpenRA.Support;
+using OpenRA.Widgets;
+
+namespace OpenRA.Mods.Cnc.Widgets.Logic
+{
+ public class ButtonTooltipLogic
+ {
+ [ObjectCreator.UseCtor]
+ public ButtonTooltipLogic([ObjectCreator.Param] Widget widget,
+ [ObjectCreator.Param] TooltipButtonWidget button)
+ {
+ widget.GetWidget("LABEL").GetText = () => button.TooltipText;
+ widget.GetWidget("HOTKEY").GetText = () => button.Key;
+ }
+ }
+}
+
diff --git a/OpenRA.Mods.Cnc/Widgets/Logic/ProductionTooltipLogic.cs b/OpenRA.Mods.Cnc/Widgets/Logic/ProductionTooltipLogic.cs
new file mode 100644
index 0000000000..5d1eda2c83
--- /dev/null
+++ b/OpenRA.Mods.Cnc/Widgets/Logic/ProductionTooltipLogic.cs
@@ -0,0 +1,27 @@
+#region Copyright & License Information
+/*
+ * Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
+ * This file is part of OpenRA, which is free software. It is made
+ * available to you under the terms of the GNU General Public License
+ * as published by the Free Software Foundation. For more information,
+ * see COPYING.
+ */
+#endregion
+
+using OpenRA.Support;
+using OpenRA.Widgets;
+
+namespace OpenRA.Mods.Cnc.Widgets.Logic
+{
+ public class ProductionTooltipLogic
+ {
+ [ObjectCreator.UseCtor]
+ public ProductionTooltipLogic([ObjectCreator.Param] Widget widget,
+ [ObjectCreator.Param] ProductionPaletteWidget palette)
+ {
+ widget.IsVisible = () => palette.TooltipActor != null;
+ widget.GetWidget("NAME").GetText = () => palette.TooltipActor;
+ }
+ }
+}
+
diff --git a/OpenRA.Mods.Cnc/Widgets/ProductionPaletteWidget.cs b/OpenRA.Mods.Cnc/Widgets/ProductionPaletteWidget.cs
index 84e90e3a88..6834b8cc7b 100755
--- a/OpenRA.Mods.Cnc/Widgets/ProductionPaletteWidget.cs
+++ b/OpenRA.Mods.Cnc/Widgets/ProductionPaletteWidget.cs
@@ -33,7 +33,11 @@ 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 string TooltipActor { get; private set; }
+ Lazy tooltipContainer;
ProductionQueue currentQueue;
public ProductionQueue CurrentQueue
{
@@ -62,7 +66,9 @@ namespace OpenRA.Mods.Cnc.Widgets
{
this.world = world;
this.worldRenderer = worldRenderer;
-
+ tooltipContainer = new Lazy(() =>
+ Widget.RootWidget.GetWidget(TooltipContainer));
+
cantBuild = new Animation("clock");
cantBuild.PlayFetchIndex("idle", () => 0);
clock = new Animation("clock");
@@ -83,12 +89,36 @@ namespace OpenRA.Mods.Cnc.Widgets
if (CurrentQueue != null)
RefreshIcons();
}
-
+
+ public override void MouseEntered()
+ {
+ if (TooltipContainer == null)
+ return;
+
+ var panel = Widget.LoadWidget(TooltipTemplate, null, new WidgetArgs() {{ "palette", this }});
+ tooltipContainer.Value.SetTooltip(panel);
+ }
+
+ public override void MouseExited()
+ {
+ if (TooltipContainer == null) return;
+ tooltipContainer.Value.RemoveTooltip();
+ }
+
public override bool HandleMouseInput(MouseInput mi)
{
+ if (mi.Event == MouseInputEvent.Move)
+ {
+ var hover = Icons.Where(i => i.Key.Contains(mi.Location))
+ .Select(i => i.Value).FirstOrDefault();
+
+ TooltipActor = hover != null ? hover.Name : null;
+ return false;
+ }
+
if (mi.Event != MouseInputEvent.Down)
return false;
-
+
var clicked = Icons.Where(i => i.Key.Contains(mi.Location))
.Select(i => i.Value).FirstOrDefault();
diff --git a/OpenRA.Mods.Cnc/Widgets/TooltipButtonWidget.cs b/OpenRA.Mods.Cnc/Widgets/TooltipButtonWidget.cs
new file mode 100644
index 0000000000..b7abb2e111
--- /dev/null
+++ b/OpenRA.Mods.Cnc/Widgets/TooltipButtonWidget.cs
@@ -0,0 +1,55 @@
+#region Copyright & License Information
+/*
+ * Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
+ * This file is part of OpenRA, which is free software. It is made
+ * available to you under the terms of the GNU General Public License
+ * as published by the Free Software Foundation. For more information,
+ * see COPYING.
+ */
+#endregion
+
+using OpenRA.FileFormats;
+using OpenRA.Widgets;
+
+namespace OpenRA.Mods.Cnc.Widgets
+{
+ public class TooltipButtonWidget : ButtonWidget
+ {
+ public readonly string TooltipTemplate;
+ public readonly string TooltipText;
+ public readonly string TooltipContainer;
+ Lazy tooltipContainer;
+
+ public TooltipButtonWidget()
+ : base()
+ {
+ tooltipContainer = new Lazy(() =>
+ Widget.RootWidget.GetWidget(TooltipContainer));
+ }
+
+ protected TooltipButtonWidget(TooltipButtonWidget other)
+ : base(other)
+ {
+ TooltipTemplate = other.TooltipTemplate;
+ TooltipText = other.TooltipText;
+ TooltipContainer = other.TooltipContainer;
+ tooltipContainer = new Lazy(() =>
+ Widget.RootWidget.GetWidget(TooltipContainer));
+ }
+
+ public override void MouseEntered()
+ {
+ if (TooltipContainer == null)
+ return;
+
+ var panel = Widget.LoadWidget(TooltipTemplate, null, new WidgetArgs() {{ "button", this }});
+ tooltipContainer.Value.SetTooltip(panel);
+ }
+
+ public override void MouseExited()
+ {
+ if (TooltipContainer == null) return;
+ tooltipContainer.Value.RemoveTooltip();
+ }
+ }
+}
\ No newline at end of file
diff --git a/OpenRA.Mods.Cnc/Widgets/TooltipContainerWidget.cs b/OpenRA.Mods.Cnc/Widgets/TooltipContainerWidget.cs
new file mode 100755
index 0000000000..b8b308e4a1
--- /dev/null
+++ b/OpenRA.Mods.Cnc/Widgets/TooltipContainerWidget.cs
@@ -0,0 +1,64 @@
+#region Copyright & License Information
+/*
+ * Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
+ * This file is part of OpenRA, which is free software. It is made
+ * available to you under the terms of the GNU General Public License
+ * as published by the Free Software Foundation. For more information,
+ * see COPYING.
+ */
+#endregion
+
+using System.Collections.Generic;
+using System.Drawing;
+using System.Linq;
+using OpenRA.FileFormats;
+using OpenRA.Graphics;
+using OpenRA.Mods.RA;
+using OpenRA.Widgets;
+using System;
+
+namespace OpenRA.Mods.Cnc.Widgets
+{
+ class TooltipContainerWidget : Widget
+ {
+ public int2 CursorOffset = new int2(20, 0);
+ public int TooltipDelay = 10;
+ Widget tooltip;
+
+ public TooltipContainerWidget()
+ {
+ IsVisible = () => Viewport.TicksSinceLastMove >= TooltipDelay;
+ }
+
+ public void SetTooltip(Widget tooltip)
+ {
+ this.tooltip = tooltip;
+ RemoveChildren();
+ AddChild(tooltip);
+ }
+
+ public void RemoveTooltip()
+ {
+ RemoveChildren();
+ }
+
+ public override Rectangle GetEventBounds() { return Rectangle.Empty; }
+ public override int2 ChildOrigin
+ {
+ get
+ {
+ var pos = Viewport.LastMousePos + CursorOffset;
+ if (tooltip != null)
+ {
+ if (pos.X + tooltip.Bounds.Right > Game.viewport.Width)
+ pos.X -= 2*CursorOffset.X + tooltip.Bounds.Right;
+ }
+
+ return pos;
+ }
+ }
+
+ public override string GetCursor(int2 pos) { return null; }
+ public override Widget Clone() { throw new NotImplementedException(); }
+ }
+}
diff --git a/mods/cnc/chrome/ingame.yaml b/mods/cnc/chrome/ingame.yaml
index b4dac21f7f..cf3152568b 100644
--- a/mods/cnc/chrome/ingame.yaml
+++ b/mods/cnc/chrome/ingame.yaml
@@ -24,7 +24,6 @@ Container@INGAME_ROOT:
Width:140
Height:35
Text:Cheats
- WorldTooltip:
ChatDisplay@CHAT_DISPLAY:
Id:CHAT_DISPLAY
X:250
@@ -180,40 +179,55 @@ Container@INGAME_ROOT:
Width:170
Height:30
Children:
- Button@BUILDING:
+ TooltipButton@BUILDING:
Id:BUILDING
Width:30
Height:30
Text: B
Key: y
- Button@DEFENSE:
+ TooltipText: Buildings
+ TooltipContainer: TOOLTIP_CONTAINER
+ TooltipTemplate: BUTTON_TOOLTIP
+ TooltipButton@DEFENSE:
Id:DEFENSE
X:35
Width:30
Height:30
Text: D
Key: u
- Button@INFANTRY:
+ TooltipText: Defense
+ TooltipContainer: TOOLTIP_CONTAINER
+ TooltipTemplate: BUTTON_TOOLTIP
+ TooltipButton@INFANTRY:
Id:INFANTRY
X:70
Width:30
Height:30
Text: I
Key: i
- Button@VEHICLE:
+ TooltipText: Infantry
+ TooltipContainer: TOOLTIP_CONTAINER
+ TooltipTemplate: BUTTON_TOOLTIP
+ TooltipButton@VEHICLE:
Id:VEHICLE
X:105
Width:30
Height:30
Text: V
Key: o
- Button@AIRCRAFT:
+ TooltipText: Vehicles
+ TooltipContainer: TOOLTIP_CONTAINER
+ TooltipTemplate: BUTTON_TOOLTIP
+ TooltipButton@AIRCRAFT:
Id:AIRCRAFT
X:140
Width:30
Height:30
Text: H
Key: p
+ TooltipText: Aircraft
+ TooltipContainer: TOOLTIP_CONTAINER
+ TooltipTemplate: BUTTON_TOOLTIP
ProductionTabs:
Id:PRODUCTION_TABS
PaletteWidget:PRODUCTION_PALETTE
@@ -226,6 +240,11 @@ Container@INGAME_ROOT:
X:WINDOW_RIGHT - 204
Y:287
TabClick: button.aud
+ TooltipContainer: TOOLTIP_CONTAINER
+ TooltipTemplate: PRODUCTION_TOOLTIP
+ TooltipContainer:
+ Id:TOOLTIP_CONTAINER
+
Background@FMVPLAYER:
Id:FMVPLAYER
Width:WINDOW_RIGHT
diff --git a/mods/cnc/chrome/tooltips.yaml b/mods/cnc/chrome/tooltips.yaml
new file mode 100644
index 0000000000..0fde42d0de
--- /dev/null
+++ b/mods/cnc/chrome/tooltips.yaml
@@ -0,0 +1,36 @@
+Background@PRODUCTION_TOOLTIP:
+ Id:PRODUCTION_TOOLTIP
+ Logic:ProductionTooltipLogic
+ Background:panel-black
+ Width:100
+ Height:30
+ Children:
+ Label@NAME:
+ Id:NAME
+ X:5
+ Y:5
+ Width:PARENT_RIGHT-10
+ Height:PARENT_BOTTOM-10
+ Font:Bold
+Background@BUTTON_TOOLTIP:
+ Id:BUTTON_TOOLTIP
+ Logic:ButtonTooltipLogic
+ Background:panel-black
+ Width:100
+ Height:30
+ Children:
+ Label@LABEL:
+ Id:LABEL
+ X:5
+ Y:5
+ Width:PARENT_RIGHT-10
+ Height:PARENT_BOTTOM-10
+ Font:Bold
+ Label@HOTKEY:
+ Id:HOTKEY
+ X:PARENT_RIGHT-15
+ Y:5
+ Color:255,255,0
+ Width:PARENT_RIGHT-10
+ Height:PARENT_BOTTOM-10
+ Font:Bold
\ No newline at end of file
diff --git a/mods/cnc/mod.yaml b/mods/cnc/mod.yaml
index 89d5f4f49c..f622fef8b9 100644
--- a/mods/cnc/mod.yaml
+++ b/mods/cnc/mod.yaml
@@ -80,6 +80,7 @@ ChromeLayout:
mods/cnc/chrome/cheats.yaml
mods/cnc/chrome/dropdowns.yaml
mods/cnc/chrome/objectives.yaml
+ mods/cnc/chrome/tooltips.yaml
Weapons:
mods/cnc/weapons.yaml