Introduce SoundType enum.

This commit is contained in:
Paul Chote
2016-12-10 17:38:44 +00:00
parent 28182ddc36
commit 9ddfdc45b3
48 changed files with 83 additions and 80 deletions

View File

@@ -59,7 +59,7 @@ namespace OpenRA.Mods.Common.Activities
if (!playedSound && helicopter.Info.TakeoffSound != null && self.IsAtGroundLevel())
{
Game.Sound.Play(helicopter.Info.TakeoffSound);
Game.Sound.Play(SoundType.World, helicopter.Info.TakeoffSound);
playedSound = true;
}

View File

@@ -42,7 +42,7 @@ namespace OpenRA.Mods.Common.Activities
if (!playedSound && helicopter.Info.LandingSound != null && !self.IsAtGroundLevel())
{
Game.Sound.Play(helicopter.Info.LandingSound);
Game.Sound.Play(SoundType.World, helicopter.Info.LandingSound);
playedSound = true;
}

View File

@@ -64,7 +64,7 @@ namespace OpenRA.Mods.Common.Activities
var sound = pool.Info.RearmSound;
if (sound != null)
Game.Sound.PlayToPlayer(self.Owner, sound, self.CenterPosition);
Game.Sound.PlayToPlayer(SoundType.World, self.Owner, sound, self.CenterPosition);
ammoPoolsReloadTimes[pool] = pool.Info.ReloadDelay;
}

View File

@@ -50,7 +50,7 @@ namespace OpenRA.Mods.Common.Activities
self.Dispose();
foreach (var s in Sounds)
Game.Sound.PlayToPlayer(self.Owner, s, self.CenterPosition);
Game.Sound.PlayToPlayer(SoundType.World, self.Owner, s, self.CenterPosition);
Game.Sound.PlayNotification(self.World.Map.Rules, self.Owner, "Speech", Notification, self.Owner.Faction.InternalName);

View File

@@ -60,7 +60,7 @@ namespace OpenRA.Mods.Common.Effects
pos = launchPos;
if (weapon.Report != null && weapon.Report.Any())
Game.Sound.Play(weapon.Report.Random(firedBy.World.SharedRandom), pos);
Game.Sound.Play(SoundType.World, weapon.Report.Random(firedBy.World.SharedRandom), pos);
if (skipAscent)
ticks = turn;

View File

@@ -52,7 +52,8 @@ namespace OpenRA.Mods.Common.Scripting
[Desc("Play a sound file")]
public void PlaySound(string file)
{
Game.Sound.Play(file);
// TODO: Investigate how scripts use this function, and think about exposing the UI vs World distinction if needed
Game.Sound.Play(SoundType.World, file);
}
[Desc("Play track defined in music.yaml or map.yaml, or keep track empty for playing a random song.")]

View File

@@ -245,7 +245,7 @@ namespace OpenRA.Mods.Common.Traits
self.World.Add(projectile);
if (args.Weapon.Report != null && args.Weapon.Report.Any())
Game.Sound.Play(args.Weapon.Report.Random(self.World.SharedRandom), self.CenterPosition);
Game.Sound.Play(SoundType.World, args.Weapon.Report.Random(self.World.SharedRandom), self.CenterPosition);
foreach (var na in self.TraitsImplementing<INotifyAttack>())
na.Attacking(self, target, this, barrel);

View File

@@ -100,7 +100,7 @@ namespace OpenRA.Mods.Common.Traits
notify.Charging(self, target);
if (!string.IsNullOrEmpty(attack.info.ChargeAudio))
Game.Sound.Play(attack.info.ChargeAudio, self.CenterPosition);
Game.Sound.Play(SoundType.World, attack.info.ChargeAudio, self.CenterPosition);
return ActivityUtils.SequenceActivities(new Wait(attack.info.InitialChargeDelay), new ChargeFire(attack, target), this);
}

View File

@@ -236,7 +236,7 @@ namespace OpenRA.Mods.Common.Traits
RemoveSmudges();
foreach (var s in Info.UndeploySounds)
Game.Sound.PlayToPlayer(self.Owner, s, self.CenterPosition);
Game.Sound.PlayToPlayer(SoundType.World, self.Owner, s, self.CenterPosition);
}
void INotifyTransform.OnTransform(Actor self) { }

