using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;

namespace FredriksdalAssault2
{
    /// <summary>
    /// A popup message box screen, used to display information about
    /// the game.
    /// </summary>
    class AboutTheGameScreen : GameScreen
    {
        #region Variables

        string title;
        string message;
        Texture2D gradientTexture;

        #endregion

        #region Events

        public event EventHandler<PlayerIndexEventArgs> Cancelled;

        #endregion

        #region Constructors

        /// <summary>
        /// Create a new about the game screen.
        /// </summary>
        public AboutTheGameScreen()
        {
            this.title = Resources.AboutTheGame;

            this.message = "Fredriksdal Assault is a multiplayer game with two game modes, Assault " + Environment.NewLine +
                           "and Deathmatch. In Assault mode, each network player is assigned " + Environment.NewLine + 
                           "to a team, attacking or defending, where the attacking team should " + Environment.NewLine + 
                           "collect barrels located in houses and the defending team should prevent " + Environment.NewLine +
                           "the attacking team from collecting all the barrels before the time ends. " + Environment.NewLine + Environment.NewLine +
                           "The Deathmatch mode means that every player fights against each other " + Environment.NewLine +
                           "and the game ends when one player has made a certain number of kills " + Environment.NewLine +
                           "or when the time has run out. " + Environment.NewLine + Environment.NewLine +
                           "Fredriksdal Assault is created by: xfsgames.com (Fredrik Stigsson) " + Environment.NewLine +
                           "Copyright and creation year: 2011";

            IsPopup = true;

            TransitionOnTime = TimeSpan.FromSeconds(0.2);
            TransitionOffTime = TimeSpan.FromSeconds(0.2);
        }

        #endregion

        #region Initialization

        /// <summary>
        /// Loads graphics content for this screen. This uses the shared ContentManager
        /// provided by the Game class, so the content will remain loaded forever.
        /// Whenever a subsequent MessageBoxScreen tries to load this same content,
        /// it will just get back another reference to the already loaded data.
        /// </summary>
        public override void LoadContent()
        {
            ContentManager content = ScreenManager.Game.Content;

            gradientTexture = content.Load<Texture2D>("Menus/gradient");
        }

        #endregion

        #region Handle Input


        /// <summary>
        /// Responds to user input, accepting or cancelling the message box.
        /// </summary>
        public override void HandleInput(InputState input)
        {
            PlayerIndex playerIndex;

            // 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 our Cancelled events, 
            // so they can tell which player triggered them.
            if (input.IsMenuCancel(ControllingPlayer, out playerIndex))
            {
                // Raise the cancelled event, then exit the message box.
                if (Cancelled != null)
                    Cancelled(this, new PlayerIndexEventArgs(playerIndex));

                ExitScreen();
            }
        }

        #endregion

        #region Draw

        /// <summary>
        /// Draws the message box.
        /// </summary>
        public override void Draw(GameTime gameTime)
        {
            SpriteBatch spriteBatch = ScreenManager.SpriteBatch;
            SpriteFont font = ScreenManager.Font;

            // Darken down any other screens that were drawn beneath the popup.
            ScreenManager.FadeBackBufferToBlack(TransitionAlpha * 2 / 3);

            // Center the message text in the viewport.
            Viewport viewport = ScreenManager.GraphicsDevice.Viewport;
            int safeAreaTop = viewport.TitleSafeArea.Top;
            int safeAreaBottom = viewport.TitleSafeArea.Bottom;

            // The background includes a border somewhat larger than the text itself.
            Rectangle backgroundRectangle = new Rectangle(viewport.X + 200, safeAreaTop,
                viewport.Width - 400, safeAreaBottom);

            // Fade the popup alpha during transitions.
            Color color = Color.White * TransitionAlpha;

            spriteBatch.Begin();

            // Draw the background rectangle.
            spriteBatch.Draw(gradientTexture, backgroundRectangle, color);

            // Draw the title
            spriteBatch.DrawString(font, title, new Vector2(220, safeAreaTop + 10), Color.White, 0, new Vector2(0, 0), 1.25f, SpriteEffects.None, 0);

            // Draw the text
            spriteBatch.DrawString(font, message, new Vector2(220, safeAreaTop + 65), Color.White, 0, new Vector2(0, 0), 0.8f, SpriteEffects.None, 0);

#if (!XBOX360)

            // Draw the exit screen text
            spriteBatch.DrawString(font, "Press Escape (Esc) to exit from this screen", new Vector2(220, safeAreaBottom - 40), Color.White, 0, new Vector2(0, 0), 0.8f, SpriteEffects.None, 0);
#endif
#if XBOX360
            // Draw the exit screen text
            spriteBatch.DrawString(font, "Press button B to exit from this screen", new Vector2(220, safeAreaBottom - 40), Color.White, 0, new Vector2(0, 0), 0.8f, SpriteEffects.None, 0);
#endif


            spriteBatch.End();
        }


        #endregion
    }
}
