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