Simple support power tooltips
This commit is contained in:
@@ -8,6 +8,8 @@
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using OpenRA.Mods.RA;
|
||||
using OpenRA.Support;
|
||||
using OpenRA.Widgets;
|
||||
|
||||
@@ -17,10 +19,38 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
|
||||
{
|
||||
[ObjectCreator.UseCtor]
|
||||
public SupportPowerTooltipLogic([ObjectCreator.Param] Widget widget,
|
||||
[ObjectCreator.Param] TooltipContainerWidget tooltipContainer,
|
||||
[ObjectCreator.Param] SupportPowersWidget palette)
|
||||
{
|
||||
widget.IsVisible = () => palette.TooltipPower != null;
|
||||
widget.GetWidget<LabelWidget>("NAME").GetText = () => palette.TooltipPower;
|
||||
var nameLabel = widget.GetWidget<LabelWidget>("NAME");
|
||||
var timeLabel = widget.GetWidget<LabelWidget>("TIME");
|
||||
var nameFont = Game.Renderer.Fonts[nameLabel.Font];
|
||||
var timeFont = Game.Renderer.Fonts[timeLabel.Font];
|
||||
var name = "";
|
||||
var time = "";
|
||||
|
||||
SupportPowerManager.SupportPowerInstance lastPower = null;
|
||||
tooltipContainer.BeforeRender = () =>
|
||||
{
|
||||
var sp = palette.TooltipPower;
|
||||
if (sp == null)
|
||||
return;
|
||||
|
||||
time = "{0} / {1}".F(WidgetUtils.FormatTime(sp.RemainingTime),
|
||||
WidgetUtils.FormatTime(sp.Info.ChargeTime*25));
|
||||
|
||||
if (sp == lastPower)
|
||||
return;
|
||||
|
||||
name = sp.Info.Description;
|
||||
widget.Bounds.Width = 2*nameLabel.Bounds.X
|
||||
+ Math.Max(nameFont.Measure(name).X, timeFont.Measure(time).X);
|
||||
lastPower = sp;
|
||||
};
|
||||
|
||||
nameLabel.GetText = () => name;
|
||||
timeLabel.GetText = () => time;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user