Added TooltipName as an actor Lua property

This commit is contained in:
Curtis Shmyr
2019-10-01 19:01:45 -06:00
committed by abcdefg30
parent b1571ad17a
commit f037436536

View File

@@ -9,6 +9,7 @@
*/ */
#endregion #endregion
using System.Linq;
using Eluant; using Eluant;
using OpenRA.Mods.Common.Activities; using OpenRA.Mods.Common.Activities;
using OpenRA.Mods.Common.Effects; using OpenRA.Mods.Common.Effects;
@@ -103,6 +104,7 @@ namespace OpenRA.Mods.Common.Scripting
readonly IFacing facing; readonly IFacing facing;
readonly AutoTarget autotarget; readonly AutoTarget autotarget;
readonly ScriptTags scriptTags; readonly ScriptTags scriptTags;
readonly Tooltip[] tooltips;
public GeneralProperties(ScriptContext context, Actor self) public GeneralProperties(ScriptContext context, Actor self)
: base(context, self) : base(context, self)
@@ -110,6 +112,7 @@ namespace OpenRA.Mods.Common.Scripting
facing = self.TraitOrDefault<IFacing>(); facing = self.TraitOrDefault<IFacing>();
autotarget = self.TraitOrDefault<AutoTarget>(); autotarget = self.TraitOrDefault<AutoTarget>();
scriptTags = self.TraitOrDefault<ScriptTags>(); scriptTags = self.TraitOrDefault<ScriptTags>();
tooltips = self.TraitsImplementing<Tooltip>().ToArray();
} }
[Desc("The actor position in cell coordinates.")] [Desc("The actor position in cell coordinates.")]
@@ -189,6 +192,19 @@ namespace OpenRA.Mods.Common.Scripting
} }
} }
[Desc("The actor's tooltip name. Returns nil if the actor has no tooltip.")]
public string TooltipName
{
get
{
var tooltip = tooltips.FirstEnabledTraitOrDefault();
if (tooltip == null)
return null;
return tooltip.Info.Name;
}
}
[Desc("Specifies whether or not the actor supports 'tags'.")] [Desc("Specifies whether or not the actor supports 'tags'.")]
public bool IsTaggable { get { return scriptTags != null; } } public bool IsTaggable { get { return scriptTags != null; } }