Implemented an interface that allows traits to add custom information to tooltips.
This commit is contained in:
@@ -136,6 +136,12 @@ namespace OpenRA.Traits
|
||||
bool IsOwnerRowVisible { get; }
|
||||
}
|
||||
|
||||
public interface IProvideTooltipInfo
|
||||
{
|
||||
bool IsTooltipVisible(Player forPlayer);
|
||||
string TooltipText { get; }
|
||||
}
|
||||
|
||||
public interface IDisabledTrait { bool IsTraitDisabled { get; } }
|
||||
public interface IDisable { bool Disabled { get; } }
|
||||
public interface IExplodeModifier { bool ShouldExplode(Actor self); }
|
||||
|
||||
@@ -27,6 +27,7 @@ namespace OpenRA.Widgets
|
||||
|
||||
public WorldTooltipType TooltipType { get; private set; }
|
||||
public IToolTip ActorTooltip { get; private set; }
|
||||
public IEnumerable<IProvideTooltipInfo> ActorTooltipExtra { get; private set; }
|
||||
public FrozenActor FrozenActorTooltip { get; private set; }
|
||||
|
||||
public int EdgeScrollThreshold = 15;
|
||||
@@ -109,6 +110,7 @@ namespace OpenRA.Widgets
|
||||
if (underCursor != null)
|
||||
{
|
||||
ActorTooltip = underCursor.TraitsImplementing<IToolTip>().First();
|
||||
ActorTooltipExtra = underCursor.TraitsImplementing<IProvideTooltipInfo>();
|
||||
TooltipType = WorldTooltipType.Actor;
|
||||
return;
|
||||
}
|
||||
@@ -120,6 +122,7 @@ namespace OpenRA.Widgets
|
||||
if (frozen != null)
|
||||
{
|
||||
FrozenActorTooltip = frozen;
|
||||
ActorTooltipExtra = frozen.Actor.TraitsImplementing<IProvideTooltipInfo>();
|
||||
TooltipType = WorldTooltipType.FrozenActor;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.Widgets;
|
||||
@@ -24,6 +25,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
var label = widget.Get<LabelWidget>("LABEL");
|
||||
var flag = widget.Get<ImageWidget>("FLAG");
|
||||
var owner = widget.Get<LabelWidget>("OWNER");
|
||||
var extras = widget.Get<LabelWidget>("EXTRA");
|
||||
|
||||
var font = Game.Renderer.Fonts[label.Font];
|
||||
var ownerFont = Game.Renderer.Fonts[owner.Font];
|
||||
@@ -33,6 +35,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
var flagRace = "";
|
||||
var ownerName = "";
|
||||
var ownerColor = Color.White;
|
||||
var extraText = "";
|
||||
|
||||
var singleHeight = widget.Get("SINGLE_HEIGHT").Bounds.Height;
|
||||
var doubleHeight = widget.Get("DOUBLE_HEIGHT").Bounds.Height;
|
||||
@@ -42,6 +45,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
if (viewport == null || viewport.TooltipType == WorldTooltipType.None)
|
||||
return;
|
||||
|
||||
var index = 0;
|
||||
extraText = "";
|
||||
showOwner = false;
|
||||
|
||||
Player o = null;
|
||||
@@ -71,7 +76,22 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
}
|
||||
}
|
||||
|
||||
var textWidth = font.Measure(labelText).X;
|
||||
if (viewport.ActorTooltipExtra != null)
|
||||
{
|
||||
foreach (var info in viewport.ActorTooltipExtra)
|
||||
{
|
||||
if (info.IsTooltipVisible(world.LocalPlayer))
|
||||
{
|
||||
if (index != 0)
|
||||
extraText += "\n";
|
||||
extraText += info.TooltipText;
|
||||
index++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var textWidth = Math.Max(font.Measure(labelText).X, font.Measure(extraText).X);
|
||||
|
||||
if (textWidth != cachedWidth)
|
||||
{
|
||||
label.Bounds.Width = textWidth;
|
||||
@@ -86,9 +106,15 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
widget.Bounds.Height = doubleHeight;
|
||||
widget.Bounds.Width = Math.Max(widget.Bounds.Width,
|
||||
owner.Bounds.X + ownerFont.Measure(ownerName).X + label.Bounds.X);
|
||||
index++;
|
||||
}
|
||||
else
|
||||
widget.Bounds.Height = singleHeight;
|
||||
|
||||
if (extraText != "")
|
||||
{
|
||||
widget.Bounds.Height += font.Measure(extraText).Y + extras.Bounds.Height;
|
||||
}
|
||||
};
|
||||
|
||||
label.GetText = () => labelText;
|
||||
@@ -98,6 +124,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
owner.IsVisible = () => showOwner;
|
||||
owner.GetText = () => ownerName;
|
||||
owner.GetColor = () => ownerColor;
|
||||
extras.GetText = () => extraText;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,6 +45,11 @@ Background@WORLD_TOOLTIP:
|
||||
Y: 19
|
||||
Height: 23
|
||||
Font: Bold
|
||||
Label@EXTRA:
|
||||
X: 5
|
||||
Y: 45
|
||||
Height: 4
|
||||
Font: Bold
|
||||
|
||||
Background@PRODUCTION_TOOLTIP:
|
||||
Logic: ProductionTooltipLogic
|
||||
|
||||
@@ -49,6 +49,11 @@ Background@WORLD_TOOLTIP:
|
||||
Y: 25
|
||||
Height: 23
|
||||
Font: Bold
|
||||
Label@EXTRA:
|
||||
X: 7
|
||||
Y: 55
|
||||
Height: 4
|
||||
Font: Bold
|
||||
|
||||
Background@SPAWN_TOOLTIP:
|
||||
Logic: SpawnSelectorTooltipLogic
|
||||
|
||||
@@ -49,6 +49,11 @@ Background@WORLD_TOOLTIP:
|
||||
Y: 22
|
||||
Height: 23
|
||||
Font: Bold
|
||||
Label@EXTRA:
|
||||
X: 7
|
||||
Y: 48
|
||||
Height: 4
|
||||
Font: Bold
|
||||
|
||||
Background@SPAWN_TOOLTIP:
|
||||
Logic: SpawnSelectorTooltipLogic
|
||||
|
||||
Reference in New Issue
Block a user