|
| 1 | +using DotRPG.Objects; |
| 2 | +using Microsoft.Xna.Framework.Audio; |
| 3 | +using System; |
| 4 | +using System.Collections.Generic; |
| 5 | +using System.Text; |
| 6 | + |
| 7 | +namespace DotRPG.Behavior.Management |
| 8 | +{ |
| 9 | + public class SoundManager : IDisposable |
| 10 | + { |
| 11 | + protected ResourceHeap Resources; |
| 12 | + Dictionary<String, SoundEffectInstance> PlayedSounds = new Dictionary<string, SoundEffectInstance>(); |
| 13 | + |
| 14 | + public SoundManager(ResourceHeap resources) |
| 15 | + { |
| 16 | + Resources = resources; |
| 17 | + } |
| 18 | + |
| 19 | + public void PlayLocal(String ID) |
| 20 | + { |
| 21 | + Resources.Sounds[ID].Play(); |
| 22 | + } |
| 23 | + |
| 24 | + public void BufferLocal(String ID, String playID) |
| 25 | + { |
| 26 | + PlayedSounds.Add(playID, Resources.Sounds[ID].CreateInstance()); |
| 27 | + } |
| 28 | + |
| 29 | + public void BufferGlobal(String ID, String playID) |
| 30 | + { |
| 31 | + PlayedSounds.Add(playID, Resources.Global.Sounds[ID].CreateInstance()); |
| 32 | + } |
| 33 | + |
| 34 | + public void PlayLocal(String ID, Single volume, Single pitch, Single pan) |
| 35 | + { |
| 36 | + Resources.Sounds[ID].Play(volume, pitch, pan); |
| 37 | + } |
| 38 | + |
| 39 | + public void PlayGlobal(String ID) |
| 40 | + { |
| 41 | + Resources.Global.Sounds[ID].Play(); |
| 42 | + } |
| 43 | + |
| 44 | + public void PlayGlobal(String ID, Single volume, Single pitch, Single pan) |
| 45 | + { |
| 46 | + Resources.Global.Sounds[ID].Play(volume, pitch, pan); |
| 47 | + } |
| 48 | + |
| 49 | + public void Play(String ID) |
| 50 | + { |
| 51 | + PlayedSounds[ID].Play(); |
| 52 | + } |
| 53 | + |
| 54 | + public void SetLooped(String ID, Boolean looped) |
| 55 | + { |
| 56 | + PlayedSounds[ID].IsLooped = looped; |
| 57 | + } |
| 58 | + |
| 59 | + public void SetParameters(String ID, Single volume, Single pitch, Single pan) |
| 60 | + { |
| 61 | + PlayedSounds[ID].Volume = volume; |
| 62 | + PlayedSounds[ID].Pitch = pitch; |
| 63 | + PlayedSounds[ID].Pan = pan; |
| 64 | + } |
| 65 | + |
| 66 | + public void Stop(String ID) |
| 67 | + { |
| 68 | + PlayedSounds[ID].Stop(); |
| 69 | + } |
| 70 | + |
| 71 | + public void Unbuffer(String ID) |
| 72 | + { |
| 73 | + PlayedSounds[ID].Stop(); |
| 74 | + PlayedSounds.Remove(ID); |
| 75 | + } |
| 76 | + |
| 77 | + public void StopAll() |
| 78 | + { |
| 79 | + foreach (String x in PlayedSounds.Keys) |
| 80 | + { |
| 81 | + Stop(x); |
| 82 | + } |
| 83 | + } |
| 84 | + |
| 85 | + public void UnbufferAll() |
| 86 | + { |
| 87 | + foreach (String x in PlayedSounds.Keys) |
| 88 | + { |
| 89 | + Unbuffer(x); |
| 90 | + } |
| 91 | + } |
| 92 | + |
| 93 | + public void Dispose() |
| 94 | + { |
| 95 | + UnbufferAll(); |
| 96 | + } |
| 97 | + } |
| 98 | +} |
0 commit comments