Exemplo n.º 1
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();
        }