View File

@@ -62,7 +62,7 @@ namespace OpenRA.Mods.Common.Traits
// Gate was fully open
if (Position == OpenPosition)
{
Game.Sound.Play(info.ClosingSound, self.CenterPosition);
Game.Sound.Play(SoundType.World, info.ClosingSound, self.CenterPosition);
self.World.ActorMap.AddInfluence(self, this);
}
@@ -72,7 +72,7 @@ namespace OpenRA.Mods.Common.Traits
{
// Gate was fully closed
if (Position == 0)
Game.Sound.Play(info.OpeningSound, self.CenterPosition);
Game.Sound.Play(SoundType.World, info.OpeningSound, self.CenterPosition);
Position++;

View File

@@ -148,7 +148,7 @@ namespace OpenRA.Mods.Common.Traits
cloakedToken = upgradeManager.GrantCondition(self, Info.CloakedCondition);
if (!self.TraitsImplementing<Cloak>().Any(a => a != this && a.Cloaked))
Game.Sound.Play(Info.CloakSound, self.CenterPosition);
Game.Sound.Play(SoundType.World, Info.CloakSound, self.CenterPosition);
}
else if (!isCloaked && wasCloaked)
{
@@ -156,7 +156,7 @@ namespace OpenRA.Mods.Common.Traits
cloakedToken = upgradeManager.RevokeCondition(self, cloakedToken);
if (!self.TraitsImplementing<Cloak>().Any(a => a != this && a.Cloaked))
Game.Sound.Play(Info.UncloakSound, self.CenterPosition);
Game.Sound.Play(SoundType.World, Info.UncloakSound, self.CenterPosition);
}
wasCloaked = isCloaked;

View File

@@ -73,7 +73,7 @@ namespace OpenRA.Mods.Common.Traits
public virtual void Activate(Actor collector)
{
Game.Sound.PlayToPlayer(collector.Owner, info.Notification);
Game.Sound.PlayToPlayer(SoundType.World, collector.Owner, info.Notification);
if (info.Effect != null)
collector.World.AddFrameEndTask(w => w.Add(new CrateEffect(collector, info.Effect, info.Palette)));

View File

@@ -56,7 +56,7 @@ namespace OpenRA.Mods.Common.Traits
if (!CrushableInner(crushClasses, crusher.Owner))
return;
Game.Sound.Play(info.CrushSound, crusher.CenterPosition);
Game.Sound.Play(SoundType.World, info.CrushSound, crusher.CenterPosition);
self.Kill(crusher);
}

View File

@@ -82,7 +82,7 @@ namespace OpenRA.Mods.Common.Traits
w.Add(pilot);
pilot.QueueActivity(new Parachute(pilot, cp));
});
Game.Sound.Play(info.ChuteSound, cp);
Game.Sound.Play(SoundType.World, info.ChuteSound, cp);
}
else
{

View File

@@ -88,7 +88,7 @@ namespace OpenRA.Mods.Common.Traits
return;
if (weapon.Report != null && weapon.Report.Any())
Game.Sound.Play(weapon.Report.Random(e.Attacker.World.SharedRandom), self.CenterPosition);
Game.Sound.Play(SoundType.World, weapon.Report.Random(e.Attacker.World.SharedRandom), self.CenterPosition);
if (info.Type == ExplosionType.Footprint && buildingInfo != null)
{

View File

@@ -88,7 +88,7 @@ namespace OpenRA.Mods.Common.Traits
w.Add(a);
a.QueueActivity(new Parachute(a, self.CenterPosition));
});
Game.Sound.Play(info.ChuteSound, self.CenterPosition);
Game.Sound.Play(SoundType.World, info.ChuteSound, self.CenterPosition);
}
static bool IsSuitableCell(Actor actorToDrop, CPos p)

View File

@@ -88,7 +88,7 @@ namespace OpenRA.Mods.Common.Traits
var onWater = info.WaterTerrainTypes.Contains(self.World.Map.GetTerrainInfo(cell).Type);
var sound = onWater ? info.WaterImpactSound : info.GroundImpactSound;
Game.Sound.Play(sound, self.CenterPosition);
Game.Sound.Play(SoundType.World, sound, self.CenterPosition);
var sequence = onWater ? info.WaterCorpseSequence : info.GroundCorpseSequence;
var palette = onWater ? info.WaterCorpsePalette : info.GroundCorpsePalette;

