Made Tooltip trait upgradable
This commit is contained in:
@@ -40,7 +40,7 @@ namespace OpenRA.Traits
|
||||
|
||||
public ITooltipInfo TooltipInfo { get; private set; }
|
||||
public Player TooltipOwner { get; private set; }
|
||||
readonly ITooltip tooltip;
|
||||
readonly ITooltip[] tooltips;
|
||||
|
||||
public int HP { get; private set; }
|
||||
public DamageState DamageState { get; private set; }
|
||||
@@ -80,7 +80,7 @@ namespace OpenRA.Traits
|
||||
Bounds = self.Bounds;
|
||||
TargetTypes = self.GetEnabledTargetTypes().ToHashSet();
|
||||
|
||||
tooltip = self.TraitsImplementing<ITooltip>().FirstOrDefault();
|
||||
tooltips = self.TraitsImplementing<ITooltip>().ToArray();
|
||||
health = self.TraitOrDefault<IHealth>();
|
||||
|
||||
UpdateVisibility();
|
||||
@@ -101,6 +101,7 @@ namespace OpenRA.Traits
|
||||
DamageState = health.DamageState;
|
||||
}
|
||||
|
||||
var tooltip = tooltips.FirstOrDefault(Exts.IsTraitEnabled);
|
||||
if (tooltip != null)
|
||||
{
|
||||
TooltipInfo = tooltip.TooltipInfo;
|
||||
|
||||
@@ -13,11 +13,9 @@ using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Traits
|
||||
{
|
||||
public abstract class TooltipInfoBase : ITraitInfo
|
||||
public abstract class TooltipInfoBase : UpgradableTraitInfo
|
||||
{
|
||||
[Translate] public readonly string Name = "";
|
||||
|
||||
public abstract object Create(ActorInitializer init);
|
||||
}
|
||||
|
||||
[Desc("Shown in map editor.")]
|
||||
@@ -61,7 +59,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
public bool IsOwnerRowVisible { get { return ShowOwnerRow; } }
|
||||
}
|
||||
|
||||
public class Tooltip : ITooltip
|
||||
public class Tooltip : UpgradableTrait<TooltipInfo>, ITooltip
|
||||
{
|
||||
readonly Actor self;
|
||||
readonly TooltipInfo info;
|
||||
@@ -70,6 +68,7 @@ namespace OpenRA.Mods.Common.Traits
|
||||
public Player Owner { get { return self.Owner; } }
|
||||
|
||||
public Tooltip(Actor self, TooltipInfo info)
|
||||
: base(info)
|
||||
{
|
||||
this.self = self;
|
||||
this.info = info;
|
||||
|
||||
@@ -70,7 +70,9 @@ namespace OpenRA.Mods.Common.Traits
|
||||
Footprint = new ReadOnlyDictionary<CPos, SubCell>(footprint);
|
||||
}
|
||||
|
||||
var tooltip = Info.TraitInfoOrDefault<EditorOnlyTooltipInfo>() as TooltipInfoBase ?? Info.TraitInfoOrDefault<TooltipInfo>();
|
||||
var tooltip = Info.TraitInfos<EditorOnlyTooltipInfo>().FirstOrDefault(Exts.IsTraitEnabled) as TooltipInfoBase
|
||||
?? Info.TraitInfos<TooltipInfo>().FirstOrDefault(Exts.IsTraitEnabled);
|
||||
|
||||
Tooltip = (tooltip == null ? " < " + Info.Name + " >" : tooltip.Name) + "\n" + owner.Name + " (" + owner.Faction + ")"
|
||||
+ "\nID: " + ID + "\nType: " + Info.Name;
|
||||
|
||||
|
||||
@@ -132,7 +132,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
item.Bounds.Height = preview.Bounds.Height + 2 * preview.Bounds.Y;
|
||||
item.IsVisible = () => true;
|
||||
|
||||
var tooltip = actor.TraitInfoOrDefault<EditorOnlyTooltipInfo>() as TooltipInfoBase ?? actor.TraitInfoOrDefault<TooltipInfo>();
|
||||
var tooltip = actor.TraitInfos<EditorOnlyTooltipInfo>().FirstOrDefault(Exts.IsTraitEnabled) as TooltipInfoBase
|
||||
?? actor.TraitInfos<TooltipInfo>().FirstOrDefault(Exts.IsTraitEnabled);
|
||||
|
||||
item.GetTooltipText = () => (tooltip == null ? "Type: " : tooltip.Name + "\nType: ") + actor.Name;
|
||||
|
||||
panel.AddChild(item);
|
||||
|
||||
@@ -55,7 +55,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
if (actor == null || actor == lastActor)
|
||||
return;
|
||||
|
||||
var tooltip = actor.TraitInfo<TooltipInfo>();
|
||||
var tooltip = actor.TraitInfos<TooltipInfo>().First(Exts.IsTraitEnabled);
|
||||
var buildable = actor.TraitInfo<BuildableInfo>();
|
||||
var cost = actor.TraitInfo<ValuedInfo>().Cost;
|
||||
|
||||
@@ -115,7 +115,11 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
{
|
||||
ActorInfo ai;
|
||||
if (rules.Actors.TryGetValue(a.ToLowerInvariant(), out ai) && ai.HasTraitInfo<TooltipInfo>())
|
||||
return ai.TraitInfo<TooltipInfo>().Name;
|
||||
{
|
||||
var actorTooltip = ai.TraitInfos<TooltipInfo>().FirstOrDefault(Exts.IsTraitEnabled);
|
||||
if (actorTooltip != null)
|
||||
return actorTooltip.Name;
|
||||
}
|
||||
|
||||
return a;
|
||||
}
|
||||
|
||||
@@ -191,9 +191,13 @@ namespace OpenRA.Mods.Common.Widgets
|
||||
|
||||
if (underCursor != null)
|
||||
{
|
||||
ActorTooltip = underCursor.TraitsImplementing<ITooltip>().First();
|
||||
ActorTooltipExtra = underCursor.TraitsImplementing<IProvideTooltipInfo>().ToArray();
|
||||
TooltipType = WorldTooltipType.Actor;
|
||||
ActorTooltip = underCursor.TraitsImplementing<ITooltip>().FirstOrDefault(Exts.IsTraitEnabled);
|
||||
if (ActorTooltip != null)
|
||||
{
|
||||
ActorTooltipExtra = underCursor.TraitsImplementing<IProvideTooltipInfo>().ToArray();
|
||||
TooltipType = WorldTooltipType.Actor;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user