Add support for non-overlapping sound notifications
This commit is contained in:
committed by
abcdefg30
parent
137d384304
commit
fa6ff32f65
@@ -33,11 +33,11 @@ namespace OpenRA.GameRules
|
|||||||
{
|
{
|
||||||
FieldLoader.Load(this, y);
|
FieldLoader.Load(this, y);
|
||||||
|
|
||||||
VoicePools = Exts.Lazy(() => Voices.ToDictionary(a => a.Key, a => new SoundPool(1f, a.Value)));
|
VoicePools = Exts.Lazy(() => Voices.ToDictionary(a => a.Key, a => new SoundPool(1f, false, a.Value)));
|
||||||
NotificationsPools = Exts.Lazy(() => ParseSoundPool(y, "Notifications"));
|
NotificationsPools = Exts.Lazy(() => ParseSoundPool(y, "Notifications"));
|
||||||
}
|
}
|
||||||
|
|
||||||
Dictionary<string, SoundPool> ParseSoundPool(MiniYaml y, string key)
|
static Dictionary<string, SoundPool> ParseSoundPool(MiniYaml y, string key)
|
||||||
{
|
{
|
||||||
var ret = new Dictionary<string, SoundPool>();
|
var ret = new Dictionary<string, SoundPool>();
|
||||||
var classifiction = y.Nodes.First(x => x.Key == key);
|
var classifiction = y.Nodes.First(x => x.Key == key);
|
||||||
@@ -48,8 +48,13 @@ namespace OpenRA.GameRules
|
|||||||
if (volumeModifierNode != null)
|
if (volumeModifierNode != null)
|
||||||
volumeModifier = FieldLoader.GetValue<float>(volumeModifierNode.Key, volumeModifierNode.Value.Value);
|
volumeModifier = FieldLoader.GetValue<float>(volumeModifierNode.Key, volumeModifierNode.Value.Value);
|
||||||
|
|
||||||
|
var allowInterrupt = false;
|
||||||
|
var allowInterruptNode = t.Value.Nodes.FirstOrDefault(x => x.Key == "AllowInterrupt");
|
||||||
|
if (allowInterruptNode != null)
|
||||||
|
allowInterrupt = FieldLoader.GetValue<bool>(allowInterruptNode.Key, allowInterruptNode.Value.Value);
|
||||||
|
|
||||||
var names = FieldLoader.GetValue<string[]>(t.Key, t.Value.Value);
|
var names = FieldLoader.GetValue<string[]>(t.Key, t.Value.Value);
|
||||||
var sp = new SoundPool(volumeModifier, names);
|
var sp = new SoundPool(volumeModifier, allowInterrupt, names);
|
||||||
ret.Add(t.Key, sp);
|
ret.Add(t.Key, sp);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,12 +65,14 @@ namespace OpenRA.GameRules
|
|||||||
public class SoundPool
|
public class SoundPool
|
||||||
{
|
{
|
||||||
public readonly float VolumeModifier;
|
public readonly float VolumeModifier;
|
||||||
|
public readonly bool AllowInterrupt;
|
||||||
readonly string[] clips;
|
readonly string[] clips;
|
||||||
readonly List<string> liveclips = new List<string>();
|
readonly List<string> liveclips = new List<string>();
|
||||||
|
|
||||||
public SoundPool(float volumeModifier, params string[] clips)
|
public SoundPool(float volumeModifier, bool allowInterrupt, params string[] clips)
|
||||||
{
|
{
|
||||||
VolumeModifier = volumeModifier;
|
VolumeModifier = volumeModifier;
|
||||||
|
AllowInterrupt = allowInterrupt;
|
||||||
this.clips = clips;
|
this.clips = clips;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ namespace OpenRA
|
|||||||
ISound video;
|
ISound video;
|
||||||
MusicInfo currentMusic;
|
MusicInfo currentMusic;
|
||||||
Dictionary<uint, ISound> currentSounds = new Dictionary<uint, ISound>();
|
Dictionary<uint, ISound> currentSounds = new Dictionary<uint, ISound>();
|
||||||
|
Dictionary<string, ISound> currentNotifications = new Dictionary<string, ISound>();
|
||||||
public bool DummyEngine { get; private set; }
|
public bool DummyEngine { get; private set; }
|
||||||
|
|
||||||
public Sound(IPlatform platform, SoundSettings soundSettings)
|
public Sound(IPlatform platform, SoundSettings soundSettings)
|
||||||
@@ -390,16 +391,29 @@ namespace OpenRA
|
|||||||
|
|
||||||
if (!string.IsNullOrEmpty(name) && (p == null || p == p.World.LocalPlayer))
|
if (!string.IsNullOrEmpty(name) && (p == null || p == p.World.LocalPlayer))
|
||||||
{
|
{
|
||||||
|
if (currentNotifications.ContainsKey(name) && !currentNotifications[name].Complete)
|
||||||
|
{
|
||||||
|
if (pool.AllowInterrupt)
|
||||||
|
soundEngine.StopSound(currentNotifications[name]);
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else if (currentSounds.ContainsKey(id) && !currentSounds[id].Complete)
|
||||||
|
{
|
||||||
|
if (pool.AllowInterrupt)
|
||||||
|
soundEngine.StopSound(currentSounds[id]);
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
var sound = soundEngine.Play2D(sounds[name],
|
var sound = soundEngine.Play2D(sounds[name],
|
||||||
false, relative, pos,
|
false, relative, pos,
|
||||||
InternalSoundVolume * volumeModifier * pool.VolumeModifier, attenuateVolume);
|
InternalSoundVolume * volumeModifier * pool.VolumeModifier, attenuateVolume);
|
||||||
if (id != 0)
|
|
||||||
{
|
|
||||||
if (currentSounds.ContainsKey(id))
|
|
||||||
soundEngine.StopSound(currentSounds[id]);
|
|
||||||
|
|
||||||
|
if (id != 0)
|
||||||
currentSounds[id] = sound;
|
currentSounds[id] = sound;
|
||||||
}
|
else
|
||||||
|
currentNotifications[name] = sound;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -54,6 +54,7 @@ Sounds:
|
|||||||
Notifications:
|
Notifications:
|
||||||
Appear: appear1
|
Appear: appear1
|
||||||
Beacon: bleep2
|
Beacon: bleep2
|
||||||
|
AllowInterrupt: true
|
||||||
Beepy2: beepy2
|
Beepy2: beepy2
|
||||||
Beepy3: beepy3
|
Beepy3: beepy3
|
||||||
Beepy6: beepy6
|
Beepy6: beepy6
|
||||||
@@ -61,8 +62,11 @@ Sounds:
|
|||||||
CashTickUp: tone15
|
CashTickUp: tone15
|
||||||
VolumeModifier: 0.33
|
VolumeModifier: 0.33
|
||||||
ChatLine: scold1
|
ChatLine: scold1
|
||||||
|
AllowInterrupt: true
|
||||||
ClickDisabledSound: scold2
|
ClickDisabledSound: scold2
|
||||||
|
AllowInterrupt: true
|
||||||
ClickSound: button
|
ClickSound: button
|
||||||
|
AllowInterrupt: true
|
||||||
Cloak: trans1
|
Cloak: trans1
|
||||||
Clock: clock1
|
Clock: clock1
|
||||||
Construction: constru2
|
Construction: constru2
|
||||||
|
|||||||
@@ -70,9 +70,14 @@ Sounds:
|
|||||||
CashTickDown: CASHTIK1
|
CashTickDown: CASHTIK1
|
||||||
LevelUp: SCORTIK1
|
LevelUp: SCORTIK1
|
||||||
ChatLine: CHAT1
|
ChatLine: CHAT1
|
||||||
|
AllowInterrupt: true
|
||||||
BuildPaletteOpen: BUTTON1
|
BuildPaletteOpen: BUTTON1
|
||||||
BuildPaletteClose: BUTTON1
|
BuildPaletteClose: BUTTON1
|
||||||
TabClick: SIDEBAR1
|
TabClick: SIDEBAR1
|
||||||
|
AllowInterrupt: true
|
||||||
ClickSound: BUTTON1
|
ClickSound: BUTTON1
|
||||||
|
AllowInterrupt: true
|
||||||
ClickDisabledSound: ENDLIST1
|
ClickDisabledSound: ENDLIST1
|
||||||
|
AllowInterrupt: true
|
||||||
Beacon: CHAT1
|
Beacon: CHAT1
|
||||||
|
AllowInterrupt: true
|
||||||
|
|||||||
@@ -126,9 +126,12 @@ Sounds:
|
|||||||
DisablePower: bleep11
|
DisablePower: bleep11
|
||||||
EnablePower: bleep12
|
EnablePower: bleep12
|
||||||
ChatLine: rabeep1
|
ChatLine: rabeep1
|
||||||
|
AllowInterrupt: true
|
||||||
ClickSound: ramenu1
|
ClickSound: ramenu1
|
||||||
|
AllowInterrupt: true
|
||||||
ClickDisabledSound:
|
ClickDisabledSound:
|
||||||
Beacon: beepslct
|
Beacon: beepslct
|
||||||
|
AllowInterrupt: true
|
||||||
AlertBuzzer: buzzy1
|
AlertBuzzer: buzzy1
|
||||||
AlertBleep: bleep6
|
AlertBleep: bleep6
|
||||||
BaseSetup: bleep9
|
BaseSetup: bleep9
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ Sounds:
|
|||||||
Notifications:
|
Notifications:
|
||||||
Bargraph: bargraph
|
Bargraph: bargraph
|
||||||
Beacon: message1
|
Beacon: message1
|
||||||
|
AllowInterrupt: true
|
||||||
Bestbox: bestbox
|
Bestbox: bestbox
|
||||||
Blip: blip
|
Blip: blip
|
||||||
BuildPaletteClose: emblem
|
BuildPaletteClose: emblem
|
||||||
@@ -13,8 +14,11 @@ Sounds:
|
|||||||
CashTickUp: credup1
|
CashTickUp: credup1
|
||||||
VolumeModifier: 0.33
|
VolumeModifier: 0.33
|
||||||
ChatLine: message1
|
ChatLine: message1
|
||||||
|
AllowInterrupt: true
|
||||||
ClickDisabledSound: wrong1
|
ClickDisabledSound: wrong1
|
||||||
|
AllowInterrupt: true
|
||||||
ClickSound: clicky1
|
ClickSound: clicky1
|
||||||
|
AllowInterrupt: true
|
||||||
GameForming: gamefrm1
|
GameForming: gamefrm1
|
||||||
Gdiclose: gdiclose
|
Gdiclose: gdiclose
|
||||||
Gdiopen: gdiopen
|
Gdiopen: gdiopen
|
||||||
|
|||||||
Reference in New Issue
Block a user