#region File Description
//-----------------------------------------------------------------------------
// MainMenuScreen.cs
//
// Microsoft XNA Community Game Platform
// Copyright (C) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
#endregion

#region Using Statements
using System;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Net;

#endregion

namespace GhostArena3D
{
    /// <summary>
    /// The main menu screen is the first thing displayed when the game starts up.
    /// </summary>
    class MainMenuScreen : MenuScreen
    {
        private Cue _titleCue = null;

        /// <summary>
        /// Constructor fills in the menu contents.
        /// </summary>
        public MainMenuScreen() : base("")
        {
            MenuEntries.Add(new MenuEntry("Play Game"));
            MenuEntries.Add(new MenuEntry("High Scores"));
            MenuEntries.Add(new MenuEntry("Achievements"));
            MenuEntries.Add(new MenuEntry("Options"));
            MenuEntries.Add(new MenuEntry("Exit"));
        }

        public override void LoadContent()
        {
            _titleCue = ((GhostArena3D)ScreenManager.Game).SoundBank.GetCue("title");

            if(_titleCue.IsPlaying == false)
               _titleCue.Play();

            base.LoadContent();
        }


       public override void UnloadContent()
       {
          _titleCue.Stop(AudioStopOptions.Immediate);
          base.UnloadContent();
       }

        /// <summary>
        /// Responds to user menu selections.
        /// </summary>
        protected override void OnSelectEntry(int entryIndex)
        {
            switch (entryIndex)
            {
                case 0:
                    // Get game type screen.
                    ScreenManager.AddScreen(new GametypeScreen());
                    break;

                case 1:
                    // Display the high score.
                    ScreenManager.AddScreen(new HighScoreScreen());
                    break;


                case 2:
                    break;

                case 3:
                    // Go to the options screen.
                    ScreenManager.AddScreen(new OptionsMenuScreen());
                    break;

                case 4:
                    // Exit the sample.
                    OnCancel();
                    break;
            }
        }


        /// <summary>
        /// When the user cancels the main menu, ask if they want to exit the sample.
        /// </summary>
        protected override void OnCancel()
        {
            const string message = "Are you sure you want to exit this sample?";

            MessageBoxScreen messageBox = new MessageBoxScreen(message);

            messageBox.Accepted += ExitMessageBoxAccepted;

            ScreenManager.AddScreen(messageBox);
        }


        /// <summary>
        /// Event handler for when the user selects ok on the "are you sure
        /// you want to exit" message box.
        /// </summary>
        void ExitMessageBoxAccepted(object sender, EventArgs e)
        {
            ScreenManager.Game.Exit();
        }


      public override void Draw(GameTime gameTime)
      {
         if(SignedInGamer.SignedInGamers.Count == 0)
         {
            SpriteBatch spriteBatch = ScreenManager.SpriteBatch;
            SpriteFont font = ScreenManager.Font;
            int width = ScreenManager.GraphicsDevice.Viewport.Width;
            int height = ScreenManager.GraphicsDevice.Viewport.Height;

            spriteBatch.Begin();

            spriteBatch.DrawString(font, "Please Sign-In",
                                   new Vector2(width / 3, height / 2),
                                   Color.Yellow);

            spriteBatch.End();
         }
         else
         {
            base.Draw(gameTime);
         }
      }
   }
}
