Power/Silo bar tooltips.
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using OpenRA.FileFormats;
|
||||
using OpenRA.Graphics;
|
||||
using OpenRA.Mods.RA.Buildings;
|
||||
using OpenRA.Widgets;
|
||||
@@ -18,14 +19,34 @@ namespace OpenRA.Mods.Cnc.Widgets
|
||||
{
|
||||
public class PowerBarWidget : Widget
|
||||
{
|
||||
public readonly string TooltipTemplate = "SIMPLE_TOOLTIP";
|
||||
public readonly string TooltipContainer;
|
||||
Lazy<TooltipContainerWidget> tooltipContainer;
|
||||
|
||||
float? lastProvidedFrac;
|
||||
float? lastDrainedFrac;
|
||||
|
||||
readonly PowerManager pm;
|
||||
|
||||
[ObjectCreator.UseCtor]
|
||||
public PowerBarWidget( [ObjectCreator.Param] World world )
|
||||
{
|
||||
pm = world.LocalPlayer.PlayerActor.Trait<PowerManager>();
|
||||
tooltipContainer = new Lazy<TooltipContainerWidget>(() =>
|
||||
Widget.RootWidget.GetWidget<TooltipContainerWidget>(TooltipContainer));
|
||||
}
|
||||
|
||||
public override void MouseEntered()
|
||||
{
|
||||
if (TooltipContainer == null) return;
|
||||
Func<string> getText = () => "Power Usage: {0}/{1}".F(pm.PowerDrained, pm.PowerProvided);
|
||||
tooltipContainer.Value.SetTooltip(
|
||||
Widget.LoadWidget(TooltipTemplate, null, new WidgetArgs() {{ "getText", getText }}));
|
||||
}
|
||||
|
||||
public override void MouseExited()
|
||||
{
|
||||
if (TooltipContainer == null) return;
|
||||
tooltipContainer.Value.RemoveTooltip();
|
||||
}
|
||||
|
||||
public override void Draw()
|
||||
|
||||
Reference in New Issue
Block a user