using LeMangeurDEnfants.Core.Entities;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using MonoGame.FourEngine;
using System;

namespace LeMangeurDEnfants.Core.Scenes
{
    public class StartScene : Scene
    {
        private AutoSprite _startText;

        private TimeSpan _switchText = TimeSpan.FromMilliseconds(5000);

        public StartScene()
        {
            AddEntity(new AutoSprite(Resources.Sprites.Start, Configuration.InnerResolution));
            AddEntity(_startText = new AutoSprite(Resources.Sprites.StartText, new Point(Configuration.InnerResolution.X, 50))
            {
                Position = new Point(0, Configuration.InnerResolution.Y - 50)
            });
        }

        public override void OnUpdate(UpdateEventArgs args)
        {
            base.OnUpdate(args);
            if (_switchText > args.DeltaTime)
            {
                _switchText -= args.DeltaTime;
            }
            else
            {
                _switchText = TimeSpan.Zero;
                _startText.Component.Frame = new Point(0, 1);
            }
            if (args.Keyboard.State[Keys.Space].HasClicked
                || args.Keyboard.State[Keys.Enter].HasClicked
                || args.GamePad.State[Buttons.Start].HasClicked)
                (DrawingSurface as DrawingSurface)?.NavigateTo<IntroScene>();
        }

        public override void OnClear(ClearEventArgs args)
        {
            args.Color = Color.White;
        }
    }
}