Example #1
0
 private void _copyFrom(EOSoundManager other)
 {
     //shallow copy is intended
     m_sounds       = other.m_sounds;
     m_guitarSounds = other.m_guitarSounds;
     m_harpSounds   = other.m_harpSounds;
     m_music        = other.m_music;
 }
Example #2
0
        public EOSoundManager()
        {
            lock (_construction_locker_)
            {
                if (inst != null)
                {
                    _copyFrom(inst);
                    return;
                }

                string[] soundFiles = Directory.GetFiles(SFX_DIR, "*.wav");
                Array.Sort(soundFiles);

                string[] musicFiles = Directory.GetFiles(MFX_DIR, "*.mid");
                Array.Sort(musicFiles);

                m_sounds       = new List <SoundInfo>(81);
                m_guitarSounds = new List <SoundInfo>(36);
                m_harpSounds   = new List <SoundInfo>(36);
                m_music        = new List <Uri>(musicFiles.Length);

                foreach (string sfx in soundFiles)
                {
                    _correctTheFileLength(sfx);

                    using (FileStream fs = new FileStream(sfx, FileMode.Open, FileAccess.Read, FileShare.Read))
                    {
                        //Note: this MAY throw InvalidOperationException if the file is invalid. However, _correctTheFileLength fixes
                        //	this for the original sfx files.
                        SoundEffect nextEffect = SoundEffect.FromStream(fs);

                        if (sfx.ToLower().Contains("gui"))
                        {
                            m_guitarSounds.Add(nextEffect == null ? null : new SoundInfo(nextEffect));
                        }
                        else if (sfx.ToLower().Contains("har"))
                        {
                            m_harpSounds.Add(nextEffect == null ? null : new SoundInfo(nextEffect));
                        }
                        else
                        {
                            m_sounds.Add(nextEffect == null ? null : new SoundInfo(nextEffect));
                        }
                    }
                }

                m_songPlayer             = new System.Windows.Media.MediaPlayer();
                m_dispatcher             = Dispatcher.CurrentDispatcher;
                m_songPlayer.MediaEnded += (o, e) => m_songPlayer.Position = new TimeSpan(0);

                foreach (string mfx in musicFiles)
                {
                    m_music.Add(new Uri(mfx, UriKind.Relative));
                }

                inst = this;
            }
        }
Example #3
0
 private void _copyFrom(EOSoundManager other)
 {
     //shallow copy is intended
     m_sounds = other.m_sounds;
     m_guitarSounds = other.m_guitarSounds;
     m_harpSounds = other.m_harpSounds;
     m_music = other.m_music;
 }
Example #4
0
        public EOSoundManager()
        {
            lock (_construction_locker_)
            {
                if (inst != null)
                {
                    _copyFrom(inst);
                    return;
                }

                string[] soundFiles = Directory.GetFiles(SFX_DIR, "*.wav");
                Array.Sort(soundFiles);

                string[] musicFiles = Directory.GetFiles(MFX_DIR, "*.mid");
                Array.Sort(musicFiles);

                m_sounds = new List<SoundInfo>(81);
                m_guitarSounds = new List<SoundInfo>(36);
                m_harpSounds = new List<SoundInfo>(36);
                m_music = new List<Uri>(musicFiles.Length);

                foreach (string sfx in soundFiles)
                {
                    _correctTheFileLength(sfx);

                    using (FileStream fs = new FileStream(sfx, FileMode.Open, FileAccess.Read, FileShare.Read))
                    {
                        //Note: this MAY throw InvalidOperationException if the file is invalid. However, _correctTheFileLength fixes
                        //	this for the original sfx files.
                        SoundEffect nextEffect = SoundEffect.FromStream(fs);

                        if (sfx.ToLower().Contains("gui"))
                            m_guitarSounds.Add(nextEffect == null ? null : new SoundInfo(nextEffect));
                        else if (sfx.ToLower().Contains("har"))
                            m_harpSounds.Add(nextEffect == null ? null : new SoundInfo(nextEffect));
                        else
                            m_sounds.Add(nextEffect == null ? null : new SoundInfo(nextEffect));
                    }
                }

                m_songPlayer = new System.Windows.Media.MediaPlayer();
                m_dispatcher = Dispatcher.CurrentDispatcher;
                m_songPlayer.MediaEnded += (o, e) => m_songPlayer.Position = new TimeSpan(0);

                foreach (string mfx in musicFiles)
                    m_music.Add(new Uri(mfx, UriKind.Relative));

                inst = this;
            }
        }
