#region Using Statements
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Storage;
#endregion

namespace Menu.GameLogic
{
    //Classe qui permet l'affichage des textures et initialise position, taille,...
    public class WorldEntity : DrawableGameComponent
    {
        #region Fields
        ContentManager _content;
        
        Texture2D _texture;
        public string _nomTexture;
        Vector2 _position;
        Vector2 _taille;
        public enum Mode {ON, OFF, DISABLEOFF, DISABLEON, newbie, pro};
        public Mode _mode;
        //Amélioration possible? Affichage des options a l'aide d'une boucle foreach
        public enum Option {storymode, skirmishmode, library, mapeditor, loadgame, options, highscore, quit, difficulty};
        public Option _option;

        public SpriteBatch _spriteBatch;
        #endregion

        #region Constructeurs
        public WorldEntity(Game game, string nomTexture, float posX, float posY, float sizeX, float sizeY)
            : base(game)
        {
            _content = new ContentManager(this.Game.Services);
            this._nomTexture = nomTexture;
            _position = new Vector2(posX, posY);
            _taille = new Vector2(sizeX, sizeY);
        }

        public WorldEntity(Game game, string nomTexture, float posX, float posY, float sizeX, float sizeY, Mode mode, Option option)
            : base(game)
        {
            _content = new ContentManager(this.Game.Services);
            this._mode = mode;
            this._option = option;
            this._nomTexture = nomTexture + "_" + option + "_" + mode;
            _position = new Vector2(posX, posY);
            _taille = new Vector2(sizeX, sizeY);
        }

        public WorldEntity(Game game, float posX, float posY, float sizeX, float sizeY)
            : base(game)
        {
            _content = new ContentManager(this.Game.Services);
            _position = new Vector2(posX, posY);
            _taille = new Vector2(sizeX, sizeY);
        }

        public WorldEntity(Game game, string nomTexture)
            : base(game)
        {
            _content = new ContentManager(this.Game.Services);
            this._nomTexture = nomTexture;
        }

        #endregion

        #region Accesseurs
        public SpriteBatch SpriteBatch
        {
            get { return _spriteBatch; }            
        }

        public Vector2 Taille
        {
            get { return _taille; }
        }

        public float TailleUnique
        {
            get { return _taille.X; }            
        }

        public float TailleX
        {
            get { return _taille.X; }
        }

        public float TailleY
        {
            get { return _taille.Y; }
        }


        public Vector2 Position
        {
            get { return _position; }
            set { _position = value; }
        }

        public float PositionY
        {
            get { return _position.Y; }
            set { _position.Y = value; }
        }

        public float PositionX
        {
            get { return _position.X; }
            set { _position.X = value; }
        }
	    public Texture2D Texture2D
        {
            get { return _texture; }
            set { _texture = value; }
        }

        public string NomTexture
        {
            get { return _nomTexture; }
            set { _nomTexture = value; }
        }
	
        #endregion

        #region Initialize_LoadGraphicsContent_UnloadGraphicsContent
        
        public override void Initialize()
        {
            _content = new ContentManager(this.Game.Services);
            IGraphicsDeviceService gds = (IGraphicsDeviceService)Game.Services.GetService(typeof(IGraphicsDeviceService));
            
            _spriteBatch = new SpriteBatch(gds.GraphicsDevice);
            base.Initialize();
        }

        protected override void LoadGraphicsContent(bool loadAllContent)
        {

            _texture = _content.Load<Texture2D>("Data/Textures/Menu/" + _nomTexture);
            base.LoadGraphicsContent(loadAllContent);
        }

        protected override void UnloadGraphicsContent(bool unloadAllContent)
        {
            _content.Unload();
            base.UnloadGraphicsContent(unloadAllContent);
        }
        #endregion

        #region UpdateAndDraw
        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);
        }

        public override void Draw(GameTime gameTime)
        {
            _spriteBatch.Begin();
            _spriteBatch.Draw(_texture, new Rectangle((int)this._position.X, (int)this._position.Y, (int)_taille.X, (int)_taille.Y), Color.White);
            _spriteBatch.End();
            base.Draw(gameTime);
        }
        #endregion
        
    }
}

