check voice actor references

This commit is contained in:
Matthias Mailänder
2015-06-20 12:09:58 +02:00
parent 264a63e58c
commit 50e5e9df24
52 changed files with 390 additions and 81 deletions

View File

@@ -57,9 +57,21 @@ namespace OpenRA
}
}
var voicedActor = actors.FirstOrDefault(a => a.Owner == world.LocalPlayer && a.IsInWorld && a.HasTrait<IVoiced>());
if (voicedActor != null)
voicedActor.PlayVoice("Select");
// Play the selection voice from one of the selected actors
// TODO: This probably should only be considering the newly selected actors
// TODO: Ship this into an INotifySelection trait to remove the engine dependency on Selectable
foreach (var actor in actors)
{
if (actor.Owner != world.LocalPlayer || !actor.IsInWorld)
continue;
var selectable = actor.Info.Traits.GetOrDefault<SelectableInfo>();
if (selectable == null || !actor.HasVoice(selectable.Voice))
continue;
actor.PlayVoice(selectable.Voice);
break;
}
foreach (var a in newSelection)
foreach (var sel in a.TraitsImplementing<INotifySelected>())

View File

@@ -324,12 +324,6 @@ namespace OpenRA
if (voicedActor != null)
{
if (!rules.VoicePools.Value.ContainsKey("Attack"))
rules.VoicePools.Value.Add("Attack", rules.VoicePools.Value["Move"]);
if (!rules.VoicePools.Value.ContainsKey("AttackMove"))
rules.VoicePools.Value.Add("AttackMove", rules.VoicePools.Value["Move"]);
if (!rules.VoicePools.Value.ContainsKey(definition))
throw new InvalidOperationException("Can't find {0} in voice pool.".F(definition));

View File

@@ -20,6 +20,9 @@ namespace OpenRA.Traits
[AttributeUsage(AttributeTargets.Field)]
public sealed class WeaponReferenceAttribute : Attribute { }
[AttributeUsage(AttributeTargets.Field)]
public sealed class VoiceSetReferenceAttribute : Attribute { }
[AttributeUsage(AttributeTargets.Field)]
public sealed class VoiceReferenceAttribute : Attribute { }
}

View File

@@ -22,6 +22,8 @@ namespace OpenRA.Traits
+ "Defaults to the actor name when not defined or inherited.")]
public readonly string Class = null;
[VoiceReference] public readonly string Voice = "Select";
public object Create(ActorInitializer init) { return new Selectable(init.Self, this); }
}
@@ -29,9 +31,12 @@ namespace OpenRA.Traits
{
public readonly string Class = null;
public SelectableInfo Info;
public Selectable(Actor self, SelectableInfo info)
{
Class = string.IsNullOrEmpty(info.Class) ? self.Info.Name : info.Class;
Info = info;
}
}
}