View File

@@ -86,7 +86,7 @@ namespace OpenRA.Mods.Common.Traits
if (playSounds)
foreach (var s in buildingInfo.BuildSounds)
Game.Sound.PlayToPlayer(order.Player, s, building.CenterPosition);
Game.Sound.PlayToPlayer(SoundType.World, order.Player, s, building.CenterPosition);
playSounds = false;
}
@@ -110,7 +110,7 @@ namespace OpenRA.Mods.Common.Traits
pluggable.EnablePlug(host, plugInfo.Type);
foreach (var s in buildingInfo.BuildSounds)
Game.Sound.PlayToPlayer(order.Player, s, host.CenterPosition);
Game.Sound.PlayToPlayer(SoundType.World, order.Player, s, host.CenterPosition);
}
else
{
@@ -126,7 +126,7 @@ namespace OpenRA.Mods.Common.Traits
});
foreach (var s in buildingInfo.BuildSounds)
Game.Sound.PlayToPlayer(order.Player, s, building.CenterPosition);
Game.Sound.PlayToPlayer(SoundType.World, order.Player, s, building.CenterPosition);
}
if (producer.Actor != null)

View File

@@ -86,7 +86,7 @@ namespace OpenRA.Mods.Common.Traits
cargo.Delivered(self);
self.World.AddFrameEndTask(ww => DoProduction(self, producee, exit, factionVariant));
Game.Sound.Play(info.ChuteSound, self.CenterPosition);
Game.Sound.Play(SoundType.World, info.ChuteSound, self.CenterPosition);
Game.Sound.PlayNotification(self.World.Map.Rules, self.Owner, "Speech", info.ReadyAudio, self.Owner.Faction.InternalName);
}));

View File

@@ -58,7 +58,7 @@ namespace OpenRA.Mods.Common.Traits
self.CancelActivity();
foreach (var s in info.SellSounds)
Game.Sound.PlayToPlayer(self.Owner, s, self.CenterPosition);
Game.Sound.PlayToPlayer(SoundType.UI, self.Owner, s, self.CenterPosition);
foreach (var ns in self.TraitsImplementing<INotifySold>())
ns.Selling(self);

View File

@@ -50,9 +50,9 @@ namespace OpenRA.Mods.Common.Traits.Sound
if (wasDisabled && Info.Interval <= 0)
{
if (self.OccupiesSpace != null)
currentSound = Game.Sound.PlayLooped(Info.SoundFile, self.CenterPosition);
currentSound = Game.Sound.PlayLooped(SoundType.World, Info.SoundFile, self.CenterPosition);
else
currentSound = Game.Sound.PlayLooped(Info.SoundFile);
currentSound = Game.Sound.PlayLooped(SoundType.World, Info.SoundFile);
}
wasDisabled = false;
@@ -66,9 +66,9 @@ namespace OpenRA.Mods.Common.Traits.Sound
interval = Info.Interval;
if (self.OccupiesSpace != null)
Game.Sound.Play(Info.SoundFile, self.CenterPosition);
Game.Sound.Play(SoundType.World, Info.SoundFile, self.CenterPosition);
else
Game.Sound.Play(Info.SoundFile);
Game.Sound.Play(SoundType.World, Info.SoundFile);
}
}
}

View File

@@ -43,7 +43,7 @@ namespace OpenRA.Mods.Common.Traits.Sound
void PlaySound(Actor self)
{
if (info.Sounds.Any())
Game.Sound.Play(info.Sounds.Random(self.World.SharedRandom), self.CenterPosition);
Game.Sound.Play(SoundType.World, info.Sounds.Random(self.World.SharedRandom), self.CenterPosition);
}
void INotifyAttack.Attacking(Actor self, Target target, Armament a, Barrel barrel)

View File

