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 StrategicCombat.MenuScreens
{
    /// <summary>
    /// This class represents a splash screen.
    /// </summary>
    public class SplashScreen : GameScreen
    {
        #region Variables

        // The splash screen texture.
        Texture2D splashScreenTexture;

        // Number of milliseconds to display the splash screen.
        const float splashScreenDuration = 4000;
        
        // Keep track of how much time has passed
        float durationCounter = 0;

        #endregion

        #region Constructors

        /// <summary>
        /// Create a new splash screen.
        /// </summary>
        public SplashScreen()
        {

            // Set transition times for fading.
            TransitionOnTime = TimeSpan.FromSeconds(0.5);
            TransitionOffTime = TimeSpan.FromSeconds(0.5);

        }

        /// <summary>
        /// Loads graphics content used by the splash screen.
        /// </summary>
        public override void LoadContent()
        {
            // Create a new content manager.
            ContentManager content = ScreenManager.Game.Content;

            // Load background textures.
            this.splashScreenTexture = content.Load<Texture2D>("MenuAssets/splashScreen");
  
        }

        #endregion

        #region Methods

        /// <summary>
        /// Updates the splash screen.
        /// </summary>
        public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen)
        {
            // Call the update method in the base class.
            base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen);

            if (!IsExiting)
            {
                // Update the timer.
                this.durationCounter += gameTime.ElapsedGameTime.Milliseconds;

                // Check if we should exit from this screen.
                if (this.durationCounter >= splashScreenDuration)
                {
                    // Exit from the screen.
                    ExitScreen();

                }

            }
            else
            {
                if (TransitionPosition == 1)
                {
                    // Add the menu screens
                    ScreenManager.AddScreen(new BackgroundScreen(), null);
                    ScreenManager.AddScreen(new MainMenuScreen(), null);
                }

            }

        } // End of the Update method.

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

            spriteBatch.Begin();

            // Draw the splash screen
            spriteBatch.Draw(splashScreenTexture, new Rectangle(0, 0, 1280, 720), Color.White * TransitionAlpha);

            spriteBatch.End();

        } // End of the Draw method.

        #endregion

    } // End of class

} // End of namespace
