Merge pull request #8012 from reaperrr/voiceset
Extracted actor Voices from Selectable into own Voiced trait
This commit is contained in:
@@ -179,6 +179,7 @@
|
||||
<Compile Include="Traits\World\Shroud.cs" />
|
||||
<Compile Include="World.cs" />
|
||||
<Compile Include="WorldUtils.cs" />
|
||||
<Compile Include="VoiceExts.cs" />
|
||||
<Compile Include="Network\ReplayRecorderConnection.cs" />
|
||||
<Compile Include="Traits\DebugPauseState.cs" />
|
||||
<Compile Include="Network\UPnP.cs" />
|
||||
|
||||
@@ -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.HasTrait<IVoiced>());
|
||||
if (voicedActor != null)
|
||||
voicedActor.PlayVoice("Select");
|
||||
|
||||
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,32 +364,6 @@ namespace OpenRA
|
||||
return true;
|
||||
}
|
||||
|
||||
public static bool PlayVoice(string phrase, Actor voicedUnit, string variant)
|
||||
{
|
||||
if (voicedUnit == null || phrase == null)
|
||||
return false;
|
||||
|
||||
var mi = voicedUnit.Info.Traits.GetOrDefault<SelectableInfo>();
|
||||
if (mi == null || mi.Voice == null)
|
||||
return false;
|
||||
|
||||
var type = mi.Voice.ToLowerInvariant();
|
||||
return PlayPredefined(voicedUnit.World.Map.Rules, null, voicedUnit, type, phrase, variant, true, WPos.Zero, 1f, true);
|
||||
}
|
||||
|
||||
public static bool PlayVoiceLocal(string phrase, Actor voicedUnit, string variant, WPos pos, float volume)
|
||||
{
|
||||
if (voicedUnit == null || phrase == null)
|
||||
return false;
|
||||
|
||||
var mi = voicedUnit.Info.Traits.GetOrDefault<SelectableInfo>();
|
||||
if (mi == null || mi.Voice == null)
|
||||
return false;
|
||||
|
||||
var type = mi.Voice.ToLowerInvariant();
|
||||
return PlayPredefined(voicedUnit.World.Map.Rules, null, voicedUnit, type, phrase, variant, false, pos, volume, true);
|
||||
}
|
||||
|
||||
public static bool PlayNotification(Ruleset rules, Player player, string type, string notification, string variant)
|
||||
{
|
||||
if (rules == null)
|
||||
|
||||
@@ -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,14 @@ namespace OpenRA.Traits
|
||||
|
||||
public interface ISeedableResource { void Seed(Actor self); }
|
||||
|
||||
public interface IVoiced
|
||||
{
|
||||
string VoiceSet { get; }
|
||||
bool PlayVoice(Actor self, string phrase, string variant);
|
||||
bool PlayVoiceLocal(Actor self, string phrase, string variant, float volume);
|
||||
bool HasVoice(Actor self, string voice);
|
||||
}
|
||||
|
||||
public interface IDemolishableInfo { bool IsValidTarget(ActorInfo actorInfo, Actor saboteur); }
|
||||
public interface IDemolishable
|
||||
{
|
||||
|
||||
75
OpenRA.Game/VoiceExts.cs
Normal file
75
OpenRA.Game/VoiceExts.cs
Normal file
@@ -0,0 +1,75 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2015 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation. For more information,
|
||||
* see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA
|
||||
{
|
||||
public static class VoiceExts
|
||||
{
|
||||
public static void PlayVoice(this Actor self, string phrase)
|
||||
{
|
||||
if (phrase == null)
|
||||
return;
|
||||
|
||||
foreach (var voiced in self.TraitsImplementing<IVoiced>())
|
||||
{
|
||||
if (string.IsNullOrEmpty(voiced.VoiceSet))
|
||||
return;
|
||||
|
||||
voiced.PlayVoice(self, phrase, self.Owner.Country.Race);
|
||||
}
|
||||
}
|
||||
|
||||
public static void PlayVoiceLocal(this Actor self, string phrase, float volume)
|
||||
{
|
||||
if (phrase == null)
|
||||
return;
|
||||
|
||||
foreach (var voiced in self.TraitsImplementing<IVoiced>())
|
||||
{
|
||||
if (string.IsNullOrEmpty(voiced.VoiceSet))
|
||||
return;
|
||||
|
||||
voiced.PlayVoiceLocal(self, phrase, self.Owner.Country.Race, volume);
|
||||
}
|
||||
}
|
||||
|
||||
public static bool HasVoice(this Actor self, string voice)
|
||||
{
|
||||
return self.TraitsImplementing<IVoiced>().Any(x => x.HasVoice(self, voice));
|
||||
}
|
||||
|
||||
public static void PlayVoiceForOrders(this World w, Order[] orders)
|
||||
{
|
||||
// Find an actor with a phrase to say
|
||||
foreach (var o in orders)
|
||||
{
|
||||
if (o == null)
|
||||
continue;
|
||||
|
||||
var orderSubject = o.Subject;
|
||||
if (orderSubject.Destroyed)
|
||||
continue;
|
||||
|
||||
foreach (var voice in orderSubject.TraitsImplementing<IVoiced>())
|
||||
foreach (var v in orderSubject.TraitsImplementing<IOrderVoice>())
|
||||
{
|
||||
if (voice.PlayVoice(orderSubject, v.VoicePhraseForOrder(orderSubject, o),
|
||||
orderSubject.Owner.Country.Race))
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -42,44 +42,6 @@ namespace OpenRA
|
||||
}
|
||||
}
|
||||
|
||||
public static bool HasVoices(this Actor a)
|
||||
{
|
||||
var selectable = a.Info.Traits.GetOrDefault<SelectableInfo>();
|
||||
return selectable != null && selectable.Voice != null;
|
||||
}
|
||||
|
||||
public static bool HasVoice(this Actor a, string voice)
|
||||
{
|
||||
var v = GetVoices(a);
|
||||
return v != null && v.Voices.ContainsKey(voice);
|
||||
}
|
||||
|
||||
public static SoundInfo GetVoices(this Actor a)
|
||||
{
|
||||
var selectable = a.Info.Traits.GetOrDefault<SelectableInfo>();
|
||||
if (selectable == null) return null;
|
||||
var v = selectable.Voice;
|
||||
return (v == null) ? null : a.World.Map.Rules.Voices[v.ToLowerInvariant()];
|
||||
}
|
||||
|
||||
public static void PlayVoiceForOrders(this World w, Order[] orders)
|
||||
{
|
||||
// Find an actor with a phrase to say
|
||||
foreach (var o in orders)
|
||||
{
|
||||
if (o == null)
|
||||
continue;
|
||||
|
||||
if (o.Subject.Destroyed)
|
||||
continue;
|
||||
|
||||
foreach (var v in o.Subject.TraitsImplementing<IOrderVoice>())
|
||||
if (Sound.PlayVoice(v.VoicePhraseForOrder(o.Subject, o),
|
||||
o.Subject, o.Subject.Owner.Country.Race))
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public static void DoTimed<T>(this IEnumerable<T> e, Action<T> a, string text)
|
||||
{
|
||||
// Note - manual enumeration here for performance due to high call volume.
|
||||
|
||||
Reference in New Issue
Block a user