Expose common actor Inits in the map editor.

This commit is contained in:
Paul Chote
2018-12-08 18:41:12 +00:00
committed by reaperrr
parent f6768fe624
commit 4723e5ddb9
11 changed files with 369 additions and 79 deletions

View File

@@ -9,13 +9,14 @@
*/
#endregion
using System.Collections.Generic;
using System.Linq;
using OpenRA.Primitives;
using OpenRA.Traits;
namespace OpenRA.Mods.Common.Traits
{
public class HealthInfo : IHealthInfo, IRulesetLoaded
public class HealthInfo : IHealthInfo, IRulesetLoaded, IEditorActorOptions
{
[Desc("HitPoints")]
public readonly int HP = 0;
@@ -23,6 +24,9 @@ namespace OpenRA.Mods.Common.Traits
[Desc("Trigger interfaces such as AnnounceOnKill?")]
public readonly bool NotifyAppliedDamage = true;
[Desc("Display order for the health slider in the map editor")]
public readonly int EditorHealthDisplayOrder = 2;
public virtual object Create(ActorInitializer init) { return new Health(init, this); }
public void RulesetLoaded(Ruleset rules, ActorInfo ai)
@@ -32,6 +36,17 @@ namespace OpenRA.Mods.Common.Traits
}
int IHealthInfo.MaxHP { get { return HP; } }
IEnumerable<EditorActorOption> IEditorActorOptions.ActorOptions(ActorInfo ai, World world)
{
yield return new EditorActorSlider("Health", EditorHealthDisplayOrder, 0, 100, 5,
actor =>
{
var init = actor.Init<HealthInit>();
return init != null ? init.Value(world) : 100;
},
(actor, value) => actor.ReplaceInit(new HealthInit((int)value)));
}
}
public class Health : IHealth, ISync, ITick, INotifyCreated, INotifyOwnerChanged