using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace TribbleExtinction
{
    public class TutorialGame : GenericGame
    {
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;

        public Texture2D Background;
        float Timer;

        public TutorialGame()
        {
        }

        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        public override void Initialize()
        {
            graphics = Program.masterGame.graphics;
            spriteBatch = Program.masterGame.spriteBatch;

            // TODO: Add your initialization logic here
            graphics.PreferredBackBufferWidth = 896;
            graphics.PreferredBackBufferHeight = 640;
            graphics.ApplyChanges();


            
            spriteBatch = new SpriteBatch(Program.masterGame.GraphicsDevice);

            Timer = 1.0f;

            prevMouse = Mouse.GetState();
            
            Program.masterGame.IsMouseVisible = true;

            base.Initialize();
        }

        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        MouseState prevMouse;
        public override void Update(GameTime gameTime)
        {
            bool click = false;
            Timer -= (float)gameTime.ElapsedGameTime.TotalSeconds;

            MouseState cMouse = Mouse.GetState();

            if (prevMouse.LeftButton == ButtonState.Pressed && cMouse.LeftButton == ButtonState.Released
                || prevMouse.MiddleButton == ButtonState.Pressed && cMouse.MiddleButton == ButtonState.Released
                || prevMouse.RightButton == ButtonState.Pressed && cMouse.RightButton == ButtonState.Released)
                click = true;

            if (Timer < 0 && click)
            {
                Game1 tg = new Game1();
                tg.Initialize();
                Program.masterGame.ChildGame = tg;
            }

            prevMouse = cMouse;

            base.Update(gameTime);
        }

        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

        public override void Draw(GameTime gameTime)
        {
            Program.masterGame.spriteBatch.Begin();
            Program.masterGame.spriteBatch.Draw(Background, new Rectangle(0, 0, graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight), Color.White);
            Program.masterGame.spriteBatch.End();

            base.Draw(gameTime);
        }
    }
}

