using ECOT.Engine;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace ECOT.Game.States
{
    public class EcothinkState : GameState
    {
        private Texture2D logoTex;
        private int timer;

        public override void LoadGraphicsContent(bool loadAllContent)
        {
            this.timer = 4000;

            if (this.loaded) return;

            this.logoTex = Kernel.Instance.Medias.Get<Texture2D>(@"Bootstrap\Logo");
            //Sound.PlayEffectNow(EcotSound.EcothinkSound);

            base.LoadGraphicsContent(loadAllContent);
        }

        public override void UnloadGraphicsContent(bool unloadAllContent)
        {
            if (unloadAllContent)
                this.logoTex.Dispose();
        }

        public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen)
        {
            base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen);

            if (this.timer == 0) return;

            this.timer -= gameTime.ElapsedGameTime.Milliseconds;
            if (this.timer <= 0)
            {
                Kernel.Instance.StateManager.SwitchTo("Gameplay", this.ToString());

                this.timer = 0;
            }
        }

        public override void Draw(GameTime gameTime)
        {
            SpriteBatch sb = Kernel.Instance.SpriteBatch;

            sb.Begin();
            sb.Draw(
                this.logoTex,
                new Vector2((Kernel.Instance.Width - this.logoTex.Width) / 2, (Kernel.Instance.Height - this.logoTex.Height) / 2),
                new Color(255, 255, 255, this.TransitionAlpha));
            sb.End();
        }

        public override string ToString()
        {
            return "Ecothink";
        }
    }
}
