Added tooltip to support powers in spec ui
This commit is contained in:
@@ -21,12 +21,19 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
{
|
||||
public class ObserverSupportPowerIconsWidget : Widget
|
||||
{
|
||||
public readonly string TooltipTemplate = "SUPPORT_POWER_TOOLTIP";
|
||||
public readonly string TooltipContainer;
|
||||
readonly Animation icon;
|
||||
readonly World world;
|
||||
readonly WorldRenderer worldRenderer;
|
||||
readonly Dictionary<string, Animation> clocks;
|
||||
readonly int timestep;
|
||||
|
||||
readonly Lazy<TooltipContainerWidget> tooltipContainer;
|
||||
|
||||
public Func<SupportPowersWidget.SupportPowerIcon> GetTooltipIcon;
|
||||
public SupportPowersWidget.SupportPowerIcon TooltipIcon { get; private set; }
|
||||
|
||||
public int IconWidth = 32;
|
||||
public int IconHeight = 24;
|
||||
public int IconSpacing = 1;
|
||||
@@ -36,6 +43,10 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
public string ClockPalette = "chrome";
|
||||
public Func<Player> GetPlayer;
|
||||
|
||||
readonly List<SupportPowersWidget.SupportPowerIcon> supportPowerIconsIcons = new List<SupportPowersWidget.SupportPowerIcon>();
|
||||
readonly List<Rectangle> supportPowerIconsBounds = new List<Rectangle>();
|
||||
int lastIconIdx;
|
||||
|
||||
[ObjectCreator.UseCtor]
|
||||
public ObserverSupportPowerIconsWidget(World world, WorldRenderer worldRenderer)
|
||||
{
|
||||
@@ -48,6 +59,9 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
timestep = world.Timestep;
|
||||
if (world.IsReplay)
|
||||
timestep = world.WorldActor.Trait<MapOptions>().GameSpeed.Timestep;
|
||||
|
||||
tooltipContainer = Exts.Lazy(() =>
|
||||
Ui.Root.Get<TooltipContainerWidget>(TooltipContainer));
|
||||
}
|
||||
|
||||
protected ObserverSupportPowerIconsWidget(ObserverSupportPowerIconsWidget other)
|
||||
@@ -67,22 +81,38 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
ClockAnimation = other.ClockAnimation;
|
||||
ClockSequence = other.ClockSequence;
|
||||
ClockPalette = other.ClockPalette;
|
||||
|
||||
TooltipIcon = other.TooltipIcon;
|
||||
GetTooltipIcon = () => TooltipIcon;
|
||||
|
||||
TooltipTemplate = other.TooltipTemplate;
|
||||
TooltipContainer = other.TooltipContainer;
|
||||
|
||||
tooltipContainer = Exts.Lazy(() =>
|
||||
Ui.Root.Get<TooltipContainerWidget>(TooltipContainer));
|
||||
}
|
||||
|
||||
public override void Draw()
|
||||
{
|
||||
supportPowerIconsIcons.Clear();
|
||||
supportPowerIconsBounds.Clear();
|
||||
|
||||
var player = GetPlayer();
|
||||
if (player == null)
|
||||
return;
|
||||
|
||||
var powers = player.PlayerActor.Trait<SupportPowerManager>().Powers
|
||||
.Where(x => !x.Value.Disabled).Select((a, i) => new { a, i });
|
||||
.Where(x => !x.Value.Disabled).Select((a, i) => new { a, i })
|
||||
.ToList();
|
||||
|
||||
foreach (var power in powers)
|
||||
{
|
||||
if (!clocks.ContainsKey(power.a.Key))
|
||||
clocks.Add(power.a.Key, new Animation(world, ClockAnimation));
|
||||
}
|
||||
|
||||
Bounds.Width = powers.Count() * (IconWidth + IconSpacing);
|
||||
|
||||
var iconSize = new float2(IconWidth, IconHeight);
|
||||
foreach (var power in powers)
|
||||
{
|
||||
@@ -92,6 +122,10 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
|
||||
icon.Play(item.Info.Icon);
|
||||
var location = new float2(RenderBounds.Location) + new float2(power.i * (IconWidth + IconSpacing), 0);
|
||||
|
||||
supportPowerIconsIcons.Add(new SupportPowersWidget.SupportPowerIcon { Power = item });
|
||||
supportPowerIconsBounds.Add(new Rectangle((int)location.X, (int)location.Y, (int)iconSize.X, (int)iconSize.Y));
|
||||
|
||||
WidgetUtils.DrawSHPCentered(icon.Image, location + 0.5f * iconSize, worldRenderer.Palette(item.Info.IconPalette), 0.5f);
|
||||
|
||||
var clock = clocks[power.a.Key];
|
||||
@@ -120,5 +154,46 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
{
|
||||
return new ObserverSupportPowerIconsWidget(this);
|
||||
}
|
||||
|
||||
public override void MouseEntered()
|
||||
{
|
||||
if (TooltipContainer == null)
|
||||
return;
|
||||
|
||||
tooltipContainer.Value.SetTooltip(TooltipTemplate,
|
||||
new WidgetArgs() { { "world", worldRenderer.World }, { "player", GetPlayer() }, { "getTooltipIcon", GetTooltipIcon } });
|
||||
}
|
||||
|
||||
public override void MouseExited()
|
||||
{
|
||||
if (TooltipContainer == null)
|
||||
return;
|
||||
|
||||
tooltipContainer.Value.RemoveTooltip();
|
||||
}
|
||||
|
||||
public override void Tick()
|
||||
{
|
||||
if (lastIconIdx >= supportPowerIconsBounds.Count)
|
||||
{
|
||||
TooltipIcon = null;
|
||||
return;
|
||||
}
|
||||
|
||||
if (TooltipIcon != null && supportPowerIconsBounds[lastIconIdx].Contains(Viewport.LastMousePos))
|
||||
return;
|
||||
|
||||
for (var i = 0; i < supportPowerIconsBounds.Count; i++)
|
||||
{
|
||||
if (!supportPowerIconsBounds[i].Contains(Viewport.LastMousePos))
|
||||
continue;
|
||||
|
||||
lastIconIdx = i;
|
||||
TooltipIcon = supportPowerIconsIcons[i];
|
||||
return;
|
||||
}
|
||||
|
||||
TooltipIcon = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user