@@ -40,12 +40,12 @@ namespace OpenRA.Mods.Common.Traits.Sound
if (e.DamageState == DamageState.Dead)
{
var sound = info.DestroyedSounds.RandomOrDefault(rand);
Game.Sound.Play(sound, self.CenterPosition);
Game.Sound.Play(SoundType.World, sound, self.CenterPosition);
}
else if (e.DamageState >= DamageState.Heavy && e.PreviousDamageState < DamageState.Heavy)
{
var sound = info.DamagedSounds.RandomOrDefault(rand);
Game.Sound.Play(sound, self.CenterPosition);
Game.Sound.Play(SoundType.World, sound, self.CenterPosition);
}
}
}

View File

@@ -53,7 +53,7 @@ namespace OpenRA.Mods.Common.Traits
public override void SelectTarget(Actor self, string order, SupportPowerManager manager)
{
Game.Sound.PlayToPlayer(manager.Self.Owner, Info.SelectTargetSound);
Game.Sound.PlayToPlayer(SoundType.World, manager.Self.Owner, Info.SelectTargetSound);
self.World.OrderGenerator = new SelectUpgradeTarget(Self.World, order, manager, this);
}
@@ -65,7 +65,7 @@ namespace OpenRA.Mods.Common.Traits
if (wsb != null && wsb.DefaultAnimation.HasSequence(info.Sequence))
wsb.PlayCustomAnimation(self, info.Sequence, () => wsb.CancelCustomAnimation(self));
Game.Sound.Play(info.OnFireSound, self.World.Map.CenterOfCell(order.TargetLocation));
Game.Sound.Play(SoundType.World, info.OnFireSound, self.World.Map.CenterOfCell(order.TargetLocation));
foreach (var a in UnitsInRange(order.TargetLocation))
{

View File

@@ -50,7 +50,7 @@ namespace OpenRA.Mods.Common.Traits
{
var location = self.World.Map.CenterOfCell(order.TargetLocation);
Game.Sound.Play(info.DeploySound, location);
Game.Sound.Play(SoundType.World, info.DeploySound, location);
if (!string.IsNullOrEmpty(info.EffectSequence) && !string.IsNullOrEmpty(info.EffectPalette))
w.Add(new SpriteEffect(location, w, info.EffectImage, info.EffectSequence, info.EffectPalette));

View File

@@ -89,21 +89,21 @@ namespace OpenRA.Mods.Common.Traits
public virtual void Charging(Actor self, string key)
{
Game.Sound.PlayToPlayer(self.Owner, Info.BeginChargeSound);
Game.Sound.PlayToPlayer(SoundType.UI, self.Owner, Info.BeginChargeSound);
Game.Sound.PlayNotification(self.World.Map.Rules, self.Owner, "Speech",
Info.BeginChargeSpeechNotification, self.Owner.Faction.InternalName);
}
public virtual void Charged(Actor self, string key)
{
Game.Sound.PlayToPlayer(self.Owner, Info.EndChargeSound);
Game.Sound.PlayToPlayer(SoundType.UI, self.Owner, Info.EndChargeSound);
Game.Sound.PlayNotification(self.World.Map.Rules, self.Owner, "Speech",
Info.EndChargeSpeechNotification, self.Owner.Faction.InternalName);
}
public virtual void SelectTarget(Actor self, string order, SupportPowerManager manager)
{
Game.Sound.PlayToPlayer(manager.Self.Owner, Info.SelectTargetSound);
Game.Sound.PlayToPlayer(SoundType.UI, manager.Self.Owner, Info.SelectTargetSound);
Game.Sound.PlayNotification(self.World.Map.Rules, self.Owner, "Speech",
Info.SelectTargetSpeechNotification, self.Owner.Faction.InternalName);
self.World.OrderGenerator = new SelectGenericPowerTarget(order, manager, info.Cursor, MouseButton.Left);
@@ -125,7 +125,7 @@ namespace OpenRA.Mods.Common.Traits
{
var renderPlayer = Self.World.RenderPlayer;
var isAllied = Self.Owner.IsAlliedWith(renderPlayer);
Game.Sound.Play(isAllied ? Info.LaunchSound : Info.IncomingSound);
Game.Sound.Play(SoundType.UI, isAllied ? Info.LaunchSound : Info.IncomingSound);
// IsAlliedWith returns true if renderPlayer is null, so we are safe here.
var toPlayer = isAllied ? renderPlayer ?? Self.Owner : renderPlayer;

View File

@@ -85,7 +85,7 @@ namespace OpenRA.Mods.Common.Traits
self.World.Add(projectile);
if (args.Weapon.Report != null && args.Weapon.Report.Any())
Game.Sound.Play(args.Weapon.Report.Random(self.World.SharedRandom), self.CenterPosition);
Game.Sound.Play(SoundType.World, args.Weapon.Report.Random(self.World.SharedRandom), self.CenterPosition);
}
});
}

