/// <summary>
        /// The constructor is private: loading screens should
        /// be activated via the static Load method instead.
        /// </summary>
        private LoadingScreen(ScreenManager screenManager, bool loadingIsSlow,
            GameScreen[] screensToLoad)
            : base(screenManager)
        {
            this.loadingIsSlow = loadingIsSlow;
            this.screensToLoad = screensToLoad;

            TransitionOnTime = TimeSpan.FromSeconds(0.5);
        }
        /// <summary>
        /// Adds a new screen to the screen manager.
        /// </summary>
        public void AddScreen(GameScreen screen, PlayerIndex? controllingPlayer)
        {
            screen.ControllingPlayer = controllingPlayer;
            //screen.ScreenManager = this;
            screen.IsExiting = false;
            screen.mSound = ((SuperXbloxGame)(Game)).mSound;
            screen.Game = (SuperXbloxGame)this.Game;
            // If we have a graphics device, tell the screen to load content.
              //  if (isInitialized)
            {
                screen.LoadContent();
            }

            screens.Add(screen);
        }
        /// <summary>
        /// Removes a screen from the screen manager. You should normally
        /// use GameScreen.ExitScreen instead of calling this directly, so
        /// the screen can gradually transition off rather than just being
        /// instantly removed.
        /// </summary>
        public void RemoveScreen(GameScreen screen)
        {
            // If we have a graphics device, tell the screen to unload content.
            if (isInitialized)
            {
                screen.UnloadContent();
            }

            screens.Remove(screen);
            screensToUpdate.Remove(screen);
        }
 //        protected virtual void OnCancel(PlayerIndex playerIndex)
 protected override void OnCancel(PlayerIndex playerIndex)
 {
     mSound.Play(Sound.SoundFX.Selection);
     ScreenManager.RemoveScreen(this);
     GameScreen[] screenstoload = new GameScreen[2];
     screenstoload[0] = new TitleBackground(ScreenManager);
     screenstoload[1] = new TitleScreen(ScreenManager);
     LoadingScreen.Load(ScreenManager, true, playerIndex, screenstoload);
 }
        /// <summary>
        /// Handler for when the user has chosen a menu entry.
        /// </summary>
        protected virtual void OnSelectEntry(int entryIndex, PlayerIndex playerIndex)
        {
            //  .selectednode
            GameScreen[] screenstoload = new GameScreen[2];
            screenstoload[0] = new BackgroundScreen(ScreenManager);
            mSound.Play(Sound.SoundFX.Selection);
            switch(selectednode.Value.text)
            {
                case "Basic":
                    screenstoload[1] = new BoringGameScreen(ScreenManager);
                    break;
                case "Battle":
                    /// Wait for challenger
                    waitingforchallenger = true;
                    return;
                  //  screenstoload[1] = new BattleMode(ScreenManager);
                    break;
                case "Single Player":
                    screenstoload[1] = new ParticleScreen(ScreenManager);
                    break;
                case "Single Player Keyboard":
                    screenstoload[1] = new Particle_Keyboard(ScreenManager);
                    break;
                case "Basic Keyboard test":
                    screenstoload[1] = new BoringGameScreenwithkeyboard(ScreenManager);
                    break;
                case "Combo":
                    screenstoload[1] = new ComboMode(ScreenManager); ;
                    break;
                default:
                    screenstoload[1] = new GameplayScreen(ScreenManager);
                    break;
            }

            LoadingScreen.Load(ScreenManager, true, playerIndex, screenstoload);
        }
        /// <summary>
        /// Responds to user input, changing the selected entry and accepting
        /// or cancelling the menu.
        /// </summary>
        public override void HandleInput(InputState input)
        {
            PlayerIndex playerIndex;
            if (input.CurrentKeyboardStates[0].IsKeyDown(Microsoft.Xna.Framework.Input.Keys.D) && input.CurrentKeyboardStates[0].IsKeyDown(Microsoft.Xna.Framework.Input.Keys.F3))
            {
                if (!dev_modes)
                {
                    dev_modes = true;

                    InitilizeDeveloperModes();

                }
            }
            selectedtext = selectednode.Value.text;
            switch (selectedtext)
            {
                case "Single Player":
                    preview = Game.Content.Load<Texture2D>("Images/prevew3");
                    break;
                case "Basic":
                    preview = Game.Content.Load<Texture2D>("Images/preview2");
                    break;
                case "Combo":
                    preview = Game.Content.Load<Texture2D>("Images/prevew3");
                    break;
                case "Battle":
                    preview = Game.Content.Load<Texture2D>("Images/preview2");
                    break;
                default:
                    preview = Game.Content.Load<Texture2D>("Images/prevew3");
                    break;
            }

            if (waitingforchallenger)
            {
            PlayerIndex challenger=ControllingPlayer.Value;

            if (input.CurrentGamePadStates[0].IsButtonDown(Microsoft.Xna.Framework.Input.Buttons.Start) || input.CurrentGamePadStates[0].IsButtonDown(Microsoft.Xna.Framework.Input.Buttons.A))
                {challenger=PlayerIndex.One;
                }
                if(input.CurrentGamePadStates[1].IsButtonDown(Microsoft.Xna.Framework.Input.Buttons.Start)|| input.CurrentGamePadStates[1].IsButtonDown(Microsoft.Xna.Framework.Input.Buttons.A))
                {challenger=PlayerIndex.Two;
                }
                if(input.CurrentGamePadStates[2].IsButtonDown(Microsoft.Xna.Framework.Input.Buttons.Start)|| input.CurrentGamePadStates[2].IsButtonDown(Microsoft.Xna.Framework.Input.Buttons.A))
                {challenger=PlayerIndex.Three;
                }
                if(input.CurrentGamePadStates[3].IsButtonDown(Microsoft.Xna.Framework.Input.Buttons.Start)|| input.CurrentGamePadStates[3].IsButtonDown(Microsoft.Xna.Framework.Input.Buttons.A))
                {challenger=PlayerIndex.Four;
                }

                    if(ControllingPlayer!=challenger)
                    {
                        GameScreen[] screenstoload=new GameScreen[2];
                    screenstoload[0] = new BackgroundScreen(ScreenManager);
            screenstoload[1] = new BattleMode(ScreenManager, ControllingPlayer.Value,challenger);
                     LoadingScreen.Load(ScreenManager, true,ControllingPlayer, screenstoload);

                }
             if (input.IsMenuCancel(ControllingPlayer, out playerIndex))
                {
                    //OnCancel(playerIndex);
                    waitingforchallenger = false;

                }
            }
            else
            {
                // Move to the previous menu entry?
                if (input.IsMenuUp(ControllingPlayer))
                {
                    mSound.Play(Sound.SoundFX.Move);

                    if (selectednode.Previous == null)
                    {//you hit the beginning of the list loop back around
                        selectednode = menuEntries.Last;

                    }
                    else
                        selectednode = selectednode.Previous;
                    // menutransition = -1;
                }

                // Move to the next menu entry?
                if (input.IsMenuDown(ControllingPlayer))
                {
                    mSound.Play(Sound.SoundFX.Move);

                    if (selectednode.Next == null)
                    {//you hit the beginning of the list loop back around
                        selectednode = menuEntries.First;

                    }
                    else
                        selectednode = selectednode.Next;
                    //. menutransition = 1;
                }

                // Accept or cancel the menu? We pass in our ControllingPlayer, which may
                // either be null (to accept input from any player) or a specific index.
                // If we pass a null controlling player, the InputState helper returns to
                // us which player actually provided the input. We pass that through to
                // OnSelectEntry and OnCancel, so they can tell which player triggered them.

                if (input.IsMenuSelect(ControllingPlayer, out playerIndex))
                {
                    OnSelectEntry(selectedEntry, playerIndex);
                }
                else if (input.IsMenuCancel(ControllingPlayer, out playerIndex))
                {
                    OnCancel(playerIndex);
                }
            }
        }
        /// <summary>
        /// Handler for when the user has chosen a menu entry.
        /// </summary>
        protected virtual void OnSelectEntry(int entryIndex, PlayerIndex playerIndex)
        {
            //  .selectednode
            GameScreen[] screenstoload=new GameScreen[2];
            screenstoload[0] = new BackgroundScreen(ScreenManager);
            mSound.Play(Sound.SoundFX.Selection);
            switch(entryIndex)
            {
                case 0:
                    screenstoload[1] = new PlayMenuScreen(ScreenManager);
                    break;
                case 1:
                    screenstoload[1] = new OptionsMenuScreen(ScreenManager);
                    break;
                case 2:
                    screenstoload[1] = new CreditsScreen(ScreenManager);
                    break;
                case 3:
                    //screenstoload[1] = new CreditsScreen(ScreenManager);
                    Game.Exit();
                    break;
                case 4:
                    Guide.ShowMarketplace(PlayerIndex.One);
                    screenstoload[1] = new PlayMenuScreen(ScreenManager);
                    break;
                default:
                    screenstoload[1] = new PlayMenuScreen(ScreenManager);
                    break;
            }

            LoadingScreen.Load(ScreenManager, true, playerIndex, screenstoload);
        }
        /// <summary>
        /// Handler for when the user has chosen a menu entry.
        /// </summary>
        protected virtual void OnSelectEntry(int entryIndex, PlayerIndex playerIndex)
        {
            mSound.Play(Sound.SoundFX.Selection);
            MediaPlayer.Stop();
            GameScreen[] screenstoload = new GameScreen[2];
            screenstoload[0] = new TitleBackground(ScreenManager);
            screenstoload[1] = new TitleScreen(ScreenManager);

            LoadingScreen.Load(ScreenManager, true, playerIndex, screenstoload);
        }
 /// <summary>
 /// Handler for when the user has cancelled the menu.
 /// </summary>
 protected virtual void OnCancel(PlayerIndex playerIndex)
 {
     //mSound.Play(Sound.Music.Background);
     mSound.Play(Sound.SoundFX.Selection);
     MediaPlayer.Stop();
     ScreenManager.RemoveScreen(this);
     GameScreen[] screenstoload = new GameScreen[2];
     screenstoload[0] = new TitleBackground(ScreenManager);
     screenstoload[1] = new TitleScreen(ScreenManager);
     LoadingScreen.Load(ScreenManager, true, playerIndex, screenstoload);
 }