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

#region Using Statements
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
#endregion

namespace FredriksdalAssault2
{
    /// <summary>
    /// The background screen sits behind all the other menu screens.
    /// It draws a background image that remains fixed in place regardless
    /// of whatever transitions the screens on top of it may be doing.
    /// </summary>
    class BackgroundScreen : GameScreen
    {
        #region Fields

        ContentManager content;
        Texture2D backgroundTexture;

        // Xbox icons
        Texture2D aButtonTexture;
        Texture2D bButtonTexture;

        // Pc icons
        Texture2D enterButtonTexture;
        Texture2D escapeButtonTexture;

        #endregion

        #region Initialization


        /// <summary>
        /// Constructor.
        /// </summary>
        public BackgroundScreen()
        {
            TransitionOnTime = TimeSpan.FromSeconds(0.5);
            TransitionOffTime = TimeSpan.FromSeconds(0.5);
        }


        /// <summary>
        /// Loads graphics content for this screen. The background texture is quite
        /// big, so we use our own local ContentManager to load it. This allows us
        /// to unload before going from the menus into the game itself, wheras if we
        /// used the shared ContentManager provided by the Game class, the content
        /// would remain loaded forever.
        /// </summary>
        public override void LoadContent()
        {
            if (content == null)
                content = new ContentManager(ScreenManager.Game.Services, "Content");

            backgroundTexture = content.Load<Texture2D>("Menus/forrest");
            aButtonTexture = content.Load<Texture2D>("Menus/a");
            bButtonTexture = content.Load<Texture2D>("Menus/b");
            enterButtonTexture = content.Load<Texture2D>("Menus/enter");
            escapeButtonTexture = content.Load<Texture2D>("Menus/escape");

        }


        /// <summary>
        /// Unloads graphics content for this screen.
        /// </summary>
        public override void UnloadContent()
        {
            content.Unload();
        }


        #endregion

        #region Update and Draw


        /// <summary>
        /// Updates the background screen. Unlike most screens, this should not
        /// transition off even if it has been covered by another screen: it is
        /// supposed to be covered, after all! This overload forces the
        /// coveredByOtherScreen parameter to false in order to stop the base
        /// Update method wanting to transition off.
        /// </summary>
        public override void Update(GameTime gameTime, bool otherScreenHasFocus,
                                                       bool coveredByOtherScreen)
        {
            base.Update(gameTime, otherScreenHasFocus, false);
        }


        /// <summary>
        /// Draws the background screen.
        /// </summary>
        public override void Draw(GameTime gameTime)
        {
            SpriteBatch spriteBatch = ScreenManager.SpriteBatch;
            Viewport viewport = ScreenManager.GraphicsDevice.Viewport;
            int safeAreaLeft = viewport.TitleSafeArea.Left;
            int safeAreaBottom = viewport.TitleSafeArea.Bottom;
            Rectangle fullscreen = new Rectangle(0, 0, viewport.Width, viewport.Height);
            SpriteFont font = ScreenManager.Font;

            spriteBatch.Begin();

            spriteBatch.Draw(backgroundTexture, fullscreen,
                             new Color(TransitionAlpha, TransitionAlpha, TransitionAlpha));
#if (!XBOX360)
            // Draw select key with text (enter button)
            spriteBatch.Draw(enterButtonTexture, new Vector2(safeAreaLeft + 10, safeAreaBottom - 42),
                                 Color.White * TransitionAlpha);

            spriteBatch.DrawString(font, "Select", new Vector2(safeAreaLeft + 51, safeAreaBottom - 41), Color.DarkGray, 0,
                                   Vector2.Zero, 0.8f, SpriteEffects.None, 0);
            spriteBatch.DrawString(font, "Select", new Vector2(safeAreaLeft + 50, safeAreaBottom - 42), Color.White, 0,
                                   Vector2.Zero, 0.8f, SpriteEffects.None, 0);

            // Draw back button with text (esc button)
            spriteBatch.Draw(escapeButtonTexture, new Vector2(safeAreaLeft + 120, safeAreaBottom - 42),
                                 Color.White * TransitionAlpha);

            spriteBatch.DrawString(font, "Back", new Vector2(safeAreaLeft + 161, safeAreaBottom - 41), Color.DarkGray, 0,
                                   Vector2.Zero, 0.8f, SpriteEffects.None, 0);
            spriteBatch.DrawString(font, "Back", new Vector2(safeAreaLeft + 160, safeAreaBottom - 42), Color.White, 0,
                                   Vector2.Zero, 0.8f, SpriteEffects.None, 0);
#endif

#if (XBOX360)
            // Draw select button with text (a button)
            spriteBatch.Draw(aButtonTexture, new Vector2(safeAreaLeft + 10, safeAreaBottom - 42),
                                 Color.White * TransitionAlpha);

            spriteBatch.DrawString(font, "Select", new Vector2(safeAreaLeft + 51, safeAreaBottom - 41), Color.DarkGray, 0,
                                   Vector2.Zero, 0.8f, SpriteEffects.None, 0);
            spriteBatch.DrawString(font, "Select", new Vector2(safeAreaLeft + 50, safeAreaBottom - 42), Color.White, 0,
                                   Vector2.Zero, 0.8f, SpriteEffects.None, 0);

            // Draw back button with text (b button)
            spriteBatch.Draw(bButtonTexture, new Vector2(safeAreaLeft + 120, safeAreaBottom - 42),
                                 Color.White * TransitionAlpha);

            spriteBatch.DrawString(font, "Back", new Vector2(safeAreaLeft + 161, safeAreaBottom - 41), Color.DarkGray, 0,
                                   Vector2.Zero, 0.8f, SpriteEffects.None, 0);
            spriteBatch.DrawString(font, "Back", new Vector2(safeAreaLeft + 160, safeAreaBottom - 42), Color.White, 0,
                                   Vector2.Zero, 0.8f, SpriteEffects.None, 0);
#endif

            spriteBatch.End();
        }


        #endregion
    }
}