View File

@@ -103,7 +103,7 @@ namespace OpenRA.Mods.Common.Traits
// Only play the "Cannot deploy here" audio
// for non-queued orders
foreach (var s in info.NoTransformSounds)
Game.Sound.PlayToPlayer(self.Owner, s);
Game.Sound.PlayToPlayer(SoundType.World, self.Owner, s);
Game.Sound.PlayNotification(self.World.Map.Rules, self.Owner, "Speech", info.NoTransformNotification, self.Owner.Faction.InternalName);

View File

@@ -64,7 +64,7 @@ namespace OpenRA.Mods.Common.Traits
conditionToken = manager.GrantCondition(self, info.Condition);
var sound = info.EnabledSounds.RandomOrDefault(Game.CosmeticRandom);
Game.Sound.Play(sound, self.CenterPosition);
Game.Sound.Play(SoundType.World, sound, self.CenterPosition);
}
void INotifyDamageStateChanged.DamageStateChanged(Actor self, AttackInfo e)
@@ -80,7 +80,7 @@ namespace OpenRA.Mods.Common.Traits
conditionToken = manager.RevokeCondition(self, conditionToken);
var sound = info.DisabledSounds.RandomOrDefault(Game.CosmeticRandom);
Game.Sound.Play(sound, self.CenterPosition);
Game.Sound.Play(SoundType.World, sound, self.CenterPosition);
}
}
}

View File

@@ -204,7 +204,7 @@ namespace OpenRA.Mods.Common.Traits
return;
if (!string.IsNullOrEmpty(info.DeploySound))
Game.Sound.Play(info.DeploySound, self.CenterPosition);
Game.Sound.Play(SoundType.World, info.DeploySound, self.CenterPosition);
// Revoke upgrades that are used while undeployed.
if (!init)
@@ -227,7 +227,7 @@ namespace OpenRA.Mods.Common.Traits
return;
if (!string.IsNullOrEmpty(info.UndeploySound))
Game.Sound.Play(info.UndeploySound, self.CenterPosition);
Game.Sound.Play(SoundType.World, info.UndeploySound, self.CenterPosition);
if (!init)
OnUndeployStarted();

View File

@@ -81,7 +81,7 @@ namespace OpenRA.Mods.Common.Traits
if (cachedDisabled != disabled)
{
Game.Sound.Play(disabled ? info.DisableSound : info.EnableSound, self.CenterPosition);
Game.Sound.Play(SoundType.World, disabled ? info.DisableSound : info.EnableSound, self.CenterPosition);
desiredRange = disabled ? WDist.Zero : info.Range;
desiredVRange = disabled ? WDist.Zero : info.MaximumVerticalOffset;
cachedDisabled = disabled;

View File

@@ -47,7 +47,7 @@ namespace OpenRA.Mods.Common.Traits
var type = Info.VoiceSet.ToLowerInvariant();
var volume = Info.Volume;
return Game.Sound.PlayPredefined(self.World.Map.Rules, null, self, type, phrase, variant, true, WPos.Zero, volume, true);
return Game.Sound.PlayPredefined(SoundType.World, self.World.Map.Rules, null, self, type, phrase, variant, true, WPos.Zero, volume, true);
}
public bool PlayVoiceLocal(Actor self, string phrase, string variant, float volume)
@@ -59,7 +59,7 @@ namespace OpenRA.Mods.Common.Traits
return false;
var type = Info.VoiceSet.ToLowerInvariant();
return Game.Sound.PlayPredefined(self.World.Map.Rules, null, self, type, phrase, variant, false, self.CenterPosition, volume, true);
return Game.Sound.PlayPredefined(SoundType.World, self.World.Map.Rules, null, self, type, phrase, variant, false, self.CenterPosition, volume, true);
}
public bool HasVoice(Actor self, string voice)

