Extract actor voice set into Voiced trait
This commit is contained in:
@@ -57,9 +57,9 @@ namespace OpenRA
|
||||
}
|
||||
}
|
||||
|
||||
var voicedUnit = actors.FirstOrDefault(a => a.Owner == world.LocalPlayer && a.IsInWorld && a.HasVoices());
|
||||
if (voicedUnit != null)
|
||||
Sound.PlayVoice("Select", voicedUnit, voicedUnit.Owner.Country.Race);
|
||||
var voicedActor = actors.FirstOrDefault(a => a.Owner == world.LocalPlayer && a.IsInWorld && a.HasVoices());
|
||||
if (voicedActor != null)
|
||||
Sound.PlayVoice("Select", voicedActor, voicedActor.Owner.Country.Race);
|
||||
|
||||
foreach (var a in newSelection)
|
||||
foreach (var sel in a.TraitsImplementing<INotifySelected>())
|
||||
|
||||
@@ -300,7 +300,7 @@ namespace OpenRA
|
||||
}
|
||||
|
||||
// Returns true if played successfully
|
||||
public static bool PlayPredefined(Ruleset ruleset, Player p, Actor voicedUnit, string type, string definition, string variant,
|
||||
public static bool PlayPredefined(Ruleset ruleset, Player p, Actor voicedActor, string type, string definition, string variant,
|
||||
bool relative, WPos pos, float volumeModifier, bool attenuateVolume)
|
||||
{
|
||||
if (ruleset == null)
|
||||
@@ -312,17 +312,17 @@ namespace OpenRA
|
||||
if (ruleset.Voices == null || ruleset.Notifications == null)
|
||||
return false;
|
||||
|
||||
var rules = (voicedUnit != null) ? ruleset.Voices[type] : ruleset.Notifications[type];
|
||||
var rules = (voicedActor != null) ? ruleset.Voices[type] : ruleset.Notifications[type];
|
||||
if (rules == null)
|
||||
return false;
|
||||
|
||||
var id = voicedUnit != null ? voicedUnit.ActorID : 0;
|
||||
var id = voicedActor != null ? voicedActor.ActorID : 0;
|
||||
|
||||
string clip;
|
||||
var suffix = rules.DefaultVariant;
|
||||
var prefix = rules.DefaultPrefix;
|
||||
|
||||
if (voicedUnit != null)
|
||||
if (voicedActor != null)
|
||||
{
|
||||
if (!rules.VoicePools.Value.ContainsKey("Attack"))
|
||||
rules.VoicePools.Value.Add("Attack", rules.VoicePools.Value["Move"]);
|
||||
@@ -364,30 +364,30 @@ namespace OpenRA
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool PlayVoice(string phrase, Actor voicedUnit, string variant)
|
||||
public static bool PlayVoice(string phrase, Actor voicedActor, string variant)
|
||||
{
|
||||
if (voicedUnit == null || phrase == null)
|
||||
if (voicedActor == null || phrase == null)
|
||||
return false;
|
||||
|
||||
var mi = voicedUnit.Info.Traits.GetOrDefault<SelectableInfo>();
|
||||
if (mi == null || mi.Voice == null)
|
||||
var mi = voicedActor.TraitOrDefault<IVoiced>();
|
||||
if (mi == null || mi.VoiceSet == null)
|
||||
return false;
|
||||
|
||||
var type = mi.Voice.ToLowerInvariant();
|
||||
return PlayPredefined(voicedUnit.World.Map.Rules, null, voicedUnit, type, phrase, variant, true, WPos.Zero, 1f, true);
|
||||
var type = mi.VoiceSet.ToLowerInvariant();
|
||||
return PlayPredefined(voicedActor.World.Map.Rules, null, voicedActor, type, phrase, variant, true, WPos.Zero, 1f, true);
|
||||
}
|
||||
|
||||
public static bool PlayVoiceLocal(string phrase, Actor voicedUnit, string variant, WPos pos, float volume)
|
||||
public static bool PlayVoiceLocal(string phrase, Actor voicedActor, string variant, WPos pos, float volume)
|
||||
{
|
||||
if (voicedUnit == null || phrase == null)
|
||||
if (voicedActor == null || phrase == null)
|
||||
return false;
|
||||
|
||||
var mi = voicedUnit.Info.Traits.GetOrDefault<SelectableInfo>();
|
||||
if (mi == null || mi.Voice == null)
|
||||
var mi = voicedActor.TraitOrDefault<IVoiced>();
|
||||
if (mi == null || mi.VoiceSet == null)
|
||||
return false;
|
||||
|
||||
var type = mi.Voice.ToLowerInvariant();
|
||||
return PlayPredefined(voicedUnit.World.Map.Rules, null, voicedUnit, type, phrase, variant, false, pos, volume, true);
|
||||
var type = mi.VoiceSet.ToLowerInvariant();
|
||||
return PlayPredefined(voicedActor.World.Map.Rules, null, voicedActor, type, phrase, variant, false, pos, volume, true);
|
||||
}
|
||||
|
||||
public static bool PlayNotification(Ruleset rules, Player player, string type, string notification, string variant)
|
||||
|
||||
@@ -20,7 +20,6 @@ namespace OpenRA.Traits
|
||||
public readonly bool Selectable = true;
|
||||
public readonly int Priority = 10;
|
||||
public readonly int[] Bounds = null;
|
||||
[VoiceReference] public readonly string Voice = null;
|
||||
|
||||
public object Create(ActorInitializer init) { return new Selectable(init.Self, this); }
|
||||
}
|
||||
|
||||
@@ -109,6 +109,7 @@ namespace OpenRA.Traits
|
||||
|
||||
public interface ISeedableResource { void Seed(Actor self); }
|
||||
|
||||
public interface IVoiced { string VoiceSet { get; } }
|
||||
public interface IDemolishableInfo { bool IsValidTarget(ActorInfo actorInfo, Actor saboteur); }
|
||||
public interface IDemolishable
|
||||
{
|
||||
|
||||
@@ -44,8 +44,8 @@ namespace OpenRA
|
||||
|
||||
public static bool HasVoices(this Actor a)
|
||||
{
|
||||
var selectable = a.Info.Traits.GetOrDefault<SelectableInfo>();
|
||||
return selectable != null && selectable.Voice != null;
|
||||
var voice = a.TraitOrDefault<IVoiced>();
|
||||
return voice != null && voice.VoiceSet != null;
|
||||
}
|
||||
|
||||
public static bool HasVoice(this Actor a, string voice)
|
||||
@@ -56,9 +56,11 @@ namespace OpenRA
|
||||
|
||||
public static SoundInfo GetVoices(this Actor a)
|
||||
{
|
||||
var selectable = a.Info.Traits.GetOrDefault<SelectableInfo>();
|
||||
if (selectable == null) return null;
|
||||
var v = selectable.Voice;
|
||||
var voiced = a.TraitOrDefault<IVoiced>();
|
||||
if (voiced == null)
|
||||
return null;
|
||||
|
||||
var v = voiced.VoiceSet;
|
||||
return (v == null) ? null : a.World.Map.Rules.Voices[v.ToLowerInvariant()];
|
||||
}
|
||||
|
||||
@@ -73,6 +75,9 @@ namespace OpenRA
|
||||
if (o.Subject.Destroyed)
|
||||
continue;
|
||||
|
||||
if (!o.Subject.HasVoices())
|
||||
continue;
|
||||
|
||||
foreach (var v in o.Subject.TraitsImplementing<IOrderVoice>())
|
||||
if (Sound.PlayVoice(v.VoicePhraseForOrder(o.Subject, o),
|
||||
o.Subject, o.Subject.Owner.Country.Race))
|
||||
|
||||
Reference in New Issue
Block a user