#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;

#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();
        }

        /// <summary>
        /// Responds to user menu selections.
        /// </summary>
        protected override void OnSelectEntry(int entryIndex)
        {
            switch (entryIndex)
            {
                case 0:
                     _titleCue.Stop(AudioStopOptions.Immediate);

                    // Play the game.
                    LoadingScreen.Load(ScreenManager, true, new GameplayScreen());
                    break;

                case 1:
                    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;
            }
        }

        void StartGame(object sender, EventArgs e)
        {
            ScreenManager.AddScreen(new GameplayScreen());
        }

        /// <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();
        }

    }
}