View File

@@ -115,7 +115,7 @@ namespace OpenRA.Mods.Common.Warheads
var impactSound = ImpactSounds.RandomOrDefault(Game.CosmeticRandom);
if (impactSound != null)
Game.Sound.Play(impactSound, pos);
Game.Sound.Play(SoundType.World, impactSound, pos);
}
public bool IsValidImpact(WPos pos, Actor firedBy)

View File

@@ -87,7 +87,7 @@ namespace OpenRA.Mods.Common.Widgets
recentLines.Add(new ChatLine(from, text, Game.LocalTick + RemoveTime, c));
if (Notification != null)
Game.Sound.Play(Notification);
Game.Sound.Play(SoundType.UI, Notification);
while (recentLines.Count > LogLength)
recentLines.RemoveAt(0);

View File

@@ -218,14 +218,14 @@ namespace OpenRA.Mods.Common.Widgets
{
if (PickUpCompletedBuildingIcon(icon, item))
{
Game.Sound.Play(TabClick);
Game.Sound.Play(SoundType.UI, TabClick);
return true;
}
if (item != null && item.Paused)
{
// Resume a paused item
Game.Sound.Play(TabClick);
Game.Sound.Play(SoundType.UI, TabClick);
World.IssueOrder(Order.PauseProduction(CurrentQueue.Actor, icon.Name, false));
return true;
}
@@ -233,7 +233,7 @@ namespace OpenRA.Mods.Common.Widgets
if (CurrentQueue.BuildableItems().Any(a => a.Name == icon.Name))
{
// Queue a new item
Game.Sound.Play(TabClick);
Game.Sound.Play(SoundType.UI, TabClick);
Game.Sound.PlayNotification(World.Map.Rules, World.LocalPlayer, "Speech", CurrentQueue.Info.QueuedAudio, World.LocalPlayer.Faction.InternalName);
World.IssueOrder(Order.StartProduction(CurrentQueue.Actor, icon.Name, handleCount));
return true;
@@ -247,7 +247,7 @@ namespace OpenRA.Mods.Common.Widgets
if (item == null)
return false;
Game.Sound.Play(TabClick);
Game.Sound.Play(SoundType.UI, TabClick);
if (item.Paused || item.Done || item.TotalCost == item.RemainingCost)
{
@@ -271,7 +271,7 @@ namespace OpenRA.Mods.Common.Widgets
return false;
// Directly cancel, skipping "on-hold"
Game.Sound.Play(TabClick);
Game.Sound.Play(SoundType.UI, TabClick);
Game.Sound.PlayNotification(World.Map.Rules, World.LocalPlayer, "Speech", CurrentQueue.Info.CancelledAudio, World.LocalPlayer.Faction.InternalName);
World.IssueOrder(Order.CancelProduction(CurrentQueue.Actor, icon.Name, handleCount));
@@ -289,7 +289,7 @@ namespace OpenRA.Mods.Common.Widgets
: false;
if (!handled)
Game.Sound.Play(DisabledTabClick);
Game.Sound.Play(SoundType.UI, DisabledTabClick);
return true;
}

View File

@@ -333,7 +333,7 @@ namespace OpenRA.Mods.Common.Widgets
// Enable/Disable the radar
var enabled = IsEnabled();
if (enabled != cachedEnabled)
Game.Sound.Play(enabled ? RadarOnlineSound : RadarOfflineSound);
Game.Sound.Play(SoundType.UI, enabled ? RadarOnlineSound : RadarOfflineSound);
cachedEnabled = enabled;
if (enabled)

View File

@@ -115,7 +115,7 @@ namespace OpenRA.Mods.Common.Widgets
{
if (!clicked.Power.Active)
{
Game.Sound.PlayToPlayer(spm.Self.Owner, clicked.Power.Info.InsufficientPowerSound);
Game.Sound.PlayToPlayer(SoundType.UI, spm.Self.Owner, clicked.Power.Info.InsufficientPowerSound);
Game.Sound.PlayNotification(spm.Self.World.Map.Rules, spm.Self.Owner, "Speech",
clicked.Power.Info.InsufficientPowerSpeechNotification, spm.Self.Owner.Faction.InternalName);
}