Add tooltips for the power and cash displays.
This commit is contained in:
62
OpenRA.Mods.RA/Widgets/LabelWithTooltipWidget.cs
Normal file
62
OpenRA.Mods.RA/Widgets/LabelWithTooltipWidget.cs
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -11,7 +11,7 @@
|
|||||||
using OpenRA.Traits;
|
using OpenRA.Traits;
|
||||||
using OpenRA.Widgets;
|
using OpenRA.Widgets;
|
||||||
|
|
||||||
namespace OpenRA.Mods.Cnc.Widgets.Logic
|
namespace OpenRA.Mods.RA.Widgets.Logic
|
||||||
{
|
{
|
||||||
public class IngameCashCounterLogic
|
public class IngameCashCounterLogic
|
||||||
{
|
{
|
||||||
@@ -19,10 +19,11 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
|
|||||||
public IngameCashCounterLogic(Widget widget, World world)
|
public IngameCashCounterLogic(Widget widget, World world)
|
||||||
{
|
{
|
||||||
var playerResources = world.LocalPlayer.PlayerActor.Trait<PlayerResources>();
|
var playerResources = world.LocalPlayer.PlayerActor.Trait<PlayerResources>();
|
||||||
var cash = widget.Get<LabelWidget>("CASH");
|
var cash = widget.Get<LabelWithTooltipWidget>("CASH");
|
||||||
var label = cash.Text;
|
var label = cash.Text;
|
||||||
|
|
||||||
cash.GetText = () => label.F(playerResources.DisplayCash + playerResources.DisplayResources);
|
cash.GetText = () => label.F(playerResources.DisplayCash + playerResources.DisplayResources);
|
||||||
|
cash.GetTooltipText = () => "Silo Usage: {0}/{1}".F(playerResources.Resources, playerResources.ResourceCapacity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,9 +8,7 @@
|
|||||||
*/
|
*/
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
using System.Drawing;
|
|
||||||
using OpenRA.Mods.RA.Buildings;
|
using OpenRA.Mods.RA.Buildings;
|
||||||
using OpenRA.Network;
|
|
||||||
using OpenRA.Widgets;
|
using OpenRA.Widgets;
|
||||||
|
|
||||||
namespace OpenRA.Mods.RA.Widgets.Logic
|
namespace OpenRA.Mods.RA.Widgets.Logic
|
||||||
@@ -18,15 +16,13 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
|||||||
public class IngamePowerCounterLogic
|
public class IngamePowerCounterLogic
|
||||||
{
|
{
|
||||||
[ObjectCreator.UseCtor]
|
[ObjectCreator.UseCtor]
|
||||||
public IngamePowerCounterLogic(Widget widget, OrderManager orderManager, World world)
|
public IngamePowerCounterLogic(Widget widget, World world)
|
||||||
{
|
{
|
||||||
var powerManager = world.LocalPlayer.PlayerActor.Trait<PowerManager>();
|
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");
|
power.GetText = () => powerManager.PowerProvided == 1000000 ? "inf" : powerManager.ExcessPower.ToString();
|
||||||
|
power.GetTooltipText = () => "Power Usage: " + powerManager.PowerDrained.ToString() + (powerManager.PowerProvided != 1000000 ? "/" + powerManager.PowerProvided.ToString() : "");
|
||||||
// Blink red when low power
|
|
||||||
power.GetColor = () => powerManager.ExcessPower < 0 && orderManager.LocalFrameNumber / 9 % 2 == 0 ? Color.Red : power.TextColor;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -310,7 +310,7 @@ Container@PLAYER_WIDGETS:
|
|||||||
TooltipContainer: TOOLTIP_CONTAINER
|
TooltipContainer: TOOLTIP_CONTAINER
|
||||||
TooltipTemplate: SIMPLE_TOOLTIP
|
TooltipTemplate: SIMPLE_TOOLTIP
|
||||||
IndicatorImage: indicator-right
|
IndicatorImage: indicator-right
|
||||||
Label@CASH:
|
LabelWithTooltip@CASH:
|
||||||
Logic: IngameCashCounterLogic
|
Logic: IngameCashCounterLogic
|
||||||
Y: 170
|
Y: 170
|
||||||
Width: PARENT_RIGHT
|
Width: PARENT_RIGHT
|
||||||
|
|||||||
@@ -174,23 +174,6 @@ Container@PLAYER_WIDGETS:
|
|||||||
Width: 220
|
Width: 220
|
||||||
Height: 220
|
Height: 220
|
||||||
Children:
|
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:
|
Label@GAME_TIMER:
|
||||||
Logic: GameTimerLogic
|
Logic: GameTimerLogic
|
||||||
Y: 263
|
Y: 263
|
||||||
@@ -198,6 +181,27 @@ Container@PLAYER_WIDGETS:
|
|||||||
Height: 22
|
Height: 22
|
||||||
Align: Center
|
Align: Center
|
||||||
Font: TinyBold
|
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:
|
Container@SIDEBAR_PRODUCTION:
|
||||||
Logic: ClassicProductionLogic
|
Logic: ClassicProductionLogic
|
||||||
X: WINDOW_RIGHT - 250
|
X: WINDOW_RIGHT - 250
|
||||||
|
|||||||
Reference in New Issue
Block a user