Add tooltips for the power and cash displays.

This commit is contained in:
Paul Chote
2014-07-17 18:51:38 +12:00
parent f7f01cc08e
commit 7c9223caea
5 changed files with 91 additions and 28 deletions

View File

@@ -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<TooltipContainerWidget> tooltipContainer;
public Func<string> GetTooltipText = () => "";
[ObjectCreator.UseCtor]
public LabelWithTooltipWidget(World world)
: base()
{
tooltipContainer = Exts.Lazy(() =>
Ui.Root.Get<TooltipContainerWidget>(TooltipContainer));
}
protected LabelWithTooltipWidget(LabelWithTooltipWidget other)
: base(other)
{
TooltipTemplate = other.TooltipTemplate;
TooltipContainer = other.TooltipContainer;
tooltipContainer = Exts.Lazy(() =>
Ui.Root.Get<TooltipContainerWidget>(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();
}
}
}

View File

@@ -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<PlayerResources>();
var cash = widget.Get<LabelWidget>("CASH");
var cash = widget.Get<LabelWithTooltipWidget>("CASH");
var label = cash.Text;
cash.GetText = () => label.F(playerResources.DisplayCash + playerResources.DisplayResources);
cash.GetTooltipText = () => "Silo Usage: {0}/{1}".F(playerResources.Resources, playerResources.ResourceCapacity);
}
}
}

View File

@@ -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<PowerManager>();
var power = widget.Get<LabelWidget>("POWER");
var power = widget.Get<LabelWithTooltipWidget>("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() : "");
}
}
}

View File

@@ -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

View File

@@ -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