diff --git a/OpenRA.Mods.RA/Widgets/LabelWithTooltipWidget.cs b/OpenRA.Mods.RA/Widgets/LabelWithTooltipWidget.cs new file mode 100644 index 0000000000..58ef367714 --- /dev/null +++ b/OpenRA.Mods.RA/Widgets/LabelWithTooltipWidget.cs @@ -0,0 +1,62 @@ +#region Copyright & License Information +/* + * Copyright 2007-2014 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; +using OpenRA.Widgets; + +namespace OpenRA.Mods.RA.Widgets +{ + public class LabelWithTooltipWidget : LabelWidget + { + public readonly string TooltipTemplate; + public readonly string TooltipContainer; + Lazy tooltipContainer; + + public Func GetTooltipText = () => ""; + + [ObjectCreator.UseCtor] + public LabelWithTooltipWidget(World world) + : base() + { + tooltipContainer = Exts.Lazy(() => + Ui.Root.Get(TooltipContainer)); + } + + protected LabelWithTooltipWidget(LabelWithTooltipWidget other) + : base(other) + { + TooltipTemplate = other.TooltipTemplate; + TooltipContainer = other.TooltipContainer; + + tooltipContainer = Exts.Lazy(() => + Ui.Root.Get(TooltipContainer)); + + GetTooltipText = other.GetTooltipText; + } + + public override Widget Clone() { return new LabelWithTooltipWidget(this); } + + public override void MouseEntered() + { + if (TooltipContainer == null) + return; + + tooltipContainer.Value.SetTooltip(TooltipTemplate, new WidgetArgs() {{ "getText", GetTooltipText }}); + } + + public override void MouseExited() + { + if (TooltipContainer == null) + return; + + tooltipContainer.Value.RemoveTooltip(); + } + } +} diff --git a/OpenRA.Mods.RA/Widgets/Logic/Ingame/IngameCashCounterLogic.cs b/OpenRA.Mods.RA/Widgets/Logic/Ingame/IngameCashCounterLogic.cs index 02fe191188..cf3ae7323a 100644 --- a/OpenRA.Mods.RA/Widgets/Logic/Ingame/IngameCashCounterLogic.cs +++ b/OpenRA.Mods.RA/Widgets/Logic/Ingame/IngameCashCounterLogic.cs @@ -11,7 +11,7 @@ using OpenRA.Traits; using OpenRA.Widgets; -namespace OpenRA.Mods.Cnc.Widgets.Logic +namespace OpenRA.Mods.RA.Widgets.Logic { public class IngameCashCounterLogic { @@ -19,10 +19,11 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic public IngameCashCounterLogic(Widget widget, World world) { var playerResources = world.LocalPlayer.PlayerActor.Trait(); - var cash = widget.Get("CASH"); + var cash = widget.Get("CASH"); var label = cash.Text; cash.GetText = () => label.F(playerResources.DisplayCash + playerResources.DisplayResources); + cash.GetTooltipText = () => "Silo Usage: {0}/{1}".F(playerResources.Resources, playerResources.ResourceCapacity); } } } diff --git a/OpenRA.Mods.RA/Widgets/Logic/Ingame/IngamePowerCounterLogic.cs b/OpenRA.Mods.RA/Widgets/Logic/Ingame/IngamePowerCounterLogic.cs index ec13966cf7..b8c5cfdbaa 100644 --- a/OpenRA.Mods.RA/Widgets/Logic/Ingame/IngamePowerCounterLogic.cs +++ b/OpenRA.Mods.RA/Widgets/Logic/Ingame/IngamePowerCounterLogic.cs @@ -8,9 +8,7 @@ */ #endregion -using System.Drawing; using OpenRA.Mods.RA.Buildings; -using OpenRA.Network; using OpenRA.Widgets; namespace OpenRA.Mods.RA.Widgets.Logic @@ -18,15 +16,13 @@ namespace OpenRA.Mods.RA.Widgets.Logic public class IngamePowerCounterLogic { [ObjectCreator.UseCtor] - public IngamePowerCounterLogic(Widget widget, OrderManager orderManager, World world) + public IngamePowerCounterLogic(Widget widget, World world) { var powerManager = world.LocalPlayer.PlayerActor.Trait(); - var power = widget.Get("POWER"); + var power = widget.Get("POWER"); - power.GetText = () => powerManager.PowerProvided == 1000000 ? "inf" : powerManager.ExcessPower.ToString("+#;-#;0"); - - // Blink red when low power - power.GetColor = () => powerManager.ExcessPower < 0 && orderManager.LocalFrameNumber / 9 % 2 == 0 ? Color.Red : power.TextColor; + power.GetText = () => powerManager.PowerProvided == 1000000 ? "inf" : powerManager.ExcessPower.ToString(); + power.GetTooltipText = () => "Power Usage: " + powerManager.PowerDrained.ToString() + (powerManager.PowerProvided != 1000000 ? "/" + powerManager.PowerProvided.ToString() : ""); } } } diff --git a/mods/cnc/chrome/ingame.yaml b/mods/cnc/chrome/ingame.yaml index 6af5249a42..28c3318cff 100644 --- a/mods/cnc/chrome/ingame.yaml +++ b/mods/cnc/chrome/ingame.yaml @@ -310,7 +310,7 @@ Container@PLAYER_WIDGETS: TooltipContainer: TOOLTIP_CONTAINER TooltipTemplate: SIMPLE_TOOLTIP IndicatorImage: indicator-right - Label@CASH: + LabelWithTooltip@CASH: Logic: IngameCashCounterLogic Y: 170 Width: PARENT_RIGHT diff --git a/mods/ra/chrome/ingame-player.yaml b/mods/ra/chrome/ingame-player.yaml index 1c55696df9..3d19a85862 100644 --- a/mods/ra/chrome/ingame-player.yaml +++ b/mods/ra/chrome/ingame-player.yaml @@ -174,23 +174,6 @@ Container@PLAYER_WIDGETS: Width: 220 Height: 220 Children: - Label@CASH: - Logic: IngameCashCounterLogic - X: 35 - Y: 262 - Width: 100 - Height: 22 - Font: Bold - Text: {0} - Label@POWER: - Logic: IngamePowerCounterLogic - X: PARENT_RIGHT - WIDTH - 30 - Y: 262 - Width: 100 - Height: 22 - Align: Right - Font: Bold - Text: {0} Label@GAME_TIMER: Logic: GameTimerLogic Y: 263 @@ -198,6 +181,27 @@ Container@PLAYER_WIDGETS: Height: 22 Align: Center Font: TinyBold + LabelWithTooltip@CASH: + Logic: IngameCashCounterLogic + X: 35 + Y: 262 + Width: 50 + Height: 22 + Font: Bold + Text: {0} + TooltipContainer: TOOLTIP_CONTAINER + TooltipTemplate: SIMPLE_TOOLTIP + LabelWithTooltip@POWER: + Logic: IngamePowerCounterLogic + X: PARENT_RIGHT - WIDTH - 30 + Y: 262 + Width: 50 + Height: 22 + Align: Right + Font: Bold + Text: {0} + TooltipContainer: TOOLTIP_CONTAINER + TooltipTemplate: SIMPLE_TOOLTIP Container@SIDEBAR_PRODUCTION: Logic: ClassicProductionLogic X: WINDOW_RIGHT - 250