Example #5
0
        protected override void Initialize()
        {
            try
            {
                //yup. class named the same as a namespace. #whut #rekt
                XNAControls.XNAControls.Initialize(this);
            }
            catch (ArgumentNullException ex)
            {
                MessageBox.Show("Something super weird happened: " + ex.Message);
                Exit();
                return;
            }

            IsMouseVisible = true;
            Dispatcher     = new KeyboardDispatcher(Window);
            ResetPeopleIndices();

            try
            {
                GFXLoader.Initialize(GraphicsDevice);
                World w = World.Instance;                 //set up the world
                w.Init();

                host = World.Instance.Host;
                port = World.Instance.Port;
            }
            catch (WorldLoadException wle)             //could be thrown from World's constructor
            {
                MessageBox.Show(wle.Message, "Error");
                Exit();
                return;
            }
            catch (ConfigStringLoadException csle)
            {
                host = World.Instance.Host;
                port = World.Instance.Port;
                switch (csle.WhichString)
                {
                case ConfigStrings.Host:
                    MessageBox.Show(
                        string.Format("There was an error loading the host/port from the config file. Defaults will be used: {0}:{1}",
                                      host, port),
                        "Config Load Failed",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Warning);
                    break;

                case ConfigStrings.Port:
                    MessageBox.Show(
                        string.Format("There was an error loading the port from the config file. Default will be used: {0}:{1}",
                                      host, port),
                        "Config Load Failed",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Warning);
                    break;
                }
            }
            catch (ArgumentException ex)             //could be thrown from GFXLoader.Initialize
            {
                MessageBox.Show("Error initializing GFXLoader: " + ex.Message, "Error");
                Exit();
                return;
            }

            if (World.Instance.EIF != null && World.Instance.EIF.Version == 0)
            {
                MessageBox.Show("The item pub file you are using is using an older format of the EIF specification. Some features may not work properly. Run the file through a batch processor or use updated pub files.", "Warning");
            }

            GFXTypes curValue = 0;

            try
            {
                Array values = Enum.GetValues(typeof(GFXTypes));
                foreach (GFXTypes value in values)
                {
                    curValue = value;
                    //check for GFX files. Each file has a GFX 1.
                    using (Texture2D throwAway = GFXLoader.TextureFromResource(value, -99))
                    {
                        throwAway.Name = "";                         //no-op to keep resharper happy
                    }
                }
            }
            catch
            {
                MessageBox.Show(string.Format("There was an error loading GFX{0:000}.EGF : {1}. Place all .GFX files in .\\gfx\\", (int)curValue, curValue.ToString()), "Error");
                Exit();
                return;
            }

            try
            {
                SoundManager = new EOSoundManager();
            }
            catch
            {
                MessageBox.Show(string.Format("There was an error initializing the sound manager."), "Error");
                Exit();
                return;
            }

            if (World.Instance.MusicEnabled)
            {
                SoundManager.PlayBackgroundMusic(1);                 //mfx001 == main menu theme
            }

            base.Initialize();
        }
Example #6
0
		protected override void Initialize()
		{
			try
			{
				//yup. class named the same as a namespace. #whut #rekt
				XNAControls.XNAControls.Initialize(this);
			}
			catch (ArgumentNullException ex)
			{
				MessageBox.Show("Something super weird happened: " + ex.Message);
				Exit();
				return;
			}

			IsMouseVisible = true;
			Dispatcher = new KeyboardDispatcher(Window);
			ResetPeopleIndices();

			try
			{
				GFXLoader.Initialize(GraphicsDevice);
				World w = World.Instance; //set up the world
				w.Init();

				host = World.Instance.Host;
				port = World.Instance.Port;
			}
			catch (WorldLoadException wle) //could be thrown from World's constructor
			{
				MessageBox.Show(wle.Message, "Error");
				Exit();
				return;
			}
			catch (ConfigStringLoadException csle)
			{
				host = World.Instance.Host;
				port = World.Instance.Port;
				switch (csle.WhichString)
				{
					case ConfigStrings.Host:
						MessageBox.Show(
							string.Format("There was an error loading the host/port from the config file. Defaults will be used: {0}:{1}",
								host, port),
							"Config Load Failed",
							MessageBoxButtons.OK,
							MessageBoxIcon.Warning);
						break;
					case ConfigStrings.Port:
						MessageBox.Show(
							string.Format("There was an error loading the port from the config file. Default will be used: {0}:{1}",
								host, port),
							"Config Load Failed",
							MessageBoxButtons.OK,
							MessageBoxIcon.Warning);
						break;
				}
			}
			catch (ArgumentException ex) //could be thrown from GFXLoader.Initialize
			{
				MessageBox.Show("Error initializing GFXLoader: " + ex.Message, "Error");
				Exit();
				return;
			}

			if(World.Instance.EIF != null && World.Instance.EIF.Version == 0)
			{
				MessageBox.Show("The item pub file you are using is using an older format of the EIF specification. Some features may not work properly. Run the file through a batch processor or use updated pub files.", "Warning");
			}

			GFXTypes curValue = 0;
			try
			{
				Array values = Enum.GetValues(typeof(GFXTypes));
				foreach (GFXTypes value in values)
				{
					curValue = value;
					//check for GFX files. Each file has a GFX 1.
					using (Texture2D throwAway = GFXLoader.TextureFromResource(value, -99))
					{
						throwAway.Name = ""; //no-op to keep resharper happy
					}
				}
			}
			catch
			{
				MessageBox.Show(string.Format("There was an error loading GFX{0:000}.EGF : {1}. Place all .GFX files in .\\gfx\\", (int)curValue, curValue.ToString()), "Error");
				Exit();
				return;
			}

			try
			{
				SoundManager = new EOSoundManager();
			}
			catch
			{
				MessageBox.Show(string.Format("There was an error initializing the sound manager."), "Error");
				Exit();
				return;
			}

			if (World.Instance.MusicEnabled)
			{
				SoundManager.PlayBackgroundMusic(1); //mfx001 == main menu theme
			}
			
			base.Initialize();
		}